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() == GURL(chrome::kChromeSearchLocalNtpUrl) || |
| 340 entry->GetVirtualURL() == |
| 341 GURL(chrome::kChromeSearchLocalGoogleNtpUrl)) && |
339 GetSearchTermsImpl(contents, entry).empty(); | 342 GetSearchTermsImpl(contents, entry).empty(); |
340 } | 343 } |
341 | 344 |
342 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { | 345 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { |
343 return url.is_valid() && | 346 return url.is_valid() && |
344 profile && | 347 profile && |
345 (url.SchemeIs(chrome::kChromeSearchScheme) || | 348 (url.SchemeIs(chrome::kChromeSearchScheme) || |
346 IsInstantURL(url, profile)); | 349 IsInstantURL(url, profile)); |
347 } | 350 } |
348 | 351 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 const std::string secure_scheme = chrome::kHttpsScheme; | 462 const std::string secure_scheme = chrome::kHttpsScheme; |
460 GURL::Replacements replacements; | 463 GURL::Replacements replacements; |
461 replacements.SetSchemeStr(secure_scheme); | 464 replacements.SetSchemeStr(secure_scheme); |
462 instant_url = instant_url.ReplaceComponents(replacements); | 465 instant_url = instant_url.ReplaceComponents(replacements); |
463 } | 466 } |
464 } | 467 } |
465 | 468 |
466 return instant_url; | 469 return instant_url; |
467 } | 470 } |
468 | 471 |
| 472 GURL GetLocalInstantURL(Profile* profile) { |
| 473 const TemplateURL* default_provider = |
| 474 TemplateURLServiceFactory::GetForProfile(profile)-> |
| 475 GetDefaultSearchProvider(); |
| 476 |
| 477 if (!default_provider) |
| 478 return GURL(); |
| 479 |
| 480 if (default_provider && |
| 481 (TemplateURLPrepopulateData::GetEngineType(default_provider->url()) == |
| 482 SEARCH_ENGINE_GOOGLE)) { |
| 483 return GURL(chrome::kChromeSearchLocalGoogleNtpUrl); |
| 484 } |
| 485 return GURL(chrome::kChromeSearchLocalNtpUrl); |
| 486 } |
| 487 |
469 bool IsInstantEnabled(Profile* profile) { | 488 bool IsInstantEnabled(Profile* profile) { |
470 return GetInstantURL(profile, kDisableStartMargin).is_valid(); | 489 return GetInstantURL(profile, kDisableStartMargin).is_valid(); |
471 } | 490 } |
472 | 491 |
473 bool IsAggressiveLocalNTPFallbackEnabled() { | 492 bool IsAggressiveLocalNTPFallbackEnabled() { |
474 // Check the command-line/about:flags setting first, which should have | 493 // 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). | 494 // precedence and allows the trial to not be reported (if it's never queried). |
476 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 495 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
477 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || | 496 if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI) || |
478 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { | 497 command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 replacements.SetHostStr(search_host); | 617 replacements.SetHostStr(search_host); |
599 replacements.SetPortStr(search_port); | 618 replacements.SetPortStr(search_port); |
600 return instant_url.ReplaceComponents(replacements); | 619 return instant_url.ReplaceComponents(replacements); |
601 } | 620 } |
602 | 621 |
603 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { | 622 bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { |
604 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); | 623 return MatchesOrigin(my_url, other_url) && my_url.path() == other_url.path(); |
605 } | 624 } |
606 | 625 |
607 } // namespace chrome | 626 } // namespace chrome |
OLD | NEW |