summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines
diff options
context:
space:
mode:
authorsreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-14 03:39:32 +0000
committersreeram@chromium.org <sreeram@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-14 03:39:32 +0000
commit7c60f50438f48400252f330c313a99897b5b7ca9 (patch)
tree1ffacb67392a7fe10a8eb0a51ef620010463d16c /chrome/browser/search_engines
parentd0a62f0d356c745c0d40e3014910984aeeff6ef4 (diff)
downloadchromium_src-7c60f50438f48400252f330c313a99897b5b7ca9.zip
chromium_src-7c60f50438f48400252f330c313a99897b5b7ca9.tar.gz
chromium_src-7c60f50438f48400252f330c313a99897b5b7ca9.tar.bz2
Consolidate search terms extraction and Instant process determination.
Reverts changes made to template_url.* in http://crrev.com/178755. BUG=170390 R=dhollowa@chromium.org,pkasting@chromium.org,sky@chromium.org TEST=none; no visible changes. Review URL: https://chromiumcodereview.appspot.com/12250033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182381 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines')
-rw-r--r--chrome/browser/search_engines/template_url.cc36
-rw-r--r--chrome/browser/search_engines/template_url.h15
-rw-r--r--chrome/browser/search_engines/template_url_unittest.cc110
3 files changed, 11 insertions, 150 deletions
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 24abf88..a14bbc4 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -416,11 +416,6 @@ std::string TemplateURLRef::DisplayURLToURLRef(
return UTF16ToUTF8(result);
}
-const std::string& TemplateURLRef::GetScheme() const {
- ParseIfNecessary();
- return scheme_;
-}
-
const std::string& TemplateURLRef::GetHost() const {
ParseIfNecessary();
return host_;
@@ -524,7 +519,6 @@ bool TemplateURLRef::ExtractSearchTermsFromURL(const GURL& url,
void TemplateURLRef::InvalidateCachedValues() const {
supports_replacements_ = valid_ = parsed_ = false;
- scheme_.clear();
host_.clear();
path_.clear();
search_term_key_.clear();
@@ -691,7 +685,6 @@ void TemplateURLRef::ParseHostAndSearchTermKey(
search_terms_data.GoogleBaseSuggestURLValue());
search_term_key_.clear();
- scheme_.clear();
host_.clear();
path_.clear();
search_term_key_location_ = url_parse::Parsed::REF;
@@ -707,7 +700,6 @@ void TemplateURLRef::ParseHostAndSearchTermKey(
search_term_key_ = query_key.empty() ? ref_key : query_key;
search_term_key_location_ = query_key.empty() ?
url_parse::Parsed::REF : url_parse::Parsed::QUERY;
- scheme_ = url.scheme();
host_ = url.host();
path_ = url.path();
}
@@ -878,34 +870,6 @@ bool TemplateURL::HasSearchTermsReplacementKey(const GURL& url) const {
return false;
}
-bool TemplateURL::IsInstantURL(const GURL& url) {
- // If the url matches the Instant ref, there's no need to
- // check the replacement-key parameter, since we know this
- // is instant.
- // TODO(dhollowa): http://crbug.com/170390. Consolidate Instant URL checks.
- TemplateURLRef ref(this, TemplateURLRef::INSTANT);
- GURL instant_url(ref.ReplaceSearchTerms(
- TemplateURLRef::SearchTermsArgs(string16())));
- if (instant_url.scheme() == url.scheme() &&
- instant_url.host() == url.host() &&
- instant_url.path() == url.path())
- return true;
-
- // Anything else requires the existence of the replacement-key.
- if (!HasSearchTermsReplacementKey(url))
- return false;
-
- for (size_t i = 0; i < URLCount(); ++i) {
- TemplateURLRef ref(this, i);
- if (ref.GetScheme() == url.scheme() &&
- ref.GetHost() == url.host() &&
- ref.GetPath() == url.path())
- return true;
- }
-
- return false;
-}
-
void TemplateURL::CopyFrom(const TemplateURL& other) {
if (this == &other)
return;
diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h
index e81d671..d2d2c48 100644
--- a/chrome/browser/search_engines/template_url.h
+++ b/chrome/browser/search_engines/template_url.h
@@ -121,8 +121,7 @@ class TemplateURLRef {
static std::string DisplayURLToURLRef(const string16& display_url);
// If this TemplateURLRef is valid and contains one search term, this returns
- // the scheme/host/path of the URL, otherwise this returns an empty string.
- const std::string& GetScheme() const;
+ // the host/path of the URL, otherwise this returns an empty string.
const std::string& GetHost() const;
const std::string& GetPath() const;
@@ -252,9 +251,8 @@ class TemplateURLRef {
// into the string, and may be empty.
mutable Replacements replacements_;
- // Scheme, host, path, key and location of the search term. These are only set
- // if the url contains one search term.
- mutable std::string scheme_;
+ // Host, path, key and location of the search term. These are only set if the
+ // url contains one search term.
mutable std::string host_;
mutable std::string path_;
mutable std::string search_term_key_;
@@ -493,13 +491,6 @@ class TemplateURL {
// InstantExtended capable URL.
bool HasSearchTermsReplacementKey(const GURL& url) const;
- // Returns true if the specified |url| matches the search, alternates, or
- // instant url in scheme, domain, and path. In addition, the search term
- // replacement key must be present in the |url|.
- // This predicate is used for site isolation purposes, so has security
- // implications. Seek security review if changing it.
- bool IsInstantURL(const GURL& url);
-
private:
friend class TemplateURLService;
diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc
index 5550b03..3273fa5 100644
--- a/chrome/browser/search_engines/template_url_unittest.cc
+++ b/chrome/browser/search_engines/template_url_unittest.cc
@@ -539,37 +539,35 @@ TEST_F(TemplateURLTest, RLZ) {
TEST_F(TemplateURLTest, HostAndSearchTermKey) {
struct TestData {
const std::string url;
- const std::string scheme;
const std::string host;
const std::string path;
const std::string search_term_key;
} test_data[] = {
- { "http://blah/?foo=bar&q={searchTerms}&b=x", "http", "blah", "/", "q"},
+ { "http://blah/?foo=bar&q={searchTerms}&b=x", "blah", "/", "q"},
// No query key should result in empty values.
- { "http://blah/{searchTerms}", "", "", "", ""},
+ { "http://blah/{searchTerms}", "", "", ""},
// No term should result in empty values.
- { "http://blah/", "", "", "", ""},
+ { "http://blah/", "", "", ""},
// Multiple terms should result in empty values.
- { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", "", ""},
+ { "http://blah/?q={searchTerms}&x={searchTerms}", "", "", ""},
// Term in the host shouldn't match.
- { "http://{searchTerms}", "", "", "", ""},
+ { "http://{searchTerms}", "", "", ""},
- { "http://blah/?q={searchTerms}", "http", "blah", "/", "q"},
- { "https://blah/?q={searchTerms}", "https", "blah", "/", "q"},
+ { "http://blah/?q={searchTerms}", "blah", "/", "q"},
+ { "https://blah/?q={searchTerms}", "blah", "/", "q"},
// Single term with extra chars in value should match.
- { "http://blah/?q=stock:{searchTerms}", "http", "blah", "/", "q"},
+ { "http://blah/?q=stock:{searchTerms}", "blah", "/", "q"},
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
TemplateURLData data;
data.SetURL(test_data[i].url);
TemplateURL url(NULL, data);
- EXPECT_EQ(test_data[i].scheme, url.url_ref().GetScheme());
EXPECT_EQ(test_data[i].host, url.url_ref().GetHost());
EXPECT_EQ(test_data[i].path, url.url_ref().GetPath());
EXPECT_EQ(test_data[i].search_term_key, url.url_ref().GetSearchTermKey());
@@ -927,95 +925,3 @@ TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) {
EXPECT_TRUE(url.HasSearchTermsReplacementKey(
GURL("http://bing.com/#espv")));
}
-
-TEST_F(TemplateURLTest, IsInstantURL) {
- TemplateURLData data;
- data.SetURL("http://google.com/?q={searchTerms}");
- data.instant_url = "http://google.com/instant#q={searchTerms}";
- data.alternate_urls.push_back("http://google.com/alt/#q={searchTerms}");
- data.alternate_urls.push_back(
- "http://google.com/alt/?ext=foo&q={searchTerms}#ref=bar");
- data.search_terms_replacement_key = "espv";
- TemplateURL url(NULL, data);
-
- EXPECT_FALSE(url.IsInstantURL(
- GURL("http://google.com/")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?espv")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/#espv")));
-
- EXPECT_FALSE(url.IsInstantURL(
- GURL("http://google.com/?q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/instant?q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/instant?x=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?q=something&espv")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?q=something&espv=1")));
-
- EXPECT_FALSE(url.IsInstantURL(
- GURL("https://google.com/?q=something&espv=1")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?q=something&espv=0")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?espv&q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?espv=1&q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?espv=0&q=something")));
-
- EXPECT_FALSE(url.IsInstantURL(
- GURL("http://google.com/alt/#q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/alt/#q=something&espv")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/alt/#q=something&espv=1")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/alt/#q=something&espv=0")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/alt/#espv&q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/alt/#espv=1&q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/alt/#espv=0&q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?espv#q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?espv=1#q=something")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?q=something#espv")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/?q=something#espv=1")));
-
- EXPECT_TRUE(url.IsInstantURL(
- GURL("http://google.com/instant#q=something&espv=1")));
-
- EXPECT_FALSE(url.IsInstantURL(
- GURL("http://bing.com/?espv=1")));
-
- EXPECT_FALSE(url.IsInstantURL(
- GURL("http://bing.com/#espv=1")));
-}