Index: chrome/common/extensions/url_pattern.cc |
diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc |
index 4849d4fbe39d21663391e2bd96076cebbffa0bf8..05eff76f2cee60a3f63c423c54dc3753c3d0cf76 100644 |
--- a/chrome/common/extensions/url_pattern.cc |
+++ b/chrome/common/extensions/url_pattern.cc |
@@ -99,12 +99,21 @@ bool URLPattern::MatchesUrl(const GURL &test) const { |
if (!MatchesHost(test)) |
return false; |
- if (!MatchesPath(test)) |
+ if (!MatchesPath(test.PathForRequest())) |
return false; |
return true; |
} |
+bool URLPattern::MatchesHost(const std::string& host) const { |
+ std::string url(chrome::kHttpScheme); |
+ url += chrome::kStandardSchemeSeparator; |
+ url += host; |
+ url += "/"; |
+ |
+ return MatchesHost(GURL(url)); |
+} |
+ |
bool URLPattern::MatchesHost(const GURL& test) const { |
// If the hosts are exactly equal, we have a match. |
if (test.host() == host_) |
@@ -136,14 +145,14 @@ bool URLPattern::MatchesHost(const GURL& test) const { |
return test.host()[test.host().length() - host_.length() - 1] == '.'; |
} |
-bool URLPattern::MatchesPath(const GURL& test) const { |
+bool URLPattern::MatchesPath(const std::string& test) const { |
if (path_escaped_.empty()) { |
path_escaped_ = path_; |
ReplaceSubstringsAfterOffset(&path_escaped_, 0, "\\", "\\\\"); |
ReplaceSubstringsAfterOffset(&path_escaped_, 0, "?", "\\?"); |
} |
- if (!MatchPatternASCII(test.PathForRequest(), path_escaped_)) |
+ if (!MatchPatternASCII(test, path_escaped_)) |
return false; |
return true; |
@@ -166,3 +175,25 @@ std::string URLPattern::GetAsString() const { |
return spec; |
} |
+ |
+bool URLPattern::OverlapsWith(const URLPattern& other) const { |
+ if (scheme_ != other.scheme()) |
+ return false; |
+ |
+ if (!MatchesHost(other.host()) && !other.MatchesHost(host_)) |
+ return false; |
+ |
+ // We currently only use OverlapsWith() for the patterns inside |
+ // ExtensionExtent. In those cases, we know that the path will have only a |
+ // single wildcard at the end. This makes figuring out overlap much easier. It |
+ // seems like there is probably a computer-sciency way to solve the general |
+ // case, but we don't need that yet. |
+ DCHECK(path_.find('*') == path_.size() - 1); |
+ DCHECK(other.path().find('*') == other.path().size() - 1); |
+ |
+ if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && |
+ !other.MatchesPath(path_.substr(0, path_.size() - 1))) |
+ return false; |
+ |
+ return true; |
+} |