| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/omnibox_search_hint.h" | 5 #include "chrome/browser/omnibox_search_hint.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 void OmniboxSearchHint::ShowInfoBar() { | 217 void OmniboxSearchHint::ShowInfoBar() { |
| 218 InfoBarTabHelper* infobar_tab_helper = | 218 InfoBarTabHelper* infobar_tab_helper = |
| 219 InfoBarTabHelper::FromWebContents(web_contents_); | 219 InfoBarTabHelper::FromWebContents(web_contents_); |
| 220 infobar_tab_helper->AddInfoBar(new HintInfoBar(this, infobar_tab_helper)); | 220 infobar_tab_helper->AddInfoBar(new HintInfoBar(this, infobar_tab_helper)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void OmniboxSearchHint::ShowEnteringQuery() { | 223 void OmniboxSearchHint::ShowEnteringQuery() { |
| 224 LocationBar* location_bar = browser::FindBrowserWithWebContents( | 224 LocationBar* location_bar = chrome::FindBrowserWithWebContents( |
| 225 web_contents_)->window()->GetLocationBar(); | 225 web_contents_)->window()->GetLocationBar(); |
| 226 OmniboxView* omnibox_view = location_bar->GetLocationEntry(); | 226 OmniboxView* omnibox_view = location_bar->GetLocationEntry(); |
| 227 location_bar->FocusLocation(true); | 227 location_bar->FocusLocation(true); |
| 228 omnibox_view->SetUserText( | 228 omnibox_view->SetUserText( |
| 229 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); | 229 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); |
| 230 omnibox_view->SelectAll(false); | 230 omnibox_view->SelectAll(false); |
| 231 // Entering text in the omnibox view triggers the suggestion popup that we | 231 // Entering text in the omnibox view triggers the suggestion popup that we |
| 232 // don't want to show in this case. | 232 // don't want to show in this case. |
| 233 omnibox_view->CloseOmniboxPopup(); | 233 omnibox_view->CloseOmniboxPopup(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void OmniboxSearchHint::DisableHint() { | 236 void OmniboxSearchHint::DisableHint() { |
| 237 // The NAV_ENTRY_COMMITTED notification was needed to show the infobar, the | 237 // The NAV_ENTRY_COMMITTED notification was needed to show the infobar, the |
| 238 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint | 238 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint |
| 239 // prefs to false, none of them are needed anymore. | 239 // prefs to false, none of them are needed anymore. |
| 240 notification_registrar_.RemoveAll(); | 240 notification_registrar_.RemoveAll(); |
| 241 Profile* profile = | 241 Profile* profile = |
| 242 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 242 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 243 profile->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, false); | 243 profile->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, false); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // static | 246 // static |
| 247 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 247 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
| 248 // The infobar can only be shown if the correct switch has been provided and | 248 // The infobar can only be shown if the correct switch has been provided and |
| 249 // the user did not dismiss the infobar before. | 249 // the user did not dismiss the infobar before. |
| 250 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 250 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
| 251 CommandLine::ForCurrentProcess()->HasSwitch( | 251 CommandLine::ForCurrentProcess()->HasSwitch( |
| 252 switches::kSearchInOmniboxHint); | 252 switches::kSearchInOmniboxHint); |
| 253 } | 253 } |
| OLD | NEW |