2012-04-03 03:34:16 +02: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 file.
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/url_request_context_getter_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include <string>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2015-08-21 22:17:59 +02:00
|
|
|
#include "libcef/browser/cookie_manager_impl.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/network_delegate.h"
|
|
|
|
#include "libcef/browser/net/scheme_handler.h"
|
|
|
|
#include "libcef/browser/net/url_request_interceptor.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2013-02-13 20:53:41 +01:00
|
|
|
#include "libcef/common/cef_switches.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "libcef/common/content_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "base/command_line.h"
|
2014-11-12 20:25:15 +01:00
|
|
|
#include "base/files/file_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/logging.h"
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2012-06-28 19:21:18 +02:00
|
|
|
#include "base/stl_util.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_util.h"
|
2012-05-18 17:04:56 +02:00
|
|
|
#include "base/threading/thread_restrictions.h"
|
|
|
|
#include "base/threading/worker_pool.h"
|
2016-01-06 20:20:54 +01:00
|
|
|
#include "build/build_config.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "chrome/browser/net/proxy_service_factory.h"
|
2015-12-09 17:10:16 +01:00
|
|
|
#include "chrome/common/pref_names.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "components/net_log/chrome_net_log.h"
|
2016-06-21 00:59:23 +02:00
|
|
|
#include "components/prefs/pref_registry_simple.h"
|
2016-02-05 01:49:19 +01:00
|
|
|
#include "components/prefs/pref_service.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-10-30 18:42:05 +01:00
|
|
|
#include "content/public/common/content_client.h"
|
2013-02-14 00:43:16 +01:00
|
|
|
#include "content/public/common/content_switches.h"
|
2013-02-23 01:43:28 +01:00
|
|
|
#include "content/public/common/url_constants.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "net/cert/cert_verifier.h"
|
2016-09-16 18:37:34 +02:00
|
|
|
#include "net/cert/ct_known_logs.h"
|
|
|
|
#include "net/cert/ct_log_verifier.h"
|
2016-07-06 21:34:09 +02:00
|
|
|
#include "net/cert/ct_policy_enforcer.h"
|
|
|
|
#include "net/cert/multi_log_ct_verifier.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/cookies/cookie_monster.h"
|
2015-06-06 00:06:48 +02:00
|
|
|
#include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
|
2013-04-02 19:21:37 +02:00
|
|
|
#include "net/dns/host_resolver.h"
|
2013-06-24 20:57:05 +02:00
|
|
|
#include "net/ftp/ftp_network_layer.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/http/http_auth_handler_factory.h"
|
2015-12-09 17:10:16 +01:00
|
|
|
#include "net/http/http_auth_preferences.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/http/http_cache.h"
|
|
|
|
#include "net/http/http_server_properties_impl.h"
|
2013-10-30 18:42:05 +01:00
|
|
|
#include "net/http/http_util.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "net/http/transport_security_state.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/proxy/proxy_service.h"
|
2013-04-02 19:21:37 +02:00
|
|
|
#include "net/ssl/ssl_config_service_defaults.h"
|
2014-06-12 22:28:58 +02:00
|
|
|
#include "url/url_constants.h"
|
2013-10-30 18:42:05 +01:00
|
|
|
#include "net/url_request/http_user_agent_settings.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/url_request/url_request.h"
|
|
|
|
#include "net/url_request/url_request_context.h"
|
|
|
|
#include "net/url_request/url_request_context_storage.h"
|
2014-06-12 22:28:58 +02:00
|
|
|
#include "net/url_request/url_request_intercepting_job_factory.h"
|
2012-08-29 00:26:35 +02:00
|
|
|
#include "net/url_request/url_request_job_factory_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/url_request/url_request_job_manager.h"
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <winhttp.h>
|
|
|
|
#endif
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
#include "net/cert_net/nss_ocsp.h"
|
2015-01-21 00:57:30 +01:00
|
|
|
#endif
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#pragma comment(lib, "winhttp.lib")
|
|
|
|
#endif
|
|
|
|
|
2013-10-30 18:42:05 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// An implementation of |HttpUserAgentSettings| that provides a static
|
|
|
|
// HTTP Accept-Language header value and uses |content::GetUserAgent|
|
|
|
|
// to provide the HTTP User-Agent header value.
|
|
|
|
class CefHttpUserAgentSettings : public net::HttpUserAgentSettings {
|
|
|
|
public:
|
|
|
|
explicit CefHttpUserAgentSettings(const std::string& raw_language_list)
|
|
|
|
: http_accept_language_(net::HttpUtil::GenerateAcceptLanguageHeader(
|
|
|
|
raw_language_list)) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
}
|
|
|
|
|
|
|
|
// net::HttpUserAgentSettings implementation
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetAcceptLanguage() const override {
|
2013-10-30 18:42:05 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
return http_accept_language_;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
std::string GetUserAgent() const override {
|
2013-10-30 18:42:05 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
2014-04-04 18:50:38 +02:00
|
|
|
return CefContentClient::Get()->GetUserAgent();
|
2013-10-30 18:42:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string http_accept_language_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefHttpUserAgentSettings);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
CefURLRequestContextGetterImpl::CefURLRequestContextGetterImpl(
|
2015-03-02 21:25:14 +01:00
|
|
|
const CefRequestContextSettings& settings,
|
2015-12-09 17:10:16 +01:00
|
|
|
PrefService* pref_service,
|
2016-03-16 03:55:59 +01:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::ProxyConfigService> proxy_config_service,
|
2014-06-12 22:28:58 +02:00
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors)
|
2015-03-02 21:25:14 +01:00
|
|
|
: settings_(settings),
|
2016-11-07 20:14:09 +01:00
|
|
|
net_log_(g_browser_process->net_log()),
|
2016-03-16 03:55:59 +01:00
|
|
|
io_task_runner_(std::move(io_task_runner)),
|
|
|
|
file_task_runner_(std::move(file_task_runner)),
|
2016-01-06 20:20:54 +01:00
|
|
|
proxy_config_service_(std::move(proxy_config_service)),
|
|
|
|
request_interceptors_(std::move(request_interceptors)) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Must first be created on the UI thread.
|
|
|
|
CEF_REQUIRE_UIT();
|
2016-11-07 20:14:09 +01:00
|
|
|
DCHECK(net_log_);
|
2013-03-12 21:23:24 +01:00
|
|
|
|
|
|
|
std::swap(protocol_handlers_, *protocol_handlers);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
auto io_thread_proxy =
|
2016-07-21 23:21:32 +02:00
|
|
|
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
|
2016-06-21 00:59:23 +02:00
|
|
|
|
|
|
|
quick_check_enabled_.Init(prefs::kQuickCheckEnabled, pref_service);
|
|
|
|
quick_check_enabled_.MoveToThread(io_thread_proxy);
|
|
|
|
|
|
|
|
pac_https_url_stripping_enabled_.Init(prefs::kPacHttpsUrlStrippingEnabled,
|
|
|
|
pref_service);
|
|
|
|
pac_https_url_stripping_enabled_.MoveToThread(io_thread_proxy);
|
|
|
|
|
2016-06-07 20:44:59 +02:00
|
|
|
force_google_safesearch_.Init(prefs::kForceGoogleSafeSearch, pref_service);
|
2016-06-21 00:59:23 +02:00
|
|
|
force_google_safesearch_.MoveToThread(io_thread_proxy);
|
2016-06-07 20:44:59 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
#if defined(OS_POSIX) && !defined(OS_ANDROID)
|
|
|
|
gsapi_library_name_ = pref_service->GetString(prefs::kGSSAPILibraryName);
|
|
|
|
#endif
|
2016-10-27 18:52:54 +02:00
|
|
|
|
|
|
|
auth_server_whitelist_.Init(
|
|
|
|
prefs::kAuthServerWhitelist, pref_service,
|
|
|
|
base::Bind(&CefURLRequestContextGetterImpl::UpdateServerWhitelist,
|
|
|
|
base::Unretained(this)));
|
|
|
|
auth_server_whitelist_.MoveToThread(io_thread_proxy);
|
|
|
|
|
|
|
|
auth_negotiate_delegate_whitelist_.Init(
|
|
|
|
prefs::kAuthNegotiateDelegateWhitelist, pref_service,
|
|
|
|
base::Bind(&CefURLRequestContextGetterImpl::UpdateDelegateWhitelist,
|
|
|
|
base::Unretained(this)));
|
|
|
|
auth_negotiate_delegate_whitelist_.MoveToThread(io_thread_proxy);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
CefURLRequestContextGetterImpl::~CefURLRequestContextGetterImpl() {
|
2012-12-04 02:12:11 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
2013-09-17 10:13:02 +02:00
|
|
|
|
|
|
|
// Delete the ProxyService object here so that any pending requests will be
|
|
|
|
// canceled before the associated URLRequestContext is destroyed in this
|
|
|
|
// object's destructor.
|
|
|
|
storage_->set_proxy_service(NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
// static
|
|
|
|
void CefURLRequestContextGetterImpl::RegisterPrefs(
|
|
|
|
PrefRegistrySimple* registry) {
|
|
|
|
// Based on IOThread::RegisterPrefs.
|
|
|
|
#if defined(OS_POSIX) && !defined(OS_ANDROID)
|
|
|
|
registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
|
|
|
|
#endif
|
|
|
|
registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true);
|
|
|
|
registry->RegisterBooleanPref(prefs::kPacHttpsUrlStrippingEnabled, true);
|
|
|
|
|
|
|
|
// Based on ProfileImpl::RegisterProfilePrefs.
|
|
|
|
registry->RegisterBooleanPref(prefs::kForceGoogleSafeSearch, false);
|
|
|
|
}
|
|
|
|
|
2016-06-07 20:44:59 +02:00
|
|
|
void CefURLRequestContextGetterImpl::ShutdownOnUIThread() {
|
|
|
|
CEF_REQUIRE_UIT();
|
2016-06-21 00:59:23 +02:00
|
|
|
quick_check_enabled_.Destroy();
|
|
|
|
pac_https_url_stripping_enabled_.Destroy();
|
2016-06-07 20:44:59 +02:00
|
|
|
force_google_safesearch_.Destroy();
|
2016-10-27 19:22:34 +02:00
|
|
|
auth_server_whitelist_.Destroy();
|
|
|
|
auth_negotiate_delegate_whitelist_.Destroy();
|
2016-06-07 20:44:59 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
net::URLRequestContext* CefURLRequestContextGetterImpl::GetURLRequestContext() {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
if (!url_request_context_.get()) {
|
2015-01-09 18:22:10 +01:00
|
|
|
const base::CommandLine* command_line =
|
|
|
|
base::CommandLine::ForCurrentProcess();
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
base::FilePath cache_path;
|
|
|
|
if (settings_.cache_path.length > 0)
|
|
|
|
cache_path = base::FilePath(CefString(&settings_.cache_path));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
url_request_context_.reset(new CefURLRequestContextImpl());
|
2016-11-07 20:14:09 +01:00
|
|
|
url_request_context_->set_net_log(net_log_);
|
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
storage_.reset(
|
|
|
|
new net::URLRequestContextStorage(url_request_context_.get()));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
SetCookieStoragePath(cache_path,
|
|
|
|
settings_.persist_session_cookies ? true : false);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-06-07 20:44:59 +02:00
|
|
|
std::unique_ptr<CefNetworkDelegate> network_delegate(
|
|
|
|
new CefNetworkDelegate());
|
|
|
|
network_delegate->set_force_google_safesearch(&force_google_safesearch_);
|
|
|
|
storage_->set_network_delegate(std::move(network_delegate));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-02-18 19:10:44 +01:00
|
|
|
const std::string& accept_language =
|
2015-03-02 21:25:14 +01:00
|
|
|
settings_.accept_language_list.length > 0 ?
|
|
|
|
CefString(&settings_.accept_language_list): "en-US,en";
|
2016-04-27 22:38:52 +02:00
|
|
|
storage_->set_http_user_agent_settings(base::WrapUnique(
|
|
|
|
new CefHttpUserAgentSettings(accept_language)));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
storage_->set_host_resolver(
|
|
|
|
net::HostResolver::CreateDefaultResolver(net_log_));
|
2012-04-03 03:34:16 +02:00
|
|
|
storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
|
2016-11-18 22:11:38 +01:00
|
|
|
|
|
|
|
std::unique_ptr<net::TransportSecurityState> transport_security_state(
|
|
|
|
new net::TransportSecurityState);
|
|
|
|
transport_security_state->set_enforce_net_security_expiration(
|
|
|
|
settings_.enable_net_security_expiration ? true : false);
|
|
|
|
storage_->set_transport_security_state(std::move(transport_security_state));
|
2016-09-16 18:37:34 +02:00
|
|
|
|
|
|
|
std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs(
|
|
|
|
net::ct::CreateLogVerifiersForKnownLogs());
|
|
|
|
std::unique_ptr<net::MultiLogCTVerifier> ct_verifier(
|
|
|
|
new net::MultiLogCTVerifier());
|
|
|
|
ct_verifier->AddLogs(ct_logs);
|
|
|
|
storage_->set_cert_transparency_verifier(std::move(ct_verifier));
|
|
|
|
|
2016-11-18 22:11:38 +01:00
|
|
|
std::unique_ptr<net::CTPolicyEnforcer> ct_policy_enforcer(
|
|
|
|
new net::CTPolicyEnforcer);
|
|
|
|
ct_policy_enforcer->set_enforce_net_security_expiration(
|
|
|
|
settings_.enable_net_security_expiration ? true : false);
|
|
|
|
storage_->set_ct_policy_enforcer(std::move(ct_policy_enforcer));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::ProxyService> system_proxy_service =
|
2013-02-06 21:41:54 +01:00
|
|
|
ProxyServiceFactory::CreateProxyService(
|
2016-11-07 20:14:09 +01:00
|
|
|
net_log_,
|
2013-02-06 21:41:54 +01:00
|
|
|
url_request_context_.get(),
|
2013-04-02 19:21:37 +02:00
|
|
|
url_request_context_->network_delegate(),
|
2016-01-06 20:20:54 +01:00
|
|
|
std::move(proxy_config_service_),
|
2015-01-09 18:22:10 +01:00
|
|
|
*command_line,
|
2016-06-21 00:59:23 +02:00
|
|
|
quick_check_enabled_.GetValue(),
|
|
|
|
pac_https_url_stripping_enabled_.GetValue());
|
2016-01-06 20:20:54 +01:00
|
|
|
storage_->set_proxy_service(std::move(system_proxy_service));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
|
|
|
|
|
|
|
|
std::vector<std::string> supported_schemes;
|
|
|
|
supported_schemes.push_back("basic");
|
|
|
|
supported_schemes.push_back("digest");
|
|
|
|
supported_schemes.push_back("ntlm");
|
|
|
|
supported_schemes.push_back("negotiate");
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
http_auth_preferences_.reset(
|
|
|
|
new net::HttpAuthPreferences(supported_schemes
|
|
|
|
#if defined(OS_POSIX) && !defined(OS_ANDROID)
|
|
|
|
, gsapi_library_name_
|
|
|
|
#endif
|
|
|
|
));
|
|
|
|
|
|
|
|
storage_->set_http_auth_handler_factory(
|
2012-04-03 03:34:16 +02:00
|
|
|
net::HttpAuthHandlerRegistryFactory::Create(
|
2015-12-09 17:10:16 +01:00
|
|
|
http_auth_preferences_.get(),
|
|
|
|
url_request_context_->host_resolver()));
|
2016-04-27 22:38:52 +02:00
|
|
|
storage_->set_http_server_properties(base::WrapUnique(
|
|
|
|
new net::HttpServerPropertiesImpl));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-07-12 21:00:12 +02:00
|
|
|
base::FilePath http_cache_path;
|
|
|
|
if (!cache_path.empty())
|
|
|
|
http_cache_path = cache_path.Append(FILE_PATH_LITERAL("Cache"));
|
2016-10-27 18:52:54 +02:00
|
|
|
|
|
|
|
UpdateServerWhitelist();
|
|
|
|
UpdateDelegateWhitelist();
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::HttpCache::DefaultBackend> main_backend(
|
2012-04-03 03:34:16 +02:00
|
|
|
new net::HttpCache::DefaultBackend(
|
2012-05-18 17:04:56 +02:00
|
|
|
cache_path.empty() ? net::MEMORY_CACHE : net::DISK_CACHE,
|
2013-06-04 19:41:37 +02:00
|
|
|
net::CACHE_BACKEND_DEFAULT,
|
2016-07-12 21:00:12 +02:00
|
|
|
http_cache_path,
|
2012-04-03 03:34:16 +02:00
|
|
|
0,
|
2016-07-21 23:21:32 +02:00
|
|
|
BrowserThread::GetTaskRunnerForThread(
|
2015-11-10 21:18:16 +01:00
|
|
|
BrowserThread::CACHE)));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-10-03 21:52:50 +02:00
|
|
|
net::HttpNetworkSession::Params network_session_params;
|
|
|
|
network_session_params.host_resolver =
|
|
|
|
url_request_context_->host_resolver();
|
|
|
|
network_session_params.cert_verifier =
|
|
|
|
url_request_context_->cert_verifier();
|
2013-06-22 04:06:32 +02:00
|
|
|
network_session_params.transport_security_state =
|
|
|
|
url_request_context_->transport_security_state();
|
2016-07-06 21:34:09 +02:00
|
|
|
network_session_params.cert_transparency_verifier =
|
|
|
|
url_request_context_->cert_transparency_verifier();
|
|
|
|
network_session_params.ct_policy_enforcer =
|
|
|
|
url_request_context_->ct_policy_enforcer();
|
2012-10-03 21:52:50 +02:00
|
|
|
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_auth_handler_factory =
|
|
|
|
url_request_context_->http_auth_handler_factory();
|
|
|
|
network_session_params.http_server_properties =
|
|
|
|
url_request_context_->http_server_properties();
|
|
|
|
network_session_params.ignore_certificate_errors =
|
2015-03-02 21:25:14 +01:00
|
|
|
settings_.ignore_certificate_errors ? true : false;
|
2016-11-07 20:14:09 +01:00
|
|
|
network_session_params.net_log = net_log_;
|
2012-10-03 21:52:50 +02:00
|
|
|
|
2015-11-10 21:18:16 +01:00
|
|
|
storage_->set_http_network_session(
|
2016-05-25 01:35:43 +02:00
|
|
|
base::WrapUnique(new net::HttpNetworkSession(network_session_params)));
|
|
|
|
storage_->set_http_transaction_factory(base::WrapUnique(
|
2015-11-10 21:18:16 +01:00
|
|
|
new net::HttpCache(storage_->http_network_session(),
|
2016-01-06 20:20:54 +01:00
|
|
|
std::move(main_backend),
|
2015-11-10 21:18:16 +01:00
|
|
|
true /* set_up_quic_server_info */)));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory(
|
2013-02-23 01:43:28 +01:00
|
|
|
new net::URLRequestJobFactoryImpl());
|
2015-03-02 21:25:14 +01:00
|
|
|
url_request_manager_.reset(new CefURLRequestManager(job_factory.get()));
|
2013-03-12 21:23:24 +01:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Install internal scheme handlers that cannot be overridden.
|
2016-11-23 21:54:29 +01:00
|
|
|
scheme::InstallInternalProtectedHandlers(
|
|
|
|
job_factory.get(),
|
|
|
|
url_request_manager_.get(),
|
|
|
|
&protocol_handlers_,
|
|
|
|
network_session_params.host_resolver);
|
2013-03-12 21:23:24 +01:00
|
|
|
protocol_handlers_.clear();
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Register internal scheme handlers that can be overridden.
|
|
|
|
scheme::RegisterInternalHandlers(url_request_manager_.get());
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
request_interceptors_.push_back(base::MakeUnique<CefRequestInterceptor>());
|
2014-12-13 21:18:31 +01:00
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
// Set up interceptors in the reverse order.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::URLRequestJobFactory> top_job_factory =
|
2016-01-06 20:20:54 +01:00
|
|
|
std::move(job_factory);
|
2017-01-23 18:36:54 +01:00
|
|
|
for (auto i = request_interceptors_.rbegin();
|
|
|
|
i != request_interceptors_.rend(); ++i) {
|
2014-06-12 22:28:58 +02:00
|
|
|
top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
|
2017-01-23 18:36:54 +01:00
|
|
|
std::move(top_job_factory), std::move(*i)));
|
2014-04-04 18:50:38 +02:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
request_interceptors_.clear();
|
2014-04-04 18:50:38 +02:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
storage_->set_job_factory(std::move(top_job_factory));
|
2015-01-21 00:57:30 +01:00
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2015-03-02 21:25:14 +01:00
|
|
|
// Only do this for the first (global) request context.
|
|
|
|
static bool request_context_for_nss_set = false;
|
|
|
|
if (!request_context_for_nss_set) {
|
|
|
|
net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
|
|
|
|
request_context_for_nss_set = true;
|
|
|
|
}
|
2015-01-21 00:57:30 +01:00
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
return url_request_context_.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-06-22 00:50:34 +02:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner>
|
2015-02-14 00:17:08 +01:00
|
|
|
CefURLRequestContextGetterImpl::GetNetworkTaskRunner() const {
|
2016-07-21 23:21:32 +02:00
|
|
|
return BrowserThread::GetTaskRunnerForThread(CEF_IOT);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
net::HostResolver* CefURLRequestContextGetterImpl::GetHostResolver() const {
|
2012-04-03 03:34:16 +02:00
|
|
|
return url_request_context_->host_resolver();
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
void CefURLRequestContextGetterImpl::SetCookieStoragePath(
|
2013-02-23 01:43:28 +01:00
|
|
|
const base::FilePath& path,
|
2013-02-13 20:53:41 +01:00
|
|
|
bool persist_session_cookies) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
if (url_request_context_->cookie_store() &&
|
|
|
|
((cookie_store_path_.empty() && path.empty()) ||
|
|
|
|
cookie_store_path_ == path)) {
|
|
|
|
// The path has not changed so don't do anything.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-06 00:06:48 +02:00
|
|
|
scoped_refptr<net::SQLitePersistentCookieStore> persistent_store;
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!path.empty()) {
|
2012-05-18 17:04:56 +02:00
|
|
|
// TODO(cef): Move directory creation to the blocking pool instead of
|
|
|
|
// allowing file IO on this thread.
|
2012-05-18 22:32:28 +02:00
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
2013-07-24 22:15:18 +02:00
|
|
|
if (base::DirectoryExists(path) ||
|
2013-12-17 23:04:35 +01:00
|
|
|
base::CreateDirectory(path)) {
|
2013-02-23 01:43:28 +01:00
|
|
|
const base::FilePath& cookie_path = path.AppendASCII("Cookies");
|
2012-05-31 17:19:33 +02:00
|
|
|
persistent_store =
|
2015-06-06 00:06:48 +02:00
|
|
|
new net::SQLitePersistentCookieStore(
|
2013-03-12 21:23:24 +01:00
|
|
|
cookie_path,
|
2016-07-21 23:21:32 +02:00
|
|
|
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
|
|
|
|
BrowserThread::GetTaskRunnerForThread(BrowserThread::DB),
|
2013-03-12 21:23:24 +01:00
|
|
|
persist_session_cookies,
|
2014-02-05 21:35:45 +01:00
|
|
|
NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
NOTREACHED() << "The cookie storage directory could not be created";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the new cookie store that will be used for all new requests. The old
|
|
|
|
// cookie store, if any, will be automatically flushed and closed when no
|
|
|
|
// longer referenced.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::CookieMonster> cookie_monster(
|
2016-03-16 03:55:59 +01:00
|
|
|
new net::CookieMonster(persistent_store.get(), NULL));
|
2013-02-13 20:53:41 +01:00
|
|
|
if (persistent_store.get() && persist_session_cookies)
|
|
|
|
cookie_monster->SetPersistSessionCookies(true);
|
2012-04-03 03:34:16 +02:00
|
|
|
cookie_store_path_ = path;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
// Restore the previously supported schemes.
|
2015-08-21 22:17:59 +02:00
|
|
|
CefCookieManagerImpl::SetCookieMonsterSchemes(cookie_monster.get(),
|
|
|
|
cookie_supported_schemes_);
|
2016-03-16 03:55:59 +01:00
|
|
|
|
|
|
|
storage_->set_cookie_store(std::move(cookie_monster));
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
void CefURLRequestContextGetterImpl::SetCookieSupportedSchemes(
|
2016-02-05 01:49:19 +01:00
|
|
|
const std::vector<std::string>& schemes) {
|
2012-06-19 18:29:49 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
cookie_supported_schemes_ = schemes;
|
2016-03-16 03:55:59 +01:00
|
|
|
CefCookieManagerImpl::SetCookieMonsterSchemes(
|
|
|
|
static_cast<net::CookieMonster*>(GetExistingCookieStore()),
|
|
|
|
cookie_supported_schemes_);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void CefURLRequestContextGetterImpl::AddHandler(
|
|
|
|
CefRefPtr<CefRequestContextHandler> handler) {
|
|
|
|
if (!CEF_CURRENTLY_ON_IOT()) {
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefURLRequestContextGetterImpl::AddHandler, this, handler));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handler_list_.push_back(handler);
|
|
|
|
}
|
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
net::CookieStore*
|
|
|
|
CefURLRequestContextGetterImpl::GetExistingCookieStore() const {
|
2015-08-21 22:17:59 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
2016-03-16 03:55:59 +01:00
|
|
|
if (url_request_context_ && url_request_context_->cookie_store())
|
|
|
|
return url_request_context_->cookie_store();
|
|
|
|
|
|
|
|
LOG(ERROR) << "Cookie store does not exist";
|
|
|
|
return nullptr;
|
2015-08-21 22:17:59 +02:00
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
void CefURLRequestContextGetterImpl::CreateProxyConfigService() {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (proxy_config_service_.get())
|
|
|
|
return;
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
proxy_config_service_ =
|
2012-05-31 17:19:33 +02:00
|
|
|
net::ProxyService::CreateSystemProxyConfigService(
|
2016-03-16 03:55:59 +01:00
|
|
|
io_task_runner_, file_task_runner_);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2016-10-27 18:52:54 +02:00
|
|
|
|
|
|
|
void CefURLRequestContextGetterImpl::UpdateServerWhitelist() {
|
|
|
|
http_auth_preferences_->set_server_whitelist(
|
|
|
|
auth_server_whitelist_.GetValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefURLRequestContextGetterImpl::UpdateDelegateWhitelist() {
|
|
|
|
http_auth_preferences_->set_delegate_whitelist(
|
|
|
|
auth_negotiate_delegate_whitelist_.GetValue());
|
|
|
|
}
|