OLD | NEW |
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 const SearchTermsData& search_terms_data, | 113 const SearchTermsData& search_terms_data, |
114 bool append_extra_query_params, | 114 bool append_extra_query_params, |
115 bool force_instant_results) { | 115 bool force_instant_results) { |
116 TemplateURLRef::SearchTermsArgs search_terms_args = | 116 TemplateURLRef::SearchTermsArgs search_terms_args = |
117 TemplateURLRef::SearchTermsArgs(base::string16()); | 117 TemplateURLRef::SearchTermsArgs(base::string16()); |
118 search_terms_args.append_extra_query_params = append_extra_query_params; | 118 search_terms_args.append_extra_query_params = append_extra_query_params; |
119 search_terms_args.force_instant_results = force_instant_results; | 119 search_terms_args.force_instant_results = force_instant_results; |
120 return GURL(ref.ReplaceSearchTerms(search_terms_args, search_terms_data)); | 120 return GURL(ref.ReplaceSearchTerms(search_terms_args, search_terms_data)); |
121 } | 121 } |
122 | 122 |
| 123 // |url| should either have a secure scheme or have a non-HTTPS base URL that |
| 124 // the user specified using --google-base-url. (This allows testers to use |
| 125 // --google-base-url to point at non-HTTPS servers, which eases testing.) |
| 126 bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) { |
| 127 return template_url->HasSearchTermsReplacementKey(url) && |
| 128 (url.SchemeIsCryptographic() || |
| 129 google_util::StartsWithCommandLineGoogleBaseURL(url)); |
| 130 } |
| 131 |
123 // Returns true if |url| can be used as an Instant URL for |profile|. | 132 // Returns true if |url| can be used as an Instant URL for |profile|. |
124 bool IsInstantURL(const GURL& url, Profile* profile) { | 133 bool IsInstantURL(const GURL& url, Profile* profile) { |
125 if (!IsInstantExtendedAPIEnabled()) | 134 if (!IsInstantExtendedAPIEnabled()) |
126 return false; | 135 return false; |
127 | 136 |
128 if (!url.is_valid()) | 137 if (!url.is_valid()) |
129 return false; | 138 return false; |
130 | 139 |
131 const GURL new_tab_url(GetNewTabPageURL(profile)); | 140 const GURL new_tab_url(GetNewTabPageURL(profile)); |
132 if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url)) | 141 if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url)) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 263 } |
255 | 264 |
256 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 265 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); |
257 base::string16 search_terms; | 266 base::string16 search_terms; |
258 if (template_url) | 267 if (template_url) |
259 template_url->ExtractSearchTermsFromURL( | 268 template_url->ExtractSearchTermsFromURL( |
260 url, UIThreadSearchTermsData(profile), &search_terms); | 269 url, UIThreadSearchTermsData(profile), &search_terms); |
261 return search_terms; | 270 return search_terms; |
262 } | 271 } |
263 | 272 |
264 bool IsQueryExtractionAllowedForURL(Profile* profile, const GURL& url) { | |
265 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | |
266 return template_url && IsSuitableURLForInstant(url, template_url); | |
267 } | |
268 | |
269 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { | 273 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { |
270 return url.is_valid() && | 274 return url.is_valid() && |
271 profile && | 275 profile && |
272 IsInstantExtendedAPIEnabled() && | 276 IsInstantExtendedAPIEnabled() && |
273 (url.SchemeIs(chrome::kChromeSearchScheme) || | 277 (url.SchemeIs(chrome::kChromeSearchScheme) || |
274 IsInstantURL(url, profile)); | 278 IsInstantURL(url, profile)); |
275 } | 279 } |
276 | 280 |
277 bool IsRenderedInInstantProcess(const content::WebContents* contents, | 281 bool IsRenderedInInstantProcess(const content::WebContents* contents, |
278 Profile* profile) { | 282 Profile* profile) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 false, false)); | 389 false, false)); |
386 } | 390 } |
387 return result; | 391 return result; |
388 } | 392 } |
389 | 393 |
390 GURL GetNewTabPageURL(Profile* profile) { | 394 GURL GetNewTabPageURL(Profile* profile) { |
391 return NewTabURLDetails::ForProfile(profile).url; | 395 return NewTabURLDetails::ForProfile(profile).url; |
392 } | 396 } |
393 | 397 |
394 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { | 398 GURL GetSearchResultPrefetchBaseURL(Profile* profile) { |
395 return ShouldPrefetchSearchResults() ? GetInstantURL(profile, true) : GURL(); | 399 return GetInstantURL(profile, true); |
396 } | 400 } |
397 | 401 |
398 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { | 402 GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { |
399 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) | 403 CHECK(ShouldAssignURLToInstantRenderer(url, profile)) |
400 << "Error granting Instant access."; | 404 << "Error granting Instant access."; |
401 | 405 |
402 if (url.SchemeIs(chrome::kChromeSearchScheme)) | 406 if (url.SchemeIs(chrome::kChromeSearchScheme)) |
403 return url; | 407 return url; |
404 | 408 |
405 // Replace the scheme with "chrome-search:", and clear the port, since | 409 // Replace the scheme with "chrome-search:", and clear the port, since |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 459 |
456 if (IsInstantNTPURL(*url, profile)) { | 460 if (IsInstantNTPURL(*url, profile)) { |
457 *url = GURL(chrome::kChromeUINewTabURL); | 461 *url = GURL(chrome::kChromeUINewTabURL); |
458 return true; | 462 return true; |
459 } | 463 } |
460 | 464 |
461 return false; | 465 return false; |
462 } | 466 } |
463 | 467 |
464 } // namespace search | 468 } // namespace search |
OLD | NEW |