| 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" |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 return url.is_valid() && | 441 return url.is_valid() && |
| 442 profile && | 442 profile && |
| 443 IsInstantExtendedAPIEnabled() && | 443 IsInstantExtendedAPIEnabled() && |
| 444 (url.SchemeIs(chrome::kChromeSearchScheme) || | 444 (url.SchemeIs(chrome::kChromeSearchScheme) || |
| 445 IsInstantURL(url, profile)); | 445 IsInstantURL(url, profile)); |
| 446 } | 446 } |
| 447 | 447 |
| 448 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile) { | 448 bool ShouldUseProcessPerSiteForInstantURL(const GURL& url, Profile* profile) { |
| 449 return ShouldAssignURLToInstantRenderer(url, profile) && | 449 return ShouldAssignURLToInstantRenderer(url, profile) && |
| 450 (url.host() == chrome::kChromeSearchLocalNtpHost || | 450 (url.host() == chrome::kChromeSearchLocalNtpHost || |
| 451 url.host() == chrome::kChromeSearchOnlineNtpHost); | 451 url.host() == chrome::kChromeSearchRemoteNtpHost); |
| 452 } | 452 } |
| 453 | 453 |
| 454 bool IsNTPURL(const GURL& url, Profile* profile) { | 454 bool IsNTPURL(const GURL& url, Profile* profile) { |
| 455 if (!url.is_valid()) | 455 if (!url.is_valid()) |
| 456 return false; | 456 return false; |
| 457 | 457 |
| 458 if (!IsInstantExtendedAPIEnabled()) | 458 if (!IsInstantExtendedAPIEnabled()) |
| 459 return url == GURL(chrome::kChromeUINewTabURL); | 459 return url == GURL(chrome::kChromeUINewTabURL); |
| 460 | 460 |
| 461 const base::string16 search_terms = ExtractSearchTermsFromURL(profile, url); | 461 const base::string16 search_terms = ExtractSearchTermsFromURL(profile, url); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 return url; | 672 return url; |
| 673 | 673 |
| 674 GURL effective_url(url); | 674 GURL effective_url(url); |
| 675 | 675 |
| 676 // Replace the scheme with "chrome-search:". | 676 // Replace the scheme with "chrome-search:". |
| 677 url_canon::Replacements<char> replacements; | 677 url_canon::Replacements<char> replacements; |
| 678 std::string search_scheme(chrome::kChromeSearchScheme); | 678 std::string search_scheme(chrome::kChromeSearchScheme); |
| 679 replacements.SetScheme(search_scheme.data(), | 679 replacements.SetScheme(search_scheme.data(), |
| 680 url_parse::Component(0, search_scheme.length())); | 680 url_parse::Component(0, search_scheme.length())); |
| 681 | 681 |
| 682 // If the URL corresponds to an online NTP, replace the host with | 682 // If this is the URL for a server-provided NTP, replace the host with |
| 683 // "online-ntp". | 683 // "remote-ntp". |
| 684 std::string online_ntp_host(chrome::kChromeSearchOnlineNtpHost); | 684 std::string remote_ntp_host(chrome::kChromeSearchRemoteNtpHost); |
| 685 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); | 685 NewTabURLDetails details = NewTabURLDetails::ForProfile(profile); |
| 686 if (template_url) { | 686 if (details.state == NEW_TAB_URL_VALID && |
| 687 const GURL instant_url = TemplateURLRefToGURL( | 687 search::MatchesOriginAndPath(url, details.url)) { |
| 688 template_url->instant_url_ref(), kDisableStartMargin, false, false); | 688 replacements.SetHost(remote_ntp_host.c_str(), |
| 689 if (instant_url.is_valid() && | 689 url_parse::Component(0, remote_ntp_host.length())); |
| 690 search::MatchesOriginAndPath(url, instant_url)) { | |
| 691 replacements.SetHost(online_ntp_host.c_str(), | |
| 692 url_parse::Component(0, online_ntp_host.length())); | |
| 693 } | |
| 694 } | 690 } |
| 695 | 691 |
| 696 effective_url = effective_url.ReplaceComponents(replacements); | 692 effective_url = effective_url.ReplaceComponents(replacements); |
| 697 return effective_url; | 693 return effective_url; |
| 698 } | 694 } |
| 699 | 695 |
| 700 bool HandleNewTabURLRewrite(GURL* url, | 696 bool HandleNewTabURLRewrite(GURL* url, |
| 701 content::BrowserContext* browser_context) { | 697 content::BrowserContext* browser_context) { |
| 702 if (!IsInstantExtendedAPIEnabled()) | 698 if (!IsInstantExtendedAPIEnabled()) |
| 703 return false; | 699 return false; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 | 825 |
| 830 // Given a FieldTrialFlags object, returns the boolean value of the provided | 826 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 831 // flag. | 827 // flag. |
| 832 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 828 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 833 bool default_value, | 829 bool default_value, |
| 834 const FieldTrialFlags& flags) { | 830 const FieldTrialFlags& flags) { |
| 835 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 831 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 836 } | 832 } |
| 837 | 833 |
| 838 } // namespace chrome | 834 } // namespace chrome |
| OLD | NEW |