fix: switch to mojo proxy resolver (3-1-x) (#15813)
This commit is contained in:
parent
d5a6bb665b
commit
4abf55801f
65 changed files with 1838 additions and 1797 deletions
|
@ -4,12 +4,16 @@
|
|||
|
||||
#include "atom/browser/atom_browser_context.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "atom/browser/atom_blob_reader.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/atom_download_manager_delegate.h"
|
||||
#include "atom/browser/atom_permission_manager.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/request_context_delegate.h"
|
||||
#include "atom/browser/cookie_change_notifier.h"
|
||||
#include "atom/browser/net/resolve_proxy_helper.h"
|
||||
#include "atom/browser/pref_store_delegate.h"
|
||||
#include "atom/browser/web_view_manager.h"
|
||||
#include "atom/common/atom_version.h"
|
||||
#include "atom/common/chrome_version.h"
|
||||
|
@ -17,12 +21,31 @@
|
|||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/threading/sequenced_task_runner_handle.h"
|
||||
#include "base/threading/thread_restrictions.h"
|
||||
#include "brightray/browser/brightray_paths.h"
|
||||
#include "brightray/browser/inspectable_web_contents_impl.h"
|
||||
#include "brightray/browser/special_storage_policy.h"
|
||||
#include "brightray/browser/zoom_level_delegate.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
#include "chrome/common/chrome_paths.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
#include "components/prefs/json_pref_store.h"
|
||||
#include "components/prefs/pref_registry_simple.h"
|
||||
#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"
|
||||
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "content/public/common/user_agent.h"
|
||||
#include "net/base/escape.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -36,13 +59,25 @@ std::string RemoveWhitespace(const std::string& str) {
|
|||
return str;
|
||||
}
|
||||
|
||||
// Convert string to lower case and escape it.
|
||||
std::string MakePartitionName(const std::string& input) {
|
||||
return net::EscapePath(base::ToLowerASCII(input));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
AtomBrowserContext::BrowserContextMap AtomBrowserContext::browser_context_map_;
|
||||
|
||||
AtomBrowserContext::AtomBrowserContext(const std::string& partition,
|
||||
bool in_memory,
|
||||
const base::DictionaryValue& options)
|
||||
: brightray::BrowserContext(partition, in_memory),
|
||||
url_request_context_getter_(nullptr) {
|
||||
: base::RefCountedDeleteOnSequence<AtomBrowserContext>(
|
||||
base::SequencedTaskRunnerHandle::Get()),
|
||||
in_memory_pref_store_(nullptr),
|
||||
storage_policy_(new brightray::SpecialStoragePolicy),
|
||||
in_memory_(in_memory),
|
||||
weak_factory_(this) {
|
||||
// Construct user agent string.
|
||||
Browser* browser = Browser::Get();
|
||||
std::string name = RemoveWhitespace(browser->GetName());
|
||||
|
@ -59,23 +94,131 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition,
|
|||
|
||||
// Read options.
|
||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
bool use_cache = !command_line->HasSwitch(switches::kDisableHttpCache);
|
||||
options.GetBoolean("cache", &use_cache);
|
||||
use_cache_ = !command_line->HasSwitch(switches::kDisableHttpCache);
|
||||
options.GetBoolean("cache", &use_cache_);
|
||||
|
||||
request_context_delegate_.reset(new RequestContextDelegate(use_cache));
|
||||
base::StringToInt(command_line->GetSwitchValueASCII(switches::kDiskCacheSize),
|
||||
&max_cache_size_);
|
||||
|
||||
// Initialize Pref Registry in brightray.
|
||||
if (!base::PathService::Get(brightray::DIR_USER_DATA, &path_)) {
|
||||
base::PathService::Get(brightray::DIR_APP_DATA, &path_);
|
||||
path_ = path_.Append(
|
||||
base::FilePath::FromUTF8Unsafe(brightray::GetApplicationName()));
|
||||
base::PathService::Override(brightray::DIR_USER_DATA, path_);
|
||||
}
|
||||
|
||||
if (!in_memory && !partition.empty())
|
||||
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
||||
.Append(base::FilePath::FromUTF8Unsafe(
|
||||
MakePartitionName(partition)));
|
||||
|
||||
content::BrowserContext::Initialize(this, path_);
|
||||
|
||||
// Initialize Pref Registry.
|
||||
InitPrefs();
|
||||
|
||||
proxy_config_monitor_ = std::make_unique<ProxyConfigMonitor>(prefs_.get());
|
||||
io_handle_ = new URLRequestContextGetter::Handle(weak_factory_.GetWeakPtr());
|
||||
cookie_change_notifier_ = std::make_unique<CookieChangeNotifier>(this);
|
||||
}
|
||||
|
||||
AtomBrowserContext::~AtomBrowserContext() {
|
||||
url_request_context_getter_->set_delegate(nullptr);
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
NotifyWillBeDestroyed(this);
|
||||
ShutdownStoragePartitions();
|
||||
io_handle_->ShutdownOnUIThread();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
auto registry = WrapRefCounted(new PrefRegistrySimple);
|
||||
|
||||
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);
|
||||
brightray::InspectableWebContentsImpl::RegisterPrefs(registry.get());
|
||||
brightray::MediaDeviceIDSalt::RegisterPrefs(registry.get());
|
||||
brightray::ZoomLevelDelegate::RegisterPrefs(registry.get());
|
||||
PrefProxyConfigTrackerImpl::RegisterPrefs(registry.get());
|
||||
|
||||
prefs_ = prefs_factory.Create(
|
||||
registry.get(),
|
||||
std::make_unique<PrefStoreDelegate>(weak_factory_.GetWeakPtr()));
|
||||
prefs_->UpdateCommandLinePrefStore(new ValueMapPrefStore);
|
||||
}
|
||||
|
||||
void AtomBrowserContext::SetUserAgent(const std::string& user_agent) {
|
||||
user_agent_ = user_agent;
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter* AtomBrowserContext::CreateRequestContext(
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
||||
return io_handle_
|
||||
->CreateMainRequestContextGetter(protocol_handlers,
|
||||
std::move(protocol_interceptors))
|
||||
.get();
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter* AtomBrowserContext::CreateMediaRequestContext() {
|
||||
return io_handle_->GetMainRequestContextGetter().get();
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter* AtomBrowserContext::GetRequestContext() {
|
||||
return GetDefaultStoragePartition(this)->GetURLRequestContext();
|
||||
}
|
||||
|
||||
network::mojom::NetworkContextPtr AtomBrowserContext::GetNetworkContext() {
|
||||
return io_handle_->GetNetworkContext();
|
||||
}
|
||||
|
||||
base::FilePath AtomBrowserContext::GetPath() const {
|
||||
return path_;
|
||||
}
|
||||
|
||||
bool AtomBrowserContext::IsOffTheRecord() const {
|
||||
return in_memory_;
|
||||
}
|
||||
|
||||
bool AtomBrowserContext::CanUseHttpCache() const {
|
||||
return use_cache_;
|
||||
}
|
||||
|
||||
int AtomBrowserContext::GetMaxCacheSize() const {
|
||||
return max_cache_size_;
|
||||
}
|
||||
|
||||
content::ResourceContext* AtomBrowserContext::GetResourceContext() {
|
||||
return io_handle_->GetResourceContext();
|
||||
}
|
||||
|
||||
std::string AtomBrowserContext::GetMediaDeviceIDSalt() {
|
||||
if (!media_device_id_salt_.get())
|
||||
media_device_id_salt_.reset(new brightray::MediaDeviceIDSalt(prefs_.get()));
|
||||
return media_device_id_salt_->GetSalt();
|
||||
}
|
||||
|
||||
std::unique_ptr<content::ZoomLevelDelegate>
|
||||
AtomBrowserContext::CreateZoomLevelDelegate(
|
||||
const base::FilePath& partition_path) {
|
||||
if (!IsOffTheRecord()) {
|
||||
return std::make_unique<brightray::ZoomLevelDelegate>(prefs(),
|
||||
partition_path);
|
||||
}
|
||||
return std::unique_ptr<content::ZoomLevelDelegate>();
|
||||
}
|
||||
|
||||
content::DownloadManagerDelegate*
|
||||
AtomBrowserContext::GetDownloadManagerDelegate() {
|
||||
if (!download_manager_delegate_.get()) {
|
||||
|
@ -98,26 +241,14 @@ content::PermissionManager* AtomBrowserContext::GetPermissionManager() {
|
|||
return permission_manager_.get();
|
||||
}
|
||||
|
||||
void AtomBrowserContext::RegisterPrefs(PrefRegistrySimple* pref_registry) {
|
||||
pref_registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory,
|
||||
base::FilePath());
|
||||
base::FilePath download_dir;
|
||||
PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &download_dir);
|
||||
pref_registry->RegisterFilePathPref(prefs::kDownloadDefaultDirectory,
|
||||
download_dir);
|
||||
pref_registry->RegisterDictionaryPref(prefs::kDevToolsFileSystemPaths);
|
||||
storage::SpecialStoragePolicy* AtomBrowserContext::GetSpecialStoragePolicy() {
|
||||
return storage_policy_.get();
|
||||
}
|
||||
|
||||
std::string AtomBrowserContext::GetUserAgent() const {
|
||||
return user_agent_;
|
||||
}
|
||||
|
||||
void AtomBrowserContext::OnMainRequestContextCreated(
|
||||
brightray::URLRequestContextGetter* getter) {
|
||||
getter->set_delegate(request_context_delegate_.get());
|
||||
url_request_context_getter_ = getter;
|
||||
}
|
||||
|
||||
AtomBlobReader* AtomBrowserContext::GetBlobReader() {
|
||||
if (!blob_reader_.get()) {
|
||||
content::ChromeBlobStorageContext* blob_context =
|
||||
|
@ -127,16 +258,67 @@ AtomBlobReader* AtomBrowserContext::GetBlobReader() {
|
|||
return blob_reader_.get();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter*
|
||||
AtomBrowserContext::CreateRequestContextForStoragePartition(
|
||||
const base::FilePath& partition_path,
|
||||
bool in_memory,
|
||||
content::ProtocolHandlerMap* protocol_handlers,
|
||||
content::URLRequestInterceptorScopedVector request_interceptors) {
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter*
|
||||
AtomBrowserContext::CreateMediaRequestContextForStoragePartition(
|
||||
const base::FilePath& partition_path,
|
||||
bool in_memory) {
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ResolveProxyHelper* AtomBrowserContext::GetResolveProxyHelper() {
|
||||
if (!resolve_proxy_helper_) {
|
||||
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(this);
|
||||
}
|
||||
return resolve_proxy_helper_.get();
|
||||
}
|
||||
|
||||
// static
|
||||
scoped_refptr<AtomBrowserContext> AtomBrowserContext::From(
|
||||
const std::string& partition,
|
||||
bool in_memory,
|
||||
const base::DictionaryValue& options) {
|
||||
auto browser_context = brightray::BrowserContext::Get(partition, in_memory);
|
||||
PartitionKey key(partition, in_memory);
|
||||
auto* browser_context = browser_context_map_[key].get();
|
||||
if (browser_context)
|
||||
return static_cast<AtomBrowserContext*>(browser_context.get());
|
||||
return scoped_refptr<AtomBrowserContext>(browser_context);
|
||||
|
||||
return new AtomBrowserContext(partition, in_memory, options);
|
||||
auto* new_context = new AtomBrowserContext(partition, in_memory, options);
|
||||
browser_context_map_[key] = new_context->GetWeakPtr();
|
||||
return scoped_refptr<AtomBrowserContext>(new_context);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue