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.
|
|
|
|
|
|
|
|
#include "libcef/browser/url_request_context_getter.h"
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <winhttp.h>
|
|
|
|
#endif
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/context.h"
|
2013-06-04 19:41:37 +02:00
|
|
|
#include "libcef/browser/scheme_handler.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
#include "libcef/browser/url_network_delegate.h"
|
2012-06-28 19:21:18 +02:00
|
|
|
#include "libcef/browser/url_request_context_proxy.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/url_request_interceptor.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"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/file_util.h"
|
|
|
|
#include "base/logging.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"
|
2013-02-06 21:41:54 +01:00
|
|
|
#include "chrome/browser/net/proxy_service_factory.h"
|
2013-04-16 00:16:01 +02:00
|
|
|
#include "content/browser/net/sqlite_persistent_cookie_store.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-12-17 23:04:35 +01:00
|
|
|
#include "content/public/browser/cookie_crypto_delegate.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"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/cookies/cookie_monster.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"
|
|
|
|
#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/default_server_bound_cert_store.h"
|
|
|
|
#include "net/ssl/server_bound_cert_service.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CefHttpUserAgentSettings() {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
}
|
|
|
|
|
|
|
|
// net::HttpUserAgentSettings implementation
|
|
|
|
virtual std::string GetAcceptLanguage() const OVERRIDE {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
return http_accept_language_;
|
|
|
|
}
|
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
virtual 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
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefURLRequestContextGetter::CefURLRequestContextGetter(
|
2013-04-16 00:16:01 +02:00
|
|
|
base::MessageLoop* io_loop,
|
|
|
|
base::MessageLoop* file_loop,
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-06-12 22:28:58 +02:00
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors)
|
2013-02-14 00:43:16 +01:00
|
|
|
: io_loop_(io_loop),
|
2014-04-04 18:50:38 +02:00
|
|
|
file_loop_(file_loop),
|
2014-06-12 22:28:58 +02:00
|
|
|
request_interceptors_(request_interceptors.Pass()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// Must first be created on the UI thread.
|
|
|
|
CEF_REQUIRE_UIT();
|
2013-03-12 21:23:24 +01:00
|
|
|
|
|
|
|
std::swap(protocol_handlers_, *protocol_handlers);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefURLRequestContextGetter::~CefURLRequestContextGetter() {
|
2012-12-04 02:12:11 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
2012-06-28 19:21:18 +02:00
|
|
|
STLDeleteElements(&url_request_context_proxies_);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContext* CefURLRequestContextGetter::GetURLRequestContext() {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
if (!url_request_context_.get()) {
|
2013-09-03 20:06:25 +02:00
|
|
|
const base::FilePath& cache_path = CefContext::Get()->cache_path();
|
2013-02-06 21:41:54 +01:00
|
|
|
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
|
2013-09-03 20:06:25 +02:00
|
|
|
const CefSettings& settings = CefContext::Get()->settings();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
url_request_context_.reset(new net::URLRequestContext());
|
|
|
|
storage_.reset(
|
|
|
|
new net::URLRequestContextStorage(url_request_context_.get()));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-02-13 20:53:41 +01:00
|
|
|
bool persist_session_cookies =
|
|
|
|
(settings.persist_session_cookies ||
|
|
|
|
command_line.HasSwitch(switches::kPersistSessionCookies));
|
|
|
|
SetCookieStoragePath(cache_path, persist_session_cookies);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
storage_->set_network_delegate(new CefNetworkDelegate);
|
|
|
|
|
|
|
|
storage_->set_server_bound_cert_service(new net::ServerBoundCertService(
|
2012-05-18 17:04:56 +02:00
|
|
|
new net::DefaultServerBoundCertStore(NULL),
|
|
|
|
base::WorkerPool::GetTaskRunner(true)));
|
2012-11-16 03:58:25 +01:00
|
|
|
storage_->set_http_user_agent_settings(
|
2013-10-30 18:42:05 +01:00
|
|
|
new CefHttpUserAgentSettings("en-us,en"));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-11-05 21:18:20 +01:00
|
|
|
storage_->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL));
|
2012-04-03 03:34:16 +02:00
|
|
|
storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
|
2013-06-22 04:06:32 +02:00
|
|
|
storage_->set_transport_security_state(new net::TransportSecurityState);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-02-06 21:41:54 +01:00
|
|
|
scoped_ptr<net::ProxyService> system_proxy_service;
|
|
|
|
system_proxy_service.reset(
|
|
|
|
ProxyServiceFactory::CreateProxyService(
|
|
|
|
NULL,
|
|
|
|
url_request_context_.get(),
|
2013-04-02 19:21:37 +02:00
|
|
|
url_request_context_->network_delegate(),
|
2013-09-03 18:43:31 +02:00
|
|
|
CefContentBrowserClient::Get()->proxy_config_service().release(),
|
2014-01-02 23:41:11 +01:00
|
|
|
command_line,
|
|
|
|
true));
|
2013-02-06 21:41:54 +01:00
|
|
|
storage_->set_proxy_service(system_proxy_service.release());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
|
|
|
|
|
|
|
|
// Add support for single sign-on.
|
|
|
|
url_security_manager_.reset(net::URLSecurityManager::Create(NULL, NULL));
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
storage_->set_http_auth_handler_factory(
|
|
|
|
net::HttpAuthHandlerRegistryFactory::Create(
|
|
|
|
supported_schemes,
|
|
|
|
url_security_manager_.get(),
|
|
|
|
url_request_context_->host_resolver(),
|
|
|
|
std::string(),
|
|
|
|
false,
|
|
|
|
false));
|
2013-07-24 22:15:18 +02:00
|
|
|
storage_->set_http_server_properties(
|
|
|
|
make_scoped_ptr<net::HttpServerProperties>(
|
|
|
|
new net::HttpServerPropertiesImpl));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
net::HttpCache::DefaultBackend* main_backend =
|
|
|
|
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,
|
2012-04-03 03:34:16 +02:00
|
|
|
cache_path,
|
|
|
|
0,
|
|
|
|
BrowserThread::GetMessageLoopProxyForThread(
|
|
|
|
BrowserThread::CACHE));
|
|
|
|
|
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();
|
2012-10-03 21:52:50 +02:00
|
|
|
network_session_params.server_bound_cert_service =
|
|
|
|
url_request_context_->server_bound_cert_service();
|
|
|
|
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.network_delegate =
|
|
|
|
url_request_context_->network_delegate();
|
|
|
|
network_session_params.http_server_properties =
|
|
|
|
url_request_context_->http_server_properties();
|
|
|
|
network_session_params.ignore_certificate_errors =
|
2013-02-14 00:43:16 +01:00
|
|
|
(settings.ignore_certificate_errors ||
|
|
|
|
command_line.HasSwitch(switches::kIgnoreCertificateErrors));
|
2012-10-03 21:52:50 +02:00
|
|
|
|
|
|
|
net::HttpCache* main_cache = new net::HttpCache(network_session_params,
|
|
|
|
main_backend);
|
2012-04-03 03:34:16 +02:00
|
|
|
storage_->set_http_transaction_factory(main_cache);
|
|
|
|
|
2013-06-24 20:57:05 +02:00
|
|
|
#if !defined(DISABLE_FTP_SUPPORT)
|
|
|
|
ftp_transaction_factory_.reset(
|
|
|
|
new net::FtpNetworkLayer(network_session_params.host_resolver));
|
|
|
|
#endif
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
|
|
|
|
new net::URLRequestJobFactoryImpl());
|
2013-02-27 18:56:03 +01:00
|
|
|
job_factory_impl_ = job_factory.get();
|
2013-03-12 21:23:24 +01:00
|
|
|
|
|
|
|
scheme::InstallInternalProtectedHandlers(job_factory.get(),
|
2013-06-24 20:57:05 +02:00
|
|
|
&protocol_handlers_,
|
|
|
|
ftp_transaction_factory_.get());
|
2013-03-12 21:23:24 +01:00
|
|
|
protocol_handlers_.clear();
|
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
// Set up interceptors in the reverse order.
|
|
|
|
scoped_ptr<net::URLRequestJobFactory> top_job_factory =
|
|
|
|
job_factory.PassAs<net::URLRequestJobFactory>();
|
2014-06-12 22:28:58 +02:00
|
|
|
for (content::URLRequestInterceptorScopedVector::reverse_iterator i =
|
|
|
|
request_interceptors_.rbegin();
|
|
|
|
i != request_interceptors_.rend();
|
2014-04-04 18:50:38 +02:00
|
|
|
++i) {
|
2014-06-12 22:28:58 +02:00
|
|
|
top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
|
2014-04-04 18:50:38 +02:00
|
|
|
top_job_factory.Pass(), make_scoped_ptr(*i)));
|
|
|
|
}
|
2014-06-12 22:28:58 +02:00
|
|
|
request_interceptors_.weak_clear();
|
2014-04-04 18:50:38 +02:00
|
|
|
|
|
|
|
storage_->set_job_factory(top_job_factory.release());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
request_interceptor_.reset(new CefRequestInterceptor);
|
|
|
|
}
|
|
|
|
|
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>
|
|
|
|
CefURLRequestContextGetter::GetNetworkTaskRunner() const {
|
2012-04-03 03:34:16 +02:00
|
|
|
return BrowserThread::GetMessageLoopProxyForThread(CEF_IOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
net::HostResolver* CefURLRequestContextGetter::host_resolver() {
|
|
|
|
return url_request_context_->host_resolver();
|
|
|
|
}
|
|
|
|
|
2013-02-13 20:53:41 +01:00
|
|
|
void CefURLRequestContextGetter::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;
|
|
|
|
}
|
|
|
|
|
2013-04-16 00:16:01 +02:00
|
|
|
scoped_refptr<content::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 =
|
2013-04-16 00:16:01 +02:00
|
|
|
new content::SQLitePersistentCookieStore(
|
2013-03-12 21:23:24 +01:00
|
|
|
cookie_path,
|
|
|
|
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
|
|
|
|
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
|
|
|
|
persist_session_cookies,
|
2013-12-17 23:04:35 +01:00
|
|
|
NULL,
|
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.
|
2013-02-13 20:53:41 +01:00
|
|
|
scoped_refptr<net::CookieMonster> cookie_monster =
|
|
|
|
new net::CookieMonster(persistent_store.get(), NULL);
|
|
|
|
storage_->set_cookie_store(cookie_monster);
|
|
|
|
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.
|
|
|
|
SetCookieSupportedSchemes(cookie_supported_schemes_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefURLRequestContextGetter::SetCookieSupportedSchemes(
|
|
|
|
const std::vector<std::string>& schemes) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
cookie_supported_schemes_ = schemes;
|
|
|
|
|
|
|
|
if (cookie_supported_schemes_.empty()) {
|
|
|
|
cookie_supported_schemes_.push_back("http");
|
|
|
|
cookie_supported_schemes_.push_back("https");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<std::string> scheme_set;
|
|
|
|
std::vector<std::string>::const_iterator it =
|
|
|
|
cookie_supported_schemes_.begin();
|
|
|
|
for (; it != cookie_supported_schemes_.end(); ++it)
|
|
|
|
scheme_set.insert(*it);
|
|
|
|
|
|
|
|
const char** arr = new const char*[scheme_set.size()];
|
|
|
|
std::set<std::string>::const_iterator it2 = scheme_set.begin();
|
|
|
|
for (int i = 0; it2 != scheme_set.end(); ++it2, ++i)
|
|
|
|
arr[i] = it2->c_str();
|
|
|
|
|
|
|
|
url_request_context_->cookie_store()->GetCookieMonster()->
|
|
|
|
SetCookieableSchemes(arr, scheme_set.size());
|
|
|
|
|
|
|
|
delete [] arr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
CefURLRequestContextProxy*
|
|
|
|
CefURLRequestContextGetter::CreateURLRequestContextProxy() {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
CefURLRequestContextProxy* proxy = new CefURLRequestContextProxy(this);
|
|
|
|
url_request_context_proxies_.insert(proxy);
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefURLRequestContextGetter::ReleaseURLRequestContextProxy(
|
|
|
|
CefURLRequestContextProxy* proxy) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
// Don't do anything if we're currently shutting down. The proxy objects will
|
|
|
|
// be deleted when this object is destroyed.
|
2013-09-03 20:06:25 +02:00
|
|
|
if (CefContext::Get()->shutting_down())
|
2012-06-28 19:21:18 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (proxy->url_requests()->size() == 0) {
|
|
|
|
// Safe to delete the proxy.
|
|
|
|
RequestContextProxySet::iterator it =
|
|
|
|
url_request_context_proxies_.find(proxy);
|
|
|
|
DCHECK(it != url_request_context_proxies_.end());
|
|
|
|
url_request_context_proxies_.erase(it);
|
|
|
|
delete proxy;
|
|
|
|
} else {
|
|
|
|
proxy->increment_delete_try_count();
|
|
|
|
if (proxy->delete_try_count() <= 1) {
|
|
|
|
// Cancel the pending requests. This may result in additional tasks being
|
|
|
|
// posted on the IO thread.
|
|
|
|
std::set<const net::URLRequest*>::iterator it =
|
|
|
|
proxy->url_requests()->begin();
|
|
|
|
for (; it != proxy->url_requests()->end(); ++it)
|
|
|
|
const_cast<net::URLRequest*>(*it)->Cancel();
|
|
|
|
|
|
|
|
// Try to delete the proxy again later.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefURLRequestContextGetter::ReleaseURLRequestContextProxy,
|
|
|
|
this, proxy));
|
|
|
|
} else {
|
|
|
|
NOTREACHED() <<
|
|
|
|
"too many retries to delete URLRequestContext proxy object";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefURLRequestContextGetter::CreateProxyConfigService() {
|
|
|
|
if (proxy_config_service_.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
proxy_config_service_.reset(
|
2012-05-31 17:19:33 +02:00
|
|
|
net::ProxyService::CreateSystemProxyConfigService(
|
|
|
|
io_loop_->message_loop_proxy(), file_loop_));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|