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