Chromium Code Reviews| 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) { | |
|
raymes
2016/06/16 03:23:51
in this case I think we can just assume the http p
lshang
2016/06/20 01:34:22
Done.
| |
| 453 if (!origin_pattern.parts_.is_scheme_wildcard) { | |
| 454 origin_pattern.parts_.port = GetDefaultPort(origin_pattern.parts_.scheme); | |
| 455 origin_pattern.parts_.is_port_wildcard = false; | |
| 456 } | |
| 457 } | |
| 458 return origin_pattern; | |
| 459 } | |
| 460 | |
| 461 // static | |
| 442 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( | 462 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( |
| 443 const char* scheme) { | 463 const char* scheme) { |
| 444 DCHECK(scheme); | 464 DCHECK(scheme); |
| 445 DCHECK(!non_port_non_domain_wildcard_scheme || | 465 DCHECK(!non_port_non_domain_wildcard_scheme || |
| 446 non_port_non_domain_wildcard_scheme == scheme); | 466 non_port_non_domain_wildcard_scheme == scheme); |
| 447 non_port_non_domain_wildcard_scheme = scheme; | 467 non_port_non_domain_wildcard_scheme = scheme; |
| 448 } | 468 } |
| 449 | 469 |
| 450 // static | 470 // static |
| 451 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( | 471 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 return false; | 542 return false; |
| 523 } | 543 } |
| 524 | 544 |
| 525 return true; | 545 return true; |
| 526 } | 546 } |
| 527 | 547 |
| 528 bool ContentSettingsPattern::MatchesAllHosts() const { | 548 bool ContentSettingsPattern::MatchesAllHosts() const { |
| 529 return parts_.has_domain_wildcard && parts_.host.empty(); | 549 return parts_.has_domain_wildcard && parts_.host.empty(); |
| 530 } | 550 } |
| 531 | 551 |
| 552 bool ContentSettingsPattern::IsGeneratedFromURLDomainScoped() const { | |
|
raymes
2016/06/16 03:23:51
Maybe call this:
IsGeneratedUsingFromURLNoWildcard
lshang
2016/06/20 01:34:22
Done. IsGeneratedUsingFromURL():)
| |
| 553 return (!parts_.host.empty()) && parts_.has_domain_wildcard; | |
|
raymes
2016/06/16 03:23:51
I think there are more checks we can do here. Name
lshang
2016/06/20 01:34:22
Done. Yeah this is more clear.
| |
| 554 } | |
| 555 | |
| 532 std::string ContentSettingsPattern::ToString() const { | 556 std::string ContentSettingsPattern::ToString() const { |
| 533 if (IsValid()) | 557 if (IsValid()) |
| 534 return content_settings::PatternParser::ToString(parts_); | 558 return content_settings::PatternParser::ToString(parts_); |
| 535 else | 559 else |
| 536 return std::string(); | 560 return std::string(); |
| 537 } | 561 } |
| 538 | 562 |
| 539 ContentSettingsPattern::Relation ContentSettingsPattern::Compare( | 563 ContentSettingsPattern::Relation ContentSettingsPattern::Compare( |
| 540 const ContentSettingsPattern& other) const { | 564 const ContentSettingsPattern& other) const { |
| 541 // Two invalid patterns are identical in the way they behave. They don't match | 565 // 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) | 761 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) |
| 738 return ContentSettingsPattern::PREDECESSOR; | 762 return ContentSettingsPattern::PREDECESSOR; |
| 739 | 763 |
| 740 int result = parts.path.compare(other_parts.path); | 764 int result = parts.path.compare(other_parts.path); |
| 741 if (result == 0) | 765 if (result == 0) |
| 742 return ContentSettingsPattern::IDENTITY; | 766 return ContentSettingsPattern::IDENTITY; |
| 743 if (result > 0) | 767 if (result > 0) |
| 744 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 768 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 745 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 769 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 746 } | 770 } |
| OLD | NEW |