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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months 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/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/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/search_engines/template_url.h" 17 #include "chrome/browser/search_engines/template_url.h"
18 #include "chrome/browser/search_engines/template_url_service.h" 18 #include "chrome/browser/search_engines/template_url_service.h"
19 #include "chrome/browser/search_engines/template_url_service_factory.h" 19 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 20 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
21 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/omnibox/location_bar.h" 23 #include "chrome/browser/ui/omnibox/location_bar.h"
24 #include "chrome/browser/ui/omnibox/omnibox_view.h" 24 #include "chrome/browser/ui/omnibox/omnibox_view.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
26 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "content/browser/tab_contents/navigation_details.h" 29 #include "content/browser/tab_contents/navigation_details.h"
29 #include "content/common/notification_details.h" 30 #include "content/common/notification_details.h"
30 #include "content/common/notification_source.h" 31 #include "content/common/notification_source.h"
31 #include "content/common/notification_type.h"
32 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
33 #include "grit/theme_resources_standard.h" 33 #include "grit/theme_resources_standard.h"
34 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
36 36
37 // The URLs of search engines for which we want to trigger the infobar. 37 // The URLs of search engines for which we want to trigger the infobar.
38 const char* kSearchEngineURLs[] = { 38 const char* kSearchEngineURLs[] = {
39 "http://www.google.com/", 39 "http://www.google.com/",
40 "http://www.yahoo.com/", 40 "http://www.yahoo.com/",
41 "http://www.bing.com/", 41 "http://www.bing.com/",
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 NotificationType::NAV_ENTRY_COMMITTED, 152 NotificationType::NAV_ENTRY_COMMITTED,
153 Source<NavigationController>(controller)); 153 Source<NavigationController>(controller));
154 // Fill the search_engine_urls_ map, used for faster look-up (overkill?). 154 // Fill the search_engine_urls_ map, used for faster look-up (overkill?).
155 for (size_t i = 0; 155 for (size_t i = 0;
156 i < sizeof(kSearchEngineURLs) / sizeof(kSearchEngineURLs[0]); ++i) { 156 i < sizeof(kSearchEngineURLs) / sizeof(kSearchEngineURLs[0]); ++i) {
157 search_engine_urls_[kSearchEngineURLs[i]] = 1; 157 search_engine_urls_[kSearchEngineURLs[i]] = 1;
158 } 158 }
159 159
160 // Listen for omnibox to figure-out when the user searches from the omnibox. 160 // Listen for omnibox to figure-out when the user searches from the omnibox.
161 notification_registrar_.Add(this, 161 notification_registrar_.Add(this,
162 NotificationType::OMNIBOX_OPENED_URL, 162 chrome::OMNIBOX_OPENED_URL,
163 Source<Profile>(tab->profile())); 163 Source<Profile>(tab->profile()));
164 } 164 }
165 165
166 OmniboxSearchHint::~OmniboxSearchHint() { 166 OmniboxSearchHint::~OmniboxSearchHint() {
167 } 167 }
168 168
169 void OmniboxSearchHint::Observe(NotificationType type, 169 void OmniboxSearchHint::Observe(NotificationType type,
170 const NotificationSource& source, 170 const NotificationSource& source,
171 const NotificationDetails& details) { 171 const NotificationDetails& details) {
172 if (type == NotificationType::NAV_ENTRY_COMMITTED) { 172 if (type == NotificationType::NAV_ENTRY_COMMITTED) {
173 NavigationEntry* entry = tab_->controller().GetActiveEntry(); 173 NavigationEntry* entry = tab_->controller().GetActiveEntry();
174 if (search_engine_urls_.find(entry->url().spec()) == 174 if (search_engine_urls_.find(entry->url().spec()) ==
175 search_engine_urls_.end()) { 175 search_engine_urls_.end()) {
176 // The search engine is not in our white-list, bail. 176 // The search engine is not in our white-list, bail.
177 return; 177 return;
178 } 178 }
179 const TemplateURL* const default_provider = 179 const TemplateURL* const default_provider =
180 TemplateURLServiceFactory::GetForProfile(tab_->profile())-> 180 TemplateURLServiceFactory::GetForProfile(tab_->profile())->
181 GetDefaultSearchProvider(); 181 GetDefaultSearchProvider();
182 if (!default_provider) 182 if (!default_provider)
183 return; 183 return;
184 184
185 const TemplateURLRef* const search_url = default_provider->url(); 185 const TemplateURLRef* const search_url = default_provider->url();
186 if (search_url->GetHost() == entry->url().host()) 186 if (search_url->GetHost() == entry->url().host())
187 ShowInfoBar(); 187 ShowInfoBar();
188 } else if (type == NotificationType::OMNIBOX_OPENED_URL) { 188 } else if (type == chrome::OMNIBOX_OPENED_URL) {
189 AutocompleteLog* log = Details<AutocompleteLog>(details).ptr(); 189 AutocompleteLog* log = Details<AutocompleteLog>(details).ptr();
190 AutocompleteMatch::Type type = 190 AutocompleteMatch::Type type =
191 log->result.match_at(log->selected_index).type; 191 log->result.match_at(log->selected_index).type;
192 if (type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || 192 if (type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED ||
193 type == AutocompleteMatch::SEARCH_HISTORY || 193 type == AutocompleteMatch::SEARCH_HISTORY ||
194 type == AutocompleteMatch::SEARCH_SUGGEST) { 194 type == AutocompleteMatch::SEARCH_SUGGEST) {
195 // The user performed a search from the omnibox, don't show the infobar 195 // The user performed a search from the omnibox, don't show the infobar
196 // again. 196 // again.
197 DisableHint(); 197 DisableHint();
198 } 198 }
(...skipping 27 matching lines...) Expand all
226 } 226 }
227 227
228 // static 228 // static
229 bool OmniboxSearchHint::IsEnabled(Profile* profile) { 229 bool OmniboxSearchHint::IsEnabled(Profile* profile) {
230 // The infobar can only be shown if the correct switch has been provided and 230 // The infobar can only be shown if the correct switch has been provided and
231 // the user did not dismiss the infobar before. 231 // the user did not dismiss the infobar before.
232 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) && 232 return profile->GetPrefs()->GetBoolean(prefs::kShowOmniboxSearchHint) &&
233 CommandLine::ForCurrentProcess()->HasSwitch( 233 CommandLine::ForCurrentProcess()->HasSwitch(
234 switches::kSearchInOmniboxHint); 234 switches::kSearchInOmniboxHint);
235 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698