Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Unified Diff: chrome/browser/search/search.cc

Issue 17022004: Replace --google-base-suggest-url and --instant-url with --google-base-url. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search/search.h ('k') | chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/search.cc
===================================================================
--- chrome/browser/search/search.cc (revision 206485)
+++ chrome/browser/search/search.cc (working copy)
@@ -100,12 +100,6 @@
other_url.SchemeIs(chrome::kHttpScheme)));
}
-bool IsCommandLineInstantURL(const GURL& url) {
- const CommandLine* cl = CommandLine::ForCurrentProcess();
- const GURL instant_url(cl->GetSwitchValueASCII(switches::kInstantURL));
- return instant_url.is_valid() && MatchesOrigin(url, instant_url);
-}
-
bool MatchesAnySearchURL(const GURL& url, TemplateURL* template_url) {
GURL search_url =
TemplateURLRefToGURL(template_url->url_ref(), kDisableStartMargin);
@@ -196,37 +190,31 @@
// Returns true if |url| can be used as an Instant URL for |profile|.
bool IsInstantURL(const GURL& url, Profile* profile) {
+ if (!url.is_valid())
+ return false;
+
TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
if (!template_url)
return false;
- const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
const bool extended_api_enabled = IsInstantExtendedAPIEnabled();
- GURL effective_url = url;
-
- if (IsCommandLineInstantURL(url))
- effective_url = CoerceCommandLineURLToTemplateURL(url, instant_url_ref,
- kDisableStartMargin);
-
- if (!effective_url.is_valid())
+ if (extended_api_enabled && !url.SchemeIsSecure())
samarth 2013/06/17 20:39:37 I ran into two issues while trying out your patch:
return false;
- if (extended_api_enabled && !effective_url.SchemeIsSecure())
- return false;
-
if (extended_api_enabled &&
- !template_url->HasSearchTermsReplacementKey(effective_url))
+ !template_url->HasSearchTermsReplacementKey(url))
return false;
+ const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
const GURL instant_url =
TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin);
if (!instant_url.is_valid())
return false;
- if (MatchesOriginAndPath(effective_url, instant_url))
+ if (MatchesOriginAndPath(url, instant_url))
return true;
- if (extended_api_enabled && MatchesAnySearchURL(effective_url, template_url))
+ if (extended_api_enabled && MatchesAnySearchURL(url, template_url))
return true;
return false;
@@ -312,21 +300,12 @@
return false;
}
-string16 GetSearchTermsFromURL(Profile* profile, const GURL& in_url) {
- GURL url(in_url);
+string16 GetSearchTermsFromURL(Profile* profile, const GURL& url) {
string16 search_terms;
-
TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
- if (!template_url)
- return string16();
-
- if (IsCommandLineInstantURL(url))
- url = CoerceCommandLineURLToTemplateURL(url, template_url->url_ref(),
- kDisableStartMargin);
-
- if (url.SchemeIsSecure() && template_url->HasSearchTermsReplacementKey(url))
+ if (template_url && url.SchemeIsSecure() &&
+ template_url->HasSearchTermsReplacementKey(url))
template_url->ExtractSearchTermsFromURL(url, &search_terms);
-
return search_terms;
}
@@ -490,19 +469,6 @@
return GURL();
TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
- CommandLine* cl = CommandLine::ForCurrentProcess();
- if (cl->HasSwitch(switches::kInstantURL)) {
- GURL instant_url(cl->GetSwitchValueASCII(switches::kInstantURL));
- if (extended_api_enabled) {
- // Extended mode won't work if the search terms replacement key is absent.
- GURL coerced_url = CoerceCommandLineURLToTemplateURL(
- instant_url, template_url->instant_url_ref(), start_margin);
- if (!template_url->HasSearchTermsReplacementKey(coerced_url))
- return GURL();
- }
- return instant_url;
- }
-
GURL instant_url =
TemplateURLRefToGURL(template_url->instant_url_ref(), start_margin);
if (extended_api_enabled && !instant_url.SchemeIsSecure()) {
@@ -707,27 +673,6 @@
return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags);
}
-// Coerces the commandline Instant URL to look like a template URL, so that we
-// can extract search terms from it.
-GURL CoerceCommandLineURLToTemplateURL(const GURL& instant_url,
- const TemplateURLRef& ref,
- int start_margin) {
- GURL search_url = TemplateURLRefToGURL(ref, start_margin);
-
- // NOTE(samarth): GURL returns temporaries which we must save because
- // GURL::Replacements expects the replacements to live until
- // ReplaceComponents is called.
- const std::string search_scheme = chrome::kHttpsScheme;
- const std::string search_host = search_url.host();
- const std::string search_port = search_url.port();
-
- GURL::Replacements replacements;
- replacements.SetSchemeStr(search_scheme);
- replacements.SetHostStr(search_host);
- replacements.SetPortStr(search_port);
- return instant_url.ReplaceComponents(replacements);
-}
-
bool DefaultSearchProviderSupportsInstant(Profile* profile) {
TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
if (!template_url)
« no previous file with comments | « chrome/browser/search/search.h ('k') | chrome/browser/search/search_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698