OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "components/url_pattern_index/url_pattern_index.h" | 5 #include "components/url_pattern_index/url_pattern_index.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (domains.size() <= 5) { | 434 if (domains.size() <= 5) { |
435 for (auto* domain : domains) { | 435 for (auto* domain : domains) { |
436 const base::StringPiece domain_piece = ToStringPiece(domain); | 436 const base::StringPiece domain_piece = ToStringPiece(domain); |
437 if (origin.DomainIs(domain_piece)) | 437 if (origin.DomainIs(domain_piece)) |
438 return domain_piece.size(); | 438 return domain_piece.size(); |
439 } | 439 } |
440 return 0; | 440 return 0; |
441 } | 441 } |
442 // Otherwise look for each subdomain of the |origin| using binary search. | 442 // Otherwise look for each subdomain of the |origin| using binary search. |
443 | 443 |
444 DCHECK(!origin.unique()); | 444 DCHECK(!origin.opaque()); |
445 base::StringPiece canonicalized_host(origin.host()); | 445 base::StringPiece canonicalized_host(origin.host()); |
446 if (canonicalized_host.empty()) | 446 if (canonicalized_host.empty()) |
447 return 0; | 447 return 0; |
448 | 448 |
449 // If the host name ends with a dot, then ignore it. | 449 // If the host name ends with a dot, then ignore it. |
450 if (canonicalized_host.back() == '.') | 450 if (canonicalized_host.back() == '.') |
451 canonicalized_host.remove_suffix(1); | 451 canonicalized_host.remove_suffix(1); |
452 | 452 |
453 // The |left| bound of the search is shared between iterations, because | 453 // The |left| bound of the search is shared between iterations, because |
454 // subdomains are considered in decreasing order of their lengths, therefore | 454 // subdomains are considered in decreasing order of their lengths, therefore |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // considered a "generic" rule. Therefore, if |disable_generic_rules| is set, | 490 // considered a "generic" rule. Therefore, if |disable_generic_rules| is set, |
491 // this function will always return false for such rules. | 491 // this function will always return false for such rules. |
492 bool DoesOriginMatchDomainList(const url::Origin& origin, | 492 bool DoesOriginMatchDomainList(const url::Origin& origin, |
493 const flat::UrlRule& rule, | 493 const flat::UrlRule& rule, |
494 bool disable_generic_rules) { | 494 bool disable_generic_rules) { |
495 const bool is_generic = !rule.domains_included(); | 495 const bool is_generic = !rule.domains_included(); |
496 DCHECK(is_generic || rule.domains_included()->size()); | 496 DCHECK(is_generic || rule.domains_included()->size()); |
497 if (disable_generic_rules && is_generic) | 497 if (disable_generic_rules && is_generic) |
498 return false; | 498 return false; |
499 | 499 |
500 // Unique |origin| matches lists of exception domains only. | 500 // Opaque |origin| matches lists of exception domains only. |
501 if (origin.unique()) | 501 if (origin.opaque()) |
502 return is_generic; | 502 return is_generic; |
503 | 503 |
504 size_t longest_matching_included_domain_length = 1; | 504 size_t longest_matching_included_domain_length = 1; |
505 if (!is_generic) { | 505 if (!is_generic) { |
506 longest_matching_included_domain_length = | 506 longest_matching_included_domain_length = |
507 GetLongestMatchingSubdomain(origin, *rule.domains_included()); | 507 GetLongestMatchingSubdomain(origin, *rule.domains_included()); |
508 } | 508 } |
509 if (longest_matching_included_domain_length && rule.domains_excluded()) { | 509 if (longest_matching_included_domain_length && rule.domains_excluded()) { |
510 return GetLongestMatchingSubdomain(origin, *rule.domains_excluded()) < | 510 return GetLongestMatchingSubdomain(origin, *rule.domains_excluded()) < |
511 longest_matching_included_domain_length; | 511 longest_matching_included_domain_length; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 (activation_type == flat::ActivationType_NONE)) { | 656 (activation_type == flat::ActivationType_NONE)) { |
657 return nullptr; | 657 return nullptr; |
658 } | 658 } |
659 | 659 |
660 return FindMatchInFlatUrlPatternIndex(*flat_index_, url, first_party_origin, | 660 return FindMatchInFlatUrlPatternIndex(*flat_index_, url, first_party_origin, |
661 element_type, activation_type, | 661 element_type, activation_type, |
662 is_third_party, disable_generic_rules); | 662 is_third_party, disable_generic_rules); |
663 } | 663 } |
664 | 664 |
665 } // namespace url_pattern_index | 665 } // namespace url_pattern_index |
OLD | NEW |