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

Unified Diff: extensions/common/url_pattern.cc

Issue 12792005: Allow extensions on chrome:// URLs, when flag is set and permission is explicitly requested (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup Created 7 years, 9 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 | « extensions/common/url_pattern.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/common/url_pattern.cc
diff --git a/extensions/common/url_pattern.cc b/extensions/common/url_pattern.cc
index 820aacf51aa03031f49af356caffc541ef88c666..f46e22ccaa0b8e629a9d60cdeaccd85c59d119d7 100644
--- a/extensions/common/url_pattern.cc
+++ b/extensions/common/url_pattern.cc
@@ -111,12 +111,14 @@ std::string StripTrailingWildcard(const std::string& path) {
URLPattern::URLPattern()
: valid_schemes_(SCHEME_NONE),
+ allowed_schemes_(SCHEME_NONE),
match_all_urls_(false),
match_subdomains_(false),
port_("*") {}
URLPattern::URLPattern(int valid_schemes)
: valid_schemes_(valid_schemes),
+ allowed_schemes_(valid_schemes),
match_all_urls_(false),
match_subdomains_(false),
port_("*") {}
@@ -125,6 +127,7 @@ URLPattern::URLPattern(int valid_schemes, const std::string& pattern)
// Strict error checking is used, because this constructor is only
// appropriate when we know |pattern| is valid.
: valid_schemes_(valid_schemes),
+ allowed_schemes_(valid_schemes),
match_all_urls_(false),
match_subdomains_(false),
port_("*") {
@@ -239,6 +242,8 @@ URLPattern::ParseResult URLPattern::Parse(const std::string& pattern) {
if (host_.find('*') != std::string::npos)
return PARSE_ERROR_INVALID_HOST_WILDCARD;
+ SetAllowedSchemes(valid_schemes_);
+
return PARSE_SUCCESS;
}
@@ -247,6 +252,11 @@ void URLPattern::SetValidSchemes(int valid_schemes) {
valid_schemes_ = valid_schemes;
}
+void URLPattern::SetAllowedSchemes(int allowed_schemes) {
+ spec_.clear();
+ allowed_schemes_ = allowed_schemes;
+}
+
void URLPattern::SetHost(const std::string& host) {
spec_.clear();
host_ = host;
@@ -280,12 +290,20 @@ bool URLPattern::SetScheme(const std::string& scheme) {
return true;
}
+bool URLPattern::IsAllowedScheme(const std::string& scheme) const {
+ return URLPattern::IsSchemeBitSet(scheme, allowed_schemes_);
+}
+
bool URLPattern::IsValidScheme(const std::string& scheme) const {
- if (valid_schemes_ == SCHEME_ALL)
+ return URLPattern::IsSchemeBitSet(scheme, valid_schemes_);
+}
+
+bool URLPattern::IsSchemeBitSet(const std::string& scheme, const int mask) {
+ if (mask == SCHEME_ALL)
return true;
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
- if (scheme == kValidSchemes[i] && (valid_schemes_ & kValidSchemeMasks[i]))
+ if (scheme == kValidSchemes[i] && (mask & kValidSchemeMasks[i]))
return true;
}
@@ -353,7 +371,7 @@ bool URLPattern::MatchesSecurityOrigin(const GURL& test) const {
}
bool URLPattern::MatchesScheme(const std::string& test) const {
- if (!IsValidScheme(test))
+ if (!IsAllowedScheme(test))
return false;
return scheme_ == "*" || test == scheme_;
« no previous file with comments | « extensions/common/url_pattern.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698