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

Unified Diff: chrome/common/extensions/matcher/url_matcher.cc

Issue 10823313: Let url filter test the scheme in urlContains/Equals/Prefix/Suffix criteria (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 4 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
Index: chrome/common/extensions/matcher/url_matcher.cc
diff --git a/chrome/common/extensions/matcher/url_matcher.cc b/chrome/common/extensions/matcher/url_matcher.cc
index 722efd9c3c633e6898c7f4462cdc181fbd387dac..0eb5ab507351d641e4655d34802bbe4bf4224f77 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(
« no previous file with comments | « chrome/common/extensions/docs/samples.json ('k') | chrome/common/extensions/matcher/url_matcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698