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

Side by Side Diff: net/base/registry_controlled_domains/registry_controlled_domain.cc

Issue 2497753002: Invert host/domain checks in SameDomainOrHost (Closed)
Patch Set: pkasting review 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 unified diff | Download patch
OLDNEW
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 // NB: Modelled after Mozilla's code (originally written by Pamela Greene, 5 // NB: Modelled after Mozilla's code (originally written by Pamela Greene,
6 // later modified by others), but almost entirely rewritten for Chrome. 6 // later modified by others), but almost entirely rewritten for Chrome.
7 // (netwerk/dns/src/nsEffectiveTLDService.cpp) 7 // (netwerk/dns/src/nsEffectiveTLDService.cpp)
8 /* ***** BEGIN LICENSE BLOCK ***** 8 /* ***** BEGIN LICENSE BLOCK *****
9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 9 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
10 * 10 *
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 const std::string canon_host(CanonicalizeHost(host, &host_info)); 322 const std::string canon_host(CanonicalizeHost(host, &host_info));
323 if (canon_host.empty() || host_info.IsIPAddress()) 323 if (canon_host.empty() || host_info.IsIPAddress())
324 return std::string(); 324 return std::string();
325 return GetDomainAndRegistryImpl(canon_host, filter).as_string(); 325 return GetDomainAndRegistryImpl(canon_host, filter).as_string();
326 } 326 }
327 327
328 bool SameDomainOrHost( 328 bool SameDomainOrHost(
329 const GURL& gurl1, 329 const GURL& gurl1,
330 const GURL& gurl2, 330 const GURL& gurl2,
331 PrivateRegistryFilter filter) { 331 PrivateRegistryFilter filter) {
332 // See if both URLs have a known domain + registry, and those values are the 332 // Quickly reject cases where either host is empty.
333 // same. 333 if (!gurl1.has_host() || !gurl2.has_host())
334 const base::StringPiece domain1 = 334 return false;
335
336 // Check for exact host matches, which is faster than looking up the domain
337 // and registry.
338 if (gurl1.host_piece() == gurl2.host_piece())
339 return true;
340
341 // Check for a domain and registry match.
342 const base::StringPiece& domain1 =
335 GetDomainAndRegistryAsStringPiece(gurl1, filter); 343 GetDomainAndRegistryAsStringPiece(gurl1, filter);
336 const base::StringPiece domain2 = 344 return !domain1.empty() &&
337 GetDomainAndRegistryAsStringPiece(gurl2, filter); 345 (domain1 == GetDomainAndRegistryAsStringPiece(gurl2, filter));
338 if (!domain1.empty() || !domain2.empty())
339 return domain1 == domain2;
340
341 // No domains. See if the hosts are identical.
342 const url::Component host1 = gurl1.parsed_for_possibly_invalid_spec().host;
343 const url::Component host2 = gurl2.parsed_for_possibly_invalid_spec().host;
344 if ((host1.len <= 0) || (host1.len != host2.len))
345 return false;
346 return !strncmp(gurl1.possibly_invalid_spec().data() + host1.begin,
347 gurl2.possibly_invalid_spec().data() + host2.begin,
348 host1.len);
349 } 346 }
350 347
351 bool SameDomainOrHost(const url::Origin& origin1, 348 bool SameDomainOrHost(const url::Origin& origin1,
352 const url::Origin& origin2, 349 const url::Origin& origin2,
353 PrivateRegistryFilter filter) { 350 PrivateRegistryFilter filter) {
354 return SameDomainOrHost(origin1.GetURL(), origin2.GetURL(), filter); 351 return SameDomainOrHost(origin1.GetURL(), origin2.GetURL(), filter);
355 } 352 }
356 353
357 bool SameDomainOrHost(const url::Origin& origin1, 354 bool SameDomainOrHost(const url::Origin& origin1,
358 const base::Optional<url::Origin>& origin2, 355 const base::Optional<url::Origin>& origin2,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 429
433 void SetFindDomainGraph(const unsigned char* domains, size_t length) { 430 void SetFindDomainGraph(const unsigned char* domains, size_t length) {
434 CHECK(domains); 431 CHECK(domains);
435 CHECK_NE(length, 0u); 432 CHECK_NE(length, 0u);
436 g_graph = domains; 433 g_graph = domains;
437 g_graph_length = length; 434 g_graph_length = length;
438 } 435 }
439 436
440 } // namespace registry_controlled_domains 437 } // namespace registry_controlled_domains
441 } // namespace net 438 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698