| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // URL should not be used because it is blocked for a supervised user. | 78 // URL should not be used because it is blocked for a supervised user. |
| 79 NEW_TAB_URL_BLOCKED = 6, | 79 NEW_TAB_URL_BLOCKED = 6, |
| 80 | 80 |
| 81 NEW_TAB_URL_MAX | 81 NEW_TAB_URL_MAX |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 base::Feature kUseGoogleLocalNtp { | 84 base::Feature kUseGoogleLocalNtp { |
| 85 "UseGoogleLocalNtp", base::FEATURE_DISABLED_BY_DEFAULT | 85 "UseGoogleLocalNtp", base::FEATURE_DISABLED_BY_DEFAULT |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) { | 88 const TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) { |
| 89 if (profile) { | 89 if (profile) { |
| 90 TemplateURLService* template_url_service = | 90 TemplateURLService* template_url_service = |
| 91 TemplateURLServiceFactory::GetForProfile(profile); | 91 TemplateURLServiceFactory::GetForProfile(profile); |
| 92 if (template_url_service) | 92 if (template_url_service) |
| 93 return template_url_service->GetDefaultSearchProvider(); | 93 return template_url_service->GetDefaultSearchProvider(); |
| 94 } | 94 } |
| 95 return NULL; | 95 return NULL; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool DefaultSearchProviderIsGoogle(Profile* profile) { | 98 bool DefaultSearchProviderIsGoogle(Profile* profile) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (!IsInstantExtendedAPIEnabled()) | 134 if (!IsInstantExtendedAPIEnabled()) |
| 135 return false; | 135 return false; |
| 136 | 136 |
| 137 if (!url.is_valid()) | 137 if (!url.is_valid()) |
| 138 return false; | 138 return false; |
| 139 | 139 |
| 140 const GURL new_tab_url(GetNewTabPageURL(profile)); | 140 const GURL new_tab_url(GetNewTabPageURL(profile)); |
| 141 if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url)) | 141 if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url)) |
| 142 return true; | 142 return true; |
| 143 | 143 |
| 144 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 144 const TemplateURL* template_url = |
| 145 GetDefaultSearchProviderTemplateURL(profile); |
| 145 if (!template_url) | 146 if (!template_url) |
| 146 return false; | 147 return false; |
| 147 | 148 |
| 148 if (!IsSuitableURLForInstant(url, template_url)) | 149 if (!IsSuitableURLForInstant(url, template_url)) |
| 149 return false; | 150 return false; |
| 150 | 151 |
| 151 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); | 152 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); |
| 152 UIThreadSearchTermsData search_terms_data(profile); | 153 UIThreadSearchTermsData search_terms_data(profile); |
| 153 const GURL instant_url = TemplateURLRefToGURL( | 154 const GURL instant_url = TemplateURLRefToGURL( |
| 154 instant_url_ref, search_terms_data, false, false); | 155 instant_url_ref, search_terms_data, false, false); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 NewTabURLDetails(const GURL& url, NewTabURLState state) | 212 NewTabURLDetails(const GURL& url, NewTabURLState state) |
| 212 : url(url), state(state) {} | 213 : url(url), state(state) {} |
| 213 | 214 |
| 214 static NewTabURLDetails ForProfile(Profile* profile) { | 215 static NewTabURLDetails ForProfile(Profile* profile) { |
| 215 const GURL local_url(chrome::kChromeSearchLocalNtpUrl); | 216 const GURL local_url(chrome::kChromeSearchLocalNtpUrl); |
| 216 | 217 |
| 217 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 218 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 218 if (command_line->HasSwitch(switches::kForceLocalNtp)) | 219 if (command_line->HasSwitch(switches::kForceLocalNtp)) |
| 219 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID); | 220 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID); |
| 220 | 221 |
| 221 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 222 const TemplateURL* template_url = |
| 223 GetDefaultSearchProviderTemplateURL(profile); |
| 222 if (!profile || !template_url) | 224 if (!profile || !template_url) |
| 223 return NewTabURLDetails(local_url, NEW_TAB_URL_BAD); | 225 return NewTabURLDetails(local_url, NEW_TAB_URL_BAD); |
| 224 | 226 |
| 225 GURL search_provider_url = TemplateURLRefToGURL( | 227 GURL search_provider_url = TemplateURLRefToGURL( |
| 226 template_url->new_tab_url_ref(), UIThreadSearchTermsData(profile), | 228 template_url->new_tab_url_ref(), UIThreadSearchTermsData(profile), |
| 227 false, false); | 229 false, false); |
| 228 | 230 |
| 229 if (ShouldShowLocalNewTab(search_provider_url, profile)) | 231 if (ShouldShowLocalNewTab(search_provider_url, profile)) |
| 230 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID); | 232 return NewTabURLDetails(local_url, NEW_TAB_URL_VALID); |
| 231 | 233 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 254 // InstantSearchPrerenderer has the search query for the Instant search base | 256 // InstantSearchPrerenderer has the search query for the Instant search base |
| 255 // page. | 257 // page. |
| 256 InstantSearchPrerenderer* prerenderer = | 258 InstantSearchPrerenderer* prerenderer = |
| 257 InstantSearchPrerenderer::GetForProfile(profile); | 259 InstantSearchPrerenderer::GetForProfile(profile); |
| 258 // TODO(kmadhusu): Remove this CHECK after the investigation of | 260 // TODO(kmadhusu): Remove this CHECK after the investigation of |
| 259 // crbug.com/367204. | 261 // crbug.com/367204. |
| 260 CHECK(prerenderer); | 262 CHECK(prerenderer); |
| 261 return prerenderer->get_last_query(); | 263 return prerenderer->get_last_query(); |
| 262 } | 264 } |
| 263 | 265 |
| 264 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 266 const TemplateURL* template_url = |
| 267 GetDefaultSearchProviderTemplateURL(profile); |
| 265 base::string16 search_terms; | 268 base::string16 search_terms; |
| 266 if (template_url) | 269 if (template_url) |
| 267 template_url->ExtractSearchTermsFromURL( | 270 template_url->ExtractSearchTermsFromURL( |
| 268 url, UIThreadSearchTermsData(profile), &search_terms); | 271 url, UIThreadSearchTermsData(profile), &search_terms); |
| 269 return search_terms; | 272 return search_terms; |
| 270 } | 273 } |
| 271 | 274 |
| 272 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { | 275 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { |
| 273 return url.is_valid() && | 276 return url.is_valid() && |
| 274 profile && | 277 profile && |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 346 |
| 344 bool IsSuggestPrefEnabled(Profile* profile) { | 347 bool IsSuggestPrefEnabled(Profile* profile) { |
| 345 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && | 348 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && |
| 346 profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); | 349 profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); |
| 347 } | 350 } |
| 348 | 351 |
| 349 GURL GetInstantURL(Profile* profile, bool force_instant_results) { | 352 GURL GetInstantURL(Profile* profile, bool force_instant_results) { |
| 350 if (!IsInstantExtendedAPIEnabled() || !IsSuggestPrefEnabled(profile)) | 353 if (!IsInstantExtendedAPIEnabled() || !IsSuggestPrefEnabled(profile)) |
| 351 return GURL(); | 354 return GURL(); |
| 352 | 355 |
| 353 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 356 const TemplateURL* template_url = |
| 357 GetDefaultSearchProviderTemplateURL(profile); |
| 354 if (!template_url) | 358 if (!template_url) |
| 355 return GURL(); | 359 return GURL(); |
| 356 | 360 |
| 357 GURL instant_url = TemplateURLRefToGURL( | 361 GURL instant_url = TemplateURLRefToGURL( |
| 358 template_url->instant_url_ref(), UIThreadSearchTermsData(profile), | 362 template_url->instant_url_ref(), UIThreadSearchTermsData(profile), |
| 359 true, force_instant_results); | 363 true, force_instant_results); |
| 360 if (!instant_url.is_valid() || | 364 if (!instant_url.is_valid() || |
| 361 !template_url->HasSearchTermsReplacementKey(instant_url)) | 365 !template_url->HasSearchTermsReplacementKey(instant_url)) |
| 362 return GURL(); | 366 return GURL(); |
| 363 | 367 |
| 364 // Extended mode requires HTTPS. Force it unless the base URL was overridden | 368 // Extended mode requires HTTPS. Force it unless the base URL was overridden |
| 365 // on the command line, in which case we allow HTTP (see comments on | 369 // on the command line, in which case we allow HTTP (see comments on |
| 366 // IsSuitableURLForInstant()). | 370 // IsSuitableURLForInstant()). |
| 367 if (!instant_url.SchemeIsCryptographic() && | 371 if (!instant_url.SchemeIsCryptographic() && |
| 368 !google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) { | 372 !google_util::StartsWithCommandLineGoogleBaseURL(instant_url)) { |
| 369 GURL::Replacements replacements; | 373 GURL::Replacements replacements; |
| 370 replacements.SetSchemeStr(url::kHttpsScheme); | 374 replacements.SetSchemeStr(url::kHttpsScheme); |
| 371 instant_url = instant_url.ReplaceComponents(replacements); | 375 instant_url = instant_url.ReplaceComponents(replacements); |
| 372 } | 376 } |
| 373 | 377 |
| 374 if (!IsURLAllowedForSupervisedUser(instant_url, profile)) | 378 if (!IsURLAllowedForSupervisedUser(instant_url, profile)) |
| 375 return GURL(); | 379 return GURL(); |
| 376 | 380 |
| 377 return instant_url; | 381 return instant_url; |
| 378 } | 382 } |
| 379 | 383 |
| 380 // Returns URLs associated with the default search engine for |profile|. | 384 // Returns URLs associated with the default search engine for |profile|. |
| 381 std::vector<GURL> GetSearchURLs(Profile* profile) { | 385 std::vector<GURL> GetSearchURLs(Profile* profile) { |
| 382 std::vector<GURL> result; | 386 std::vector<GURL> result; |
| 383 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 387 const TemplateURL* template_url = |
| 388 GetDefaultSearchProviderTemplateURL(profile); |
| 384 if (!template_url) | 389 if (!template_url) |
| 385 return result; | 390 return result; |
| 386 for (const TemplateURLRef& ref : template_url->url_refs()) { | 391 for (const TemplateURLRef& ref : template_url->url_refs()) { |
| 387 result.push_back(TemplateURLRefToGURL(ref, UIThreadSearchTermsData(profile), | 392 result.push_back(TemplateURLRefToGURL(ref, UIThreadSearchTermsData(profile), |
| 388 false, false)); | 393 false, false)); |
| 389 } | 394 } |
| 390 return result; | 395 return result; |
| 391 } | 396 } |
| 392 | 397 |
| 393 GURL GetNewTabPageURL(Profile* profile) { | 398 GURL GetNewTabPageURL(Profile* profile) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 463 |
| 459 if (IsInstantNTPURL(*url, profile)) { | 464 if (IsInstantNTPURL(*url, profile)) { |
| 460 *url = GURL(chrome::kChromeUINewTabURL); | 465 *url = GURL(chrome::kChromeUINewTabURL); |
| 461 return true; | 466 return true; |
| 462 } | 467 } |
| 463 | 468 |
| 464 return false; | 469 return false; |
| 465 } | 470 } |
| 466 | 471 |
| 467 } // namespace search | 472 } // namespace search |
| OLD | NEW |