summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/url_pattern.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-26 06:35:02 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-26 06:35:02 +0000
commit22c966cde1eab5e2c25c295467b5a7549ab1324c (patch)
tree3088411fc203d8d7a8ac39ccbfe5fa5d263e74f1 /chrome/common/extensions/url_pattern.cc
parent0bf0ce3331ea4e597b47126dd71c6448fdc4fc5f (diff)
downloadchromium_src-22c966cde1eab5e2c25c295467b5a7549ab1324c.zip
chromium_src-22c966cde1eab5e2c25c295467b5a7549ab1324c.tar.gz
chromium_src-22c966cde1eab5e2c25c295467b5a7549ab1324c.tar.bz2
Re-implement app overlap detection with new extent syntax.
BUG=47445 Review URL: http://codereview.chromium.org/2876009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/url_pattern.cc')
-rw-r--r--chrome/common/extensions/url_pattern.cc28
1 files changed, 25 insertions, 3 deletions
diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc
index 41a5f6e..2b1e4ce 100644
--- a/chrome/common/extensions/url_pattern.cc
+++ b/chrome/common/extensions/url_pattern.cc
@@ -98,7 +98,7 @@ bool URLPattern::MatchesUrl(const GURL &test) const {
if (!MatchesHost(test))
return false;
- if (!MatchesPath(test))
+ if (!MatchesPath(test.PathForRequest()))
return false;
return true;
@@ -143,14 +143,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;
@@ -173,3 +173,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;
+}