#include "chrome/browser/extensions/api/settings_private/prefs_util.h"
#include <memory>
#include "ash/constants/ash_pref_names.h"
#include "base/feature_list.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/content_settings/generated_cookie_prefs.h"
#include "chrome/browser/content_settings/generated_notification_pref.h"
#include "chrome/browser/content_settings/generated_permission_prompting_behavior_pref.h"
#include "chrome/browser/extensions/api/settings_private/generated_prefs.h"
#include "chrome/browser/extensions/api/settings_private/generated_prefs_factory.h"
#include "chrome/browser/extensions/settings_api_helpers.h"
#include "chrome/browser/metrics/profile_pref_names.h"
#include "chrome/browser/nearby_sharing/common/nearby_share_prefs.h"
#include "chrome/browser/password_manager/generated_password_leak_detection_pref.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/generated_safe_browsing_pref.h"
#include "chrome/browser/ssl/generated_https_first_mode_pref.h"
#include "chrome/browser/ui/safety_hub/safety_hub_prefs.h"
#include "chrome/browser/ui/tabs/tab_strip_prefs.h"
#include "chrome/browser/ui/toolbar/toolbar_pref_names.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/browsing_data/core/pref_names.h"
#include "components/commerce/core/pref_names.h"
#include "components/component_updater/pref_names.h"
#include "components/compose/buildflags.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/dom_distiller/core/pref_names.h"
#include "components/drive/drive_pref_names.h"
#include "components/embedder_support/pref_names.h"
#include "components/language/core/browser/pref_names.h"
#include "components/live_caption/pref_names.h"
#include "components/media_router/common/pref_names.h"
#include "components/omnibox/browser/omnibox_prefs.h"
#include "components/optimization_guide/core/optimization_guide_prefs.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/payments/core/payment_prefs.h"
#include "components/performance_manager/public/user_tuning/prefs.h"
#include "components/permissions/pref_names.h"
#include "components/prefs/pref_service.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/saved_tab_groups/pref_names.h"
#include "components/search_engines/default_search_manager.h"
#include "components/signin/public/base/signin_pref_names.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/supervised_user/core/common/pref_names.h"
#include "components/translate/core/browser/translate_pref_names.h"
#include "components/translate/core/browser/translate_prefs.h"
#include "components/unified_consent/pref_names.h"
#include "components/url_formatter/url_fixer.h"
#include "extensions/browser/extension_pref_value_map.h"
#include "extensions/browser/extension_pref_value_map_factory.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h"
#include "extensions/common/extension.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/components/arc/arc_prefs.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/public/cpp/ambient/ambient_prefs.h"
#include "chrome/browser/ash/app_restore/full_restore_prefs.h"
#include "chrome/browser/ash/bruschetta/bruschetta_pref_names.h"
#include "chrome/browser/ash/crostini/crostini_pref_names.h"
#include "chrome/browser/ash/guest_os/guest_os_pref_names.h"
#include "chrome/browser/ash/ownership/owner_settings_service_ash.h"
#include "chrome/browser/ash/ownership/owner_settings_service_ash_factory.h"
#include "chrome/browser/ash/plugin_vm/plugin_vm_pref_names.h"
#include "chrome/browser/ash/policy/core/browser_policy_connector_ash.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/ash/settings/supervised_user_cros_settings_provider.h"
#include "chrome/browser/ash/system/timezone_util.h"
#include "chrome/browser/extensions/api/settings_private/chromeos_resolve_time_zone_by_geolocation_method_short.h"
#include "chrome/browser/extensions/api/settings_private/chromeos_resolve_time_zone_by_geolocation_on_off.h"
#include "chromeos/ash/components/settings/cros_settings.h"
#include "chromeos/ash/components/settings/cros_settings_names.h"
#include "chromeos/ash/components/tether/pref_names.h"
#include "chromeos/ash/services/assistant/public/cpp/assistant_prefs.h"
#include "chromeos/components/quick_answers/public/cpp/quick_answers_prefs.h"
#include "components/account_manager_core/pref_names.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "ui/events/ash/pref_names.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/chromeos/extensions/controlled_pref_mapping.h"
#endif
namespace {
#if BUILDFLAG(IS_CHROMEOS_ASH)
bool IsPrivilegedCrosSetting(const std::string& pref_name) {
return ash::CrosSettings::IsCrosSettings(pref_name);
}
bool IsRestrictedCrosSettingForChildUser(Profile* profile,
const std::string& pref_name) {
if (!profile->IsChild()) {
return false;
}
return ash::CrosSettings::Get()
->supervised_user_cros_settings_provider()
->HandlesSetting(pref_name);
}
const base::Value* GetRestrictedCrosSettingValueForChildUser(
Profile* profile,
const std::string& pref_name) {
DCHECK(IsRestrictedCrosSettingForChildUser(profile, pref_name));
return ash::CrosSettings::Get()
->supervised_user_cros_settings_provider()
->Get(pref_name);
}
#endif
bool IsSettingReadOnly(const std::string& pref_name) { … }
}
namespace extensions {
settings_api;
PrefsUtil::PrefsUtil(Profile* profile) : … { … }
PrefsUtil::~PrefsUtil() { … }
const PrefsUtil::TypedPrefMap& PrefsUtil::GetAllowlistedKeys() { … }
settings_api::PrefType PrefsUtil::GetAllowlistedPrefType(
const std::string& pref_name) { … }
settings_api::PrefType PrefsUtil::GetType(const std::string& name,
base::Value::Type type) { … }
std::optional<settings_api::PrefObject> PrefsUtil::GetCrosSettingsPref(
const std::string& name) { … }
std::optional<settings_api::PrefObject> PrefsUtil::GetPref(
const std::string& name) { … }
settings_private::SetPrefResult PrefsUtil::SetPref(const std::string& pref_name,
const base::Value* value) { … }
settings_private::SetPrefResult PrefsUtil::SetCrosSettingsPref(
const std::string& pref_name,
const base::Value* value) { … }
bool PrefsUtil::AppendToListCrosSetting(const std::string& pref_name,
const base::Value& value) { … }
bool PrefsUtil::RemoveFromListCrosSetting(const std::string& pref_name,
const base::Value& value) { … }
bool PrefsUtil::IsPrefTypeURL(const std::string& pref_name) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
bool PrefsUtil::IsPrefEnterpriseManaged(const std::string& pref_name) {
policy::BrowserPolicyConnectorAsh* connector =
g_browser_process->platform_part()->browser_policy_connector_ash();
if (!connector->IsDeviceEnterpriseManaged()) {
return false;
}
if (pref_name == ash::kSystemTimezone || pref_name == prefs::kUserTimezone) {
return ash::system::IsTimezonePrefsManaged(pref_name);
}
return IsPrivilegedCrosSetting(pref_name);
}
bool PrefsUtil::IsPrefOwnerControlled(const std::string& pref_name) {
if (pref_name == ash::kSystemTimezone) {
return false;
}
if (IsPrivilegedCrosSetting(pref_name)) {
if (!ash::ProfileHelper::IsOwnerProfile(profile_)) {
return true;
}
}
return false;
}
bool PrefsUtil::IsPrefPrimaryUserControlled(const std::string& pref_name) {
if (pref_name == prefs::kUserTimezone || pref_name == ash::kSystemTimezone) {
user_manager::UserManager* user_manager = user_manager::UserManager::Get();
const user_manager::User* user =
ash::ProfileHelper::Get()->GetUserByProfile(profile_);
if (user && user->GetAccountId() !=
user_manager->GetPrimaryUser()->GetAccountId()) {
return true;
}
}
return false;
}
bool PrefsUtil::IsHotwordDisabledForChildUser(const std::string& pref_name) {
const std::string& hotwordEnabledPref =
ash::assistant::prefs::kAssistantHotwordEnabled;
if (!profile_->IsChild() || pref_name != hotwordEnabledPref) {
return false;
}
PrefService* pref_service = FindServiceForPref(hotwordEnabledPref);
const PrefService::Preference* pref =
pref_service->FindPreference(hotwordEnabledPref);
DCHECK(pref);
const bool isHotwordEnabled = pref->GetValue()->GetIfBool().value_or(false);
return !isHotwordEnabled;
}
#endif
bool PrefsUtil::IsPrefSupervisorControlled(const std::string& pref_name) { … }
bool PrefsUtil::IsPrefUserModifiable(const std::string& pref_name) { … }
PrefService* PrefsUtil::FindServiceForPref(const std::string& pref_name) { … }
bool PrefsUtil::IsCrosSetting(const std::string& pref_name) { … }
const Extension* PrefsUtil::GetExtensionControllingPref(
const settings_api::PrefObject& pref_object) { … }
}