Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: net/base/registry_controlled_domains/registry_controlled_domain.cc

Issue 2497753002: Invert host/domain checks in SameDomainOrHost (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 493ea68678b0b2a11d1817f42eefa33328894dc2..e1e24907a08cd080baa29781279d32c166a56ebb 100644
--- a/net/base/registry_controlled_domains/registry_controlled_domain.cc
+++ b/net/base/registry_controlled_domains/registry_controlled_domain.cc
@@ -329,6 +329,15 @@ bool SameDomainOrHost(
const GURL& gurl1,
const GURL& gurl2,
PrivateRegistryFilter filter) {
+ // First, check if the hosts are identical.
+ const url::Component host1 = gurl1.parsed_for_possibly_invalid_spec().host;
+ const url::Component host2 = gurl2.parsed_for_possibly_invalid_spec().host;
+ if ((host1.len > 0) && (host1.len == host2.len) &&
+ !strncmp(gurl1.possibly_invalid_spec().data() + host1.begin,
+ gurl2.possibly_invalid_spec().data() + host2.begin, host1.len)) {
+ return true;
+ }
+
// See if both URLs have a known domain + registry, and those values are the
// same.
const base::StringPiece domain1 =
@@ -337,15 +346,7 @@ bool SameDomainOrHost(
GetDomainAndRegistryAsStringPiece(gurl2, filter);
if (!domain1.empty() || !domain2.empty())
return domain1 == domain2;
-
- // No domains. See if the hosts are identical.
- const url::Component host1 = gurl1.parsed_for_possibly_invalid_spec().host;
- const url::Component host2 = gurl2.parsed_for_possibly_invalid_spec().host;
- if ((host1.len <= 0) || (host1.len != host2.len))
- return false;
- return !strncmp(gurl1.possibly_invalid_spec().data() + host1.begin,
- gurl2.possibly_invalid_spec().data() + host2.begin,
- host1.len);
+ return false;
Peter Kasting 2016/11/14 23:00:25 I think a slightly faster, and hopefully more read
}
bool SameDomainOrHost(const url::Origin& origin1,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698