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

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

Issue 2211983002: Remove search::IsQueryExtractionEnabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_prefetch_non_default
Patch Set: remove more tests 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/search/search.h" 5 #include "chrome/browser/search/search.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const SearchTermsData& search_terms_data, 147 const SearchTermsData& search_terms_data,
148 bool append_extra_query_params, 148 bool append_extra_query_params,
149 bool force_instant_results) { 149 bool force_instant_results) {
150 TemplateURLRef::SearchTermsArgs search_terms_args = 150 TemplateURLRef::SearchTermsArgs search_terms_args =
151 TemplateURLRef::SearchTermsArgs(base::string16()); 151 TemplateURLRef::SearchTermsArgs(base::string16());
152 search_terms_args.append_extra_query_params = append_extra_query_params; 152 search_terms_args.append_extra_query_params = append_extra_query_params;
153 search_terms_args.force_instant_results = force_instant_results; 153 search_terms_args.force_instant_results = force_instant_results;
154 return GURL(ref.ReplaceSearchTerms(search_terms_args, search_terms_data)); 154 return GURL(ref.ReplaceSearchTerms(search_terms_args, search_terms_data));
155 } 155 }
156 156
157 bool MatchesAnySearchURL(const GURL& url,
158 TemplateURL* template_url,
159 const SearchTermsData& search_terms_data) {
160 for (const TemplateURLRef& ref : template_url->url_refs()) {
161 GURL search_url =
162 TemplateURLRefToGURL(ref, search_terms_data, false, false);
163 if (search_url.is_valid() && MatchesOriginAndPath(url, search_url))
164 return true;
165 }
166 return false;
167 }
168
169 // Returns true if |url| can be used as an Instant URL for |profile|. 157 // Returns true if |url| can be used as an Instant URL for |profile|.
170 bool IsInstantURL(const GURL& url, Profile* profile) { 158 bool IsInstantURL(const GURL& url, Profile* profile) {
171 if (!IsInstantExtendedAPIEnabled()) 159 if (!IsInstantExtendedAPIEnabled())
172 return false; 160 return false;
173 161
174 if (!url.is_valid()) 162 if (!url.is_valid())
175 return false; 163 return false;
176 164
177 const GURL new_tab_url(GetNewTabPageURL(profile)); 165 const GURL new_tab_url(GetNewTabPageURL(profile));
178 if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url)) 166 if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url))
179 return true; 167 return true;
180 168
181 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); 169 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
182 if (!template_url) 170 if (!template_url)
183 return false; 171 return false;
184 172
185 if (!IsSuitableURLForInstant(url, template_url)) 173 if (!IsSuitableURLForInstant(url, template_url))
186 return false; 174 return false;
187 175
188 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); 176 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
189 UIThreadSearchTermsData search_terms_data(profile); 177 UIThreadSearchTermsData search_terms_data(profile);
190 const GURL instant_url = TemplateURLRefToGURL( 178 const GURL instant_url = TemplateURLRefToGURL(
191 instant_url_ref, search_terms_data, false, false); 179 instant_url_ref, search_terms_data, false, false);
192 if (!instant_url.is_valid()) 180 if (!instant_url.is_valid())
193 return false; 181 return false;
194 182
195 if (MatchesOriginAndPath(url, instant_url)) 183 return MatchesOriginAndPath(url, instant_url);
196 return true;
197
198 return IsQueryExtractionEnabled() &&
199 MatchesAnySearchURL(url, template_url, search_terms_data);
200 } 184 }
201 185
202 base::string16 GetSearchTermsImpl(const content::WebContents* contents, 186 base::string16 GetSearchTermsImpl(const content::WebContents* contents,
203 const content::NavigationEntry* entry) { 187 const content::NavigationEntry* entry) {
204 if (!contents || !IsQueryExtractionEnabled()) 188 // TODO(treib): Remove this and update callers accordingly. crbug.com/627747
205 return base::string16(); 189 return base::string16();
206
207 // For security reasons, don't extract search terms if the page is not being
208 // rendered in the privileged Instant renderer process. This is to protect
209 // against a malicious page somehow scripting the search results page and
210 // faking search terms in the URL. Random pages can't get into the Instant
211 // renderer and scripting doesn't work cross-process, so if the page is in
212 // the Instant process, we know it isn't being exploited.
213 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
214 if (IsInstantExtendedAPIEnabled() &&
215 !IsRenderedInInstantProcess(contents, profile) &&
216 ((entry == contents->GetController().GetLastCommittedEntry()) ||
217 !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile)))
218 return base::string16();
219
220 // Check to see if search terms have already been extracted.
221 base::string16 search_terms = GetSearchTermsFromNavigationEntry(entry);
222 if (!search_terms.empty())
223 return search_terms;
224
225 if (!IsQueryExtractionAllowedForURL(profile, entry->GetVirtualURL()))
226 return base::string16();
227
228 // Otherwise, extract from the URL.
229 return ExtractSearchTermsFromURL(profile, entry->GetVirtualURL());
230 } 190 }
231 191
232 bool IsURLAllowedForSupervisedUser(const GURL& url, Profile* profile) { 192 bool IsURLAllowedForSupervisedUser(const GURL& url, Profile* profile) {
233 #if defined(ENABLE_SUPERVISED_USERS) 193 #if defined(ENABLE_SUPERVISED_USERS)
234 SupervisedUserService* supervised_user_service = 194 SupervisedUserService* supervised_user_service =
235 SupervisedUserServiceFactory::GetForProfile(profile); 195 SupervisedUserServiceFactory::GetForProfile(profile);
236 SupervisedUserURLFilter* url_filter = 196 SupervisedUserURLFilter* url_filter =
237 supervised_user_service->GetURLFilterForUIThread(); 197 supervised_user_service->GetURLFilterForUIThread();
238 if (url_filter->GetFilteringBehaviorForURL(url) == 198 if (url_filter->GetFilteringBehaviorForURL(url) ==
239 SupervisedUserURLFilter::BLOCK) { 199 SupervisedUserURLFilter::BLOCK) {
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 kUseAltInstantURL, false, flags); 564 kUseAltInstantURL, false, flags);
605 } 565 }
606 566
607 bool ShouldUseSearchPathForInstant() { 567 bool ShouldUseSearchPathForInstant() {
608 FieldTrialFlags flags; 568 FieldTrialFlags flags;
609 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault( 569 return GetFieldTrialInfo(&flags) && GetBoolValueForFlagWithDefault(
610 kUseSearchPathForInstant, false, flags); 570 kUseSearchPathForInstant, false, flags);
611 } 571 }
612 572
613 } // namespace search 573 } // namespace search
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698