2015-02-14 00:17:08 +01:00
|
|
|
// Copyright (c) 2015 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/resource_context.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
|
|
|
|
#include "libcef/browser/net/url_request_context_getter.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
|
2015-05-19 19:55:58 +02:00
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
#include "net/ssl/client_cert_store_nss.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "net/ssl/client_cert_store_win.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
#include "net/ssl/client_cert_store_mac.h"
|
|
|
|
#endif
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
CefResourceContext::CefResourceContext(
|
|
|
|
bool is_off_the_record,
|
2015-09-25 13:59:30 +02:00
|
|
|
extensions::InfoMap* extension_info_map,
|
|
|
|
CefRefPtr<CefRequestContextHandler> handler)
|
2015-07-16 23:40:01 +02:00
|
|
|
: is_off_the_record_(is_off_the_record),
|
2015-09-25 13:59:30 +02:00
|
|
|
extension_info_map_(extension_info_map),
|
|
|
|
handler_(handler) {
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefResourceContext::~CefResourceContext() {
|
|
|
|
if (getter_.get()) {
|
|
|
|
// When the parent object (ResourceContext) destructor executes all
|
|
|
|
// associated URLRequests should be destroyed. If there are no other
|
|
|
|
// references it should then be safe to destroy the URLRequestContextGetter
|
|
|
|
// which owns the URLRequestContext.
|
|
|
|
getter_->AddRef();
|
|
|
|
CefURLRequestContextGetter* raw_getter = getter_.get();
|
|
|
|
getter_ = NULL;
|
|
|
|
content::BrowserThread::ReleaseSoon(
|
|
|
|
content::BrowserThread::IO, FROM_HERE, raw_getter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
net::HostResolver* CefResourceContext::GetHostResolver() {
|
|
|
|
CHECK(getter_.get());
|
|
|
|
return getter_->GetHostResolver();
|
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContext* CefResourceContext::GetRequestContext() {
|
|
|
|
CHECK(getter_.get());
|
|
|
|
return getter_->GetURLRequestContext();
|
|
|
|
}
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
std::unique_ptr<net::ClientCertStore>
|
|
|
|
CefResourceContext::CreateClientCertStore() {
|
2015-05-19 19:55:58 +02:00
|
|
|
#if defined(USE_NSS_CERTS)
|
2016-04-27 22:38:52 +02:00
|
|
|
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreNSS(
|
2015-05-19 19:55:58 +02:00
|
|
|
net::ClientCertStoreNSS::PasswordDelegateFactory()));
|
|
|
|
#elif defined(OS_WIN)
|
2016-04-27 22:38:52 +02:00
|
|
|
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreWin());
|
2015-05-19 19:55:58 +02:00
|
|
|
#elif defined(OS_MACOSX)
|
2016-04-27 22:38:52 +02:00
|
|
|
return std::unique_ptr<net::ClientCertStore>(new net::ClientCertStoreMac());
|
2015-05-19 19:55:58 +02:00
|
|
|
#elif defined(USE_OPENSSL)
|
|
|
|
// OpenSSL does not use the ClientCertStore infrastructure. On Android client
|
|
|
|
// cert matching is done by the OS as part of the call to show the cert
|
|
|
|
// selection dialog.
|
2016-04-27 22:38:52 +02:00
|
|
|
return std::unique_ptr<net::ClientCertStore>();
|
2015-05-19 19:55:58 +02:00
|
|
|
#else
|
|
|
|
#error Unknown platform.
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
void CefResourceContext::set_url_request_context_getter(
|
2016-08-24 11:28:52 +02:00
|
|
|
CefURLRequestContextGetter* getter) {
|
2015-02-14 00:17:08 +01:00
|
|
|
DCHECK(!getter_.get());
|
|
|
|
getter_ = getter;
|
|
|
|
}
|