chromium/chrome/browser/extensions/pref_mapping.cc

// Copyright 2022 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/pref_mapping.h"

#include <optional>
#include <span>  // std::size.
#include <string_view>

#include "base/containers/contains.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/extensions/pref_transformer_interface.h"
#include "chrome/browser/prefetch/pref_names.h"
#include "chrome/browser/preloading/preloading_prefs.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/embedder_support/pref_names.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/privacy_sandbox/tracking_protection_prefs.h"
#include "components/proxy_config/proxy_config_pref_names.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/translate/core/browser/translate_pref_names.h"

#if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/browser/chromeos/extensions/controlled_pref_mapping.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "base/containers/fixed_flat_map.h"
#endif

APIPermissionID;

namespace extensions {

namespace {

constexpr char kOnPrefChangeFormat[] =;

const PrefMappingEntry kMappings[] =;

class IdentityPrefTransformer : public PrefTransformerInterface {};

}  // namespace

// static
PrefMapping* PrefMapping::GetInstance() {}

// static
base::span<const PrefMappingEntry> PrefMapping::GetMappings() {}

bool PrefMapping::FindBrowserPrefForExtensionPref(
    const std::string& extension_pref,
    std::string* browser_pref,
    APIPermissionID* read_permission,
    APIPermissionID* write_permission) const {}

bool PrefMapping::FindEventForBrowserPref(const std::string& browser_pref,
                                          std::string* event_name,
                                          APIPermissionID* permission) const {}

PrefTransformerInterface* PrefMapping::FindTransformerForBrowserPref(
    const std::string& browser_pref) const {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Given a pref name for an extension-controlled pref where the underlying
// pref is controlled by ash, returns the PrefPath used by the crosapi to set
// the pref in ash, or nullptr if no pref exists.
crosapi::mojom::PrefPath PrefMapping::GetPrefPathForPrefName(
    const std::string& pref_name) const {
  static constexpr auto name_to_extension_prefpath = base::MakeFixedFlatMap<
      std::string_view, crosapi::mojom::PrefPath>(
      {{chromeos::prefs::kDockedMagnifierEnabled,
        crosapi::mojom::PrefPath::kDockedMagnifierEnabled},
       {chromeos::prefs::kAccessibilityAutoclickEnabled,
        crosapi::mojom::PrefPath::kAccessibilityAutoclickEnabled},
       {chromeos::prefs::kAccessibilityCaretHighlightEnabled,
        crosapi::mojom::PrefPath::kAccessibilityCaretHighlightEnabled},
       {chromeos::prefs::kAccessibilityCursorColorEnabled,
        crosapi::mojom::PrefPath::kAccessibilityCursorColorEnabled},
       {chromeos::prefs::kAccessibilityCursorHighlightEnabled,
        crosapi::mojom::PrefPath::kAccessibilityCursorHighlightEnabled},
       {chromeos::prefs::kAccessibilityDictationEnabled,
        crosapi::mojom::PrefPath::kAccessibilityDictationEnabled},
       {chromeos::prefs::kAccessibilityFocusHighlightEnabled,
        crosapi::mojom::PrefPath::kAccessibilityFocusHighlightEnabled},
       {chromeos::prefs::kAccessibilityHighContrastEnabled,
        crosapi::mojom::PrefPath::kAccessibilityHighContrastEnabled},
       {chromeos::prefs::kAccessibilityLargeCursorEnabled,
        crosapi::mojom::PrefPath::kAccessibilityLargeCursorEnabled},
       {chromeos::prefs::kAccessibilityScreenMagnifierEnabled,
        crosapi::mojom::PrefPath::kAccessibilityScreenMagnifierEnabled},
       {chromeos::prefs::kAccessibilitySelectToSpeakEnabled,
        crosapi::mojom::PrefPath::kAccessibilitySelectToSpeakEnabled},
       {chromeos::prefs::kAccessibilitySpokenFeedbackEnabled,
        crosapi::mojom::PrefPath::kExtensionAccessibilitySpokenFeedbackEnabled},
       {chromeos::prefs::kAccessibilityStickyKeysEnabled,
        crosapi::mojom::PrefPath::kAccessibilityStickyKeysEnabled},
       {chromeos::prefs::kAccessibilitySwitchAccessEnabled,
        crosapi::mojom::PrefPath::kAccessibilitySwitchAccessEnabled},
       {chromeos::prefs::kAccessibilityVirtualKeyboardEnabled,
        crosapi::mojom::PrefPath::kAccessibilityVirtualKeyboardEnabled},
       {proxy_config::prefs::kProxy, crosapi::mojom::PrefPath::kProxy}});
  auto pref_iter = name_to_extension_prefpath.find(pref_name);
  return pref_iter == name_to_extension_prefpath.end()
             ? crosapi::mojom::PrefPath::kUnknown
             : pref_iter->second;
}
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

PrefMapping::PrefMapping() {}

PrefMapping::~PrefMapping() = default;

void PrefMapping::RegisterPrefTransformer(
    const std::string& browser_pref,
    std::unique_ptr<PrefTransformerInterface> transformer) {}

}  // namespace extensions