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"
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "content/browser/resource_context_impl.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#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
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool ShouldProxyUserData(const void* key) {
|
|
|
|
// If this value is not proxied WebUI will fail to load.
|
|
|
|
if (key == content::GetURLDataManagerBackendUserDataKey())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
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)
|
2016-11-07 20:14:09 +01:00
|
|
|
: parent_(nullptr),
|
|
|
|
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() {
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
base::SupportsUserData::Data* CefResourceContext::GetUserData(const void* key)
|
|
|
|
const {
|
|
|
|
if (parent_ && ShouldProxyUserData(key))
|
|
|
|
return parent_->GetUserData(key);
|
|
|
|
return content::ResourceContext::GetUserData(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefResourceContext::SetUserData(const void* key, Data* data) {
|
|
|
|
if (parent_ && ShouldProxyUserData(key))
|
|
|
|
parent_->SetUserData(key, data);
|
|
|
|
else
|
|
|
|
content::ResourceContext::SetUserData(key, data);
|
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
void CefResourceContext::SetUserData(const void* key,
|
|
|
|
std::unique_ptr<Data> data) {
|
|
|
|
if (parent_ && ShouldProxyUserData(key))
|
|
|
|
parent_->SetUserData(key, std::move(data));
|
|
|
|
else
|
|
|
|
content::ResourceContext::SetUserData(key, std::move(data));
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
void CefResourceContext::RemoveUserData(const void* key) {
|
|
|
|
if (parent_ && ShouldProxyUserData(key))
|
|
|
|
parent_->RemoveUserData(key);
|
|
|
|
else
|
|
|
|
content::ResourceContext::RemoveUserData(key);
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
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;
|
|
|
|
}
|
2016-10-17 20:14:44 +02:00
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
void CefResourceContext::set_parent(CefResourceContext* parent) {
|
|
|
|
DCHECK(!parent_);
|
|
|
|
DCHECK(parent);
|
|
|
|
parent_ = parent;
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
void CefResourceContext::AddPluginLoadDecision(
|
|
|
|
int render_process_id,
|
|
|
|
const base::FilePath& plugin_path,
|
2017-01-19 00:37:56 +01:00
|
|
|
bool is_main_frame,
|
|
|
|
const url::Origin& main_frame_origin,
|
|
|
|
CefViewHostMsg_GetPluginInfo_Status status) {
|
2016-10-17 20:14:44 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
DCHECK_GE(render_process_id, 0);
|
|
|
|
DCHECK(!plugin_path.empty());
|
|
|
|
|
|
|
|
plugin_load_decision_map_.insert(
|
2017-01-19 00:37:56 +01:00
|
|
|
std::make_pair(
|
|
|
|
std::make_pair(std::make_pair(render_process_id, plugin_path),
|
|
|
|
std::make_pair(is_main_frame, main_frame_origin)),
|
|
|
|
status));
|
2016-10-17 20:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefResourceContext::HasPluginLoadDecision(
|
|
|
|
int render_process_id,
|
|
|
|
const base::FilePath& plugin_path,
|
2017-01-19 00:37:56 +01:00
|
|
|
bool is_main_frame,
|
|
|
|
const url::Origin& main_frame_origin,
|
|
|
|
CefViewHostMsg_GetPluginInfo_Status* status) const {
|
2016-10-17 20:14:44 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
DCHECK_GE(render_process_id, 0);
|
|
|
|
DCHECK(!plugin_path.empty());
|
|
|
|
|
|
|
|
PluginLoadDecisionMap::const_iterator it =
|
|
|
|
plugin_load_decision_map_.find(
|
2017-01-19 00:37:56 +01:00
|
|
|
std::make_pair(std::make_pair(render_process_id, plugin_path),
|
|
|
|
std::make_pair(is_main_frame, main_frame_origin)));
|
2016-10-17 20:14:44 +02:00
|
|
|
if (it == plugin_load_decision_map_.end())
|
|
|
|
return false;
|
|
|
|
|
2017-01-19 00:37:56 +01:00
|
|
|
*status = it->second;
|
2016-10-17 20:14:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefResourceContext::ClearPluginLoadDecision(int render_process_id) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
if (render_process_id == -1) {
|
|
|
|
plugin_load_decision_map_.clear();
|
|
|
|
} else {
|
|
|
|
PluginLoadDecisionMap::iterator it = plugin_load_decision_map_.begin();
|
|
|
|
while (it != plugin_load_decision_map_.end()) {
|
2017-01-19 00:37:56 +01:00
|
|
|
if (it->first.first.first == render_process_id)
|
2016-10-17 20:14:44 +02:00
|
|
|
it = plugin_load_decision_map_.erase(it);
|
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|