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 "extensions/common/url_pattern.h" | 5 #include "extensions/common/url_pattern.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <ostream> | 9 #include <ostream> |
10 | 10 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 // Check if it matches all urls or is a pattern like http://*/*. | 438 // Check if it matches all urls or is a pattern like http://*/*. |
439 if (match_all_urls_ || | 439 if (match_all_urls_ || |
440 (match_subdomains_ && host_.empty() && port_ == "*" && path_ == "/*")) { | 440 (match_subdomains_ && host_.empty() && port_ == "*" && path_ == "/*")) { |
441 return true; | 441 return true; |
442 } | 442 } |
443 | 443 |
444 // If this doesn't even match subdomains, it can't possibly imply all hosts. | 444 // If this doesn't even match subdomains, it can't possibly imply all hosts. |
445 if (!match_subdomains_) | 445 if (!match_subdomains_) |
446 return false; | 446 return false; |
447 | 447 |
| 448 // If |host_| is a recognized TLD, this will be 0. We don't include private |
| 449 // TLDs, so that, e.g., *.appspot.com does not imply all hosts. |
| 450 size_t registry_length = net::registry_controlled_domains::GetRegistryLength( |
| 451 host_, |
| 452 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
| 453 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
448 // If there was more than just a TLD in the host (e.g., *.foobar.com), it | 454 // If there was more than just a TLD in the host (e.g., *.foobar.com), it |
449 // doesn't imply all hosts. We don't include private TLDs, so that, e.g., | 455 // doesn't imply all hosts. |
450 // *.appspot.com does not imply all hosts. | 456 if (registry_length > 0) |
451 if (net::registry_controlled_domains::HostHasRegistryControlledDomain( | |
452 host_, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
453 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES)) | |
454 return false; | 457 return false; |
455 | 458 |
456 // At this point the host could either be just a TLD ("com") or some unknown | 459 // At this point the host could either be just a TLD ("com") or some unknown |
457 // TLD-like string ("notatld"). To disambiguate between them construct a | 460 // TLD-like string ("notatld"). To disambiguate between them construct a |
458 // fake URL, and check the registry. | 461 // fake URL, and check the registry. This returns 0 if the TLD is |
459 // | 462 // unrecognized, or the length of the recognized TLD. |
460 // If we recognized this TLD, then this is a pattern like *.com, and it | 463 registry_length = net::registry_controlled_domains::GetRegistryLength( |
461 // should imply all hosts. | 464 base::StringPrintf("foo.%s", host_.c_str()), |
462 return net::registry_controlled_domains::HostHasRegistryControlledDomain( | |
463 "notatld." + host_, | |
464 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 465 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
465 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 466 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 467 // If we recognized this TLD, then this is a pattern like *.com, and it |
| 468 // should imply all hosts. Otherwise, this doesn't imply all hosts. |
| 469 return registry_length > 0; |
466 } | 470 } |
467 | 471 |
468 bool URLPattern::MatchesSingleOrigin() const { | 472 bool URLPattern::MatchesSingleOrigin() const { |
469 // Strictly speaking, the port is part of the origin, but in URLPattern it | 473 // Strictly speaking, the port is part of the origin, but in URLPattern it |
470 // defaults to *. It's not very interesting anyway, so leave it out. | 474 // defaults to *. It's not very interesting anyway, so leave it out. |
471 return !ImpliesAllHosts() && scheme_ != "*" && !match_subdomains_; | 475 return !ImpliesAllHosts() && scheme_ != "*" && !match_subdomains_; |
472 } | 476 } |
473 | 477 |
474 bool URLPattern::MatchesPath(const std::string& test) const { | 478 bool URLPattern::MatchesPath(const std::string& test) const { |
475 // Make the behaviour of OverlapsWith consistent with MatchesURL, which is | 479 // Make the behaviour of OverlapsWith consistent with MatchesURL, which is |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 } | 609 } |
606 | 610 |
607 return result; | 611 return result; |
608 } | 612 } |
609 | 613 |
610 // static | 614 // static |
611 const char* URLPattern::GetParseResultString( | 615 const char* URLPattern::GetParseResultString( |
612 URLPattern::ParseResult parse_result) { | 616 URLPattern::ParseResult parse_result) { |
613 return kParseResultMessages[parse_result]; | 617 return kParseResultMessages[parse_result]; |
614 } | 618 } |
OLD | NEW |