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

Unified Diff: extensions/common/url_pattern.cc

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Fix effective TLD wildcard bug, move to Leaky LazyInstance in PermissionsData, removed unnecessary … Created 3 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
Index: extensions/common/url_pattern.cc
diff --git a/extensions/common/url_pattern.cc b/extensions/common/url_pattern.cc
index 6a948b433764baa505ab54d9392bd2b05262bd4f..bf385d210850d5cd5888daed61d18ab7de70099c 100644
--- a/extensions/common/url_pattern.cc
+++ b/extensions/common/url_pattern.cc
@@ -143,12 +143,14 @@ URLPattern::URLPattern()
: valid_schemes_(SCHEME_NONE),
match_all_urls_(false),
match_subdomains_(false),
+ match_effective_tld_(true),
port_("*") {}
URLPattern::URLPattern(int valid_schemes)
: valid_schemes_(valid_schemes),
match_all_urls_(false),
match_subdomains_(false),
+ match_effective_tld_(true),
port_("*") {}
URLPattern::URLPattern(int valid_schemes, const std::string& pattern)
@@ -157,6 +159,7 @@ URLPattern::URLPattern(int valid_schemes, const std::string& pattern)
: valid_schemes_(valid_schemes),
match_all_urls_(false),
match_subdomains_(false),
+ match_effective_tld_(true),
port_("*") {
ParseResult result = Parse(pattern);
if (PARSE_SUCCESS != result)
@@ -185,9 +188,15 @@ std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern) {
}
URLPattern::ParseResult URLPattern::Parse(const std::string& pattern) {
+ return Parse(pattern, DENY_WILDCARD_FOR_EFFECTIVE_TLD);
+}
+
+URLPattern::ParseResult URLPattern::Parse(const std::string& pattern,
+ ParseOptions parse_options) {
spec_.clear();
SetMatchAllURLs(false);
SetMatchSubdomains(false);
+ SetMatchEffectiveTld(true);
SetPort("*");
// Special case pattern to match every valid URL.
@@ -266,6 +275,14 @@ URLPattern::ParseResult URLPattern::Parse(const std::string& pattern) {
host_components.erase(host_components.begin(),
host_components.begin() + 1);
}
+
+ // If explicitly allowed, the last component can optionally be '*' to
+ // match all effective TLDs.
+ if (parse_options == ALLOW_WILDCARD_FOR_EFFECTIVE_TLD &&
+ host_components.size() > 1 && host_components.back() == "*") {
+ match_effective_tld_ = false;
+ host_components.pop_back();
+ }
host_ = base::JoinString(host_components, ".");
path_start_pos = host_end_pos;
@@ -320,6 +337,11 @@ void URLPattern::SetMatchSubdomains(bool val) {
match_subdomains_ = val;
}
+void URLPattern::SetMatchEffectiveTld(bool val) {
+ spec_.clear();
+ match_effective_tld_ = val;
+}
+
bool URLPattern::SetScheme(const std::string& scheme) {
spec_.clear();
scheme_ = scheme;
@@ -419,10 +441,19 @@ bool URLPattern::MatchesHost(const std::string& host) const {
}
bool URLPattern::MatchesHost(const GURL& test) const {
- const base::StringPiece test_host(
- CanonicalizeHostForMatching(test.host_piece()));
+ base::StringPiece test_host(CanonicalizeHostForMatching(test.host_piece()));
const base::StringPiece pattern_host(CanonicalizeHostForMatching(host_));
+ // If we don't care about matching the effective TLD, remove it.
+ if (!match_effective_tld_) {
+ int reg_length = net::registry_controlled_domains::GetRegistryLength(
+ test, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
+ net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
+ if (reg_length > 0) {
+ test_host = test_host.substr(0, test_host.size() - reg_length - 1);
+ }
+ }
+
// If the hosts are exactly equal, we have a match.
if (test_host == pattern_host)
return true;
@@ -522,6 +553,12 @@ const std::string& URLPattern::GetAsString() const {
if (!host_.empty())
spec += host_;
+ if (!match_effective_tld_) {
+ if (!host_.empty())
+ spec += ".";
+ spec += "*";
+ }
+
if (port_ != "*") {
spec += ":";
spec += port_;

Powered by Google App Engine
This is Rietveld 408576698