summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 09:38:03 +0000
committermarkusheintz@chromium.org <markusheintz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 09:38:03 +0000
commit8f7a1406139af3b49506e85f728b1ab6e6bf6683 (patch)
tree073a3d424037c6c26ee970adb3603176f080b476 /chrome
parentb881f4f4f4dd39bd84f7b130b2307c7f0bfbc268 (diff)
downloadchromium_src-8f7a1406139af3b49506e85f728b1ab6e6bf6683.zip
chromium_src-8f7a1406139af3b49506e85f728b1ab6e6bf6683.tar.gz
chromium_src-8f7a1406139af3b49506e85f728b1ab6e6bf6683.tar.bz2
Add additional preferences and policies to manage default-content-settings.
BUG=49607 TEST=host_content_settings_map_unittest.cc Review URL: http://codereview.chromium.org/4668001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/host_content_settings_map.cc129
-rw-r--r--chrome/browser/host_content_settings_map.h17
-rw-r--r--chrome/browser/host_content_settings_map_unittest.cc236
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.cc20
-rw-r--r--chrome/browser/policy/configuration_policy_store_interface.h5
-rw-r--r--chrome/common/policy_constants.cc5
-rw-r--r--chrome/common/policy_constants.h5
-rw-r--r--chrome/common/pref_names.cc13
-rw-r--r--chrome/common/pref_names.h6
9 files changed, 432 insertions, 4 deletions
diff --git a/chrome/browser/host_content_settings_map.cc b/chrome/browser/host_content_settings_map.cc
index 2f90bfd..dc6517c 100644
--- a/chrome/browser/host_content_settings_map.cc
+++ b/chrome/browser/host_content_settings_map.cc
@@ -43,6 +43,11 @@ const char kDomainWildcard[] = "[*.]";
// The length of kDomainWildcard (without the trailing '\0')
const size_t kDomainWildcardLength = arraysize(kDomainWildcard) - 1;
+// Base pref path of the prefs that contain the managed default content
+// settings values.
+const std::string kManagedSettings =
+ "profile.managed_default_content_settings";
+
// The preference keys where resource identifiers are stored for
// ContentSettingsType values that support resource identifiers.
const char* kResourceTypeNames[CONTENT_SETTINGS_NUM_TYPES] = {
@@ -66,6 +71,17 @@ const char* kTypeNames[CONTENT_SETTINGS_NUM_TYPES] = {
NULL, // Not used for Notifications
};
+// The preferences used to manage ContentSettingsTypes.
+const char* kPrefToManageType[CONTENT_SETTINGS_NUM_TYPES] = {
+ prefs::kManagedDefaultCookiesSetting,
+ prefs::kManagedDefaultImagesSetting,
+ prefs::kManagedDefaultJavaScriptSetting,
+ prefs::kManagedDefaultPluginsSetting,
+ prefs::kManagedDefaultPopupsSetting,
+ NULL, // Not used for Geolocation
+ NULL, // Not used for Notifications
+};
+
// The default setting for each content type.
const ContentSetting kDefaultSettings[CONTENT_SETTINGS_NUM_TYPES] = {
CONTENT_SETTING_ALLOW, // CONTENT_SETTINGS_TYPE_COOKIES
@@ -229,6 +245,18 @@ HostContentSettingsMap::HostContentSettingsMap(Profile* profile)
pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this);
pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this);
pref_change_registrar_.Add(prefs::kBlockNonsandboxedPlugins, this);
+ // The following preferences are only used to indicate if a
+ // default-content-setting is managed and to hold the managed default-setting
+ // value. If the value for any of the following perferences is set then the
+ // corresponding default-content-setting is managed. These preferences exist
+ // in parallel to the preference default-content-settings. If a
+ // default-content-settings-type is managed any user defined excpetions
+ // (patterns) for this type are ignored.
+ pref_change_registrar_.Add(prefs::kManagedDefaultCookiesSetting, this);
+ pref_change_registrar_.Add(prefs::kManagedDefaultImagesSetting, this);
+ pref_change_registrar_.Add(prefs::kManagedDefaultJavaScriptSetting, this);
+ pref_change_registrar_.Add(prefs::kManagedDefaultPluginsSetting, this);
+ pref_change_registrar_.Add(prefs::kManagedDefaultPopupsSetting, this);
notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
Source<Profile>(profile_));
}
@@ -243,6 +271,19 @@ void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kBlockNonsandboxedPlugins, false);
prefs->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0);
+ // Preferences for default content setting policies. A policy is not set of
+ // the corresponding preferences below is set to CONTENT_SETTING_DEFAULT.
+ prefs->RegisterIntegerPref(prefs::kManagedDefaultCookiesSetting,
+ CONTENT_SETTING_DEFAULT);
+ prefs->RegisterIntegerPref(prefs::kManagedDefaultImagesSetting,
+ CONTENT_SETTING_DEFAULT);
+ prefs->RegisterIntegerPref(prefs::kManagedDefaultJavaScriptSetting,
+ CONTENT_SETTING_DEFAULT);
+ prefs->RegisterIntegerPref(prefs::kManagedDefaultPluginsSetting,
+ CONTENT_SETTING_DEFAULT);
+ prefs->RegisterIntegerPref(prefs::kManagedDefaultPopupsSetting,
+ CONTENT_SETTING_DEFAULT);
+
// Obsolete prefs, for migration:
prefs->RegisterIntegerPref(prefs::kCookieBehavior,
net::StaticCookiePolicy::ALLOW_ALL_COOKIES);
@@ -253,6 +294,8 @@ void HostContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
ContentSettingsType content_type) const {
AutoLock auto_lock(lock_);
+ if (IsDefaultContentSettingManaged(content_type))
+ return managed_default_content_settings_.settings[content_type];
return default_content_settings_.settings[content_type];
}
@@ -263,8 +306,10 @@ ContentSetting HostContentSettingsMap::GetContentSetting(
ContentSetting setting = GetNonDefaultContentSetting(url,
content_type,
resource_identifier);
- if (setting == CONTENT_SETTING_DEFAULT)
+ if (setting == CONTENT_SETTING_DEFAULT ||
+ IsDefaultContentSettingManaged(content_type)) {
return GetDefaultContentSetting(content_type);
+ }
return setting;
}
@@ -283,6 +328,12 @@ ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting(
DCHECK(!resource_identifier.empty());
}
+ // Host content settings are ignored if the default_content_setting is
+ // managed.
+ if (IsDefaultContentSettingManaged(content_type)) {
+ return GetDefaultContentSetting(content_type);
+ }
+
AutoLock auto_lock(lock_);
const std::string host(net::GetHostOrSpecFromURL(url));
@@ -345,10 +396,19 @@ ContentSettings HostContentSettingsMap::GetContentSettings(
// If we require a resource identifier, set the content settings to default,
// otherwise make the defaults explicit.
for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
- if (RequiresResourceIdentifier(ContentSettingsType(j)))
+ if (RequiresResourceIdentifier(ContentSettingsType(j))) {
output.settings[j] = CONTENT_SETTING_DEFAULT;
- else if (output.settings[j] == CONTENT_SETTING_DEFAULT)
- output.settings[j] = default_content_settings_.settings[j];
+ } else {
+ if (output.settings[j] == CONTENT_SETTING_DEFAULT) {
+ output.settings[j] = default_content_settings_.settings[j];
+ }
+ // A managed default content setting has the highest priority and hence
+ // will overwrite any previously set value.
+ if (IsDefaultContentSettingManaged(ContentSettingsType(j))) {
+ output.settings[j] =
+ managed_default_content_settings_.settings[j];
+ }
+ }
}
return output;
}
@@ -777,6 +837,26 @@ void HostContentSettingsMap::Observe(NotificationType type,
AutoLock auto_lock(lock_);
block_nonsandboxed_plugins_ = profile_->GetPrefs()->GetBoolean(
prefs::kBlockNonsandboxedPlugins);
+ } else if (prefs::kManagedDefaultCookiesSetting == *name) {
+ UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES,
+ profile_->GetPrefs(),
+ &managed_default_content_settings_);
+ } else if (prefs::kManagedDefaultImagesSetting == *name) {
+ UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_IMAGES,
+ profile_->GetPrefs(),
+ &managed_default_content_settings_);
+ } else if (prefs::kManagedDefaultJavaScriptSetting == *name) {
+ UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
+ profile_->GetPrefs(),
+ &managed_default_content_settings_);
+ } else if (prefs::kManagedDefaultPluginsSetting == *name) {
+ UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
+ profile_->GetPrefs(),
+ &managed_default_content_settings_);
+ } else if (prefs::kManagedDefaultPopupsSetting == *name) {
+ UpdateManagedDefaultSetting(CONTENT_SETTINGS_TYPE_POPUPS,
+ profile_->GetPrefs(),
+ &managed_default_content_settings_);
} else {
NOTREACHED() << "Unexpected preference observed";
return;
@@ -889,6 +969,47 @@ void HostContentSettingsMap::ReadDefaultSettings(bool overwrite) {
&default_content_settings_);
}
ForceDefaultsToBeExplicit();
+
+ // Read managed default content settings.
+ ReadManagedDefaultSettings(prefs, &managed_default_content_settings_);
+}
+
+void HostContentSettingsMap::ReadManagedDefaultSettings (
+ const PrefService* prefs, ContentSettings* settings) {
+ for (size_t type = 0; type < arraysize(kPrefToManageType); ++type) {
+ if (kPrefToManageType[type] == NULL) {
+ // TODO(markusheintz): Handle Geolocation and notification separately.
+ continue;
+ }
+ UpdateManagedDefaultSetting(ContentSettingsType(type), prefs, settings);
+ }
+}
+
+void HostContentSettingsMap::UpdateManagedDefaultSetting(
+ ContentSettingsType type,
+ const PrefService* prefs,
+ ContentSettings* settings) {
+ // 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[type]) ||
+ prefs->IsManagedPreference(kPrefToManageType[type]));
+ AutoLock auto_lock(lock_);
+ settings->settings[type] = IntToContentSetting(
+ prefs->GetInteger(kPrefToManageType[type]));
+}
+
+bool HostContentSettingsMap::IsDefaultContentSettingManaged(
+ ContentSettingsType content_type) const {
+ // All managed_default_content_settings_ are always set explicitly or
+ // initialized to CONTENT_SETTINGS_DEFAULT. Hence each content settings type
+ // that is set to CONTENT_SETTINGS_DEFAULT is not managed since it was not set
+ // explicitly.
+ return managed_default_content_settings_.settings[content_type] !=
+ CONTENT_SETTING_DEFAULT;
}
void HostContentSettingsMap::ReadExceptions(bool overwrite) {
diff --git a/chrome/browser/host_content_settings_map.h b/chrome/browser/host_content_settings_map.h
index 25edb99..449ece2 100644
--- a/chrome/browser/host_content_settings_map.h
+++ b/chrome/browser/host_content_settings_map.h
@@ -234,6 +234,9 @@ class HostContentSettingsMap
// This should only be called on the UI thread.
void ResetToDefaults();
+ // Returns true if the default setting for the |content_type| is managed.
+ bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const;
+
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
@@ -269,6 +272,19 @@ class HostContentSettingsMap
// true and the preference is missing, the local copy will be cleared as well.
void ReadDefaultSettings(bool overwrite);
+ // Reads managed default content settings from the preference service |prefs|.
+ // |settings| is set to the respective content setting for managed settings,
+ // and to CONTENT_SETTING_DEFAULT for other settings.
+ void ReadManagedDefaultSettings(const PrefService* prefs,
+ ContentSettings* settings);
+
+ // Updates the managed setting of the default-content-settings-type |type|.
+ // The updated setting is read from the preference service |prefs| and written
+ // to |settings|.
+ void UpdateManagedDefaultSetting(ContentSettingsType type,
+ const PrefService* prefs,
+ ContentSettings* settings);
+
// Reads the host exceptions from the prefereces service. If |overwrite| is
// true and the preference is missing, the local copy will be cleared as well.
void ReadExceptions(bool overwrite);
@@ -300,6 +316,7 @@ class HostContentSettingsMap
// Copies of the pref data, so that we can read it on the IO thread.
ContentSettings default_content_settings_;
+ ContentSettings managed_default_content_settings_;
HostContentSettings host_content_settings_;
// Differences to the preference-stored host content settings for
diff --git a/chrome/browser/host_content_settings_map_unittest.cc b/chrome/browser/host_content_settings_map_unittest.cc
index a66e971..1312d43 100644
--- a/chrome/browser/host_content_settings_map_unittest.cc
+++ b/chrome/browser/host_content_settings_map_unittest.cc
@@ -14,6 +14,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "chrome/test/testing_pref_service.h"
#include "chrome/test/testing_profile.h"
#include "googleurl/src/gurl.h"
#include "net/base/static_cookie_policy.h"
@@ -49,6 +50,7 @@ class StubSettingsObserver : public NotificationObserver {
last_pattern = settings_details.ptr()->pattern();
last_update_all = settings_details.ptr()->update_all();
last_update_all_types = settings_details.ptr()->update_all_types();
+ last_type = settings_details.ptr()->type();
// This checks that calling a Get function from an observer doesn't
// deadlock.
last_notifier->GetContentSettings(GURL("http://random-hostname.com/"));
@@ -59,6 +61,7 @@ class StubSettingsObserver : public NotificationObserver {
bool last_update_all;
bool last_update_all_types;
int counter;
+ ContentSettingsType last_type;
private:
NotificationRegistrar registrar_;
@@ -748,4 +751,237 @@ TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) {
prefs_as_json.c_str());
}
+// If a default-content-setting is managed, the managed value should be used
+// instead of the default value.
+TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
+ TestingProfile profile;
+ HostContentSettingsMap* host_content_settings_map =
+ profile.GetHostContentSettingsMap();
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT));
+
+ // Set managed-default-content-setting through the coresponding preferences.
+ prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT));
+
+ // Remove managed-default-content-settings-preferences.
+ prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT));
+
+ // Set preference to manage the default-content-setting for Plugins.
+ prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_PLUGINS));
+
+ // Remove the preference to manage the default-content-setting for Plugins.
+ prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_PLUGINS));
+}
+
+TEST_F(HostContentSettingsMapTest,
+ GetNonDefaultContentSettingsIfTypeManaged) {
+ TestingProfile profile;
+ HostContentSettingsMap* host_content_settings_map =
+ profile.GetHostContentSettingsMap();
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+
+ // Set pattern for JavaScript setting.
+ HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ host_content_settings_map->SetContentSetting(pattern,
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK);
+
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT));
+
+ GURL host("http://example.com/");
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, ""));
+
+ // Set managed-default-content-setting for content-settings-type JavaScript.
+ prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, ""));
+}
+
+// Managed default content setting should have higher priority
+// than user defined patterns.
+TEST_F(HostContentSettingsMapTest,
+ ManagedDefaultContentSettingIgnoreUserPattern) {
+ TestingProfile profile;
+ HostContentSettingsMap* host_content_settings_map =
+ profile.GetHostContentSettingsMap();
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+
+ // Block all JavaScript.
+ host_content_settings_map->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
+
+ // Set an exception to allow "[*.]example.com"
+ HostContentSettingsMap::Pattern pattern("[*.]example.com");
+ host_content_settings_map->SetContentSetting(pattern,
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_ALLOW);
+
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT));
+ GURL host("http://example.com/");
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, ""));
+
+ // Set managed-default-content-settings-preferences.
+ prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, ""));
+
+ // Remove managed-default-content-settings-preferences.
+ prefs->RemoveManagedPref(prefs::kManagedDefaultJavaScriptSetting);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, ""));
+}
+
+// If a default-content-setting is set to managed setting, the user defined
+// setting should be preserved.
+TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
+ TestingProfile profile;
+ HostContentSettingsMap* host_content_settings_map =
+ profile.GetHostContentSettingsMap();
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+
+ // Set user defined default-content-setting for Cookies.
+ host_content_settings_map->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_COOKIES));
+
+ // Set preference to manage the default-content-setting for Cookies.
+ prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_COOKIES));
+
+ // Remove the preference to manage the default-content-setting for Cookies.
+ prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_COOKIES));
+ }
+
+// When a default-content-setting is set to a managed setting a
+// CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen
+// if the managed setting is removed.
+TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsChange) {
+ TestingProfile profile;
+ HostContentSettingsMap* host_content_settings_map =
+ profile.GetHostContentSettingsMap();
+ StubSettingsObserver observer;
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+
+ // TODO(markusheintz): I think it would be better to send notifications only
+ // for a specific content-settings-type.
+
+ // Set the managed default-content-setting.
+ prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
+ EXPECT_EQ(host_content_settings_map, observer.last_notifier);
+ EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
+ EXPECT_TRUE(observer.last_update_all);
+ EXPECT_TRUE(observer.last_update_all_types);
+ EXPECT_EQ(1, observer.counter);
+
+ // Remove the managed default-content-setting.
+ prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
+ EXPECT_EQ(host_content_settings_map, observer.last_notifier);
+ EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
+ EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_TRUE(observer.last_update_all);
+ EXPECT_TRUE(observer.last_update_all_types);
+ EXPECT_EQ(2, observer.counter);
+}
+
+// When a default-content-setting is set to a managed setting a
+// CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen
+// if the managed setting is removed. In this test-case the actual managed
+// setting is the same. Just the managed status of the default-content-setting
+// changes.
+TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsNoChange) {
+ TestingProfile profile;
+ HostContentSettingsMap* host_content_settings_map =
+ profile.GetHostContentSettingsMap();
+ StubSettingsObserver observer;
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+
+ // TODO(markusheintz): I think it would be better to send notifications only
+ // for a specific content-settings-type.
+
+ // Set the managed default-content-setting. In this case the actual setting
+ // does not change.
+ prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
+ EXPECT_EQ(host_content_settings_map, observer.last_notifier);
+ EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
+ EXPECT_TRUE(observer.last_update_all);
+ EXPECT_TRUE(observer.last_update_all_types);
+ EXPECT_EQ(1, observer.counter);
+
+ // Remove the managed default-content-setting.
+ prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
+ EXPECT_EQ(host_content_settings_map, observer.last_notifier);
+ EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type);
+ EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern);
+ EXPECT_TRUE(observer.last_update_all);
+ EXPECT_TRUE(observer.last_update_all_types);
+ EXPECT_EQ(2, observer.counter);
+}
+
+// If a setting for a default-content-setting-type is set while the type is
+// managed, then the new setting should be preserved and used after the
+// default-content-setting-type is not managed anymore.
+TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
+ TestingProfile profile;
+ HostContentSettingsMap* host_content_settings_map =
+ profile.GetHostContentSettingsMap();
+ TestingPrefService* prefs = profile.GetTestingPrefService();
+
+ prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_PLUGINS));
+
+ host_content_settings_map->SetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
+ EXPECT_EQ(CONTENT_SETTING_ALLOW,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_PLUGINS));
+
+ prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
+ EXPECT_EQ(CONTENT_SETTING_BLOCK,
+ host_content_settings_map->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_PLUGINS));
+}
+
} // namespace
diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc
index e83887f..67294c7 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store.cc
@@ -155,6 +155,16 @@ const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry
prefs::kDevToolsDisabled },
{ Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies,
prefs::kBlockThirdPartyCookies},
+ { Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting,
+ prefs::kManagedDefaultCookiesSetting},
+ { Value::TYPE_INTEGER, kPolicyDefaultImagesSetting,
+ prefs::kManagedDefaultImagesSetting},
+ { Value::TYPE_INTEGER, kPolicyDefaultJavaScriptSetting,
+ prefs::kManagedDefaultJavaScriptSetting},
+ { Value::TYPE_INTEGER, kPolicyDefaultPluginsSetting,
+ prefs::kManagedDefaultPluginsSetting},
+ { Value::TYPE_INTEGER, kPolicyDefaultPopupsSetting,
+ prefs::kManagedDefaultPopupsSetting},
{ Value::TYPE_STRING, kPolicyAuthSchemes,
prefs::kAuthSchemes },
{ Value::TYPE_BOOLEAN, kPolicyDisableAuthNegotiateCnameLookup,
@@ -262,6 +272,16 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() {
key::kDeveloperToolsDisabled },
{ kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN,
key::kBlockThirdPartyCookies },
+ { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER,
+ key::kDefaultCookiesSetting},
+ { kPolicyDefaultImagesSetting, Value::TYPE_INTEGER,
+ key::kDefaultImagesSetting},
+ { kPolicyDefaultJavaScriptSetting, Value::TYPE_INTEGER,
+ key::kDefaultJavaScriptSetting},
+ { kPolicyDefaultPluginsSetting, Value::TYPE_INTEGER,
+ key::kDefaultPluginsSetting},
+ { kPolicyDefaultPopupsSetting, Value::TYPE_INTEGER,
+ key::kDefaultPopupsSetting},
{ kPolicyAuthSchemes, Value::TYPE_STRING, key::kAuthSchemes },
{ kPolicyDisableAuthNegotiateCnameLookup, Value::TYPE_BOOLEAN,
key::kDisableAuthNegotiateCnameLookup },
diff --git a/chrome/browser/policy/configuration_policy_store_interface.h b/chrome/browser/policy/configuration_policy_store_interface.h
index 646430b..cfb943e 100644
--- a/chrome/browser/policy/configuration_policy_store_interface.h
+++ b/chrome/browser/policy/configuration_policy_store_interface.h
@@ -51,6 +51,11 @@ enum ConfigurationPolicyType {
kPolicySavingBrowserHistoryDisabled,
kPolicyDeveloperToolsDisabled,
kPolicyBlockThirdPartyCookies,
+ kPolicyDefaultCookiesSetting,
+ kPolicyDefaultImagesSetting,
+ kPolicyDefaultJavaScriptSetting,
+ kPolicyDefaultPluginsSetting,
+ kPolicyDefaultPopupsSetting,
kPolicyExtensionInstallForceList,
kPolicyChromeOsLockOnIdleSuspend,
kPolicyAuthSchemes,
diff --git a/chrome/common/policy_constants.cc b/chrome/common/policy_constants.cc
index 31b61b2..36e6874 100644
--- a/chrome/common/policy_constants.cc
+++ b/chrome/common/policy_constants.cc
@@ -57,6 +57,11 @@ const char kJavascriptEnabled[] = "JavascriptEnabled";
const char kSavingBrowserHistoryDisabled[] = "SavingBrowserHistoryDisabled";
const char kDeveloperToolsDisabled[] = "DeveloperToolsDisabled";
const char kBlockThirdPartyCookies[] = "BlockThirdPartyCookies";
+const char kDefaultCookiesSetting[] = "DefaultCookiesSetting";
+const char kDefaultImagesSetting[] = "DefaultImagesSetting";
+const char kDefaultJavaScriptSetting[] = "DefaultJavaScriptSetting";
+const char kDefaultPluginsSetting[] = "DefaultPluginsSetting";
+const char kDefaultPopupsSetting[] = "DefaultPopupsSetting";
const char kAuthSchemes[] = "AuthSchemes";
const char kDisableAuthNegotiateCnameLookup[] =
"DisableAuthNegotiateCnameLookup";
diff --git a/chrome/common/policy_constants.h b/chrome/common/policy_constants.h
index be82cbd..623cc17 100644
--- a/chrome/common/policy_constants.h
+++ b/chrome/common/policy_constants.h
@@ -54,6 +54,11 @@ extern const char kJavascriptEnabled[];
extern const char kSavingBrowserHistoryDisabled[];
extern const char kDeveloperToolsDisabled[];
extern const char kBlockThirdPartyCookies[];
+extern const char kDefaultCookiesSetting[];
+extern const char kDefaultImagesSetting[];
+extern const char kDefaultJavaScriptSetting[];
+extern const char kDefaultPluginsSetting[];
+extern const char kDefaultPopupsSetting[];
extern const char kAuthSchemes[];
extern const char kDisableAuthNegotiateCnameLookup[];
extern const char kEnableAuthNegotiatePort[];
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 93a68cc..13006f5 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -1098,4 +1098,17 @@ const char kProxyPacUrl[] = "proxy.pac_url";
// expected syntax see net::ProxyBypassRules::ParseFromString().
const char kProxyBypassList[] = "proxy.bypass_list";
+// Preferences that are exclusivly used to store managed values for default
+// content settings.
+const char kManagedDefaultCookiesSetting[] =
+ "profile.managed_default_content_settings.cookies";
+const char kManagedDefaultImagesSetting[] =
+ "profile.managed_default_content_settings.images";
+const char kManagedDefaultJavaScriptSetting[] =
+ "profile.managed_default_content_settings.javascript";
+const char kManagedDefaultPluginsSetting[] =
+ "profile.managed_default_content_settings.plugins";
+const char kManagedDefaultPopupsSetting[] =
+ "profile.managed_default_content_settings.popups";
+
} // namespace prefs
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 42232a48..c4d6af1 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -403,6 +403,12 @@ extern const char kProxyServer[];
extern const char kProxyPacUrl[];
extern const char kProxyBypassList[];
+extern const char kManagedDefaultCookiesSetting[];
+extern const char kManagedDefaultImagesSetting[];
+extern const char kManagedDefaultJavaScriptSetting[];
+extern const char kManagedDefaultPluginsSetting[];
+extern const char kManagedDefaultPopupsSetting[];
+
#if defined(OS_CHROMEOS)
extern const char kSignedSettingsTempStorage[];
#endif