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 // 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 return 0; // Multiple trailing dots. | 97 return 0; // Multiple trailing dots. |
98 } | 98 } |
99 | 99 |
100 // Walk up the domain tree, most specific to least specific, | 100 // Walk up the domain tree, most specific to least specific, |
101 // looking for matches at each level. | 101 // looking for matches at each level. |
102 size_t prev_start = std::string::npos; | 102 size_t prev_start = std::string::npos; |
103 size_t curr_start = host_check_begin; | 103 size_t curr_start = host_check_begin; |
104 size_t next_dot = host.find('.', curr_start); | 104 size_t next_dot = host.find('.', curr_start); |
105 if (next_dot >= host_check_len) // Catches std::string::npos as well. | 105 if (next_dot >= host_check_len) // Catches std::string::npos as well. |
106 return 0; // This can't have a registry + domain. | 106 return 0; // This can't have a registry + domain. |
107 while (1) { | 107 while (1) { |
ncarter (slow)
2017/01/03 19:38:27
Totally random thought -- is this function a hot s
Charlie Harrison
2017/01/03 22:16:56
I think I understand what you are saying. Rather t
| |
108 const char* domain_str = host.data() + curr_start; | 108 const char* domain_str = host.data() + curr_start; |
109 size_t domain_length = host_check_len - curr_start; | 109 size_t domain_length = host_check_len - curr_start; |
110 int type = LookupStringInFixedSet(g_graph, g_graph_length, domain_str, | 110 int type = LookupStringInFixedSet(g_graph, g_graph_length, domain_str, |
111 domain_length); | 111 domain_length); |
112 bool do_check = type != kDafsaNotFound && | 112 bool do_check = type != kDafsaNotFound && |
113 (!(type & kDafsaPrivateRule) || | 113 (!(type & kDafsaPrivateRule) || |
114 private_filter == INCLUDE_PRIVATE_REGISTRIES); | 114 private_filter == INCLUDE_PRIVATE_REGISTRIES); |
115 | 115 |
116 // If the apparent match is a private registry and we're not including | 116 // If the apparent match is a private registry and we're not including |
117 // those, it can't be an actual match. | 117 // those, it can't be an actual match. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 try_output.Complete(); | 302 try_output.Complete(); |
303 if (try_string == canonical_rcd) | 303 if (try_string == canonical_rcd) |
304 return host.length() - current_try; | 304 return host.length() - current_try; |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 NOTREACHED(); | 308 NOTREACHED(); |
309 return canonical_rcd_len; | 309 return canonical_rcd_len; |
310 } | 310 } |
311 | 311 |
312 } // namespace | |
313 | |
314 std::string GetDomainAndRegistry(const GURL& gurl, | |
315 PrivateRegistryFilter filter) { | |
316 return GetDomainAndRegistryAsStringPiece(gurl.host_piece(), filter) | |
317 .as_string(); | |
318 } | |
319 | |
320 std::string GetDomainAndRegistry(base::StringPiece host, | |
321 PrivateRegistryFilter filter) { | |
322 url::CanonHostInfo host_info; | |
323 const std::string canon_host(CanonicalizeHost(host, &host_info)); | |
324 if (canon_host.empty() || host_info.IsIPAddress()) | |
325 return std::string(); | |
326 return GetDomainAndRegistryImpl(canon_host, filter).as_string(); | |
327 } | |
328 | |
312 bool SameDomainOrHost(base::StringPiece host1, | 329 bool SameDomainOrHost(base::StringPiece host1, |
313 base::StringPiece host2, | 330 base::StringPiece host2, |
314 PrivateRegistryFilter filter) { | 331 PrivateRegistryFilter filter) { |
315 // Quickly reject cases where either host is empty. | 332 // Quickly reject cases where either host is empty. |
316 if (host1.empty() || host2.empty()) | 333 if (host1.empty() || host2.empty()) |
317 return false; | 334 return false; |
318 | 335 |
319 // Check for exact host matches, which is faster than looking up the domain | 336 // Check for exact host matches, which is faster than looking up the domain |
320 // and registry. | 337 // and registry. |
321 if (host1 == host2) | 338 if (host1 == host2) |
322 return true; | 339 return true; |
323 | 340 |
324 // Check for a domain and registry match. | 341 // Check for a domain and registry match. |
325 const base::StringPiece& domain1 = | 342 const base::StringPiece& domain1 = |
326 GetDomainAndRegistryAsStringPiece(host1, filter); | 343 GetDomainAndRegistryAsStringPiece(host1, filter); |
327 return !domain1.empty() && | 344 return !domain1.empty() && |
328 (domain1 == GetDomainAndRegistryAsStringPiece(host2, filter)); | 345 (domain1 == GetDomainAndRegistryAsStringPiece(host2, filter)); |
329 } | 346 } |
330 | 347 |
331 } // namespace | 348 bool SameDomainOrHost(const GURL& gurl1, |
332 | 349 const GURL& gurl2, |
333 std::string GetDomainAndRegistry(const GURL& gurl, | 350 PrivateRegistryFilter filter) { |
334 PrivateRegistryFilter filter) { | |
335 return GetDomainAndRegistryAsStringPiece(gurl.host_piece(), filter) | |
336 .as_string(); | |
337 } | |
338 | |
339 std::string GetDomainAndRegistry(base::StringPiece host, | |
340 PrivateRegistryFilter filter) { | |
341 url::CanonHostInfo host_info; | |
342 const std::string canon_host(CanonicalizeHost(host, &host_info)); | |
343 if (canon_host.empty() || host_info.IsIPAddress()) | |
344 return std::string(); | |
345 return GetDomainAndRegistryImpl(canon_host, filter).as_string(); | |
346 } | |
347 | |
348 bool SameDomainOrHost( | |
349 const GURL& gurl1, | |
350 const GURL& gurl2, | |
351 PrivateRegistryFilter filter) { | |
352 return SameDomainOrHost(gurl1.host_piece(), gurl2.host_piece(), filter); | 351 return SameDomainOrHost(gurl1.host_piece(), gurl2.host_piece(), filter); |
353 } | 352 } |
354 | 353 |
355 bool SameDomainOrHost(const url::Origin& origin1, | 354 bool SameDomainOrHost(const url::Origin& origin1, |
356 const url::Origin& origin2, | 355 const url::Origin& origin2, |
357 PrivateRegistryFilter filter) { | 356 PrivateRegistryFilter filter) { |
358 return SameDomainOrHost(origin1.host(), origin2.host(), filter); | 357 return SameDomainOrHost(origin1.host(), origin2.host(), filter); |
359 } | 358 } |
360 | 359 |
361 bool SameDomainOrHost(const url::Origin& origin1, | 360 bool SameDomainOrHost(const url::Origin& origin1, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 | 434 |
436 void SetFindDomainGraph(const unsigned char* domains, size_t length) { | 435 void SetFindDomainGraph(const unsigned char* domains, size_t length) { |
437 CHECK(domains); | 436 CHECK(domains); |
438 CHECK_NE(length, 0u); | 437 CHECK_NE(length, 0u); |
439 g_graph = domains; | 438 g_graph = domains; |
440 g_graph_length = length; | 439 g_graph_length = length; |
441 } | 440 } |
442 | 441 |
443 } // namespace registry_controlled_domains | 442 } // namespace registry_controlled_domains |
444 } // namespace net | 443 } // namespace net |
OLD | NEW |