Index: chrome/browser/search/search.cc |
diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc |
index 1328ffeba8cb10bc442fe6d5062008e452094617..ae7fc25d6e2063470157190b22c6f38347e6bf18 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,27 @@ GURL TemplateURLRefToGURL(const TemplateURLRef& ref, |
return GURL(ref.ReplaceSearchTerms(search_terms_args)); |
} |
+GURL GetNewTabPageURL(Profile* profile) { |
+ FieldTrialFlags flags; |
+ if (!GetFieldTrialInfo( |
+ base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), |
+ &flags, NULL)) |
+ return GURL(); |
+ |
+ if (!GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags)) |
+ 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 +213,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 +221,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); |
@@ -389,7 +405,7 @@ bool NavEntryIsInstantNTP(const content::WebContents* contents, |
return GetSearchTermsImpl(contents, entry).empty(); |
return entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL) && |
- IsCommandLineInstantNTPURL(entry->GetURL()); |
+ MatchesOriginAndPath(entry->GetURL(), GetNewTabPageURL(profile)); |
samarth
2013/08/13 23:47:59
In the previous check you check that GetNewTabPage
Jered
2013/08/14 15:41:49
Done.
|
} |
bool IsSuggestPrefEnabled(Profile* profile) { |
@@ -459,16 +475,14 @@ bool ShouldHideTopVerbatimMatch() { |
} |
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)) |
- return false; |
- |
FieldTrialFlags flags; |
if (GetFieldTrialInfo( |
base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), |
&flags, NULL)) { |
+ // If the use_cacheable_ntp field trial flag is set, load the NTP directly |
samarth
2013/08/13 23:47:59
Please make this into a helper (ShouldUseCacheable
Jered
2013/08/14 15:41:49
Done.
|
+ // instead of preloading contents using InstantNTP. |
+ if (GetBoolValueForFlagWithDefault(kUseCacheableNTP, false, flags)) |
+ return false; |
return GetBoolValueForFlagWithDefault(kShowNtpFlagName, true, flags); |
} |
return true; |
@@ -570,12 +584,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()) |
+ GURL new_tab_url(GetNewTabPageURL( |
samarth
2013/08/13 23:47:59
nit: fits on one line?
Jered
2013/08/14 15:41:49
Split out profile.
|
+ Profile::FromBrowserContext(browser_context))); |
+ if (!new_tab_url.is_valid()) |
return false; |
- *url = ntp_url; |
+ *url = new_tab_url; |
return true; |
} |
@@ -584,9 +598,9 @@ bool HandleNewTabURLReverseRewrite(GURL* url, |
if (!IsInstantExtendedAPIEnabled()) |
return false; |
- const GURL ntp_url(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
- switches::kInstantNewTabURL)); |
- if (!MatchesOriginAndPath(ntp_url, *url)) |
+ GURL new_tab_url(GetNewTabPageURL( |
+ Profile::FromBrowserContext(browser_context))); |
+ if (!MatchesOriginAndPath(new_tab_url, *url)) |
return false; |
*url = GURL(chrome::kChromeUINewTabURL); |