Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/extensions/url_pattern.h" | 5 #include "chrome/common/extensions/url_pattern.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 if (!base::StringToInt(port, &parsed_port)) | 90 if (!base::StringToInt(port, &parsed_port)) |
| 91 return false; | 91 return false; |
| 92 return (parsed_port >= 0) && (parsed_port < 65536); | 92 return (parsed_port >= 0) && (parsed_port < 65536); |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace | 95 } // namespace |
| 96 | 96 |
| 97 URLPattern::URLPattern() | 97 URLPattern::URLPattern() |
| 98 : valid_schemes_(SCHEME_NONE), | 98 : valid_schemes_(SCHEME_NONE), |
| 99 match_all_urls_(false), | 99 match_all_urls_(false), |
| 100 partial_filesystem_support_hack_(false), | |
| 101 match_subdomains_(false), | 100 match_subdomains_(false), |
| 102 port_("*") {} | 101 port_("*") {} |
| 103 | 102 |
| 104 URLPattern::URLPattern(int valid_schemes) | 103 URLPattern::URLPattern(int valid_schemes) |
| 105 : valid_schemes_(valid_schemes), | 104 : valid_schemes_(valid_schemes), |
| 106 match_all_urls_(false), | 105 match_all_urls_(false), |
| 107 partial_filesystem_support_hack_(false), | |
| 108 match_subdomains_(false), | 106 match_subdomains_(false), |
| 109 port_("*") {} | 107 port_("*") {} |
| 110 | 108 |
| 111 URLPattern::URLPattern(int valid_schemes, const std::string& pattern) | 109 URLPattern::URLPattern(int valid_schemes, const std::string& pattern) |
| 112 // Strict error checking is used, because this constructor is only | 110 // Strict error checking is used, because this constructor is only |
| 113 // appropriate when we know |pattern| is valid. | 111 // appropriate when we know |pattern| is valid. |
| 114 : valid_schemes_(valid_schemes), | 112 : valid_schemes_(valid_schemes), |
| 115 match_all_urls_(false), | 113 match_all_urls_(false), |
| 116 partial_filesystem_support_hack_(false), | |
| 117 match_subdomains_(false), | 114 match_subdomains_(false), |
| 118 port_("*") { | 115 port_("*") { |
| 119 if (PARSE_SUCCESS != Parse(pattern)) | 116 if (PARSE_SUCCESS != Parse(pattern)) |
| 120 NOTREACHED() << "URLPattern is invalid: " << pattern; | 117 NOTREACHED() << "URLPattern is invalid: " << pattern; |
| 121 } | 118 } |
| 122 | 119 |
| 123 URLPattern::~URLPattern() { | 120 URLPattern::~URLPattern() { |
| 124 } | 121 } |
| 125 | 122 |
| 126 bool URLPattern::operator<(const URLPattern& other) const { | 123 bool URLPattern::operator<(const URLPattern& other) const { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 port_ = port; | 291 port_ = port; |
| 295 return true; | 292 return true; |
| 296 } | 293 } |
| 297 return false; | 294 return false; |
| 298 } | 295 } |
| 299 | 296 |
| 300 bool URLPattern::MatchesURL(const GURL& test) const { | 297 bool URLPattern::MatchesURL(const GURL& test) const { |
| 301 const GURL* test_url = &test; | 298 const GURL* test_url = &test; |
| 302 bool has_inner_url = test.inner_url() != NULL; | 299 bool has_inner_url = test.inner_url() != NULL; |
| 303 | 300 |
| 304 if (partial_filesystem_support_hack_ != has_inner_url) | |
| 305 return false; | |
| 306 | |
| 307 if (has_inner_url) | 301 if (has_inner_url) |
| 308 test_url = test.inner_url(); | 302 test_url = test.inner_url(); |
| 309 | 303 |
| 310 if (!MatchesScheme(test_url->scheme())) | 304 if (!MatchesScheme(test_url->scheme())) |
|
Aaron Boodman
2012/05/02 04:04:05
Perhaps this only makes sense for the filesystem s
ericu
2012/05/02 16:51:16
That makes sense. Done.
| |
| 311 return false; | 305 return false; |
| 312 | 306 |
| 313 if (match_all_urls_) | 307 if (match_all_urls_) |
| 314 return true; | 308 return true; |
| 315 | 309 |
| 316 std::string path_for_request = test.PathForRequest(); | 310 std::string path_for_request = test.PathForRequest(); |
| 317 if (has_inner_url) | 311 if (has_inner_url) |
| 318 path_for_request = test_url->path() + path_for_request; | 312 path_for_request = test_url->path() + path_for_request; |
| 319 | 313 |
| 320 return MatchesSecurityOriginHelper(*test_url) && | 314 return MatchesSecurityOriginHelper(*test_url) && |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 return false; | 436 return false; |
| 443 | 437 |
| 444 // We currently only use OverlapsWith() for the patterns inside | 438 // We currently only use OverlapsWith() for the patterns inside |
| 445 // URLPatternSet. In those cases, we know that the path will have only a | 439 // URLPatternSet. In those cases, we know that the path will have only a |
| 446 // single wildcard at the end. This makes figuring out overlap much easier. It | 440 // single wildcard at the end. This makes figuring out overlap much easier. It |
| 447 // seems like there is probably a computer-sciency way to solve the general | 441 // seems like there is probably a computer-sciency way to solve the general |
| 448 // case, but we don't need that yet. | 442 // case, but we don't need that yet. |
| 449 DCHECK(path_.find('*') == path_.size() - 1); | 443 DCHECK(path_.find('*') == path_.size() - 1); |
| 450 DCHECK(other.path().find('*') == other.path().size() - 1); | 444 DCHECK(other.path().find('*') == other.path().size() - 1); |
| 451 | 445 |
| 452 if (partial_filesystem_support_hack_ != | |
| 453 other.partial_filesystem_support_hack()) | |
| 454 return false; | |
| 455 | |
| 456 if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && | 446 if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && |
| 457 !other.MatchesPath(path_.substr(0, path_.size() - 1))) | 447 !other.MatchesPath(path_.substr(0, path_.size() - 1))) |
| 458 return false; | 448 return false; |
| 459 | 449 |
| 460 return true; | 450 return true; |
| 461 } | 451 } |
| 462 | 452 |
| 463 bool URLPattern::MatchesAnyScheme( | 453 bool URLPattern::MatchesAnyScheme( |
| 464 const std::vector<std::string>& schemes) const { | 454 const std::vector<std::string>& schemes) const { |
| 465 for (std::vector<std::string>::const_iterator i = schemes.begin(); | 455 for (std::vector<std::string>::const_iterator i = schemes.begin(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 } | 502 } |
| 513 | 503 |
| 514 return result; | 504 return result; |
| 515 } | 505 } |
| 516 | 506 |
| 517 // static | 507 // static |
| 518 const char* URLPattern::GetParseResultString( | 508 const char* URLPattern::GetParseResultString( |
| 519 URLPattern::ParseResult parse_result) { | 509 URLPattern::ParseResult parse_result) { |
| 520 return kParseResultMessages[parse_result]; | 510 return kParseResultMessages[parse_result]; |
| 521 } | 511 } |
| OLD | NEW |