#include "chrome/browser/extensions/policy_handlers.h"
#include <stddef.h>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/check.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/extension_management_constants.h"
#include "chrome/browser/extensions/external_policy_loader.h"
#include "components/crx_file/id_util.h"
#include "components/policy/core/browser/configuration_policy_handler.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/schema.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h"
#include "components/strings/grit/components_strings.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/url_pattern.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_WIN)
#include "base/enterprise_util.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/crosapi/browser_util.h"
#include "chrome/browser/extensions/extension_keeplist_chromeos.h"
#endif
namespace extensions {
namespace {
bool IsValidIdList(const std::string& extension_ids) { … }
bool IsValidUpdateUrl(const std::string& update_url) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void FilterOutExtensionsMeantToRunInLacros(base::Value::Dict& extensions) {
auto iterator = extensions.begin();
while (iterator != extensions.end()) {
const std::string& extension_id = iterator->first;
if (ExtensionRunsInOS(extension_id) || ExtensionAppRunsInOS(extension_id)) {
iterator++;
} else {
iterator = extensions.erase(iterator);
}
}
}
#endif
}
ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name,
const char* pref_path,
bool allow_wildcards)
: … { … }
ExtensionListPolicyHandler::~ExtensionListPolicyHandler() = default;
bool ExtensionListPolicyHandler::CheckListEntry(const base::Value& value) { … }
void ExtensionListPolicyHandler::ApplyList(base::Value::List filtered_list,
PrefValueMap* prefs) { … }
ExtensionInstallForceListPolicyHandler::ExtensionInstallForceListPolicyHandler()
: … { … }
bool ExtensionInstallForceListPolicyHandler::CheckPolicySettings(
const policy::PolicyMap& policies,
policy::PolicyErrorMap* errors) { … }
void ExtensionInstallForceListPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& policies,
PrefValueMap* prefs) { … }
bool ExtensionInstallForceListPolicyHandler::ParseList(
const base::Value* policy_value,
base::Value::Dict* extension_dict,
policy::PolicyErrorMap* errors) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::optional<base::Value::Dict>
ExtensionInstallForceListPolicyHandler::GetAshPolicyDict(
const policy::PolicyMap& policies) {
std::optional<base::Value::Dict> dict = GetPolicyDict(policies);
if (dict.has_value() && crosapi::browser_util::IsLacrosEnabled()) {
FilterOutExtensionsMeantToRunInLacros(dict.value());
}
return dict;
}
#endif
#if BUILDFLAG(IS_CHROMEOS)
std::optional<base::Value::Dict>
ExtensionInstallForceListPolicyHandler::GetLacrosPolicyDict(
const policy::PolicyMap& policies) {
return GetPolicyDict(policies);
}
#endif
std::optional<base::Value::Dict>
ExtensionInstallForceListPolicyHandler::GetPolicyDict(
const policy::PolicyMap& policies) { … }
ExtensionInstallBlockListPolicyHandler::ExtensionInstallBlockListPolicyHandler()
: … { … }
ExtensionInstallBlockListPolicyHandler::
~ExtensionInstallBlockListPolicyHandler() = default;
bool ExtensionInstallBlockListPolicyHandler::CheckPolicySettings(
const policy::PolicyMap& policies,
policy::PolicyErrorMap* errors) { … }
void ExtensionInstallBlockListPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& policies,
PrefValueMap* prefs) { … }
ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler(
const char* policy_name,
const char* pref_path)
: … { … }
ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() =
default;
bool ExtensionURLPatternListPolicyHandler::CheckPolicySettings(
const policy::PolicyMap& policies,
policy::PolicyErrorMap* errors) { … }
void ExtensionURLPatternListPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& policies,
PrefValueMap* prefs) { … }
ExtensionSettingsPolicyHandler::ExtensionSettingsPolicyHandler(
const policy::Schema& chrome_schema)
: … { … }
ExtensionSettingsPolicyHandler::~ExtensionSettingsPolicyHandler() = default;
void ExtensionSettingsPolicyHandler::SanitizePolicySettings(
base::Value* policy_value,
policy::PolicyErrorMap* errors) { … }
bool ExtensionSettingsPolicyHandler::CheckPolicySettings(
const policy::PolicyMap& policies,
policy::PolicyErrorMap* errors) { … }
void ExtensionSettingsPolicyHandler::ApplyPolicySettings(
const policy::PolicyMap& policies,
PrefValueMap* prefs) { … }
}