Chromium Code Reviews| Index: chrome/common/extensions/url_pattern.cc |
| diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc |
| index ac648114aaed54e93ec873b92dbd71afe384ae42..c39768f43872b94fd4645bc5487b4420c7c93785 100644 |
| --- a/chrome/common/extensions/url_pattern.cc |
| +++ b/chrome/common/extensions/url_pattern.cc |
| @@ -67,7 +67,7 @@ COMPILE_ASSERT(URLPattern::NUM_PARSE_RESULTS == arraysize(kParseResultMessages), |
| const char kPathSeparator[] = "/"; |
| -bool IsStandardScheme(const std::string& scheme) { |
| +bool is_standard_scheme(const std::string& scheme) { |
|
Aaron Boodman
2012/03/21 23:51:57
Why rename this? I think the current capitalizatio
ericu
2012/03/22 00:22:14
You requested this change in your comments on patc
|
| // "*" gets the same treatment as a standard scheme. |
| if (scheme == "*") |
| return true; |
| @@ -97,12 +97,14 @@ bool IsValidPortForScheme(const std::string scheme, const std::string& port) { |
| URLPattern::URLPattern() |
| : valid_schemes_(SCHEME_NONE), |
| match_all_urls_(false), |
| + match_nested_url_path_(false), |
| match_subdomains_(false), |
| port_("*") {} |
| URLPattern::URLPattern(int valid_schemes) |
| : valid_schemes_(valid_schemes), |
| match_all_urls_(false), |
| + match_nested_url_path_(false), |
| match_subdomains_(false), |
| port_("*") {} |
| @@ -111,6 +113,7 @@ URLPattern::URLPattern(int valid_schemes, const std::string& pattern) |
| // appropriate when we know |pattern| is valid. |
| : valid_schemes_(valid_schemes), |
| match_all_urls_(false), |
| + match_nested_url_path_(false), |
| match_subdomains_(false), |
| port_("*") { |
| if (PARSE_SUCCESS != Parse(pattern)) |
| @@ -156,7 +159,7 @@ URLPattern::ParseResult URLPattern::Parse(const std::string& pattern) { |
| if (!SetScheme(pattern.substr(0, scheme_end_pos))) |
| return PARSE_ERROR_INVALID_SCHEME; |
| - bool standard_scheme = IsStandardScheme(scheme_); |
| + bool standard_scheme = is_standard_scheme(scheme_); |
| if (standard_scheme != has_standard_scheme_separator) |
| return PARSE_ERROR_WRONG_SCHEME_SEPARATOR; |
| @@ -249,6 +252,10 @@ void URLPattern::SetMatchAllURLs(bool val) { |
| } |
| } |
| +void URLPattern::SetMatchNestedURLPath(bool val) { |
|
Aaron Boodman
2012/03/21 23:51:57
This one on the other hand should be set_match_nes
ericu
2012/03/22 00:22:14
Done.
|
| + match_nested_url_path_ = val; |
| +} |
| + |
| void URLPattern::SetMatchSubdomains(bool val) { |
| spec_.clear(); |
| match_subdomains_ = val; |
| @@ -295,14 +302,25 @@ bool URLPattern::SetPort(const std::string& port) { |
| } |
| bool URLPattern::MatchesURL(const GURL& test) const { |
| - if (!MatchesScheme(test.scheme())) |
| + const GURL* test_url = &test; |
| + bool has_inner_url = false; |
| + if (test.inner_url()) { |
| + test_url = test.inner_url(); |
| + has_inner_url = true; |
| + } |
| + |
| + if (!MatchesScheme(test_url->scheme())) |
| return false; |
| if (match_all_urls_) |
| return true; |
| - return MatchesSecurityOriginHelper(test) && |
| - MatchesPath(test.PathForRequest()); |
| + std::string path_for_request = test.PathForRequest(); |
| + if (has_inner_url) { |
| + path_for_request = test_url->path() + path_for_request; |
| + } |
| + return MatchesSecurityOriginHelper(*test_url) && |
| + MatchesPath(path_for_request, has_inner_url); |
| } |
| bool URLPattern::MatchesSecurityOrigin(const GURL& test) const { |
| @@ -361,7 +379,10 @@ bool URLPattern::MatchesHost(const GURL& test) const { |
| return test.host()[test.host().length() - host_.length() - 1] == '.'; |
| } |
| -bool URLPattern::MatchesPath(const std::string& test) const { |
| +bool URLPattern::MatchesPath(const std::string& test, bool nested_url) |
| + const { |
| + if (nested_url != match_nested_url_path_ && path_ != "/*") |
| + return false; |
| if (!MatchPattern(test, path_escaped_)) |
| return false; |
| @@ -385,7 +406,7 @@ const std::string& URLPattern::GetAsString() const { |
| return spec_; |
| } |
| - bool standard_scheme = IsStandardScheme(scheme_); |
| + bool standard_scheme = is_standard_scheme(scheme_); |
| std::string spec = scheme_ + |
| (standard_scheme ? chrome::kStandardSchemeSeparator : ":"); |
| @@ -433,8 +454,14 @@ bool URLPattern::OverlapsWith(const URLPattern& other) const { |
| 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))) |
| + if ((path_.size() > 2 || other.path().size() > 2) && |
| + match_nested_url_path_ != other.match_nested_url_path()) |
| + return false; |
| + |
| + if (!MatchesPath(other.path().substr(0, other.path().size() - 1), |
| + match_nested_url_path_) && |
| + !other.MatchesPath(path_.substr(0, path_.size() - 1), |
| + match_nested_url_path_)) |
| return false; |
| return true; |