summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/url_pattern.cc
diff options
context:
space:
mode:
authormihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-23 18:34:21 +0000
committermihaip@chromium.org <mihaip@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-23 18:34:21 +0000
commit65e0e1512469b98cab0e187109b5875f07487853 (patch)
treec30698c96e68016bca23734a2a18c561a2412cb5 /chrome/common/extensions/url_pattern.cc
parent20bc1f8743a9eb9a35004a45493f19803d31d9ee (diff)
downloadchromium_src-65e0e1512469b98cab0e187109b5875f07487853.zip
chromium_src-65e0e1512469b98cab0e187109b5875f07487853.tar.gz
chromium_src-65e0e1512469b98cab0e187109b5875f07487853.tar.bz2
Make URLPattern::OverlapsWith handle wildcards better by expanding them to explicit schemes.
BUG=70126 TEST=no R=asargent@chromium.org Review URL: http://codereview.chromium.org/7049032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/url_pattern.cc')
-rw-r--r--chrome/common/extensions/url_pattern.cc41
1 files changed, 33 insertions, 8 deletions
diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc
index f041256..ad7e937 100644
--- a/chrome/common/extensions/url_pattern.cc
+++ b/chrome/common/extensions/url_pattern.cc
@@ -311,8 +311,10 @@ std::string URLPattern::GetAsString() const {
}
bool URLPattern::OverlapsWith(const URLPattern& other) const {
- if (!MatchesScheme(other.scheme_) && !other.MatchesScheme(scheme_))
+ if (!MatchesAnyScheme(other.GetExplicitSchemes()) &&
+ !other.MatchesAnyScheme(GetExplicitSchemes())) {
return false;
+ }
if (!MatchesHost(other.host()) && !other.MatchesHost(host_))
return false;
@@ -332,26 +334,49 @@ bool URLPattern::OverlapsWith(const URLPattern& other) const {
return true;
}
-std::vector<URLPattern> URLPattern::ConvertToExplicitSchemes() const {
- std::vector<URLPattern> result;
+bool URLPattern::MatchesAnyScheme(
+ const std::vector<std::string>& schemes) const {
+ for (std::vector<std::string>::const_iterator i = schemes.begin();
+ i != schemes.end(); ++i) {
+ if (MatchesScheme(*i))
+ return true;
+ }
+
+ return false;
+}
+
+std::vector<std::string> URLPattern::GetExplicitSchemes() const {
+ std::vector<std::string> result;
if (scheme_ != "*" && !match_all_urls_ && IsValidScheme(scheme_)) {
- result.push_back(*this);
+ result.push_back(scheme_);
return result;
}
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
if (MatchesScheme(kValidSchemes[i])) {
- URLPattern temp = *this;
- temp.SetScheme(kValidSchemes[i]);
- temp.set_match_all_urls(false);
- result.push_back(temp);
+ result.push_back(kValidSchemes[i]);
}
}
return result;
}
+std::vector<URLPattern> URLPattern::ConvertToExplicitSchemes() const {
+ std::vector<std::string> explicit_schemes = GetExplicitSchemes();
+ std::vector<URLPattern> result;
+
+ for (std::vector<std::string>::const_iterator i = explicit_schemes.begin();
+ i != explicit_schemes.end(); ++i) {
+ URLPattern temp = *this;
+ temp.SetScheme(*i);
+ temp.set_match_all_urls(false);
+ result.push_back(temp);
+ }
+
+ return result;
+}
+
// static
const char* URLPattern::GetParseResultString(
URLPattern::ParseResult parse_result) {