2013-10-18 18:33:56 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "libcef/browser/prefs/browser_prefs.h"
|
2014-10-07 22:44:33 +02:00
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
#include "libcef/browser/browser_context.h"
|
2013-10-18 18:33:56 +02:00
|
|
|
#include "libcef/browser/media_capture_devices_dispatcher.h"
|
2017-05-31 17:33:30 +02:00
|
|
|
#include "libcef/browser/prefs/pref_store.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "libcef/browser/prefs/renderer_prefs.h"
|
2014-10-07 22:44:33 +02:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2013-10-18 18:33:56 +02:00
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "base/files/file_path.h"
|
2014-10-07 22:44:33 +02:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2018-08-09 22:18:24 +02:00
|
|
|
#include "base/task/post_task.h"
|
2013-10-18 18:33:56 +02:00
|
|
|
#include "base/values.h"
|
2018-07-31 21:21:39 +02:00
|
|
|
#include "chrome/browser/accessibility/accessibility_ui.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "chrome/browser/download/download_prefs.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "chrome/browser/net/prediction_options.h"
|
2019-03-21 01:23:23 +01:00
|
|
|
#include "chrome/browser/net/profile_network_context_service.h"
|
|
|
|
#include "chrome/browser/net/system_network_context_manager.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "chrome/browser/plugins/plugin_info_host_impl.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "chrome/browser/prefs/chrome_command_line_pref_store.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "chrome/browser/renderer_host/pepper/device_id_fetcher.h"
|
2019-03-21 01:23:23 +01:00
|
|
|
#include "chrome/browser/ssl/ssl_config_service_manager.h"
|
2016-07-14 03:35:07 +02:00
|
|
|
#include "chrome/browser/themes/theme_service.h"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "chrome/browser/ui/webui/print_preview/sticky_settings.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "chrome/common/buildflags.h"
|
2014-10-07 22:44:33 +02:00
|
|
|
#include "chrome/common/chrome_switches.h"
|
2019-09-25 15:59:51 +02:00
|
|
|
#include "chrome/common/net/safe_search_util.h"
|
2013-10-18 18:33:56 +02:00
|
|
|
#include "chrome/common/pref_names.h"
|
2016-07-14 03:35:07 +02:00
|
|
|
#include "chrome/grit/locale_settings.h"
|
2019-03-21 01:23:23 +01:00
|
|
|
#include "components/certificate_transparency/pref_names.h"
|
2016-08-04 14:37:53 +02:00
|
|
|
#include "components/content_settings/core/browser/cookie_settings.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "components/content_settings/core/browser/host_content_settings_map.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "components/flags_ui/pref_service_flags_storage.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
2019-02-21 01:42:36 +01:00
|
|
|
#include "components/language/core/browser/language_prefs.h"
|
2019-05-11 00:14:48 +02:00
|
|
|
#include "components/language/core/browser/pref_names.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "components/pref_registry/pref_registry_syncable.h"
|
2016-02-05 01:49:19 +01:00
|
|
|
#include "components/prefs/json_pref_store.h"
|
|
|
|
#include "components/prefs/pref_filter.h"
|
|
|
|
#include "components/prefs/pref_registry_simple.h"
|
|
|
|
#include "components/prefs/pref_service.h"
|
2015-10-09 17:23:12 +02:00
|
|
|
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
|
2015-07-24 02:06:56 +02:00
|
|
|
#include "components/proxy_config/proxy_config_dictionary.h"
|
2016-08-31 13:25:56 +02:00
|
|
|
#include "components/spellcheck/browser/pref_names.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "components/sync_preferences/pref_service_syncable.h"
|
|
|
|
#include "components/sync_preferences/pref_service_syncable_factory.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "components/update_client/update_client.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/browser/extension_prefs.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "extensions/buildflags/buildflags.h"
|
2014-10-07 22:44:33 +02:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2019-06-05 16:15:45 +02:00
|
|
|
#include "ui/base/ui_base_switches.h"
|
2014-10-07 22:44:33 +02:00
|
|
|
|
2019-04-29 17:31:13 +02:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
#include "components/os_crypt/os_crypt.h"
|
|
|
|
#endif
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
|
|
|
|
#include "chrome/browser/supervised_user/supervised_user_pref_store.h"
|
|
|
|
#include "chrome/browser/supervised_user/supervised_user_settings_service.h"
|
|
|
|
#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
|
|
|
|
#endif
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
namespace browser_prefs {
|
|
|
|
|
2019-05-11 00:14:48 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
std::string GetAcceptLanguageList(Profile* profile) {
|
|
|
|
const CefRequestContextSettings& context_settings =
|
|
|
|
static_cast<CefBrowserContext*>(profile)->GetSettings();
|
|
|
|
if (context_settings.accept_language_list.length > 0) {
|
|
|
|
return CefString(&context_settings.accept_language_list);
|
|
|
|
}
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
const char kUserPrefsFileName[] = "UserPrefs.json";
|
2013-10-18 18:33:56 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
|
|
|
const base::FilePath& cache_path,
|
2017-09-25 15:11:17 +02:00
|
|
|
bool persist_user_preferences) {
|
2014-10-07 22:44:33 +02:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
|
|
|
|
2016-09-08 22:35:15 +02:00
|
|
|
// Use of PrefServiceSyncable is required by Chrome code such as
|
|
|
|
// HostContentSettingsMapFactory that calls PrefServiceSyncableFromProfile.
|
2016-11-23 21:54:29 +01:00
|
|
|
sync_preferences::PrefServiceSyncableFactory factory;
|
2015-10-17 02:44:00 +02:00
|
|
|
|
|
|
|
// 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.
|
2016-11-23 21:54:29 +01:00
|
|
|
scoped_refptr<ChromeCommandLinePrefStore> command_line_pref_store(
|
|
|
|
new ChromeCommandLinePrefStore(command_line));
|
2015-10-17 02:44:00 +02:00
|
|
|
renderer_prefs::SetCommandLinePrefDefaults(command_line_pref_store.get());
|
|
|
|
factory.set_command_line_prefs(command_line_pref_store);
|
|
|
|
|
2016-08-04 14:37:53 +02:00
|
|
|
// True if preferences will be stored on disk.
|
2017-09-25 15:11:17 +02:00
|
|
|
const bool store_on_disk = !cache_path.empty() && persist_user_preferences;
|
2016-08-04 14:37:53 +02:00
|
|
|
|
|
|
|
scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner;
|
|
|
|
if (store_on_disk) {
|
2017-10-20 19:45:20 +02:00
|
|
|
// Get sequenced task runner for making sure that file operations are
|
|
|
|
// executed in expected order (what was previously assured by the FILE
|
|
|
|
// thread).
|
2019-10-01 15:55:16 +02:00
|
|
|
sequenced_task_runner = base::CreateSequencedTaskRunner(
|
|
|
|
{base::ThreadPool(), base::MayBlock(),
|
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
|
2016-08-04 14:37:53 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// Used to store user preferences.
|
|
|
|
scoped_refptr<PersistentPrefStore> user_pref_store;
|
2016-08-04 14:37:53 +02:00
|
|
|
if (store_on_disk) {
|
|
|
|
const base::FilePath& pref_path =
|
|
|
|
cache_path.AppendASCII(browser_prefs::kUserPrefsFileName);
|
2017-05-17 11:29:28 +02:00
|
|
|
scoped_refptr<JsonPrefStore> json_pref_store = new JsonPrefStore(
|
2018-08-09 22:18:24 +02:00
|
|
|
pref_path, std::unique_ptr<PrefFilter>(), sequenced_task_runner);
|
2015-10-17 02:44:00 +02:00
|
|
|
factory.set_user_prefs(json_pref_store.get());
|
|
|
|
} else {
|
2017-05-31 17:33:30 +02:00
|
|
|
scoped_refptr<CefPrefStore> cef_pref_store = new CefPrefStore();
|
|
|
|
cef_pref_store->SetInitializationCompleted();
|
|
|
|
factory.set_user_prefs(cef_pref_store.get());
|
2015-10-17 02:44:00 +02:00
|
|
|
}
|
2013-10-18 18:33:56 +02:00
|
|
|
|
2017-02-13 23:12:57 +01:00
|
|
|
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
|
2019-03-21 01:23:23 +01:00
|
|
|
if (profile) {
|
|
|
|
// Used to store supervised user preferences.
|
|
|
|
SupervisedUserSettingsService* supervised_user_settings =
|
2019-06-05 16:15:45 +02:00
|
|
|
SupervisedUserSettingsServiceFactory::GetForKey(
|
|
|
|
profile->GetProfileKey());
|
2019-03-21 01:23:23 +01:00
|
|
|
|
|
|
|
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);
|
2016-08-04 14:37:53 +02:00
|
|
|
}
|
2017-02-13 23:12:57 +01:00
|
|
|
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
|
2016-08-04 14:37:53 +02:00
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// Registry that will be populated with all known preferences. Preferences
|
|
|
|
// are registered with default values that may be changed via a *PrefStore.
|
2015-09-09 16:05:39 +02:00
|
|
|
scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
|
2015-07-16 23:40:01 +02:00
|
|
|
new user_prefs::PrefRegistrySyncable());
|
2013-10-18 18:33:56 +02:00
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
// 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.
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// Default preferences.
|
2014-09-27 01:48:19 +02:00
|
|
|
CefMediaCaptureDevicesDispatcher::RegisterPrefs(registry.get());
|
2019-03-21 01:23:23 +01:00
|
|
|
certificate_transparency::prefs::RegisterPrefs(registry.get());
|
2019-10-01 15:55:16 +02:00
|
|
|
flags_ui::PrefServiceFlagsStorage::RegisterPrefs(registry.get());
|
2017-12-07 22:44:24 +01:00
|
|
|
PluginInfoHostImpl::RegisterUserPrefs(registry.get());
|
|
|
|
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
|
2019-03-21 01:23:23 +01:00
|
|
|
SSLConfigServiceManager::RegisterPrefs(registry.get());
|
2016-05-25 01:35:43 +02:00
|
|
|
update_client::RegisterPrefs(registry.get());
|
2013-10-18 18:33:56 +02:00
|
|
|
|
2019-07-29 23:27:12 +02:00
|
|
|
if (!profile) {
|
2019-03-21 01:23:23 +01:00
|
|
|
SystemNetworkContextManager::RegisterPrefs(registry.get());
|
2019-04-29 17:31:13 +02:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
OSCrypt::RegisterLocalPrefs(registry.get());
|
|
|
|
#endif
|
2014-10-07 22:44:33 +02:00
|
|
|
}
|
2016-10-27 18:52:54 +02:00
|
|
|
|
2019-07-16 19:59:21 +02:00
|
|
|
// Browser process preferences.
|
|
|
|
// Based on chrome/browser/browser_process_impl.cc RegisterPrefs.
|
|
|
|
registry->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false);
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
// Browser UI preferences.
|
|
|
|
// Based on chrome/browser/ui/browser_ui_prefs.cc RegisterBrowserPrefs.
|
|
|
|
registry->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true);
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
// From Chrome::RegisterBrowserUserPrefs.
|
|
|
|
registry->RegisterBooleanPref(prefs::kPrintPreviewUseSystemDefaultPrinter,
|
|
|
|
true);
|
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
if (command_line->HasSwitch(switches::kEnablePreferenceTesting)) {
|
2015-10-17 02:44:00 +02:00
|
|
|
// Preferences used with unit tests.
|
2015-10-03 01:03:16 +02:00
|
|
|
registry->RegisterBooleanPref("test.bool", true);
|
|
|
|
registry->RegisterIntegerPref("test.int", 2);
|
|
|
|
registry->RegisterDoublePref("test.double", 5.0);
|
|
|
|
registry->RegisterStringPref("test.string", "default");
|
|
|
|
registry->RegisterListPref("test.list");
|
|
|
|
registry->RegisterDictionaryPref("test.dict");
|
|
|
|
}
|
|
|
|
|
2019-03-21 01:23:23 +01:00
|
|
|
if (profile) {
|
|
|
|
// Call RegisterProfilePrefs() for all services listed by
|
|
|
|
// EnsureBrowserContextKeyedServiceFactoriesBuilt().
|
|
|
|
BrowserContextDependencyManager::GetInstance()
|
2019-04-16 16:38:48 +02:00
|
|
|
->RegisterProfilePrefsForServices(registry.get());
|
2019-03-21 01:23:23 +01:00
|
|
|
|
|
|
|
// Default profile preferences.
|
|
|
|
AccessibilityUIMessageHandler::RegisterProfilePrefs(registry.get());
|
|
|
|
chrome_browser_net::RegisterPredictionOptionsProfilePrefs(registry.get());
|
|
|
|
DeviceIDFetcher::RegisterProfilePrefs(registry.get());
|
|
|
|
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
|
|
|
|
HostContentSettingsMap::RegisterProfilePrefs(registry.get());
|
2019-04-16 16:38:48 +02:00
|
|
|
language::LanguagePrefs::RegisterProfilePrefs(registry.get());
|
2019-03-21 01:23:23 +01:00
|
|
|
ProfileNetworkContextService::RegisterProfilePrefs(registry.get());
|
2019-06-05 16:15:45 +02:00
|
|
|
|
|
|
|
const std::string& locale =
|
|
|
|
command_line->GetSwitchValueASCII(switches::kLang);
|
|
|
|
DCHECK(!locale.empty());
|
|
|
|
renderer_prefs::RegisterProfilePrefs(registry.get(), locale);
|
2019-03-21 01:23:23 +01:00
|
|
|
|
|
|
|
// Print preferences.
|
|
|
|
// Based on ProfileImpl::RegisterProfilePrefs.
|
2019-09-25 15:59:51 +02:00
|
|
|
registry->RegisterBooleanPref(prefs::kForceGoogleSafeSearch, false);
|
|
|
|
registry->RegisterIntegerPref(prefs::kForceYouTubeRestrict,
|
|
|
|
safe_search_util::YOUTUBE_RESTRICT_OFF);
|
|
|
|
registry->RegisterStringPref(prefs::kAllowedDomainsForApps, std::string());
|
2019-03-21 01:23:23 +01:00
|
|
|
registry->RegisterBooleanPref(prefs::kPrintingEnabled, true);
|
2019-07-17 20:47:27 +02:00
|
|
|
registry->RegisterBooleanPref(prefs::kPrintPreviewDisabled,
|
|
|
|
!extensions::PrintPreviewEnabled());
|
|
|
|
registry->RegisterStringPref(
|
|
|
|
prefs::kPrintPreviewDefaultDestinationSelectionRules, std::string());
|
|
|
|
registry->RegisterBooleanPref(prefs::kCloudPrintSubmitEnabled, false);
|
|
|
|
printing::StickySettings::RegisterProfilePrefs(registry.get());
|
|
|
|
DownloadPrefs::RegisterProfilePrefs(registry.get());
|
2019-03-21 01:23:23 +01:00
|
|
|
|
2019-03-24 19:41:42 +01:00
|
|
|
// Cache preferences.
|
|
|
|
// Based on ProfileImpl::RegisterProfilePrefs.
|
|
|
|
registry->RegisterFilePathPref(prefs::kDiskCacheDir, cache_path);
|
|
|
|
registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0);
|
|
|
|
|
2019-03-21 01:23:23 +01:00
|
|
|
// 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_));
|
|
|
|
|
|
|
|
// Pepper flash preferences.
|
|
|
|
// Modify defaults from DeviceIDFetcher::RegisterProfilePrefs.
|
|
|
|
registry->SetDefaultPrefValue(prefs::kEnableDRM, base::Value(false));
|
|
|
|
|
|
|
|
// DevTools preferences.
|
|
|
|
// Based on DevToolsWindow::RegisterProfilePrefs.
|
|
|
|
registry->RegisterDictionaryPref(prefs::kDevToolsPreferences);
|
|
|
|
registry->RegisterDictionaryPref(prefs::kDevToolsEditedFiles);
|
2019-05-11 00:14:48 +02:00
|
|
|
|
|
|
|
// Language preferences. Used by ProfileNetworkContextService and
|
|
|
|
// InterceptedRequestHandlerWrapper.
|
|
|
|
const std::string& accept_language_list = GetAcceptLanguageList(profile);
|
|
|
|
if (!accept_language_list.empty()) {
|
|
|
|
registry->SetDefaultPrefValue(language::prefs::kAcceptLanguages,
|
|
|
|
base::Value(accept_language_list));
|
|
|
|
}
|
2019-03-21 01:23:23 +01:00
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// Build the PrefService that manages the PrefRegistry and PrefStores.
|
2016-09-08 22:35:15 +02:00
|
|
|
return factory.CreateSyncable(registry.get());
|
2013-10-18 18:33:56 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
} // namespace browser_prefs
|