Commit fef490a5 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Add policy handler for cookie controls

When third party cookies are managed by enterprise policy, the
cookie controls preference needs to be forced to be disabled.

Bug: 967668
Change-Id: I68a78d083157c63fa9cfe088b097c73f9f3f1ea2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1658156
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672050}
parent 14bbcc9d
......@@ -42,6 +42,7 @@
#include "components/browsing_data/core/pref_names.h"
#include "components/certificate_transparency/pref_names.h"
#include "components/component_updater/pref_names.h"
#include "components/content_settings/core/browser/cookie_settings_policy_handler.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/history/core/common/pref_names.h"
......@@ -1115,6 +1116,8 @@ std::unique_ptr<ConfigurationPolicyHandlerList> BuildHandlerList(
handlers->AddHandler(
std::make_unique<autofill::AutofillCreditCardPolicyHandler>());
handlers->AddHandler(std::make_unique<autofill::AutofillPolicyHandler>());
handlers->AddHandler(
std::make_unique<content_settings::CookieSettingsPolicyHandler>());
handlers->AddHandler(std::make_unique<DefaultSearchPolicyHandler>());
handlers->AddHandler(std::make_unique<ForceSafeSearchPolicyHandler>());
handlers->AddHandler(std::make_unique<ForceYouTubeSafetyModePolicyHandler>());
......
......@@ -66,6 +66,17 @@ jumbo_static_library("browser") {
deps += [ "//media" ]
}
if (!is_ios) {
sources += [
"cookie_settings_policy_handler.cc",
"cookie_settings_policy_handler.h",
]
deps += [
"//components/policy:generated",
"//components/policy/core/browser",
]
}
configs += [
"//build/config/compiler:no_size_t_to_int_warning",
"//build/config/compiler:wexit_time_destructors",
......@@ -104,4 +115,13 @@ jumbo_source_set("unit_tests") {
"//testing/gtest",
"//url",
]
if (!is_ios) {
sources += [ "cookie_settings_policy_handler_unittest.cc" ]
deps += [
"//components/policy:generated",
"//components/policy/core/browser:test_support",
]
}
}
......@@ -3,6 +3,7 @@ include_rules = [
"+components/content_settings/core/test",
"+components/keyed_service/core",
"+components/pref_registry",
"+components/policy",
"+components/sync_preferences",
"+components/url_formatter",
"+extensions/buildflags",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/content_settings/core/browser/cookie_settings_policy_handler.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h"
namespace content_settings {
CookieSettingsPolicyHandler::CookieSettingsPolicyHandler() {}
CookieSettingsPolicyHandler::~CookieSettingsPolicyHandler() {}
bool CookieSettingsPolicyHandler::CheckPolicySettings(
const policy::PolicyMap& policies,
policy::PolicyErrorMap* errors) {
return true;
}
void CookieSettingsPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& policies,
PrefValueMap* prefs) {
// When third party cookie blocking is set by policy, the cookie controls UI
// can't be enabled.
const base::Value* third_party_cookie_blocking =
policies.GetValue(policy::key::kBlockThirdPartyCookies);
if (third_party_cookie_blocking) {
prefs->SetBoolean(prefs::kCookieControlsEnabled, false);
}
}
} // namespace content_settings
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_POLICY_HANDLER_H_
#define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_POLICY_HANDLER_H_
#include "base/macros.h"
#include "components/policy/core/browser/configuration_policy_handler.h"
class PrefValueMap;
namespace content_settings {
// A ConfigurationPolicyHandler which forces kCookieControlsEnabled to false
// when BlockThirdPartyCookies is set by policy.
class CookieSettingsPolicyHandler : public policy::ConfigurationPolicyHandler {
public:
CookieSettingsPolicyHandler();
~CookieSettingsPolicyHandler() override;
// ConfigurationPolicyHandler:
bool CheckPolicySettings(const policy::PolicyMap& policies,
policy::PolicyErrorMap* errors) override;
void ApplyPolicySettings(const policy::PolicyMap& policies,
PrefValueMap* prefs) override;
private:
DISALLOW_COPY_AND_ASSIGN(CookieSettingsPolicyHandler);
};
} // namespace content_settings
#endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_COOKIE_SETTINGS_POLICY_HANDLER_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/content_settings/core/browser/cookie_settings_policy_handler.h"
#include <memory>
#include "base/values.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/policy/core/browser/configuration_policy_pref_store.h"
#include "components/policy/core/browser/configuration_policy_pref_store_test.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
namespace content_settings {
class CookieSettingsPolicyHandlerTest
: public policy::ConfigurationPolicyPrefStoreTest {
public:
void SetUp() override {
handler_list_.AddHandler(std::make_unique<CookieSettingsPolicyHandler>());
}
protected:
void SetThirdPartyCookiePolicy(bool third_party_cookie_blocking_enabled) {
policy::PolicyMap policy;
policy.Set(
policy::key::kBlockThirdPartyCookies, policy::POLICY_LEVEL_MANDATORY,
policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
std::make_unique<base::Value>(third_party_cookie_blocking_enabled),
nullptr);
UpdateProviderPolicy(policy);
}
};
TEST_F(CookieSettingsPolicyHandlerTest, ThirdPartyCookieBlockingNotSet) {
policy::PolicyMap policy;
UpdateProviderPolicy(policy);
const base::Value* value;
EXPECT_FALSE(store_->GetValue(prefs::kCookieControlsEnabled, &value));
}
TEST_F(CookieSettingsPolicyHandlerTest, ThirdPartyCookieBlockingEnabled) {
SetThirdPartyCookiePolicy(true);
const base::Value* value;
ASSERT_TRUE(store_->GetValue(prefs::kCookieControlsEnabled, &value));
EXPECT_FALSE(value->GetBool());
}
TEST_F(CookieSettingsPolicyHandlerTest, ThirdPartyCookieBlockingDisabled) {
SetThirdPartyCookiePolicy(false);
const base::Value* value;
ASSERT_TRUE(store_->GetValue(prefs::kCookieControlsEnabled, &value));
EXPECT_FALSE(value->GetBool());
}
} // namespace content_settings
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment