Chromium Code Reviews| Index: net/base/registry_controlled_domains/registry_controlled_domain.cc |
| diff --git a/net/base/registry_controlled_domains/registry_controlled_domain.cc b/net/base/registry_controlled_domains/registry_controlled_domain.cc |
| index 5f29f89f27cacdd71154db87177dd39ab6a224da..73d5cc1134fe4e864b4b727e146d15784e7476ff 100644 |
| --- a/net/base/registry_controlled_domains/registry_controlled_domain.cc |
| +++ b/net/base/registry_controlled_domains/registry_controlled_domain.cc |
| @@ -321,11 +321,28 @@ bool SameDomainOrHost(base::StringPiece host1, |
| if (host1 == host2) |
| return true; |
| - // Check for a domain and registry match. |
| - const base::StringPiece& domain1 = |
| + const base::StringPiece domain1 = |
| GetDomainAndRegistryAsStringPiece(host1, filter); |
| - return !domain1.empty() && |
| - (domain1 == GetDomainAndRegistryAsStringPiece(host2, filter)); |
| + |
| + // If |domain1| is empty, |host1| either matched no rules in the registry, |
| + // or is an IP literal. Since |host2| and |host1| are known to differ, |
| + // they can't possibly be same-origin. |
| + if (domain1.empty()) |
| + return false; |
| + |
| + // Fail fast before computing |domain2|, if possible, by checking to see if |
| + // |domain1| is a suffix of |host2|. This is a necessary but not sufficient |
| + // condition for |domain1| and |domain2| to be equal. |
| + if (!base::EndsWith(host2, domain1, base::CompareCase::SENSITIVE)) |
|
Ryan Sleevi
2017/01/06 00:38:16
Unclear if you're doing sensitive as an optimizati
|
| + return false; |
| + |
| + const base::StringPiece domain2 = |
| + GetDomainAndRegistryAsStringPiece(host2, filter); |
| + |
| + // We already verified that |domain1| is a suffix of |host2|. And |domain2| is |
| + // also a suffix of |host2|, by construction. So if their lengths are equal, |
| + // they are identical. |
| + return domain2.length() == domain1.length(); |
| } |
| } // namespace |