2013-03-13 19:12:05 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/url_request_context_getter.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2013-11-17 23:11:47 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-08-15 04:30:50 +00:00
|
|
|
#include "base/command_line.h"
|
2016-05-23 01:59:07 +00:00
|
|
|
#include "base/memory/ptr_util.h"
|
2017-04-26 09:16:25 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2017-05-18 22:29:22 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2017-12-18 00:46:57 +00:00
|
|
|
#include "base/task_scheduler/post_task.h"
|
2017-12-16 09:21:29 +00:00
|
|
|
#include "brightray/browser/browser_client.h"
|
2018-08-22 15:24:56 +00:00
|
|
|
#include "brightray/browser/browser_context.h"
|
2017-11-15 13:09:22 +00:00
|
|
|
#include "brightray/browser/net/require_ct_delegate.h"
|
2017-05-18 22:58:12 +00:00
|
|
|
#include "brightray/browser/net_log.h"
|
|
|
|
#include "brightray/common/switches.h"
|
2017-08-23 20:37:19 +00:00
|
|
|
#include "components/network_session_configurator/common/network_switches.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-04-18 03:27:53 +00:00
|
|
|
#include "content/public/browser/cookie_store_factory.h"
|
2017-12-19 18:17:48 +00:00
|
|
|
#include "content/public/browser/devtools_network_transaction_factory.h"
|
2018-08-22 15:24:56 +00:00
|
|
|
#include "content/public/browser/resource_context.h"
|
2014-08-15 04:30:50 +00:00
|
|
|
#include "net/base/host_mapping_rules.h"
|
2013-04-18 03:27:53 +00:00
|
|
|
#include "net/cert/cert_verifier.h"
|
2016-09-21 16:48:17 +00:00
|
|
|
#include "net/cert/ct_known_logs.h"
|
|
|
|
#include "net/cert/ct_log_verifier.h"
|
2016-09-07 08:54:21 +00:00
|
|
|
#include "net/cert/ct_policy_enforcer.h"
|
2016-09-28 18:17:42 +00:00
|
|
|
#include "net/cert/multi_log_ct_verifier.h"
|
2018-04-18 12:14:21 +00:00
|
|
|
#include "net/cookies/cookie_monster.h"
|
2018-04-08 20:08:24 +00:00
|
|
|
#include "net/cookies/cookie_store.h"
|
2014-08-15 04:41:56 +00:00
|
|
|
#include "net/dns/mapped_host_resolver.h"
|
2018-08-28 18:37:09 +00:00
|
|
|
#include "net/extras/sqlite/sqlite_channel_id_store.h"
|
2016-03-10 06:56:13 +00:00
|
|
|
#include "net/http/http_auth_filter.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "net/http/http_auth_handler_factory.h"
|
2016-03-08 11:59:29 +00:00
|
|
|
#include "net/http/http_auth_preferences.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "net/http/http_server_properties_impl.h"
|
2015-06-06 09:03:07 +00:00
|
|
|
#include "net/log/net_log.h"
|
2018-04-04 12:58:09 +00:00
|
|
|
#include "net/proxy_resolution/dhcp_pac_file_fetcher_factory.h"
|
|
|
|
#include "net/proxy_resolution/pac_file_fetcher_impl.h"
|
|
|
|
#include "net/proxy_resolution/proxy_config.h"
|
|
|
|
#include "net/proxy_resolution/proxy_config_service.h"
|
|
|
|
#include "net/proxy_resolution/proxy_service.h"
|
2014-10-11 08:38:27 +00:00
|
|
|
#include "net/ssl/channel_id_service.h"
|
|
|
|
#include "net/ssl/default_channel_id_store.h"
|
2013-03-21 19:09:00 +00:00
|
|
|
#include "net/ssl/ssl_config_service_defaults.h"
|
2013-06-01 16:23:59 +00:00
|
|
|
#include "net/url_request/data_protocol_handler.h"
|
|
|
|
#include "net/url_request/file_protocol_handler.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "net/url_request/static_http_user_agent_settings.h"
|
|
|
|
#include "net/url_request/url_request_context.h"
|
2016-09-28 23:00:23 +00:00
|
|
|
#include "net/url_request/url_request_context_builder.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "net/url_request/url_request_context_storage.h"
|
2014-08-31 10:43:01 +00:00
|
|
|
#include "net/url_request/url_request_intercepting_job_factory.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "net/url_request/url_request_job_factory_impl.h"
|
2018-04-08 17:32:24 +00:00
|
|
|
#include "services/network/public/cpp/network_switches.h"
|
2017-05-18 22:29:22 +00:00
|
|
|
#include "storage/browser/quota/special_storage_policy.h"
|
2014-08-31 10:43:01 +00:00
|
|
|
#include "url/url_constants.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2014-08-13 07:09:26 +00:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
namespace brightray {
|
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
class ResourceContext : public content::ResourceContext {
|
|
|
|
public:
|
|
|
|
ResourceContext() = default;
|
|
|
|
~ResourceContext() override = default;
|
2018-04-17 23:47:47 +00:00
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
net::HostResolver* GetHostResolver() override {
|
|
|
|
if (request_context_)
|
|
|
|
return request_context_->host_resolver();
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-08-20 06:48:02 +00:00
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
net::URLRequestContext* GetRequestContext() override {
|
|
|
|
return request_context_;
|
2016-06-15 11:30:26 +00:00
|
|
|
}
|
2018-08-22 15:24:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class URLRequestContextGetter;
|
|
|
|
|
|
|
|
net::URLRequestContext* request_context_ = nullptr;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ResourceContext);
|
|
|
|
};
|
|
|
|
|
|
|
|
URLRequestContextGetter::Handle::Handle(
|
|
|
|
base::WeakPtr<BrowserContext> browser_context)
|
|
|
|
: resource_context_(new ResourceContext),
|
|
|
|
browser_context_(browser_context),
|
|
|
|
initialized_(false) {}
|
|
|
|
|
|
|
|
URLRequestContextGetter::Handle::~Handle() {}
|
|
|
|
|
|
|
|
content::ResourceContext* URLRequestContextGetter::Handle::GetResourceContext()
|
|
|
|
const {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
LazyInitialize();
|
|
|
|
return resource_context_.get();
|
2014-08-20 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
scoped_refptr<URLRequestContextGetter>
|
|
|
|
URLRequestContextGetter::Handle::CreateMainRequestContextGetter(
|
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
|
|
|
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
DCHECK(!main_request_context_getter_.get());
|
|
|
|
main_request_context_getter_ = new URLRequestContextGetter(
|
|
|
|
BrowserClient::Get()->GetNetLog(), resource_context_.get(),
|
|
|
|
browser_context_->IsOffTheRecord(), browser_context_->GetUserAgent(),
|
|
|
|
browser_context_->GetPath(), protocol_handlers,
|
|
|
|
std::move(protocol_interceptors));
|
|
|
|
browser_context_->OnMainRequestContextCreated(
|
|
|
|
main_request_context_getter_.get());
|
|
|
|
return main_request_context_getter_;
|
2015-01-05 21:29:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
scoped_refptr<URLRequestContextGetter>
|
|
|
|
URLRequestContextGetter::Handle::GetMainRequestContextGetter() const {
|
|
|
|
return main_request_context_getter_;
|
2015-11-05 15:26:46 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
void URLRequestContextGetter::Handle::LazyInitialize() const {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
if (initialized_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
initialized_ = true;
|
|
|
|
content::BrowserContext::EnsureResourceContextInitialized(
|
|
|
|
browser_context_.get());
|
2015-09-21 16:44:32 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
void URLRequestContextGetter::Handle::ShutdownOnUIThread() {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
|
if (main_request_context_getter_.get()) {
|
|
|
|
if (BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
|
|
|
|
BrowserThread::PostTask(
|
|
|
|
BrowserThread::IO, FROM_HERE,
|
|
|
|
base::BindOnce(&URLRequestContextGetter::NotifyContextShuttingDown,
|
|
|
|
base::RetainedRef(main_request_context_getter_),
|
|
|
|
std::move(resource_context_)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this))
|
|
|
|
delete this;
|
2016-08-05 07:23:31 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
URLRequestContextGetter::URLRequestContextGetter(
|
2015-08-11 10:29:55 +00:00
|
|
|
NetLog* net_log,
|
2018-08-22 15:24:56 +00:00
|
|
|
ResourceContext* resource_context,
|
2015-08-26 21:40:02 +00:00
|
|
|
bool in_memory,
|
2018-08-22 15:24:56 +00:00
|
|
|
const std::string& user_agent,
|
|
|
|
const base::FilePath& base_path,
|
2014-06-26 20:27:22 +00:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-08-31 10:43:01 +00:00
|
|
|
content::URLRequestInterceptorScopedVector protocol_interceptors)
|
2018-08-22 15:24:56 +00:00
|
|
|
: job_factory_(nullptr),
|
|
|
|
delegate_(nullptr),
|
2015-08-11 10:29:55 +00:00
|
|
|
net_log_(net_log),
|
2018-08-22 15:24:56 +00:00
|
|
|
resource_context_(resource_context),
|
|
|
|
protocol_interceptors_(std::move(protocol_interceptors)),
|
2014-08-20 06:39:09 +00:00
|
|
|
base_path_(base_path),
|
2015-08-26 21:40:02 +00:00
|
|
|
in_memory_(in_memory),
|
2018-08-22 15:24:56 +00:00
|
|
|
user_agent_(user_agent),
|
2018-03-30 13:24:55 +00:00
|
|
|
context_shutting_down_(false) {
|
2013-03-13 19:12:05 +00:00
|
|
|
// Must first be created on the UI thread.
|
2017-12-16 09:21:29 +00:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2016-03-10 05:39:07 +00:00
|
|
|
if (protocol_handlers)
|
|
|
|
std::swap(protocol_handlers_, *protocol_handlers);
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2014-08-20 07:19:25 +00:00
|
|
|
// We must create the proxy config service on the UI loop on Linux because it
|
|
|
|
// must synchronously run on the glib message loop. This will be passed to
|
|
|
|
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
|
2018-04-18 01:56:12 +00:00
|
|
|
proxy_config_service_ =
|
2018-04-05 21:28:05 +00:00
|
|
|
net::ProxyResolutionService::CreateSystemProxyConfigService(
|
2018-08-22 15:24:56 +00:00
|
|
|
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
URLRequestContextGetter::~URLRequestContextGetter() {}
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
void URLRequestContextGetter::NotifyContextShuttingDown(
|
|
|
|
std::unique_ptr<ResourceContext> resource_context) {
|
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
|
|
|
2018-03-30 13:24:55 +00:00
|
|
|
context_shutting_down_ = true;
|
|
|
|
cookie_change_sub_.reset();
|
2018-08-22 15:24:56 +00:00
|
|
|
resource_context.reset();
|
|
|
|
net::URLRequestContextGetter::NotifyContextShuttingDown();
|
|
|
|
url_request_context_.reset();
|
|
|
|
storage_.reset();
|
2018-03-30 13:24:55 +00:00
|
|
|
http_network_session_.reset();
|
|
|
|
http_auth_preferences_.reset();
|
|
|
|
host_mapping_rules_.reset();
|
|
|
|
ct_delegate_.reset();
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:11:47 +00:00
|
|
|
net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
2017-12-16 09:21:29 +00:00
|
|
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2018-03-30 13:24:55 +00:00
|
|
|
if (context_shutting_down_)
|
|
|
|
return nullptr;
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
if (!url_request_context_.get()) {
|
2017-11-15 13:09:22 +00:00
|
|
|
ct_delegate_.reset(new RequireCTDelegate);
|
2015-08-26 21:40:02 +00:00
|
|
|
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
2014-08-20 07:19:25 +00:00
|
|
|
url_request_context_.reset(new net::URLRequestContext);
|
2015-06-08 13:49:44 +00:00
|
|
|
|
|
|
|
// --log-net-log
|
2016-03-10 05:39:07 +00:00
|
|
|
if (net_log_) {
|
2017-08-24 13:08:05 +00:00
|
|
|
net_log_->StartLogging();
|
2016-03-10 05:39:07 +00:00
|
|
|
url_request_context_->set_net_log(net_log_);
|
|
|
|
}
|
2015-06-08 13:49:44 +00:00
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
storage_.reset(
|
|
|
|
new net::URLRequestContextStorage(url_request_context_.get()));
|
2015-08-26 21:40:02 +00:00
|
|
|
|
2017-12-15 17:32:33 +00:00
|
|
|
storage_->set_network_delegate(delegate_->CreateNetworkDelegate());
|
|
|
|
|
2018-08-28 18:37:09 +00:00
|
|
|
std::unique_ptr<net::CookieStore> cookie_store;
|
|
|
|
scoped_refptr<net::SQLiteChannelIDStore> channel_id_db;
|
|
|
|
// Create a single task runner to use with the CookieStore and
|
|
|
|
// ChannelIDStore.
|
|
|
|
scoped_refptr<base::SequencedTaskRunner> cookie_background_task_runner =
|
|
|
|
base::CreateSequencedTaskRunnerWithTraits(
|
|
|
|
{base::MayBlock(), base::TaskPriority::BACKGROUND,
|
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
|
2018-04-18 01:56:12 +00:00
|
|
|
auto cookie_path = in_memory_
|
|
|
|
? base::FilePath()
|
|
|
|
: base_path_.Append(FILE_PATH_LITERAL("Cookies"));
|
2018-08-28 18:37:09 +00:00
|
|
|
if (!in_memory_) {
|
|
|
|
channel_id_db = new net::SQLiteChannelIDStore(
|
|
|
|
base_path_.Append(FILE_PATH_LITERAL("Origin Bound Certs")),
|
|
|
|
cookie_background_task_runner);
|
|
|
|
}
|
|
|
|
std::unique_ptr<net::ChannelIDService> channel_id_service(
|
|
|
|
new net::ChannelIDService(
|
|
|
|
new net::DefaultChannelIDStore(channel_id_db.get())));
|
|
|
|
content::CookieStoreConfig cookie_config(cookie_path, false, false,
|
|
|
|
nullptr);
|
|
|
|
cookie_config.channel_id_service = channel_id_service.get();
|
|
|
|
cookie_config.background_task_runner = cookie_background_task_runner;
|
|
|
|
cookie_store = content::CreateCookieStore(cookie_config);
|
|
|
|
cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
|
2018-04-18 12:14:21 +00:00
|
|
|
|
|
|
|
// Set custom schemes that can accept cookies.
|
|
|
|
net::CookieMonster* cookie_monster =
|
2018-08-28 18:37:09 +00:00
|
|
|
static_cast<net::CookieMonster*>(cookie_store.get());
|
2018-08-22 15:24:56 +00:00
|
|
|
std::vector<std::string> cookie_schemes({"http", "https", "ws", "wss"});
|
|
|
|
delegate_->GetCookieableSchemes(&cookie_schemes);
|
|
|
|
cookie_monster->SetCookieableSchemes(cookie_schemes);
|
2017-11-27 03:27:14 +00:00
|
|
|
// Cookie store will outlive notifier by order of declaration
|
|
|
|
// in the header.
|
2018-08-28 18:37:09 +00:00
|
|
|
cookie_change_sub_ =
|
|
|
|
cookie_store->GetChangeDispatcher().AddCallbackForAllChanges(
|
|
|
|
base::Bind(&URLRequestContextGetter::OnCookieChanged,
|
|
|
|
base::RetainedRef(this)));
|
|
|
|
storage_->set_cookie_store(std::move(cookie_store));
|
|
|
|
storage_->set_channel_id_service(std::move(channel_id_service));
|
2015-10-09 07:51:53 +00:00
|
|
|
|
2017-12-16 09:21:29 +00:00
|
|
|
storage_->set_http_user_agent_settings(
|
|
|
|
base::WrapUnique(new net::StaticHttpUserAgentSettings(
|
|
|
|
net::HttpUtil::GenerateAcceptLanguageHeader(
|
|
|
|
BrowserClient::Get()->GetApplicationLocale()),
|
2016-06-22 06:52:04 +00:00
|
|
|
user_agent_)));
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2017-03-23 19:48:22 +00:00
|
|
|
std::unique_ptr<net::HostResolver> host_resolver(
|
|
|
|
net::HostResolver::CreateDefaultResolver(nullptr));
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2014-08-15 04:41:56 +00:00
|
|
|
// --host-resolver-rules
|
2018-04-08 17:32:24 +00:00
|
|
|
if (command_line.HasSwitch(network::switches::kHostResolverRules)) {
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::MappedHostResolver> remapped_resolver(
|
2016-03-08 11:59:29 +00:00
|
|
|
new net::MappedHostResolver(std::move(host_resolver)));
|
2018-04-08 17:32:24 +00:00
|
|
|
remapped_resolver->SetRulesFromString(command_line.GetSwitchValueASCII(
|
|
|
|
network::switches::kHostResolverRules));
|
2016-03-08 11:59:29 +00:00
|
|
|
host_resolver = std::move(remapped_resolver);
|
2014-08-15 04:41:56 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 06:48:02 +00:00
|
|
|
// --proxy-server
|
2016-08-03 10:22:09 +00:00
|
|
|
if (command_line.HasSwitch(switches::kNoProxyServer)) {
|
2018-04-05 21:28:05 +00:00
|
|
|
storage_->set_proxy_resolution_service(
|
|
|
|
net::ProxyResolutionService::CreateDirect());
|
2016-08-03 10:22:09 +00:00
|
|
|
} else if (command_line.HasSwitch(switches::kProxyServer)) {
|
2015-11-22 20:56:35 +00:00
|
|
|
net::ProxyConfig proxy_config;
|
|
|
|
proxy_config.proxy_rules().ParseFromString(
|
2016-08-03 10:22:09 +00:00
|
|
|
command_line.GetSwitchValueASCII(switches::kProxyServer));
|
2015-11-22 20:56:35 +00:00
|
|
|
proxy_config.proxy_rules().bypass_rules.ParseFromString(
|
2016-08-03 10:22:09 +00:00
|
|
|
command_line.GetSwitchValueASCII(switches::kProxyBypassList));
|
2018-04-05 21:28:05 +00:00
|
|
|
storage_->set_proxy_resolution_service(
|
|
|
|
net::ProxyResolutionService::CreateFixed(proxy_config));
|
2016-08-03 10:22:09 +00:00
|
|
|
} else if (command_line.HasSwitch(switches::kProxyPacUrl)) {
|
2015-07-10 08:22:02 +00:00
|
|
|
auto proxy_config = net::ProxyConfig::CreateFromCustomPacURL(
|
2016-08-03 10:22:09 +00:00
|
|
|
GURL(command_line.GetSwitchValueASCII(switches::kProxyPacUrl)));
|
2015-07-10 08:22:02 +00:00
|
|
|
proxy_config.set_pac_mandatory(true);
|
2018-04-05 21:28:05 +00:00
|
|
|
storage_->set_proxy_resolution_service(
|
|
|
|
net::ProxyResolutionService::CreateFixed(proxy_config));
|
2015-07-10 08:22:02 +00:00
|
|
|
} else {
|
2018-04-05 21:28:05 +00:00
|
|
|
storage_->set_proxy_resolution_service(
|
|
|
|
net::ProxyResolutionService::CreateUsingSystemProxyResolver(
|
2018-04-18 01:56:12 +00:00
|
|
|
std::move(proxy_config_service_), net_log_));
|
2015-07-10 08:22:02 +00:00
|
|
|
}
|
2015-05-04 22:35:25 +00:00
|
|
|
|
|
|
|
std::vector<std::string> schemes;
|
|
|
|
schemes.push_back(std::string("basic"));
|
|
|
|
schemes.push_back(std::string("digest"));
|
|
|
|
schemes.push_back(std::string("ntlm"));
|
|
|
|
schemes.push_back(std::string("negotiate"));
|
2016-03-08 11:59:29 +00:00
|
|
|
#if defined(OS_POSIX)
|
2018-04-18 01:56:12 +00:00
|
|
|
http_auth_preferences_.reset(
|
|
|
|
new net::HttpAuthPreferences(schemes, std::string()));
|
2016-03-08 11:59:29 +00:00
|
|
|
#else
|
|
|
|
http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes));
|
|
|
|
#endif
|
2016-05-21 18:10:02 +00:00
|
|
|
|
|
|
|
// --auth-server-whitelist
|
2016-08-03 10:22:09 +00:00
|
|
|
if (command_line.HasSwitch(switches::kAuthServerWhitelist)) {
|
2018-04-08 20:11:37 +00:00
|
|
|
http_auth_preferences_->SetServerWhitelist(
|
2016-08-03 10:22:09 +00:00
|
|
|
command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist));
|
2016-05-21 18:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// --auth-negotiate-delegate-whitelist
|
2016-08-03 10:22:09 +00:00
|
|
|
if (command_line.HasSwitch(switches::kAuthNegotiateDelegateWhitelist)) {
|
2018-04-08 20:11:37 +00:00
|
|
|
http_auth_preferences_->SetDelegateWhitelist(
|
2017-03-23 22:47:30 +00:00
|
|
|
command_line.GetSwitchValueASCII(
|
|
|
|
switches::kAuthNegotiateDelegateWhitelist));
|
2016-05-21 18:10:02 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
auto auth_handler_factory = net::HttpAuthHandlerRegistryFactory::Create(
|
|
|
|
http_auth_preferences_.get(), host_resolver.get());
|
2015-05-04 22:35:25 +00:00
|
|
|
|
2016-10-17 10:36:37 +00:00
|
|
|
std::unique_ptr<net::TransportSecurityState> transport_security_state =
|
|
|
|
base::WrapUnique(new net::TransportSecurityState);
|
2017-11-15 13:09:22 +00:00
|
|
|
transport_security_state->SetRequireCTDelegate(ct_delegate_.get());
|
2016-10-17 10:36:37 +00:00
|
|
|
storage_->set_transport_security_state(std::move(transport_security_state));
|
2017-11-15 13:09:22 +00:00
|
|
|
storage_->set_cert_verifier(
|
|
|
|
delegate_->CreateCertVerifier(ct_delegate_.get()));
|
2018-08-22 15:24:56 +00:00
|
|
|
storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults());
|
2016-03-08 14:28:28 +00:00
|
|
|
storage_->set_http_auth_handler_factory(std::move(auth_handler_factory));
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::HttpServerProperties> server_properties(
|
2013-11-17 23:11:47 +00:00
|
|
|
new net::HttpServerPropertiesImpl);
|
2016-03-08 11:59:29 +00:00
|
|
|
storage_->set_http_server_properties(std::move(server_properties));
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2016-09-28 18:14:18 +00:00
|
|
|
std::unique_ptr<net::MultiLogCTVerifier> ct_verifier =
|
2018-04-12 12:48:32 +00:00
|
|
|
std::make_unique<net::MultiLogCTVerifier>();
|
2016-09-28 18:14:18 +00:00
|
|
|
ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs());
|
|
|
|
storage_->set_cert_transparency_verifier(std::move(ct_verifier));
|
2018-04-12 12:48:32 +00:00
|
|
|
storage_->set_ct_policy_enforcer(std::make_unique<net::CTPolicyEnforcer>());
|
2016-09-07 08:54:21 +00:00
|
|
|
|
2017-08-25 09:51:13 +00:00
|
|
|
net::HttpNetworkSession::Params network_session_params;
|
2014-08-20 07:19:25 +00:00
|
|
|
network_session_params.ignore_certificate_errors = false;
|
2016-05-17 18:19:23 +00:00
|
|
|
|
|
|
|
// --disable-http2
|
2017-01-13 08:52:45 +00:00
|
|
|
if (command_line.HasSwitch(switches::kDisableHttp2))
|
2016-05-17 18:19:23 +00:00
|
|
|
network_session_params.enable_http2 = false;
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2015-01-07 04:36:20 +00:00
|
|
|
// --ignore-certificate-errors
|
2017-05-18 20:37:32 +00:00
|
|
|
if (command_line.HasSwitch(::switches::kIgnoreCertificateErrors))
|
2015-01-07 04:36:20 +00:00
|
|
|
network_session_params.ignore_certificate_errors = true;
|
|
|
|
|
2014-08-15 04:30:50 +00:00
|
|
|
// --host-rules
|
2016-08-03 10:22:09 +00:00
|
|
|
if (command_line.HasSwitch(switches::kHostRules)) {
|
2014-08-15 04:30:50 +00:00
|
|
|
host_mapping_rules_.reset(new net::HostMappingRules);
|
2017-03-23 19:48:22 +00:00
|
|
|
host_mapping_rules_->SetRulesFromString(
|
|
|
|
command_line.GetSwitchValueASCII(switches::kHostRules));
|
2017-08-25 09:51:13 +00:00
|
|
|
network_session_params.host_mapping_rules = *host_mapping_rules_.get();
|
2014-08-15 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
// Give |storage_| ownership at the end in case it's |mapped_host_resolver|.
|
2016-03-08 11:59:29 +00:00
|
|
|
storage_->set_host_resolver(std::move(host_resolver));
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2017-11-02 14:05:30 +00:00
|
|
|
net::HttpNetworkSession::Context network_session_context;
|
|
|
|
net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
|
|
|
|
url_request_context_.get(), &network_session_context);
|
2017-08-25 09:51:13 +00:00
|
|
|
http_network_session_.reset(new net::HttpNetworkSession(
|
|
|
|
network_session_params, network_session_context));
|
2017-11-02 14:05:30 +00:00
|
|
|
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::HttpCache::BackendFactory> backend;
|
2015-08-26 21:40:02 +00:00
|
|
|
if (in_memory_) {
|
|
|
|
backend = net::HttpCache::DefaultBackend::InMemory(0);
|
|
|
|
} else {
|
2016-03-08 11:59:29 +00:00
|
|
|
backend.reset(delegate_->CreateHttpCacheBackendFactory(base_path_));
|
2015-08-26 21:40:02 +00:00
|
|
|
}
|
2016-03-10 05:39:07 +00:00
|
|
|
|
2018-04-12 12:48:32 +00:00
|
|
|
storage_->set_http_transaction_factory(std::make_unique<net::HttpCache>(
|
2017-12-19 18:17:48 +00:00
|
|
|
content::CreateDevToolsNetworkTransactionFactory(
|
|
|
|
http_network_session_.get()),
|
|
|
|
std::move(backend), false));
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2016-06-15 11:30:26 +00:00
|
|
|
std::unique_ptr<net::URLRequestJobFactory> job_factory =
|
2018-08-22 15:24:56 +00:00
|
|
|
delegate_->CreateURLRequestJobFactory(url_request_context_.get(),
|
|
|
|
&protocol_handlers_);
|
2016-06-15 11:30:26 +00:00
|
|
|
job_factory_ = job_factory.get();
|
|
|
|
|
|
|
|
// Set up interceptors in the reverse order.
|
|
|
|
std::unique_ptr<net::URLRequestJobFactory> top_job_factory =
|
|
|
|
std::move(job_factory);
|
2018-03-30 13:24:55 +00:00
|
|
|
if (!protocol_interceptors_.empty()) {
|
|
|
|
for (auto it = protocol_interceptors_.rbegin();
|
|
|
|
it != protocol_interceptors_.rend(); ++it) {
|
|
|
|
top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
|
|
|
|
std::move(top_job_factory), std::move(*it)));
|
|
|
|
}
|
|
|
|
protocol_interceptors_.clear();
|
2016-06-15 11:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
storage_->set_job_factory(std::move(top_job_factory));
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
if (resource_context_)
|
|
|
|
resource_context_->request_context_ = url_request_context_.get();
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
return url_request_context_.get();
|
|
|
|
}
|
|
|
|
|
2017-03-23 22:47:30 +00:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
|
|
|
URLRequestContextGetter::GetNetworkTaskRunner() const {
|
2017-01-13 08:52:45 +00:00
|
|
|
return BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 15:24:56 +00:00
|
|
|
void URLRequestContextGetter::OnCookieChanged(
|
|
|
|
const net::CanonicalCookie& cookie,
|
|
|
|
net::CookieChangeCause cause) const {
|
|
|
|
if (delegate_)
|
|
|
|
delegate_->OnCookieChanged(cookie, cause);
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:11:47 +00:00
|
|
|
} // namespace brightray
|