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.
|
|
|
|
|
2013-03-27 12:53:35 +00:00
|
|
|
#include "browser/url_request_context_getter.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2013-11-17 23:11:47 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2016-04-14 01:29:14 +00:00
|
|
|
#include "browser/net/devtools_network_controller_handle.h"
|
2015-09-26 18:19:27 +00:00
|
|
|
#include "browser/net/devtools_network_transaction_factory.h"
|
2015-06-05 14:54:38 +00:00
|
|
|
#include "browser/net_log.h"
|
2013-11-17 23:11:47 +00:00
|
|
|
#include "browser/network_delegate.h"
|
|
|
|
|
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"
|
2013-10-07 19:16:49 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2013-12-02 16:39:26 +00:00
|
|
|
#include "base/threading/sequenced_worker_pool.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "base/threading/worker_pool.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-04-18 03:27:53 +00:00
|
|
|
#include "content/public/browser/cookie_store_factory.h"
|
2014-08-15 04:41:56 +00:00
|
|
|
#include "content/public/common/content_switches.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"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "net/cookies/cookie_monster.h"
|
2014-08-15 04:41:56 +00:00
|
|
|
#include "net/dns/mapped_host_resolver.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"
|
2013-12-05 10:56:28 +00:00
|
|
|
#include "net/proxy/dhcp_proxy_script_fetcher_factory.h"
|
2015-11-22 20:56:35 +00:00
|
|
|
#include "net/proxy/proxy_config.h"
|
2013-12-05 10:56:28 +00:00
|
|
|
#include "net/proxy/proxy_config_service.h"
|
|
|
|
#include "net/proxy/proxy_script_fetcher_impl.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "net/proxy/proxy_service.h"
|
2013-12-05 10:56:28 +00:00
|
|
|
#include "net/proxy/proxy_service_v8.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"
|
|
|
|
#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"
|
2015-10-09 07:51:53 +00:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2014-08-31 10:43:01 +00:00
|
|
|
#include "url/url_constants.h"
|
2014-12-07 06:16:00 +00:00
|
|
|
#include "storage/browser/quota/special_storage_policy.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2015-10-13 12:50:12 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
#include "net/cert_net/nss_ocsp.h"
|
|
|
|
#endif
|
|
|
|
|
2014-08-13 07:09:26 +00:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
namespace brightray {
|
|
|
|
|
2014-08-15 04:30:50 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Comma-separated list of rules that control how hostnames are mapped.
|
|
|
|
//
|
|
|
|
// For example:
|
|
|
|
// "MAP * 127.0.0.1" --> Forces all hostnames to be mapped to 127.0.0.1
|
|
|
|
// "MAP *.google.com proxy" --> Forces all google.com subdomains to be
|
|
|
|
// resolved to "proxy".
|
|
|
|
// "MAP test.com [::1]:77 --> Forces "test.com" to resolve to IPv6 loopback.
|
|
|
|
// Will also force the port of the resulting
|
|
|
|
// socket address to be 77.
|
|
|
|
// "MAP * baz, EXCLUDE www.google.com" --> Remaps everything to "baz",
|
|
|
|
// except for "www.google.com".
|
|
|
|
//
|
|
|
|
// These mappings apply to the endpoint host in a net::URLRequest (the TCP
|
|
|
|
// connect and host resolver in a direct connection, and the CONNECT in an http
|
|
|
|
// proxy connection, and the endpoint host in a SOCKS proxy connection).
|
2014-08-20 03:44:45 +00:00
|
|
|
const char kHostRules[] = "host-rules";
|
|
|
|
|
|
|
|
// Don't use a proxy server, always make direct connections. Overrides any
|
|
|
|
// other proxy server flags that are passed.
|
|
|
|
const char kNoProxyServer[] = "no-proxy-server";
|
2014-08-15 04:30:50 +00:00
|
|
|
|
2014-08-20 03:49:18 +00:00
|
|
|
// Uses a specified proxy server, overrides system settings. This switch only
|
|
|
|
// affects HTTP and HTTPS requests.
|
|
|
|
const char kProxyServer[] = "proxy-server";
|
|
|
|
|
2015-11-22 20:56:35 +00:00
|
|
|
// Bypass specified proxy for the given semi-colon-separated list of hosts. This
|
|
|
|
// flag has an effect only when --proxy-server is set.
|
|
|
|
const char kProxyBypassList[] = "proxy-bypass-list";
|
|
|
|
|
2015-07-10 08:22:02 +00:00
|
|
|
// Uses the pac script at the given URL.
|
|
|
|
const char kProxyPacUrl[] = "proxy-pac-url";
|
|
|
|
|
2016-05-17 18:19:23 +00:00
|
|
|
// Disable HTTP/2 and SPDY/3.1 protocols.
|
|
|
|
const char kDisableHttp2[] = "disable-http2";
|
|
|
|
|
2014-08-15 04:30:50 +00:00
|
|
|
} // namespace
|
|
|
|
|
2015-10-16 23:39:42 +00:00
|
|
|
|
2015-10-19 19:51:01 +00:00
|
|
|
URLRequestContextGetter::DelegateURLSecurityManager::DelegateURLSecurityManager
|
|
|
|
(URLRequestContextGetter::Delegate* delegate) :
|
|
|
|
delegate_(delegate) {}
|
2015-10-16 23:43:03 +00:00
|
|
|
|
2015-10-19 19:51:01 +00:00
|
|
|
bool URLRequestContextGetter::DelegateURLSecurityManager::CanUseDefaultCredentials
|
|
|
|
(const GURL& auth_origin) const {
|
|
|
|
return delegate_->AllowNTLMCredentialsForDomain(auth_origin);
|
2015-10-16 23:39:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 19:51:01 +00:00
|
|
|
bool URLRequestContextGetter::DelegateURLSecurityManager::CanDelegate
|
|
|
|
(const GURL& auth_origin) const {
|
|
|
|
return delegate_->CanDelegateURLSecurity(auth_origin);
|
2015-10-16 23:39:42 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 06:58:25 +00:00
|
|
|
void URLRequestContextGetter::DelegateURLSecurityManager::SetDefaultWhitelist(
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::HttpAuthFilter> whitelist_default) {
|
2016-03-08 06:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void URLRequestContextGetter::DelegateURLSecurityManager::SetDelegateWhitelist(
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::HttpAuthFilter> whitelist_delegate) {
|
2016-03-08 06:58:25 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 19:51:01 +00:00
|
|
|
URLRequestContextGetter::Delegate::Delegate() :
|
2016-03-08 06:58:25 +00:00
|
|
|
orig_url_sec_mgr_(net::URLSecurityManager::Create()) {}
|
2015-10-19 19:51:01 +00:00
|
|
|
|
2015-07-14 17:04:34 +00:00
|
|
|
std::string URLRequestContextGetter::Delegate::GetUserAgent() {
|
|
|
|
return base::EmptyString();
|
|
|
|
}
|
|
|
|
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::URLRequestJobFactory>
|
2015-12-07 11:55:01 +00:00
|
|
|
URLRequestContextGetter::Delegate::CreateURLRequestJobFactory(
|
2014-08-20 06:48:02 +00:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-08-31 10:43:01 +00:00
|
|
|
content::URLRequestInterceptorScopedVector* protocol_interceptors) {
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory(new net::URLRequestJobFactoryImpl);
|
2014-08-20 06:48:02 +00:00
|
|
|
|
|
|
|
for (auto it = protocol_handlers->begin(); it != protocol_handlers->end(); ++it)
|
2015-12-07 11:55:01 +00:00
|
|
|
job_factory->SetProtocolHandler(
|
2016-05-23 01:59:07 +00:00
|
|
|
it->first, base::WrapUnique(it->second.release()));
|
2014-08-20 06:48:02 +00:00
|
|
|
protocol_handlers->clear();
|
|
|
|
|
2015-12-07 11:55:01 +00:00
|
|
|
job_factory->SetProtocolHandler(
|
2016-05-23 01:59:07 +00:00
|
|
|
url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler));
|
2015-12-07 11:55:01 +00:00
|
|
|
job_factory->SetProtocolHandler(
|
|
|
|
url::kFileScheme,
|
2016-05-23 01:59:07 +00:00
|
|
|
base::WrapUnique(new net::FileProtocolHandler(
|
2015-12-07 11:55:01 +00:00
|
|
|
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
|
|
|
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))));
|
2014-08-20 06:48:02 +00:00
|
|
|
|
|
|
|
// Set up interceptors in the reverse order.
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::URLRequestJobFactory> top_job_factory = std::move(job_factory);
|
2014-08-31 12:04:48 +00:00
|
|
|
content::URLRequestInterceptorScopedVector::reverse_iterator i;
|
|
|
|
for (i = protocol_interceptors->rbegin(); i != protocol_interceptors->rend(); ++i)
|
2014-08-31 10:43:01 +00:00
|
|
|
top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
|
2016-05-23 01:59:07 +00:00
|
|
|
std::move(top_job_factory), base::WrapUnique(*i)));
|
2014-08-20 06:48:02 +00:00
|
|
|
protocol_interceptors->weak_clear();
|
|
|
|
|
2016-03-08 11:59:29 +00:00
|
|
|
return top_job_factory;
|
2014-08-20 06:48:02 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 21:29:16 +00:00
|
|
|
net::HttpCache::BackendFactory*
|
|
|
|
URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::FilePath& base_path) {
|
|
|
|
base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache"));
|
|
|
|
return new net::HttpCache::DefaultBackend(
|
|
|
|
net::DISK_CACHE,
|
|
|
|
net::CACHE_BACKEND_DEFAULT,
|
|
|
|
cache_path,
|
|
|
|
0,
|
|
|
|
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
|
|
|
|
}
|
|
|
|
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::CertVerifier>
|
2015-12-07 11:55:01 +00:00
|
|
|
URLRequestContextGetter::Delegate::CreateCertVerifier() {
|
2015-11-05 15:26:46 +00:00
|
|
|
return net::CertVerifier::CreateDefault();
|
|
|
|
}
|
|
|
|
|
2015-09-21 16:44:32 +00:00
|
|
|
net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService() {
|
|
|
|
return new net::SSLConfigServiceDefaults;
|
|
|
|
}
|
|
|
|
|
2015-10-19 19:51:01 +00:00
|
|
|
bool URLRequestContextGetter::Delegate::AllowNTLMCredentialsForDomain(const GURL& auth_origin) {
|
|
|
|
return orig_url_sec_mgr_->CanUseDefaultCredentials(auth_origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool URLRequestContextGetter::Delegate::CanDelegateURLSecurity(const GURL& auth_origin) {
|
|
|
|
return orig_url_sec_mgr_->CanDelegate(auth_origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
URLRequestContextGetter::URLRequestContextGetter(
|
2014-08-20 06:39:09 +00:00
|
|
|
Delegate* delegate,
|
2016-04-14 01:29:14 +00:00
|
|
|
DevToolsNetworkControllerHandle* handle,
|
2015-08-11 10:29:55 +00:00
|
|
|
NetLog* net_log,
|
2013-03-13 19:12:05 +00:00
|
|
|
const base::FilePath& base_path,
|
2015-08-26 21:40:02 +00:00
|
|
|
bool in_memory,
|
2013-08-23 20:56:41 +00:00
|
|
|
base::MessageLoop* io_loop,
|
|
|
|
base::MessageLoop* file_loop,
|
2014-06-26 20:27:22 +00:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-08-31 10:43:01 +00:00
|
|
|
content::URLRequestInterceptorScopedVector protocol_interceptors)
|
2014-08-20 06:39:09 +00:00
|
|
|
: delegate_(delegate),
|
2016-04-14 01:29:14 +00:00
|
|
|
network_controller_handle_(handle),
|
2015-08-11 10:29:55 +00:00
|
|
|
net_log_(net_log),
|
2014-08-20 06:39:09 +00:00
|
|
|
base_path_(base_path),
|
2015-08-26 21:40:02 +00:00
|
|
|
in_memory_(in_memory),
|
2013-03-13 19:12:05 +00:00
|
|
|
io_loop_(io_loop),
|
2013-07-17 14:21:33 +00:00
|
|
|
file_loop_(file_loop),
|
2016-03-08 11:59:29 +00:00
|
|
|
protocol_interceptors_(std::move(protocol_interceptors)) {
|
2013-03-13 19:12:05 +00:00
|
|
|
// Must first be created on the UI thread.
|
2014-08-13 07:09:26 +00:00
|
|
|
DCHECK(BrowserThread::CurrentlyOn(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().
|
2015-12-07 11:55:01 +00:00
|
|
|
proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService(
|
|
|
|
io_loop_->task_runner(), file_loop_->task_runner());
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
URLRequestContextGetter::~URLRequestContextGetter() {
|
2015-10-13 12:50:12 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
net::SetURLRequestContextForNSSHttpIO(NULL);
|
|
|
|
#endif
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
net::HostResolver* URLRequestContextGetter::host_resolver() {
|
|
|
|
return url_request_context_->host_resolver();
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:11:47 +00:00
|
|
|
net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
2014-08-13 07:09:26 +00:00
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
2013-03-13 19:12:05 +00:00
|
|
|
|
|
|
|
if (!url_request_context_.get()) {
|
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
|
|
|
|
2015-10-14 01:47:22 +00:00
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
|
|
|
|
#endif
|
2015-10-13 12:50:12 +00:00
|
|
|
|
2015-06-08 13:49:44 +00:00
|
|
|
// --log-net-log
|
2016-03-10 05:39:07 +00:00
|
|
|
if (net_log_) {
|
|
|
|
net_log_->StartLogging(url_request_context_.get());
|
|
|
|
url_request_context_->set_net_log(net_log_);
|
|
|
|
}
|
2015-06-08 13:49:44 +00:00
|
|
|
|
2014-08-20 06:39:09 +00:00
|
|
|
network_delegate_.reset(delegate_->CreateNetworkDelegate());
|
2013-03-13 19:12:05 +00:00
|
|
|
url_request_context_->set_network_delegate(network_delegate_.get());
|
2014-08-20 07:19:25 +00:00
|
|
|
|
|
|
|
storage_.reset(new net::URLRequestContextStorage(url_request_context_.get()));
|
2015-08-26 21:40:02 +00:00
|
|
|
|
2016-05-23 01:59:07 +00:00
|
|
|
std::unique_ptr<net::CookieStore> cookie_store = nullptr;
|
2015-08-26 21:40:02 +00:00
|
|
|
if (in_memory_) {
|
|
|
|
cookie_store = content::CreateCookieStore(content::CookieStoreConfig());
|
|
|
|
} else {
|
|
|
|
auto cookie_config = content::CookieStoreConfig(
|
|
|
|
base_path_.Append(FILE_PATH_LITERAL("Cookies")),
|
|
|
|
content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
|
|
|
|
NULL, NULL);
|
|
|
|
cookie_store = content::CreateCookieStore(cookie_config);
|
|
|
|
}
|
2016-05-23 01:59:07 +00:00
|
|
|
storage_->set_cookie_store(std::move(cookie_store));
|
|
|
|
storage_->set_channel_id_service(base::WrapUnique(
|
2015-04-21 10:54:57 +00:00
|
|
|
new net::ChannelIDService(new net::DefaultChannelIDStore(NULL),
|
|
|
|
base::WorkerPool::GetTaskRunner(true))));
|
2015-10-09 07:51:53 +00:00
|
|
|
|
|
|
|
std::string accept_lang = l10n_util::GetApplicationLocale("");
|
2016-05-23 01:59:07 +00:00
|
|
|
storage_->set_http_user_agent_settings(base::WrapUnique(
|
2015-12-07 11:55:01 +00:00
|
|
|
new net::StaticHttpUserAgentSettings(
|
|
|
|
net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang),
|
|
|
|
delegate_->GetUserAgent())));
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2016-05-23 01:59:07 +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
|
|
|
|
if (command_line.HasSwitch(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)));
|
2014-08-15 04:41:56 +00:00
|
|
|
remapped_resolver->SetRulesFromString(
|
|
|
|
command_line.GetSwitchValueASCII(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
|
2013-12-15 07:00:52 +00:00
|
|
|
net::DhcpProxyScriptFetcherFactory dhcp_factory;
|
2015-07-10 08:22:02 +00:00
|
|
|
if (command_line.HasSwitch(kNoProxyServer)) {
|
2014-08-20 03:44:45 +00:00
|
|
|
storage_->set_proxy_service(net::ProxyService::CreateDirect());
|
2015-07-10 08:22:02 +00:00
|
|
|
} else if (command_line.HasSwitch(kProxyServer)) {
|
2015-11-22 20:56:35 +00:00
|
|
|
net::ProxyConfig proxy_config;
|
|
|
|
proxy_config.proxy_rules().ParseFromString(
|
|
|
|
command_line.GetSwitchValueASCII(kProxyServer));
|
|
|
|
proxy_config.proxy_rules().bypass_rules.ParseFromString(
|
|
|
|
command_line.GetSwitchValueASCII(kProxyBypassList));
|
|
|
|
storage_->set_proxy_service(net::ProxyService::CreateFixed(proxy_config));
|
2015-07-10 08:22:02 +00:00
|
|
|
} else if (command_line.HasSwitch(kProxyPacUrl)) {
|
|
|
|
auto proxy_config = net::ProxyConfig::CreateFromCustomPacURL(
|
|
|
|
GURL(command_line.GetSwitchValueASCII(kProxyPacUrl)));
|
|
|
|
proxy_config.set_pac_mandatory(true);
|
|
|
|
storage_->set_proxy_service(net::ProxyService::CreateFixed(
|
|
|
|
proxy_config));
|
|
|
|
} else {
|
2014-08-20 03:44:45 +00:00
|
|
|
storage_->set_proxy_service(
|
|
|
|
net::CreateProxyServiceUsingV8ProxyResolver(
|
2016-03-08 11:59:29 +00:00
|
|
|
std::move(proxy_config_service_),
|
2014-08-20 03:44:45 +00:00
|
|
|
new net::ProxyScriptFetcherImpl(url_request_context_.get()),
|
|
|
|
dhcp_factory.Create(url_request_context_.get()),
|
|
|
|
host_resolver.get(),
|
|
|
|
NULL,
|
|
|
|
url_request_context_->network_delegate()));
|
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)
|
|
|
|
http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes,
|
|
|
|
std::string()));
|
|
|
|
#else
|
|
|
|
http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes));
|
|
|
|
#endif
|
2016-03-08 14:28:28 +00:00
|
|
|
auto auth_handler_factory =
|
2015-05-06 05:28:00 +00:00
|
|
|
net::HttpAuthHandlerRegistryFactory::Create(
|
2016-03-08 14:28:28 +00:00
|
|
|
http_auth_preferences_.get(), host_resolver.get());
|
2015-05-04 22:35:25 +00:00
|
|
|
|
2015-11-05 15:26:46 +00:00
|
|
|
storage_->set_cert_verifier(delegate_->CreateCertVerifier());
|
2015-12-07 11:55:01 +00:00
|
|
|
storage_->set_transport_security_state(
|
2016-05-23 01:59:07 +00:00
|
|
|
base::WrapUnique(new net::TransportSecurityState));
|
2015-09-21 16:44:32 +00:00
|
|
|
storage_->set_ssl_config_service(delegate_->CreateSSLConfigService());
|
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
|
|
|
|
|
|
|
net::HttpNetworkSession::Params network_session_params;
|
2014-08-20 07:19:25 +00:00
|
|
|
network_session_params.cert_verifier = url_request_context_->cert_verifier();
|
|
|
|
network_session_params.proxy_service = url_request_context_->proxy_service();
|
|
|
|
network_session_params.ssl_config_service = url_request_context_->ssl_config_service();
|
|
|
|
network_session_params.http_server_properties = url_request_context_->http_server_properties();
|
|
|
|
network_session_params.ignore_certificate_errors = false;
|
2014-01-30 14:01:23 +00:00
|
|
|
network_session_params.transport_security_state =
|
|
|
|
url_request_context_->transport_security_state();
|
2014-10-11 08:38:27 +00:00
|
|
|
network_session_params.channel_id_service =
|
|
|
|
url_request_context_->channel_id_service();
|
2013-03-13 19:12:05 +00:00
|
|
|
network_session_params.http_auth_handler_factory =
|
|
|
|
url_request_context_->http_auth_handler_factory();
|
2015-06-05 14:54:38 +00:00
|
|
|
network_session_params.net_log = url_request_context_->net_log();
|
2016-05-17 18:19:23 +00:00
|
|
|
|
|
|
|
// --disable-http2
|
|
|
|
if (command_line.HasSwitch(kDisableHttp2)) {
|
|
|
|
network_session_params.enable_spdy31 = false;
|
|
|
|
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
|
|
|
|
if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
|
|
|
|
network_session_params.ignore_certificate_errors = true;
|
|
|
|
|
2014-08-15 04:30:50 +00:00
|
|
|
// --host-rules
|
|
|
|
if (command_line.HasSwitch(kHostRules)) {
|
|
|
|
host_mapping_rules_.reset(new net::HostMappingRules);
|
|
|
|
host_mapping_rules_->SetRulesFromString(command_line.GetSwitchValueASCII(kHostRules));
|
|
|
|
network_session_params.host_mapping_rules = host_mapping_rules_.get();
|
|
|
|
}
|
|
|
|
|
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));
|
2014-08-20 07:19:25 +00:00
|
|
|
network_session_params.host_resolver = url_request_context_->host_resolver();
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2016-03-08 11:59:29 +00:00
|
|
|
http_network_session_.reset(
|
|
|
|
new net::HttpNetworkSession(network_session_params));
|
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
|
|
|
|
2016-04-14 01:29:14 +00:00
|
|
|
if (network_controller_handle_) {
|
2016-05-23 01:59:07 +00:00
|
|
|
storage_->set_http_transaction_factory(base::WrapUnique(
|
2016-03-10 05:39:07 +00:00
|
|
|
new net::HttpCache(
|
2016-05-23 01:59:07 +00:00
|
|
|
base::WrapUnique(new DevToolsNetworkTransactionFactory(
|
2016-04-14 01:29:14 +00:00
|
|
|
network_controller_handle_->GetController(), http_network_session_.get())),
|
2016-03-10 05:39:07 +00:00
|
|
|
std::move(backend),
|
|
|
|
false)));
|
|
|
|
} else {
|
2016-05-23 01:59:07 +00:00
|
|
|
storage_->set_http_transaction_factory(base::WrapUnique(
|
2016-03-10 05:39:07 +00:00
|
|
|
new net::HttpCache(http_network_session_.get(),
|
|
|
|
std::move(backend),
|
|
|
|
false)));
|
|
|
|
}
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2014-08-20 06:48:02 +00:00
|
|
|
storage_->set_job_factory(delegate_->CreateURLRequestJobFactory(
|
|
|
|
&protocol_handlers_, &protocol_interceptors_));
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return url_request_context_.get();
|
|
|
|
}
|
|
|
|
|
2014-08-20 07:19:25 +00:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> URLRequestContextGetter::GetNetworkTaskRunner() const {
|
2014-08-13 07:09:26 +00:00
|
|
|
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:11:47 +00:00
|
|
|
} // namespace brightray
|