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 "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 // TODO(avi): remove when conversions not needed any more |
| 13 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/autocomplete/autocomplete.h" | 14 #include "chrome/browser/autocomplete/autocomplete.h" |
13 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 15 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
14 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 16 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
15 #include "chrome/browser/autocomplete/autocomplete_match.h" | 17 #include "chrome/browser/autocomplete/autocomplete_match.h" |
16 #include "chrome/browser/browser_list.h" | 18 #include "chrome/browser/browser_list.h" |
17 #include "chrome/browser/browser_window.h" | 19 #include "chrome/browser/browser_window.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search_engines/template_url.h" | 22 #include "chrome/browser/search_engines/template_url.h" |
21 #include "chrome/browser/search_engines/template_url_model.h" | 23 #include "chrome/browser/search_engines/template_url_model.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 178 |
177 void OmniboxSearchHint::ShowInfoBar() { | 179 void OmniboxSearchHint::ShowInfoBar() { |
178 tab_->AddInfoBar(new HintInfoBar(this)); | 180 tab_->AddInfoBar(new HintInfoBar(this)); |
179 } | 181 } |
180 | 182 |
181 void OmniboxSearchHint::ShowEnteringQuery() { | 183 void OmniboxSearchHint::ShowEnteringQuery() { |
182 LocationBar* location_bar = BrowserList::GetLastActive()->window()-> | 184 LocationBar* location_bar = BrowserList::GetLastActive()->window()-> |
183 GetLocationBar(); | 185 GetLocationBar(); |
184 AutocompleteEditView* edit_view = location_bar->location_entry(); | 186 AutocompleteEditView* edit_view = location_bar->location_entry(); |
185 location_bar->FocusLocation(true); | 187 location_bar->FocusLocation(true); |
186 edit_view->SetUserText( | 188 edit_view->SetUserText(UTF16ToWideHack( |
187 l10n_util::GetString(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); | 189 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT))); |
188 edit_view->SelectAll(false); | 190 edit_view->SelectAll(false); |
189 // Entering text in the autocomplete edit view triggers the suggestion popup | 191 // Entering text in the autocomplete edit view triggers the suggestion popup |
190 // that we don't want to show in this case. | 192 // that we don't want to show in this case. |
191 edit_view->ClosePopup(); | 193 edit_view->ClosePopup(); |
192 } | 194 } |
193 | 195 |
194 void OmniboxSearchHint::DisableHint() { | 196 void OmniboxSearchHint::DisableHint() { |
195 // 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 |
196 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint | 198 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint |
197 // prefs to false, none of them are needed anymore. | 199 // prefs to false, none of them are needed anymore. |
198 notification_registrar_.RemoveAll(); | 200 notification_registrar_.RemoveAll(); |
199 tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, | 201 tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, |
200 false); | 202 false); |
201 } | 203 } |
202 | 204 |
203 // static | 205 // static |
204 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 206 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
205 // 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 |
206 // the user did not dismiss the infobar before. | 208 // the user did not dismiss the infobar before. |
207 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 209 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
208 CommandLine::ForCurrentProcess()->HasSwitch( | 210 CommandLine::ForCurrentProcess()->HasSwitch( |
209 switches::kSearchInOmniboxHint); | 211 switches::kSearchInOmniboxHint); |
210 } | 212 } |
OLD | NEW |