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

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.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: Fixed keyword_table_unittest 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/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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 NOTREACHED() << "Unexpected notification type."; 159 NOTREACHED() << "Unexpected notification type.";
157 } 160 }
158 } 161 }
159 162
160 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url, 163 void SearchTabHelper::UpdateModelBasedOnURL(const GURL& url,
161 NTPLoadState load_state, 164 NTPLoadState load_state,
162 bool animate) { 165 bool animate) {
163 Mode::Type type = Mode::MODE_DEFAULT; 166 Mode::Type type = Mode::MODE_DEFAULT;
164 if (IsNTP(url)) 167 if (IsNTP(url))
165 type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING; 168 type = load_state == PAINTED ? Mode::MODE_NTP : Mode::MODE_NTP_LOADING;
166 else if (google_util::IsInstantExtendedAPIGoogleSearchUrl(url.spec())) 169 else if (CanExtractSearchTerms(url))
dhollowa 2012/09/28 18:06:29 Instant extended is not equivalent to search term
beaudoin 2012/10/02 17:43:29 QQ: Should I check for espv=1 for search term repl
dhollowa 2012/10/02 18:14:13 That's not quite true. I believe you're referring
167 type = Mode::MODE_SEARCH_RESULTS; 170 type = Mode::MODE_SEARCH_RESULTS;
168 model_.SetMode(Mode(type, animate)); 171 model_.SetMode(Mode(type, animate));
169 } 172 }
170 173
174 bool SearchTabHelper::CanExtractSearchTerms(const GURL& url) {
175 Profile* profile =
176 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
177
178 // Ensure instant extended API is enabled.
179 if (!profile || !chrome::search::IsInstantExtendedAPIEnabled(profile))
180 return false;
181
182 TemplateURLService* template_url_service =
183 TemplateURLServiceFactory::GetForProfile(profile);
184
185 if (!template_url_service)
186 return false;
187
188 TemplateURL *template_url = template_url_service->GetDefaultSearchProvider();
189 if (!template_url)
190 return false;
191
192 string16 dummy;
193 return template_url->ExtractSearchTermsFromInstantExtendedURL(url, &dummy);
194 }
195
171 const content::WebContents* SearchTabHelper::web_contents() const { 196 const content::WebContents* SearchTabHelper::web_contents() const {
172 return model_.web_contents(); 197 return model_.web_contents();
173 } 198 }
174 199
175 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() { 200 content::RenderWidgetHost* SearchTabHelper::GetRenderWidgetHost() {
176 content::RenderWidgetHostView* rwhv = 201 content::RenderWidgetHostView* rwhv =
177 web_contents()->GetRenderWidgetHostView(); 202 web_contents()->GetRenderWidgetHostView();
178 return rwhv ? rwhv->GetRenderWidgetHost() : NULL; 203 return rwhv ? rwhv->GetRenderWidgetHost() : NULL;
179 } 204 }
180 205
181 } // namespace search 206 } // namespace search
182 } // namespace chrome 207 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698