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

Unified Diff: chrome/common/extensions/url_pattern.cc

Issue 7049032: Make URLPattern::OverlapsWith handle wildcards better by expanding them to explicit schemes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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
« no previous file with comments | « chrome/common/extensions/url_pattern.h ('k') | chrome/common/extensions/url_pattern_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/url_pattern.cc
diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc
index 986487a27bb68ab44c433908134dcb8e4f75b25b..a97088efc8375acb50746729e64011e1087660f6 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) {
« no previous file with comments | « chrome/common/extensions/url_pattern.h ('k') | chrome/common/extensions/url_pattern_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698