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

Unified Diff: components/content_settings/core/browser/host_content_settings_map.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: address review comments and split the CL Created 4 years, 6 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/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..bd2562b5aae7547b4fa88034bd92eea461d570b5 100644
--- a/components/content_settings/core/browser/host_content_settings_map.cc
+++ b/components/content_settings/core/browser/host_content_settings_map.cc
@@ -497,6 +497,70 @@ void HostContentSettingsMap::MigrateKeygenSettings() {
}
}
+void HostContentSettingsMap::MigrateDomainScopedSettings() {
+ const ContentSettingsType kDomainScopedTypes[] = {
+ CONTENT_SETTINGS_TYPE_COOKIES,
+ CONTENT_SETTINGS_TYPE_IMAGES,
+ CONTENT_SETTINGS_TYPE_PLUGINS,
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT,
+ CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
+ CONTENT_SETTINGS_TYPE_POPUPS};
+ for (const ContentSettingsType& type : kDomainScopedTypes) {
+ if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type))
+ continue;
+ 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()) {
+ continue;
+ }
+
+ DCHECK(setting_entry.secondary_pattern ==
raymes 2016/06/20 04:03:26 DCHECK_EQ
lshang 2016/06/23 01:32:31 Compiler complains when I change to use DCHECK_EQ
raymes 2016/06/27 07:23:29 What's the error?
+ ContentSettingsPattern::Wildcard());
+
+ if (!setting_entry.primary_pattern.IsGeneratedUsingFromURL())
+ continue;
+
+ ContentSettingsPattern origin_pattern =
+ ContentSettingsPattern::FromDomainToOrigin(
+ setting_entry.primary_pattern);
+ GURL origin(origin_pattern.ToString());
+ if (!origin.is_valid())
raymes 2016/06/20 04:03:26 Are there cases where this is possible? Should we
lshang 2016/06/23 01:32:31 Done.
+ continue;
+ // Ensure that the current resolved content setting for this origin is
+ // allowed. Otherwise we may be overriding some narrower setting which is
+ // set to block.
+ ContentSetting origin_setting =
+ GetContentSetting(origin, origin, type, std::string());
+
+ // Remove the domain scoped pattern. If |origin_setting| is not
+ // CONTENT_SETTING_ALLOW it implies there is some narrower pattern in
+ // effect, so it's still safe to remove the domain-scoped pattern.
+ SetContentSettingCustomScope(setting_entry.primary_pattern,
+ setting_entry.secondary_pattern, type,
+ std::string(), CONTENT_SETTING_DEFAULT);
+
+ // If the current resolved content setting is allowed it's safe to set the
+ // origin-scoped pattern.
+ if (origin_setting == CONTENT_SETTING_ALLOW)
+ SetContentSettingCustomScope(
+ ContentSettingsPattern::FromURLNoWildcard(origin),
+ ContentSettingsPattern::Wildcard(), type, std::string(),
+ CONTENT_SETTING_ALLOW);
+ }
+ }
+}
+
void HostContentSettingsMap::RecordNumberOfExceptions() {
for (const content_settings::WebsiteSettingsInfo* info :
*content_settings::WebsiteSettingsRegistry::GetInstance()) {

Powered by Google App Engine
This is Rietveld 408576698