| Index: chrome/browser/search/search.cc
|
| diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc
|
| index 1328ffeba8cb10bc442fe6d5062008e452094617..f42fafb8bb16758cbd8114180e33f75ec0fe532a 100644
|
| --- a/chrome/browser/search/search.cc
|
| +++ b/chrome/browser/search/search.cc
|
| @@ -62,6 +62,7 @@ const char kHideVerbatimFlagName[] = "hide_verbatim";
|
| const char kUseRemoteNTPOnStartupFlagName[] = "use_remote_ntp_on_startup";
|
| const char kShowNtpFlagName[] = "show_ntp";
|
| const char kRecentTabsOnNTPFlagName[] = "show_recent_tabs";
|
| +const char kUseCacheableNTP[] = "use_cacheable_ntp";
|
|
|
| // Constants for the field trial name and group prefix.
|
| const char kInstantExtendedFieldTrialName[] = "InstantExtended";
|
| @@ -120,6 +121,21 @@ GURL TemplateURLRefToGURL(const TemplateURLRef& ref,
|
| return GURL(ref.ReplaceSearchTerms(search_terms_args));
|
| }
|
|
|
| +GURL GetNewTabPageURL(Profile* profile) {
|
| + if (!ShouldUseCacheableNTP())
|
| + return GURL();
|
| +
|
| + if (!profile)
|
| + return GURL();
|
| +
|
| + TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
|
| + if (!template_url)
|
| + return GURL();
|
| +
|
| + return TemplateURLRefToGURL(template_url->new_tab_url_ref(),
|
| + kDisableStartMargin, false);
|
| +}
|
| +
|
| bool MatchesOrigin(const GURL& my_url, const GURL& other_url) {
|
| return my_url.host() == other_url.host() &&
|
| my_url.port() == other_url.port() &&
|
| @@ -191,13 +207,6 @@ bool IsSuitableURLForInstant(const GURL& url, const TemplateURL* template_url) {
|
| google_util::StartsWithCommandLineGoogleBaseURL(url));
|
| }
|
|
|
| -// Returns true if |url| matches --instant-new-tab-url.
|
| -bool IsCommandLineInstantNTPURL(const GURL& url) {
|
| - const GURL ntp_url(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
| - switches::kInstantNewTabURL));
|
| - return ntp_url.is_valid() && MatchesOriginAndPath(ntp_url, url);
|
| -}
|
| -
|
| // Returns true if |url| can be used as an Instant URL for |profile|.
|
| bool IsInstantURL(const GURL& url, Profile* profile) {
|
| if (!IsInstantExtendedAPIEnabled())
|
| @@ -206,7 +215,8 @@ bool IsInstantURL(const GURL& url, Profile* profile) {
|
| if (!url.is_valid())
|
| return false;
|
|
|
| - if (IsCommandLineInstantNTPURL(url))
|
| + const GURL new_tab_url(GetNewTabPageURL(profile));
|
| + if (new_tab_url.is_valid() && MatchesOriginAndPath(url, new_tab_url))
|
| return true;
|
|
|
| TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
|
| @@ -388,8 +398,10 @@ bool NavEntryIsInstantNTP(const content::WebContents* contents,
|
| entry->GetVirtualURL() == GetLocalInstantURL(profile))
|
| return GetSearchTermsImpl(contents, entry).empty();
|
|
|
| + GURL new_tab_url(GetNewTabPageURL(profile));
|
| return entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL) &&
|
| - IsCommandLineInstantNTPURL(entry->GetURL());
|
| + new_tab_url.is_valid() &&
|
| + MatchesOriginAndPath(entry->GetURL(), new_tab_url);
|
| }
|
|
|
| bool IsSuggestPrefEnabled(Profile* profile) {
|
| @@ -458,11 +470,20 @@ bool ShouldHideTopVerbatimMatch() {
|
| return false;
|
| }
|
|
|
| +bool ShouldUseCacheableNTP() {
|
| + FieldTrialFlags flags;
|
| + if (GetFieldTrialInfo(
|
| + base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName),
|
| + &flags, NULL)) {
|
| + return GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags);
|
| + }
|
| + return false;
|
| +}
|
| +
|
| bool ShouldShowInstantNTP() {
|
| - // If the instant-new-tab-url flag is set, we'll always just load the NTP
|
| - // directly instead of preloading contents using InstantNTP.
|
| - const CommandLine* command_line = CommandLine::ForCurrentProcess();
|
| - if (command_line->HasSwitch(switches::kInstantNewTabURL))
|
| + // If using the cacheable NTP, load the NTP directly instead of preloading its
|
| + // contents using InstantNTP.
|
| + if (ShouldUseCacheableNTP())
|
| return false;
|
|
|
| FieldTrialFlags flags;
|
| @@ -570,12 +591,12 @@ bool HandleNewTabURLRewrite(GURL* url,
|
| url->host() != chrome::kChromeUINewTabHost)
|
| return false;
|
|
|
| - const GURL ntp_url(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
| - switches::kInstantNewTabURL));
|
| - if (!ntp_url.is_valid())
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + GURL new_tab_url(GetNewTabPageURL(profile));
|
| + if (!new_tab_url.is_valid())
|
| return false;
|
|
|
| - *url = ntp_url;
|
| + *url = new_tab_url;
|
| return true;
|
| }
|
|
|
| @@ -584,9 +605,9 @@ bool HandleNewTabURLReverseRewrite(GURL* url,
|
| if (!IsInstantExtendedAPIEnabled())
|
| return false;
|
|
|
| - const GURL ntp_url(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
| - switches::kInstantNewTabURL));
|
| - if (!MatchesOriginAndPath(ntp_url, *url))
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + GURL new_tab_url(GetNewTabPageURL(profile));
|
| + if (!new_tab_url.is_valid() || !MatchesOriginAndPath(new_tab_url, *url))
|
| return false;
|
|
|
| *url = GURL(chrome::kChromeUINewTabURL);
|
|
|