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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // First, check if the hosts are identical.
333 const url::Component host1 = gurl1.parsed_for_possibly_invalid_spec().host;
334 const url::Component host2 = gurl2.parsed_for_possibly_invalid_spec().host;
335 if ((host1.len > 0) && (host1.len == host2.len) &&
336 !strncmp(gurl1.possibly_invalid_spec().data() + host1.begin,
337 gurl2.possibly_invalid_spec().data() + host2.begin, host1.len)) {
338 return true;
339 }
340
332 // See if both URLs have a known domain + registry, and those values are the 341 // See if both URLs have a known domain + registry, and those values are the
333 // same. 342 // same.
334 const base::StringPiece domain1 = 343 const base::StringPiece domain1 =
335 GetDomainAndRegistryAsStringPiece(gurl1, filter); 344 GetDomainAndRegistryAsStringPiece(gurl1, filter);
336 const base::StringPiece domain2 = 345 const base::StringPiece domain2 =
337 GetDomainAndRegistryAsStringPiece(gurl2, filter); 346 GetDomainAndRegistryAsStringPiece(gurl2, filter);
338 if (!domain1.empty() || !domain2.empty()) 347 if (!domain1.empty() || !domain2.empty())
339 return domain1 == domain2; 348 return domain1 == domain2;
340 349 return false;
Peter Kasting 2016/11/14 23:00:25 I think a slightly faster, and hopefully more read
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 } 350 }
350 351
351 bool SameDomainOrHost(const url::Origin& origin1, 352 bool SameDomainOrHost(const url::Origin& origin1,
352 const url::Origin& origin2, 353 const url::Origin& origin2,
353 PrivateRegistryFilter filter) { 354 PrivateRegistryFilter filter) {
354 return SameDomainOrHost(origin1.GetURL(), origin2.GetURL(), filter); 355 return SameDomainOrHost(origin1.GetURL(), origin2.GetURL(), filter);
355 } 356 }
356 357
357 bool SameDomainOrHost(const url::Origin& origin1, 358 bool SameDomainOrHost(const url::Origin& origin1,
358 const base::Optional<url::Origin>& origin2, 359 const base::Optional<url::Origin>& origin2,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 433
433 void SetFindDomainGraph(const unsigned char* domains, size_t length) { 434 void SetFindDomainGraph(const unsigned char* domains, size_t length) {
434 CHECK(domains); 435 CHECK(domains);
435 CHECK_NE(length, 0u); 436 CHECK_NE(length, 0u);
436 g_graph = domains; 437 g_graph = domains;
437 g_graph_length = length; 438 g_graph_length = length;
438 } 439 }
439 440
440 } // namespace registry_controlled_domains 441 } // namespace registry_controlled_domains
441 } // namespace net 442 } // namespace net
OLDNEW
« 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