| 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 |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.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/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/search_engines/template_url.h" | 18 #include "chrome/browser/search_engines/template_url.h" |
| 18 #include "chrome/browser/search_engines/template_url_service.h" | 19 #include "chrome/browser/search_engines/template_url_service.h" |
| 19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 20 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 21 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/omnibox/location_bar.h" | 24 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 24 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 25 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 type == AutocompleteMatch::SEARCH_HISTORY || | 195 type == AutocompleteMatch::SEARCH_HISTORY || |
| 195 type == AutocompleteMatch::SEARCH_SUGGEST) { | 196 type == AutocompleteMatch::SEARCH_SUGGEST) { |
| 196 // The user performed a search from the omnibox, don't show the infobar | 197 // The user performed a search from the omnibox, don't show the infobar |
| 197 // again. | 198 // again. |
| 198 DisableHint(); | 199 DisableHint(); |
| 199 } | 200 } |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 void OmniboxSearchHint::ShowInfoBar() { | 204 void OmniboxSearchHint::ShowInfoBar() { |
| 204 tab_->AddInfoBar(new HintInfoBar(this)); | 205 tab_->infobar_tab_helper()->AddInfoBar(new HintInfoBar(this)); |
| 205 } | 206 } |
| 206 | 207 |
| 207 void OmniboxSearchHint::ShowEnteringQuery() { | 208 void OmniboxSearchHint::ShowEnteringQuery() { |
| 208 LocationBar* location_bar = BrowserList::GetLastActiveWithProfile( | 209 LocationBar* location_bar = BrowserList::GetLastActiveWithProfile( |
| 209 tab_->profile())->window()->GetLocationBar(); | 210 tab_->profile())->window()->GetLocationBar(); |
| 210 OmniboxView* omnibox_view = location_bar->location_entry(); | 211 OmniboxView* omnibox_view = location_bar->location_entry(); |
| 211 location_bar->FocusLocation(true); | 212 location_bar->FocusLocation(true); |
| 212 omnibox_view->SetUserText( | 213 omnibox_view->SetUserText( |
| 213 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); | 214 l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); |
| 214 omnibox_view->SelectAll(false); | 215 omnibox_view->SelectAll(false); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 227 } | 228 } |
| 228 | 229 |
| 229 // static | 230 // static |
| 230 bool OmniboxSearchHint::IsEnabled(Profile* profile) { | 231 bool OmniboxSearchHint::IsEnabled(Profile* profile) { |
| 231 // The infobar can only be shown if the correct switch has been provided and | 232 // The infobar can only be shown if the correct switch has been provided and |
| 232 // the user did not dismiss the infobar before. | 233 // the user did not dismiss the infobar before. |
| 233 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && | 234 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && |
| 234 CommandLine::ForCurrentProcess()->HasSwitch( | 235 CommandLine::ForCurrentProcess()->HasSwitch( |
| 235 switches::kSearchInOmniboxHint); | 236 switches::kSearchInOmniboxHint); |
| 236 } | 237 } |
| OLD | NEW |