2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-15 16:25:08 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_browser_context.h"
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
#include "base/barrier_closure.h"
|
2015-01-05 21:40:38 +00:00
|
|
|
#include "base/command_line.h"
|
2015-07-26 08:17:55 +00:00
|
|
|
#include "base/files/file_path.h"
|
2020-08-17 20:21:53 +00:00
|
|
|
#include "base/no_destructor.h"
|
2016-01-21 08:21:37 +00:00
|
|
|
#include "base/path_service.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#include "base/task/post_task.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "base/threading/sequenced_task_runner_handle.h"
|
|
|
|
#include "base/threading/thread_restrictions.h"
|
2016-01-21 08:21:37 +00:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2015-07-26 08:17:55 +00:00
|
|
|
#include "chrome/common/pref_names.h"
|
2018-10-11 13:52:12 +00:00
|
|
|
#include "components/keyed_service/content/browser_context_dependency_manager.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "components/prefs/json_pref_store.h"
|
2016-06-15 11:31:29 +00:00
|
|
|
#include "components/prefs/pref_registry_simple.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "components/prefs/pref_service.h"
|
|
|
|
#include "components/prefs/pref_service_factory.h"
|
|
|
|
#include "components/prefs/value_map_pref_store.h"
|
|
|
|
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
|
|
|
|
#include "components/proxy_config/proxy_config_pref_names.h"
|
2019-03-05 05:08:55 +00:00
|
|
|
#include "content/browser/blob_storage/chrome_blob_storage_context.h" // nogncheck
|
2019-01-22 19:50:25 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2021-02-09 20:16:21 +00:00
|
|
|
#include "content/public/browser/cors_origin_pattern_setter.h"
|
|
|
|
#include "content/public/browser/shared_cors_origin_access_list.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "content/public/browser/storage_partition.h"
|
2019-11-14 18:01:18 +00:00
|
|
|
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "net/base/escape.h"
|
2019-03-26 01:10:48 +00:00
|
|
|
#include "services/network/public/cpp/features.h"
|
2019-08-29 06:07:46 +00:00
|
|
|
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
#include "services/network/public/mojom/network_context.mojom.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_url_loader.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/cookie_change_notifier.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/electron_browser_client.h"
|
|
|
|
#include "shell/browser/electron_browser_main_parts.h"
|
|
|
|
#include "shell/browser/electron_download_manager_delegate.h"
|
|
|
|
#include "shell/browser/electron_permission_manager.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/net/resolve_proxy_helper.h"
|
|
|
|
#include "shell/browser/pref_store_delegate.h"
|
2020-03-26 17:34:32 +00:00
|
|
|
#include "shell/browser/protocol_registry.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/special_storage_policy.h"
|
2020-07-15 18:27:42 +00:00
|
|
|
#include "shell/browser/ui/inspectable_web_contents.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/web_view_manager.h"
|
|
|
|
#include "shell/browser/zoom_level_delegate.h"
|
|
|
|
#include "shell/common/application_info.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "shell/common/electron_paths.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/options_switches.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
#include "extensions/browser/browser_context_keyed_service_factories.h"
|
|
|
|
#include "extensions/browser/extension_pref_store.h"
|
|
|
|
#include "extensions/browser/extension_pref_value_map_factory.h"
|
|
|
|
#include "extensions/browser/extension_prefs.h"
|
|
|
|
#include "extensions/browser/pref_names.h"
|
|
|
|
#include "extensions/common/extension_api.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/browser/extensions/electron_browser_context_keyed_service_factories.h"
|
|
|
|
#include "shell/browser/extensions/electron_extension_system.h"
|
|
|
|
#include "shell/browser/extensions/electron_extension_system_factory.h"
|
|
|
|
#include "shell/browser/extensions/electron_extensions_browser_client.h"
|
|
|
|
#include "shell/common/extensions/electron_extensions_client.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) || \
|
|
|
|
BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
#include "components/pref_registry/pref_registry_syncable.h"
|
|
|
|
#include "components/user_prefs/user_prefs.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
#include "base/i18n/rtl.h"
|
|
|
|
#include "components/language/core/browser/language_prefs.h"
|
|
|
|
#include "components/spellcheck/browser/pref_names.h"
|
|
|
|
#include "components/spellcheck/common/spellcheck_common.h"
|
|
|
|
#endif
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
using content::BrowserThread;
|
2013-09-20 08:47:47 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-09-20 08:47:47 +00:00
|
|
|
|
2014-09-23 04:13:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
// Convert string to lower case and escape it.
|
|
|
|
std::string MakePartitionName(const std::string& input) {
|
|
|
|
return net::EscapePath(base::ToLowerASCII(input));
|
|
|
|
}
|
|
|
|
|
2014-09-23 04:13:46 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
// static
|
2020-08-17 20:21:53 +00:00
|
|
|
ElectronBrowserContext::BrowserContextMap&
|
|
|
|
ElectronBrowserContext::browser_context_map() {
|
|
|
|
static base::NoDestructor<ElectronBrowserContext::BrowserContextMap>
|
|
|
|
browser_context_map;
|
|
|
|
return *browser_context_map;
|
|
|
|
}
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::ElectronBrowserContext(const std::string& partition,
|
|
|
|
bool in_memory,
|
|
|
|
base::DictionaryValue options)
|
2021-01-26 18:16:21 +00:00
|
|
|
: storage_policy_(new SpecialStoragePolicy),
|
2020-03-26 17:34:32 +00:00
|
|
|
protocol_registry_(new ProtocolRegistry),
|
2018-10-04 18:08:56 +00:00
|
|
|
in_memory_(in_memory),
|
2021-02-09 20:16:21 +00:00
|
|
|
ssl_config_(network::mojom::SSLConfig::New()),
|
|
|
|
shared_cors_origin_access_list_(
|
|
|
|
content::SharedCorsOriginAccessList::Create()) {
|
2020-02-04 20:19:40 +00:00
|
|
|
user_agent_ = ElectronBrowserClient::Get()->GetUserAgent();
|
2016-07-12 13:05:07 +00:00
|
|
|
|
|
|
|
// Read options.
|
2018-08-14 21:07:53 +00:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
2018-10-04 18:08:56 +00:00
|
|
|
use_cache_ = !command_line->HasSwitch(switches::kDisableHttpCache);
|
|
|
|
options.GetBoolean("cache", &use_cache_);
|
|
|
|
|
|
|
|
base::StringToInt(command_line->GetSwitchValueASCII(switches::kDiskCacheSize),
|
|
|
|
&max_cache_size_);
|
|
|
|
|
2018-10-24 10:49:10 +00:00
|
|
|
if (!base::PathService::Get(DIR_USER_DATA, &path_)) {
|
|
|
|
base::PathService::Get(DIR_APP_DATA, &path_);
|
|
|
|
path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
|
|
|
base::PathService::Override(DIR_USER_DATA, path_);
|
2019-10-31 20:11:51 +00:00
|
|
|
base::PathService::Override(chrome::DIR_USER_DATA, path_);
|
2020-02-28 23:37:53 +00:00
|
|
|
base::PathService::Override(
|
|
|
|
chrome::DIR_APP_DICTIONARIES,
|
|
|
|
path_.Append(base::FilePath::FromUTF8Unsafe("Dictionaries")));
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
2018-08-14 21:07:53 +00:00
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
if (!in_memory && !partition.empty())
|
|
|
|
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
|
|
|
.Append(base::FilePath::FromUTF8Unsafe(
|
|
|
|
MakePartitionName(partition)));
|
2016-07-26 11:04:04 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(this);
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
// Initialize Pref Registry.
|
2016-07-26 11:04:04 +00:00
|
|
|
InitPrefs();
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
cookie_change_notifier_ = std::make_unique<CookieChangeNotifier>(this);
|
2018-10-11 13:52:12 +00:00
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-05-08 18:17:28 +00:00
|
|
|
if (!in_memory_) {
|
|
|
|
BrowserContextDependencyManager::GetInstance()
|
|
|
|
->CreateBrowserContextServices(this);
|
|
|
|
|
|
|
|
extension_system_ = static_cast<extensions::ElectronExtensionSystem*>(
|
|
|
|
extensions::ExtensionSystem::Get(this));
|
|
|
|
extension_system_->InitForRegularProfile(true /* extensions_enabled */);
|
|
|
|
extension_system_->FinishInitialization();
|
|
|
|
}
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
2016-06-22 06:46:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::~ElectronBrowserContext() {
|
2018-10-04 18:08:56 +00:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
NotifyWillBeDestroyed(this);
|
2020-01-13 22:55:58 +00:00
|
|
|
// Notify any keyed services of browser context destruction.
|
|
|
|
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
|
|
|
|
this);
|
2018-10-04 18:08:56 +00:00
|
|
|
ShutdownStoragePartitions();
|
2019-03-26 01:10:48 +00:00
|
|
|
|
2019-08-02 23:56:46 +00:00
|
|
|
BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
|
|
|
|
std::move(resource_context_));
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserContext::InitPrefs() {
|
2018-10-04 18:08:56 +00:00
|
|
|
auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences"));
|
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
|
|
|
PrefServiceFactory prefs_factory;
|
|
|
|
scoped_refptr<JsonPrefStore> pref_store =
|
|
|
|
base::MakeRefCounted<JsonPrefStore>(prefs_path);
|
|
|
|
pref_store->ReadPrefs(); // Synchronous.
|
|
|
|
prefs_factory.set_user_prefs(pref_store);
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-05-08 18:17:28 +00:00
|
|
|
if (!in_memory_) {
|
|
|
|
auto* ext_pref_store = new ExtensionPrefStore(
|
|
|
|
ExtensionPrefValueMapFactory::GetForBrowserContext(this),
|
|
|
|
IsOffTheRecord());
|
|
|
|
prefs_factory.set_extension_prefs(ext_pref_store);
|
|
|
|
}
|
2019-10-31 20:11:51 +00:00
|
|
|
#endif
|
2019-07-24 23:01:08 +00:00
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) || \
|
|
|
|
BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2019-07-24 23:01:08 +00:00
|
|
|
auto registry = WrapRefCounted(new user_prefs::PrefRegistrySyncable);
|
|
|
|
#else
|
2018-10-04 18:08:56 +00:00
|
|
|
auto registry = WrapRefCounted(new PrefRegistrySimple);
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory,
|
|
|
|
base::FilePath());
|
|
|
|
base::FilePath download_dir;
|
|
|
|
base::PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &download_dir);
|
|
|
|
registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
|
|
|
|
download_dir);
|
|
|
|
registry->RegisterDictionaryPref(prefs::kDevToolsFileSystemPaths);
|
2020-07-15 18:27:42 +00:00
|
|
|
InspectableWebContents::RegisterPrefs(registry.get());
|
2018-10-19 18:51:43 +00:00
|
|
|
MediaDeviceIDSalt::RegisterPrefs(registry.get());
|
|
|
|
ZoomLevelDelegate::RegisterPrefs(registry.get());
|
2018-10-04 18:08:56 +00:00
|
|
|
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
|
2019-07-24 23:01:08 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-05-08 18:17:28 +00:00
|
|
|
if (!in_memory_)
|
|
|
|
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
|
2019-07-24 23:01:08 +00:00
|
|
|
#endif
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
BrowserContextDependencyManager::GetInstance()
|
|
|
|
->RegisterProfilePrefsForServices(registry.get());
|
|
|
|
|
|
|
|
language::LanguagePrefs::RegisterProfilePrefs(registry.get());
|
|
|
|
#endif
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
prefs_ = prefs_factory.Create(
|
|
|
|
registry.get(),
|
|
|
|
std::make_unique<PrefStoreDelegate>(weak_factory_.GetWeakPtr()));
|
|
|
|
prefs_->UpdateCommandLinePrefStore(new ValueMapPrefStore);
|
2019-10-31 20:11:51 +00:00
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) || \
|
|
|
|
BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
2019-07-24 23:01:08 +00:00
|
|
|
user_prefs::UserPrefs::Set(this, prefs_.get());
|
|
|
|
#endif
|
2019-10-31 20:11:51 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
|
|
|
auto* current_dictionaries =
|
|
|
|
prefs()->Get(spellcheck::prefs::kSpellCheckDictionaries);
|
|
|
|
// No configured dictionaries, the default will be en-US
|
2020-10-22 20:24:59 +00:00
|
|
|
if (current_dictionaries->GetList().empty()) {
|
2019-10-31 20:11:51 +00:00
|
|
|
std::string default_code = spellcheck::GetCorrespondingSpellCheckLanguage(
|
|
|
|
base::i18n::GetConfiguredLocale());
|
|
|
|
if (!default_code.empty()) {
|
|
|
|
base::ListValue language_codes;
|
|
|
|
language_codes.AppendString(default_code);
|
|
|
|
prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries, language_codes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2018-08-14 21:07:53 +00:00
|
|
|
}
|
2016-06-22 06:46:46 +00:00
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserContext::SetUserAgent(const std::string& user_agent) {
|
2016-06-22 06:57:51 +00:00
|
|
|
user_agent_ = user_agent;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
base::FilePath ElectronBrowserContext::GetPath() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return path_;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserContext::IsOffTheRecord() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return in_memory_;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronBrowserContext::CanUseHttpCache() const {
|
2018-10-04 18:08:56 +00:00
|
|
|
return use_cache_;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
int ElectronBrowserContext::GetMaxCacheSize() const {
|
2018-10-04 18:08:56 +00:00
|
|
|
return max_cache_size_;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::ResourceContext* ElectronBrowserContext::GetResourceContext() {
|
2019-08-02 23:56:46 +00:00
|
|
|
if (!resource_context_)
|
2019-09-16 22:12:00 +00:00
|
|
|
resource_context_ = std::make_unique<content::ResourceContext>();
|
2019-08-02 23:56:46 +00:00
|
|
|
return resource_context_.get();
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserContext::GetMediaDeviceIDSalt() {
|
2018-10-04 18:08:56 +00:00
|
|
|
if (!media_device_id_salt_.get())
|
2019-09-16 22:12:00 +00:00
|
|
|
media_device_id_salt_ = std::make_unique<MediaDeviceIDSalt>(prefs_.get());
|
2018-10-04 18:08:56 +00:00
|
|
|
return media_device_id_salt_->GetSalt();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<content::ZoomLevelDelegate>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::CreateZoomLevelDelegate(
|
2018-10-04 18:08:56 +00:00
|
|
|
const base::FilePath& partition_path) {
|
|
|
|
if (!IsOffTheRecord()) {
|
2018-10-19 18:51:43 +00:00
|
|
|
return std::make_unique<ZoomLevelDelegate>(prefs(), partition_path);
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
return std::unique_ptr<content::ZoomLevelDelegate>();
|
|
|
|
}
|
|
|
|
|
2015-06-22 11:43:49 +00:00
|
|
|
content::DownloadManagerDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetDownloadManagerDelegate() {
|
2015-06-22 11:43:49 +00:00
|
|
|
if (!download_manager_delegate_.get()) {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* download_manager = content::BrowserContext::GetDownloadManager(this);
|
2019-09-16 22:12:00 +00:00
|
|
|
download_manager_delegate_ =
|
2020-02-04 20:19:40 +00:00
|
|
|
std::make_unique<ElectronDownloadManagerDelegate>(download_manager);
|
2015-06-22 11:43:49 +00:00
|
|
|
}
|
|
|
|
return download_manager_delegate_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::BrowserPluginGuestManager* ElectronBrowserContext::GetGuestManager() {
|
2014-10-22 14:55:13 +00:00
|
|
|
if (!guest_manager_)
|
2019-09-16 22:12:00 +00:00
|
|
|
guest_manager_ = std::make_unique<WebViewManager>();
|
2014-10-22 14:55:13 +00:00
|
|
|
return guest_manager_.get();
|
|
|
|
}
|
|
|
|
|
2018-10-02 21:53:10 +00:00
|
|
|
content::PermissionControllerDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetPermissionControllerDelegate() {
|
2016-01-31 19:13:29 +00:00
|
|
|
if (!permission_manager_.get())
|
2020-02-04 20:19:40 +00:00
|
|
|
permission_manager_ = std::make_unique<ElectronPermissionManager>();
|
2016-01-30 11:19:18 +00:00
|
|
|
return permission_manager_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
storage::SpecialStoragePolicy*
|
|
|
|
ElectronBrowserContext::GetSpecialStoragePolicy() {
|
2018-08-21 15:51:04 +00:00
|
|
|
return storage_policy_.get();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
std::string ElectronBrowserContext::GetUserAgent() const {
|
2018-08-14 21:07:53 +00:00
|
|
|
return user_agent_;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
predictors::PreconnectManager* ElectronBrowserContext::GetPreconnectManager() {
|
2019-08-26 16:47:32 +00:00
|
|
|
if (!preconnect_manager_.get()) {
|
2019-09-16 22:12:00 +00:00
|
|
|
preconnect_manager_ =
|
|
|
|
std::make_unique<predictors::PreconnectManager>(nullptr, this);
|
2019-08-26 16:47:32 +00:00
|
|
|
}
|
|
|
|
return preconnect_manager_.get();
|
|
|
|
}
|
|
|
|
|
2019-08-29 06:07:46 +00:00
|
|
|
scoped_refptr<network::SharedURLLoaderFactory>
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetURLLoaderFactory() {
|
2019-08-29 06:07:46 +00:00
|
|
|
if (url_loader_factory_)
|
|
|
|
return url_loader_factory_;
|
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
mojo::PendingRemote<network::mojom::URLLoaderFactory> network_factory_remote;
|
|
|
|
mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver =
|
|
|
|
network_factory_remote.InitWithNewPipeAndPassReceiver();
|
2019-08-29 06:07:46 +00:00
|
|
|
|
|
|
|
// Consult the embedder.
|
2019-09-18 19:58:00 +00:00
|
|
|
mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>
|
|
|
|
header_client;
|
2020-02-04 20:19:40 +00:00
|
|
|
static_cast<content::ContentBrowserClient*>(ElectronBrowserClient::Get())
|
2019-08-29 06:07:46 +00:00
|
|
|
->WillCreateURLLoaderFactory(
|
|
|
|
this, nullptr, -1,
|
|
|
|
content::ContentBrowserClient::URLLoaderFactoryType::kNavigation,
|
2020-10-28 00:33:04 +00:00
|
|
|
url::Origin(), base::nullopt, ukm::kInvalidSourceIdObj,
|
2020-10-16 01:30:41 +00:00
|
|
|
&factory_receiver, &header_client, nullptr, nullptr, nullptr);
|
2019-08-29 06:07:46 +00:00
|
|
|
|
|
|
|
network::mojom::URLLoaderFactoryParamsPtr params =
|
|
|
|
network::mojom::URLLoaderFactoryParams::New();
|
|
|
|
params->header_client = std::move(header_client);
|
2019-11-14 18:01:18 +00:00
|
|
|
params->auth_client = auth_client_.BindNewPipeAndPassRemote();
|
2019-08-29 06:07:46 +00:00
|
|
|
params->process_id = network::mojom::kBrowserProcessId;
|
|
|
|
params->is_trusted = true;
|
|
|
|
params->is_corb_enabled = false;
|
|
|
|
// The tests of net module would fail if this setting is true, it seems that
|
|
|
|
// the non-NetworkService implementation always has web security enabled.
|
|
|
|
params->disable_web_security = false;
|
|
|
|
|
|
|
|
auto* storage_partition =
|
|
|
|
content::BrowserContext::GetDefaultStoragePartition(this);
|
2021-03-04 17:27:05 +00:00
|
|
|
params->auth_cert_observer =
|
|
|
|
storage_partition->CreateAuthAndCertObserverForNavigationRequest(-1);
|
2019-08-29 06:07:46 +00:00
|
|
|
storage_partition->GetNetworkContext()->CreateURLLoaderFactory(
|
2019-10-28 22:12:35 +00:00
|
|
|
std::move(factory_receiver), std::move(params));
|
2019-08-29 06:07:46 +00:00
|
|
|
url_loader_factory_ =
|
|
|
|
base::MakeRefCounted<network::WrapperSharedURLLoaderFactory>(
|
2019-10-28 22:12:35 +00:00
|
|
|
std::move(network_factory_remote));
|
2019-08-29 06:07:46 +00:00
|
|
|
return url_loader_factory_;
|
2019-11-14 18:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class AuthResponder : public network::mojom::TrustedAuthClient {
|
|
|
|
public:
|
|
|
|
AuthResponder() {}
|
|
|
|
~AuthResponder() override = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnAuthRequired(
|
|
|
|
const base::Optional<::base::UnguessableToken>& window_id,
|
|
|
|
uint32_t process_id,
|
|
|
|
uint32_t routing_id,
|
|
|
|
uint32_t request_id,
|
|
|
|
const ::GURL& url,
|
|
|
|
bool first_auth_attempt,
|
|
|
|
const ::net::AuthChallengeInfo& auth_info,
|
|
|
|
::network::mojom::URLResponseHeadPtr head,
|
|
|
|
mojo::PendingRemote<network::mojom::AuthChallengeResponder>
|
|
|
|
auth_challenge_responder) override {
|
2019-11-27 01:01:13 +00:00
|
|
|
api::SimpleURLLoaderWrapper* url_loader =
|
|
|
|
api::SimpleURLLoaderWrapper::FromID(routing_id);
|
|
|
|
if (url_loader) {
|
|
|
|
url_loader->OnAuthRequired(url, first_auth_attempt, auth_info,
|
|
|
|
std::move(head),
|
|
|
|
std::move(auth_challenge_responder));
|
2019-11-14 18:01:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronBrowserContext::OnLoaderCreated(
|
2019-11-14 18:01:18 +00:00
|
|
|
int32_t request_id,
|
|
|
|
mojo::PendingReceiver<network::mojom::TrustedAuthClient> auth_client) {
|
|
|
|
mojo::MakeSelfOwnedReceiver(std::make_unique<AuthResponder>(),
|
|
|
|
std::move(auth_client));
|
2019-08-29 06:07:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::PushMessagingService*
|
|
|
|
ElectronBrowserContext::GetPushMessagingService() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
content::SSLHostStateDelegate*
|
|
|
|
ElectronBrowserContext::GetSSLHostStateDelegate() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BackgroundFetchDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetBackgroundFetchDelegate() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BackgroundSyncController*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetBackgroundSyncController() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BrowsingDataRemoverDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetBrowsingDataRemoverDelegate() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-22 19:50:25 +00:00
|
|
|
content::ClientHintsControllerDelegate*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetClientHintsControllerDelegate() {
|
2019-01-22 19:50:25 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
content::StorageNotificationService*
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronBrowserContext::GetStorageNotificationService() {
|
2019-10-28 22:12:35 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ResolveProxyHelper* ElectronBrowserContext::GetResolveProxyHelper() {
|
2018-10-04 18:08:56 +00:00
|
|
|
if (!resolve_proxy_helper_) {
|
|
|
|
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(this);
|
|
|
|
}
|
|
|
|
return resolve_proxy_helper_.get();
|
|
|
|
}
|
|
|
|
|
2020-09-23 20:22:10 +00:00
|
|
|
network::mojom::SSLConfigPtr ElectronBrowserContext::GetSSLConfig() {
|
|
|
|
return ssl_config_.Clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronBrowserContext::SetSSLConfig(network::mojom::SSLConfigPtr config) {
|
|
|
|
ssl_config_ = std::move(config);
|
|
|
|
if (ssl_config_client_) {
|
|
|
|
ssl_config_client_->OnSSLConfigUpdated(ssl_config_.Clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElectronBrowserContext::SetSSLConfigClient(
|
|
|
|
mojo::Remote<network::mojom::SSLConfigClient> client) {
|
|
|
|
ssl_config_client_ = std::move(client);
|
|
|
|
}
|
|
|
|
|
2015-09-05 12:54:36 +00:00
|
|
|
// static
|
2020-08-17 20:21:53 +00:00
|
|
|
ElectronBrowserContext* ElectronBrowserContext::From(
|
2018-04-18 01:55:30 +00:00
|
|
|
const std::string& partition,
|
|
|
|
bool in_memory,
|
2019-10-30 05:30:59 +00:00
|
|
|
base::DictionaryValue options) {
|
2018-10-04 18:08:56 +00:00
|
|
|
PartitionKey key(partition, in_memory);
|
2020-08-17 20:21:53 +00:00
|
|
|
ElectronBrowserContext* browser_context = browser_context_map()[key].get();
|
|
|
|
if (browser_context) {
|
|
|
|
return browser_context;
|
|
|
|
}
|
2016-07-12 12:39:54 +00:00
|
|
|
|
2019-10-30 05:30:59 +00:00
|
|
|
auto* new_context =
|
2020-02-04 20:19:40 +00:00
|
|
|
new ElectronBrowserContext(partition, in_memory, std::move(options));
|
2020-08-17 20:21:53 +00:00
|
|
|
browser_context_map()[key] =
|
|
|
|
std::unique_ptr<ElectronBrowserContext>(new_context);
|
|
|
|
return new_context;
|
2015-09-05 12:54:36 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|