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 bool ContentSettingsPattern::MigrateFromDomainToOrigin( | |
443 const ContentSettingsPattern& domain_pattern, | |
444 ContentSettingsPattern* origin_pattern) { | |
445 DCHECK(origin_pattern); | |
446 | |
447 // Generated patterns with ::FromURL (which we want to migrate) must either | |
448 // have a scheme wildcard or be https. | |
449 if (domain_pattern.parts_.scheme != url::kHttpsScheme && | |
450 !domain_pattern.parts_.is_scheme_wildcard) { | |
451 return false; | |
452 } | |
453 | |
454 // Generated patterns using ::FromURL with the HTTPs scheme can not have a | |
455 // port wildcard. | |
456 if (domain_pattern.parts_.is_port_wildcard && | |
457 domain_pattern.parts_.scheme == url::kHttpsScheme) { | |
458 return false; | |
459 } | |
460 | |
461 // Patterns generated with ::FromURL will always have a domain wildcard. Those | |
462 // generated with ::FromURLNoWildcard don't. | |
463 if (!domain_pattern.parts_.has_domain_wildcard) | |
464 return false; | |
465 | |
466 // Generated patterns with ::FromURL will always have a host. | |
467 if (domain_pattern.parts_.host.empty()) | |
468 return false; | |
469 | |
470 std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder( | |
471 ContentSettingsPattern::CreateBuilder(false)); | |
472 | |
473 if (domain_pattern.parts_.is_scheme_wildcard) | |
474 builder->WithScheme(url::kHttpScheme); | |
475 else | |
476 builder->WithScheme(domain_pattern.parts_.scheme); | |
477 | |
478 builder->WithHost(domain_pattern.parts_.host); | |
479 | |
480 if (domain_pattern.parts_.is_port_wildcard) { | |
msramek
2016/07/07 12:19:24
This logic is exactly what the PatternParser does
lshang
2016/07/08 01:19:43
Since we need to generate a new pattern which is b
| |
481 if (domain_pattern.parts_.scheme == url::kHttpsScheme) { | |
482 builder->WithPort(GetDefaultPort(url::kHttpsScheme)); | |
483 } else { | |
484 builder->WithPort(GetDefaultPort(url::kHttpScheme)); | |
485 } | |
486 } else { | |
487 builder->WithPort(domain_pattern.parts_.port); | |
488 } | |
489 | |
490 *origin_pattern = builder->Build(); | |
491 | |
492 return true; | |
493 } | |
494 | |
495 // static | |
442 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( | 496 void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( |
443 const char* scheme) { | 497 const char* scheme) { |
444 DCHECK(scheme); | 498 DCHECK(scheme); |
445 DCHECK(!non_port_non_domain_wildcard_scheme || | 499 DCHECK(!non_port_non_domain_wildcard_scheme || |
446 non_port_non_domain_wildcard_scheme == scheme); | 500 non_port_non_domain_wildcard_scheme == scheme); |
447 non_port_non_domain_wildcard_scheme = scheme; | 501 non_port_non_domain_wildcard_scheme = scheme; |
448 } | 502 } |
449 | 503 |
450 // static | 504 // static |
451 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( | 505 bool ContentSettingsPattern::IsNonWildcardDomainNonPortScheme( |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) | 791 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) |
738 return ContentSettingsPattern::PREDECESSOR; | 792 return ContentSettingsPattern::PREDECESSOR; |
739 | 793 |
740 int result = parts.path.compare(other_parts.path); | 794 int result = parts.path.compare(other_parts.path); |
741 if (result == 0) | 795 if (result == 0) |
742 return ContentSettingsPattern::IDENTITY; | 796 return ContentSettingsPattern::IDENTITY; |
743 if (result > 0) | 797 if (result > 0) |
744 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 798 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
745 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 799 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
746 } | 800 } |
OLD | NEW |