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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/search/instant_service.h" | 14 #include "chrome/browser/search/instant_service.h" |
15 #include "chrome/browser/search/instant_service_factory.h" | 15 #include "chrome/browser/search/instant_service_factory.h" |
| 16 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
16 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
21 #include "components/user_prefs/pref_registry_syncable.h" | 22 #include "components/user_prefs/pref_registry_syncable.h" |
22 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
23 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
25 | 26 |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 329 |
329 bool NavEntryIsInstantNTP(const content::WebContents* contents, | 330 bool NavEntryIsInstantNTP(const content::WebContents* contents, |
330 const content::NavigationEntry* entry) { | 331 const content::NavigationEntry* entry) { |
331 if (!contents || !entry) | 332 if (!contents || !entry) |
332 return false; | 333 return false; |
333 | 334 |
334 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 335 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
335 return IsInstantExtendedAPIEnabled() && | 336 return IsInstantExtendedAPIEnabled() && |
336 IsRenderedInInstantProcess(contents, profile) && | 337 IsRenderedInInstantProcess(contents, profile) && |
337 (IsInstantURL(entry->GetVirtualURL(), profile) || | 338 (IsInstantURL(entry->GetVirtualURL(), profile) || |
338 entry->GetVirtualURL() == GURL(chrome::kChromeSearchLocalNtpUrl)) && | 339 entry->GetVirtualURL() == GetLocalInstantURL(profile)) && |
339 GetSearchTermsImpl(contents, entry).empty(); | 340 GetSearchTermsImpl(contents, entry).empty(); |
340 } | 341 } |
341 | 342 |
342 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { | 343 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { |
343 return url.is_valid() && | 344 return url.is_valid() && |
344 profile && | 345 profile && |
345 (url.SchemeIs(chrome::kChromeSearchScheme) || | 346 (url.SchemeIs(chrome::kChromeSearchScheme) || |
346 IsInstantURL(url, profile)); | 347 IsInstantURL(url, profile)); |
347 } | 348 } |
348 | 349 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 const std::string secure_scheme = chrome::kHttpsScheme; | 460 const std::string secure_scheme = chrome::kHttpsScheme; |
460 GURL::Replacements replacements; | 461 GURL::Replacements replacements; |
461 replacements.SetSchemeStr(secure_scheme); | 462 replacements.SetSchemeStr(secure_scheme); |
462 instant_url = instant_url.ReplaceComponents(replacements); | 463 instant_url = instant_url.ReplaceComponents(replacements); |
463 } | 464 } |
464 } | 465 } |
465 | 466 |
466 return instant_url; | 467 return instant_url; |
467 } | 468 } |
468 | 469 |
| 470 GURL GetLocalInstantURL(Profile* profile) { |
| 471 const TemplateURL* default_provider = |
| 472 TemplateURLServiceFactory::GetForProfile(profile)-> |
| 473 GetDefaultSearchProvider(); |
| 474 |
| 475 if (default_provider && |
| 476 (TemplateURLPrepopulateData::GetEngineType(default_provider->url()) == |
| 477 SEARCH_ENGINE_GOOGLE)) { |
| 478 return GURL(chrome::kChromeSearchLocalGoogleNtpUrl); |
| 479 } |
| 480 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 481 } |
| 482 |
469 bool IsInstantEnabled(Profile* profile) { | 483 bool IsInstantEnabled(Profile* profile) { |
470 return GetInstantURL(profile, kDisableStartMargin).is_valid(); | 484 return GetInstantURL(profile, kDisableStartMargin).is_valid(); |
471 } | 485 } |
472 | 486 |
473 bool IsAggressiveLocalNTPFallbackEnabled() { | 487 bool IsAggressiveLocalNTPFallbackEnabled() { |
474 // Check the command-line/about:flags setting first, which should have | 488 // Check the command-line/about:flags setting first, which should have |
475 // precedence and allows the trial to not be reported (if it's never queried). | 489 // precedence and allows the trial to not be reported (if it's never queried). |
476 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 490 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
477 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | 491 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || |
478 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | 492 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 replacements.SetHostStr(search_host); | 612 replacements.SetHostStr(search_host); |
599 replacements.SetPortStr(search_port); | 613 replacements.SetPortStr(search_port); |
600 return instant_url.ReplaceComponents(replacements); | 614 return instant_url.ReplaceComponents(replacements); |
601 } | 615 } |
602 | 616 |
603 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { | 617 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { |
604 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); | 618 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); |
605 } | 619 } |
606 | 620 |
607 } // namespace chrome | 621 } // namespace chrome |
OLD | NEW |