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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "chrome/browser/autocomplete/autocomplete.h" | 12 #include "chrome/browser/autocomplete/autocomplete.h" |
13 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 13 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
15 #include "chrome/browser/infobars/infobar_tab_helper.h" | 15 #include "chrome/browser/infobars/infobar_tab_helper.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/search_engines/template_url.h" | 18 #include "chrome/browser/search_engines/template_url.h" |
19 #include "chrome/browser/search_engines/template_url_service.h" | 19 #include "chrome/browser/search_engines/template_url_service.h" |
20 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_finder.h" |
23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/omnibox/location_bar.h" | 25 #include "chrome/browser/ui/omnibox/location_bar.h" |
25 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 26 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "content/public/browser/navigation_details.h" | 31 #include "content/public/browser/navigation_details.h" |
31 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
32 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 DisableHint(); | 205 DisableHint(); |
205 } | 206 } |
206 } | 207 } |
207 } | 208 } |
208 | 209 |
209 void OmniboxSearchHint::ShowInfoBar() { | 210 void OmniboxSearchHint::ShowInfoBar() { |
210 tab_->infobar_tab_helper()->AddInfoBar(new HintInfoBar(this)); | 211 tab_->infobar_tab_helper()->AddInfoBar(new HintInfoBar(this)); |
211 } | 212 } |
212 | 213 |
213 void OmniboxSearchHint::ShowEnteringQuery() { | 214 void OmniboxSearchHint::ShowEnteringQuery() { |
214 LocationBar* location_bar = BrowserList::GetLastActiveWithProfile( | 215 LocationBar* location_bar = browser::FindLastActiveWithProfile( |
215 tab_->profile())->window()->GetLocationBar(); | 216 tab_->profile())->window()->GetLocationBar(); |
216 OmniboxView* omnibox_view = location_bar->GetLocationEntry(); | 217 OmniboxView* omnibox_view = location_bar->GetLocationEntry(); |
217 location_bar->FocusLocation(true); | 218 location_bar->FocusLocation(true); |
218 omnibox_view->SetUserText( | 219 omnibox_view->SetUserText( |
219 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); | 220 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); |
220 omnibox_view->SelectAll(false); | 221 omnibox_view->SelectAll(false); |
221 // Entering text in the omnibox view triggers the suggestion popup that we | 222 // Entering text in the omnibox view triggers the suggestion popup that we |
222 // don't want to show in this case. | 223 // don't want to show in this case. |
223 omnibox_view->ClosePopup(); | 224 omnibox_view->ClosePopup(); |
224 } | 225 } |
225 | 226 |
226 void OmniboxSearchHint::DisableHint() { | 227 void OmniboxSearchHint::DisableHint() { |
227 // The NAV_ENTRY_COMMITTED notification was needed to show the infobar, the | 228 // The NAV_ENTRY_COMMITTED notification was needed to show the infobar, the |
228 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint | 229 // OMNIBOX_OPENED_URL notification was there to set the kShowOmniboxSearchHint |
229 // prefs to false, none of them are needed anymore. | 230 // prefs to false, none of them are needed anymore. |
230 notification_registrar_.RemoveAll(); | 231 notification_registrar_.RemoveAll(); |
231 tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, | 232 tab_->profile()->GetPrefs()->SetBoolean(prefs::kShowOmniboxSearchHint, |
232 false); | 233 false); |
233 } | 234 } |
234 | 235 |
235 // static | 236 // static |
236 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 237 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
237 // The infobar can only be shown if the correct switch has been provided and | 238 // The infobar can only be shown if the correct switch has been provided and |
238 // the user did not dismiss the infobar before. | 239 // the user did not dismiss the infobar before. |
239 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 240 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
240 CommandLine::ForCurrentProcess()->HasSwitch( | 241 CommandLine::ForCurrentProcess()->HasSwitch( |
241 switches::kSearchInOmniboxHint); | 242 switches::kSearchInOmniboxHint); |
242 } | 243 } |
OLD | NEW |