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.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/atom_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>
|
|
|
|
|
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"
|
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"
|
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"
|
2019-11-14 18:01:18 +00:00
|
|
|
#include "shell/browser/api/atom_api_url_request.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/atom_browser_client.h"
|
|
|
|
#include "shell/browser/atom_browser_main_parts.h"
|
|
|
|
#include "shell/browser/atom_download_manager_delegate.h"
|
|
|
|
#include "shell/browser/atom_paths.h"
|
|
|
|
#include "shell/browser/atom_permission_manager.h"
|
|
|
|
#include "shell/browser/cookie_change_notifier.h"
|
|
|
|
#include "shell/browser/net/resolve_proxy_helper.h"
|
|
|
|
#include "shell/browser/pref_store_delegate.h"
|
|
|
|
#include "shell/browser/special_storage_policy.h"
|
|
|
|
#include "shell/browser/ui/inspectable_web_contents_impl.h"
|
|
|
|
#include "shell/browser/web_view_manager.h"
|
|
|
|
#include "shell/browser/zoom_level_delegate.h"
|
|
|
|
#include "shell/common/application_info.h"
|
|
|
|
#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"
|
|
|
|
#include "shell/browser/extensions/atom_browser_context_keyed_service_factories.h"
|
|
|
|
#include "shell/browser/extensions/atom_extension_system.h"
|
|
|
|
#include "shell/browser/extensions/atom_extension_system_factory.h"
|
|
|
|
#include "shell/browser/extensions/atom_extensions_browser_client.h"
|
|
|
|
#include "shell/common/extensions/atom_extensions_client.h"
|
|
|
|
#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
|
|
|
|
AtomBrowserContext::BrowserContextMap AtomBrowserContext::browser_context_map_;
|
|
|
|
|
2016-10-17 10:33:24 +00:00
|
|
|
AtomBrowserContext::AtomBrowserContext(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
|
|
|
: base::RefCountedDeleteOnSequence<AtomBrowserContext>(
|
2018-10-08 21:29:58 +00:00
|
|
|
base::ThreadTaskRunnerHandle::Get()),
|
2018-10-04 18:08:56 +00:00
|
|
|
in_memory_pref_store_(nullptr),
|
|
|
|
storage_policy_(new SpecialStoragePolicy),
|
|
|
|
in_memory_(in_memory),
|
|
|
|
weak_factory_(this) {
|
2019-05-01 23:34:42 +00:00
|
|
|
user_agent_ = AtomBrowserClient::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_);
|
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
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
content::BrowserContext::Initialize(this, path_);
|
|
|
|
|
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)
|
|
|
|
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
|
|
|
|
this);
|
|
|
|
|
|
|
|
extension_system_ = static_cast<extensions::AtomExtensionSystem*>(
|
|
|
|
extensions::ExtensionSystem::Get(this));
|
|
|
|
extension_system_->InitForRegularProfile(true /* extensions_enabled */);
|
|
|
|
extension_system_->FinishInitialization();
|
|
|
|
#endif
|
2016-06-22 06:46:46 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 21:07:53 +00:00
|
|
|
AtomBrowserContext::~AtomBrowserContext() {
|
2018-10-04 18:08:56 +00:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
NotifyWillBeDestroyed(this);
|
|
|
|
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_));
|
2019-03-26 01:10:48 +00:00
|
|
|
|
2018-10-11 13:52:12 +00:00
|
|
|
// Notify any keyed services of browser context destruction.
|
|
|
|
BrowserContextDependencyManager::GetInstance()->DestroyBrowserContextServices(
|
|
|
|
this);
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AtomBrowserContext::InitPrefs() {
|
|
|
|
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)
|
|
|
|
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);
|
2018-10-19 13:50:30 +00:00
|
|
|
InspectableWebContentsImpl::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)
|
|
|
|
extensions::ExtensionPrefs::RegisterProfilePrefs(registry.get());
|
|
|
|
#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
|
|
|
|
if (current_dictionaries->GetList().size() == 0) {
|
|
|
|
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
|
|
|
|
2016-06-22 06:57:51 +00:00
|
|
|
void AtomBrowserContext::SetUserAgent(const std::string& user_agent) {
|
|
|
|
user_agent_ = user_agent;
|
|
|
|
}
|
|
|
|
|
2019-07-03 01:22:09 +00:00
|
|
|
base::FilePath AtomBrowserContext::GetPath() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return path_;
|
|
|
|
}
|
|
|
|
|
2019-07-03 01:22:09 +00:00
|
|
|
bool AtomBrowserContext::IsOffTheRecord() {
|
2018-10-04 18:08:56 +00:00
|
|
|
return in_memory_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtomBrowserContext::CanUseHttpCache() const {
|
|
|
|
return use_cache_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AtomBrowserContext::GetMaxCacheSize() const {
|
|
|
|
return max_cache_size_;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::ResourceContext* AtomBrowserContext::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
|
|
|
}
|
|
|
|
|
|
|
|
std::string AtomBrowserContext::GetMediaDeviceIDSalt() {
|
|
|
|
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>
|
|
|
|
AtomBrowserContext::CreateZoomLevelDelegate(
|
|
|
|
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*
|
|
|
|
AtomBrowserContext::GetDownloadManagerDelegate() {
|
|
|
|
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_ =
|
|
|
|
std::make_unique<AtomDownloadManagerDelegate>(download_manager);
|
2015-06-22 11:43:49 +00:00
|
|
|
}
|
|
|
|
return download_manager_delegate_.get();
|
|
|
|
}
|
|
|
|
|
2014-10-22 14:55:13 +00:00
|
|
|
content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() {
|
|
|
|
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*
|
|
|
|
AtomBrowserContext::GetPermissionControllerDelegate() {
|
2016-01-31 19:13:29 +00:00
|
|
|
if (!permission_manager_.get())
|
2019-09-16 22:12:00 +00:00
|
|
|
permission_manager_ = std::make_unique<AtomPermissionManager>();
|
2016-01-30 11:19:18 +00:00
|
|
|
return permission_manager_.get();
|
|
|
|
}
|
|
|
|
|
2018-08-21 15:51:04 +00:00
|
|
|
storage::SpecialStoragePolicy* AtomBrowserContext::GetSpecialStoragePolicy() {
|
|
|
|
return storage_policy_.get();
|
|
|
|
}
|
|
|
|
|
2018-08-14 21:07:53 +00:00
|
|
|
std::string AtomBrowserContext::GetUserAgent() const {
|
|
|
|
return user_agent_;
|
|
|
|
}
|
|
|
|
|
2019-08-26 16:47:32 +00:00
|
|
|
predictors::PreconnectManager* AtomBrowserContext::GetPreconnectManager() {
|
|
|
|
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>
|
|
|
|
AtomBrowserContext::GetURLLoaderFactory() {
|
|
|
|
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;
|
2019-08-29 06:07:46 +00:00
|
|
|
static_cast<content::ContentBrowserClient*>(AtomBrowserClient::Get())
|
|
|
|
->WillCreateURLLoaderFactory(
|
|
|
|
this, nullptr, -1,
|
|
|
|
content::ContentBrowserClient::URLLoaderFactoryType::kNavigation,
|
2019-10-28 22:12:35 +00:00
|
|
|
url::Origin(), &factory_receiver, &header_client, 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);
|
|
|
|
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 {
|
|
|
|
api::URLRequest* url_request = api::URLRequest::FromID(routing_id);
|
|
|
|
if (url_request) {
|
|
|
|
url_request->OnAuthRequired(url, first_auth_attempt, auth_info,
|
|
|
|
std::move(head),
|
|
|
|
std::move(auth_challenge_responder));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void AtomBrowserContext::OnLoaderCreated(
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
content::PushMessagingService* AtomBrowserContext::GetPushMessagingService() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::SSLHostStateDelegate* AtomBrowserContext::GetSSLHostStateDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BackgroundFetchDelegate*
|
|
|
|
AtomBrowserContext::GetBackgroundFetchDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BackgroundSyncController*
|
|
|
|
AtomBrowserContext::GetBackgroundSyncController() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
content::BrowsingDataRemoverDelegate*
|
|
|
|
AtomBrowserContext::GetBrowsingDataRemoverDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-22 19:50:25 +00:00
|
|
|
content::ClientHintsControllerDelegate*
|
|
|
|
AtomBrowserContext::GetClientHintsControllerDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
content::StorageNotificationService*
|
|
|
|
AtomBrowserContext::GetStorageNotificationService() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
void AtomBrowserContext::SetCorsOriginAccessListForOrigin(
|
|
|
|
const url::Origin& source_origin,
|
|
|
|
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
|
|
|
|
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
|
|
|
|
base::OnceClosure closure) {
|
|
|
|
// TODO(nornagon): actually set the CORS access lists. This is called from
|
|
|
|
// extensions/browser/renderer_startup_helper.cc.
|
|
|
|
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(closure));
|
|
|
|
}
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
ResolveProxyHelper* AtomBrowserContext::GetResolveProxyHelper() {
|
|
|
|
if (!resolve_proxy_helper_) {
|
|
|
|
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(this);
|
|
|
|
}
|
|
|
|
return resolve_proxy_helper_.get();
|
|
|
|
}
|
|
|
|
|
2015-09-05 12:54:36 +00:00
|
|
|
// static
|
2016-07-12 12:39:54 +00:00
|
|
|
scoped_refptr<AtomBrowserContext> AtomBrowserContext::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);
|
|
|
|
auto* browser_context = browser_context_map_[key].get();
|
2016-07-12 12:39:54 +00:00
|
|
|
if (browser_context)
|
2018-10-04 18:08:56 +00:00
|
|
|
return scoped_refptr<AtomBrowserContext>(browser_context);
|
2016-07-12 12:39:54 +00:00
|
|
|
|
2019-10-30 05:30:59 +00:00
|
|
|
auto* new_context =
|
|
|
|
new AtomBrowserContext(partition, in_memory, std::move(options));
|
2018-10-04 18:08:56 +00:00
|
|
|
browser_context_map_[key] = new_context->GetWeakPtr();
|
|
|
|
return scoped_refptr<AtomBrowserContext>(new_context);
|
2015-09-05 12:54:36 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|