Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chrome/browser/omnibox_search_hint.cc

Issue 8892011: Clean up TCW, make it solely a hub for 1:1 observer/helper objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/task.h" 10 #include "base/task.h"
11 // TODO(avi): remove when conversions not needed any more
12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autocomplete/autocomplete.h" 11 #include "chrome/browser/autocomplete/autocomplete.h"
14 #include "chrome/browser/autocomplete/autocomplete_edit.h" 12 #include "chrome/browser/autocomplete/autocomplete_edit.h"
15 #include "chrome/browser/autocomplete/autocomplete_match.h" 13 #include "chrome/browser/autocomplete/autocomplete_match.h"
16 #include "chrome/browser/infobars/infobar_tab_helper.h" 14 #include "chrome/browser/infobars/infobar_tab_helper.h"
17 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search_engines/template_url.h" 17 #include "chrome/browser/search_engines/template_url.h"
20 #include "chrome/browser/search_engines/template_url_service.h" 18 #include "chrome/browser/search_engines/template_url_service.h"
21 #include "chrome/browser/search_engines/template_url_service_factory.h" 19 #include "chrome/browser/search_engines/template_url_service_factory.h"
22 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 20 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
23 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/omnibox/location_bar.h" 23 #include "chrome/browser/ui/omnibox/location_bar.h"
26 #include "chrome/browser/ui/omnibox/omnibox_view.h" 24 #include "chrome/browser/ui/omnibox/omnibox_view.h"
27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
28 #include "chrome/common/chrome_notification_types.h" 26 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
31 #include "content/browser/tab_contents/navigation_details.h" 29 #include "content/browser/tab_contents/navigation_details.h"
30 #include "content/browser/tab_contents/tab_contents.h"
32 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
33 #include "content/public/browser/notification_source.h" 32 #include "content/public/browser/notification_source.h"
34 #include "content/public/browser/notification_types.h" 33 #include "content/public/browser/notification_types.h"
35 #include "grit/generated_resources.h" 34 #include "grit/generated_resources.h"
36 #include "grit/theme_resources_standard.h" 35 #include "grit/theme_resources_standard.h"
37 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
39 38
40 // The URLs of search engines for which we want to trigger the infobar. 39 // The URLs of search engines for which we want to trigger the infobar.
41 const char* const kSearchEngineURLs[] = { 40 const char* const kSearchEngineURLs[] = {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.ShowMe", 1); 142 UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.ShowMe", 1);
144 omnibox_hint_->DisableHint(); 143 omnibox_hint_->DisableHint();
145 omnibox_hint_->ShowEnteringQuery(); 144 omnibox_hint_->ShowEnteringQuery();
146 return true; 145 return true;
147 } 146 }
148 147
149 148
150 // OmniboxSearchHint ---------------------------------------------------------- 149 // OmniboxSearchHint ----------------------------------------------------------
151 150
152 OmniboxSearchHint::OmniboxSearchHint(TabContentsWrapper* tab) : tab_(tab) { 151 OmniboxSearchHint::OmniboxSearchHint(TabContentsWrapper* tab) : tab_(tab) {
153 NavigationController* controller = &(tab->controller()); 152 NavigationController* controller = &(tab->tab_contents()->controller());
154 notification_registrar_.Add( 153 notification_registrar_.Add(
155 this, 154 this,
156 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 155 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
157 content::Source<NavigationController>(controller)); 156 content::Source<NavigationController>(controller));
158 // Fill the search_engine_urls_ map, used for faster look-up (overkill?). 157 // Fill the search_engine_urls_ map, used for faster look-up (overkill?).
159 for (size_t i = 0; i < arraysize(kSearchEngineURLs); ++i) 158 for (size_t i = 0; i < arraysize(kSearchEngineURLs); ++i)
160 search_engine_urls_[kSearchEngineURLs[i]] = 1; 159 search_engine_urls_[kSearchEngineURLs[i]] = 1;
161 160
162 // Listen for omnibox to figure-out when the user searches from the omnibox. 161 // Listen for omnibox to figure-out when the user searches from the omnibox.
163 notification_registrar_.Add(this, 162 notification_registrar_.Add(this,
164 chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 163 chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
165 content::Source<Profile>(tab->profile())); 164 content::Source<Profile>(tab->profile()));
166 } 165 }
167 166
168 OmniboxSearchHint::~OmniboxSearchHint() { 167 OmniboxSearchHint::~OmniboxSearchHint() {
169 } 168 }
170 169
171 void OmniboxSearchHint::Observe(int type, 170 void OmniboxSearchHint::Observe(int type,
172 const content::NotificationSource& source, 171 const content::NotificationSource& source,
173 const content::NotificationDetails& details) { 172 const content::NotificationDetails& details) {
174 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 173 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
175 NavigationEntry* entry = tab_->controller().GetActiveEntry(); 174 NavigationEntry* entry =
175 tab_->tab_contents()->controller().GetActiveEntry();
176 if (search_engine_urls_.find(entry->url().spec()) == 176 if (search_engine_urls_.find(entry->url().spec()) ==
177 search_engine_urls_.end()) { 177 search_engine_urls_.end()) {
178 // The search engine is not in our white-list, bail. 178 // The search engine is not in our white-list, bail.
179 return; 179 return;
180 } 180 }
181 const TemplateURL* const default_provider = 181 const TemplateURL* const default_provider =
182 TemplateURLServiceFactory::GetForProfile(tab_->profile())-> 182 TemplateURLServiceFactory::GetForProfile(tab_->profile())->
183 GetDefaultSearchProvider(); 183 GetDefaultSearchProvider();
184 if (!default_provider) 184 if (!default_provider)
185 return; 185 return;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 229
230 // static 230 // static
231 bool OmniboxSearchHint::IsEnabled(Profile* profile) { 231 bool OmniboxSearchHint::IsEnabled(Profile* profile) {
232 // 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
233 // the user did not dismiss the infobar before. 233 // the user did not dismiss the infobar before.
234 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && 234 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) &&
235 CommandLine::ForCurrentProcess()->HasSwitch( 235 CommandLine::ForCurrentProcess()->HasSwitch(
236 switches::kSearchInOmniboxHint); 236 switches::kSearchInOmniboxHint);
237 } 237 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_loader.cc ('k') | chrome/browser/password_manager_delegate_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698