Commit 3ad6465f authored by Lutz Justen's avatar Lutz Justen Committed by Commit Bot

Move PolicyHandlers out of handler list factory

Moves
- ForceSafeSearchPolicyHandler
- ForceYouTubeSafetyModePolicyHandler
- BrowsingHistoryPolicyHandler
- SecureOriginPolicyHandler
out of configuration_policy_handler_list_factory.cc to the places that
use the prefs. Merely a cleanup CL - no other changes.

BUG=chromium:872717
TEST=tryjobs

Change-Id: Ic234b0aac5f869abe9dcb99908d4ffb615bc4f2c
Reviewed-on: https://chromium-review.googlesource.com/1169173
Commit-Queue: Lutz Justen <ljusten@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Reviewed-by: default avatarMustafa Emre Acer <meacer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584408}
parent 42a9534d
......@@ -1064,6 +1064,8 @@ jumbo_split_static_library("browser") {
"policy/browser_dm_token_storage_mac.mm",
"policy/browser_dm_token_storage_win.cc",
"policy/browser_dm_token_storage_win.h",
"policy/browsing_history_policy_handler.cc",
"policy/browsing_history_policy_handler.h",
"policy/chrome_browser_policy_connector.cc",
"policy/chrome_browser_policy_connector.h",
"policy/cloud/cloud_policy_invalidator.cc",
......@@ -1224,6 +1226,10 @@ jumbo_split_static_library("browser") {
"profiles/chrome_browser_main_extra_parts_profiles.h",
"profiles/chrome_version_service.cc",
"profiles/chrome_version_service.h",
"profiles/force_safe_search_policy_handler.cc",
"profiles/force_safe_search_policy_handler.h",
"profiles/force_youtube_safety_mode_policy_handler.cc",
"profiles/force_youtube_safety_mode_policy_handler.h",
"profiles/gaia_info_update_service.cc",
"profiles/gaia_info_update_service.h",
"profiles/gaia_info_update_service_factory.cc",
......@@ -1470,6 +1476,8 @@ jumbo_split_static_library("browser") {
"ssl/insecure_sensitive_input_driver_factory.h",
"ssl/mitm_software_blocking_page.cc",
"ssl/mitm_software_blocking_page.h",
"ssl/secure_origin_policy_handler.cc",
"ssl/secure_origin_policy_handler.h",
"ssl/security_state_tab_helper.cc",
"ssl/security_state_tab_helper.h",
"ssl/ssl_blocking_page.cc",
......
// Copyright 2018 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 "chrome/browser/policy/browsing_history_policy_handler.h"
#include "base/values.h"
#include "components/browsing_data/core/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 policy {
BrowsingHistoryPolicyHandler::BrowsingHistoryPolicyHandler()
: TypeCheckingPolicyHandler(key::kAllowDeletingBrowserHistory,
base::Value::Type::BOOLEAN) {}
BrowsingHistoryPolicyHandler::~BrowsingHistoryPolicyHandler() {}
void BrowsingHistoryPolicyHandler::ApplyPolicySettings(
const PolicyMap& policies,
PrefValueMap* prefs) {
const base::Value* value = policies.GetValue(policy_name());
bool deleting_history_allowed;
if (value && value->GetAsBoolean(&deleting_history_allowed) &&
!deleting_history_allowed) {
prefs->SetBoolean(browsing_data::prefs::kDeleteBrowsingHistory, false);
prefs->SetBoolean(browsing_data::prefs::kDeleteBrowsingHistoryBasic, false);
prefs->SetBoolean(browsing_data::prefs::kDeleteDownloadHistory, false);
}
}
} // namespace policy
// Copyright 2018 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 CHROME_BROWSER_POLICY_BROWSING_HISTORY_POLICY_HANDLER_H_
#define CHROME_BROWSER_POLICY_BROWSING_HISTORY_POLICY_HANDLER_H_
#include "base/macros.h"
#include "components/policy/core/browser/configuration_policy_handler.h"
class PrefValueMap;
namespace policy {
class PolicyMap;
// Handles the |kAllowDeletingBrowserHistory| policy. If set to false, sets the
// all of the 3 prefs |kDeleteBrowsingHistory|, |kDeleteBrowsingHistoryBasic|
// and |kDeleteDownloadHistory| to false.
class BrowsingHistoryPolicyHandler : public TypeCheckingPolicyHandler {
public:
BrowsingHistoryPolicyHandler();
~BrowsingHistoryPolicyHandler() override;
protected:
// ConfigurationPolicyHandler:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override;
private:
DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryPolicyHandler);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_BROWSING_HISTORY_POLICY_HANDLER_H_
......@@ -16,19 +16,22 @@
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/net/disk_cache_dir_policy_handler.h"
#include "chrome/browser/policy/browsing_history_policy_handler.h"
#include "chrome/browser/policy/developer_tools_policy_handler.h"
#include "chrome/browser/policy/file_selection_dialogs_policy_handler.h"
#include "chrome/browser/policy/javascript_policy_handler.h"
#include "chrome/browser/policy/managed_bookmarks_policy_handler.h"
#include "chrome/browser/policy/network_prediction_policy_handler.h"
#include "chrome/browser/profiles/force_safe_search_policy_handler.h"
#include "chrome/browser/profiles/force_youtube_safety_mode_policy_handler.h"
#include "chrome/browser/profiles/guest_mode_policy_handler.h"
#include "chrome/browser/profiles/incognito_mode_policy_handler.h"
#include "chrome/browser/sessions/restore_on_startup_policy_handler.h"
#include "chrome/browser/spellchecker/spellcheck_language_policy_handler.h"
#include "chrome/browser/ssl/secure_origin_policy_handler.h"
#include "chrome/browser/supervised_user/supervised_user_creation_policy_handler.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/net/safe_search_util.h"
#include "chrome/common/pref_names.h"
#include "components/autofill/core/browser/autofill_address_policy_handler.h"
#include "components/autofill/core/browser/autofill_credit_card_policy_handler.h"
......@@ -53,7 +56,6 @@
#include "components/policy/core/common/policy_pref_names.h"
#include "components/policy/core/common/schema.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/search_engines/default_search_policy_handler.h"
#include "components/signin/core/browser/signin_pref_names.h"
......@@ -846,133 +848,13 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
};
// clang-format on
class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler {
public:
ForceSafeSearchPolicyHandler()
: TypeCheckingPolicyHandler(key::kForceSafeSearch,
base::Value::Type::BOOLEAN) {}
~ForceSafeSearchPolicyHandler() override {}
// ConfigurationPolicyHandler implementation:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override {
// If either of the new ForceGoogleSafeSearch, ForceYouTubeSafetyMode or
// ForceYouTubeRestrict policies are defined, then this one should be
// ignored. crbug.com/476908, crbug.com/590478
// Note: Those policies are declared in kSimplePolicyMap above, except
// ForceYouTubeSafetyMode, which has been replaced by ForceYouTubeRestrict.
if (policies.GetValue(key::kForceGoogleSafeSearch) ||
policies.GetValue(key::kForceYouTubeSafetyMode) ||
policies.GetValue(key::kForceYouTubeRestrict)) {
return;
}
const base::Value* value = policies.GetValue(policy_name());
if (value) {
bool enabled;
prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy());
// Note that ForceYouTubeRestrict is an int policy, we cannot simply deep
// copy value, which is a boolean.
if (value->GetAsBoolean(&enabled)) {
prefs->SetValue(
prefs::kForceYouTubeRestrict,
std::make_unique<base::Value>(
enabled ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
: safe_search_util::YOUTUBE_RESTRICT_OFF));
}
}
}
private:
DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler);
};
class ForceYouTubeSafetyModePolicyHandler : public TypeCheckingPolicyHandler {
public:
ForceYouTubeSafetyModePolicyHandler()
: TypeCheckingPolicyHandler(key::kForceYouTubeSafetyMode,
base::Value::Type::BOOLEAN) {}
~ForceYouTubeSafetyModePolicyHandler() override {}
// ConfigurationPolicyHandler implementation:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override {
// If only the deprecated ForceYouTubeSafetyMode policy is set,
// but not ForceYouTubeRestrict, set ForceYouTubeRestrict to Moderate.
if (policies.GetValue(key::kForceYouTubeRestrict))
return;
const base::Value* value = policies.GetValue(policy_name());
bool enabled;
if (value && value->GetAsBoolean(&enabled)) {
prefs->SetValue(prefs::kForceYouTubeRestrict,
std::make_unique<base::Value>(
enabled ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
: safe_search_util::YOUTUBE_RESTRICT_OFF));
}
}
private:
DISALLOW_COPY_AND_ASSIGN(ForceYouTubeSafetyModePolicyHandler);
};
class BrowsingHistoryPolicyHandler : public TypeCheckingPolicyHandler {
public:
BrowsingHistoryPolicyHandler()
: TypeCheckingPolicyHandler(key::kAllowDeletingBrowserHistory,
base::Value::Type::BOOLEAN) {}
~BrowsingHistoryPolicyHandler() override {}
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override {
const base::Value* value = policies.GetValue(policy_name());
bool deleting_history_allowed;
if (value && value->GetAsBoolean(&deleting_history_allowed) &&
!deleting_history_allowed) {
prefs->SetBoolean(
browsing_data::prefs::kDeleteBrowsingHistory, false);
prefs->SetBoolean(browsing_data::prefs::kDeleteBrowsingHistoryBasic,
false);
prefs->SetBoolean(browsing_data::prefs::kDeleteDownloadHistory, false);
}
}
};
class SecureOriginPolicyHandler : public SchemaValidatingPolicyHandler {
public:
SecureOriginPolicyHandler(const char* policy_name, Schema schema)
: SchemaValidatingPolicyHandler(policy_name,
schema.GetKnownProperty(policy_name),
SCHEMA_STRICT) {
DCHECK(policy_name == key::kUnsafelyTreatInsecureOriginAsSecure ||
policy_name == key::kOverrideSecurityRestrictionsOnInsecureOrigin);
}
protected:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override {
const base::Value* value = policies.GetValue(policy_name());
if (!value)
return;
std::string pref_string;
for (const auto& list_entry : value->GetList()) {
if (!pref_string.empty())
pref_string.append(",");
pref_string.append(list_entry.GetString());
}
prefs->SetString(prefs::kUnsafelyTreatInsecureOriginAsSecure, pref_string);
}
};
#if BUILDFLAG(ENABLE_EXTENSIONS)
void GetExtensionAllowedTypesMap(
std::vector<std::unique_ptr<StringMappingListPolicyHandler::MappingEntry>>*
result) {
// Mapping from extension type names to Manifest::Type.
for (size_t index = 0;
index < extensions::schema_constants::kAllowedTypesMapSize;
++index) {
index < extensions::schema_constants::kAllowedTypesMapSize; ++index) {
const extensions::schema_constants::AllowedTypesMapEntry& entry =
extensions::schema_constants::kAllowedTypesMap[index];
result->push_back(
......
// Copyright 2018 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 "chrome/browser/profiles/force_safe_search_policy_handler.h"
#include <memory>
#include "base/values.h"
#include "chrome/common/net/safe_search_util.h"
#include "chrome/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 policy {
ForceSafeSearchPolicyHandler::ForceSafeSearchPolicyHandler()
: TypeCheckingPolicyHandler(key::kForceSafeSearch,
base::Value::Type::BOOLEAN) {}
ForceSafeSearchPolicyHandler::~ForceSafeSearchPolicyHandler() = default;
void ForceSafeSearchPolicyHandler::ApplyPolicySettings(
const PolicyMap& policies,
PrefValueMap* prefs) {
// These three policies take precedence over |kForceGoogleSafeSearch|. If any
// of them is set, their handlers will set the proper prefs.
// https://crbug.com/476908, https://crbug.com/590478.
if (policies.GetValue(key::kForceGoogleSafeSearch) ||
policies.GetValue(key::kForceYouTubeSafetyMode) ||
policies.GetValue(key::kForceYouTubeRestrict)) {
return;
}
const base::Value* value = policies.GetValue(policy_name());
if (value) {
prefs->SetValue(prefs::kForceGoogleSafeSearch, value->CreateDeepCopy());
// Note that ForceYouTubeRestrict is an int policy, we cannot simply deep
// copy value, which is a boolean.
bool enabled = false;
if (value->GetAsBoolean(&enabled)) {
prefs->SetValue(prefs::kForceYouTubeRestrict,
std::make_unique<base::Value>(
enabled ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
: safe_search_util::YOUTUBE_RESTRICT_OFF));
}
}
}
} // namespace policy
// Copyright 2018 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 CHROME_BROWSER_PROFILES_FORCE_SAFE_SEARCH_POLICY_HANDLER_H_
#define CHROME_BROWSER_PROFILES_FORCE_SAFE_SEARCH_POLICY_HANDLER_H_
#include "base/macros.h"
#include "components/policy/core/browser/configuration_policy_handler.h"
class PrefValueMap;
namespace policy {
class PolicyMap;
// Handles the deprecated |kForceSafeSearch| policy. Sets both the newer
// |kForceGoogleSafeSearch| and |kForceYouTubeRestrict| prefs, the latter to
// |YOUTUBE_RESTRICT_MODERATE| if set. Does nothing if any of the
// |kForceGoogleSafeSearch|, |kForceYouTubeSafetyMode| and
// |kForceYouTubeRestrict| policies are set because they take precedence.
class ForceSafeSearchPolicyHandler : public TypeCheckingPolicyHandler {
public:
ForceSafeSearchPolicyHandler();
~ForceSafeSearchPolicyHandler() override;
protected:
// ConfigurationPolicyHandler:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override;
private:
DISALLOW_COPY_AND_ASSIGN(ForceSafeSearchPolicyHandler);
};
} // namespace policy
#endif // CHROME_BROWSER_PROFILES_FORCE_SAFE_SEARCH_POLICY_HANDLER_H_
// Copyright 2018 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 "chrome/browser/profiles/force_youtube_safety_mode_policy_handler.h"
#include <memory>
#include "base/values.h"
#include "chrome/common/net/safe_search_util.h"
#include "chrome/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 policy {
ForceYouTubeSafetyModePolicyHandler::ForceYouTubeSafetyModePolicyHandler()
: TypeCheckingPolicyHandler(key::kForceYouTubeSafetyMode,
base::Value::Type::BOOLEAN) {}
ForceYouTubeSafetyModePolicyHandler::~ForceYouTubeSafetyModePolicyHandler() =
default;
void ForceYouTubeSafetyModePolicyHandler::ApplyPolicySettings(
const PolicyMap& policies,
PrefValueMap* prefs) {
// If only the deprecated ForceYouTubeSafetyMode policy is set,
// but not ForceYouTubeRestrict, set ForceYouTubeRestrict to Moderate.
if (policies.GetValue(key::kForceYouTubeRestrict))
return;
const base::Value* value = policies.GetValue(policy_name());
bool enabled;
if (value && value->GetAsBoolean(&enabled)) {
prefs->SetValue(prefs::kForceYouTubeRestrict,
std::make_unique<base::Value>(
enabled ? safe_search_util::YOUTUBE_RESTRICT_MODERATE
: safe_search_util::YOUTUBE_RESTRICT_OFF));
}
}
} // namespace policy
// Copyright 2018 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 CHROME_BROWSER_PROFILES_FORCE_YOUTUBE_SAFETY_MODE_POLICY_HANDLER_H_
#define CHROME_BROWSER_PROFILES_FORCE_YOUTUBE_SAFETY_MODE_POLICY_HANDLER_H_
#include "base/macros.h"
#include "components/policy/core/browser/configuration_policy_handler.h"
class PrefValueMap;
namespace policy {
class PolicyMap;
// Handles the deprecated 2-state |kForceYouTubeSafetyMode| policy. Sets the
// newer 3-state |kForceYouTubeRestrict| pref, mapping |true| to
// |YOUTUBE_RESTRICT_MODERATE| and |false| to |YOUTUBE_RESTRICT_OFF|. Does
// nothing if the |kForceYouTubeRestrict| policy is set because it take
// precedence.
class ForceYouTubeSafetyModePolicyHandler : public TypeCheckingPolicyHandler {
public:
ForceYouTubeSafetyModePolicyHandler();
~ForceYouTubeSafetyModePolicyHandler() override;
protected:
// ConfigurationPolicyHandler:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override;
private:
DISALLOW_COPY_AND_ASSIGN(ForceYouTubeSafetyModePolicyHandler);
};
} // namespace policy
#endif // CHROME_BROWSER_PROFILES_FORCE_YOUTUBE_SAFETY_MODE_POLICY_HANDLER_H_
// Copyright 2018 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 "chrome/browser/ssl/secure_origin_policy_handler.h"
#include <string>
#include "base/logging.h"
#include "base/values.h"
#include "chrome/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 policy {
SecureOriginPolicyHandler::SecureOriginPolicyHandler(const char* policy_name,
Schema schema)
: SchemaValidatingPolicyHandler(policy_name,
schema.GetKnownProperty(policy_name),
SCHEMA_STRICT) {
DCHECK(policy_name == key::kUnsafelyTreatInsecureOriginAsSecure ||
policy_name == key::kOverrideSecurityRestrictionsOnInsecureOrigin);
}
SecureOriginPolicyHandler::~SecureOriginPolicyHandler() = default;
void SecureOriginPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) {
const base::Value* value = policies.GetValue(policy_name());
if (!value)
return;
std::string pref_string;
for (const auto& list_entry : value->GetList()) {
if (!pref_string.empty())
pref_string.append(",");
pref_string.append(list_entry.GetString());
}
prefs->SetString(prefs::kUnsafelyTreatInsecureOriginAsSecure, pref_string);
}
} // namespace policy
// Copyright 2018 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 CHROME_BROWSER_SSL_SECURE_ORIGIN_POLICY_HANDLER_H_
#define CHROME_BROWSER_SSL_SECURE_ORIGIN_POLICY_HANDLER_H_
#include "base/macros.h"
#include "components/policy/core/browser/configuration_policy_handler.h"
class PrefValueMap;
namespace policy {
class PolicyMap;
class SecureOriginPolicyHandler : public SchemaValidatingPolicyHandler {
public:
SecureOriginPolicyHandler(const char* policy_name, Schema schema);
~SecureOriginPolicyHandler() override;
protected:
// ConfigurationPolicyHandler:
void ApplyPolicySettings(const PolicyMap& policies,
PrefValueMap* prefs) override;
private:
DISALLOW_COPY_AND_ASSIGN(SecureOriginPolicyHandler);
};
} // namespace policy
#endif // CHROME_BROWSER_SSL_SECURE_ORIGIN_POLICY_HANDLER_H_
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