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/content_browser_client.h"
|
|
|
|
#include "libcef/browser/context.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/browser/extensions/extension_system.h"
|
2019-03-25 19:14:23 +01:00
|
|
|
#include "libcef/browser/net/cookie_manager_old_impl.h"
|
|
|
|
#include "libcef/browser/net_service/cookie_manager_impl.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2019-03-21 01:23:23 +01:00
|
|
|
#include "libcef/common/net_service/util.h"
|
2017-09-21 13:57:40 +02:00
|
|
|
#include "libcef/common/task_runner_impl.h"
|
2015-10-03 01:03:16 +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"
|
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"
|
2015-09-25 13:59:30 +02:00
|
|
|
#include "content/public/browser/plugin_service.h"
|
2016-02-23 20:29:18 +01:00
|
|
|
#include "content/public/browser/ssl_host_state_delegate.h"
|
|
|
|
#include "net/http/http_cache.h"
|
|
|
|
#include "net/http/http_transaction_factory.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
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
const char* GetTypeString(base::Value::Type type) {
|
|
|
|
switch (type) {
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::NONE:
|
2015-10-03 01:03:16 +02:00
|
|
|
return "NULL";
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::BOOLEAN:
|
2015-10-03 01:03:16 +02:00
|
|
|
return "BOOLEAN";
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::INTEGER:
|
2015-10-03 01:03:16 +02:00
|
|
|
return "INTEGER";
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::DOUBLE:
|
2015-10-03 01:03:16 +02:00
|
|
|
return "DOUBLE";
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::STRING:
|
2015-10-03 01:03:16 +02:00
|
|
|
return "STRING";
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::BINARY:
|
2015-10-03 01:03:16 +02:00
|
|
|
return "BINARY";
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::DICTIONARY:
|
2015-10-03 01:03:16 +02:00
|
|
|
return "DICTIONARY";
|
2017-01-23 18:36:54 +01:00
|
|
|
case base::Value::Type::LIST:
|
2015-10-03 01:03:16 +02:00
|
|
|
return "LIST";
|
2019-04-16 16:38:48 +02:00
|
|
|
case base::Value::Type::DEAD:
|
|
|
|
return "DEAD";
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NOTREACHED();
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
|
2016-02-24 00:27:05 +01:00
|
|
|
// Helper for HostResolver::Resolve.
|
|
|
|
struct ResolveHostHelper {
|
|
|
|
explicit ResolveHostHelper(CefRefPtr<CefResolveCallback> callback)
|
2017-05-17 11:29:28 +02:00
|
|
|
: callback_(callback) {}
|
2016-02-24 00:27:05 +01:00
|
|
|
|
|
|
|
void OnResolveCompleted(int result) {
|
|
|
|
std::vector<CefString> resolved_ips;
|
2019-03-13 22:27:37 +01:00
|
|
|
base::Optional<net::AddressList> maybe_address_list =
|
|
|
|
request_->GetAddressResults();
|
|
|
|
if (maybe_address_list) {
|
|
|
|
net::AddressList::const_iterator iter = maybe_address_list->begin();
|
|
|
|
for (; iter != maybe_address_list->end(); ++iter)
|
|
|
|
resolved_ips.push_back(iter->ToStringWithoutPort());
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2017-02-14 23:27:19 +01:00
|
|
|
base::Bind(&CefResolveCallback::OnResolveCompleted, callback_,
|
2016-02-24 00:27:05 +01:00
|
|
|
static_cast<cef_errorcode_t>(result), resolved_ips));
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefResolveCallback> callback_;
|
2019-03-13 22:27:37 +01:00
|
|
|
std::unique_ptr<net::HostResolver::ResolveHostRequest> request_;
|
2016-02-24 00:27:05 +01:00
|
|
|
};
|
|
|
|
|
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()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
NOTREACHED() << "context not valid";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!other.get())
|
|
|
|
return NULL;
|
|
|
|
|
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);
|
|
|
|
impl->Initialize();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserContext* CefRequestContextImpl::GetBrowserContext() {
|
|
|
|
EnsureBrowserContext();
|
|
|
|
return browser_context();
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void CefRequestContextImpl::GetBrowserContext(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
const BrowserContextCallback& callback) {
|
|
|
|
if (!task_runner.get())
|
2017-09-21 13:57:40 +02:00
|
|
|
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
|
2015-03-02 21:25:14 +01:00
|
|
|
GetBrowserContextOnUIThread(task_runner, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::GetRequestContextImpl(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
const RequestContextCallback& callback) {
|
2019-03-21 01:23:23 +01:00
|
|
|
DCHECK(!net_service::IsEnabled());
|
2015-03-02 21:25:14 +01:00
|
|
|
if (!task_runner.get())
|
2017-09-21 13:57:40 +02:00
|
|
|
task_runner = CefTaskRunnerImpl::GetCurrentTaskRunner();
|
2019-03-22 23:11:51 +01:00
|
|
|
if (request_context_getter_) {
|
2015-03-02 21:25:14 +01:00
|
|
|
// The browser context already exists.
|
2017-02-14 23:27:19 +01:00
|
|
|
DCHECK(browser_context());
|
|
|
|
GetRequestContextImplOnIOThread(task_runner, callback, browser_context());
|
2015-03-02 21:25:14 +01:00
|
|
|
} else {
|
|
|
|
// Need to initialize the browser context first.
|
|
|
|
GetBrowserContextOnUIThread(
|
2018-10-02 14:14:11 +02:00
|
|
|
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
|
2015-03-02 21:25:14 +01:00
|
|
|
base::Bind(&CefRequestContextImpl::GetRequestContextImplOnIOThread,
|
|
|
|
this, task_runner, callback));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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());
|
2015-03-02 21:25:14 +01:00
|
|
|
if (!other_impl)
|
2013-09-03 18:43:31 +02:00
|
|
|
return false;
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
// Compare whether both are the global context.
|
|
|
|
if (config_.is_global && other_impl->config_.is_global)
|
|
|
|
return true;
|
|
|
|
|
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());
|
|
|
|
if (!other_impl)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (IsSame(other))
|
|
|
|
return true;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
if (request_context_getter_ && other_impl->request_context_getter_) {
|
2015-03-02 21:25:14 +01:00
|
|
|
// Both objects are initialized. Compare the request context objects.
|
2019-03-22 23:11:51 +01:00
|
|
|
return (request_context_getter_ == other_impl->request_context_getter_);
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-03-25 19:14:23 +01:00
|
|
|
if (!net_service::IsEnabled()) {
|
|
|
|
CefRefPtr<CefCookieManagerOldImpl> cookie_manager =
|
|
|
|
new CefCookieManagerOldImpl();
|
|
|
|
cookie_manager->Initialize(this, CefString(), false, callback);
|
|
|
|
return cookie_manager.get();
|
|
|
|
} else {
|
|
|
|
CefRefPtr<CefCookieManagerImpl> cookie_manager = new CefCookieManagerImpl();
|
|
|
|
cookie_manager->Initialize(this, callback);
|
|
|
|
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) {
|
2019-03-21 01:23:23 +01:00
|
|
|
if (net_service::IsEnabled()) {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
GetRequestContextImpl(
|
2018-10-02 14:14:11 +02:00
|
|
|
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
|
2015-03-02 21:25:14 +01:00
|
|
|
base::Bind(&CefRequestContextImpl::RegisterSchemeHandlerFactoryInternal,
|
|
|
|
this, scheme_name, domain_name, factory));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::ClearSchemeHandlerFactories() {
|
2019-03-21 01:23:23 +01:00
|
|
|
if (net_service::IsEnabled()) {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-02 21:25:14 +01:00
|
|
|
GetRequestContextImpl(
|
2018-10-02 14:14:11 +02:00
|
|
|
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
|
2015-03-02 21:25:14 +01:00
|
|
|
base::Bind(&CefRequestContextImpl::ClearSchemeHandlerFactoriesInternal,
|
|
|
|
this));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-25 13:59:30 +02:00
|
|
|
void CefRequestContextImpl::PurgePluginListCache(bool reload_pages) {
|
|
|
|
GetBrowserContext(
|
2018-10-02 14:14:11 +02:00
|
|
|
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}),
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Bind(&CefRequestContextImpl::PurgePluginListCacheInternal, this,
|
|
|
|
reload_pages));
|
2015-09-25 13:59:30 +02:00
|
|
|
}
|
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
bool CefRequestContextImpl::HasPreference(const CefString& name) {
|
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the browser context exists.
|
|
|
|
EnsureBrowserContext();
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
PrefService* pref_service = browser_context()->GetPrefs();
|
2015-10-03 01:03:16 +02:00
|
|
|
return (pref_service->FindPreference(name) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> CefRequestContextImpl::GetPreference(
|
|
|
|
const CefString& name) {
|
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the browser context exists.
|
|
|
|
EnsureBrowserContext();
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
PrefService* pref_service = browser_context()->GetPrefs();
|
2015-10-03 01:03:16 +02:00
|
|
|
const PrefService::Preference* pref = pref_service->FindPreference(name);
|
|
|
|
if (!pref)
|
|
|
|
return NULL;
|
|
|
|
return new CefValueImpl(pref->GetValue()->DeepCopy());
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDictionaryValue> CefRequestContextImpl::GetAllPreferences(
|
|
|
|
bool include_defaults) {
|
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the browser context exists.
|
|
|
|
EnsureBrowserContext();
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
PrefService* pref_service = browser_context()->GetPrefs();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
std::unique_ptr<base::DictionaryValue> values =
|
|
|
|
pref_service->GetPreferenceValues(include_defaults
|
|
|
|
? PrefService::INCLUDE_DEFAULTS
|
|
|
|
: PrefService::EXCLUDE_DEFAULTS);
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// CefDictionaryValueImpl takes ownership of |values|.
|
|
|
|
return new CefDictionaryValueImpl(values.release(), true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::CanSetPreference(const CefString& name) {
|
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the browser context exists.
|
|
|
|
EnsureBrowserContext();
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
PrefService* pref_service = browser_context()->GetPrefs();
|
2015-10-03 01:03:16 +02:00
|
|
|
const PrefService::Preference* pref = pref_service->FindPreference(name);
|
|
|
|
return (pref && pref->IsUserModifiable());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRequestContextImpl::SetPreference(const CefString& name,
|
|
|
|
CefRefPtr<CefValue> value,
|
|
|
|
CefString& error) {
|
|
|
|
// Verify that this method is being called on the UI thread.
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the browser context exists.
|
|
|
|
EnsureBrowserContext();
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
PrefService* pref_service = browser_context()->GetPrefs();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// The below validation logic should match PrefService::SetUserPrefValue.
|
|
|
|
|
|
|
|
const PrefService::Preference* pref = pref_service->FindPreference(name);
|
|
|
|
if (!pref) {
|
|
|
|
error = "Trying to modify an unregistered preference";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pref->IsUserModifiable()) {
|
|
|
|
error = "Trying to modify a preference that is not user modifiable";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value.get()) {
|
|
|
|
// Reset the preference to its default value.
|
|
|
|
pref_service->ClearPref(name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value->IsValid()) {
|
|
|
|
error = "A valid value is required";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefValueImpl* impl = static_cast<CefValueImpl*>(value.get());
|
|
|
|
|
|
|
|
CefValueImpl::ScopedLockedValue scoped_locked_value(impl);
|
|
|
|
base::Value* impl_value = impl->GetValueUnsafe();
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
if (pref->GetType() != impl_value->type()) {
|
2015-10-03 01:03:16 +02:00
|
|
|
error = base::StringPrintf(
|
|
|
|
"Trying to set a preference of type %s to value of type %s",
|
2017-12-07 22:44:24 +01:00
|
|
|
GetTypeString(pref->GetType()), GetTypeString(impl_value->type()));
|
2015-10-03 01:03:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrefService will make a DeepCopy of |impl_value|.
|
|
|
|
pref_service->Set(name, *impl_value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-23 20:29:18 +01:00
|
|
|
void CefRequestContextImpl::ClearCertificateExceptions(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
|
|
|
GetBrowserContext(
|
2018-10-02 14:14:11 +02:00
|
|
|
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}),
|
2016-02-23 20:29:18 +01:00
|
|
|
base::Bind(&CefRequestContextImpl::ClearCertificateExceptionsInternal,
|
|
|
|
this, callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::CloseAllConnections(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) {
|
|
|
|
GetRequestContextImpl(
|
2018-10-02 14:14:11 +02:00
|
|
|
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
|
2016-02-23 20:29:18 +01:00
|
|
|
base::Bind(&CefRequestContextImpl::CloseAllConnectionsInternal, this,
|
|
|
|
callback));
|
|
|
|
}
|
|
|
|
|
2016-02-24 00:27:05 +01:00
|
|
|
void CefRequestContextImpl::ResolveHost(
|
|
|
|
const CefString& origin,
|
|
|
|
CefRefPtr<CefResolveCallback> callback) {
|
|
|
|
GetRequestContextImpl(
|
2018-10-02 14:14:11 +02:00
|
|
|
base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO}),
|
2016-02-24 00:27:05 +01:00
|
|
|
base::Bind(&CefRequestContextImpl::ResolveHostInternal, this, origin,
|
|
|
|
callback));
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void CefRequestContextImpl::LoadExtension(
|
|
|
|
const CefString& root_directory,
|
|
|
|
CefRefPtr<CefDictionaryValue> manifest,
|
|
|
|
CefRefPtr<CefExtensionHandler> handler) {
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::BindOnce(&CefRequestContextImpl::LoadExtension, this,
|
|
|
|
root_directory, manifest, handler));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extensions::ExtensionsEnabled()) {
|
|
|
|
if (handler)
|
|
|
|
handler->OnExtensionLoadFailed(ERR_ABORTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (manifest && manifest->GetSize() > 0) {
|
|
|
|
CefDictionaryValueImpl* value_impl =
|
|
|
|
static_cast<CefDictionaryValueImpl*>(manifest.get());
|
|
|
|
GetBrowserContext()->extension_system()->LoadExtension(
|
|
|
|
base::WrapUnique(value_impl->CopyValue()), root_directory,
|
|
|
|
false /* builtin */, this, handler);
|
|
|
|
} else {
|
|
|
|
GetBrowserContext()->extension_system()->LoadExtension(
|
|
|
|
root_directory, false /* builtin */, this, handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extensions::ExtensionsEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
extensions::CefExtensionSystem::ExtensionMap extension_map =
|
|
|
|
GetBrowserContext()->extension_system()->GetExtensions();
|
|
|
|
extensions::CefExtensionSystem::ExtensionMap::const_iterator it =
|
|
|
|
extension_map.begin();
|
|
|
|
for (; it != extension_map.end(); ++it)
|
|
|
|
extension_ids.push_back(it->second->GetIdentifier());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefExtension> CefRequestContextImpl::GetExtension(
|
|
|
|
const CefString& extension_id) {
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extensions::ExtensionsEnabled())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return GetBrowserContext()->extension_system()->GetExtension(extension_id);
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:40:32 +01:00
|
|
|
void CefRequestContextImpl::OnRenderFrameCreated(int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view) {
|
|
|
|
browser_context_->OnRenderFrameCreated(
|
|
|
|
this, render_process_id, render_frame_id, is_main_frame, is_guest_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::OnRenderFrameDeleted(int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view) {
|
|
|
|
browser_context_->OnRenderFrameDeleted(
|
|
|
|
this, render_process_id, render_frame_id, is_main_frame, is_guest_view);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
return CefContentBrowserClient::Get()->request_context();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The new context will be initialized later by EnsureBrowserContext().
|
|
|
|
return new CefRequestContextImpl(config);
|
|
|
|
}
|
|
|
|
|
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_);
|
|
|
|
DCHECK(!request_context_getter_);
|
2017-02-14 23:27:19 +01:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
if (config_.other) {
|
|
|
|
// Share storage with |config_.other|.
|
2019-03-22 23:11:51 +01:00
|
|
|
browser_context_ =
|
|
|
|
CefBrowserContext::GetForContext(config_.other->GetBrowserContext());
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
if (!browser_context_) {
|
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.
|
2019-03-22 23:11:51 +01:00
|
|
|
browser_context_ = CefBrowserContext::GetForCachePath(cache_path);
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2017-02-14 23:27:19 +01:00
|
|
|
// be a completely isolated "incongento mode" context.
|
2019-03-22 23:11:51 +01:00
|
|
|
browser_context_ = new CefBrowserContext(config_.settings);
|
|
|
|
browser_context_->Initialize();
|
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
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
// Force our settings to match |browser_context_|.
|
|
|
|
config_.settings = browser_context_->GetSettings();
|
2017-02-14 23:27:19 +01:00
|
|
|
|
2019-03-21 01:23:23 +01:00
|
|
|
if (!net_service::IsEnabled()) {
|
2019-03-22 23:11:51 +01:00
|
|
|
request_context_getter_ = browser_context_->request_context_getter().get();
|
|
|
|
DCHECK(request_context_getter_);
|
2017-02-14 23:27:19 +01:00
|
|
|
|
2019-03-21 01:23:23 +01:00
|
|
|
if (config_.handler.get()) {
|
|
|
|
// Keep the handler alive until the associated request context is
|
|
|
|
// destroyed.
|
2019-03-22 23:11:51 +01:00
|
|
|
request_context_getter_->AddHandler(config_.handler);
|
2019-03-21 01:23:23 +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().
|
|
|
|
config_.other = NULL;
|
2017-02-14 23:27:19 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
if (config_.handler)
|
|
|
|
config_.handler->OnRequestContextInitialized(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();
|
2017-02-14 23:27:19 +01:00
|
|
|
if (!browser_context())
|
|
|
|
Initialize();
|
|
|
|
DCHECK(browser_context());
|
2019-03-22 23:11:51 +01:00
|
|
|
DCHECK(net_service::IsEnabled() || request_context_getter_);
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void CefRequestContextImpl::GetBrowserContextOnUIThread(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
const BrowserContextCallback& callback) {
|
|
|
|
if (!CEF_CURRENTLY_ON_UIT()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT, base::Bind(&CefRequestContextImpl::GetBrowserContextOnUIThread,
|
|
|
|
this, task_runner, callback));
|
2015-03-02 21:25:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the browser context exists.
|
2015-10-03 01:03:16 +02:00
|
|
|
EnsureBrowserContext();
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
if (task_runner->BelongsToCurrentThread()) {
|
|
|
|
// Execute the callback immediately.
|
2017-02-14 23:27:19 +01:00
|
|
|
callback.Run(browser_context());
|
2015-03-02 21:25:14 +01:00
|
|
|
} else {
|
|
|
|
// Execute the callback on the target thread.
|
2017-02-14 23:27:19 +01:00
|
|
|
task_runner->PostTask(FROM_HERE, base::Bind(callback, browser_context()));
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::GetRequestContextImplOnIOThread(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
const RequestContextCallback& callback,
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* browser_context) {
|
2015-03-02 21:25:14 +01:00
|
|
|
if (!CEF_CURRENTLY_ON_IOT()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_IOT,
|
2015-03-02 21:25:14 +01:00
|
|
|
base::Bind(&CefRequestContextImpl::GetRequestContextImplOnIOThread,
|
|
|
|
this, task_runner, callback, browser_context));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-21 01:23:23 +01:00
|
|
|
DCHECK(!net_service::IsEnabled());
|
2019-03-22 23:11:51 +01:00
|
|
|
DCHECK(request_context_getter_);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
// Make sure the request context exists.
|
2019-03-22 23:11:51 +01:00
|
|
|
request_context_getter_->GetURLRequestContext();
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
if (task_runner->BelongsToCurrentThread()) {
|
|
|
|
// Execute the callback immediately.
|
2019-03-22 23:11:51 +01:00
|
|
|
callback.Run(request_context_getter_);
|
2015-03-02 21:25:14 +01:00
|
|
|
} else {
|
|
|
|
// Execute the callback on the target thread.
|
2017-05-17 11:29:28 +02:00
|
|
|
task_runner->PostTask(
|
2019-03-22 23:11:51 +01:00
|
|
|
FROM_HERE,
|
|
|
|
base::Bind(callback, base::WrapRefCounted(request_context_getter_)));
|
2015-03-02 21:25:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::RegisterSchemeHandlerFactoryInternal(
|
|
|
|
const CefString& scheme_name,
|
|
|
|
const CefString& domain_name,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory,
|
2019-03-22 23:11:51 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> request_context) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
request_context->request_manager()->AddFactory(scheme_name, domain_name,
|
|
|
|
factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::ClearSchemeHandlerFactoriesInternal(
|
2019-03-22 23:11:51 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> request_context) {
|
2015-03-02 21:25:14 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
request_context->request_manager()->ClearFactories();
|
|
|
|
}
|
2015-09-25 13:59:30 +02:00
|
|
|
|
|
|
|
void CefRequestContextImpl::PurgePluginListCacheInternal(
|
|
|
|
bool reload_pages,
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* browser_context) {
|
2015-09-25 13:59:30 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
2016-10-17 20:14:44 +02:00
|
|
|
browser_context->OnPurgePluginListCache();
|
2017-05-17 11:29:28 +02:00
|
|
|
content::PluginService::GetInstance()->PurgePluginListCache(browser_context,
|
|
|
|
false);
|
2015-09-25 13:59:30 +02:00
|
|
|
}
|
2016-02-23 20:29:18 +01:00
|
|
|
|
|
|
|
void CefRequestContextImpl::ClearCertificateExceptionsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* browser_context) {
|
2016-02-23 20:29:18 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
content::SSLHostStateDelegate* ssl_delegate =
|
|
|
|
browser_context->GetSSLHostStateDelegate();
|
|
|
|
if (ssl_delegate)
|
2016-10-17 20:14:44 +02:00
|
|
|
ssl_delegate->Clear(base::Callback<bool(const std::string&)>());
|
2016-02-23 20:29:18 +01:00
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Bind(&CefCompletionCallback::OnComplete, callback));
|
2016-02-23 20:29:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRequestContextImpl::CloseAllConnectionsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2019-03-22 23:11:51 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> request_context) {
|
2016-02-23 20:29:18 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
net::URLRequestContext* url_context = request_context->GetURLRequestContext();
|
|
|
|
if (url_context) {
|
|
|
|
net::HttpTransactionFactory* http_factory =
|
|
|
|
url_context->http_transaction_factory();
|
|
|
|
if (http_factory) {
|
|
|
|
net::HttpCache* cache = http_factory->GetCache();
|
|
|
|
if (cache)
|
|
|
|
cache->CloseAllConnections();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Bind(&CefCompletionCallback::OnComplete, callback));
|
2016-02-23 20:29:18 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-24 00:27:05 +01:00
|
|
|
|
|
|
|
void CefRequestContextImpl::ResolveHostInternal(
|
|
|
|
const CefString& origin,
|
|
|
|
CefRefPtr<CefResolveCallback> callback,
|
2019-03-22 23:11:51 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> request_context) {
|
2016-02-24 00:27:05 +01:00
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
int retval = ERR_FAILED;
|
|
|
|
|
|
|
|
// |helper| will be deleted in ResolveHostHelper::OnResolveCompleted().
|
|
|
|
ResolveHostHelper* helper = new ResolveHostHelper(callback);
|
|
|
|
|
|
|
|
net::HostResolver* host_resolver = request_context->GetHostResolver();
|
|
|
|
if (host_resolver) {
|
2019-03-13 22:27:37 +01:00
|
|
|
helper->request_ = host_resolver->CreateRequest(
|
|
|
|
net::HostPortPair::FromURL(GURL(origin.ToString())),
|
|
|
|
net::NetLogWithSource(), {});
|
|
|
|
retval = helper->request_->Start(base::Bind(
|
|
|
|
&ResolveHostHelper::OnResolveCompleted, base::Unretained(helper)));
|
2016-02-24 00:27:05 +01:00
|
|
|
if (retval == net::ERR_IO_PENDING) {
|
|
|
|
// The result will be delivered asynchronously via the callback.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
helper->OnResolveCompleted(retval);
|
|
|
|
}
|
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
|
|
|
}
|