Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: components/content_settings/core/common/content_settings_pattern.cc

Issue 1895993003: Add migration code to change existing domain scoped content settings to be origin scoped (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698