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

Unified Diff: components/content_settings/core/browser/host_content_settings_map.cc

Issue 1754073002: Migrate old settings for ContentSettingTypes with wildcard as secondary_pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scoping_set_content_setting
Patch Set: use string 'preference' Created 4 years, 8 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
« no previous file with comments | « components/content_settings/core/browser/host_content_settings_map.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/content_settings/core/browser/host_content_settings_map.cc
diff --git a/components/content_settings/core/browser/host_content_settings_map.cc b/components/content_settings/core/browser/host_content_settings_map.cc
index e023a79de22361915f1499f27f64f05dca79beb0..5307adea4accab3db64c9445ad8e715bf5ec0bed 100644
--- a/components/content_settings/core/browser/host_content_settings_map.cc
+++ b/components/content_settings/core/browser/host_content_settings_map.cc
@@ -166,6 +166,8 @@ HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs,
new content_settings::DefaultProvider(prefs_, is_off_the_record_);
default_provider->AddObserver(this);
content_settings_providers_[DEFAULT_PROVIDER] = default_provider;
+
+ MigrateOldSettings();
}
// static
@@ -439,6 +441,52 @@ void HostContentSettingsMap::SetContentSettingDefaultScope(
resource_identifier, setting);
}
+void HostContentSettingsMap::MigrateOldSettings() {
+ const ContentSettingsType kMigrateContentSettingTypes[] = {
+ // Only content types of scoping type: REQUESTING_DOMAIN_ONLY_SCOPE,
+ // REQUESTING_ORIGIN_ONLY_SCOPE and TOP_LEVEL_DOMAIN_ONLY_SCOPE need to be
+ // migrated.
+ CONTENT_SETTINGS_TYPE_KEYGEN};
+ for (const ContentSettingsType& type : kMigrateContentSettingTypes) {
+ WebsiteSettingsInfo::ScopingType scoping_type =
+ content_settings::ContentSettingsRegistry::GetInstance()
+ ->Get(type)
+ ->website_settings_info()
+ ->scoping_type();
+ DCHECK_NE(
+ scoping_type,
+ WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE);
+
+ ContentSettingsForOneType settings;
+ GetSettingsForOneType(type, std::string(), &settings);
+ for (const ContentSettingPatternSource& setting_entry : settings) {
+ // Migrate user preference settings only.
+ if (setting_entry.source != "preference")
+ continue;
+ // Migrate old-format settings only.
+ if (setting_entry.secondary_pattern !=
+ ContentSettingsPattern::Wildcard()) {
+ GURL url(setting_entry.primary_pattern.ToString());
+ // Pull out the value of the old-format setting. Only do this if the
+ // patterns are as we expect them to be, otherwise the setting will just
+ // be removed for safety.
+ ContentSetting content_setting = CONTENT_SETTING_DEFAULT;
+ if (setting_entry.primary_pattern == setting_entry.secondary_pattern &&
+ url.is_valid()) {
+ content_setting = GetContentSetting(url, url, type, std::string());
+ }
+ // Remove the old pattern.
+ SetContentSetting(setting_entry.primary_pattern,
+ setting_entry.secondary_pattern, type, std::string(),
+ CONTENT_SETTING_DEFAULT);
+ // Set the new pattern.
+ SetContentSettingDefaultScope(url, GURL(), type, std::string(),
+ content_setting);
+ }
+ }
+ }
+}
+
ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage(
const GURL& primary_url,
const GURL& secondary_url,
« no previous file with comments | « components/content_settings/core/browser/host_content_settings_map.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698