Add initial NetworkService support (see issue #2622).

This change adds an --enable-network-service command-line flag to run with
NetworkService enabled.

To test: Run `cefclient --enable-network-service --disable-extensions`. The
application should start, load a website and exit without crashing.
Network-related handlers (for cookies, schemes, requests, etc) and extensions
are not expected to work yet.

There should be no functional change when running without the NetworkService
enabled.
This commit is contained in:
Marshall Greenblatt
2019-03-20 20:23:23 -04:00
parent af349ade33
commit 6b2c1fe969
19 changed files with 289 additions and 98 deletions

View File

@@ -17,9 +17,12 @@
#include "base/values.h"
#include "chrome/browser/accessibility/accessibility_ui.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/net/profile_network_context_service.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/plugins/plugin_info_host_impl.h"
#include "chrome/browser/prefs/chrome_command_line_pref_store.h"
#include "chrome/browser/renderer_host/pepper/device_id_fetcher.h"
#include "chrome/browser/ssl/ssl_config_service_manager.h"
#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"
@@ -27,6 +30,7 @@
#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/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/google/core/browser/google_url_tracker.h"
@@ -97,23 +101,25 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
}
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
// Used to store supervised user preferences.
SupervisedUserSettingsService* supervised_user_settings =
SupervisedUserSettingsServiceFactory::GetForProfile(profile);
if (profile) {
// Used to store supervised user preferences.
SupervisedUserSettingsService* supervised_user_settings =
SupervisedUserSettingsServiceFactory::GetForProfile(profile);
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);
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);
}
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);
#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
// Registry that will be populated with all known preferences. Preferences
@@ -138,64 +144,24 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
// use) then register the preferences directly instead of calling the
// existing registration method.
// Call RegisterProfilePrefs() for all services listed by
// EnsureBrowserContextKeyedServiceFactoriesBuilt().
BrowserContextDependencyManager::GetInstance()
->RegisterProfilePrefsForServices(profile, registry.get());
// Default preferences.
AccessibilityUIMessageHandler::RegisterProfilePrefs(registry.get());
CefMediaCaptureDevicesDispatcher::RegisterPrefs(registry.get());
CefURLRequestContextGetterImpl::RegisterPrefs(registry.get());
chrome_browser_net::RegisterPredictionOptionsProfilePrefs(registry.get());
DeviceIDFetcher::RegisterProfilePrefs(registry.get());
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
GoogleURLTracker::RegisterProfilePrefs(registry.get());
HostContentSettingsMap::RegisterProfilePrefs(registry.get());
language::RegisterProfilePrefs(registry.get());
certificate_transparency::prefs::RegisterPrefs(registry.get());
PluginInfoHostImpl::RegisterUserPrefs(registry.get());
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
renderer_prefs::RegisterProfilePrefs(registry.get());
SSLConfigServiceManager::RegisterPrefs(registry.get());
update_client::RegisterPrefs(registry.get());
// Print preferences.
// Based on ProfileImpl::RegisterProfilePrefs.
registry->RegisterBooleanPref(prefs::kPrintingEnabled, 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));
if (!command_line->HasSwitch(switches::kEnableNetworkService)) {
CefURLRequestContextGetterImpl::RegisterPrefs(registry.get());
} else if (!profile) {
SystemNetworkContextManager::RegisterPrefs(registry.get());
}
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));
// Authentication preferences.
// Based on IOThread::RegisterPrefs.
registry->RegisterStringPref(prefs::kAuthServerWhitelist, "");
registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, "");
// Browser UI preferences.
// Based on chrome/browser/ui/browser_ui_prefs.cc RegisterBrowserPrefs.
registry->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true);
// DevTools preferences.
// Based on DevToolsWindow::RegisterProfilePrefs.
registry->RegisterDictionaryPref(prefs::kDevToolsPreferences);
registry->RegisterDictionaryPref(prefs::kDevToolsEditedFiles);
if (command_line->HasSwitch(switches::kEnablePreferenceTesting)) {
// Preferences used with unit tests.
registry->RegisterBooleanPref("test.bool", true);
@@ -206,6 +172,53 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
registry->RegisterDictionaryPref("test.dict");
}
if (profile) {
// Call RegisterProfilePrefs() for all services listed by
// EnsureBrowserContextKeyedServiceFactoriesBuilt().
BrowserContextDependencyManager::GetInstance()
->RegisterProfilePrefsForServices(profile, registry.get());
// Default profile preferences.
AccessibilityUIMessageHandler::RegisterProfilePrefs(registry.get());
chrome_browser_net::RegisterPredictionOptionsProfilePrefs(registry.get());
DeviceIDFetcher::RegisterProfilePrefs(registry.get());
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
GoogleURLTracker::RegisterProfilePrefs(registry.get());
HostContentSettingsMap::RegisterProfilePrefs(registry.get());
language::RegisterProfilePrefs(registry.get());
ProfileNetworkContextService::RegisterProfilePrefs(registry.get());
renderer_prefs::RegisterProfilePrefs(registry.get());
// Print preferences.
// Based on ProfileImpl::RegisterProfilePrefs.
registry->RegisterBooleanPref(prefs::kPrintingEnabled, 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_));
// 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);
}
// Build the PrefService that manages the PrefRegistry and PrefStores.
return factory.CreateSyncable(registry.get());
}