Chromium Code Reviews| 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 edfe39436eef4bf9494077d58b40dd2630c23b01..e687db5fb90b57fe497513e01e608e0eba7ed851 100644 |
| --- a/components/content_settings/core/browser/host_content_settings_map.cc |
| +++ b/components/content_settings/core/browser/host_content_settings_map.cc |
| @@ -56,6 +56,26 @@ const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = { |
| {"default", content_settings::SETTING_SOURCE_USER}, |
| }; |
| +const ContentSettingsType kMigrateContentSettingTypes[] = { |
|
raymes
2016/03/02 04:32:49
nit: could you move this into MigrateOldSettings?
lshang
2016/03/03 02:55:14
Done.
|
| + // 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_COOKIES, |
| + CONTENT_SETTINGS_TYPE_IMAGES, |
| + CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| + CONTENT_SETTINGS_TYPE_PLUGINS, |
| + CONTENT_SETTINGS_TYPE_POPUPS, |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + CONTENT_SETTINGS_TYPE_MOUSELOCK, |
| + CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| + CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| + CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
| + CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| + CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, |
| + CONTENT_SETTINGS_TYPE_KEYGEN, |
| + CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, |
| + CONTENT_SETTINGS_TYPE_MIXEDSCRIPT}; |
|
raymes
2016/03/02 04:38:11
Also, it could be good to add the content settings
lshang
2016/03/03 02:55:14
Done.
We recently encountered old formatted settin
|
| + |
| static_assert( |
| arraysize(kProviderNamesSourceMap) == |
| HostContentSettingsMap::NUM_PROVIDER_TYPES, |
| @@ -171,6 +191,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 |
| @@ -472,6 +494,37 @@ void HostContentSettingsMap::SetContentSettingDefaultScope( |
| resource_identifier, setting); |
| } |
| +void HostContentSettingsMap::MigrateOldSettings() { |
| + for (const ContentSettingsType& type : kMigrateContentSettingTypes) { |
| + ContentSettingsForOneType settings; |
| + GetSettingsForOneType(type, std::string(), &settings); |
| + for (const ContentSettingPatternSource& setting_entry : settings) { |
| + // 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. |
| + if (content_setting) { |
| + SetContentSettingDefaultScope(url, GURL(), type, std::string(), |
| + content_setting); |
| + } |
| + } |
| + } |
| + } |
| +} |
| + |
| ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
| const GURL& primary_url, |
| const GURL& secondary_url, |