chromium/chrome/browser/extensions/policy_handlers.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace extensions {
namespace {
// Returns true if extensions_ids contains a list of valid extension ids,
// divided by comma.
bool IsValidIdList(const std::string& extension_ids) {}

// Returns true if URL is valid and uses one of the supported schemes.
bool IsValidUpdateUrl(const std::string& update_url) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
// If Ash Chrome is no longer functioning as a browser and the extension is not
// meant to run in Ash, do not load the extension.
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)) {
      // Keep extension meant to run in Ash
      iterator++;
    } else {
      // Remove extension meant to run in Lacros
      iterator = extensions.erase(iterator);
    }
  }
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace
// ExtensionListPolicyHandler implementation -----------------------------------

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 implementation -----------------------

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  // BUILDFLAG(IS_CHROMEOS)

#if BUILDFLAG(IS_CHROMEOS)
std::optional<base::Value::Dict>
ExtensionInstallForceListPolicyHandler::GetLacrosPolicyDict(
    const policy::PolicyMap& policies) {
  // TODO(b/335121961): Currently always returns all extensions on Lacros,
  // even the ones that run in Ash. This is consistent with the pre-existing
  // behavior but it should be investigated if this is the correct behavior.
  return GetPolicyDict(policies);
}
#endif  // BUILDFLAG(IS_CHROMEOS)

std::optional<base::Value::Dict>
ExtensionInstallForceListPolicyHandler::GetPolicyDict(
    const policy::PolicyMap& policies) {}

// ExtensionInstallBlockListPolicyHandler implementation ----------------------

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 implementation -------------------------

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 implementation  ------------------------------

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) {}

}  // namespace extensions