summaryrefslogtreecommitdiffstats
path: root/components/content_settings
diff options
context:
space:
mode:
authorraymes <raymes@chromium.org>2015-08-16 21:02:11 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-17 04:03:14 +0000
commitd0753bbc0b350311589446e790805cc63b3fbd16 (patch)
tree6fd8746f2ca7adfec315ed3db2a6d4fcfbb716e2 /components/content_settings
parent79dc59ac7602413181079ecb463873e29a1d7d0a (diff)
downloadchromium_src-d0753bbc0b350311589446e790805cc63b3fbd16.zip
chromium_src-d0753bbc0b350311589446e790805cc63b3fbd16.tar.gz
chromium_src-d0753bbc0b350311589446e790805cc63b3fbd16.tar.bz2
Remove the array keyed off ContentSettingsType in PolicyProvider and replace with a map
The array of managed default prefs which is keyed to ContentSettingsType is fairly sparsely populated. Rather than have it keyed to ContentSettingsType, instead create an array which maps ContentSettingsType to the default policy pref name (similar to what we do for the Allowed/Blocked URL prefs). This means that when a new content setting is added, this array doesn't need to be updated. I did consider adding this to WebsiteSettingsInfo but it seems like the exception (rather than the rule) to add a new policy pref. Also there are some inconsistencies which make it hard to do this cleanly, e.g. the same mediastream pref is used for both camera and mic). I would rather leave this to a later cleanup. BUG=512683 Review URL: https://codereview.chromium.org/1276683004 Cr-Commit-Position: refs/heads/master@{#343627}
Diffstat (limited to 'components/content_settings')
-rw-r--r--components/content_settings/core/browser/content_settings_policy_provider.cc219
-rw-r--r--components/content_settings/core/browser/content_settings_policy_provider.h6
2 files changed, 87 insertions, 138 deletions
diff --git a/components/content_settings/core/browser/content_settings_policy_provider.cc b/components/content_settings/core/browser/content_settings_policy_provider.cc
index f7026e3..a0528bd0 100644
--- a/components/content_settings/core/browser/content_settings_policy_provider.cc
+++ b/components/content_settings/core/browser/content_settings_policy_provider.cc
@@ -19,39 +19,6 @@
namespace {
-// The preferences used to manage ContentSettingsTypes.
-const char* kPrefToManageType[] = {
- prefs::kManagedDefaultCookiesSetting,
- prefs::kManagedDefaultImagesSetting,
- prefs::kManagedDefaultJavaScriptSetting,
- prefs::kManagedDefaultPluginsSetting,
- prefs::kManagedDefaultPopupsSetting,
- prefs::kManagedDefaultGeolocationSetting,
- prefs::kManagedDefaultNotificationsSetting,
- nullptr, // No policy for default value of auto select certificate
- nullptr, // No policy for default value of fullscreen requests
- nullptr, // No policy for default value of mouse lock requests
- nullptr, // No policy for default value of mixed script blocking
- nullptr, // The MEDIASTREAM setting is deprecated
- prefs::kManagedDefaultMediaStreamSetting,
- prefs::kManagedDefaultMediaStreamSetting,
- nullptr, // No policy for default value of protocol handlers
- nullptr, // No policy for default value of PPAPI broker
- nullptr, // No policy for default value of multiple automatic downloads
- nullptr, // No policy for default value of MIDI system exclusive requests
- nullptr, // No policy for default value of push messaging requests
- nullptr, // No policy for default value of SSL certificate decisions
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
- nullptr, // No policy for default value of protected media identifier
-#endif
- nullptr, // No policy for default value of app banners
- nullptr, // No policy for default value of site engagement
- nullptr, // No policy for default value of durable storage
-};
-static_assert(arraysize(kPrefToManageType) == CONTENT_SETTINGS_NUM_TYPES,
- "kPrefToManageType should have CONTENT_SETTINGS_NUM_TYPES "
- "elements");
-
struct PrefsForManagedContentSettingsMapEntry {
const char* pref_name;
ContentSettingsType content_type;
@@ -60,65 +27,63 @@ struct PrefsForManagedContentSettingsMapEntry {
const PrefsForManagedContentSettingsMapEntry
kPrefsForManagedContentSettingsMap[] = {
- {
- prefs::kManagedCookiesAllowedForUrls,
- CONTENT_SETTINGS_TYPE_COOKIES,
- CONTENT_SETTING_ALLOW
- }, {
- prefs::kManagedCookiesBlockedForUrls,
- CONTENT_SETTINGS_TYPE_COOKIES,
- CONTENT_SETTING_BLOCK
- }, {
- prefs::kManagedCookiesSessionOnlyForUrls,
- CONTENT_SETTINGS_TYPE_COOKIES,
- CONTENT_SETTING_SESSION_ONLY
- }, {
- prefs::kManagedImagesAllowedForUrls,
- CONTENT_SETTINGS_TYPE_IMAGES,
- CONTENT_SETTING_ALLOW
- }, {
- prefs::kManagedImagesBlockedForUrls,
- CONTENT_SETTINGS_TYPE_IMAGES,
- CONTENT_SETTING_BLOCK
- }, {
- prefs::kManagedJavaScriptAllowedForUrls,
- CONTENT_SETTINGS_TYPE_JAVASCRIPT,
- CONTENT_SETTING_ALLOW
- }, {
- prefs::kManagedJavaScriptBlockedForUrls,
- CONTENT_SETTINGS_TYPE_JAVASCRIPT,
- CONTENT_SETTING_BLOCK
- }, {
- prefs::kManagedNotificationsAllowedForUrls,
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
- CONTENT_SETTING_ALLOW
- }, {
- prefs::kManagedNotificationsBlockedForUrls,
- CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
- CONTENT_SETTING_BLOCK
- }, {
- prefs::kManagedPluginsAllowedForUrls,
- CONTENT_SETTINGS_TYPE_PLUGINS,
- CONTENT_SETTING_ALLOW
- }, {
- prefs::kManagedPluginsBlockedForUrls,
- CONTENT_SETTINGS_TYPE_PLUGINS,
- CONTENT_SETTING_BLOCK
- }, {
- prefs::kManagedPopupsAllowedForUrls,
- CONTENT_SETTINGS_TYPE_POPUPS,
- CONTENT_SETTING_ALLOW
- }, {
- prefs::kManagedPopupsBlockedForUrls,
- CONTENT_SETTINGS_TYPE_POPUPS,
- CONTENT_SETTING_BLOCK
- }
-};
+ {prefs::kManagedCookiesAllowedForUrls, CONTENT_SETTINGS_TYPE_COOKIES,
+ CONTENT_SETTING_ALLOW},
+ {prefs::kManagedCookiesBlockedForUrls, CONTENT_SETTINGS_TYPE_COOKIES,
+ CONTENT_SETTING_BLOCK},
+ {prefs::kManagedCookiesSessionOnlyForUrls,
+ CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_SESSION_ONLY},
+ {prefs::kManagedImagesAllowedForUrls, CONTENT_SETTINGS_TYPE_IMAGES,
+ CONTENT_SETTING_ALLOW},
+ {prefs::kManagedImagesBlockedForUrls, CONTENT_SETTINGS_TYPE_IMAGES,
+ CONTENT_SETTING_BLOCK},
+ {prefs::kManagedJavaScriptAllowedForUrls,
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_ALLOW},
+ {prefs::kManagedJavaScriptBlockedForUrls,
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK},
+ {prefs::kManagedNotificationsAllowedForUrls,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW},
+ {prefs::kManagedNotificationsBlockedForUrls,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK},
+ {prefs::kManagedPluginsAllowedForUrls, CONTENT_SETTINGS_TYPE_PLUGINS,
+ CONTENT_SETTING_ALLOW},
+ {prefs::kManagedPluginsBlockedForUrls, CONTENT_SETTINGS_TYPE_PLUGINS,
+ CONTENT_SETTING_BLOCK},
+ {prefs::kManagedPopupsAllowedForUrls, CONTENT_SETTINGS_TYPE_POPUPS,
+ CONTENT_SETTING_ALLOW},
+ {prefs::kManagedPopupsBlockedForUrls, CONTENT_SETTINGS_TYPE_POPUPS,
+ CONTENT_SETTING_BLOCK}};
} // namespace
namespace content_settings {
+// The preferences used to manage the default policy value for
+// ContentSettingsTypes.
+struct PolicyProvider::PrefsForManagedDefaultMapEntry {
+ ContentSettingsType content_type;
+ const char* pref_name;
+};
+
+// static
+const PolicyProvider::PrefsForManagedDefaultMapEntry
+ PolicyProvider::kPrefsForManagedDefault[] = {
+ {CONTENT_SETTINGS_TYPE_COOKIES, prefs::kManagedDefaultCookiesSetting},
+ {CONTENT_SETTINGS_TYPE_IMAGES, prefs::kManagedDefaultImagesSetting},
+ {CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ prefs::kManagedDefaultGeolocationSetting},
+ {CONTENT_SETTINGS_TYPE_JAVASCRIPT,
+ prefs::kManagedDefaultJavaScriptSetting},
+ {CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
+ prefs::kManagedDefaultMediaStreamSetting},
+ {CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
+ prefs::kManagedDefaultMediaStreamSetting},
+ {CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ prefs::kManagedDefaultNotificationsSetting},
+ {CONTENT_SETTINGS_TYPE_PLUGINS, prefs::kManagedDefaultPluginsSetting},
+ {CONTENT_SETTINGS_TYPE_POPUPS, prefs::kManagedDefaultPopupsSetting},
+};
+
// static
void PolicyProvider::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
@@ -348,39 +313,31 @@ void PolicyProvider::GetAutoSelectCertificateSettingsFromPreferences(
}
void PolicyProvider::ReadManagedDefaultSettings() {
- for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) {
- if (kPrefToManageType[type] == nullptr) {
- continue;
- }
- UpdateManagedDefaultSetting(ContentSettingsType(type));
- }
+ for (const PrefsForManagedDefaultMapEntry& entry : kPrefsForManagedDefault)
+ UpdateManagedDefaultSetting(entry);
}
void PolicyProvider::UpdateManagedDefaultSetting(
- ContentSettingsType content_type) {
+ const PrefsForManagedDefaultMapEntry& entry) {
// If a pref to manage a default-content-setting was not set (NOTICE:
// "HasPrefPath" returns false if no value was set for a registered pref) then
// the default value of the preference is used. The default value of a
// preference to manage a default-content-settings is CONTENT_SETTING_DEFAULT.
// This indicates that no managed value is set. If a pref was set, than it
// MUST be managed.
- DCHECK(!prefs_->HasPrefPath(kPrefToManageType[content_type]) ||
- prefs_->IsManagedPreference(kPrefToManageType[content_type]));
+ DCHECK(!prefs_->HasPrefPath(entry.pref_name) ||
+ prefs_->IsManagedPreference(entry.pref_name));
base::AutoLock auto_lock(lock_);
- int setting = prefs_->GetInteger(kPrefToManageType[content_type]);
+ int setting = prefs_->GetInteger(entry.pref_name);
if (setting == CONTENT_SETTING_DEFAULT) {
- value_map_.DeleteValue(
- ContentSettingsPattern::Wildcard(),
- ContentSettingsPattern::Wildcard(),
- content_type,
- std::string());
+ value_map_.DeleteValue(ContentSettingsPattern::Wildcard(),
+ ContentSettingsPattern::Wildcard(),
+ entry.content_type, std::string());
} else {
value_map_.SetValue(ContentSettingsPattern::Wildcard(),
- ContentSettingsPattern::Wildcard(),
- content_type,
- std::string(),
- new base::FundamentalValue(setting));
+ ContentSettingsPattern::Wildcard(), entry.content_type,
+ std::string(), new base::FundamentalValue(setting));
}
}
@@ -420,37 +377,25 @@ void PolicyProvider::ShutdownOnUIThread() {
void PolicyProvider::OnPreferenceChanged(const std::string& name) {
DCHECK(CalledOnValidThread());
- if (name == prefs::kManagedDefaultCookiesSetting) {
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES);
- } else if (name == prefs::kManagedDefaultImagesSetting) {
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_IMAGES);
- } else if (name == prefs::kManagedDefaultJavaScriptSetting) {
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
- } else if (name == prefs::kManagedDefaultPluginsSetting) {
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS);
- } else if (name == prefs::kManagedDefaultPopupsSetting) {
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS);
- } else if (name == prefs::kManagedDefaultGeolocationSetting) {
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION);
- } else if (name == prefs::kManagedDefaultNotificationsSetting) {
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
- } else if (name == prefs::kManagedDefaultMediaStreamSetting) {
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
- UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
- } else if (name == prefs::kManagedAutoSelectCertificateForUrls ||
- name == prefs::kManagedCookiesAllowedForUrls ||
- name == prefs::kManagedCookiesBlockedForUrls ||
- name == prefs::kManagedCookiesSessionOnlyForUrls ||
- name == prefs::kManagedImagesAllowedForUrls ||
- name == prefs::kManagedImagesBlockedForUrls ||
- name == prefs::kManagedJavaScriptAllowedForUrls ||
- name == prefs::kManagedJavaScriptBlockedForUrls ||
- name == prefs::kManagedNotificationsAllowedForUrls ||
- name == prefs::kManagedNotificationsBlockedForUrls ||
- name == prefs::kManagedPluginsAllowedForUrls ||
- name == prefs::kManagedPluginsBlockedForUrls ||
- name == prefs::kManagedPopupsAllowedForUrls ||
- name == prefs::kManagedPopupsBlockedForUrls) {
+ for (const PrefsForManagedDefaultMapEntry& entry : kPrefsForManagedDefault) {
+ if (entry.pref_name == name)
+ UpdateManagedDefaultSetting(entry);
+ }
+
+ if (name == prefs::kManagedAutoSelectCertificateForUrls ||
+ name == prefs::kManagedCookiesAllowedForUrls ||
+ name == prefs::kManagedCookiesBlockedForUrls ||
+ name == prefs::kManagedCookiesSessionOnlyForUrls ||
+ name == prefs::kManagedImagesAllowedForUrls ||
+ name == prefs::kManagedImagesBlockedForUrls ||
+ name == prefs::kManagedJavaScriptAllowedForUrls ||
+ name == prefs::kManagedJavaScriptBlockedForUrls ||
+ name == prefs::kManagedNotificationsAllowedForUrls ||
+ name == prefs::kManagedNotificationsBlockedForUrls ||
+ name == prefs::kManagedPluginsAllowedForUrls ||
+ name == prefs::kManagedPluginsBlockedForUrls ||
+ name == prefs::kManagedPopupsAllowedForUrls ||
+ name == prefs::kManagedPopupsBlockedForUrls) {
ReadManagedContentSettings(true);
ReadManagedDefaultSettings();
}
diff --git a/components/content_settings/core/browser/content_settings_policy_provider.h b/components/content_settings/core/browser/content_settings_policy_provider.h
index b0a80a1..a8153c3 100644
--- a/components/content_settings/core/browser/content_settings_policy_provider.h
+++ b/components/content_settings/core/browser/content_settings_policy_provider.h
@@ -46,6 +46,10 @@ class PolicyProvider : public ObservableProvider {
void ShutdownOnUIThread() override;
private:
+ struct PrefsForManagedDefaultMapEntry;
+
+ static const PrefsForManagedDefaultMapEntry kPrefsForManagedDefault[];
+
// Reads the policy managed default settings.
void ReadManagedDefaultSettings();
@@ -53,7 +57,7 @@ class PolicyProvider : public ObservableProvider {
void OnPreferenceChanged(const std::string& pref_name);
// Reads the policy controlled default settings for a specific content type.
- void UpdateManagedDefaultSetting(ContentSettingsType content_type);
+ void UpdateManagedDefaultSetting(const PrefsForManagedDefaultMapEntry& entry);
void ReadManagedContentSettings(bool overwrite);