Index: components/content_settings/core/common/content_settings_pattern.cc |
diff --git a/components/content_settings/core/common/content_settings_pattern.cc b/components/content_settings/core/common/content_settings_pattern.cc |
index 74a9ffaf86d16c055e4613fe3daac1f076becb74..d6dd272f3a8fe8968f03daebd22d6b3863e518f6 100644 |
--- a/components/content_settings/core/common/content_settings_pattern.cc |
+++ b/components/content_settings/core/common/content_settings_pattern.cc |
@@ -439,6 +439,60 @@ ContentSettingsPattern ContentSettingsPattern::FromString( |
} |
// static |
+bool ContentSettingsPattern::MigrateFromDomainToOrigin( |
+ const ContentSettingsPattern& domain_pattern, |
+ ContentSettingsPattern* origin_pattern) { |
+ DCHECK(origin_pattern); |
+ |
+ // Generated patterns with ::FromURL (which we want to migrate) must either |
+ // have a scheme wildcard or be https. |
+ if (domain_pattern.parts_.scheme != url::kHttpsScheme && |
+ !domain_pattern.parts_.is_scheme_wildcard) { |
+ return false; |
+ } |
+ |
+ // Generated patterns using ::FromURL with the HTTPs scheme can not have a |
+ // port wildcard. |
+ if (domain_pattern.parts_.is_port_wildcard && |
+ domain_pattern.parts_.scheme == url::kHttpsScheme) { |
+ return false; |
+ } |
+ |
+ // Patterns generated with ::FromURL will always have a domain wildcard. Those |
+ // generated with ::FromURLNoWildcard don't. |
+ if (!domain_pattern.parts_.has_domain_wildcard) |
+ return false; |
+ |
+ // Generated patterns with ::FromURL will always have a host. |
+ if (domain_pattern.parts_.host.empty()) |
+ return false; |
+ |
+ std::unique_ptr<ContentSettingsPattern::BuilderInterface> builder( |
+ ContentSettingsPattern::CreateBuilder(false)); |
+ |
+ if (domain_pattern.parts_.is_scheme_wildcard) |
+ builder->WithScheme(url::kHttpScheme); |
+ else |
+ builder->WithScheme(domain_pattern.parts_.scheme); |
+ |
+ builder->WithHost(domain_pattern.parts_.host); |
+ |
+ if (domain_pattern.parts_.is_port_wildcard) { |
+ if (domain_pattern.parts_.scheme == url::kHttpsScheme) { |
+ builder->WithPort(GetDefaultPort(url::kHttpsScheme)); |
+ } else { |
+ builder->WithPort(GetDefaultPort(url::kHttpScheme)); |
+ } |
+ } else { |
+ builder->WithPort(domain_pattern.parts_.port); |
+ } |
+ |
+ *origin_pattern = builder->Build(); |
+ |
+ return true; |
+} |
+ |
+// static |
void ContentSettingsPattern::SetNonWildcardDomainNonPortScheme( |
const char* scheme) { |
DCHECK(scheme); |