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) | 301 if (has_inner_url) { |
305 return false; | 302 if (!test.SchemeIsFileSystem()) |
Aaron Boodman
2012/05/02 20:03:08
Can this go in MatchesScheme instead, so that the
| |
306 | 303 return false; // The only nested URLs we handle are filesystem URLs. |
307 if (has_inner_url) | |
308 test_url = test.inner_url(); | 304 test_url = test.inner_url(); |
305 } | |
309 | 306 |
310 if (!MatchesScheme(test_url->scheme())) | 307 if (!MatchesScheme(test_url->scheme())) |
311 return false; | 308 return false; |
312 | 309 |
313 if (match_all_urls_) | 310 if (match_all_urls_) |
314 return true; | 311 return true; |
315 | 312 |
316 std::string path_for_request = test.PathForRequest(); | 313 std::string path_for_request = test.PathForRequest(); |
317 if (has_inner_url) | 314 if (has_inner_url) |
318 path_for_request = test_url->path() + path_for_request; | 315 path_for_request = test_url->path() + path_for_request; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 return false; | 439 return false; |
443 | 440 |
444 // We currently only use OverlapsWith() for the patterns inside | 441 // We currently only use OverlapsWith() for the patterns inside |
445 // URLPatternSet. In those cases, we know that the path will have only a | 442 // 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 | 443 // 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 | 444 // seems like there is probably a computer-sciency way to solve the general |
448 // case, but we don't need that yet. | 445 // case, but we don't need that yet. |
449 DCHECK(path_.find('*') == path_.size() - 1); | 446 DCHECK(path_.find('*') == path_.size() - 1); |
450 DCHECK(other.path().find('*') == other.path().size() - 1); | 447 DCHECK(other.path().find('*') == other.path().size() - 1); |
451 | 448 |
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)) && | 449 if (!MatchesPath(other.path().substr(0, other.path().size() - 1)) && |
457 !other.MatchesPath(path_.substr(0, path_.size() - 1))) | 450 !other.MatchesPath(path_.substr(0, path_.size() - 1))) |
458 return false; | 451 return false; |
459 | 452 |
460 return true; | 453 return true; |
461 } | 454 } |
462 | 455 |
463 bool URLPattern::MatchesAnyScheme( | 456 bool URLPattern::MatchesAnyScheme( |
464 const std::vector<std::string>& schemes) const { | 457 const std::vector<std::string>& schemes) const { |
465 for (std::vector<std::string>::const_iterator i = schemes.begin(); | 458 for (std::vector<std::string>::const_iterator i = schemes.begin(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 } | 505 } |
513 | 506 |
514 return result; | 507 return result; |
515 } | 508 } |
516 | 509 |
517 // static | 510 // static |
518 const char* URLPattern::GetParseResultString( | 511 const char* URLPattern::GetParseResultString( |
519 URLPattern::ParseResult parse_result) { | 512 URLPattern::ParseResult parse_result) { |
520 return kParseResultMessages[parse_result]; | 513 return kParseResultMessages[parse_result]; |
521 } | 514 } |
OLD | NEW |