1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/enterprise/content/copy_prevention_settings_policy_handler.h"
#include "components/enterprise/content/pref_names.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h"
#include "components/prefs/pref_value_map.h"
#include "components/strings/grit/components_strings.h"
namespace {
const int kMinDataSizeDefault = 100;
}
CopyPreventionSettingsPolicyHandler::CopyPreventionSettingsPolicyHandler(
const char* policy_name,
const char* pref_path,
policy::Schema schema)
: SchemaValidatingPolicyHandler(
policy_name,
schema.GetKnownProperty(policy_name),
policy::SchemaOnErrorStrategy::SCHEMA_ALLOW_UNKNOWN),
pref_path_(pref_path) {}
CopyPreventionSettingsPolicyHandler::~CopyPreventionSettingsPolicyHandler() =
default;
// ConfigurationPolicyHandler:
bool CopyPreventionSettingsPolicyHandler::CheckPolicySettings(
const policy::PolicyMap& policies,
policy::PolicyErrorMap* errors) {
if (!policies.IsPolicySet(policy_name()))
return true;
if (!SchemaValidatingPolicyHandler::CheckPolicySettings(policies, errors))
return false;
const policy::PolicyMap::Entry* policy = policies.Get(policy_name());
if (policy->source != policy::POLICY_SOURCE_CLOUD &&
policy->source != policy::POLICY_SOURCE_CLOUD_FROM_ASH) {
errors->AddError(policy_name(), IDS_POLICY_CLOUD_SOURCE_ONLY_ERROR);
return false;
}
const base::Value::Dict& dict =
policies.GetValue(policy_name(), base::Value::Type::DICT)->GetDict();
const base::Value::List* enable = dict.FindList(
enterprise::content::kCopyPreventionSettingsEnableFieldName);
const base::Value::List* disable = dict.FindList(
enterprise::content::kCopyPreventionSettingsDisableFieldName);
if (!enable || !disable) {
errors->AddError(policy_name(),
IDS_ENTERPRISE_COPY_PREVENTION_MISSING_LIST_ERROR);
return false;
}
for (auto& pattern : *disable) {
if (pattern.GetString() == "*") {
errors->AddError(
policy_name(),
IDS_ENTERPRISE_COPY_PREVENTION_DISABLE_CONTAINS_WILDCARD_ERROR);
return false;
}
}
return true;
}
void CopyPreventionSettingsPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& policies,
PrefValueMap* prefs) {
const base::Value* value =
policies.GetValue(policy_name(), base::Value::Type::DICT);
if (!value)
return;
base::Value processed_value = value->Clone();
// The min data size field is optional. Default to 100 bytes if it's not
// present.
std::optional<int> min_data_size = value->GetDict().FindInt(
enterprise::content::kCopyPreventionSettingsMinDataSizeFieldName);
if (!min_data_size) {
processed_value.GetDict().Set(
enterprise::content::kCopyPreventionSettingsMinDataSizeFieldName,
kMinDataSizeDefault);
}
prefs->SetValue(pref_path_, std::move(processed_value));
}
|