2013-09-03 18:43:31 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2017-05-19 11:06:00 +02:00
|
|
|
#include "libcef/browser/request_context_impl.h"
|
2019-03-22 23:11:51 +01:00
|
|
|
#include "libcef/browser/browser_context.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/context.h"
|
2022-10-26 00:50:29 +02:00
|
|
|
#include "libcef/browser/prefs/pref_helper.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.h"
|
2017-09-21 13:57:40 +02:00
|
|
|
#include "libcef/common/task_runner_impl.h"
|
2023-05-25 13:15:06 +02:00
|
|
|
#include "libcef/common/values_impl.h"
|
2015-09-25 13:59:30 +02:00
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "base/atomic_sequence_num.h"
|
|
|
|
#include "base/logging.h"
|
2015-10-03 01:03:16 +02:00
|
|
|
#include "base/strings/stringprintf.h"
|
2023-05-25 13:15:06 +02:00
|
|
|
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
2020-07-01 02:57:00 +02:00
|
|
|
#include "chrome/browser/profiles/profile.h"
|
2023-05-25 13:15:06 +02:00
|
|
|
#include "components/content_settings/core/browser/host_content_settings_map.h"
|
2016-02-05 01:49:19 +01:00
|
|
|
#include "components/prefs/pref_service.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "content/public/browser/child_process_host.h"
|
2016-02-23 20:29:18 +01:00
|
|
|
#include "content/public/browser/ssl_host_state_delegate.h"
|
2022-09-26 21:30:45 +02:00
|
|
|
#include "mojo/public/cpp/bindings/receiver.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
2021-08-20 01:40:49 +02:00
|
|
|
#include "net/dns/host_resolver.h"
|
2019-05-18 19:41:14 +02:00
|
|
|
#include "services/network/public/cpp/resolve_host_client_base.h"
|
2023-11-21 20:17:55 +01:00
|
|
|
#include "services/network/public/mojom/clear_data_filter.mojom.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "services/network/public/mojom/network_context.mojom.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
namespace {
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
base::AtomicSequenceNumber g_next_id;
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2019-05-18 19:41:14 +02:00
|
|
|
class ResolveHostHelper : public network::ResolveHostClientBase {
|
|
|
|
public:
|
|
|
|
explicit ResolveHostHelper(CefRefPtr<CefResolveCallback> callback)
|
2019-11-12 17:11:44 +01:00
|
|
|
: callback_(callback), receiver_(this) {}
|
2019-05-18 19:41:14 +02:00
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
ResolveHostHelper(const ResolveHostHelper&) = delete;
|
|
|
|
ResolveHostHelper& operator=(const ResolveHostHelper&) = delete;
|
|
|
|
|
2019-05-18 19:41:14 +02:00
|
|
|
void Start(CefBrowserContext* browser_context, const CefString& origin) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
browser_context->GetNetworkContext()->CreateHostResolver(
|
2022-09-26 21:30:45 +02:00
|
|
|
net::DnsConfigOverrides(), host_resolver_.BindNewPipeAndPassReceiver());
|
2019-05-18 19:41:14 +02:00
|
|
|
|
2020-02-10 18:10:17 +01:00
|
|
|
host_resolver_.set_disconnect_handler(base::BindOnce(
|
|
|
|
&ResolveHostHelper::OnComplete, base::Unretained(this), net::ERR_FAILED,
|
2022-09-26 21:30:45 +02:00
|
|
|
net::ResolveErrorInfo(net::ERR_FAILED), absl::nullopt, absl::nullopt));
|
2019-11-12 17:11:44 +01:00
|
|
|
|
2019-05-18 19:41:14 +02:00
|
|
|
host_resolver_->ResolveHost(
|
2022-09-26 21:30:45 +02:00
|
|
|
network::mojom::HostResolverHost::NewHostPortPair(
|
|
|
|
net::HostPortPair::FromURL(GURL(origin.ToString()))),
|
2022-10-17 19:27:40 +02:00
|
|
|
net::NetworkAnonymizationKey::CreateTransient(), nullptr,
|
2019-11-12 17:11:44 +01:00
|
|
|
receiver_.BindNewPipeAndPassRemote());
|
2019-05-18 19:41:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-09-26 21:30:45 +02:00
|
|
|
void OnComplete(int result,
|
|
|
|
const net::ResolveErrorInfo& resolve_error_info,
|
|
|
|
const absl::optional<net::AddressList>& resolved_addresses,
|
|
|
|
const absl::optional<net::HostResolverEndpointResults>&
|
|
|
|
endpoint_results_with_metadat) override {
|
2019-05-18 19:41:14 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
host_resolver_.reset();
|
2019-11-12 17:11:44 +01:00
|
|
|
receiver_.reset();
|
2019-05-18 19:41:14 +02:00
|
|
|
|
|
|
|
std::vector<CefString> resolved_ips;
|
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
if (result == net::OK && resolved_addresses.has_value()) {
|
|
|
|
DCHECK(!resolved_addresses->empty());
|
|
|
|
for (const auto& value : *resolved_addresses) {
|
2019-05-18 19:41:14 +02:00
|
|
|
resolved_ips.push_back(value.ToStringWithoutPort());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callback_->OnResolveCompleted(static_cast<cef_errorcode_t>(result),
|
|
|
|
resolved_ips);
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefResolveCallback> callback_;
|
|
|
|
|
2019-11-12 17:11:44 +01:00
|
|
|
mojo::Remote<network::mojom::HostResolver> host_resolver_;
|
2022-09-26 21:30:45 +02:00
|
|
|
mojo::Receiver<network::mojom::ResolveHostClient> receiver_{this};
|
2019-05-18 19:41:14 +02:00
|
|
|
};
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
CefBrowserContext* GetCefBrowserContext(
|
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
CefRefPtr<CefRequestContextImpl> request_context_impl =
|
|
|
|
CefRequestContextImpl::GetOrCreateForRequestContext(request_context);
|
|
|
|
CHECK(request_context_impl);
|
|
|
|
auto* cef_browser_context = request_context_impl->GetBrowserContext();
|
|
|
|
CHECK(cef_browser_context);
|
|
|
|
return cef_browser_context;
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
} // namespace
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// CefBrowserContext
|
|
|
|
|
|
|
|
// static
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefRequestContext> CefRequestContext::GetGlobalContext() {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "context not valid";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
CefRequestContextImpl::Config config;
|
|
|
|
config.is_global = true;
|
2017-05-04 23:53:27 +02:00
|
|
|
return CefRequestContextImpl::GetOrCreateRequestContext(config);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// static
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefRequestContext> CefRequestContext::CreateContext(
|
2015-03-02 21:25:14 +01:00
|
|
|
const CefRequestContextSettings& settings,
|
|
|
|
CefRefPtr<CefRequestContextHandler> handler) {
|
2013-09-03 18:43:31 +02:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "context not valid";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
CefRequestContextImpl::Config config;
|
|
|
|
config.settings = settings;
|
|
|
|
config.handler = handler;
|
|
|
|
config.unique_id = g_next_id.GetNext();
|
2017-05-04 23:53:27 +02:00
|
|
|
return CefRequestContextImpl::GetOrCreateRequestContext(config);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefRequestContext> CefRequestContext::CreateContext(
|
|
|
|
CefRefPtr<CefRequestContext> other,
|
|
|
|
CefRefPtr<CefRequestContextHandler> handler) {
|
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "context not valid";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!other.get()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
CefRequestContextImpl::Config config;
|
|
|
|
config.other = static_cast<CefRequestContextImpl*>(other.get());
|
|
|
|
config.handler = handler;
|
|
|
|
config.unique_id = g_next_id.GetNext();
|
2017-05-04 23:53:27 +02:00
|
|
|
return CefRequestContextImpl::GetOrCreateRequestContext(config);
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
// CefRequestContextImpl
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextImpl::~CefRequestContextImpl() {
|
2017-08-04 00:55:19 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
if (browser_context_) {
|
|
|
|
// May result in |browser_context_| being deleted if no other
|
2017-05-04 23:53:27 +02:00
|
|
|
// CefRequestContextImpl are referencing it.
|
2019-03-22 23:11:51 +01:00
|
|
|
browser_context_->RemoveCefRequestContext(this);
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefRequestContextImpl>
|
|
|
|
CefRequestContextImpl::CreateGlobalRequestContext(
|
|
|
|
const CefRequestContextSettings& settings) {
|
|
|
|
// Create and initialize the global context immediately.
|
|
|
|
Config config;
|
|
|
|
config.is_global = true;
|
|
|
|
config.settings = settings;
|
|
|
|
CefRefPtr<CefRequestContextImpl> impl = new CefRequestContextImpl(config);
|
2022-08-23 18:20:45 +02:00
|
|
|
impl->Initialize();
|
2017-05-04 23:53:27 +02:00
|
|
|
return impl;
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// static
|
2017-02-14 23:27:19 +01:00
|
|
|
CefRefPtr<CefRequestContextImpl>
|
|
|
|
CefRequestContextImpl::GetOrCreateForRequestContext(
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
|
|
|
if (request_context.get()) {
|
2015-03-02 21:25:14 +01:00
|
|
|
// Use the context from the provided CefRequestContext.
|
|
|
|
return static_cast<CefRequestContextImpl*>(request_context.get());
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Use the global context.
|
2017-05-04 23:53:27 +02:00
|
|
|
Config config;
|
2017-02-14 23:27:19 +01:00
|
|
|
config.is_global = true;
|
2017-05-04 23:53:27 +02:00
|
|
|
return CefRequestContextImpl::GetOrCreateRequestContext(config);
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
content::BrowserContext* CefRequestContextImpl::GetBrowserContext(
|
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
|
|
|
auto* browser_context =
|
|
|
|
GetCefBrowserContext(request_context)->AsBrowserContext();
|
|
|
|
CHECK(browser_context);
|
|
|
|
return browser_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
Profile* CefRequestContextImpl::GetProfile(
|
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
|
|
|
auto* profile = GetCefBrowserContext(request_context)->AsProfile();
|
|
|
|
CHECK(profile);
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
bool CefRequestContextImpl::VerifyBrowserContext() const {
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "called on invalid thread";
|
2021-04-15 01:28:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!browser_context() || !browser_context()->IsInitialized()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Uninitialized context";
|
2021-04-15 01:28:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* CefRequestContextImpl::GetBrowserContext() {
|
2021-04-15 01:28:22 +02:00
|
|
|
CHECK(VerifyBrowserContext());
|
2017-02-14 23:27:19 +01:00
|
|
|
return browser_context();
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
void CefRequestContextImpl::ExecuteWhenBrowserContextInitialized(
|
|
|
|
base::OnceClosure callback) {
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
|
|
|
base::BindOnce(
|
|
|
|
&CefRequestContextImpl::ExecuteWhenBrowserContextInitialized, this,
|
|
|
|
std::move(callback)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnsureBrowserContext();
|
|
|
|
browser_context()->StoreOrTriggerInitCallback(std::move(callback));
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void CefRequestContextImpl::GetBrowserContext(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
2021-04-15 01:28:22 +02:00
|
|
|
BrowserContextCallback callback) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!task_runner.get()) {
|
2017-09-21 13:57:40 +02:00
|
|
|
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-15 01:28:22 +02:00
|
|
|
|
|
|
|
ExecuteWhenBrowserContextInitialized(base::BindOnce(
|
|
|
|
[](CefRefPtr<CefRequestContextImpl> context,
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
BrowserContextCallback callback) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
auto browser_context = context->browser_context();
|
|
|
|
DCHECK(browser_context->IsInitialized());
|
|
|
|
|
|
|
|
if (task_runner->BelongsToCurrentThread()) {
|
|
|
|
// Execute the callback immediately.
|
|
|
|
std::move(callback).Run(browser_context->getter());
|
|
|
|
} else {
|
|
|
|
// Execute the callback on the target thread.
|
|
|
|
task_runner->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::BindOnce(std::move(callback), browser_context->getter()));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
CefRefPtr<CefRequestContextImpl>(this), task_runner,
|
|
|
|
std::move(callback)));
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
bool CefRequestContextImpl::IsSame(CefRefPtr<CefRequestContext> other) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextImpl* other_impl =
|
2013-09-03 18:43:31 +02:00
|
|
|
static_cast<CefRequestContextImpl*>(other.get());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!other_impl) {
|
2013-09-03 18:43:31 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
// Compare whether both are the global context.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (config_.is_global && other_impl->config_.is_global) {
|
2017-02-14 23:27:19 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-14 23:27:19 +01:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Compare CefBrowserContext pointers if one has been associated.
|
2017-02-14 23:27:19 +01:00
|
|
|
if (browser_context() && other_impl->browser_context()) {
|
|
|
|
return (browser_context() == other_impl->browser_context());
|
|
|
|
} else if (browser_context() || other_impl->browser_context()) {
|
2013-09-03 18:43:31 +02:00
|
|
|
return false;
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
|
|
|
|
// Otherwise compare unique IDs.
|
2017-02-14 23:27:19 +01:00
|
|
|
return (config_.unique_id == other_impl->config_.unique_id);
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::IsSharingWith(CefRefPtr<CefRequestContext> other) {
|
|
|
|
CefRequestContextImpl* other_impl =
|
|
|
|
static_cast<CefRequestContextImpl*>(other.get());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!other_impl) {
|
2015-03-02 21:25:14 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (IsSame(other)) {
|
2015-03-02 21:25:14 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
CefRefPtr<CefRequestContext> pending_other = config_.other;
|
2015-03-02 21:25:14 +01:00
|
|
|
if (pending_other.get()) {
|
|
|
|
// This object is not initialized but we know what context this object will
|
|
|
|
// share with. Compare to that other context instead.
|
|
|
|
return pending_other->IsSharingWith(other);
|
|
|
|
}
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
pending_other = other_impl->config_.other;
|
2015-03-02 21:25:14 +01:00
|
|
|
if (pending_other.get()) {
|
|
|
|
// The other object is not initialized but we know what context that object
|
|
|
|
// will share with. Compare to that other context instead.
|
|
|
|
return pending_other->IsSharingWith(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This or the other object is not initialized. Compare the cache path values.
|
|
|
|
// If both are non-empty and the same then they'll share the same storage.
|
2017-02-14 23:27:19 +01:00
|
|
|
if (config_.settings.cache_path.length > 0 &&
|
|
|
|
other_impl->config_.settings.cache_path.length > 0) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return (
|
|
|
|
base::FilePath(CefString(&config_.settings.cache_path)) ==
|
|
|
|
base::FilePath(CefString(&other_impl->config_.settings.cache_path)));
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::IsGlobal() {
|
2017-02-14 23:27:19 +01:00
|
|
|
return config_.is_global;
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContextHandler> CefRequestContextImpl::GetHandler() {
|
2017-02-14 23:27:19 +01:00
|
|
|
return config_.handler;
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
CefString CefRequestContextImpl::GetCachePath() {
|
2017-02-14 23:27:19 +01:00
|
|
|
return CefString(&config_.settings.cache_path);
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
CefRefPtr<CefCookieManager> CefRequestContextImpl::GetCookieManager(
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2019-07-29 23:27:12 +02:00
|
|
|
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
|
2021-04-15 01:28:22 +02:00
|
|
|
InitializeCookieManagerInternal(cookie_manager, callback);
|
2019-07-29 23:27:12 +02:00
|
|
|
return cookie_manager.get();
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::RegisterSchemeHandlerFactory(
|
|
|
|
const CefString& scheme_name,
|
|
|
|
const CefString& domain_name,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory) {
|
2021-04-15 01:28:22 +02:00
|
|
|
GetBrowserContext(
|
|
|
|
content::GetUIThreadTaskRunner({}),
|
|
|
|
base::BindOnce(
|
|
|
|
[](const CefString& scheme_name, const CefString& domain_name,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory,
|
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
|
|
|
if (browser_context) {
|
|
|
|
browser_context->RegisterSchemeHandlerFactory(
|
|
|
|
scheme_name, domain_name, factory);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scheme_name, domain_name, factory));
|
2019-04-24 04:50:25 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::ClearSchemeHandlerFactories() {
|
2021-04-15 01:28:22 +02:00
|
|
|
GetBrowserContext(
|
|
|
|
content::GetUIThreadTaskRunner({}),
|
|
|
|
base::BindOnce([](CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_context) {
|
2021-04-15 01:28:22 +02:00
|
|
|
browser_context->ClearSchemeHandlerFactories();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-15 01:28:22 +02:00
|
|
|
}));
|
2019-04-24 04:50:25 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
bool CefRequestContextImpl::HasPreference(const CefString& name) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyBrowserContext()) {
|
2015-10-03 01:03:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
|
2022-10-26 00:50:29 +02:00
|
|
|
return pref_helper::HasPreference(pref_service, name);
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> CefRequestContextImpl::GetPreference(
|
|
|
|
const CefString& name) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyBrowserContext()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
|
2022-10-26 00:50:29 +02:00
|
|
|
return pref_helper::GetPreference(pref_service, name);
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDictionaryValue> CefRequestContextImpl::GetAllPreferences(
|
|
|
|
bool include_defaults) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyBrowserContext()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
|
2022-10-26 00:50:29 +02:00
|
|
|
return pref_helper::GetAllPreferences(pref_service, include_defaults);
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::CanSetPreference(const CefString& name) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyBrowserContext()) {
|
2015-10-03 01:03:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
|
2022-10-26 00:50:29 +02:00
|
|
|
return pref_helper::CanSetPreference(pref_service, name);
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::SetPreference(const CefString& name,
|
|
|
|
CefRefPtr<CefValue> value,
|
|
|
|
CefString& error) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyBrowserContext()) {
|
2015-10-03 01:03:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
|
2022-10-26 00:50:29 +02:00
|
|
|
return pref_helper::SetPreference(pref_service, name, value, error);
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 20:29:18 +01:00
|
|
|
void CefRequestContextImpl::ClearCertificateExceptions(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
|
|
|
GetBrowserContext(
|
2020-07-08 19:23:29 +02:00
|
|
|
content::GetUIThreadTaskRunner({}),
|
2021-04-15 01:28:22 +02:00
|
|
|
base::BindOnce(&CefRequestContextImpl::ClearCertificateExceptionsInternal,
|
|
|
|
this, callback));
|
2016-02-23 20:29:18 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 22:44:43 +02:00
|
|
|
void CefRequestContextImpl::ClearHttpAuthCredentials(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2019-07-29 23:27:12 +02:00
|
|
|
GetBrowserContext(
|
2020-07-08 19:23:29 +02:00
|
|
|
content::GetUIThreadTaskRunner({}),
|
2021-04-15 01:28:22 +02:00
|
|
|
base::BindOnce(&CefRequestContextImpl::ClearHttpAuthCredentialsInternal,
|
|
|
|
this, callback));
|
2019-07-12 22:44:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 20:29:18 +01:00
|
|
|
void CefRequestContextImpl::CloseAllConnections(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2019-07-29 23:27:12 +02:00
|
|
|
GetBrowserContext(
|
2020-07-08 19:23:29 +02:00
|
|
|
content::GetUIThreadTaskRunner({}),
|
2021-04-15 01:28:22 +02:00
|
|
|
base::BindOnce(&CefRequestContextImpl::CloseAllConnectionsInternal, this,
|
|
|
|
callback));
|
2016-02-23 20:29:18 +01:00
|
|
|
}
|
|
|
|
|
2016-02-24 00:27:05 +01:00
|
|
|
void CefRequestContextImpl::ResolveHost(
|
|
|
|
const CefString& origin,
|
|
|
|
CefRefPtr<CefResolveCallback> callback) {
|
2020-07-08 19:23:29 +02:00
|
|
|
GetBrowserContext(content::GetUIThreadTaskRunner({}),
|
2021-04-15 01:28:22 +02:00
|
|
|
base::BindOnce(&CefRequestContextImpl::ResolveHostInternal,
|
|
|
|
this, origin, callback));
|
2016-02-24 00:27:05 +01:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void CefRequestContextImpl::LoadExtension(
|
|
|
|
const CefString& root_directory,
|
|
|
|
CefRefPtr<CefDictionaryValue> manifest,
|
|
|
|
CefRefPtr<CefExtensionHandler> handler) {
|
2021-04-15 01:28:22 +02:00
|
|
|
GetBrowserContext(content::GetUIThreadTaskRunner({}),
|
|
|
|
base::BindOnce(
|
|
|
|
[](const CefString& root_directory,
|
|
|
|
CefRefPtr<CefDictionaryValue> manifest,
|
|
|
|
CefRefPtr<CefExtensionHandler> handler,
|
|
|
|
CefRefPtr<CefRequestContextImpl> self,
|
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
|
|
|
if (browser_context) {
|
|
|
|
browser_context->LoadExtension(
|
|
|
|
root_directory, manifest, handler, self);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
root_directory, manifest, handler,
|
|
|
|
CefRefPtr<CefRequestContextImpl>(this)));
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::DidLoadExtension(const CefString& extension_id) {
|
|
|
|
CefRefPtr<CefExtension> extension = GetExtension(extension_id);
|
|
|
|
// GetLoaderContext() will return NULL for internal extensions.
|
|
|
|
return extension && IsSame(extension->GetLoaderContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::HasExtension(const CefString& extension_id) {
|
|
|
|
return !!GetExtension(extension_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::GetExtensions(
|
|
|
|
std::vector<CefString>& extension_ids) {
|
|
|
|
extension_ids.clear();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyBrowserContext()) {
|
2017-08-04 00:55:19 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
return browser_context()->GetExtensions(extension_ids);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefExtension> CefRequestContextImpl::GetExtension(
|
|
|
|
const CefString& extension_id) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!VerifyBrowserContext()) {
|
2017-08-04 00:55:19 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
return browser_context()->GetExtension(extension_id);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
CefRefPtr<CefMediaRouter> CefRequestContextImpl::GetMediaRouter(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2020-03-19 16:34:15 +01:00
|
|
|
CefRefPtr<CefMediaRouterImpl> media_router = new CefMediaRouterImpl();
|
2021-04-15 01:28:22 +02:00
|
|
|
InitializeMediaRouterInternal(media_router, callback);
|
2020-03-19 16:34:15 +01:00
|
|
|
return media_router.get();
|
|
|
|
}
|
|
|
|
|
2023-05-25 13:15:06 +02:00
|
|
|
CefRefPtr<CefValue> CefRequestContextImpl::GetWebsiteSetting(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type) {
|
|
|
|
if (!VerifyBrowserContext()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* settings_map = HostContentSettingsMapFactory::GetForProfile(
|
|
|
|
browser_context()->AsProfile());
|
|
|
|
if (!settings_map) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Either or both URLs may be invalid.
|
|
|
|
GURL requesting_gurl(requesting_url.ToString());
|
|
|
|
GURL top_level_gurl(top_level_url.ToString());
|
|
|
|
|
|
|
|
content_settings::SettingInfo info;
|
|
|
|
base::Value value = settings_map->GetWebsiteSetting(
|
|
|
|
requesting_gurl, top_level_gurl,
|
|
|
|
static_cast<ContentSettingsType>(content_type), &info);
|
|
|
|
if (value.is_none()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new CefValueImpl(std::move(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::SetWebsiteSetting(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type,
|
|
|
|
CefRefPtr<CefValue> value) {
|
|
|
|
GetBrowserContext(
|
|
|
|
content::GetUIThreadTaskRunner({}),
|
|
|
|
base::BindOnce(&CefRequestContextImpl::SetWebsiteSettingInternal, this,
|
|
|
|
requesting_url, top_level_url, content_type, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
cef_content_setting_values_t CefRequestContextImpl::GetContentSetting(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type) {
|
|
|
|
// Verify that our enums match Chromium's values.
|
|
|
|
static_assert(static_cast<int>(CEF_CONTENT_SETTING_TYPE_NUM_TYPES) ==
|
|
|
|
static_cast<int>(ContentSettingsType::NUM_TYPES),
|
|
|
|
"Mismatched enum found for CEF_CONTENT_SETTING_TYPE_NUM_TYPES");
|
|
|
|
static_assert(
|
|
|
|
static_cast<int>(CEF_CONTENT_SETTING_VALUE_NUM_VALUES) ==
|
|
|
|
static_cast<int>(CONTENT_SETTING_NUM_SETTINGS),
|
|
|
|
"Mismatched enum found for CEF_CONTENT_SETTING_VALUE_NUM_VALUES");
|
|
|
|
|
|
|
|
if (!VerifyBrowserContext()) {
|
|
|
|
return CEF_CONTENT_SETTING_VALUE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* settings_map = HostContentSettingsMapFactory::GetForProfile(
|
|
|
|
browser_context()->AsProfile());
|
|
|
|
if (!settings_map) {
|
|
|
|
return CEF_CONTENT_SETTING_VALUE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentSetting value = ContentSetting::CONTENT_SETTING_DEFAULT;
|
|
|
|
|
|
|
|
if (requesting_url.empty() && top_level_url.empty()) {
|
|
|
|
value = settings_map->GetDefaultContentSetting(
|
|
|
|
static_cast<ContentSettingsType>(content_type),
|
|
|
|
/*provider_id=*/nullptr);
|
|
|
|
} else {
|
|
|
|
GURL requesting_gurl(requesting_url.ToString());
|
|
|
|
GURL top_level_gurl(top_level_url.ToString());
|
|
|
|
if (requesting_gurl.is_valid() || top_level_gurl.is_valid()) {
|
|
|
|
value = settings_map->GetContentSetting(
|
|
|
|
requesting_gurl, top_level_gurl,
|
|
|
|
static_cast<ContentSettingsType>(content_type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<cef_content_setting_values_t>(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::SetContentSetting(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type,
|
|
|
|
cef_content_setting_values_t value) {
|
|
|
|
GetBrowserContext(
|
|
|
|
content::GetUIThreadTaskRunner({}),
|
|
|
|
base::BindOnce(&CefRequestContextImpl::SetContentSettingInternal, this,
|
|
|
|
requesting_url, top_level_url, content_type, value));
|
|
|
|
}
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
void CefRequestContextImpl::OnRenderFrameCreated(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view) {
|
|
|
|
browser_context_->OnRenderFrameCreated(this, global_id, is_main_frame,
|
|
|
|
is_guest_view);
|
2019-03-24 00:40:32 +01:00
|
|
|
}
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
void CefRequestContextImpl::OnRenderFrameDeleted(
|
|
|
|
const content::GlobalRenderFrameHostId& global_id,
|
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view) {
|
|
|
|
browser_context_->OnRenderFrameDeleted(this, global_id, is_main_frame,
|
|
|
|
is_guest_view);
|
2019-03-24 00:40:32 +01:00
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefRequestContextImpl>
|
|
|
|
CefRequestContextImpl::GetOrCreateRequestContext(const Config& config) {
|
|
|
|
if (config.is_global ||
|
|
|
|
(config.other && config.other->IsGlobal() && !config.handler)) {
|
|
|
|
// Return the singleton global context.
|
2020-06-28 23:05:36 +02:00
|
|
|
return static_cast<CefRequestContextImpl*>(
|
|
|
|
CefAppManager::Get()->GetGlobalRequestContext().get());
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The new context will be initialized later by EnsureBrowserContext().
|
2021-04-07 00:09:45 +02:00
|
|
|
CefRefPtr<CefRequestContextImpl> context = new CefRequestContextImpl(config);
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
// Initialize ASAP so that any tasks blocked on initialization will execute.
|
|
|
|
if (CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
context->Initialize();
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::BindOnce(&CefRequestContextImpl::Initialize, context));
|
2021-04-07 00:09:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return context;
|
2017-05-04 23:53:27 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextImpl::CefRequestContextImpl(
|
2017-02-14 23:27:19 +01:00
|
|
|
const CefRequestContextImpl::Config& config)
|
2017-05-17 11:29:28 +02:00
|
|
|
: config_(config) {}
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
void CefRequestContextImpl::Initialize() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
DCHECK(!browser_context_);
|
2017-02-14 23:27:19 +01:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
if (config_.other) {
|
|
|
|
// Share storage with |config_.other|.
|
2021-04-15 01:28:22 +02:00
|
|
|
browser_context_ = config_.other->browser_context();
|
|
|
|
CHECK(browser_context_);
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
if (!browser_context_) {
|
2020-04-23 23:45:04 +02:00
|
|
|
if (!config_.is_global) {
|
|
|
|
// User-specified settings need to be normalized.
|
|
|
|
CefContext::Get()->NormalizeRequestContextSettings(&config_.settings);
|
|
|
|
}
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
const base::FilePath& cache_path =
|
|
|
|
base::FilePath(CefString(&config_.settings.cache_path));
|
|
|
|
if (!cache_path.empty()) {
|
2019-03-22 23:11:51 +01:00
|
|
|
// Check if a CefBrowserContext is already globally registered for
|
2017-02-14 23:27:19 +01:00
|
|
|
// the specified cache path. If so then use it.
|
2020-07-01 02:57:00 +02:00
|
|
|
browser_context_ = CefBrowserContext::FromCachePath(cache_path);
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 00:09:45 +02:00
|
|
|
auto initialized_cb =
|
|
|
|
base::BindOnce(&CefRequestContextImpl::BrowserContextInitialized, this);
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
if (!browser_context_) {
|
|
|
|
// Create a new CefBrowserContext instance. If the cache path is non-
|
2017-02-14 23:27:19 +01:00
|
|
|
// empty then this new instance will become the globally registered
|
2019-03-22 23:11:51 +01:00
|
|
|
// CefBrowserContext for that path. Otherwise, this new instance will
|
2020-04-23 23:45:04 +02:00
|
|
|
// be a completely isolated "incognito mode" context.
|
2021-04-07 00:09:45 +02:00
|
|
|
browser_context_ = CefAppManager::Get()->CreateNewBrowserContext(
|
|
|
|
config_.settings, std::move(initialized_cb));
|
2020-04-23 23:45:04 +02:00
|
|
|
} else {
|
|
|
|
// Share the same settings as the existing context.
|
2020-07-01 02:57:00 +02:00
|
|
|
config_.settings = browser_context_->settings();
|
2021-04-15 01:28:22 +02:00
|
|
|
browser_context_->StoreOrTriggerInitCallback(std::move(initialized_cb));
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
// We'll disassociate from |browser_context_| on destruction.
|
|
|
|
browser_context_->AddCefRequestContext(this);
|
2017-02-14 23:27:19 +01:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
if (config_.other) {
|
|
|
|
// Clear the reference to |config_.other| after setting
|
2019-03-22 23:11:51 +01:00
|
|
|
// |request_context_getter_|. This is the reverse order of checks in
|
2017-05-04 23:53:27 +02:00
|
|
|
// IsSharedWith().
|
2020-01-15 14:36:24 +01:00
|
|
|
config_.other = nullptr;
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
2021-04-07 00:09:45 +02:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2021-04-07 00:09:45 +02:00
|
|
|
void CefRequestContextImpl::BrowserContextInitialized() {
|
|
|
|
if (config_.handler) {
|
|
|
|
// Always execute asynchronously so the current call stack can unwind.
|
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
|
|
|
base::BindOnce(&CefRequestContextHandler::OnRequestContextInitialized,
|
|
|
|
config_.handler, CefRefPtr<CefRequestContext>(this)));
|
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
void CefRequestContextImpl::EnsureBrowserContext() {
|
2017-08-04 00:55:19 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context()) {
|
2017-02-14 23:27:19 +01:00
|
|
|
Initialize();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-14 23:27:19 +01:00
|
|
|
DCHECK(browser_context());
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 20:29:18 +01:00
|
|
|
void CefRequestContextImpl::ClearCertificateExceptionsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2021-04-15 01:28:22 +02:00
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2021-04-15 01:28:22 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-02-23 20:29:18 +01:00
|
|
|
|
|
|
|
content::SSLHostStateDelegate* ssl_delegate =
|
2020-07-01 02:57:00 +02:00
|
|
|
browser_context->AsBrowserContext()->GetSSLHostStateDelegate();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (ssl_delegate) {
|
2021-06-04 03:34:56 +02:00
|
|
|
ssl_delegate->Clear(base::NullCallback());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-02-23 20:29:18 +01:00
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(&CefCompletionCallback::OnComplete, callback));
|
2016-02-23 20:29:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 22:44:43 +02:00
|
|
|
void CefRequestContextImpl::ClearHttpAuthCredentialsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2021-04-15 01:28:22 +02:00
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2021-04-15 01:28:22 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-07-12 22:44:43 +02:00
|
|
|
|
|
|
|
browser_context->GetNetworkContext()->ClearHttpAuthCache(
|
2020-10-08 21:54:42 +02:00
|
|
|
/*start_time=*/base::Time(), /*end_time=*/base::Time::Max(),
|
2023-11-21 20:17:55 +01:00
|
|
|
/*filter=*/nullptr,
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(&CefCompletionCallback::OnComplete, callback));
|
2019-07-12 22:44:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-23 20:29:18 +01:00
|
|
|
void CefRequestContextImpl::CloseAllConnectionsInternal(
|
2019-05-18 19:41:14 +02:00
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2021-04-15 01:28:22 +02:00
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2021-04-15 01:28:22 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-05-18 19:41:14 +02:00
|
|
|
|
|
|
|
browser_context->GetNetworkContext()->CloseAllConnections(
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(&CefCompletionCallback::OnComplete, callback));
|
2019-05-18 19:41:14 +02:00
|
|
|
}
|
|
|
|
|
2016-02-24 00:27:05 +01:00
|
|
|
void CefRequestContextImpl::ResolveHostInternal(
|
2019-05-18 19:41:14 +02:00
|
|
|
const CefString& origin,
|
|
|
|
CefRefPtr<CefResolveCallback> callback,
|
2021-04-15 01:28:22 +02:00
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_context) {
|
2021-04-15 01:28:22 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-05-18 19:41:14 +02:00
|
|
|
|
|
|
|
// |helper| will be deleted in ResolveHostHelper::OnComplete().
|
|
|
|
ResolveHostHelper* helper = new ResolveHostHelper(callback);
|
|
|
|
helper->Start(browser_context, origin);
|
|
|
|
}
|
|
|
|
|
2023-05-25 13:15:06 +02:00
|
|
|
void CefRequestContextImpl::SetWebsiteSettingInternal(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type,
|
|
|
|
CefRefPtr<CefValue> value,
|
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
|
|
|
if (!browser_context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* settings_map = HostContentSettingsMapFactory::GetForProfile(
|
|
|
|
browser_context->AsProfile());
|
|
|
|
if (!settings_map) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Starts as a NONE value.
|
|
|
|
base::Value new_value;
|
|
|
|
if (value && value->IsValid()) {
|
|
|
|
new_value = static_cast<CefValueImpl*>(value.get())->CopyValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requesting_url.empty() && top_level_url.empty()) {
|
|
|
|
settings_map->SetWebsiteSettingCustomScope(
|
|
|
|
ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(),
|
|
|
|
static_cast<ContentSettingsType>(content_type), std::move(new_value));
|
|
|
|
} else {
|
|
|
|
GURL requesting_gurl(requesting_url.ToString());
|
|
|
|
GURL top_level_gurl(top_level_url.ToString());
|
|
|
|
if (requesting_gurl.is_valid() || top_level_gurl.is_valid()) {
|
|
|
|
settings_map->SetWebsiteSettingDefaultScope(
|
|
|
|
requesting_gurl, top_level_gurl,
|
|
|
|
static_cast<ContentSettingsType>(content_type), std::move(new_value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::SetContentSettingInternal(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type,
|
|
|
|
cef_content_setting_values_t value,
|
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
auto browser_context = browser_context_getter.Run();
|
|
|
|
if (!browser_context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* settings_map = HostContentSettingsMapFactory::GetForProfile(
|
|
|
|
browser_context->AsProfile());
|
|
|
|
if (!settings_map) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requesting_url.empty() && top_level_url.empty()) {
|
|
|
|
settings_map->SetDefaultContentSetting(
|
|
|
|
static_cast<ContentSettingsType>(content_type),
|
|
|
|
static_cast<ContentSetting>(value));
|
|
|
|
} else {
|
|
|
|
GURL requesting_gurl(requesting_url.ToString());
|
|
|
|
GURL top_level_gurl(top_level_url.ToString());
|
|
|
|
if (requesting_gurl.is_valid() || top_level_gurl.is_valid()) {
|
|
|
|
settings_map->SetContentSettingDefaultScope(
|
|
|
|
requesting_gurl, top_level_gurl,
|
|
|
|
static_cast<ContentSettingsType>(content_type),
|
|
|
|
static_cast<ContentSetting>(value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
void CefRequestContextImpl::InitializeCookieManagerInternal(
|
2020-03-27 21:00:36 +01:00
|
|
|
CefRefPtr<CefCookieManagerImpl> cookie_manager,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
2021-04-15 01:28:22 +02:00
|
|
|
GetBrowserContext(content::GetUIThreadTaskRunner({}),
|
|
|
|
base::BindOnce(
|
|
|
|
[](CefRefPtr<CefCookieManagerImpl> cookie_manager,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
cookie_manager->Initialize(browser_context_getter,
|
|
|
|
callback);
|
|
|
|
},
|
|
|
|
cookie_manager, callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::InitializeMediaRouterInternal(
|
|
|
|
CefRefPtr<CefMediaRouterImpl> media_router,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
|
|
|
GetBrowserContext(content::GetUIThreadTaskRunner({}),
|
|
|
|
base::BindOnce(
|
|
|
|
[](CefRefPtr<CefMediaRouterImpl> media_router,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
|
|
|
CefBrowserContext::Getter browser_context_getter) {
|
|
|
|
media_router->Initialize(browser_context_getter,
|
|
|
|
callback);
|
|
|
|
},
|
|
|
|
media_router, callback));
|
2020-03-19 16:34:15 +01:00
|
|
|
}
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* CefRequestContextImpl::browser_context() const {
|
2019-03-22 23:11:51 +01:00
|
|
|
return browser_context_;
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|