diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 00:48:18 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 00:48:18 +0000 |
commit | d5ebcf41ffffb051c5527468b4e2b134e8dba056 (patch) | |
tree | f19b83206b360b24695bcead7756c9494dafaf88 | |
parent | 6e03921e51981f830c3b65381efddaf226880f48 (diff) | |
download | chromium_src-d5ebcf41ffffb051c5527468b4e2b134e8dba056.zip chromium_src-d5ebcf41ffffb051c5527468b4e2b134e8dba056.tar.gz chromium_src-d5ebcf41ffffb051c5527468b4e2b134e8dba056.tar.bz2 |
1. Renamed {google:instantEnabledParameter} to {google:forceInstantResults}.
2. Added |force_instant_results| param to GetInstantURL() to append {google:forceInstantResults} to Instant URL.
3. Wrote a unit test for GetInstantURL().
4. Added a member variable in struct SearchTermsArgs.
5. Added |force_instant_results| param to SearchTermsData::forceInstantResultsParam().
BUG=269186
TEST=none
Review URL: https://codereview.chromium.org/35373005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231689 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autocomplete/history_url_provider.cc | 13 | ||||
-rw-r--r-- | chrome/browser/search/search.cc | 24 | ||||
-rw-r--r-- | chrome/browser/search/search.h | 8 | ||||
-rw-r--r-- | chrome/browser/search/search_unittest.cc | 46 | ||||
-rw-r--r-- | chrome/browser/search_engines/prepopulated_engines.json | 2 | ||||
-rw-r--r-- | chrome/browser/search_engines/search_terms_data.cc | 9 | ||||
-rw-r--r-- | chrome/browser/search_engines/search_terms_data.h | 22 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url.cc | 18 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url.h | 8 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_controller.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/search/instant_ntp_prerenderer.cc | 3 | ||||
-rw-r--r-- | chrome/test/data/diagnostics/user/Default/Preferences | 2 | ||||
-rw-r--r-- | chrome/test/data/page_cycler/cached_data_dir/Default/Preferences | 2 |
13 files changed, 102 insertions, 57 deletions
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index 0ff6b50..789a3a5 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -204,7 +204,8 @@ class SearchTermsDataSnapshot : public SearchTermsData { virtual std::string GetApplicationLocale() const OVERRIDE; virtual string16 GetRlzParameterValue() const OVERRIDE; virtual std::string GetSearchClient() const OVERRIDE; - virtual std::string InstantEnabledParam() const OVERRIDE; + virtual std::string ForceInstantResultsParam( + bool for_prerender) const OVERRIDE; virtual std::string InstantExtendedEnabledParam() const OVERRIDE; virtual std::string NTPIsThemedParam() const OVERRIDE; @@ -213,7 +214,7 @@ class SearchTermsDataSnapshot : public SearchTermsData { std::string application_locale_; string16 rlz_parameter_value_; std::string search_client_; - std::string instant_enabled_param_; + std::string force_instant_results_param_; std::string instant_extended_enabled_param_; std::string ntp_is_themed_param_; @@ -226,7 +227,8 @@ SearchTermsDataSnapshot::SearchTermsDataSnapshot( application_locale_(search_terms_data.GetApplicationLocale()), rlz_parameter_value_(search_terms_data.GetRlzParameterValue()), search_client_(search_terms_data.GetSearchClient()), - instant_enabled_param_(search_terms_data.InstantEnabledParam()), + force_instant_results_param_( + search_terms_data.ForceInstantResultsParam(false)), instant_extended_enabled_param_( search_terms_data.InstantExtendedEnabledParam()), ntp_is_themed_param_(search_terms_data.NTPIsThemedParam()) {} @@ -250,8 +252,9 @@ std::string SearchTermsDataSnapshot::GetSearchClient() const { return search_client_; } -std::string SearchTermsDataSnapshot::InstantEnabledParam() const { - return instant_enabled_param_; +std::string SearchTermsDataSnapshot::ForceInstantResultsParam( + bool for_prerender) const { + return force_instant_results_param_; } std::string SearchTermsDataSnapshot::InstantExtendedEnabledParam() const { diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc index c063cbc..60498e3 100644 --- a/chrome/browser/search/search.cc +++ b/chrome/browser/search/search.cc @@ -128,17 +128,20 @@ TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) { GURL TemplateURLRefToGURL(const TemplateURLRef& ref, int start_margin, - bool append_extra_query_params) { + bool append_extra_query_params, + bool force_instant_results) { TemplateURLRef::SearchTermsArgs search_terms_args = TemplateURLRef::SearchTermsArgs(string16()); search_terms_args.omnibox_start_margin = start_margin; search_terms_args.append_extra_query_params = append_extra_query_params; + search_terms_args.force_instant_results = force_instant_results; return GURL(ref.ReplaceSearchTerms(search_terms_args)); } bool MatchesAnySearchURL(const GURL& url, TemplateURL* template_url) { GURL search_url = - TemplateURLRefToGURL(template_url->url_ref(), kDisableStartMargin, false); + TemplateURLRefToGURL(template_url->url_ref(), kDisableStartMargin, false, + false); if (search_url.is_valid() && search::MatchesOriginAndPath(url, search_url)) return true; @@ -146,7 +149,7 @@ bool MatchesAnySearchURL(const GURL& url, TemplateURL* template_url) { // "URLCount() - 1" because we already tested url_ref above. for (size_t i = 0; i < template_url->URLCount() - 1; ++i) { TemplateURLRef ref(template_url, i); - search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false); + search_url = TemplateURLRefToGURL(ref, kDisableStartMargin, false, false); if (search_url.is_valid() && search::MatchesOriginAndPath(url, search_url)) return true; @@ -223,7 +226,7 @@ bool IsInstantURL(const GURL& url, Profile* profile) { const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); const GURL instant_url = - TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false); + TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin, false, false); if (!instant_url.is_valid()) return false; @@ -422,7 +425,8 @@ bool IsSuggestPrefEnabled(Profile* profile) { profile->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled); } -GURL GetInstantURL(Profile* profile, int start_margin) { +GURL GetInstantURL(Profile* profile, int start_margin, + bool force_instant_results) { if (!IsInstantExtendedAPIEnabled() || !IsSuggestPrefEnabled(profile)) return GURL(); @@ -431,7 +435,8 @@ GURL GetInstantURL(Profile* profile, int start_margin) { return GURL(); GURL instant_url = - TemplateURLRefToGURL(template_url->instant_url_ref(), start_margin, true); + TemplateURLRefToGURL(template_url->instant_url_ref(), start_margin, true, + force_instant_results); if (!instant_url.is_valid() || !template_url->HasSearchTermsReplacementKey(instant_url)) return GURL(); @@ -461,7 +466,8 @@ std::vector<GURL> GetSearchURLs(Profile* profile) { return result; for (size_t i = 0; i < template_url->URLCount(); ++i) { TemplateURLRef ref(template_url, i); - result.push_back(TemplateURLRefToGURL(ref, kDisableStartMargin, false)); + result.push_back(TemplateURLRefToGURL(ref, kDisableStartMargin, false, + false)); } return result; } @@ -481,7 +487,7 @@ GURL GetNewTabPageURL(Profile* profile) { return GURL(chrome::kChromeSearchLocalNtpUrl); GURL url(TemplateURLRefToGURL(template_url->new_tab_url_ref(), - kDisableStartMargin, false)); + kDisableStartMargin, false, false)); if (!url.is_valid() || !url.SchemeIsSecure()) return GURL(chrome::kChromeSearchLocalNtpUrl); @@ -588,7 +594,7 @@ GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) { TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); if (template_url) { const GURL instant_url = TemplateURLRefToGURL( - template_url->instant_url_ref(), kDisableStartMargin, false); + template_url->instant_url_ref(), kDisableStartMargin, false, false); if (instant_url.is_valid() && search::MatchesOriginAndPath(url, instant_url)) { replacements.SetHost(online_ntp_host.c_str(), diff --git a/chrome/browser/search/search.h b/chrome/browser/search/search.h index 5f2eee5..dd1904f 100644 --- a/chrome/browser/search/search.h +++ b/chrome/browser/search/search.h @@ -107,11 +107,15 @@ bool NavEntryIsInstantNTP(const content::WebContents* contents, // because it doesn't satisfy the requirements for extended mode or if Instant // is disabled through preferences). Callers must check that the returned URL is // valid before using it. The value of |start_margin| is used for the "es_sm" -// parameter in the URL. +// parameter in the URL. |force_instant_results| forces a search page to update +// results incrementally even if that is otherwise disabled by google.com +// preferences. // NOTE: This method expands the default search engine's instant_url template, // so it shouldn't be called from SearchTermsData or other such code that would // lead to an infinite recursion. -GURL GetInstantURL(Profile* profile, int start_margin); +GURL GetInstantURL(Profile* profile, + int start_margin, + bool force_instant_results); // Returns URLs associated with the default search engine for |profile|. std::vector<GURL> GetSearchURLs(Profile* profile); diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc index af006e6..3afc595 100644 --- a/chrome/browser/search/search_unittest.cc +++ b/chrome/browser/search/search_unittest.cc @@ -341,7 +341,8 @@ class SearchTest : public BrowserWithTestWindowTest { TemplateURLData data; data.SetURL("http://foo.com/url?bar={searchTerms}"); data.instant_url = "http://foo.com/instant?" - "{google:omniboxStartMarginParameter}foo=foo#foo=foo&strk"; + "{google:omniboxStartMarginParameter}{google:forceInstantResults}" + "foo=foo#foo=foo&strk"; if (set_ntp_url) { data.new_tab_url = (insecure_ntp_url ? "http" : "https") + std::string("://foo.com/newtab?strk"); @@ -709,7 +710,8 @@ TEST_F(SearchTest, InstantCacheableNTPNavigationEntry) { EXPECT_TRUE(NavEntryIsInstantNTP(contents, controller.GetLastCommittedEntry())); // Instant page is not cacheable NTP. - NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin)); + NavigateAndCommitActiveTab(GetInstantURL(profile(), kDisableStartMargin, + false)); EXPECT_FALSE(NavEntryIsInstantNTP(contents, controller.GetLastCommittedEntry())); // Test Cacheable NTP @@ -762,49 +764,63 @@ TEST_F(SearchTest, UseLocalNTPIfNTPURLIsBlockedForSupervisedUser) { EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), chrome::GetNewTabPageURL(profile())); - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); } TEST_F(SearchTest, GetInstantURLExtendedEnabled) { // Instant is disabled, so no Instant URL. - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); // Enable Instant. Still no Instant URL because "strk" is missing. EnableInstantExtendedAPIForTesting(); SetDefaultInstantTemplateUrl(false); - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); // Set an Instant URL with a valid search terms replacement key. SetDefaultInstantTemplateUrl(true); // Now there should be a valid Instant URL. Note the HTTPS "upgrade". EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), - GetInstantURL(profile(), kDisableStartMargin)); + GetInstantURL(profile(), kDisableStartMargin, false)); // Enable suggest. No difference. profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), - GetInstantURL(profile(), kDisableStartMargin)); + GetInstantURL(profile(), kDisableStartMargin, false)); // Disable suggest. No Instant URL. profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); } TEST_F(SearchTest, StartMarginCGI) { // Instant is disabled, so no Instant URL. - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin, false)); // Enable Instant. No margin. EnableInstantExtendedAPIForTesting(); profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), - GetInstantURL(profile(), kDisableStartMargin)); + GetInstantURL(profile(), kDisableStartMargin, false)); // With start margin. EXPECT_EQ(GURL("https://foo.com/instant?es_sm=10&foo=foo#foo=foo&strk"), - GetInstantURL(profile(), 10)); + GetInstantURL(profile(), 10, false)); +} + +TEST_F(SearchTest, InstantSearchEnabledCGI) { + EnableInstantExtendedAPIForTesting(); + + // Disable Instant Search. + // Make sure {google:forceInstantResults} is not set in the Instant URL. + EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), + GetInstantURL(profile(), kDisableStartMargin, false)); + + // Enable Instant Search. + // Make sure {google:forceInstantResults} is set in the Instant URL. + EXPECT_EQ(GURL("https://foo.com/instant?ion=1&foo=foo#foo=foo&strk"), + GetInstantURL(profile(), kDisableStartMargin, true)); } TEST_F(SearchTest, CommandLineOverrides) { @@ -827,7 +843,7 @@ TEST_F(SearchTest, CommandLineOverrides) { // By default, Instant Extended forces the instant URL to be HTTPS, so even if // we set a Google base URL that is HTTP, we should get an HTTPS URL. UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); - GURL instant_url(GetInstantURL(profile(), kDisableStartMargin)); + GURL instant_url(GetInstantURL(profile(), kDisableStartMargin, false)); ASSERT_TRUE(instant_url.is_valid()); EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); @@ -836,7 +852,7 @@ TEST_F(SearchTest, CommandLineOverrides) { UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, "http://www.bar.com/"); - instant_url = GetInstantURL(profile(), kDisableStartMargin); + instant_url = GetInstantURL(profile(), kDisableStartMargin, false); ASSERT_TRUE(instant_url.is_valid()); EXPECT_EQ("http://www.bar.com/webhp?strk", instant_url.spec()); @@ -850,7 +866,7 @@ TEST_F(SearchTest, CommandLineOverrides) { // query portion of the instant URL. CommandLine::ForCurrentProcess()->AppendSwitchASCII( switches::kExtraSearchQueryParams, "a=b"); - instant_url = GetInstantURL(profile(), kDisableStartMargin); + instant_url = GetInstantURL(profile(), kDisableStartMargin, false); ASSERT_TRUE(instant_url.is_valid()); EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); } @@ -909,7 +925,7 @@ TEST_F(SearchTest, IsNTPURL) { // Enable Instant. No margin. EnableInstantExtendedAPIForTesting(); profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); - GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin)); + GURL remote_ntp_url(GetInstantURL(profile(), kDisableStartMargin, false)); GURL search_url_with_search_terms("https://foo.com/url?strk&bar=abc"); GURL search_url_without_search_terms("https://foo.com/url?strk&bar"); diff --git a/chrome/browser/search_engines/prepopulated_engines.json b/chrome/browser/search_engines/prepopulated_engines.json index d8d741e..e7e4db5 100644 --- a/chrome/browser/search_engines/prepopulated_engines.json +++ b/chrome/browser/search_engines/prepopulated_engines.json @@ -488,7 +488,7 @@ "favicon_url": "http://www.google.com/favicon.ico", "search_url": "{google:baseURL}search?q={searchTerms}&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:bookmarkBarPinned}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}{google:omniboxStartMarginParameter}ie={inputEncoding}", "suggest_url": "{google:baseSuggestURL}search?{google:searchFieldtrialParameter}client={google:suggestClient}&q={searchTerms}&{google:cursorPosition}{google:zeroPrefixUrl}{google:pageClassification}sugkey={google:suggestAPIKeyParameter}", - "instant_url": "{google:baseURL}webhp?sourceid=chrome-instant&{google:RLZ}{google:instantEnabledParameter}{google:instantExtendedEnabledParameter}{google:ntpIsThemedParameter}{google:omniboxStartMarginParameter}ie={inputEncoding}", + "instant_url": "{google:baseURL}webhp?sourceid=chrome-instant&{google:RLZ}{google:forceInstantResults}{google:instantExtendedEnabledParameter}{google:ntpIsThemedParameter}{google:omniboxStartMarginParameter}ie={inputEncoding}", "image_url": "{google:baseURL}searchbyimage/upload", "new_tab_url": "{google:baseURL}_/chrome/newtab?{google:RLZ}{google:instantExtendedEnabledParameter}{google:ntpIsThemedParameter}ie={inputEncoding}", "image_url_post_params": "encoded_image={google:imageThumbnail},image_url={google:imageURL},sbisrc={google:imageSearchSource},original_width={google:imageOriginalWidth},original_height={google:imageOriginalHeight}", diff --git a/chrome/browser/search_engines/search_terms_data.cc b/chrome/browser/search_engines/search_terms_data.cc index d4af8029..34c3194 100644 --- a/chrome/browser/search_engines/search_terms_data.cc +++ b/chrome/browser/search_engines/search_terms_data.cc @@ -73,7 +73,8 @@ std::string SearchTermsData::GetSuggestClient() const { return std::string(); } -std::string SearchTermsData::InstantEnabledParam() const { +std::string SearchTermsData::ForceInstantResultsParam( + bool for_prerender) const { return std::string(); } @@ -150,10 +151,12 @@ std::string UIThreadSearchTermsData::GetSuggestClient() const { return chrome::IsInstantExtendedAPIEnabled() ? "chrome-omni" : "chrome"; } -std::string UIThreadSearchTermsData::InstantEnabledParam() const { +std::string UIThreadSearchTermsData::ForceInstantResultsParam( + bool for_prerender) const { DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || BrowserThread::CurrentlyOn(BrowserThread::UI)); - return chrome::IsInstantExtendedAPIEnabled() ? std::string() : "ion=1&"; + return (for_prerender || !chrome::IsInstantExtendedAPIEnabled()) ? "ion=1&" : + std::string(); } std::string UIThreadSearchTermsData::InstantExtendedEnabledParam() const { diff --git a/chrome/browser/search_engines/search_terms_data.h b/chrome/browser/search_engines/search_terms_data.h index cbd1e7d..4980df6 100644 --- a/chrome/browser/search_engines/search_terms_data.h +++ b/chrome/browser/search_engines/search_terms_data.h @@ -44,14 +44,15 @@ class SearchTermsData { // implementation returns the empty string. virtual std::string GetSuggestClient() const; - // Returns a string indicating whether Instant (in the visible-preview mode) - // is enabled, suitable for adding as a query string param to the homepage - // (instant_url) request. Returns an empty string if Instant is disabled, or - // if it's only active in a hidden field trial mode, or if InstantExtended is - // enabled (since that supercedes regular Instant). Determining this requires - // accessing the Profile, so this can only ever be non-empty for - // UIThreadSearchTermsData. - virtual std::string InstantEnabledParam() const; + // Returns a string that will cause the search results page to update + // incrementally. Currently, Instant Extended passes a different param to + // search results pages that also has this effect, so by default this function + // returns the empty string when Instant Extended is enabled. However, when + // doing instant search result prerendering, we still need to pass this param, + // as Instant Extended does not cause incremental updates by default for the + // prerender page. Callers should set |for_prerender| in this case to force + // the returned string to be non-empty. + virtual std::string ForceInstantResultsParam(bool for_prerender) const; // Returns a string indicating whether InstantExtended is enabled, suitable // for adding as a query string param to the homepage or search requests. @@ -74,7 +75,7 @@ class SearchTermsData { class UIThreadSearchTermsData : public SearchTermsData { public: // If |profile_| is NULL, the Google base URL accessors will return default - // values, and InstantEnabledParam(), InstantExtendedEnabledParam(), and + // values, and ForceInstantResultsParam(), InstantExtendedEnabledParam(), and // NTPIsThemedParam(), will return the empty string. explicit UIThreadSearchTermsData(Profile* profile); @@ -83,7 +84,8 @@ class UIThreadSearchTermsData : public SearchTermsData { virtual string16 GetRlzParameterValue() const OVERRIDE; virtual std::string GetSearchClient() const OVERRIDE; virtual std::string GetSuggestClient() const OVERRIDE; - virtual std::string InstantEnabledParam() const OVERRIDE; + virtual std::string ForceInstantResultsParam( + bool for_prerender) const OVERRIDE; virtual std::string InstantExtendedEnabledParam() const OVERRIDE; virtual std::string NTPIsThemedParam() const OVERRIDE; diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index 6df1b6b..abe0a0f 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -66,7 +66,7 @@ const char kGoogleBaseSuggestURLParameter[] = "google:baseSuggestURL"; const char kGoogleBaseSuggestURLParameterFull[] = "{google:baseSuggestURL}"; const char kGoogleBookmarkBarPinnedParameter[] = "google:bookmarkBarPinned"; const char kGoogleCursorPositionParameter[] = "google:cursorPosition"; -const char kGoogleInstantEnabledParameter[] = "google:instantEnabledParameter"; +const char kGoogleForceInstantResultsParameter[] = "google:forceInstantResults"; const char kGoogleInstantExtendedEnabledParameter[] = "google:instantExtendedEnabledParameter"; const char kGoogleInstantExtendedEnabledKey[] = @@ -204,7 +204,8 @@ TemplateURLRef::SearchTermsArgs::SearchTermsArgs(const string16& search_terms) omnibox_start_margin(-1), page_classification(AutocompleteInput::INVALID_SPEC), bookmark_bar_pinned(false), - append_extra_query_params(false) { + append_extra_query_params(false), + force_instant_results(false) { } TemplateURLRef::SearchTermsArgs::~SearchTermsArgs() { @@ -574,8 +575,8 @@ bool TemplateURLRef::ParseParameter(size_t start, } else if (parameter == kGoogleImageURLParameter) { replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, start)); - } else if (parameter == kGoogleInstantEnabledParameter) { - replacements->push_back(Replacement(GOOGLE_INSTANT_ENABLED, start)); + } else if (parameter == kGoogleForceInstantResultsParameter) { + replacements->push_back(Replacement(GOOGLE_FORCE_INSTANT_RESULTS, start)); } else if (parameter == kGoogleInstantExtendedEnabledParameter) { replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, start)); @@ -871,10 +872,13 @@ std::string TemplateURLRef::HandleReplacements( &url); break; - case GOOGLE_INSTANT_ENABLED: + case GOOGLE_FORCE_INSTANT_RESULTS: DCHECK(!i->is_post_param); - HandleReplacement( - std::string(), search_terms_data.InstantEnabledParam(), *i, &url); + HandleReplacement(std::string(), + search_terms_data.ForceInstantResultsParam( + search_terms_args.force_instant_results), + *i, + &url); break; case GOOGLE_INSTANT_EXTENDED_ENABLED: diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index e7cc20b..ff95397 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/template_url.h @@ -127,6 +127,12 @@ class TemplateURLRef { // When searching for an image, the original size of the image. gfx::Size image_original_size; + + // If set, ReplaceSearchTerms() will append a param to the TemplateURLRef to + // update the search results page incrementally even if that is otherwise + // disabled by google.com preferences. See comments on + // SearchTermsData::ForceInstantResultsParam(). + bool force_instant_results; }; TemplateURLRef(TemplateURL* owner, Type type); @@ -253,7 +259,7 @@ class TemplateURLRef { GOOGLE_IMAGE_SEARCH_SOURCE, GOOGLE_IMAGE_THUMBNAIL, GOOGLE_IMAGE_URL, - GOOGLE_INSTANT_ENABLED, + GOOGLE_FORCE_INSTANT_RESULTS, GOOGLE_INSTANT_EXTENDED_ENABLED, GOOGLE_NTP_IS_THEMED, GOOGLE_OMNIBOX_START_MARGIN, diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc index 334d93a..458c5f8 100644 --- a/chrome/browser/ui/search/instant_controller.cc +++ b/chrome/browser/ui/search/instant_controller.cc @@ -130,7 +130,7 @@ void InstantController::InstantPageLoadFailed(content::WebContents* contents) { // we don't want to redirect and nuke their forward history stack. const GURL& current_url = contents->GetURL(); GURL instant_url = chrome::GetInstantURL(profile(), - chrome::kDisableStartMargin); + chrome::kDisableStartMargin, false); if (instant_tab_->IsLocal() || !search::MatchesOriginAndPath(instant_url, current_url) || !current_url.ref().empty() || diff --git a/chrome/browser/ui/search/instant_ntp_prerenderer.cc b/chrome/browser/ui/search/instant_ntp_prerenderer.cc index e009b97..fd32a1b 100644 --- a/chrome/browser/ui/search/instant_ntp_prerenderer.cc +++ b/chrome/browser/ui/search/instant_ntp_prerenderer.cc @@ -133,7 +133,8 @@ std::string InstantNTPPrerenderer::GetInstantURL() const { // TODO(kmadhusu): Remove start margin param from chrome::GetInstantURL(). const GURL instant_url = chrome::GetInstantURL(profile_, - chrome::kDisableStartMargin); + chrome::kDisableStartMargin, + false); if (!instant_url.is_valid()) return GetLocalInstantURL(); diff --git a/chrome/test/data/diagnostics/user/Default/Preferences b/chrome/test/data/diagnostics/user/Default/Preferences index 4f348af..0718051 100644 --- a/chrome/test/data/diagnostics/user/Default/Preferences +++ b/chrome/test/data/diagnostics/user/Default/Preferences @@ -22,7 +22,7 @@ "encodings": "UTF-8", "icon_url": "http://www.google.com/favicon.ico", "id": "2", - "instant_url": "{google:baseURL}webhp?sourceid=chrome-instant&{google:RLZ}{google:instantEnabledParameter}{google:instantExtendedEnabledParameter}{google:ntpIsThemedParameter}{google:omniboxStartMarginParameter}ie={inputEncoding}", + "instant_url": "{google:baseURL}webhp?sourceid=chrome-instant&{google:RLZ}{google:forceInstantResults}{google:instantExtendedEnabledParameter}{google:ntpIsThemedParameter}{google:omniboxStartMarginParameter}ie={inputEncoding}", "keyword": "google.com", "name": "Google", "prepopulate_id": "1", diff --git a/chrome/test/data/page_cycler/cached_data_dir/Default/Preferences b/chrome/test/data/page_cycler/cached_data_dir/Default/Preferences index 422def0..6b8419f 100644 --- a/chrome/test/data/page_cycler/cached_data_dir/Default/Preferences +++ b/chrome/test/data/page_cycler/cached_data_dir/Default/Preferences @@ -34,7 +34,7 @@ "encodings": "UTF-8", "icon_url": "http://www.google.com/favicon.ico", "id": "2", - "instant_url": "{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&{google:instantFieldTrialGroupParameter}ie={inputEncoding}{google:instantEnabledParameter}{searchTerms}", + "instant_url": "{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&{google:instantFieldTrialGroupParameter}ie={inputEncoding}{google:forceInstantResults}{searchTerms}", "keyword": "google.com", "name": "Google", "prepopulate_id": "1", |