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

Side by Side Diff: chrome/browser/ui/search/instant_search_prerenderer.cc

Issue 2211533004: Remove SearchTabHelper::IsSearchResultsPage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/instant_search_prerenderer.h" 5 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "chrome/browser/prerender/prerender_handle.h" 9 #include "chrome/browser/prerender/prerender_handle.h"
10 #include "chrome/browser/prerender/prerender_manager.h" 10 #include "chrome/browser/prerender/prerender_manager.h"
11 #include "chrome/browser/prerender/prerender_manager_factory.h" 11 #include "chrome/browser/prerender/prerender_manager_factory.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search/instant_service.h" 13 #include "chrome/browser/search/instant_service.h"
14 #include "chrome/browser/search/instant_service_factory.h" 14 #include "chrome/browser/search/instant_service_factory.h"
15 #include "chrome/browser/search/search.h" 15 #include "chrome/browser/search/search.h"
16 #include "chrome/browser/search_engines/template_url_service_factory.h" 16 #include "chrome/browser/search_engines/template_url_service_factory.h"
17 #include "chrome/browser/ui/browser_navigator_params.h" 17 #include "chrome/browser/ui/browser_navigator_params.h"
18 #include "chrome/browser/ui/search/search_tab_helper.h" 18 #include "chrome/browser/ui/search/search_tab_helper.h"
19 #include "components/omnibox/browser/autocomplete_match.h" 19 #include "components/omnibox/browser/autocomplete_match.h"
20 #include "components/search/search.h" 20 #include "components/search/search.h"
21 #include "components/search_engines/template_url_service.h" 21 #include "components/search_engines/template_url_service.h"
22 22
23 namespace { 23 namespace {
24 24
25 // Returns true if the underlying page supports Instant search.
26 bool PageSupportsInstantSearch(content::WebContents* contents) {
27 // Search results page supports Instant search.
28 return SearchTabHelper::FromWebContents(contents)->IsSearchResultsPage();
29 }
30
31 // Returns true if |match| is associated with the default search provider. 25 // Returns true if |match| is associated with the default search provider.
32 bool MatchIsFromDefaultSearchProvider(const AutocompleteMatch& match, 26 bool MatchIsFromDefaultSearchProvider(const AutocompleteMatch& match,
33 Profile* profile) { 27 Profile* profile) {
34 DCHECK(profile); 28 DCHECK(profile);
35 TemplateURLService* template_url_service = 29 TemplateURLService* template_url_service =
36 TemplateURLServiceFactory::GetForProfile(profile); 30 TemplateURLServiceFactory::GetForProfile(profile);
37 return match.GetTemplateURL(template_url_service, false) == 31 return match.GetTemplateURL(template_url_service, false) ==
38 template_url_service->GetDefaultSearchProvider(); 32 template_url_service->GetDefaultSearchProvider();
39 } 33 }
40 34
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 113
120 bool InstantSearchPrerenderer::CanCommitQuery( 114 bool InstantSearchPrerenderer::CanCommitQuery(
121 content::WebContents* source, 115 content::WebContents* source,
122 const base::string16& query) const { 116 const base::string16& query) const {
123 if (!source || query.empty() || !prerender_handle_ || 117 if (!source || query.empty() || !prerender_handle_ ||
124 !prerender_handle_->IsFinishedLoading() || 118 !prerender_handle_->IsFinishedLoading() ||
125 !prerender_contents() || !QueryMatchesPrefetch(query)) { 119 !prerender_contents() || !QueryMatchesPrefetch(query)) {
126 return false; 120 return false;
127 } 121 }
128 122
129 // InstantSearchPrerenderer can commit query to the prerendered page only if 123 return true;
130 // the underlying |source| page doesn't support Instant search.
131 return !PageSupportsInstantSearch(source);
132 } 124 }
133 125
134 bool InstantSearchPrerenderer::UsePrerenderedPage( 126 bool InstantSearchPrerenderer::UsePrerenderedPage(
135 const GURL& url, 127 const GURL& url,
136 chrome::NavigateParams* params) { 128 chrome::NavigateParams* params) {
137 base::string16 search_terms = 129 base::string16 search_terms =
138 search::ExtractSearchTermsFromURL(profile_, url); 130 search::ExtractSearchTermsFromURL(profile_, url);
139 prerender::PrerenderManager* prerender_manager = 131 prerender::PrerenderManager* prerender_manager =
140 prerender::PrerenderManagerFactory::GetForProfile(profile_); 132 prerender::PrerenderManagerFactory::GetForProfile(profile_);
141 if (search_terms.empty() || !params->target_contents || 133 if (search_terms.empty() || !params->target_contents ||
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // there's no way to pass them to the prerendered page, and worse, if the URL 169 // there's no way to pass them to the prerendered page, and worse, if the URL
178 // does something like specifying params in both the query and ref sections of 170 // does something like specifying params in both the query and ref sections of
179 // the URL (as Google URLs often do), it can quickly become impossible to 171 // the URL (as Google URLs often do), it can quickly become impossible to
180 // figure out how to correctly tease out the right param names and values to 172 // figure out how to correctly tease out the right param names and values to
181 // send. Rather than try and write parsing code to deal with all these kinds 173 // send. Rather than try and write parsing code to deal with all these kinds
182 // of cases, for various different search engines, including accommodating 174 // of cases, for various different search engines, including accommodating
183 // changing behavior over time, we do the simple restriction described above. 175 // changing behavior over time, we do the simple restriction described above.
184 // This handles the by-far-the-most-common cases while still being simple and 176 // This handles the by-far-the-most-common cases while still being simple and
185 // maintainable. 177 // maintainable.
186 return source && AutocompleteMatch::IsSearchType(match.type) && 178 return source && AutocompleteMatch::IsSearchType(match.type) &&
187 MatchIsFromDefaultSearchProvider(match, profile_) && 179 MatchIsFromDefaultSearchProvider(match, profile_);
188 !PageSupportsInstantSearch(source);
189 } 180 }
190 181
191 content::WebContents* InstantSearchPrerenderer::prerender_contents() const { 182 content::WebContents* InstantSearchPrerenderer::prerender_contents() const {
192 return (prerender_handle_ && prerender_handle_->contents()) ? 183 return (prerender_handle_ && prerender_handle_->contents()) ?
193 prerender_handle_->contents()->prerender_contents() : NULL; 184 prerender_handle_->contents()->prerender_contents() : NULL;
194 } 185 }
195 186
196 bool InstantSearchPrerenderer::QueryMatchesPrefetch( 187 bool InstantSearchPrerenderer::QueryMatchesPrefetch(
197 const base::string16& query) const { 188 const base::string16& query) const {
198 return search::ShouldReuseInstantSearchBasePage() || 189 return search::ShouldReuseInstantSearchBasePage() ||
199 last_instant_suggestion_.text == query; 190 last_instant_suggestion_.text == query;
200 } 191 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698