| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 void OmniboxSearchHint::ShowInfoBar() { | 179 void OmniboxSearchHint::ShowInfoBar() { |
| 180 tab_->AddInfoBar(new HintInfoBar(this)); | 180 tab_->AddInfoBar(new HintInfoBar(this)); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void OmniboxSearchHint::ShowEnteringQuery() { | 183 void OmniboxSearchHint::ShowEnteringQuery() { |
| 184 LocationBar* location_bar = BrowserList::GetLastActive()->window()-> | 184 LocationBar* location_bar = BrowserList::GetLastActive()->window()-> |
| 185 GetLocationBar(); | 185 GetLocationBar(); |
| 186 AutocompleteEditView* edit_view = location_bar->location_entry(); | 186 AutocompleteEditView* edit_view = location_bar->location_entry(); |
| 187 location_bar->FocusLocation(true); | 187 location_bar->FocusLocation(true); |
| 188 edit_view->SetUserText(UTF16ToWideHack( | 188 edit_view->SetUserText( |
| 189 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT))); | 189 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); |
| 190 edit_view->SelectAll(false); | 190 edit_view->SelectAll(false); |
| 191 // Entering text in the autocomplete edit view triggers the suggestion popup | 191 // Entering text in the autocomplete edit view triggers the suggestion popup |
| 192 // that we don't want to show in this case. | 192 // that we don't want to show in this case. |
| 193 edit_view->ClosePopup(); | 193 edit_view->ClosePopup(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void OmniboxSearchHint::DisableHint() { | 196 void OmniboxSearchHint::DisableHint() { |
| 197 // The NAV_ENTRY_COMMITTED notification was needed to show the infobar, the | 197 // The NAV_ENTRY_COMMITTED notification was needed to show the infobar, the |
| 198 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint | 198 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint |
| 199 // prefs to false, none of them are needed anymore. | 199 // prefs to false, none of them are needed anymore. |
| 200 notification_registrar_.RemoveAll(); | 200 notification_registrar_.RemoveAll(); |
| 201 tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, | 201 tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, |
| 202 false); | 202 false); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // static | 205 // static |
| 206 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 206 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
| 207 // The infobar can only be shown if the correct switch has been provided and | 207 // The infobar can only be shown if the correct switch has been provided and |
| 208 // the user did not dismiss the infobar before. | 208 // the user did not dismiss the infobar before. |
| 209 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 209 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
| 210 CommandLine::ForCurrentProcess()->HasSwitch( | 210 CommandLine::ForCurrentProcess()->HasSwitch( |
| 211 switches::kSearchInOmniboxHint); | 211 switches::kSearchInOmniboxHint); |
| 212 } | 212 } |
| OLD | NEW |