Delete Alloy bootstrap (fixes #3685)

This commit is contained in:
Marshall Greenblatt
2024-06-25 20:12:37 -04:00
parent b95b3e6fd5
commit a461a89728
282 changed files with 360 additions and 22399 deletions

View File

@@ -12,77 +12,6 @@
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool.h"
#include "base/values.h"
#include "cef/libcef/browser/media_capture_devices_dispatcher.h"
#include "cef/libcef/browser/prefs/pref_store.h"
#include "cef/libcef/browser/prefs/renderer_prefs.h"
#include "cef/libcef/common/cef_switches.h"
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/media/router/discovery/access_code/access_code_cast_feature.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/media/webrtc/permission_bubble_media_access_handler.h"
#include "chrome/browser/net/profile_network_context_service.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/permissions/quiet_notification_permission_ui_state.h"
#include "chrome/browser/prefs/chrome_command_line_pref_store.h"
#include "chrome/browser/preloading/preloading_prefs.h"
#include "chrome/browser/printing/print_preview_sticky_settings.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/ssl/ssl_config_service_manager.h"
#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/browser_view_prefs.h"
#include "chrome/browser/ui/webui/accessibility/accessibility_ui.h"
#include "chrome/browser/ui/webui/print_preview/policy_settings.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/locale_settings.h"
#include "components/certificate_transparency/pref_names.h"
#include "components/component_updater/component_updater_service.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/domain_reliability/domain_reliability_prefs.h"
#include "components/flags_ui/pref_service_flags_storage.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/language/core/browser/language_prefs.h"
#include "components/media_device_salt/media_device_id_salt.h"
#include "components/permissions/permission_actions_history.h"
#include "components/permissions/permission_hats_trigger_helper.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_filter.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#include "components/proxy_config/proxy_config_dictionary.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_search_api/safe_search_util.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/supervised_user/core/browser/supervised_user_pref_store.h"
#include "components/supervised_user/core/browser/supervised_user_settings_service.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_preferences/pref_service_syncable_factory.h"
#include "components/unified_consent/unified_consent_service.h"
#include "components/update_client/update_client.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/buildflags/buildflags.h"
#include "net/http/http_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_switches.h"
#if BUILDFLAG(IS_WIN)
#include "components/os_crypt/sync/os_crypt.h"
#endif
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace browser_prefs {
namespace {
@@ -111,11 +40,6 @@ std::string GetAcceptLanguageListSetting(Profile* profile) {
return std::string();
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
constexpr char kUserPrefsFileName[] = "UserPrefs.json";
constexpr char kLocalPrefsFileName[] = "LocalPrefs.json";
#endif
} // namespace
void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
@@ -127,242 +51,14 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry);
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
const base::FilePath& cache_path,
bool persist_user_preferences) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
// Use of PrefServiceSyncable is required by Chrome code such as
// HostContentSettingsMapFactory that calls PrefServiceSyncableFromProfile.
sync_preferences::PrefServiceSyncableFactory factory;
// Used to store command-line preferences, most of which will be evaluated in
// the CommandLinePrefStore constructor. Preferences set in this manner cannot
// be overridden by the user.
scoped_refptr<ChromeCommandLinePrefStore> command_line_pref_store(
new ChromeCommandLinePrefStore(command_line));
renderer_prefs::SetCommandLinePrefDefaults(command_line_pref_store.get());
factory.set_command_line_prefs(command_line_pref_store);
// True if preferences will be stored on disk.
const bool store_on_disk = !cache_path.empty() && persist_user_preferences;
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner;
if (store_on_disk) {
// Get sequenced task runner for making sure that file operations are
// executed in expected order (what was previously assured by the FILE
// thread).
sequenced_task_runner = base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
}
// Used to store user preferences.
scoped_refptr<PersistentPrefStore> user_pref_store;
if (store_on_disk) {
const base::FilePath& pref_path = cache_path.AppendASCII(
profile ? kUserPrefsFileName : kLocalPrefsFileName);
scoped_refptr<JsonPrefStore> json_pref_store = new JsonPrefStore(
pref_path, std::unique_ptr<PrefFilter>(), sequenced_task_runner);
factory.set_user_prefs(json_pref_store.get());
} else {
scoped_refptr<CefPrefStore> cef_pref_store = new CefPrefStore();
cef_pref_store->SetInitializationCompleted();
factory.set_user_prefs(cef_pref_store.get());
}
if (profile) {
// Used to store supervised user preferences.
auto* supervised_user_settings =
SupervisedUserSettingsServiceFactory::GetForKey(
profile->GetProfileKey());
if (store_on_disk) {
supervised_user_settings->Init(cache_path, sequenced_task_runner.get(),
true);
} else {
scoped_refptr<CefPrefStore> cef_pref_store = new CefPrefStore();
cef_pref_store->SetInitializationCompleted();
supervised_user_settings->Init(cef_pref_store);
}
scoped_refptr<PrefStore> supervised_user_prefs =
base::MakeRefCounted<SupervisedUserPrefStore>(supervised_user_settings);
DCHECK(supervised_user_prefs->IsInitializationComplete());
factory.set_supervised_user_prefs(supervised_user_prefs);
}
// Registry that will be populated with all known preferences. Preferences
// are registered with default values that may be changed via a *PrefStore.
scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
new user_prefs::PrefRegistrySyncable());
// Some preferences are specific to CEF and others are defined in Chromium.
// The preferred approach for registering preferences defined in Chromium is
// as follows:
//
// 1. If a non-static RegisterProfilePrefs() method exists in a *Factory
// class then add a *Factory::GetInstance() call in
// EnsureBrowserContextKeyedServiceFactoriesBuilt().
// 2. If a static RegisterPrefs() method exists then call that method in the
// "Default preferences" section below.
// 3. If the default values are not appropriate but the set of registered
// preferences is otherwise fine then change the defaults by calling
// SetDefaultPrefValue after calling the existing registration method.
// 4. If the original registration method contains many unused preferences or
// otherwise inappropiate logic (e.g. calls to objects that CEF doesn't
// use) then register the preferences directly instead of calling the
// existing registration method.
// Default preferences.
CefMediaCaptureDevicesDispatcher::RegisterPrefs(registry.get());
certificate_transparency::prefs::RegisterPrefs(registry.get());
flags_ui::PrefServiceFlagsStorage::RegisterPrefs(registry.get());
media_router::RegisterLocalStatePrefs(registry.get());
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
ProfileNetworkContextService::RegisterLocalStatePrefs(registry.get());
SSLConfigServiceManager::RegisterPrefs(registry.get());
update_client::RegisterPrefs(registry.get());
if (!profile) {
component_updater::RegisterComponentUpdateServicePrefs(registry.get());
domain_reliability::RegisterPrefs(registry.get());
SystemNetworkContextManager::RegisterPrefs(registry.get());
#if BUILDFLAG(IS_WIN)
OSCrypt::RegisterLocalPrefs(registry.get());
#endif
}
// Browser process preferences.
// Based on chrome/browser/browser_process_impl.cc RegisterPrefs.
registry->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false);
// Browser UI preferences.
// Based on chrome/browser/ui/browser_ui_prefs.cc RegisterBrowserPrefs.
registry->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true);
// Based on chrome/browser/ui/browser_ui_prefs.cc RegisterBrowserUserPrefs.
registry->RegisterBooleanPref(prefs::kPrintPreviewUseSystemDefaultPrinter,
false);
// Profile preferences.
// Based on chrome/browser/profiles/profiles_state.cc RegisterPrefs.
registry->RegisterStringPref(prefs::kProfileLastUsed, std::string());
if (profile) {
// Call RegisterProfilePrefs() for all services listed by
// EnsureBrowserContextKeyedServiceFactoriesBuilt().
BrowserContextDependencyManager::GetInstance()
->RegisterProfilePrefsForServices(registry.get());
// Default profile preferences.
AccessibilityUIMessageHandler::RegisterProfilePrefs(registry.get());
content_settings::CookieSettings::RegisterProfilePrefs(registry.get());
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
HostContentSettingsMap::RegisterProfilePrefs(registry.get());
language::LanguagePrefs::RegisterProfilePrefs(registry.get());
media_router::RegisterAccessCodeProfilePrefs(registry.get());
media_router::RegisterProfilePrefs(registry.get());
media_device_salt::MediaDeviceIDSalt::RegisterProfilePrefs(registry.get());
PermissionBubbleMediaAccessHandler::RegisterProfilePrefs(registry.get());
permissions::PermissionActionsHistory::RegisterProfilePrefs(registry.get());
permissions::PermissionHatsTriggerHelper::RegisterProfilePrefs(
registry.get());
prefetch::RegisterPredictionOptionsProfilePrefs(registry.get());
privacy_sandbox::RegisterProfilePrefs(registry.get());
ProfileNetworkContextService::RegisterProfilePrefs(registry.get());
QuietNotificationPermissionUiState::RegisterProfilePrefs(registry.get());
RegisterBrowserViewProfilePrefs(registry.get());
safe_browsing::RegisterProfilePrefs(registry.get());
unified_consent::UnifiedConsentService::RegisterPrefs(registry.get());
const std::string& locale =
command_line->GetSwitchValueASCII(switches::kLang);
DCHECK(!locale.empty());
renderer_prefs::RegisterProfilePrefs(registry.get(), locale);
// Print preferences.
// Based on ProfileImpl::RegisterProfilePrefs.
registry->RegisterBooleanPref(policy::policy_prefs::kForceGoogleSafeSearch,
false);
registry->RegisterIntegerPref(policy::policy_prefs::kForceYouTubeRestrict,
safe_search_api::YOUTUBE_RESTRICT_OFF);
registry->RegisterStringPref(prefs::kAllowedDomainsForApps, std::string());
registry->RegisterBooleanPref(prefs::kPrintingEnabled, true);
registry->RegisterBooleanPref(prefs::kPrintPreviewDisabled, false);
registry->RegisterStringPref(
prefs::kPrintPreviewDefaultDestinationSelectionRules, std::string());
registry->RegisterBooleanPref(prefs::kEnableMediaRouter, true);
printing::PolicySettings::RegisterProfilePrefs(registry.get());
printing::PrintPreviewStickySettings::RegisterProfilePrefs(registry.get());
DownloadPrefs::RegisterProfilePrefs(registry.get());
// Cache preferences.
// Based on ProfileImpl::RegisterProfilePrefs.
registry->RegisterFilePathPref(prefs::kDiskCacheDir, cache_path);
registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
// Based on Profile::RegisterProfilePrefs.
registry->RegisterBooleanPref(prefs::kSearchSuggestEnabled, false);
registry->RegisterStringPref(prefs::kSessionExitType, std::string());
// Based on ChromeContentBrowserClient::RegisterProfilePrefs.
registry->RegisterBooleanPref(
prefs::kAccessControlAllowMethodsInCORSPreflightSpecConformant, true);
// Spell checking preferences.
// Modify defaults from SpellcheckServiceFactory::RegisterProfilePrefs.
std::string spellcheck_lang =
command_line->GetSwitchValueASCII(switches::kOverrideSpellCheckLang);
if (!spellcheck_lang.empty()) {
registry->SetDefaultPrefValue(spellcheck::prefs::kSpellCheckDictionary,
base::Value(spellcheck_lang));
}
const bool enable_spelling_service_ =
command_line->HasSwitch(switches::kEnableSpellingService);
registry->SetDefaultPrefValue(
spellcheck::prefs::kSpellCheckUseSpellingService,
base::Value(enable_spelling_service_));
registry->SetDefaultPrefValue(spellcheck::prefs::kSpellCheckEnable,
base::Value(!enable_spelling_service_));
// DevTools preferences.
// Based on DevToolsWindow::RegisterProfilePrefs.
registry->RegisterDictionaryPref(prefs::kDevToolsPreferences);
registry->RegisterDictionaryPref(prefs::kDevToolsEditedFiles);
// Language preferences. Used by ProfileNetworkContextService and
// InterceptedRequestHandlerWrapper.
const std::string& accept_language_list =
GetAcceptLanguageListSetting(profile);
if (!accept_language_list.empty()) {
registry->SetDefaultPrefValue(language::prefs::kAcceptLanguages,
base::Value(accept_language_list));
}
registry->RegisterListPref(prefs::kWebRtcLocalIpsAllowedUrls);
// Always do this after all other profile prefs.
RegisterProfilePrefs(registry.get());
} else {
// Always do this after all other local state prefs.
RegisterLocalStatePrefs(registry.get());
}
// Build the PrefService that manages the PrefRegistry and PrefStores.
return factory.CreateSyncable(registry.get());
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
std::string GetAcceptLanguageList(Profile* profile) {
// Always prefer to the CEF settings configuration, if specified.
std::string accept_language_list = GetAcceptLanguageListSetting(profile);
if (accept_language_list.empty() && profile) {
// Fall back to the preference value. For the Alloy runtime the default
// value comes from browser_prefs::CreatePrefService() above. For the Chrome
// runtime the default value comes from the configured locale
// (IDS_ACCEPT_LANGUAGES) which is then overridden by the user preference in
// chrome://settings/languages, all managed by language::LanguagePrefs.
// Fall back to the preference value. The default value comes from the
// configured locale (IDS_ACCEPT_LANGUAGES) which is then overridden by the
// user preference in chrome://settings/languages, all managed by
// language::LanguagePrefs.
accept_language_list =
profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages);
}

View File

@@ -8,19 +8,9 @@
#include <memory>
#include <string>
#include "cef/libcef/features/features.h"
class PrefRegistrySimple;
class Profile;
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace base {
class FilePath;
}
class PrefService;
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace browser_prefs {
// Register preferences specific to CEF.
@@ -28,15 +18,6 @@ namespace browser_prefs {
void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
void RegisterProfilePrefs(PrefRegistrySimple* registry);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Create the PrefService used to manage pref registration and storage.
// |profile| will be nullptr for the system-level PrefService. Used with the
// Alloy runtime only.
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
const base::FilePath& cache_path,
bool persist_user_preferences);
#endif
// Returns the value for populating the accept-language HTTP request header.
// |browser_context| and/or |browser| may be nullptr. If |expand| is true then
// base languages and Q values may be added.

View File

@@ -1,215 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cef/libcef/browser/prefs/pref_store.h"
#include <memory>
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/values.h"
CefPrefStore::CefPrefStore() = default;
bool CefPrefStore::GetValue(std::string_view key,
const base::Value** value) const {
return prefs_.GetValue(key, value);
}
base::Value::Dict CefPrefStore::GetValues() const {
return prefs_.AsDict();
}
bool CefPrefStore::GetMutableValue(const std::string& key,
base::Value** value) {
return prefs_.GetValue(key, value);
}
void CefPrefStore::AddObserver(PrefStore::Observer* observer) {
observers_.AddObserver(observer);
}
void CefPrefStore::RemoveObserver(PrefStore::Observer* observer) {
observers_.RemoveObserver(observer);
}
bool CefPrefStore::HasObservers() const {
return !observers_.empty();
}
bool CefPrefStore::IsInitializationComplete() const {
return init_complete_;
}
void CefPrefStore::SetValue(const std::string& key,
base::Value value,
uint32_t flags) {
if (prefs_.SetValue(key, std::move(value))) {
committed_ = false;
NotifyPrefValueChanged(key);
}
}
void CefPrefStore::SetValueSilently(const std::string& key,
base::Value value,
uint32_t flags) {
if (prefs_.SetValue(key, std::move(value))) {
committed_ = false;
}
}
void CefPrefStore::RemoveValuesByPrefixSilently(const std::string& prefix) {
prefs_.ClearWithPrefix(prefix);
committed_ = false;
}
void CefPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
if (prefs_.RemoveValue(key)) {
committed_ = false;
NotifyPrefValueChanged(key);
}
}
bool CefPrefStore::ReadOnly() const {
return read_only_;
}
PersistentPrefStore::PrefReadError CefPrefStore::GetReadError() const {
return read_error_;
}
PersistentPrefStore::PrefReadError CefPrefStore::ReadPrefs() {
NotifyInitializationCompleted();
return read_error_;
}
void CefPrefStore::ReadPrefsAsync(ReadErrorDelegate* error_delegate) {
DCHECK(!pending_async_read_);
error_delegate_.emplace(error_delegate);
if (block_async_read_) {
pending_async_read_ = true;
} else {
NotifyInitializationCompleted();
}
}
void CefPrefStore::CommitPendingWrite(
base::OnceClosure done_callback,
base::OnceClosure synchronous_done_callback) {
committed_ = true;
PersistentPrefStore::CommitPendingWrite(std::move(done_callback),
std::move(synchronous_done_callback));
}
void CefPrefStore::SchedulePendingLossyWrites() {}
void CefPrefStore::OnStoreDeletionFromDisk() {}
bool CefPrefStore::HasReadErrorDelegate() const {
return error_delegate_.has_value();
}
void CefPrefStore::SetInitializationCompleted() {
NotifyInitializationCompleted();
}
void CefPrefStore::NotifyPrefValueChanged(const std::string& key) {
for (Observer& observer : observers_) {
observer.OnPrefValueChanged(key);
}
}
void CefPrefStore::NotifyInitializationCompleted() {
DCHECK(!init_complete_);
init_complete_ = true;
if (read_success_ && read_error_ != PREF_READ_ERROR_NONE &&
error_delegate_.has_value() && error_delegate_.value()) {
error_delegate_.value()->OnError(read_error_);
}
for (Observer& observer : observers_) {
observer.OnInitializationCompleted(read_success_);
}
}
void CefPrefStore::ReportValueChanged(const std::string& key, uint32_t flags) {
for (Observer& observer : observers_) {
observer.OnPrefValueChanged(key);
}
}
void CefPrefStore::SetString(const std::string& key, const std::string& value) {
SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
void CefPrefStore::SetInteger(const std::string& key, int value) {
SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
void CefPrefStore::SetBoolean(const std::string& key, bool value) {
SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
bool CefPrefStore::GetString(const std::string& key, std::string* value) const {
const base::Value* stored_value;
if (!prefs_.GetValue(key, &stored_value) || !stored_value) {
return false;
}
if (value && stored_value->is_string()) {
*value = stored_value->GetString();
return true;
}
return stored_value->is_string();
}
bool CefPrefStore::GetInteger(const std::string& key, int* value) const {
const base::Value* stored_value;
if (!prefs_.GetValue(key, &stored_value) || !stored_value) {
return false;
}
if (value && stored_value->is_int()) {
*value = stored_value->GetInt();
return true;
}
return stored_value->is_int();
}
bool CefPrefStore::GetBoolean(const std::string& key, bool* value) const {
const base::Value* stored_value;
if (!prefs_.GetValue(key, &stored_value) || !stored_value) {
return false;
}
if (value && stored_value->is_bool()) {
*value = stored_value->GetBool();
return true;
}
return stored_value->is_bool();
}
void CefPrefStore::SetBlockAsyncRead(bool block_async_read) {
DCHECK(!init_complete_);
block_async_read_ = block_async_read;
if (pending_async_read_ && !block_async_read_) {
NotifyInitializationCompleted();
}
}
void CefPrefStore::set_read_only(bool read_only) {
read_only_ = read_only;
}
void CefPrefStore::set_read_success(bool read_success) {
DCHECK(!init_complete_);
read_success_ = read_success;
}
void CefPrefStore::set_read_error(
PersistentPrefStore::PrefReadError read_error) {
DCHECK(!init_complete_);
read_error_ = read_error;
}
CefPrefStore::~CefPrefStore() = default;

View File

@@ -1,121 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_PREFS_PREF_STORE_H_
#define CEF_LIBCEF_BROWSER_PREFS_PREF_STORE_H_
#include <stdint.h>
#include <optional>
#include <string>
#include "base/observer_list.h"
#include "components/prefs/persistent_pref_store.h"
#include "components/prefs/pref_value_map.h"
// Preference store implementation that supports explicit manipulation of the
// contents of the store, triggering notifications where appropriate.
// Based on components/prefs/testing_pref_store.h.
class CefPrefStore : public PersistentPrefStore {
public:
CefPrefStore();
CefPrefStore(const CefPrefStore&) = delete;
CefPrefStore& operator=(const CefPrefStore&) = delete;
// Overriden from PrefStore.
bool GetValue(std::string_view key,
const base::Value** result) const override;
base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
bool IsInitializationComplete() const override;
// PersistentPrefStore overrides:
bool GetMutableValue(const std::string& key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override;
void SetValue(const std::string& key,
base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
base::Value value,
uint32_t flags) override;
void RemoveValuesByPrefixSilently(const std::string& prefix) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
PrefReadError GetReadError() const override;
PersistentPrefStore::PrefReadError ReadPrefs() override;
void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override;
void CommitPendingWrite(base::OnceClosure done_callback,
base::OnceClosure synchronous_done_callback) override;
void SchedulePendingLossyWrites() override;
void OnStoreDeletionFromDisk() override;
bool HasReadErrorDelegate() const override;
// Marks the store as having completed initialization.
void SetInitializationCompleted();
// Used for tests to trigger notifications explicitly.
void NotifyPrefValueChanged(const std::string& key);
void NotifyInitializationCompleted();
// Some convenience getters/setters.
void SetString(const std::string& key, const std::string& value);
void SetInteger(const std::string& key, int value);
void SetBoolean(const std::string& key, bool value);
bool GetString(const std::string& key, std::string* value) const;
bool GetInteger(const std::string& key, int* value) const;
bool GetBoolean(const std::string& key, bool* value) const;
// Determines whether ReadPrefsAsync completes immediately. Defaults to false
// (non-blocking). To block, invoke this with true (blocking) before the call
// to ReadPrefsAsync. To unblock, invoke again with false (non-blocking) after
// the call to ReadPrefsAsync.
void SetBlockAsyncRead(bool block_async_read);
// Getter and Setter methods for setting and getting the state of the
// |TestingPrefStore|.
virtual void set_read_only(bool read_only);
void set_read_success(bool read_success);
void set_read_error(PersistentPrefStore::PrefReadError read_error);
bool committed() { return committed_; }
protected:
~CefPrefStore() override;
private:
// Stores the preference values.
PrefValueMap prefs_;
// Flag that indicates if the PrefStore is read-only
bool read_only_ = true;
// The result to pass to PrefStore::Observer::OnInitializationCompleted
bool read_success_ = true;
// The result to return from ReadPrefs or ReadPrefsAsync.
PersistentPrefStore::PrefReadError read_error_ =
PersistentPrefStore::PREF_READ_ERROR_NONE;
// Whether a call to ReadPrefsAsync should block.
bool block_async_read_ = false;
// Whether there is a pending call to ReadPrefsAsync.
bool pending_async_read_ = false;
// Whether initialization has been completed.
bool init_complete_ = false;
// Whether the store contents have been committed to disk since the last
// mutation.
bool committed_ = true;
// Optional so we can differentiate `nullopt` from `nullptr`.
std::optional<std::unique_ptr<ReadErrorDelegate>> error_delegate_;
base::ObserverList<PrefStore::Observer, true>::Unchecked observers_;
};
#endif // COMPONENTS_PREFS_TESTING_PREF_STORE_H_

View File

@@ -9,268 +9,8 @@
#include "content/public/common/content_switches.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "base/i18n/character_encoding.h"
#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
#include "cef/libcef/browser/context.h"
#include "cef/libcef/common/extensions/extensions_util.h"
#include "cef/libcef/features/runtime_checks.h"
#include "chrome/browser/accessibility/animation_policy_prefs.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_webkit_preferences.h"
#include "chrome/browser/font_family_cache.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/command_line_pref_store.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_store.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/view_type_utils.h"
#include "extensions/common/constants.h"
#include "media/media_buildflags.h"
#include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h"
#include "ui/color/color_provider_key.h"
#include "ui/native_theme/native_theme.h"
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace renderer_prefs {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace {
// Chrome preferences.
// Should match ChromeContentBrowserClient::OverrideWebkitPrefs.
void SetChromePrefs(Profile* profile, blink::web_pref::WebPreferences& web) {
PrefService* prefs = profile->GetPrefs();
// Fill per-script font preferences.
FontFamilyCache::FillFontFamilyMap(profile,
prefs::kWebKitStandardFontFamilyMap,
&web.standard_font_family_map);
FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap,
&web.fixed_font_family_map);
FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap,
&web.serif_font_family_map);
FontFamilyCache::FillFontFamilyMap(profile,
prefs::kWebKitSansSerifFontFamilyMap,
&web.sans_serif_font_family_map);
FontFamilyCache::FillFontFamilyMap(profile,
prefs::kWebKitCursiveFontFamilyMap,
&web.cursive_font_family_map);
FontFamilyCache::FillFontFamilyMap(profile,
prefs::kWebKitFantasyFontFamilyMap,
&web.fantasy_font_family_map);
web.default_font_size = prefs->GetInteger(prefs::kWebKitDefaultFontSize);
web.default_fixed_font_size =
prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
web.minimum_font_size = prefs->GetInteger(prefs::kWebKitMinimumFontSize);
web.minimum_logical_font_size =
prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
web.default_encoding = prefs->GetString(prefs::kDefaultCharset);
web.dom_paste_enabled = prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
web.tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) {
web.javascript_enabled = false;
}
if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) {
web.web_security_enabled = false;
}
if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) {
web.plugins_enabled = false;
}
web.loads_images_automatically =
prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
if (prefs->GetBoolean(prefs::kDisable3DAPIs)) {
web.webgl1_enabled = false;
web.webgl2_enabled = false;
}
web.allow_running_insecure_content =
prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
web.password_echo_enabled = false;
web.text_areas_are_resizable =
prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
web.hyperlink_auditing_enabled =
prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
if (extensions::ExtensionsEnabled()) {
std::string image_animation_policy =
prefs->GetString(prefs::kAnimationPolicy);
if (image_animation_policy == kAnimationPolicyOnce) {
web.animation_policy =
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
} else if (image_animation_policy == kAnimationPolicyNone) {
web.animation_policy =
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
} else {
web.animation_policy =
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
}
}
// Make sure we will set the default_encoding with canonical encoding name.
web.default_encoding =
base::GetCanonicalEncodingNameByAliasName(web.default_encoding);
if (web.default_encoding.empty()) {
prefs->ClearPref(prefs::kDefaultCharset);
web.default_encoding = prefs->GetString(prefs::kDefaultCharset);
}
DCHECK(!web.default_encoding.empty());
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnablePotentiallyAnnoyingSecurityFeatures)) {
web.disable_reading_from_canvas = true;
web.strict_mixed_content_checking = true;
web.strict_powerful_feature_restrictions = true;
}
}
// Extension preferences.
// Should match ChromeContentBrowserClientExtensionsPart::OverrideWebkitPrefs.
void SetExtensionPrefs(content::WebContents* web_contents,
content::RenderViewHost* rvh,
blink::web_pref::WebPreferences& web) {
if (!extensions::ExtensionsEnabled()) {
return;
}
const extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(
rvh->GetProcess()->GetBrowserContext());
if (!registry) {
return;
}
// Note: it's not possible for kExtensionsScheme to change during the lifetime
// of the process.
//
// Ensure that we are only granting extension preferences to URLs with the
// correct scheme. Without this check, chrome-guest:// schemes used by webview
// tags as well as hosts that happen to match the id of an installed extension
// would get the wrong preferences.
const GURL& site_url =
web_contents->GetPrimaryMainFrame()->GetSiteInstance()->GetSiteURL();
if (!site_url.SchemeIs(extensions::kExtensionScheme)) {
return;
}
const extensions::Extension* extension =
registry->enabled_extensions().GetByID(site_url.host());
extension_webkit_preferences::SetPreferences(extension, &web);
}
void SetString(CommandLinePrefStore* prefs,
const std::string& key,
const std::string& value) {
prefs->SetValue(key, base::Value(value),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
void SetBool(CommandLinePrefStore* prefs, const std::string& key, bool value) {
prefs->SetValue(key, base::Value(value),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
blink::mojom::PreferredColorScheme ToBlinkPreferredColorScheme(
ui::NativeTheme::PreferredColorScheme native_theme_scheme) {
switch (native_theme_scheme) {
case ui::NativeTheme::PreferredColorScheme::kDark:
return blink::mojom::PreferredColorScheme::kDark;
case ui::NativeTheme::PreferredColorScheme::kLight:
return blink::mojom::PreferredColorScheme::kLight;
}
DCHECK(false);
}
// From chrome/browser/chrome_content_browser_client.cc
// Returns true if preferred color scheme is modified based on at least one of
// the following -
// |url| - Last committed url.
// |native_theme| - For other platforms based on native theme scheme.
bool UpdatePreferredColorScheme(blink::web_pref::WebPreferences* web_prefs,
const GURL& url,
content::WebContents* web_contents,
const ui::NativeTheme* native_theme) {
auto old_preferred_color_scheme = web_prefs->preferred_color_scheme;
auto preferred_color_scheme = native_theme->GetPreferredColorScheme();
// Based on https://issues.chromium.org/issues/332328864#comment3
auto* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
const auto* theme_service = ThemeServiceFactory::GetForProfile(profile);
const auto browser_color_scheme = theme_service->GetBrowserColorScheme();
if (browser_color_scheme != ThemeService::BrowserColorScheme::kSystem) {
// Override the native theme.
preferred_color_scheme =
browser_color_scheme == ThemeService::BrowserColorScheme::kLight
? ui::NativeTheme::PreferredColorScheme::kLight
: ui::NativeTheme::PreferredColorScheme::kDark;
}
// Update based on native theme scheme.
web_prefs->preferred_color_scheme =
ToBlinkPreferredColorScheme(preferred_color_scheme);
if (url.SchemeIs(content::kChromeUIScheme)) {
// WebUI should track the color mode of the ColorProvider associated with
// |web_contents|.
web_prefs->preferred_color_scheme =
web_contents->GetColorMode() == ui::ColorProviderKey::ColorMode::kLight
? blink::mojom::PreferredColorScheme::kLight
: blink::mojom::PreferredColorScheme::kDark;
}
return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
}
} // namespace
void SetCommandLinePrefDefaults(CommandLinePrefStore* prefs) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kDefaultEncoding)) {
SetString(prefs, prefs::kDefaultCharset,
command_line->GetSwitchValueASCII(switches::kDefaultEncoding));
}
if (command_line->HasSwitch(switches::kDisableJavascriptDomPaste)) {
SetBool(prefs, prefs::kWebKitDomPasteEnabled, false);
}
if (command_line->HasSwitch(switches::kDisableImageLoading)) {
SetBool(prefs, prefs::kWebKitLoadsImagesAutomatically, false);
}
if (command_line->HasSwitch(switches::kDisableTabToLinks)) {
SetBool(prefs, prefs::kWebkitTabsToLinks, false);
}
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void SetDefaultPrefs(blink::web_pref::WebPreferences& web) {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
@@ -363,107 +103,4 @@ void SetCefPrefs(const CefBrowserSettings& cef,
}
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
const std::string& locale) {
PrefsTabHelper::RegisterProfilePrefs(registry, locale);
RegisterAnimationPolicyPrefs(registry);
// From chrome/browser/ui/browser_ui_prefs.cc RegisterBrowserUserPrefs.
registry->RegisterBooleanPref(prefs::kCaretBrowsingEnabled, false);
registry->RegisterStringPref(prefs::kWebRTCIPHandlingPolicy,
blink::kWebRTCIPHandlingDefault);
registry->RegisterStringPref(prefs::kWebRTCUDPPortRange, std::string());
#if !BUILDFLAG(IS_MAC)
registry->RegisterBooleanPref(prefs::kFullscreenAllowed, true);
#endif
// From ChromeContentBrowserClient::RegisterProfilePrefs.
registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true);
// From Profile::RegisterProfilePrefs.
registry->RegisterDictionaryPref(prefs::kPartitionDefaultZoomLevel);
registry->RegisterDictionaryPref(prefs::kPartitionPerHostZoomLevels);
}
void PopulateWebPreferences(content::RenderViewHost* rvh,
blink::web_pref::WebPreferences& web,
SkColor& base_background_color) {
REQUIRE_ALLOY_RUNTIME();
auto browser = AlloyBrowserHostImpl::GetBrowserForHost(rvh);
// Set defaults for preferences that are not handled by PrefService.
SetDefaultPrefs(web);
// Set preferences based on the context's PrefService.
if (browser) {
auto profile = Profile::FromBrowserContext(
browser->web_contents()->GetBrowserContext());
SetChromePrefs(profile, web);
}
auto* native_theme = ui::NativeTheme::GetInstanceForWeb();
switch (native_theme->GetPreferredColorScheme()) {
case ui::NativeTheme::PreferredColorScheme::kDark:
web.preferred_color_scheme = blink::mojom::PreferredColorScheme::kDark;
break;
case ui::NativeTheme::PreferredColorScheme::kLight:
web.preferred_color_scheme = blink::mojom::PreferredColorScheme::kLight;
break;
}
switch (native_theme->GetPreferredContrast()) {
case ui::NativeTheme::PreferredContrast::kNoPreference:
web.preferred_contrast = blink::mojom::PreferredContrast::kNoPreference;
break;
case ui::NativeTheme::PreferredContrast::kMore:
web.preferred_contrast = blink::mojom::PreferredContrast::kMore;
break;
case ui::NativeTheme::PreferredContrast::kLess:
web.preferred_contrast = blink::mojom::PreferredContrast::kLess;
break;
case ui::NativeTheme::PreferredContrast::kCustom:
web.preferred_contrast = blink::mojom::PreferredContrast::kCustom;
break;
}
auto web_contents = content::WebContents::FromRenderViewHost(rvh);
UpdatePreferredColorScheme(
&web,
web_contents->GetPrimaryMainFrame()->GetSiteInstance()->GetSiteURL(),
web_contents, native_theme);
// Set preferences based on the extension.
SetExtensionPrefs(web_contents, rvh, web);
if (browser) {
// Set preferences based on CefBrowserSettings.
SetCefPrefs(browser->settings(), web);
web.picture_in_picture_enabled = browser->IsPictureInPictureSupported();
// Set the background color for the WebView.
base_background_color = browser->GetBackgroundColor();
} else {
// We don't know for sure that the browser will be windowless but assume
// that the global windowless state is likely to be accurate.
base_background_color =
CefContext::Get()->GetBackgroundColor(nullptr, STATE_DEFAULT);
}
}
bool PopulateWebPreferencesAfterNavigation(
content::WebContents* web_contents,
blink::web_pref::WebPreferences& web) {
auto* native_theme = ui::NativeTheme::GetInstanceForWeb();
return UpdatePreferredColorScheme(&web, web_contents->GetLastCommittedURL(),
web_contents, native_theme);
}
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
} // namespace renderer_prefs

View File

@@ -9,42 +9,13 @@
#include <string>
#include "cef/include/internal/cef_types_wrappers.h"
#include "cef/libcef/features/features.h"
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
#include "third_party/skia/include/core/SkColor.h"
#endif
namespace blink::web_pref {
struct WebPreferences;
}
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace content {
class RenderViewHost;
class WebContents;
} // namespace content
namespace user_prefs {
class PrefRegistrySyncable;
}
class CommandLinePrefStore;
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
namespace renderer_prefs {
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Register additional renderer-related preferences.
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
const std::string& locale);
// Set default values based on CEF command-line flags for preferences that are
// available via the PrefService. Chromium command-line flags should not exist
// for these preferences.
void SetCommandLinePrefDefaults(CommandLinePrefStore* prefs);
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Set default values based on CEF command-line flags for preferences that are
// not available via the PrefService. Chromium command-line flags should not
// exist for these preferences.
@@ -54,17 +25,6 @@ void SetDefaultPrefs(blink::web_pref::WebPreferences& web);
void SetCefPrefs(const CefBrowserSettings& cef,
blink::web_pref::WebPreferences& web);
#if BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
// Populate WebPreferences based on a combination of command-line values,
// PrefService and CefBrowserSettings.
void PopulateWebPreferences(content::RenderViewHost* rvh,
blink::web_pref::WebPreferences& web,
SkColor& base_background_color);
bool PopulateWebPreferencesAfterNavigation(
content::WebContents* web_contents,
blink::web_pref::WebPreferences& web);
#endif // BUILDFLAG(ENABLE_ALLOY_BOOTSTRAP)
} // namespace renderer_prefs
#endif // CEF_LIBCEF_BROWSER_PREFS_RENDERER_PREFS_H_