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
|
|
|
|
|
2019-03-24 00:40:32 +01:00
|
|
|
CefResourceContext::CefResourceContext(bool is_off_the_record)
|
|
|
|
: is_off_the_record_(is_off_the_record) {}
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefResourceContext::~CefResourceContext() {}
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
std::unique_ptr<net::ClientCertStore>
|
2017-05-17 11:29:28 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void CefResourceContext::set_extensions_info_map(
|
|
|
|
extensions::InfoMap* extensions_info_map) {
|
|
|
|
DCHECK(!extension_info_map_);
|
|
|
|
extension_info_map_ = extensions_info_map;
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:40:32 +01:00
|
|
|
void CefResourceContext::AddHandler(
|
|
|
|
int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
CefRefPtr<CefRequestContextHandler> handler) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
DCHECK_GE(render_process_id, 0);
|
|
|
|
DCHECK(handler);
|
|
|
|
|
|
|
|
handler_map_.insert(std::make_pair(
|
|
|
|
std::make_pair(render_process_id, render_frame_id), handler));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefResourceContext::RemoveHandler(int render_process_id,
|
|
|
|
int render_frame_id) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
DCHECK_GE(render_process_id, 0);
|
|
|
|
|
|
|
|
HandlerMap::iterator it =
|
|
|
|
handler_map_.find(std::make_pair(render_process_id, render_frame_id));
|
|
|
|
if (it != handler_map_.end())
|
|
|
|
handler_map_.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContextHandler> CefResourceContext::GetHandler(
|
|
|
|
int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
bool require_frame_match) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
DCHECK_GE(render_process_id, 0);
|
|
|
|
|
|
|
|
HandlerMap::const_iterator it =
|
|
|
|
handler_map_.find(std::make_pair(render_process_id, render_frame_id));
|
|
|
|
if (it != handler_map_.end())
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
if (!require_frame_match) {
|
|
|
|
// Choose an arbitrary handler for the same process.
|
|
|
|
for (auto& kv : handler_map_) {
|
|
|
|
if (kv.first.first == render_process_id)
|
|
|
|
return kv.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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,
|
2017-12-07 22:44:24 +01:00
|
|
|
chrome::mojom::PluginStatus status) {
|
2016-10-17 20:14:44 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
DCHECK_GE(render_process_id, 0);
|
|
|
|
DCHECK(!plugin_path.empty());
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
plugin_load_decision_map_.insert(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,
|
2017-12-07 22:44:24 +01:00
|
|
|
chrome::mojom::PluginStatus* status) const {
|
2016-10-17 20:14:44 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
DCHECK_GE(render_process_id, 0);
|
|
|
|
DCHECK(!plugin_path.empty());
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
PluginLoadDecisionMap::const_iterator it = plugin_load_decision_map_.find(
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|