summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkerz@chromium.org <kerz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 00:36:27 +0000
committerkerz@chromium.org <kerz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 00:36:27 +0000
commitc51fd9d50084efb1bd7680d64747bf7f767999da (patch)
tree75a3aca0c146f72271265b1e650060d892ef5e99
parent2c72a0e310e3bc0c9a6c83d5501c29533c0e68ba (diff)
downloadchromium_src-c51fd9d50084efb1bd7680d64747bf7f767999da.zip
chromium_src-c51fd9d50084efb1bd7680d64747bf7f767999da.tar.gz
chromium_src-c51fd9d50084efb1bd7680d64747bf7f767999da.tar.bz2
Merge 152067 - Let url filter test the scheme in urlContains/Equals/Prefix/Suffix criteria
BUG=140238 Review URL: https://chromiumcodereview.appspot.com/10823313 TBR=battre@chromium.org Review URL: https://chromiumcodereview.appspot.com/10859003 git-svn-id: svn://svn.chromium.org/chrome/branches/1229/src@152447 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/extensions/api/events.json8
-rw-r--r--chrome/common/extensions/docs/apps/events.html8
-rw-r--r--chrome/common/extensions/docs/extensions/events.html8
-rw-r--r--chrome/common/extensions/matcher/url_matcher.cc42
-rw-r--r--chrome/common/extensions/matcher/url_matcher_unittest.cc36
5 files changed, 67 insertions, 35 deletions
diff --git a/chrome/common/extensions/api/events.json b/chrome/common/extensions/api/events.json
index da3369413..4b505cf 100644
--- a/chrome/common/extensions/api/events.json
+++ b/chrome/common/extensions/api/events.json
@@ -256,22 +256,22 @@
},
"urlContains": {
"type": "string",
- "description": "Matches if the URL contains a specified string.",
+ "description": "Matches if the URL (without fragment identifier) contains a specified string. Port numbers are stripped from the URL if they match the default port number.",
"optional": true
},
"urlEquals": {
"type": "string",
- "description": "Matches if the URL is equal to a specified string.",
+ "description": "Matches if the URL (without fragment identifier) is equal to a specified string. Port numbers are stripped from the URL if they match the default port number.",
"optional": true
},
"urlPrefix": {
"type": "string",
- "description": "Matches if the URL starts with a specified string.",
+ "description": "Matches if the URL (without fragment identifier) starts with a specified string. Port numbers are stripped from the URL if they match the default port number.",
"optional": true
},
"urlSuffix": {
"type": "string",
- "description": "Matches if the URL ends with a specified string.",
+ "description": "Matches if the URL (without fragment identifier) ends with a specified string. Port numbers are stripped from the URL if they match the default port number.",
"optional": true
},
"schemes": {
diff --git a/chrome/common/extensions/docs/apps/events.html b/chrome/common/extensions/docs/apps/events.html
index e4edf3d..320b141 100644
--- a/chrome/common/extensions/docs/apps/events.html
+++ b/chrome/common/extensions/docs/apps/events.html
@@ -1265,7 +1265,7 @@ refers to an array of rules including filled optional parameters.
</div>
</em>
</dt>
- <dd>Matches if the URL contains a specified string.</dd>
+ <dd>Matches if the URL (without fragment identifier) contains a specified string. Port numbers are stripped from the URL if they match the default port number.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
@@ -1289,7 +1289,7 @@ refers to an array of rules including filled optional parameters.
</div>
</em>
</dt>
- <dd>Matches if the URL is equal to a specified string.</dd>
+ <dd>Matches if the URL (without fragment identifier) is equal to a specified string. Port numbers are stripped from the URL if they match the default port number.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
@@ -1313,7 +1313,7 @@ refers to an array of rules including filled optional parameters.
</div>
</em>
</dt>
- <dd>Matches if the URL starts with a specified string.</dd>
+ <dd>Matches if the URL (without fragment identifier) starts with a specified string. Port numbers are stripped from the URL if they match the default port number.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
@@ -1337,7 +1337,7 @@ refers to an array of rules including filled optional parameters.
</div>
</em>
</dt>
- <dd>Matches if the URL ends with a specified string.</dd>
+ <dd>Matches if the URL (without fragment identifier) ends with a specified string. Port numbers are stripped from the URL if they match the default port number.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
diff --git a/chrome/common/extensions/docs/extensions/events.html b/chrome/common/extensions/docs/extensions/events.html
index 7874258..88ae41c 100644
--- a/chrome/common/extensions/docs/extensions/events.html
+++ b/chrome/common/extensions/docs/extensions/events.html
@@ -1395,7 +1395,7 @@ refers to an array of rules including filled optional parameters.
</div>
</em>
</dt>
- <dd>Matches if the URL contains a specified string.</dd>
+ <dd>Matches if the URL (without fragment identifier) contains a specified string. Port numbers are stripped from the URL if they match the default port number.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
@@ -1419,7 +1419,7 @@ refers to an array of rules including filled optional parameters.
</div>
</em>
</dt>
- <dd>Matches if the URL is equal to a specified string.</dd>
+ <dd>Matches if the URL (without fragment identifier) is equal to a specified string. Port numbers are stripped from the URL if they match the default port number.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
@@ -1443,7 +1443,7 @@ refers to an array of rules including filled optional parameters.
</div>
</em>
</dt>
- <dd>Matches if the URL starts with a specified string.</dd>
+ <dd>Matches if the URL (without fragment identifier) starts with a specified string. Port numbers are stripped from the URL if they match the default port number.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
@@ -1467,7 +1467,7 @@ refers to an array of rules including filled optional parameters.
</div>
</em>
</dt>
- <dd>Matches if the URL ends with a specified string.</dd>
+ <dd>Matches if the URL (without fragment identifier) ends with a specified string. Port numbers are stripped from the URL if they match the default port number.</dd>
<!-- OBJECT PROPERTIES -->
<!-- OBJECT METHODS -->
<!-- OBJECT EVENT FIELDS -->
diff --git a/chrome/common/extensions/matcher/url_matcher.cc b/chrome/common/extensions/matcher/url_matcher.cc
index 722efd9..0eb5ab5 100644
--- a/chrome/common/extensions/matcher/url_matcher.cc
+++ b/chrome/common/extensions/matcher/url_matcher.cc
@@ -8,7 +8,9 @@
#include <iterator>
#include "base/logging.h"
+#include "content/public/common/url_constants.h"
#include "googleurl/src/gurl.h"
+#include "googleurl/src/url_canon.h"
namespace extensions {
@@ -88,19 +90,23 @@ namespace extensions {
// Case 2: url_{prefix,suffix,equals,contains} searches.
// =====================================================
//
-// Step 1: as above
+// Step 1: as above, except that
+// - the scheme is not removed
+// - the port is not removed if it is specified and does not match the default
+// port for the given scheme.
//
// Step 2:
// Translate URL to String and add the following position markers:
// - BU = Beginning of URL
// - EU = End of URL
-// Furthermore, the hostname is canonicalized to start with a ".".
//
-// -> www.example.com/index.html?search=foo becomes
-// BU .www.example.com/index.html?search=foo EU
+// -> http://www.example.com:8080/index.html?search=foo#first_match becomes
+// BU http://www.example.com:8080/index.html?search=foo EU
+// -> http://www.example.com:80/index.html?search=foo#first_match becomes
+// BU http://www.example.com/index.html?search=foo EU
//
-// url_prefix(prefix) = BU add_missing_dot_prefix(prefix)
-// -> url_prefix("www.example") = BU .www.example
+// url_prefix(prefix) = BU prefix
+// -> url_prefix("http://www.example") = BU http://www.example
//
// url_contains(substring) = substring
// -> url_contains("index") = index
@@ -113,7 +119,7 @@ namespace extensions {
// by a combination of a url_contains() query followed by an explicit test:
//
// host_contains(str) = url_contains(str) followed by test whether str occurs
-// in host comonent of original URL.
+// in host component of original URL.
// -> host_contains("example.co") = example.co
// followed by gurl.host().find("example.co");
//
@@ -160,7 +166,7 @@ bool URLMatcherCondition::operator<(const URLMatcherCondition& rhs) const {
bool URLMatcherCondition::IsFullURLCondition() const {
// For these criteria the SubstringMatcher needs to be executed on the
- // GURL that is canonlizaliced with
+ // GURL that is canonicalized with
// URLMatcherConditionFactory::CanonicalizeURLForFullSearches.
switch (criterion_) {
case HOST_CONTAINS:
@@ -314,14 +320,26 @@ URLMatcherConditionFactory::CreateHostEqualsPathPrefixCondition(
std::string URLMatcherConditionFactory::CanonicalizeURLForFullSearches(
const GURL& url) {
- return kBeginningOfURL + CanonicalizeHostname(url.host()) + url.path() +
- (url.has_query() ? "?" + url.query() : "") + kEndOfURL;
+ GURL::Replacements replacements;
+ replacements.ClearPassword();
+ replacements.ClearUsername();
+ replacements.ClearRef();
+ // Clear port if it is implicit from scheme.
+ if (url.has_port()) {
+ const std::string& port = url.scheme();
+ if (url_canon::DefaultPortForScheme(port.c_str(), port.size()) ==
+ url.EffectiveIntPort()) {
+ replacements.ClearPort();
+ }
+ }
+ return kBeginningOfURL + url.ReplaceComponents(replacements).spec() +
+ kEndOfURL;
}
URLMatcherCondition URLMatcherConditionFactory::CreateURLPrefixCondition(
const std::string& prefix) {
return CreateCondition(URLMatcherCondition::URL_PREFIX,
- kBeginningOfURL + CanonicalizeHostname(prefix));
+ kBeginningOfURL + prefix);
}
URLMatcherCondition URLMatcherConditionFactory::CreateURLSuffixCondition(
@@ -337,7 +355,7 @@ URLMatcherCondition URLMatcherConditionFactory::CreateURLContainsCondition(
URLMatcherCondition URLMatcherConditionFactory::CreateURLEqualsCondition(
const std::string& str) {
return CreateCondition(URLMatcherCondition::URL_EQUALS,
- kBeginningOfURL + CanonicalizeHostname(str) + kEndOfURL);
+ kBeginningOfURL + str + kEndOfURL);
}
void URLMatcherConditionFactory::ForgetUnusedPatterns(
diff --git a/chrome/common/extensions/matcher/url_matcher_unittest.cc b/chrome/common/extensions/matcher/url_matcher_unittest.cc
index add8530..acf414f 100644
--- a/chrome/common/extensions/matcher/url_matcher_unittest.cc
+++ b/chrome/common/extensions/matcher/url_matcher_unittest.cc
@@ -230,7 +230,7 @@ TEST(URLMatcherConditionFactoryTest, TestSingletonProperty) {
}
TEST(URLMatcherConditionFactoryTest, TestComponentSearches) {
- GURL gurl("https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8"
+ GURL gurl("https://www.google.com:1234/webhp?sourceid=chrome-instant&ie=UTF-8"
"&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome");
URLMatcherConditionFactory factory;
std::string url = factory.CanonicalizeURLForComponentSearches(gurl);
@@ -326,18 +326,21 @@ TEST(URLMatcherConditionFactoryTest, TestComponentSearches) {
}
TEST(URLMatcherConditionFactoryTest, TestFullSearches) {
- GURL gurl("https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8"
+ // The Port 443 is stripped because it is the default port for https.
+ GURL gurl("https://www.google.com:443/webhp?sourceid=chrome-instant&ie=UTF-8"
"&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome");
URLMatcherConditionFactory factory;
std::string url = factory.CanonicalizeURLForFullSearches(gurl);
EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(""), url));
- EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition("www.goog"), url));
- EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition("www.google.com"), url));
- EXPECT_TRUE(
- Matches(factory.CreateURLPrefixCondition(".www.google.com"), url));
- EXPECT_TRUE(
- Matches(factory.CreateURLPrefixCondition("www.google.com/"), url));
+ EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(
+ "https://www.goog"), url));
+ EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(
+ "https://www.google.com"), url));
+ EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(
+ "https://www.google.com/webhp?"), url));
+ EXPECT_FALSE(Matches(factory.CreateURLPrefixCondition(
+ "http://www.google.com"), url));
EXPECT_FALSE(Matches(factory.CreateURLPrefixCondition("webhp"), url));
EXPECT_TRUE(Matches(factory.CreateURLSuffixCondition(""), url));
@@ -346,18 +349,29 @@ TEST(URLMatcherConditionFactoryTest, TestFullSearches) {
EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(""), url));
EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("www.goog"), url));
- EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(".www.goog"), url));
EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("webhp"), url));
EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("?"), url));
EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("sourceid"), url));
EXPECT_TRUE(Matches(factory.CreateURLContainsCondition("ion=1"), url));
+ EXPECT_FALSE(Matches(factory.CreateURLContainsCondition(".www.goog"), url));
EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("foobar"), url));
EXPECT_FALSE(Matches(factory.CreateURLContainsCondition("search"), url));
+ EXPECT_FALSE(Matches(factory.CreateURLContainsCondition(":443"), url));
EXPECT_TRUE(Matches(factory.CreateURLEqualsCondition(
- "www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1"), url));
+ "https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1"),
+ url));
EXPECT_FALSE(
- Matches(factory.CreateURLEqualsCondition("www.google.com"), url));
+ Matches(factory.CreateURLEqualsCondition("https://www.google.com"), url));
+
+ // Same as above but this time with a non-standard port.
+ gurl = GURL("https://www.google.com:1234/webhp?sourceid=chrome-instant&"
+ "ie=UTF-8&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20"
+ "awesome");
+ url = factory.CanonicalizeURLForFullSearches(gurl);
+ EXPECT_TRUE(Matches(factory.CreateURLPrefixCondition(
+ "https://www.google.com:1234/webhp?"), url));
+ EXPECT_TRUE(Matches(factory.CreateURLContainsCondition(":1234"), url));
}