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/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_service.h" |
| 12 #include "chrome/browser/search_engines/template_url_service_factory.h" |
12 #include "chrome/browser/ssl/ssl_error_info.h" | 13 #include "chrome/browser/ssl/ssl_error_info.h" |
13 #include "chrome/browser/ui/search/search.h" | 14 #include "chrome/browser/ui/search/search.h" |
14 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" |
15 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
18 #include "content/public/browser/cert_store.h" | 19 #include "content/public/browser/cert_store.h" |
19 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
20 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 NavigationController* ToolbarModel::GetNavigationController() const { | 192 NavigationController* ToolbarModel::GetNavigationController() const { |
192 // This |current_tab| can be NULL during the initialization of the | 193 // This |current_tab| can be NULL during the initialization of the |
193 // toolbar during window creation (i.e. before any tabs have been added | 194 // toolbar during window creation (i.e. before any tabs have been added |
194 // to the window). | 195 // to the window). |
195 WebContents* current_tab = delegate_->GetActiveWebContents(); | 196 WebContents* current_tab = delegate_->GetActiveWebContents(); |
196 return current_tab ? ¤t_tab->GetController() : NULL; | 197 return current_tab ? ¤t_tab->GetController() : NULL; |
197 } | 198 } |
198 | 199 |
199 string16 ToolbarModel::TryToExtractSearchTermsFromURL(const GURL& url) const { | 200 string16 ToolbarModel::TryToExtractSearchTermsFromURL(const GURL& url) const { |
200 Profile* profile = GetProfile(); | 201 Profile* profile = GetProfile(); |
201 if (profile && | 202 |
202 chrome::search::IsInstantExtendedAPIEnabled(profile) && | 203 if (!profile || !chrome::search::IsInstantExtendedAPIEnabled(profile)) |
203 google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) { | 204 return string16(); |
204 // TODO(dominich): http://crbug.com/135106 - Replace this with whatever the | 205 |
205 // final solution is as per http://crbug.com/139176. | 206 TemplateURLService* template_url_service = |
206 return google_util::GetSearchTermsFromGoogleSearchURL(url.spec()); | 207 TemplateURLServiceFactory::GetForProfile(profile); |
207 } | 208 |
208 return string16(); | 209 if (!template_url_service) |
| 210 return string16(); |
| 211 |
| 212 TemplateURL *template_url = template_url_service->GetDefaultSearchProvider(); |
| 213 if (!template_url) |
| 214 return string16(); |
| 215 |
| 216 return template_url->ExtractSearchTermsFromURL(url); |
209 } | 217 } |
210 | 218 |
211 Profile* ToolbarModel::GetProfile() const { | 219 Profile* ToolbarModel::GetProfile() const { |
212 NavigationController* navigation_controller = GetNavigationController(); | 220 NavigationController* navigation_controller = GetNavigationController(); |
213 return navigation_controller ? | 221 return navigation_controller ? |
214 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : | 222 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : |
215 NULL; | 223 NULL; |
216 } | 224 } |
OLD | NEW |