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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model.cc

Issue 10908226: Introduces a search term extraction mechanism working for arbitrary search providers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed need for espv=1 for search term extraction. Created 8 years, 2 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) 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/ui/toolbar/toolbar_model.h" 5 #include "chrome/browser/ui/toolbar/toolbar_model.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autocomplete/autocomplete_input.h" 8 #include "chrome/browser/autocomplete/autocomplete_input.h"
9 #include "chrome/browser/google/google_util.h"
10 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search_engines/template_url.h"
12 #include "chrome/browser/search_engines/template_url_service.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ssl/ssl_error_info.h" 14 #include "chrome/browser/ssl/ssl_error_info.h"
13 #include "chrome/browser/ui/search/search.h" 15 #include "chrome/browser/ui/search/search.h"
14 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" 16 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h"
15 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
17 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
18 #include "content/public/browser/cert_store.h" 20 #include "content/public/browser/cert_store.h"
19 #include "content/public/browser/navigation_controller.h" 21 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 NavigationController* ToolbarModel::GetNavigationController() const { 193 NavigationController* ToolbarModel::GetNavigationController() const {
192 // This |current_tab| can be NULL during the initialization of the 194 // This |current_tab| can be NULL during the initialization of the
193 // toolbar during window creation (i.e. before any tabs have been added 195 // toolbar during window creation (i.e. before any tabs have been added
194 // to the window). 196 // to the window).
195 WebContents* current_tab = delegate_->GetActiveWebContents(); 197 WebContents* current_tab = delegate_->GetActiveWebContents();
196 return current_tab ? &current_tab->GetController() : NULL; 198 return current_tab ? &current_tab->GetController() : NULL;
197 } 199 }
198 200
199 string16 ToolbarModel::TryToExtractSearchTermsFromURL(const GURL& url) const { 201 string16 ToolbarModel::TryToExtractSearchTermsFromURL(const GURL& url) const {
200 Profile* profile = GetProfile(); 202 Profile* profile = GetProfile();
201 if (profile && 203
202 chrome::search::IsInstantExtendedAPIEnabled(profile) && 204 string16 result;
Peter Kasting 2012/10/02 21:47:59 Nit: Declare this at the very bottom and return st
beaudoin 2012/10/03 22:46:52 Done.
203 google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) { 205
204 // TODO(dominich): http://crbug.com/135106 - Replace this with whatever the 206 // Ensure instant extended API is enabled.
205 // final solution is as per http://crbug.com/139176. 207 if (!profile || !chrome::search::IsInstantExtendedAPIEnabled(profile))
206 return google_util::GetSearchTermsFromGoogleSearchURL(url.spec()); 208 return result;
207 } 209
208 return string16(); 210 TemplateURLService* template_url_service =
211 TemplateURLServiceFactory::GetForProfile(profile);
212
213 if (!template_url_service)
Peter Kasting 2012/10/02 21:47:59 Can this ever be NULL?
beaudoin 2012/10/03 22:46:52 Upon checking, it is created if it does not alread
214 return result;
215
216 TemplateURL *template_url = template_url_service->GetDefaultSearchProvider();
217 if (!template_url)
218 return result;
219
220 template_url->ExtractSearchTermsFromURL(url, &result);
221 return result;
209 } 222 }
210 223
211 Profile* ToolbarModel::GetProfile() const { 224 Profile* ToolbarModel::GetProfile() const {
212 NavigationController* navigation_controller = GetNavigationController(); 225 NavigationController* navigation_controller = GetNavigationController();
213 return navigation_controller ? 226 return navigation_controller ?
214 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : 227 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) :
215 NULL; 228 NULL;
216 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698