summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/policy/policy_templates.json20
-rw-r--r--chrome/browser/policy/configuration_policy_handler.cc66
-rw-r--r--chrome/browser/policy/configuration_policy_handler.h26
-rw-r--r--chrome/browser/policy/configuration_policy_handler_list.cc4
-rw-r--r--chrome/browser/policy/configuration_policy_handler_unittest.cc64
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store_unittest.cc2
6 files changed, 167 insertions, 15 deletions
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json
index 3594914..6347fe4 100644
--- a/chrome/app/policy/policy_templates.json
+++ b/chrome/app/policy/policy_templates.json
@@ -743,19 +743,18 @@
'dynamic_refresh': True,
'can_be_recommended': True,
},
+ 'deprecated': True,
'example_value': True,
'id': 65,
- 'caption': '''Clear site data on browser shutdown''',
- 'desc': '''This policy is an override for the "Clear cookies and other site data when I close my browser" content settings option.
-
- When set to enabled <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> will delete all locally stored data from the browser when it is shut down.
+ 'caption': '''Clear site data on browser shutdown (deprecated)''',
+ 'desc': '''This policy is an override for the "Clear cookies and other site data when I close my browser" content settings option that <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> supported prior to version 21.
- If set to disabled site data will not be cleared on exit.
+ This policy exists only for backward-compatibility and will go away in the future. The recommended way to clear site data on exit on version 21 and later is to configure the DefaultCookiesSetting policy to session-only.
- If this policy is left not set <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> will use the default which is to preserve site data on shut down and the user will be able to change this.
+ If this policy is enabled it will be translated to the appropriate policy setting for the DefaultCookiesSetting policy, setting it to session-only if the DefaultCookiesSetting policy is not configured or set to Allow.
- If the "RestoreOnStartup" policy is set to restore URLs from previous sessions this policy will not clear cookies or other data relevant to restoring the previous browsing session completely.''',
- 'label': '''Clear site data on browser shutdown''',
+ If this policy is disabled or left unconfigured the policy for storing site data is determined by the DefaultCookiesSetting policy.''',
+ 'label': '''Clear site data on browser shutdown (deprecated)''',
},
{
'name': 'Proxy',
@@ -1388,6 +1387,11 @@
'value': 2,
'caption': '''Do not allow any site to set local data'''
},
+ {
+ 'name': 'SessionOnly',
+ 'value': 4,
+ 'caption': '''Keep cookies for the duration of the session.'''
+ },
],
'supported_on': ['chrome.*:10-', 'chrome_os:0.11-'],
'features': {'dynamic_refresh': True},
diff --git a/chrome/browser/policy/configuration_policy_handler.cc b/chrome/browser/policy/configuration_policy_handler.cc
index 06ab093..4892d2f 100644
--- a/chrome/browser/policy/configuration_policy_handler.cc
+++ b/chrome/browser/policy/configuration_policy_handler.cc
@@ -25,7 +25,6 @@
#include "chrome/browser/search_engines/search_terms_data.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/content_settings.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_service.h"
@@ -1096,6 +1095,71 @@ void JavascriptPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
}
}
+// ClearSiteDataOnExitPolicyHandler implementation -----------------------------
+
+ClearSiteDataOnExitPolicyHandler::ClearSiteDataOnExitPolicyHandler()
+ : TypeCheckingPolicyHandler(key::kClearSiteDataOnExit,
+ Value::TYPE_BOOLEAN) {
+}
+
+ClearSiteDataOnExitPolicyHandler::~ClearSiteDataOnExitPolicyHandler() {
+}
+
+bool ClearSiteDataOnExitPolicyHandler::CheckPolicySettings(
+ const PolicyMap& policies,
+ PolicyErrorMap* errors) {
+ ContentSetting content_setting = CONTENT_SETTING_DEFAULT;
+ if (ClearSiteDataEnabled(policies) &&
+ GetContentSetting(policies, &content_setting) &&
+ content_setting == CONTENT_SETTING_ALLOW) {
+ errors->AddError(key::kDefaultCookiesSetting,
+ IDS_POLICY_OVERRIDDEN,
+ policy_name());
+ }
+
+ return TypeCheckingPolicyHandler::CheckPolicySettings(policies, errors);
+}
+
+void ClearSiteDataOnExitPolicyHandler::ApplyPolicySettings(
+ const PolicyMap& policies,
+ PrefValueMap* prefs) {
+ if (ClearSiteDataEnabled(policies)) {
+ ContentSetting content_setting = CONTENT_SETTING_DEFAULT;
+ if (!GetContentSetting(policies, &content_setting) ||
+ content_setting == CONTENT_SETTING_ALLOW) {
+ prefs->SetValue(
+ prefs::kManagedDefaultCookiesSetting,
+ Value::CreateIntegerValue(CONTENT_SETTING_SESSION_ONLY));
+ }
+ }
+}
+
+bool ClearSiteDataOnExitPolicyHandler::ClearSiteDataEnabled(
+ const PolicyMap& policies) {
+ const base::Value* value = NULL;
+ PolicyErrorMap errors;
+ bool clear_site_data = false;
+
+ return (CheckAndGetValue(policies, &errors, &value) &&
+ value &&
+ value->GetAsBoolean(&clear_site_data) &&
+ clear_site_data);
+}
+
+// static
+bool ClearSiteDataOnExitPolicyHandler::GetContentSetting(
+ const PolicyMap& policies,
+ ContentSetting* content_setting) {
+ const base::Value* value = policies.GetValue(key::kDefaultCookiesSetting);
+ int setting = CONTENT_SETTING_DEFAULT;
+ if (value && value->GetAsInteger(&setting)) {
+ *content_setting = static_cast<ContentSetting>(setting);
+ return true;
+ }
+
+ return false;
+}
+
// RestoreOnStartupPolicyHandler implementation --------------------------------
RestoreOnStartupPolicyHandler::RestoreOnStartupPolicyHandler()
diff --git a/chrome/browser/policy/configuration_policy_handler.h b/chrome/browser/policy/configuration_policy_handler.h
index 6b75800..73913d7 100644
--- a/chrome/browser/policy/configuration_policy_handler.h
+++ b/chrome/browser/policy/configuration_policy_handler.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/values.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
+#include "chrome/common/content_settings.h"
class PrefValueMap;
@@ -355,6 +356,31 @@ class JavascriptPolicyHandler : public ConfigurationPolicyHandler {
DISALLOW_COPY_AND_ASSIGN(JavascriptPolicyHandler);
};
+// Handles the (deprecated) ClearSiteDataOnExit policy.
+// TODO(mnissler): Remove the policy eventually (http://crbug.com/133291).
+class ClearSiteDataOnExitPolicyHandler : public TypeCheckingPolicyHandler {
+ public:
+ ClearSiteDataOnExitPolicyHandler();
+ virtual ~ClearSiteDataOnExitPolicyHandler();
+
+ // ConfigurationPolicyHandler methods:
+ virtual bool CheckPolicySettings(const PolicyMap& policies,
+ PolicyErrorMap* errors) OVERRIDE;
+ virtual void ApplyPolicySettings(const PolicyMap& policies,
+ PrefValueMap* prefs) OVERRIDE;
+
+ private:
+ // Checks whether the clear site data policy is enabled in |policies|.
+ bool ClearSiteDataEnabled(const PolicyMap& policies);
+
+ // Checks |policies| for the cookies setting and returns it in
+ // |content_setting|. Returns true if the setting is found, false if not.
+ static bool GetContentSetting(const PolicyMap& policies,
+ ContentSetting* content_setting);
+
+ DISALLOW_COPY_AND_ASSIGN(ClearSiteDataOnExitPolicyHandler);
+};
+
// Handles RestoreOnStartup policy.
class RestoreOnStartupPolicyHandler : public TypeCheckingPolicyHandler {
public:
diff --git a/chrome/browser/policy/configuration_policy_handler_list.cc b/chrome/browser/policy/configuration_policy_handler_list.cc
index 23e19cc..304dc07 100644
--- a/chrome/browser/policy/configuration_policy_handler_list.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list.cc
@@ -96,9 +96,6 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
{ key::kSavingBrowserHistoryDisabled,
prefs::kSavingBrowserHistoryDisabled,
Value::TYPE_BOOLEAN },
- { key::kClearSiteDataOnExit,
- prefs::kClearSiteDataOnExit,
- Value::TYPE_BOOLEAN },
{ key::kDeveloperToolsDisabled,
prefs::kDevToolsDisabled,
Value::TYPE_BOOLEAN },
@@ -319,6 +316,7 @@ ConfigurationPolicyHandlerList::ConfigurationPolicyHandlerList() {
}
handlers_.push_back(new AutofillPolicyHandler());
+ handlers_.push_back(new ClearSiteDataOnExitPolicyHandler());
handlers_.push_back(new DefaultSearchPolicyHandler());
handlers_.push_back(new DiskCacheDirPolicyHandler());
handlers_.push_back(new FileSelectionDialogsHandler());
diff --git a/chrome/browser/policy/configuration_policy_handler_unittest.cc b/chrome/browser/policy/configuration_policy_handler_unittest.cc
index baba2ba..cf0c9fe 100644
--- a/chrome/browser/policy/configuration_policy_handler_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_handler_unittest.cc
@@ -22,24 +22,28 @@ TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) {
policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_TRUE(errors.empty());
list.Append(Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop"));
policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_TRUE(errors.empty());
list.Append(Value::CreateStringValue("*"));
policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_TRUE(errors.empty());
list.Append(Value::CreateStringValue("invalid"));
policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_FALSE(errors.empty());
EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallBlacklist).empty());
@@ -72,24 +76,28 @@ TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) {
policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_TRUE(errors.empty());
list.Append(Value::CreateStringValue("http://*.google.com/*"));
policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_TRUE(errors.empty());
list.Append(Value::CreateStringValue("<all_urls>"));
policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_TRUE(errors.empty());
list.Append(Value::CreateStringValue("invalid"));
policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_FALSE(errors.empty());
EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallSources).empty());
@@ -99,6 +107,7 @@ TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) {
list.Append(Value::CreateStringValue("*"));
policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
+ errors.Clear();
EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
EXPECT_FALSE(errors.empty());
EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallSources).empty());
@@ -117,8 +126,61 @@ TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) {
policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, list.DeepCopy());
handler.ApplyPolicySettings(policy_map, &prefs);
- EXPECT_TRUE(prefs.GetValue(prefs::kExtensionAllowedInstallSites, &value));
+ ASSERT_TRUE(prefs.GetValue(prefs::kExtensionAllowedInstallSites, &value));
EXPECT_TRUE(base::Value::Equals(&list, value));
}
+TEST(ClearSiteDataOnExitPolicyHandlerTest, CheckPolicySettings) {
+ ClearSiteDataOnExitPolicyHandler handler;
+ PolicyMap policy_map;
+ PolicyErrorMap errors;
+
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_TRUE(errors.empty());
+
+ policy_map.Set(key::kClearSiteDataOnExit, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true));
+ errors.Clear();
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_TRUE(errors.empty());
+
+ policy_map.Set(key::kDefaultCookiesSetting, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
+ errors.Clear();
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_FALSE(errors.empty());
+ EXPECT_FALSE(errors.GetErrors(key::kDefaultCookiesSetting).empty());
+}
+
+TEST(ClearSiteDataOnExitPolicyHandlerTest, ApplyPolicySettings) {
+ ClearSiteDataOnExitPolicyHandler handler;
+ PolicyMap policy_map;
+ PrefValueMap prefs;
+ const base::Value* val = NULL;
+
+ handler.ApplyPolicySettings(policy_map, &prefs);
+ EXPECT_FALSE(prefs.GetValue(prefs::kManagedDefaultCookiesSetting, &val));
+
+ policy_map.Set(key::kClearSiteDataOnExit, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true));
+ prefs.Clear();
+ handler.ApplyPolicySettings(policy_map, &prefs);
+ ASSERT_TRUE(prefs.GetValue(prefs::kManagedDefaultCookiesSetting, &val));
+ EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_SESSION_ONLY).Equals(val));
+
+ policy_map.Set(key::kDefaultCookiesSetting, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
+ prefs.Clear();
+ handler.ApplyPolicySettings(policy_map, &prefs);
+ ASSERT_TRUE(prefs.GetValue(prefs::kManagedDefaultCookiesSetting, &val));
+ EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_SESSION_ONLY).Equals(val));
+
+ policy_map.Clear();
+ prefs.Clear();
+ handler.ApplyPolicySettings(policy_map, &prefs);
+ EXPECT_FALSE(prefs.GetValue(prefs::kManagedDefaultCookiesSetting, &val));
+}
+
} // namespace policy
diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
index 35d057e..d3ffb8f 100644
--- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
@@ -240,8 +240,6 @@ INSTANTIATE_TEST_CASE_P(
prefs::kInstantEnabled),
PolicyAndPref(key::kDisablePluginFinder,
prefs::kDisablePluginFinder),
- PolicyAndPref(key::kClearSiteDataOnExit,
- prefs::kClearSiteDataOnExit),
PolicyAndPref(key::kDefaultBrowserSettingEnabled,
prefs::kDefaultBrowserSettingEnabled),
PolicyAndPref(key::kDisable3DAPIs,