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 6b56ae6e7f863dec90f9a3cc482015fefa96ccb3..39a971e95ad7f668b314d0b322fc78a2c7518500 100644 |
| --- a/components/content_settings/core/browser/host_content_settings_map.cc |
| +++ b/components/content_settings/core/browser/host_content_settings_map.cc |
| @@ -32,6 +32,7 @@ |
| #include "components/content_settings/core/common/pref_names.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| #include "components/prefs/pref_service.h" |
| +#include "components/syncable_prefs/pref_model_associator.h" |
| #include "net/base/net_errors.h" |
| #include "net/base/static_cookie_policy.h" |
| #include "url/gurl.h" |
| @@ -118,11 +119,7 @@ content_settings::PatternPair GetPatternsFromScopingType( |
| content_settings::PatternPair patterns; |
| switch (scoping_type) { |
| - case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: |
| - case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE: |
| - patterns.first = ContentSettingsPattern::FromURL(primary_url); |
| - patterns.second = ContentSettingsPattern::Wildcard(); |
| - break; |
| + case WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE: |
| case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: |
| patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| patterns.second = ContentSettingsPattern::Wildcard(); |
| @@ -172,8 +169,12 @@ HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
| content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
| MigrateKeygenSettings(); |
| - |
| + MigrateDomainScopedSettings(); |
| RecordNumberOfExceptions(); |
| + |
| + syncable_prefs::PrefModelAssociator::SetMergeDataFinishedCallback( |
| + base::Bind(&HostContentSettingsMap::MigrateDomainScopedSettings, |
| + base::Unretained(this))); |
| } |
| // static |
| @@ -497,6 +498,60 @@ void HostContentSettingsMap::MigrateKeygenSettings() { |
| } |
| } |
| +void HostContentSettingsMap::MigrateDomainScopedSettings() { |
| + const ContentSettingsType kDomainScopedTypes[] = { |
| + CONTENT_SETTINGS_TYPE_COOKIES, |
| +#if !defined(OS_ANDROID) && !defined(OS_IOS) |
|
raymes
2016/06/16 03:23:51
Rather than the ifdefs, can we just check to see i
lshang
2016/06/20 01:34:22
Done.
|
| + CONTENT_SETTINGS_TYPE_IMAGES, |
| + CONTENT_SETTINGS_TYPE_PLUGINS, |
| +#endif |
| +#if !defined(OS_IOS) |
| + CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| + CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| +#endif |
| + CONTENT_SETTINGS_TYPE_POPUPS |
| + }; |
| + for (const ContentSettingsType& type : kDomainScopedTypes) { |
| + DCHECK(content_settings::ContentSettingsRegistry::GetInstance()->Get(type)); |
| + 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 ALLOW settings only. |
| + if (setting_entry.setting != CONTENT_SETTING_ALLOW) |
| + continue; |
| + // Skip default settings. |
| + if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard() && |
| + setting_entry.secondary_pattern == ContentSettingsPattern::Wildcard()) |
|
raymes
2016/06/16 03:23:51
nit: add {}
lshang
2016/06/20 01:34:22
Done.
|
| + continue; |
|
raymes
2016/06/16 03:23:50
Should we also DCHECK that the secondary_pattern i
lshang
2016/06/20 01:34:22
Done.
|
| + if (setting_entry.primary_pattern.IsGeneratedFromURLDomainScoped()) { |
|
raymes
2016/06/16 03:23:50
What about using "continue" here (if this evaluate
lshang
2016/06/20 01:34:22
Done.
|
| + ContentSettingsPattern origin_pattern = |
| + ContentSettingsPattern::FromDomainToOrigin( |
| + setting_entry.primary_pattern); |
| + GURL origin(origin_pattern.ToString()); |
| + if (origin.is_valid()) { |
|
raymes
2016/06/16 03:23:51
Same here
lshang
2016/06/20 01:34:22
Done.
|
| + ContentSetting origin_setting = |
|
raymes
2016/06/16 03:23:51
Maybe say:
// Ensure that the current resolved con
lshang
2016/06/20 01:34:22
Done.
|
| + GetContentSetting(origin, origin, type, std::string()); |
| + |
| + // Remove the domiain scoped pattern. |
|
raymes
2016/06/16 03:23:50
// Remove the domain scoped pattern. If |origin_se
lshang
2016/06/20 01:34:22
Done.
|
| + SetContentSettingCustomScope(setting_entry.primary_pattern, |
| + setting_entry.secondary_pattern, type, |
| + std::string(), CONTENT_SETTING_DEFAULT); |
| + |
| + // If the current setting of narrow-down origin is ALLOW, then add a |
| + // new setting entry of this origin. |
|
raymes
2016/06/16 03:23:51
// If the current resolved content setting is allo
lshang
2016/06/20 01:34:22
Done.
|
| + if (origin_setting == CONTENT_SETTING_ALLOW) |
| + SetContentSettingDefaultScope(origin, GURL(), type, std::string(), |
| + CONTENT_SETTING_ALLOW); |
| + } |
| + } |
| + } |
| + } |
| +} |
| + |
| void HostContentSettingsMap::RecordNumberOfExceptions() { |
| for (const content_settings::WebsiteSettingsInfo* info : |
| *content_settings::WebsiteSettingsRegistry::GetInstance()) { |
| @@ -654,6 +709,7 @@ void HostContentSettingsMap::OnContentSettingChanged( |
| HostContentSettingsMap::~HostContentSettingsMap() { |
| DCHECK(!prefs_); |
| STLDeleteValues(&content_settings_providers_); |
| + syncable_prefs::PrefModelAssociator::ResetMergeDataFinishedCallback(); |
| } |
| void HostContentSettingsMap::ShutdownOnUIThread() { |