summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);