| 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 #include "components/content_settings/core/common/content_settings_pattern.h" | 5 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 ContentSettingsPattern ContentSettingsPattern::FromString( | 432 ContentSettingsPattern ContentSettingsPattern::FromString( |
| 433 const std::string& pattern_spec) { | 433 const std::string& pattern_spec) { |
| 434 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder( | 434 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder( |
| 435 ContentSettingsPattern::CreateBuilder(false)); | 435 ContentSettingsPattern::CreateBuilder(false)); |
| 436 content_settings::PatternParser::Parse(pattern_spec, | 436 content_settings::PatternParser::Parse(pattern_spec, |
| 437 builder.get()); | 437 builder.get()); |
| 438 return builder->Build(); | 438 return builder->Build(); |
| 439 } | 439 } |
| 440 | 440 |
| 441 // static | 441 // static |
| 442 ContentSettingsPattern ContentSettingsPattern::FromDomainToOrigin( |
| 443 const ContentSettingsPattern domain_pattern) { |
| 444 ContentSettingsPattern origin_pattern(domain_pattern); |
| 445 |
| 446 if (domain_pattern.parts_.is_scheme_wildcard) { |
| 447 origin_pattern.parts_.scheme = url::kHttpScheme; |
| 448 origin_pattern.parts_.is_scheme_wildcard = false; |
| 449 } |
| 450 if (domain_pattern.parts_.has_domain_wildcard) |
| 451 origin_pattern.parts_.has_domain_wildcard = false; |
| 452 if (domain_pattern.parts_.is_port_wildcard) { |
| 453 origin_pattern.parts_.port = GetDefaultPort(origin_pattern.parts_.scheme); |
| 454 origin_pattern.parts_.is_port_wildcard = false; |
| 455 } |
| 456 return origin_pattern; |
| 457 } |
| 458 |
| 459 // static |
| 442 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( | 460 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( |
| 443 const char* scheme) { | 461 const char* scheme) { |
| 444 DCHECK(scheme); | 462 DCHECK(scheme); |
| 445 DCHECK(!non_port_non_domain_wildcard_scheme || | 463 DCHECK(!non_port_non_domain_wildcard_scheme || |
| 446 non_port_non_domain_wildcard_scheme == scheme); | 464 non_port_non_domain_wildcard_scheme == scheme); |
| 447 non_port_non_domain_wildcard_scheme = scheme; | 465 non_port_non_domain_wildcard_scheme = scheme; |
| 448 } | 466 } |
| 449 | 467 |
| 450 // static | 468 // static |
| 451 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( | 469 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 return false; | 540 return false; |
| 523 } | 541 } |
| 524 | 542 |
| 525 return true; | 543 return true; |
| 526 } | 544 } |
| 527 | 545 |
| 528 bool ContentSettingsPattern::MatchesAllHosts() const { | 546 bool ContentSettingsPattern::MatchesAllHosts() const { |
| 529 return parts_.has_domain_wildcard && parts_.host.empty(); | 547 return parts_.has_domain_wildcard && parts_.host.empty(); |
| 530 } | 548 } |
| 531 | 549 |
| 550 bool ContentSettingsPattern::IsGeneratedUsingFromURL() const { |
| 551 // Generated patterns must either have a scheme wildcard or be https. |
| 552 if (parts_.scheme != url::kHttpsScheme && !parts_.is_scheme_wildcard) |
| 553 return false; |
| 554 |
| 555 // Generated patterns will either have a port wildcard or be https (but not |
| 556 // both). |
| 557 if (parts_.is_port_wildcard && parts_.scheme == url::kHttpsScheme) |
| 558 return false; |
| 559 |
| 560 // Generated patterns will always have a domain wildcard. |
| 561 if (!parts_.has_domain_wildcard) |
| 562 return false; |
| 563 |
| 564 // Generated patterns will always have a host. |
| 565 if (parts_.host.empty()) |
| 566 return false; |
| 567 |
| 568 return true; |
| 569 } |
| 570 |
| 532 std::string ContentSettingsPattern::ToString() const { | 571 std::string ContentSettingsPattern::ToString() const { |
| 533 if (IsValid()) | 572 if (IsValid()) |
| 534 return content_settings::PatternParser::ToString(parts_); | 573 return content_settings::PatternParser::ToString(parts_); |
| 535 else | 574 else |
| 536 return std::string(); | 575 return std::string(); |
| 537 } | 576 } |
| 538 | 577 |
| 539 ContentSettingsPattern::Relation ContentSettingsPattern::Compare( | 578 ContentSettingsPattern::Relation ContentSettingsPattern::Compare( |
| 540 const ContentSettingsPattern& other) const { | 579 const ContentSettingsPattern& other) const { |
| 541 // Two invalid patterns are identical in the way they behave. They don't match | 580 // Two invalid patterns are identical in the way they behave. They don't match |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) | 776 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) |
| 738 return ContentSettingsPattern::PREDECESSOR; | 777 return ContentSettingsPattern::PREDECESSOR; |
| 739 | 778 |
| 740 int result = parts.path.compare(other_parts.path); | 779 int result = parts.path.compare(other_parts.path); |
| 741 if (result == 0) | 780 if (result == 0) |
| 742 return ContentSettingsPattern::IDENTITY; | 781 return ContentSettingsPattern::IDENTITY; |
| 743 if (result > 0) | 782 if (result > 0) |
| 744 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 783 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 745 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 784 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 746 } | 785 } |
| OLD | NEW |