2013-09-03 18:43:31 +02:00
|
|
|
// Copyright (c) 2012 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/browser_context_proxy.h"
|
|
|
|
|
|
|
|
#include "libcef/browser/content_browser_client.h"
|
|
|
|
#include "libcef/browser/download_manager_delegate.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/url_request_context_getter_proxy.h"
|
2016-08-24 11:28:52 +02:00
|
|
|
#include "libcef/browser/storage_partition_proxy.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "chrome/browser/font_family_cache.h"
|
2015-09-11 14:14:45 +02:00
|
|
|
#include "components/guest_view/common/guest_view_constants.h"
|
2016-01-12 01:19:51 +01:00
|
|
|
#include "components/visitedlink/browser/visitedlink_master.h"
|
2016-08-24 11:28:52 +02:00
|
|
|
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
|
|
|
|
#include "content/browser/resource_context_impl.h"
|
2015-09-11 14:14:45 +02:00
|
|
|
#include "content/browser/streams/stream_context.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "content/browser/webui/url_data_manager.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "content/public/browser/storage_partition.h"
|
|
|
|
|
2015-09-11 14:14:45 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool ShouldProxyUserData(const void* key) {
|
2016-08-24 11:28:52 +02:00
|
|
|
// If this value is not proxied then multiple StoragePartitionImpl objects
|
|
|
|
// will be created and filesystem API access will fail, among other things.
|
|
|
|
if (key == content::BrowserContext::GetStoragePartitionMapUserDataKey())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If these values are not proxied then blob data fails to load for the PDF
|
2015-09-11 14:14:45 +02:00
|
|
|
// extension.
|
2016-08-24 11:28:52 +02:00
|
|
|
// See also the call to InitializeResourceContext().
|
|
|
|
if (key == content::ChromeBlobStorageContext::GetUserDataKey() ||
|
|
|
|
key == content::StreamContext::GetUserDataKey()) {
|
2015-09-11 14:14:45 +02:00
|
|
|
return true;
|
2016-08-24 11:28:52 +02:00
|
|
|
}
|
2015-09-11 14:14:45 +02:00
|
|
|
|
|
|
|
// If this value is not proxied then CefBrowserContextImpl::GetGuestManager()
|
|
|
|
// returns NULL.
|
2015-11-10 21:18:16 +01:00
|
|
|
// See also CefExtensionsAPIClient::CreateGuestViewManagerDelegate.
|
2015-09-11 14:14:45 +02:00
|
|
|
if (key == guest_view::kGuestViewManagerKeyName)
|
|
|
|
return true;
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// If this value is not proxied then there will be a use-after-free while
|
|
|
|
// destroying the FontFamilyCache because it will try to access the
|
|
|
|
// ProxyService owned by CefBrowserContextImpl (which has already been freed).
|
|
|
|
if (key == kFontFamilyCacheKey)
|
|
|
|
return true;
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
// If this value is not proxied WebUI will fail to load.
|
|
|
|
if (key == content::URLDataManager::GetUserDataKey())
|
|
|
|
return true;
|
|
|
|
|
2015-09-11 14:14:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefBrowserContextProxy::CefBrowserContextProxy(
|
2017-05-04 23:53:27 +02:00
|
|
|
CefRequestContextImpl* const request_context,
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefRequestContextHandler> handler,
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContextImpl* parent)
|
2016-08-31 13:25:56 +02:00
|
|
|
: CefBrowserContext(true),
|
2017-05-04 23:53:27 +02:00
|
|
|
request_context_(request_context),
|
2016-08-31 13:25:56 +02:00
|
|
|
handler_(handler),
|
2015-02-14 00:17:08 +01:00
|
|
|
parent_(parent) {
|
2015-03-02 21:25:14 +01:00
|
|
|
DCHECK(handler_.get());
|
2017-02-14 23:27:19 +01:00
|
|
|
DCHECK(parent_);
|
2015-07-16 23:40:01 +02:00
|
|
|
parent_->AddProxy(this);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserContextProxy::~CefBrowserContextProxy() {
|
2017-02-14 23:27:19 +01:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
Shutdown();
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
parent_->RemoveProxy(this);
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
void CefBrowserContextProxy::Initialize() {
|
|
|
|
CefBrowserContext::Initialize();
|
|
|
|
|
|
|
|
// This object's CefResourceContext needs to proxy some UserData requests to
|
|
|
|
// the parent object's CefResourceContext.
|
|
|
|
resource_context()->set_parent(parent_->resource_context());
|
2017-04-20 21:28:17 +02:00
|
|
|
|
|
|
|
CefBrowserContext::PostInitialize();
|
2016-11-07 20:14:09 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
base::SupportsUserData::Data* CefBrowserContextProxy::GetUserData(
|
|
|
|
const void* key) const {
|
2015-09-11 14:14:45 +02:00
|
|
|
if (ShouldProxyUserData(key))
|
|
|
|
return parent_->GetUserData(key);
|
|
|
|
return BrowserContext::GetUserData(key);
|
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
void CefBrowserContextProxy::SetUserData(const void* key,
|
|
|
|
std::unique_ptr<Data> data) {
|
|
|
|
if (ShouldProxyUserData(key))
|
|
|
|
parent_->SetUserData(key, std::move(data));
|
|
|
|
else
|
|
|
|
BrowserContext::SetUserData(key, std::move(data));
|
|
|
|
}
|
|
|
|
|
2015-09-11 14:14:45 +02:00
|
|
|
void CefBrowserContextProxy::RemoveUserData(const void* key) {
|
|
|
|
if (ShouldProxyUserData(key))
|
|
|
|
parent_->RemoveUserData(key);
|
|
|
|
else
|
|
|
|
BrowserContext::RemoveUserData(key);
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
base::FilePath CefBrowserContextProxy::GetPath() const {
|
|
|
|
return parent_->GetPath();
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<content::ZoomLevelDelegate>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextProxy::CreateZoomLevelDelegate(
|
|
|
|
const base::FilePath& partition_path) {
|
2014-12-13 21:18:31 +01:00
|
|
|
return parent_->CreateZoomLevelDelegate(partition_path);
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
bool CefBrowserContextProxy::IsOffTheRecord() const {
|
|
|
|
return parent_->IsOffTheRecord();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::DownloadManagerDelegate*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextProxy::GetDownloadManagerDelegate() {
|
2017-12-22 22:05:32 +01:00
|
|
|
if (!download_manager_delegate_) {
|
|
|
|
content::DownloadManager* manager =
|
|
|
|
BrowserContext::GetDownloadManager(this);
|
|
|
|
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
|
|
|
|
}
|
2013-09-03 18:43:31 +02:00
|
|
|
return download_manager_delegate_.get();
|
|
|
|
}
|
|
|
|
|
2014-05-29 19:15:34 +02:00
|
|
|
content::BrowserPluginGuestManager* CefBrowserContextProxy::GetGuestManager() {
|
|
|
|
return parent_->GetGuestManager();
|
|
|
|
}
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
storage::SpecialStoragePolicy*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextProxy::GetSpecialStoragePolicy() {
|
2013-09-03 18:43:31 +02:00
|
|
|
return parent_->GetSpecialStoragePolicy();
|
|
|
|
}
|
|
|
|
|
2014-07-02 20:25:22 +02:00
|
|
|
content::PushMessagingService*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextProxy::GetPushMessagingService() {
|
2014-07-02 20:25:22 +02:00
|
|
|
return parent_->GetPushMessagingService();
|
|
|
|
}
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
content::SSLHostStateDelegate*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextProxy::GetSSLHostStateDelegate() {
|
2014-09-04 19:53:40 +02:00
|
|
|
return parent_->GetSSLHostStateDelegate();
|
|
|
|
}
|
|
|
|
|
2018-07-24 00:32:02 +02:00
|
|
|
content::PermissionControllerDelegate*
|
|
|
|
CefBrowserContextProxy::GetPermissionControllerDelegate() {
|
|
|
|
return parent_->GetPermissionControllerDelegate();
|
2015-04-20 13:11:11 +02:00
|
|
|
}
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
content::BackgroundFetchDelegate*
|
|
|
|
CefBrowserContextProxy::GetBackgroundFetchDelegate() {
|
|
|
|
return parent_->GetBackgroundFetchDelegate();
|
|
|
|
}
|
|
|
|
|
2015-11-10 21:18:16 +01:00
|
|
|
content::BackgroundSyncController*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextProxy::GetBackgroundSyncController() {
|
2015-11-10 21:18:16 +01:00
|
|
|
return parent_->GetBackgroundSyncController();
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
content::BrowsingDataRemoverDelegate*
|
|
|
|
CefBrowserContextProxy::GetBrowsingDataRemoverDelegate() {
|
|
|
|
return parent_->GetBrowsingDataRemoverDelegate();
|
|
|
|
}
|
|
|
|
|
2016-08-24 11:28:52 +02:00
|
|
|
net::URLRequestContextGetter* CefBrowserContextProxy::CreateRequestContext(
|
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors) {
|
|
|
|
// CefBrowserContextImpl::GetOrCreateStoragePartitionProxy is called instead
|
|
|
|
// of this method.
|
|
|
|
NOTREACHED();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
net::URLRequestContextGetter*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserContextProxy::CreateRequestContextForStoragePartition(
|
|
|
|
const base::FilePath& partition_path,
|
|
|
|
bool in_memory,
|
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors) {
|
2016-08-24 11:28:52 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void CefBrowserContextProxy::RegisterInProcessServices(
|
|
|
|
StaticServiceMap* services) {
|
|
|
|
parent_->RegisterInProcessServices(services);
|
|
|
|
}
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
PrefService* CefBrowserContextProxy::GetPrefs() {
|
|
|
|
return parent_->GetPrefs();
|
|
|
|
}
|
|
|
|
|
|
|
|
const PrefService* CefBrowserContextProxy::GetPrefs() const {
|
|
|
|
return parent_->GetPrefs();
|
|
|
|
}
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
CefRequestContextImpl* CefBrowserContextProxy::GetCefRequestContext() const {
|
|
|
|
return request_context_;
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
const CefRequestContextSettings& CefBrowserContextProxy::GetSettings() const {
|
|
|
|
return parent_->GetSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContextHandler> CefBrowserContextProxy::GetHandler() const {
|
|
|
|
return handler_;
|
|
|
|
}
|
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
HostContentSettingsMap* CefBrowserContextProxy::GetHostContentSettingsMap() {
|
|
|
|
return parent_->GetHostContentSettingsMap();
|
|
|
|
}
|
2016-01-12 01:19:51 +01:00
|
|
|
|
|
|
|
void CefBrowserContextProxy::AddVisitedURLs(const std::vector<GURL>& urls) {
|
|
|
|
parent_->AddVisitedURLs(urls);
|
|
|
|
}
|
2016-08-24 11:28:52 +02:00
|
|
|
|
|
|
|
content::StoragePartition*
|
|
|
|
CefBrowserContextProxy::GetOrCreateStoragePartitionProxy(
|
|
|
|
content::StoragePartition* partition_impl) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
if (!storage_partition_proxy_) {
|
|
|
|
scoped_refptr<CefURLRequestContextGetterProxy> url_request_getter =
|
|
|
|
new CefURLRequestContextGetterProxy(handler_,
|
2017-05-04 23:53:27 +02:00
|
|
|
parent_->request_context_getter());
|
2016-08-24 11:28:52 +02:00
|
|
|
storage_partition_proxy_.reset(
|
2017-05-17 11:29:28 +02:00
|
|
|
new CefStoragePartitionProxy(partition_impl, url_request_getter.get()));
|
2016-08-24 11:28:52 +02:00
|
|
|
|
|
|
|
// Associates UserData keys with the ResourceContext.
|
|
|
|
// Called from StoragePartitionImplMap::Get() for CefBrowserContextImpl.
|
|
|
|
content::InitializeResourceContext(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// There should only be one CefStoragePartitionProxy for this
|
|
|
|
// CefBrowserContextProxy.
|
|
|
|
DCHECK_EQ(storage_partition_proxy_->parent(), partition_impl);
|
|
|
|
return storage_partition_proxy_.get();
|
|
|
|
}
|