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/search/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/google/google_util.h" | 7 #include "chrome/browser/google/google_util.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/search_engines/template_url.h" |
| 10 #include "chrome/browser/search_engines/template_url_service.h" |
| 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
9 #include "chrome/browser/ui/search/search.h" | 12 #include "chrome/browser/ui/search/search.h" |
10 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
11 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/navigation_details.h" | 15 #include "content/public/browser/navigation_details.h" |
13 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
16 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
17 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
18 | 21 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 NOTREACHED() << "Unexpected notification type."; | 155 NOTREACHED() << "Unexpected notification type."; |
153 } | 156 } |
154 } | 157 } |
155 | 158 |
156 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, | 159 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, |
157 NTPLoadState load_state, | 160 NTPLoadState load_state, |
158 bool animate) { | 161 bool animate) { |
159 Mode::Type type = Mode::MODE_DEFAULT; | 162 Mode::Type type = Mode::MODE_DEFAULT; |
160 if (IsNTP(url)) | 163 if (IsNTP(url)) |
161 type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING; | 164 type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING; |
162 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) | 165 else if (CanExtractSearchTerms(url)) |
163 type = Mode::MODE_SEARCH_RESULTS; | 166 type = Mode::MODE_SEARCH_RESULTS; |
164 model_.SetMode(Mode(type, animate)); | 167 model_.SetMode(Mode(type, animate)); |
165 } | 168 } |
166 | 169 |
| 170 bool SearchTabHelper::CanExtractSearchTerms(const GURL& url) { |
| 171 Profile* profile = |
| 172 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 173 |
| 174 // Ensure instant extended API is enabled. |
| 175 if (!profile || !chrome::search::IsInstantExtendedAPIEnabled(profile)) |
| 176 return false; |
| 177 |
| 178 TemplateURLService* template_url_service = |
| 179 TemplateURLServiceFactory::GetForProfile(profile); |
| 180 |
| 181 if (!template_url_service) |
| 182 return false; |
| 183 |
| 184 TemplateURL *template_url = template_url_service->GetDefaultSearchProvider(); |
| 185 if (!template_url) |
| 186 return false; |
| 187 |
| 188 string16 dummy; |
| 189 return template_url->ExtractSearchTermsFromInstantExtendedURL(url, &dummy); |
| 190 } |
| 191 |
167 const content::WebContents* SearchTabHelper::web_contents() const { | 192 const content::WebContents* SearchTabHelper::web_contents() const { |
168 return model_.web_contents(); | 193 return model_.web_contents(); |
169 } | 194 } |
170 | 195 |
171 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() { | 196 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() { |
172 content::RenderWidgetHostView* rwhv = | 197 content::RenderWidgetHostView* rwhv = |
173 web_contents()->GetRenderWidgetHostView(); | 198 web_contents()->GetRenderWidgetHostView(); |
174 return rwhv ? rwhv->GetRenderWidgetHost() : NULL; | 199 return rwhv ? rwhv->GetRenderWidgetHost() : NULL; |
175 } | 200 } |
176 | 201 |
177 } // namespace search | 202 } // namespace search |
178 } // namespace chrome | 203 } // namespace chrome |
OLD | NEW |