| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 // TODO(avi): remove when conversions not needed any more | 10 // TODO(avi): remove when conversions not needed any more |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 void OmniboxSearchHint::ShowInfoBar() { | 202 void OmniboxSearchHint::ShowInfoBar() { |
| 203 tab_->AddInfoBar(new HintInfoBar(this)); | 203 tab_->AddInfoBar(new HintInfoBar(this)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void OmniboxSearchHint::ShowEnteringQuery() { | 206 void OmniboxSearchHint::ShowEnteringQuery() { |
| 207 LocationBar* location_bar = BrowserList::GetLastActive()->window()-> | 207 LocationBar* location_bar = BrowserList::GetLastActive()->window()-> |
| 208 GetLocationBar(); | 208 GetLocationBar(); |
| 209 AutocompleteEditView* edit_view = location_bar->location_entry(); | 209 AutocompleteEditView* edit_view = location_bar->location_entry(); |
| 210 location_bar->FocusLocation(true); | 210 location_bar->FocusLocation(true); |
| 211 edit_view->SetUserText(UTF16ToWideHack( | 211 edit_view->SetUserText( |
| 212 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT))); | 212 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); |
| 213 edit_view->SelectAll(false); | 213 edit_view->SelectAll(false); |
| 214 // Entering text in the autocomplete edit view triggers the suggestion popup | 214 // Entering text in the autocomplete edit view triggers the suggestion popup |
| 215 // that we don't want to show in this case. | 215 // that we don't want to show in this case. |
| 216 edit_view->ClosePopup(); | 216 edit_view->ClosePopup(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void OmniboxSearchHint::DisableHint() { | 219 void OmniboxSearchHint::DisableHint() { |
| 220 // The NAV_ENTRY_COMMITTED notification was needed to show the infobar, the | 220 // The NAV_ENTRY_COMMITTED notification was needed to show the infobar, the |
| 221 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint | 221 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint |
| 222 // prefs to false, none of them are needed anymore. | 222 // prefs to false, none of them are needed anymore. |
| 223 notification_registrar_.RemoveAll(); | 223 notification_registrar_.RemoveAll(); |
| 224 tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, | 224 tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, |
| 225 false); | 225 false); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // static | 228 // static |
| 229 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 229 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
| 230 // The infobar can only be shown if the correct switch has been provided and | 230 // The infobar can only be shown if the correct switch has been provided and |
| 231 // the user did not dismiss the infobar before. | 231 // the user did not dismiss the infobar before. |
| 232 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 232 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
| 233 CommandLine::ForCurrentProcess()->HasSwitch( | 233 CommandLine::ForCurrentProcess()->HasSwitch( |
| 234 switches::kSearchInOmniboxHint); | 234 switches::kSearchInOmniboxHint); |
| 235 } | 235 } |
| OLD | NEW |