Make CefBrowserContext an abstract base class (see issue #2969)

Existing CefBrowserContext functionality is now split between
CefBrowserContext and AlloyBrowserContext. Runtime implementations of
CefBrowserContext will provide access to the content::BrowserContext and
Profile types via different inheritance paths. For example, the Alloy
runtime uses ChromeProfileAlloy and the Chrome runtime uses ProfileImpl.

This change also renames CefResourceContext to CefIOThreadState to more
accurately represent its purpose as it no longer needs to extend
content::ResourceContext.
This commit is contained in:
Marshall Greenblatt 2020-06-30 20:57:00 -04:00
parent 619f18fea0
commit 48fc0bd220
40 changed files with 1006 additions and 831 deletions

View File

@ -407,6 +407,8 @@ test("libcef_static_unittests") {
static_library("libcef_static") { static_library("libcef_static") {
sources = includes_common + sources = includes_common +
gypi_paths.autogen_cpp_includes + [ gypi_paths.autogen_cpp_includes + [
"libcef/browser/alloy/alloy_browser_context.cc",
"libcef/browser/alloy/alloy_browser_context.h",
"libcef/browser/alloy/alloy_browser_main.cc", "libcef/browser/alloy/alloy_browser_main.cc",
"libcef/browser/alloy/alloy_browser_main.h", "libcef/browser/alloy/alloy_browser_main.h",
"libcef/browser/alloy/chrome_browser_process_alloy.cc", "libcef/browser/alloy/chrome_browser_process_alloy.cc",
@ -512,6 +514,8 @@ static_library("libcef_static") {
"libcef/browser/frame_host_impl.h", "libcef/browser/frame_host_impl.h",
"libcef/browser/image_impl.cc", "libcef/browser/image_impl.cc",
"libcef/browser/image_impl.h", "libcef/browser/image_impl.h",
"libcef/browser/iothread_state.cc",
"libcef/browser/iothread_state.h",
"libcef/browser/javascript_dialog_runner.h", "libcef/browser/javascript_dialog_runner.h",
"libcef/browser/javascript_dialog_manager.cc", "libcef/browser/javascript_dialog_manager.cc",
"libcef/browser/javascript_dialog_manager.h", "libcef/browser/javascript_dialog_manager.h",
@ -607,8 +611,6 @@ static_library("libcef_static") {
"libcef/browser/printing/print_view_manager.cc", "libcef/browser/printing/print_view_manager.cc",
"libcef/browser/printing/print_view_manager.h", "libcef/browser/printing/print_view_manager.h",
"libcef/browser/process_util_impl.cc", "libcef/browser/process_util_impl.cc",
"libcef/browser/resource_context.cc",
"libcef/browser/resource_context.h",
"libcef/browser/request_context_handler_map.cc", "libcef/browser/request_context_handler_map.cc",
"libcef/browser/request_context_handler_map.h", "libcef/browser/request_context_handler_map.h",
"libcef/browser/request_context_impl.cc", "libcef/browser/request_context_impl.cc",

View File

@ -0,0 +1,449 @@
// 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/alloy/alloy_browser_context.h"
#include <map>
#include <utility>
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/ssl_host_state_delegate.h"
#include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "chrome/browser/font_family_cache.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "chrome/common/pref_names.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/simple_dependency_manager.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "components/prefs/pref_service.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#include "components/user_prefs/user_prefs.h"
#include "components/visitedlink/browser/visitedlink_event_listener.h"
#include "components/visitedlink/browser/visitedlink_writer.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/storage_partition.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/constants.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "services/network/public/mojom/cors_origin_pattern.mojom.h"
using content::BrowserThread;
// Creates and manages VisitedLinkEventListener objects for each
// AlloyBrowserContext sharing the same VisitedLinkWriter.
class CefVisitedLinkListener : public visitedlink::VisitedLinkWriter::Listener {
public:
CefVisitedLinkListener() { DCHECK(listener_map_.empty()); }
void CreateListenerForContext(content::BrowserContext* context) {
CEF_REQUIRE_UIT();
auto listener =
std::make_unique<visitedlink::VisitedLinkEventListener>(context);
listener_map_.insert(std::make_pair(context, std::move(listener)));
}
void RemoveListenerForContext(content::BrowserContext* context) {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.find(context);
DCHECK(it != listener_map_.end());
listener_map_.erase(it);
}
// visitedlink::VisitedLinkWriter::Listener methods.
void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
it->second->NewTable(table_region);
}
void Add(visitedlink::VisitedLinkCommon::Fingerprint fingerprint) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
it->second->Add(fingerprint);
}
void Reset(bool invalidate_hashes) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
it->second->Reset(invalidate_hashes);
}
private:
// Map of AlloyBrowserContext to the associated VisitedLinkEventListener.
typedef std::map<const content::BrowserContext*,
std::unique_ptr<visitedlink::VisitedLinkEventListener>>
ListenerMap;
ListenerMap listener_map_;
DISALLOW_COPY_AND_ASSIGN(CefVisitedLinkListener);
};
AlloyBrowserContext::AlloyBrowserContext(
const CefRequestContextSettings& settings)
: CefBrowserContext(settings) {}
AlloyBrowserContext::~AlloyBrowserContext() {
if (resource_context_) {
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
resource_context_.release());
}
}
void AlloyBrowserContext::Initialize() {
CefBrowserContext::Initialize();
key_ = std::make_unique<ProfileKey>(cache_path_);
SimpleKeyMap::GetInstance()->Associate(this, key_.get());
// Initialize the PrefService object.
pref_service_ = browser_prefs::CreatePrefService(
this, cache_path_, !!settings_.persist_user_preferences);
// This must be called before creating any services to avoid hitting
// DependencyManager::AssertContextWasntDestroyed when creating/destroying
// multiple browser contexts (due to pointer address reuse).
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this);
const bool extensions_enabled = extensions::ExtensionsEnabled();
if (extensions_enabled) {
// Create the custom ExtensionSystem first because other KeyedServices
// depend on it.
extension_system_ = static_cast<extensions::CefExtensionSystem*>(
extensions::ExtensionSystem::Get(this));
extension_system_->InitForRegularProfile(true);
// Make sure the ProcessManager is created so that it receives extension
// load notifications. This is necessary for the proper initialization of
// background/event pages.
extensions::ProcessManager::Get(this);
}
// Initialize visited links management.
base::FilePath visited_link_path;
if (!cache_path_.empty())
visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links"));
visitedlink_listener_ = new CefVisitedLinkListener;
visitedlink_master_.reset(new visitedlink::VisitedLinkWriter(
visitedlink_listener_, this, !visited_link_path.empty(), false,
visited_link_path, 0));
visitedlink_listener_->CreateListenerForContext(this);
visitedlink_master_->Init();
// Initialize proxy configuration tracker.
pref_proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(
GetPrefs(), base::CreateSingleThreadTaskRunner({BrowserThread::IO})));
// Spell checking support and possibly other subsystems retrieve the
// PrefService associated with a BrowserContext via UserPrefs::Get().
PrefService* pref_service = GetPrefs();
DCHECK(pref_service);
user_prefs::UserPrefs::Set(this, pref_service);
key_->SetPrefs(pref_service);
if (extensions_enabled)
extension_system_->Init();
ChromePluginServiceFilter::GetInstance()->RegisterProfile(this);
}
void AlloyBrowserContext::Shutdown() {
CefBrowserContext::Shutdown();
// Send notifications to clean up objects associated with this Profile.
MaybeSendDestroyedNotification();
ChromePluginServiceFilter::GetInstance()->UnregisterProfile(this);
// Remove any BrowserContextKeyedServiceFactory associations. This must be
// called before the ProxyService owned by AlloyBrowserContext is destroyed.
// The SimpleDependencyManager should always be passed after the
// BrowserContextDependencyManager. This is because the KeyedService instances
// in the BrowserContextDependencyManager's dependency graph can depend on the
// ones in the SimpleDependencyManager's graph.
DependencyManager::PerformInterlockedTwoPhaseShutdown(
BrowserContextDependencyManager::GetInstance(), this,
SimpleDependencyManager::GetInstance(), key_.get());
key_.reset();
SimpleKeyMap::GetInstance()->Dissociate(this);
// Shuts down the storage partitions associated with this browser context.
// This must be called before the browser context is actually destroyed
// and before a clean-up task for its corresponding IO thread residents
// (e.g. ResourceContext) is posted, so that the classes that hung on
// StoragePartition can have time to do necessary cleanups on IO thread.
ShutdownStoragePartitions();
visitedlink_listener_->RemoveListenerForContext(this);
// The FontFamilyCache references the ProxyService so delete it before the
// ProxyService is deleted.
SetUserData(&kFontFamilyCacheKey, nullptr);
pref_proxy_config_tracker_->DetachFromPrefService();
// Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_)
download_manager_delegate_.reset(nullptr);
}
void AlloyBrowserContext::RemoveCefRequestContext(
CefRequestContextImpl* context) {
CEF_REQUIRE_UIT();
if (extensions::ExtensionsEnabled()) {
extension_system()->OnRequestContextDeleted(context);
}
// May result in |this| being deleted.
CefBrowserContext::RemoveCefRequestContext(context);
}
void AlloyBrowserContext::LoadExtension(
const CefString& root_directory,
CefRefPtr<CefDictionaryValue> manifest,
CefRefPtr<CefExtensionHandler> handler,
CefRefPtr<CefRequestContext> loader_context) {
if (!extensions::ExtensionsEnabled()) {
if (handler)
handler->OnExtensionLoadFailed(ERR_ABORTED);
return;
}
if (manifest && manifest->GetSize() > 0) {
CefDictionaryValueImpl* value_impl =
static_cast<CefDictionaryValueImpl*>(manifest.get());
extension_system()->LoadExtension(base::WrapUnique(value_impl->CopyValue()),
root_directory, false /* builtin */,
loader_context, handler);
} else {
extension_system()->LoadExtension(root_directory, false /* builtin */,
loader_context, handler);
}
}
bool AlloyBrowserContext::GetExtensions(std::vector<CefString>& extension_ids) {
if (!extensions::ExtensionsEnabled())
return false;
extensions::CefExtensionSystem::ExtensionMap extension_map =
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> AlloyBrowserContext::GetExtension(
const CefString& extension_id) {
if (!extensions::ExtensionsEnabled())
return nullptr;
return extension_system()->GetExtension(extension_id);
}
bool AlloyBrowserContext::UnloadExtension(const CefString& extension_id) {
DCHECK(extensions::ExtensionsEnabled());
return extension_system()->UnloadExtension(extension_id);
}
bool AlloyBrowserContext::IsPrintPreviewSupported() const {
CEF_REQUIRE_UIT();
if (!extensions::PrintPreviewEnabled())
return false;
return !GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled);
}
void AlloyBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) {
visitedlink_master_->AddURLs(urls);
}
content::ResourceContext* AlloyBrowserContext::GetResourceContext() {
if (!resource_context_) {
resource_context_ = std::make_unique<content::ResourceContext>();
}
return resource_context_.get();
}
content::ClientHintsControllerDelegate*
AlloyBrowserContext::GetClientHintsControllerDelegate() {
return nullptr;
}
void AlloyBrowserContext::SetCorsOriginAccessListForOrigin(
const url::Origin& source_origin,
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
base::OnceClosure closure) {
// This method is called for Extension support.
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(closure));
}
ChromeZoomLevelPrefs* AlloyBrowserContext::GetZoomLevelPrefs() {
return static_cast<ChromeZoomLevelPrefs*>(
GetStoragePartition(this, nullptr)->GetZoomLevelDelegate());
}
scoped_refptr<network::SharedURLLoaderFactory>
AlloyBrowserContext::GetURLLoaderFactory() {
return GetDefaultStoragePartition(this)
->GetURLLoaderFactoryForBrowserProcess();
}
base::FilePath AlloyBrowserContext::GetPath() {
return cache_path_;
}
base::FilePath AlloyBrowserContext::GetPath() const {
return cache_path_;
}
std::unique_ptr<content::ZoomLevelDelegate>
AlloyBrowserContext::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
if (cache_path_.empty())
return std::unique_ptr<content::ZoomLevelDelegate>();
return base::WrapUnique(new ChromeZoomLevelPrefs(
GetPrefs(), cache_path_, partition_path,
zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
}
bool AlloyBrowserContext::IsOffTheRecord() const {
// Alloy contexts are never flagged as off-the-record. It causes problems
// for the extension system.
return false;
}
content::DownloadManagerDelegate*
AlloyBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_) {
content::DownloadManager* manager =
BrowserContext::GetDownloadManager(this);
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
}
return download_manager_delegate_.get();
}
content::BrowserPluginGuestManager* AlloyBrowserContext::GetGuestManager() {
DCHECK(extensions::ExtensionsEnabled());
return guest_view::GuestViewManager::FromBrowserContext(this);
}
storage::SpecialStoragePolicy* AlloyBrowserContext::GetSpecialStoragePolicy() {
return nullptr;
}
content::PushMessagingService* AlloyBrowserContext::GetPushMessagingService() {
return nullptr;
}
content::StorageNotificationService*
AlloyBrowserContext::GetStorageNotificationService() {
return nullptr;
}
content::SSLHostStateDelegate* AlloyBrowserContext::GetSSLHostStateDelegate() {
if (!ssl_host_state_delegate_)
ssl_host_state_delegate_.reset(new CefSSLHostStateDelegate());
return ssl_host_state_delegate_.get();
}
content::PermissionControllerDelegate*
AlloyBrowserContext::GetPermissionControllerDelegate() {
return nullptr;
}
content::BackgroundFetchDelegate*
AlloyBrowserContext::GetBackgroundFetchDelegate() {
return nullptr;
}
content::BackgroundSyncController*
AlloyBrowserContext::GetBackgroundSyncController() {
return nullptr;
}
content::BrowsingDataRemoverDelegate*
AlloyBrowserContext::GetBrowsingDataRemoverDelegate() {
return nullptr;
}
PrefService* AlloyBrowserContext::GetPrefs() {
return pref_service_.get();
}
const PrefService* AlloyBrowserContext::GetPrefs() const {
return pref_service_.get();
}
ProfileKey* AlloyBrowserContext::GetProfileKey() const {
DCHECK(key_);
return key_.get();
}
policy::SchemaRegistryService*
AlloyBrowserContext::GetPolicySchemaRegistryService() {
NOTREACHED();
return nullptr;
}
policy::UserCloudPolicyManager*
AlloyBrowserContext::GetUserCloudPolicyManager() {
NOTREACHED();
return nullptr;
}
policy::ProfilePolicyConnector*
AlloyBrowserContext::GetProfilePolicyConnector() {
NOTREACHED();
return nullptr;
}
const policy::ProfilePolicyConnector*
AlloyBrowserContext::GetProfilePolicyConnector() const {
NOTREACHED();
return nullptr;
}
void AlloyBrowserContext::RebuildTable(
const scoped_refptr<URLEnumerator>& enumerator) {
// Called when visited links will not or cannot be loaded from disk.
enumerator->OnComplete(true);
}
DownloadPrefs* AlloyBrowserContext::GetDownloadPrefs() {
CEF_REQUIRE_UIT();
if (!download_prefs_) {
download_prefs_.reset(new DownloadPrefs(this));
}
return download_prefs_.get();
}

View File

@ -0,0 +1,146 @@
// Copyright (c) 2011 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.
#ifndef CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_
#define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_
#pragma once
#include "include/cef_request_context_handler.h"
#include "libcef/browser/alloy/chrome_profile_alloy.h"
#include "libcef/browser/browser_context.h"
#include "libcef/browser/request_context_handler_map.h"
#include "chrome/browser/download/download_prefs.h"
#include "components/proxy_config/pref_proxy_config_tracker.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
class CefDownloadManagerDelegate;
class CefSSLHostStateDelegate;
class CefVisitedLinkListener;
class PrefService;
namespace extensions {
class CefExtensionSystem;
}
namespace visitedlink {
class VisitedLinkWriter;
}
// See CefBrowserContext documentation for usage. Only accessed on the UI thread
// unless otherwise indicated. ChromeProfileAlloy must be the first listed base
// class to avoid issues when casting between void* and content::BrowserContext*
// in Chromium code.
class AlloyBrowserContext : public ChromeProfileAlloy,
public CefBrowserContext,
public visitedlink::VisitedLinkDelegate {
public:
explicit AlloyBrowserContext(const CefRequestContextSettings& settings);
// CefBrowserContext overrides.
content::BrowserContext* AsBrowserContext() override { return this; }
Profile* AsProfile() override { return this; }
void Initialize() override;
void Shutdown() override;
void RemoveCefRequestContext(CefRequestContextImpl* context) override;
void LoadExtension(const CefString& root_directory,
CefRefPtr<CefDictionaryValue> manifest,
CefRefPtr<CefExtensionHandler> handler,
CefRefPtr<CefRequestContext> loader_context) override;
bool GetExtensions(std::vector<CefString>& extension_ids) override;
CefRefPtr<CefExtension> GetExtension(const CefString& extension_id) override;
bool UnloadExtension(const CefString& extension_id) override;
bool IsPrintPreviewSupported() const override;
void AddVisitedURLs(const std::vector<GURL>& urls) override;
// content::BrowserContext overrides.
content::ResourceContext* GetResourceContext() override;
content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
override;
void SetCorsOriginAccessListForOrigin(
const url::Origin& source_origin,
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
base::OnceClosure closure) override;
base::FilePath GetPath() override;
base::FilePath GetPath() const override;
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
bool IsOffTheRecord() const override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
content::StorageNotificationService* GetStorageNotificationService() override;
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
override;
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
// Profile overrides.
ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
PrefService* GetPrefs() override;
bool AllowsBrowserWindows() const override { return false; }
const PrefService* GetPrefs() const override;
ProfileKey* GetProfileKey() const override;
policy::SchemaRegistryService* GetPolicySchemaRegistryService() override;
policy::UserCloudPolicyManager* GetUserCloudPolicyManager() override;
policy::ProfilePolicyConnector* GetProfilePolicyConnector() override;
const policy::ProfilePolicyConnector* GetProfilePolicyConnector()
const override;
// Values checked in ProfileNetworkContextService::CreateNetworkContextParams
// when creating the NetworkContext.
bool ShouldRestoreOldSessionCookies() override {
return ShouldPersistSessionCookies();
}
bool ShouldPersistSessionCookies() override {
return !!settings_.persist_session_cookies;
}
base::Optional<std::vector<std::string>> GetCookieableSchemes() override {
return cookieable_schemes_;
}
// visitedlink::VisitedLinkDelegate methods.
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
// Manages extensions.
extensions::CefExtensionSystem* extension_system() const {
return extension_system_;
}
// Called from DownloadPrefs::FromBrowserContext.
DownloadPrefs* GetDownloadPrefs();
private:
~AlloyBrowserContext() override;
std::unique_ptr<PrefService> pref_service_;
std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
std::unique_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
std::unique_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_;
std::unique_ptr<visitedlink::VisitedLinkWriter> visitedlink_master_;
// |visitedlink_listener_| is owned by visitedlink_master_.
CefVisitedLinkListener* visitedlink_listener_ = nullptr;
// Owned by the KeyedService system.
extensions::CefExtensionSystem* extension_system_ = nullptr;
// The key to index KeyedService instances created by
// SimpleKeyedServiceFactory.
std::unique_ptr<ProfileKey> key_;
std::unique_ptr<DownloadPrefs> download_prefs_;
std::unique_ptr<content::ResourceContext> resource_context_;
DISALLOW_COPY_AND_ASSIGN(AlloyBrowserContext);
};
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_

View File

@ -196,8 +196,8 @@ void AlloyBrowserMainParts::PreMainMessageLoopRun() {
// Create the global RequestContext. // Create the global RequestContext.
global_request_context_ = global_request_context_ =
CefRequestContextImpl::CreateGlobalRequestContext(settings); CefRequestContextImpl::CreateGlobalRequestContext(settings);
CefBrowserContext* browser_context = static_cast<CefBrowserContext*>( auto browser_context =
global_request_context_->GetBrowserContext()); global_request_context_->GetBrowserContext()->AsBrowserContext();
CefDevToolsManagerDelegate::StartHttpHandler(browser_context); CefDevToolsManagerDelegate::StartHttpHandler(browser_context);

View File

@ -8,6 +8,7 @@
#include <utility> #include <utility>
#include "include/cef_version.h" #include "include/cef_version.h"
#include "libcef/browser/alloy/alloy_browser_context.h"
#include "libcef/browser/alloy/alloy_browser_main.h" #include "libcef/browser/alloy/alloy_browser_main.h"
#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_host_impl.h" #include "libcef/browser/browser_host_impl.h"
@ -678,8 +679,8 @@ void AlloyContentBrowserClient::SiteInstanceGotProcess(
if (!extension) if (!extension)
return; return;
CefBrowserContext* browser_context = auto browser_context =
static_cast<CefBrowserContext*>(site_instance->GetBrowserContext()); static_cast<AlloyBrowserContext*>(site_instance->GetBrowserContext());
extensions::ProcessMap::Get(browser_context) extensions::ProcessMap::Get(browser_context)
->Insert(extension->id(), site_instance->GetProcess()->GetID(), ->Insert(extension->id(), site_instance->GetProcess()->GetID(),
@ -710,8 +711,8 @@ void AlloyContentBrowserClient::SiteInstanceDeleting(
if (!extension) if (!extension)
return; return;
CefBrowserContext* browser_context = auto browser_context =
static_cast<CefBrowserContext*>(site_instance->GetBrowserContext()); static_cast<AlloyBrowserContext*>(site_instance->GetBrowserContext());
extensions::ProcessMap::Get(browser_context) extensions::ProcessMap::Get(browser_context)
->Remove(extension->id(), site_instance->GetProcess()->GetID(), ->Remove(extension->id(), site_instance->GetProcess()->GetID(),
@ -803,18 +804,19 @@ void AlloyContentBrowserClient::AppendExtraCommandLineSwitches(
if (extensions::ExtensionsEnabled()) { if (extensions::ExtensionsEnabled()) {
content::RenderProcessHost* process = content::RenderProcessHost* process =
content::RenderProcessHost::FromID(child_process_id); content::RenderProcessHost::FromID(child_process_id);
CefBrowserContext* context = auto browser_context = process->GetBrowserContext();
process CefBrowserContext* cef_browser_context =
? CefBrowserContext::GetForContext(process->GetBrowserContext()) process ? CefBrowserContext::FromBrowserContext(browser_context)
: nullptr; : nullptr;
if (context) { if (cef_browser_context) {
if (context->IsPrintPreviewSupported()) { if (cef_browser_context->IsPrintPreviewSupported()) {
command_line->AppendSwitch(switches::kEnablePrintPreview); command_line->AppendSwitch(switches::kEnablePrintPreview);
} }
// Based on ChromeContentBrowserClientExtensionsPart:: // Based on ChromeContentBrowserClientExtensionsPart::
// AppendExtraRendererCommandLineSwitches // AppendExtraRendererCommandLineSwitches
if (extensions::ProcessMap::Get(context)->Contains(process->GetID())) { if (extensions::ProcessMap::Get(browser_context)
->Contains(process->GetID())) {
command_line->AppendSwitch(extensions::switches::kExtensionProcess); command_line->AppendSwitch(extensions::switches::kExtensionProcess);
} }
} }

View File

@ -84,8 +84,9 @@ void ChromeBrowserProcessAlloy::CleanupOnUIThread() {
// Release any references held by objects associated with a Profile. The // Release any references held by objects associated with a Profile. The
// Profile will be deleted later. // Profile will be deleted later.
for (const auto& profile : CefBrowserContext::GetAll()) { for (const auto& browser_context : CefBrowserContext::GetAll()) {
// Release any references to |local_state_|. // Release any references to |local_state_|.
auto profile = browser_context->AsProfile();
PrefWatcher* pref_watcher = PrefWatcher::Get(profile); PrefWatcher* pref_watcher = PrefWatcher::Get(profile);
if (pref_watcher) if (pref_watcher)
pref_watcher->Shutdown(); pref_watcher->Shutdown();

View File

@ -7,7 +7,6 @@
#include "components/variations/variations_client.h" #include "components/variations/variations_client.h"
#include "components/variations/variations_http_header_provider.h" #include "components/variations/variations_http_header_provider.h"
#include "content/public/browser/resource_context.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
namespace { namespace {

View File

@ -24,7 +24,7 @@ namespace {
CefBrowserContext* GetActiveBrowserContext() { CefBrowserContext* GetActiveBrowserContext() {
auto request_context = static_cast<CefRequestContextImpl*>( auto request_context = static_cast<CefRequestContextImpl*>(
CefAppManager::Get()->GetGlobalRequestContext().get()); CefAppManager::Get()->GetGlobalRequestContext().get());
return static_cast<CefBrowserContext*>(request_context->GetBrowserContext()); return request_context->GetBrowserContext();
} }
} // namespace } // namespace
@ -37,7 +37,7 @@ ChromeProfileManagerAlloy::~ChromeProfileManagerAlloy() {}
Profile* ChromeProfileManagerAlloy::GetProfile( Profile* ChromeProfileManagerAlloy::GetProfile(
const base::FilePath& profile_dir) { const base::FilePath& profile_dir) {
CefBrowserContext* browser_context = CefBrowserContext* browser_context =
CefBrowserContext::GetForCachePath(profile_dir); CefBrowserContext::FromCachePath(profile_dir);
if (!browser_context) { if (!browser_context) {
// ProfileManager makes assumptions about profile directory paths that do // ProfileManager makes assumptions about profile directory paths that do
// not match CEF usage. For example, the default Chrome profile name is // not match CEF usage. For example, the default Chrome profile name is
@ -47,19 +47,19 @@ Profile* ChromeProfileManagerAlloy::GetProfile(
// asking for. // asking for.
browser_context = GetActiveBrowserContext(); browser_context = GetActiveBrowserContext();
} }
return browser_context; return browser_context->AsProfile();
} }
bool ChromeProfileManagerAlloy::IsValidProfile(const void* profile) { bool ChromeProfileManagerAlloy::IsValidProfile(const void* profile) {
if (!profile) if (!profile)
return false; return false;
return !!CefBrowserContext::GetForContext( return !!CefBrowserContext::FromBrowserContext(
reinterpret_cast<content::BrowserContext*>(const_cast<void*>(profile))); static_cast<const content::BrowserContext*>(profile));
} }
Profile* ChromeProfileManagerAlloy::GetLastUsedProfile( Profile* ChromeProfileManagerAlloy::GetLastUsedProfile(
const base::FilePath& user_data_dir) { const base::FilePath& user_data_dir) {
// Override this method to avoid having to register prefs::kProfileLastUsed, // Override this method to avoid having to register prefs::kProfileLastUsed,
// usage of which doesn't make sense for CEF. // usage of which doesn't make sense for CEF.
return GetActiveBrowserContext(); return GetActiveBrowserContext()->AsProfile();
} }

View File

@ -7,47 +7,20 @@
#include <map> #include <map>
#include <utility> #include <utility>
#include "libcef/browser/alloy/alloy_content_browser_client.h" #include "libcef/browser/iothread_state.h"
#include "libcef/browser/download_manager_delegate.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/media_router/media_router_manager.h" #include "libcef/browser/media_router/media_router_manager.h"
#include "libcef/browser/prefs/browser_prefs.h"
#include "libcef/browser/request_context_impl.h" #include "libcef/browser/request_context_impl.h"
#include "libcef/browser/ssl_host_state_delegate.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/cef_switches.h" #include "libcef/common/cef_switches.h"
#include "libcef/common/extensions/extensions_util.h"
#include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/font_family_cache.h" #include "content/public/browser/browser_context.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "chrome/common/pref_names.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/guest_view/browser/guest_view_manager.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/simple_dependency_manager.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "components/prefs/pref_service.h"
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#include "components/user_prefs/user_prefs.h"
#include "components/visitedlink/browser/visitedlink_event_listener.h"
#include "components/visitedlink/browser/visitedlink_writer.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/constants.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "services/network/public/mojom/cors_origin_pattern.mojom.h"
using content::BrowserThread; using content::BrowserThread;
@ -90,10 +63,10 @@ class ImplManager {
return GetImplPos(impl) != all_.end(); return GetImplPos(impl) != all_.end();
} }
CefBrowserContext* GetImplForIDs(int render_process_id, CefBrowserContext* GetImplFromIDs(int render_process_id,
int render_frame_id, int render_frame_id,
int frame_tree_node_id, int frame_tree_node_id,
bool require_frame_match) { bool require_frame_match) {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
for (const auto& context : all_) { for (const auto& context : all_) {
if (context->IsAssociatedContext(render_process_id, render_frame_id, if (context->IsAssociatedContext(render_process_id, render_frame_id,
@ -105,15 +78,15 @@ class ImplManager {
return nullptr; return nullptr;
} }
CefBrowserContext* GetImplForContext(const content::BrowserContext* context) { CefBrowserContext* GetImplFromBrowserContext(
const content::BrowserContext* context) {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
if (!context) if (!context)
return nullptr; return nullptr;
Vector::iterator it = all_.begin(); for (const auto& bc : all_) {
for (; it != all_.end(); ++it) { if (bc->AsBrowserContext() == context)
if (*it == context) return bc;
return *it;
} }
return nullptr; return nullptr;
} }
@ -122,11 +95,11 @@ class ImplManager {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
DCHECK(!path.empty()); DCHECK(!path.empty());
DCHECK(IsValidImpl(impl)); DCHECK(IsValidImpl(impl));
DCHECK(GetImplForPath(path) == nullptr); DCHECK(GetImplFromPath(path) == nullptr);
map_.insert(std::make_pair(path, impl)); map_.insert(std::make_pair(path, impl));
} }
CefBrowserContext* GetImplForPath(const base::FilePath& path) { CefBrowserContext* GetImplFromPath(const base::FilePath& path) {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
DCHECK(!path.empty()); DCHECK(!path.empty());
PathMap::const_iterator it = map_.find(path); PathMap::const_iterator it = map_.find(path);
@ -170,59 +143,6 @@ CefBrowserContext* GetSelf(base::WeakPtr<CefBrowserContext> self) {
} // namespace } // namespace
// Creates and manages VisitedLinkEventListener objects for each
// CefBrowserContext sharing the same VisitedLinkWriter.
class CefVisitedLinkListener : public visitedlink::VisitedLinkWriter::Listener {
public:
CefVisitedLinkListener() { DCHECK(listener_map_.empty()); }
void CreateListenerForContext(const CefBrowserContext* context) {
CEF_REQUIRE_UIT();
auto listener = std::make_unique<visitedlink::VisitedLinkEventListener>(
const_cast<CefBrowserContext*>(context));
listener_map_.insert(std::make_pair(context, std::move(listener)));
}
void RemoveListenerForContext(const CefBrowserContext* context) {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.find(context);
DCHECK(it != listener_map_.end());
listener_map_.erase(it);
}
// visitedlink::VisitedLinkWriter::Listener methods.
void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
it->second->NewTable(table_region);
}
void Add(visitedlink::VisitedLinkCommon::Fingerprint fingerprint) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
it->second->Add(fingerprint);
}
void Reset(bool invalidate_hashes) override {
CEF_REQUIRE_UIT();
ListenerMap::iterator it = listener_map_.begin();
for (; it != listener_map_.end(); ++it)
it->second->Reset(invalidate_hashes);
}
private:
// Map of CefBrowserContext to the associated VisitedLinkEventListener.
typedef std::map<const CefBrowserContext*,
std::unique_ptr<visitedlink::VisitedLinkEventListener>>
ListenerMap;
ListenerMap listener_map_;
DISALLOW_COPY_AND_ASSIGN(CefVisitedLinkListener);
};
CefBrowserContext::CefBrowserContext(const CefRequestContextSettings& settings) CefBrowserContext::CefBrowserContext(const CefRequestContextSettings& settings)
: settings_(settings), weak_ptr_factory_(this) { : settings_(settings), weak_ptr_factory_(this) {
g_manager.Get().AddImpl(this); g_manager.Get().AddImpl(this);
@ -231,6 +151,31 @@ CefBrowserContext::CefBrowserContext(const CefRequestContextSettings& settings)
CefBrowserContext::~CefBrowserContext() { CefBrowserContext::~CefBrowserContext() {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
DCHECK(is_shutdown_);
if (iothread_state_) {
// Destruction of the CefIOThreadState will trigger destruction of all
// associated network requests.
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
iothread_state_.release());
}
}
void CefBrowserContext::Initialize() {
cache_path_ = base::FilePath(CefString(&settings_.cache_path));
if (!cache_path_.empty())
g_manager.Get().SetImplPath(this, cache_path_);
iothread_state_ = std::make_unique<CefIOThreadState>();
}
void CefBrowserContext::Shutdown() {
CEF_REQUIRE_UIT();
#if DCHECK_IS_ON()
is_shutdown_ = true;
#endif
// No CefRequestContext should be referencing this object any longer. // No CefRequestContext should be referencing this object any longer.
DCHECK(request_context_set_.empty()); DCHECK(request_context_set_.empty());
@ -240,121 +185,6 @@ CefBrowserContext::~CefBrowserContext() {
// Destroy objects that may hold references to the MediaRouter. // Destroy objects that may hold references to the MediaRouter.
media_router_manager_.reset(); media_router_manager_.reset();
// Send notifications to clean up objects associated with this Profile.
MaybeSendDestroyedNotification();
ChromePluginServiceFilter::GetInstance()->UnregisterProfile(this);
// Remove any BrowserContextKeyedServiceFactory associations. This must be
// called before the ProxyService owned by CefBrowserContext is destroyed.
// The SimpleDependencyManager should always be passed after the
// BrowserContextDependencyManager. This is because the KeyedService instances
// in the BrowserContextDependencyManager's dependency graph can depend on the
// ones in the SimpleDependencyManager's graph.
DependencyManager::PerformInterlockedTwoPhaseShutdown(
BrowserContextDependencyManager::GetInstance(), this,
SimpleDependencyManager::GetInstance(), key_.get());
key_.reset();
SimpleKeyMap::GetInstance()->Dissociate(this);
// Shuts down the storage partitions associated with this browser context.
// This must be called before the browser context is actually destroyed
// and before a clean-up task for its corresponding IO thread residents
// (e.g. ResourceContext) is posted, so that the classes that hung on
// StoragePartition can have time to do necessary cleanups on IO thread.
ShutdownStoragePartitions();
if (resource_context_.get()) {
// Destruction of the ResourceContext will trigger destruction of all
// associated network requests.
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
resource_context_.release());
}
visitedlink_listener_->RemoveListenerForContext(this);
// The FontFamilyCache references the ProxyService so delete it before the
// ProxyService is deleted.
SetUserData(&kFontFamilyCacheKey, nullptr);
pref_proxy_config_tracker_->DetachFromPrefService();
if (host_content_settings_map_)
host_content_settings_map_->ShutdownOnUIThread();
// Delete the download manager delegate here because otherwise we'll crash
// when it's accessed from the content::BrowserContext destructor.
if (download_manager_delegate_)
download_manager_delegate_.reset(nullptr);
}
void CefBrowserContext::Initialize() {
cache_path_ = base::FilePath(CefString(&settings_.cache_path));
if (!cache_path_.empty())
g_manager.Get().SetImplPath(this, cache_path_);
if (!!settings_.persist_session_cookies) {
set_should_persist_session_cookies(true);
}
key_ = std::make_unique<ProfileKey>(cache_path_);
SimpleKeyMap::GetInstance()->Associate(this, key_.get());
// Initialize the PrefService object.
pref_service_ = browser_prefs::CreatePrefService(
this, cache_path_, !!settings_.persist_user_preferences);
resource_context_.reset(new CefResourceContext(IsOffTheRecord()));
// This must be called before creating any services to avoid hitting
// DependencyManager::AssertContextWasntDestroyed when creating/destroying
// multiple browser contexts (due to pointer address reuse).
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this);
const bool extensions_enabled = extensions::ExtensionsEnabled();
if (extensions_enabled) {
// Create the custom ExtensionSystem first because other KeyedServices
// depend on it.
extension_system_ = static_cast<extensions::CefExtensionSystem*>(
extensions::ExtensionSystem::Get(this));
extension_system_->InitForRegularProfile(true);
// Make sure the ProcessManager is created so that it receives extension
// load notifications. This is necessary for the proper initialization of
// background/event pages.
extensions::ProcessManager::Get(this);
}
// Initialize visited links management.
base::FilePath visited_link_path;
if (!cache_path_.empty())
visited_link_path = cache_path_.Append(FILE_PATH_LITERAL("Visited Links"));
visitedlink_listener_ = new CefVisitedLinkListener;
visitedlink_master_.reset(new visitedlink::VisitedLinkWriter(
visitedlink_listener_, this, !visited_link_path.empty(), false,
visited_link_path, 0));
visitedlink_listener_->CreateListenerForContext(this);
visitedlink_master_->Init();
// Initialize proxy configuration tracker.
pref_proxy_config_tracker_.reset(new PrefProxyConfigTrackerImpl(
GetPrefs(), base::CreateSingleThreadTaskRunner({BrowserThread::IO})));
// Spell checking support and possibly other subsystems retrieve the
// PrefService associated with a BrowserContext via UserPrefs::Get().
PrefService* pref_service = GetPrefs();
DCHECK(pref_service);
user_prefs::UserPrefs::Set(this, pref_service);
key_->SetPrefs(pref_service);
if (extensions_enabled)
extension_system_->Init();
ChromePluginServiceFilter::GetInstance()->RegisterProfile(this);
} }
void CefBrowserContext::AddCefRequestContext(CefRequestContextImpl* context) { void CefBrowserContext::AddCefRequestContext(CefRequestContextImpl* context) {
@ -366,36 +196,35 @@ void CefBrowserContext::RemoveCefRequestContext(
CefRequestContextImpl* context) { CefRequestContextImpl* context) {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
if (extensions::ExtensionsEnabled()) {
extension_system()->OnRequestContextDeleted(context);
}
request_context_set_.erase(context); request_context_set_.erase(context);
// Delete ourselves when the reference count reaches zero. // Delete ourselves when the reference count reaches zero.
if (request_context_set_.empty()) if (request_context_set_.empty()) {
Shutdown();
delete this; delete this;
}
} }
// static // static
CefBrowserContext* CefBrowserContext::GetForCachePath( CefBrowserContext* CefBrowserContext::FromCachePath(
const base::FilePath& cache_path) { const base::FilePath& cache_path) {
return g_manager.Get().GetImplForPath(cache_path); return g_manager.Get().GetImplFromPath(cache_path);
} }
// static // static
CefBrowserContext* CefBrowserContext::GetForIDs(int render_process_id, CefBrowserContext* CefBrowserContext::FromIDs(int render_process_id,
int render_frame_id, int render_frame_id,
int frame_tree_node_id, int frame_tree_node_id,
bool require_frame_match) { bool require_frame_match) {
return g_manager.Get().GetImplForIDs(render_process_id, render_frame_id, return g_manager.Get().GetImplFromIDs(render_process_id, render_frame_id,
frame_tree_node_id, require_frame_match); frame_tree_node_id,
require_frame_match);
} }
// static // static
CefBrowserContext* CefBrowserContext::GetForContext( CefBrowserContext* CefBrowserContext::FromBrowserContext(
content::BrowserContext* context) { const content::BrowserContext* context) {
return g_manager.Get().GetImplForContext(context); return g_manager.Get().GetImplFromBrowserContext(context);
} }
// static // static
@ -403,194 +232,6 @@ std::vector<CefBrowserContext*> CefBrowserContext::GetAll() {
return g_manager.Get().GetAllImpl(); return g_manager.Get().GetAllImpl();
} }
content::ResourceContext* CefBrowserContext::GetResourceContext() {
return resource_context_.get();
}
content::ClientHintsControllerDelegate*
CefBrowserContext::GetClientHintsControllerDelegate() {
return nullptr;
}
void CefBrowserContext::SetCorsOriginAccessListForOrigin(
const url::Origin& source_origin,
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
base::OnceClosure closure) {
// This method is called for Extension support.
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(closure));
}
ChromeZoomLevelPrefs* CefBrowserContext::GetZoomLevelPrefs() {
return static_cast<ChromeZoomLevelPrefs*>(
GetStoragePartition(this, nullptr)->GetZoomLevelDelegate());
}
scoped_refptr<network::SharedURLLoaderFactory>
CefBrowserContext::GetURLLoaderFactory() {
return GetDefaultStoragePartition(this)
->GetURLLoaderFactoryForBrowserProcess();
}
base::FilePath CefBrowserContext::GetPath() {
return cache_path_;
}
base::FilePath CefBrowserContext::GetPath() const {
return cache_path_;
}
std::unique_ptr<content::ZoomLevelDelegate>
CefBrowserContext::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
if (cache_path_.empty())
return std::unique_ptr<content::ZoomLevelDelegate>();
return base::WrapUnique(new ChromeZoomLevelPrefs(
GetPrefs(), cache_path_, partition_path,
zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr()));
}
bool CefBrowserContext::IsOffTheRecord() const {
// CEF contexts are never flagged as off-the-record. It causes problems
// for the extension system.
return false;
}
content::DownloadManagerDelegate*
CefBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_) {
content::DownloadManager* manager =
BrowserContext::GetDownloadManager(this);
download_manager_delegate_.reset(new CefDownloadManagerDelegate(manager));
}
return download_manager_delegate_.get();
}
content::BrowserPluginGuestManager* CefBrowserContext::GetGuestManager() {
DCHECK(extensions::ExtensionsEnabled());
return guest_view::GuestViewManager::FromBrowserContext(this);
}
storage::SpecialStoragePolicy* CefBrowserContext::GetSpecialStoragePolicy() {
return nullptr;
}
content::PushMessagingService* CefBrowserContext::GetPushMessagingService() {
return nullptr;
}
content::StorageNotificationService*
CefBrowserContext::GetStorageNotificationService() {
return nullptr;
}
content::SSLHostStateDelegate* CefBrowserContext::GetSSLHostStateDelegate() {
if (!ssl_host_state_delegate_.get())
ssl_host_state_delegate_.reset(new CefSSLHostStateDelegate());
return ssl_host_state_delegate_.get();
}
content::PermissionControllerDelegate*
CefBrowserContext::GetPermissionControllerDelegate() {
return nullptr;
}
content::BackgroundFetchDelegate*
CefBrowserContext::GetBackgroundFetchDelegate() {
return nullptr;
}
content::BackgroundSyncController*
CefBrowserContext::GetBackgroundSyncController() {
return nullptr;
}
content::BrowsingDataRemoverDelegate*
CefBrowserContext::GetBrowsingDataRemoverDelegate() {
return nullptr;
}
PrefService* CefBrowserContext::GetPrefs() {
return pref_service_.get();
}
const PrefService* CefBrowserContext::GetPrefs() const {
return pref_service_.get();
}
ProfileKey* CefBrowserContext::GetProfileKey() const {
DCHECK(key_);
return key_.get();
}
policy::SchemaRegistryService*
CefBrowserContext::GetPolicySchemaRegistryService() {
NOTREACHED();
return nullptr;
}
policy::UserCloudPolicyManager* CefBrowserContext::GetUserCloudPolicyManager() {
NOTREACHED();
return nullptr;
}
policy::ProfilePolicyConnector* CefBrowserContext::GetProfilePolicyConnector() {
NOTREACHED();
return nullptr;
}
const policy::ProfilePolicyConnector*
CefBrowserContext::GetProfilePolicyConnector() const {
NOTREACHED();
return nullptr;
}
const CefRequestContextSettings& CefBrowserContext::GetSettings() const {
return settings_;
}
HostContentSettingsMap* CefBrowserContext::GetHostContentSettingsMap() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!host_content_settings_map_.get()) {
// The |is_incognito_profile| and |is_guest_profile| arguments are
// intentionally set to false as they otherwise limit the types of values
// that can be stored in the settings map (for example, default values set
// via DefaultProvider::SetWebsiteSetting).
host_content_settings_map_ =
new HostContentSettingsMap(GetPrefs(), false, false, false, false);
// Change the default plugin policy.
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
const std::string& plugin_policy_str =
command_line->GetSwitchValueASCII(switches::kPluginPolicy);
if (!plugin_policy_str.empty()) {
ContentSetting plugin_policy = CONTENT_SETTING_ALLOW;
if (base::LowerCaseEqualsASCII(plugin_policy_str,
switches::kPluginPolicy_Detect)) {
plugin_policy = CONTENT_SETTING_DETECT_IMPORTANT_CONTENT;
} else if (base::LowerCaseEqualsASCII(plugin_policy_str,
switches::kPluginPolicy_Block)) {
plugin_policy = CONTENT_SETTING_BLOCK;
}
host_content_settings_map_->SetDefaultContentSetting(
ContentSettingsType::PLUGINS, plugin_policy);
}
}
return host_content_settings_map_.get();
}
void CefBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) {
visitedlink_master_->AddURLs(urls);
}
void CefBrowserContext::RebuildTable(
const scoped_refptr<URLEnumerator>& enumerator) {
// Called when visited links will not or cannot be loaded from disk.
enumerator->OnComplete(true);
}
void CefBrowserContext::OnRenderFrameCreated( void CefBrowserContext::OnRenderFrameCreated(
CefRequestContextImpl* request_context, CefRequestContextImpl* request_context,
int render_process_id, int render_process_id,
@ -611,15 +252,14 @@ void CefBrowserContext::OnRenderFrameCreated(
handler_map_.AddHandler(render_process_id, render_frame_id, handler_map_.AddHandler(render_process_id, render_frame_id,
frame_tree_node_id, handler); frame_tree_node_id, handler);
if (resource_context_) { if (iothread_state_) {
// Using base::Unretained() is safe because both this callback and // Using base::Unretained() is safe because both this callback and
// possible deletion of |resource_context_| will execute on the IO thread, // possible deletion of |iothread_state_| will execute on the IO thread,
// and this callback will be executed first. // and this callback will be executed first.
CEF_POST_TASK(CEF_IOT, CEF_POST_TASK(CEF_IOT, base::Bind(&CefIOThreadState::AddHandler,
base::Bind(&CefResourceContext::AddHandler, base::Unretained(iothread_state_.get()),
base::Unretained(resource_context_.get()), render_process_id, render_frame_id,
render_process_id, render_frame_id, frame_tree_node_id, handler));
frame_tree_node_id, handler));
} }
} }
} }
@ -650,15 +290,14 @@ void CefBrowserContext::OnRenderFrameDeleted(
handler_map_.RemoveHandler(render_process_id, render_frame_id, handler_map_.RemoveHandler(render_process_id, render_frame_id,
frame_tree_node_id); frame_tree_node_id);
if (resource_context_) { if (iothread_state_) {
// Using base::Unretained() is safe because both this callback and // Using base::Unretained() is safe because both this callback and
// possible deletion of |resource_context_| will execute on the IO thread, // possible deletion of |iothread_state_| will execute on the IO thread,
// and this callback will be executed first. // and this callback will be executed first.
CEF_POST_TASK( CEF_POST_TASK(CEF_IOT, base::Bind(&CefIOThreadState::RemoveHandler,
CEF_IOT, base::Unretained(iothread_state_.get()),
base::Bind(&CefResourceContext::RemoveHandler, render_process_id, render_frame_id,
base::Unretained(resource_context_.get()), frame_tree_node_id));
render_process_id, render_frame_id, frame_tree_node_id));
} }
} }
@ -760,56 +399,74 @@ void CefBrowserContext::ClearPluginLoadDecision(int render_process_id) {
} }
void CefBrowserContext::RegisterSchemeHandlerFactory( void CefBrowserContext::RegisterSchemeHandlerFactory(
const std::string& scheme_name, const CefString& scheme_name,
const std::string& domain_name, const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory) { CefRefPtr<CefSchemeHandlerFactory> factory) {
if (resource_context_) { if (iothread_state_) {
// Using base::Unretained() is safe because both this callback and possible // Using base::Unretained() is safe because both this callback and possible
// deletion of |resource_context_| will execute on the IO thread, and this // deletion of |iothread_state_| will execute on the IO thread, and this
// callback will be executed first. // callback will be executed first.
CEF_POST_TASK(CEF_IOT, CEF_POST_TASK(CEF_IOT,
base::Bind(&CefResourceContext::RegisterSchemeHandlerFactory, base::Bind(&CefIOThreadState::RegisterSchemeHandlerFactory,
base::Unretained(resource_context_.get()), base::Unretained(iothread_state_.get()),
scheme_name, domain_name, factory)); scheme_name, domain_name, factory));
} }
} }
void CefBrowserContext::ClearSchemeHandlerFactories() { void CefBrowserContext::ClearSchemeHandlerFactories() {
if (resource_context_) { if (iothread_state_) {
// Using base::Unretained() is safe because both this callback and possible // Using base::Unretained() is safe because both this callback and possible
// deletion of |resource_context_| will execute on the IO thread, and this // deletion of |iothread_state_| will execute on the IO thread, and this
// callback will be executed first. // callback will be executed first.
CEF_POST_TASK(CEF_IOT, CEF_POST_TASK(CEF_IOT,
base::Bind(&CefResourceContext::ClearSchemeHandlerFactories, base::Bind(&CefIOThreadState::ClearSchemeHandlerFactories,
base::Unretained(resource_context_.get()))); base::Unretained(iothread_state_.get())));
} }
} }
network::mojom::NetworkContext* CefBrowserContext::GetNetworkContext() { void CefBrowserContext::LoadExtension(
CEF_REQUIRE_UIT(); const CefString& root_directory,
return GetDefaultStoragePartition(this)->GetNetworkContext(); CefRefPtr<CefDictionaryValue> manifest,
CefRefPtr<CefExtensionHandler> handler,
CefRefPtr<CefRequestContext> loader_context) {
NOTIMPLEMENTED();
if (handler)
handler->OnExtensionLoadFailed(ERR_ABORTED);
} }
DownloadPrefs* CefBrowserContext::GetDownloadPrefs() { bool CefBrowserContext::GetExtensions(std::vector<CefString>& extension_ids) {
CEF_REQUIRE_UIT(); NOTIMPLEMENTED();
if (!download_prefs_) { return false;
download_prefs_.reset(new DownloadPrefs(this)); }
}
return download_prefs_.get(); CefRefPtr<CefExtension> CefBrowserContext::GetExtension(
const CefString& extension_id) {
NOTIMPLEMENTED();
return nullptr;
}
bool CefBrowserContext::UnloadExtension(const CefString& extension_id) {
NOTIMPLEMENTED();
return false;
} }
bool CefBrowserContext::IsPrintPreviewSupported() const { bool CefBrowserContext::IsPrintPreviewSupported() const {
CEF_REQUIRE_UIT(); return true;
if (!extensions::PrintPreviewEnabled()) }
return false;
return !GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled); void CefBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) {}
network::mojom::NetworkContext* CefBrowserContext::GetNetworkContext() {
CEF_REQUIRE_UIT();
auto browser_context = AsBrowserContext();
return browser_context->GetDefaultStoragePartition(browser_context)
->GetNetworkContext();
} }
CefMediaRouterManager* CefBrowserContext::GetMediaRouterManager() { CefMediaRouterManager* CefBrowserContext::GetMediaRouterManager() {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
if (!media_router_manager_) { if (!media_router_manager_) {
media_router_manager_.reset(new CefMediaRouterManager(this)); media_router_manager_.reset(new CefMediaRouterManager(AsBrowserContext()));
} }
return media_router_manager_.get(); return media_router_manager_.get();
} }

View File

@ -7,23 +7,17 @@
#pragma once #pragma once
#include <set> #include <set>
#include <vector>
#include "include/cef_request_context_handler.h" #include "include/cef_request_context_handler.h"
#include "libcef/browser/alloy/chrome_profile_alloy.h"
#include "libcef/browser/request_context_handler_map.h" #include "libcef/browser/request_context_handler_map.h"
#include "libcef/browser/resource_context.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/download/download_prefs.h" #include "base/optional.h"
#include "chrome/common/plugin.mojom.h" #include "chrome/common/plugin.mojom.h"
#include "components/proxy_config/pref_proxy_config_tracker.h" #include "services/network/public/mojom/network_context.mojom.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "url/origin.h" #include "url/origin.h"
/* /*
@ -31,32 +25,30 @@
// //
// WC = WebContents // WC = WebContents
// Content API representation of a browser. Created by BHI or the system (for // Content API representation of a browser. Created by BHI or the system (for
// popups) and owned by BHI. Keeps a pointer to BC. // popups) and owned by BHI. Keeps a pointer to the content::BrowserContext.
// //
// BHI = CefBrowserHostImpl // BHI = CefBrowserHostImpl
// Implements the CefBrowser and CefBrowserHost interfaces which are exposed // Implements the CefBrowser and CefBrowserHost interfaces which are exposed
// to clients. References an RCI instance. Owns a WC. Life span is controlled // to clients. References an RCI instance. Owns a WC. Lifespan is controlled
// by client references and AlloyContentBrowserClient. // by client references and CefBrowserInfoManager (until the browser has
// closed).
// //
// RCI = CefRequestContextImpl // RCI = CefRequestContextImpl
// Implements the CefRequestContext interface which is exposed to clients. // Implements the CefRequestContext interface which is exposed to clients.
// References the isolated BC. // Creates or references a BC. Lifespan is controlled by client references and
// BrowserMainParts (for the global RCI).
// //
// BC = CefBrowserContext // BC = CefBrowserContext
// Entry point from WC when using an isolated RCI. Owns the RC and creates the // Is/owns the content::BrowserContext which is the entry point from WC.
// SPI indirectly. Owned by AlloyBrowserMainParts for the global context or // Owns the IOTS and creates the SPI indirectly. Potentially shared by
RCI // multiple RCI. Deletes itself when no longer needed by RCI.
// for non-global contexts.
// //
// SPI = content::StoragePartitionImpl // SPI = content::StoragePartitionImpl
// Owns storage-related objects like Quota, IndexedDB, Cache, etc. Created by // Owns storage-related objects like Quota, IndexedDB, Cache, etc. Created by
// StoragePartitionImplMap::Get(). Provides access to the URCG. Life span is // StoragePartitionImplMap::Get(). Life span is controlled indirectly by BC.
// controlled indirectly by BC.
// //
// RC = CefResourceContext // IOTS = CefIOThreadState
// Acts as a bridge for resource loading. Network request life span is tied to // Stores state for access on the IO thread. Life span is controlled by BC.
// this object. Must be destroyed before the associated URCG. Life span is
// controlled by BC.
// //
// //
// Relationship diagram: // Relationship diagram:
@ -64,142 +56,65 @@ RCI
// own = ownership (std::unique_ptr) // own = ownership (std::unique_ptr)
// ptr = raw pointer // ptr = raw pointer
// //
// AlloyBrowserMainParts // BHI -ref-> RCI -ptr-> BC -own-> SPI, IOTS
// | // ^
// own // BHI -own-> WC -ptr--/
// v
// BHI -own-> WC -ptr-> BC -own-> SPI
//
// BHI -ref-> RCI -own-> BC -own-> RC
// //
// //
// How shutdown works: // How shutdown works:
// 1. CefBrowserHostImpl is destroyed on any thread due to browser close, // 1. CefBrowserHostImpl::DestroyBrowser is called on the UI thread after the
// ref release, etc. // browser is closed and deletes the WebContents.
// 1. CefBrowserHostImpl is destroyed on any thread when the last reference
// is released.
// 2. CefRequestContextImpl is destroyed (possibly asynchronously) on the UI // 2. CefRequestContextImpl is destroyed (possibly asynchronously) on the UI
// thread due to CefBrowserHostImpl destruction, ref release, etc. // thread when the last reference is released.
// 3. CefBrowserContext is destroyed on the UI thread due to // 3. CefBrowserContext is destroyed on the UI thread when no longer needed
// CefRequestContextImpl destruction or deletion in // by any CefRequestContextImpl (via RemoveCefRequestContext).
// AlloyBrowserMainParts::PostMainMessageLoopRun(). // 4. CefIOThreadState is destroyed asynchronously on the IO thread after
// 4. CefResourceContext is destroyed asynchronously on the IO thread due to // the owning CefBrowserContext is destroyed.
// CefBrowserContext destruction. This cancels/destroys any pending
// network requests.
*/ */
class CefDownloadManagerDelegate; namespace content {
class BrowserContext;
}
class CefMediaRouterManager; class CefMediaRouterManager;
class CefRequestContextImpl; class CefRequestContextImpl;
class CefSSLHostStateDelegate; class CefIOThreadState;
class CefVisitedLinkListener; class Profile;
class HostContentSettingsMap;
class PrefService;
namespace extensions { // Main entry point for configuring behavior on a per-RequestContext basis. The
class CefExtensionSystem; // content::BrowserContext represented by this class is passed to
} // WebContents::Create in CefBrowserHostImpl::CreateInternal. Only accessed on
// the UI thread unless otherwise indicated.
namespace visitedlink { class CefBrowserContext {
class VisitedLinkWriter;
}
// Main entry point for configuring behavior on a per-browser basis. An instance
// of this class is passed to WebContents::Create in CefBrowserHostImpl::
// CreateInternal. Only accessed on the UI thread unless otherwise indicated.
class CefBrowserContext : public ChromeProfileAlloy,
public visitedlink::VisitedLinkDelegate {
public: public:
explicit CefBrowserContext(const CefRequestContextSettings& settings);
// Returns the existing instance, if any, associated with the specified // Returns the existing instance, if any, associated with the specified
// |cache_path|. // |cache_path|.
static CefBrowserContext* GetForCachePath(const base::FilePath& cache_path); static CefBrowserContext* FromCachePath(const base::FilePath& cache_path);
// Returns the existing instance, if any, associated with the specified IDs. // Returns the existing instance, if any, associated with the specified IDs.
// See comments on IsAssociatedContext() for usage. // See comments on IsAssociatedContext() for usage.
static CefBrowserContext* GetForIDs(int render_process_id, static CefBrowserContext* FromIDs(int render_process_id,
int render_frame_id, int render_frame_id,
int frame_tree_node_id, int frame_tree_node_id,
bool require_frame_match); bool require_frame_match);
// Returns the underlying CefBrowserContext if any. // Returns the underlying CefBrowserContext if any.
static CefBrowserContext* GetForContext(content::BrowserContext* context); static CefBrowserContext* FromBrowserContext(
const content::BrowserContext* context);
// Returns all existing CefBrowserContext. // Returns all existing CefBrowserContext.
static std::vector<CefBrowserContext*> GetAll(); static std::vector<CefBrowserContext*> GetAll();
// Must be called immediately after this object is created. // Returns the content and chrome layer representations of the context.
void Initialize(); virtual content::BrowserContext* AsBrowserContext() = 0;
virtual Profile* AsProfile() = 0;
// Track associated CefRequestContextImpl objects. This object will delete // Called from CefRequestContextImpl to track associated objects. This
// itself when the count reaches zero. // object will delete itself when the count reaches zero.
void AddCefRequestContext(CefRequestContextImpl* context); void AddCefRequestContext(CefRequestContextImpl* context);
void RemoveCefRequestContext(CefRequestContextImpl* context); virtual void RemoveCefRequestContext(CefRequestContextImpl* context);
// BrowserContext methods.
content::ResourceContext* GetResourceContext() override;
content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
override;
void SetCorsOriginAccessListForOrigin(
const url::Origin& source_origin,
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
base::OnceClosure closure) override;
base::FilePath GetPath() override;
base::FilePath GetPath() const override;
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
bool IsOffTheRecord() const override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
content::StorageNotificationService* GetStorageNotificationService() override;
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
override;
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
// Profile methods.
ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
PrefService* GetPrefs() override;
bool AllowsBrowserWindows() const override { return false; }
const PrefService* GetPrefs() const override;
ProfileKey* GetProfileKey() const override;
policy::SchemaRegistryService* GetPolicySchemaRegistryService() override;
policy::UserCloudPolicyManager* GetUserCloudPolicyManager() override;
policy::ProfilePolicyConnector* GetProfilePolicyConnector() override;
const policy::ProfilePolicyConnector* GetProfilePolicyConnector()
const override;
// Values checked in ProfileNetworkContextService::CreateNetworkContextParams
// when creating the NetworkContext.
bool ShouldRestoreOldSessionCookies() override {
return should_persist_session_cookies_;
}
bool ShouldPersistSessionCookies() override {
return should_persist_session_cookies_;
}
base::Optional<std::vector<std::string>> GetCookieableSchemes() override {
return cookieable_schemes_;
}
// visitedlink::VisitedLinkDelegate methods.
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
// Returns the settings associated with this object. Safe to call from any
// thread.
const CefRequestContextSettings& GetSettings() const;
// Settings for plugins and extensions.
HostContentSettingsMap* GetHostContentSettingsMap();
// Called from CefBrowserHostImpl::DidNavigateAnyFrame to update the table of
// visited links.
void AddVisitedURLs(const std::vector<GURL>& urls);
// Called from CefRequestContextImpl::OnRenderFrameCreated. // Called from CefRequestContextImpl::OnRenderFrameCreated.
void OnRenderFrameCreated(CefRequestContextImpl* request_context, void OnRenderFrameCreated(CefRequestContextImpl* request_context,
@ -255,79 +170,72 @@ class CefBrowserContext : public ChromeProfileAlloy,
void ClearPluginLoadDecision(int render_process_id); void ClearPluginLoadDecision(int render_process_id);
// Called from CefRequestContextImpl methods of the same name. // Called from CefRequestContextImpl methods of the same name.
void RegisterSchemeHandlerFactory(const std::string& scheme_name, void RegisterSchemeHandlerFactory(const CefString& scheme_name,
const std::string& domain_name, const CefString& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory); CefRefPtr<CefSchemeHandlerFactory> factory);
void ClearSchemeHandlerFactories(); void ClearSchemeHandlerFactories();
// TODO(chrome-runtime): Make these extension methods pure virtual.
virtual void LoadExtension(const CefString& root_directory,
CefRefPtr<CefDictionaryValue> manifest,
CefRefPtr<CefExtensionHandler> handler,
CefRefPtr<CefRequestContext> loader_context);
virtual bool GetExtensions(std::vector<CefString>& extension_ids);
virtual CefRefPtr<CefExtension> GetExtension(const CefString& extension_id);
// Called from CefExtensionImpl::Unload().
virtual bool UnloadExtension(const CefString& extension_id);
// Returns true if this context supports print preview.
virtual bool IsPrintPreviewSupported() const;
// Called from CefBrowserHostImpl::DidNavigateAnyFrame to update the table of
// visited links.
virtual void AddVisitedURLs(const std::vector<GURL>& urls);
network::mojom::NetworkContext* GetNetworkContext(); network::mojom::NetworkContext* GetNetworkContext();
void set_should_persist_session_cookies(bool value) { CefMediaRouterManager* GetMediaRouterManager();
should_persist_session_cookies_ = value;
}
void set_cookieable_schemes( void set_cookieable_schemes(
base::Optional<std::vector<std::string>> schemes) { base::Optional<std::vector<std::string>> schemes) {
cookieable_schemes_ = schemes; cookieable_schemes_ = schemes;
} }
CefResourceContext* resource_context() const { // These accessors are safe to call from any thread because the values don't
return resource_context_.get(); // change during this object's lifespan.
} const CefRequestContextSettings& settings() const { return settings_; }
extensions::CefExtensionSystem* extension_system() const { base::FilePath cache_path() const { return cache_path_; }
return extension_system_; CefIOThreadState* iothread_state() const { return iothread_state_.get(); }
}
// Called from DownloadPrefs::FromBrowserContext. // Used to hold a WeakPtr reference to this this object. The Getter returns
DownloadPrefs* GetDownloadPrefs(); // nullptr if this object has already been destroyed.
// Returns true if this context supports print preview.
bool IsPrintPreviewSupported() const;
CefMediaRouterManager* GetMediaRouterManager();
// Returns the BrowserContext, or nullptr if the BrowserContext has already
// been destroyed.
using Getter = base::RepeatingCallback<CefBrowserContext*()>; using Getter = base::RepeatingCallback<CefBrowserContext*()>;
Getter getter() const { return getter_; } Getter getter() const { return getter_; }
private: protected:
// Allow deletion via std::unique_ptr(). explicit CefBrowserContext(const CefRequestContextSettings& settings);
friend std::default_delete<CefBrowserContext>; virtual ~CefBrowserContext();
~CefBrowserContext() override; // Will be called immediately after this object is created.
virtual void Initialize();
// Members initialized during construction are safe to access from any thread. // Will be called immediately before this object is deleted.
virtual void Shutdown();
// Members initialized during construction or Initialize() are safe to access
// from any thread.
const CefRequestContextSettings settings_; const CefRequestContextSettings settings_;
base::FilePath cache_path_; base::FilePath cache_path_;
// CefRequestContextImpl objects referencing this object.
std::set<CefRequestContextImpl*> request_context_set_;
std::unique_ptr<PrefService> pref_service_;
std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
std::unique_ptr<CefDownloadManagerDelegate> download_manager_delegate_;
std::unique_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
std::unique_ptr<visitedlink::VisitedLinkWriter> visitedlink_master_;
// |visitedlink_listener_| is owned by visitedlink_master_.
CefVisitedLinkListener* visitedlink_listener_;
bool should_persist_session_cookies_ = false;
base::Optional<std::vector<std::string>> cookieable_schemes_; base::Optional<std::vector<std::string>> cookieable_schemes_;
std::unique_ptr<CefResourceContext> resource_context_; private:
std::unique_ptr<CefIOThreadState> iothread_state_;
// Owned by the KeyedService system.
extensions::CefExtensionSystem* extension_system_ = nullptr;
// The key to index KeyedService instances created by
// SimpleKeyedServiceFactory.
std::unique_ptr<ProfileKey> key_;
std::unique_ptr<DownloadPrefs> download_prefs_;
std::unique_ptr<CefMediaRouterManager> media_router_manager_; std::unique_ptr<CefMediaRouterManager> media_router_manager_;
// CefRequestContextImpl objects referencing this object.
std::set<CefRequestContextImpl*> request_context_set_;
// Map IDs to CefRequestContextHandler objects. // Map IDs to CefRequestContextHandler objects.
CefRequestContextHandlerMap handler_map_; CefRequestContextHandlerMap handler_map_;
@ -351,6 +259,10 @@ class CefBrowserContext : public ChromeProfileAlloy,
typedef std::set<int> NodeIdSet; typedef std::set<int> NodeIdSet;
NodeIdSet node_id_set_; NodeIdSet node_id_set_;
#if DCHECK_IS_ON()
bool is_shutdown_ = false;
#endif
Getter getter_; Getter getter_;
base::WeakPtrFactory<CefBrowserContext> weak_ptr_factory_; base::WeakPtrFactory<CefBrowserContext> weak_ptr_factory_;

View File

@ -8,7 +8,6 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "libcef/browser/alloy/alloy_content_browser_client.h"
#include "libcef/browser/audio_capturer.h" #include "libcef/browser/audio_capturer.h"
#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_context.h"
#include "libcef/browser/browser_info.h" #include "libcef/browser/browser_info.h"
@ -365,9 +364,10 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
CefRequestContextImpl::GetOrCreateForRequestContext( CefRequestContextImpl::GetOrCreateForRequestContext(
create_params.request_context); create_params.request_context);
DCHECK(request_context_impl); DCHECK(request_context_impl);
CefBrowserContext* browser_context = CefBrowserContext* cef_browser_context =
request_context_impl->GetBrowserContext(); request_context_impl->GetBrowserContext();
DCHECK(browser_context); DCHECK(cef_browser_context);
auto browser_context = cef_browser_context->AsBrowserContext();
if (!create_params.request_context) { if (!create_params.request_context) {
// Using the global request context. // Using the global request context.
@ -384,8 +384,8 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
extensions::GetExtensionForUrl(browser_context, create_params.url); extensions::GetExtensionForUrl(browser_context, create_params.url);
} }
if (create_params.extension) { if (create_params.extension) {
cef_extension = browser_context->extension_system()->GetExtension( cef_extension =
create_params.extension->id()); cef_browser_context->GetExtension(create_params.extension->id());
DCHECK(cef_extension); DCHECK(cef_extension);
if (create_params.extension_host_type == extensions::VIEW_TYPE_INVALID) { if (create_params.extension_host_type == extensions::VIEW_TYPE_INVALID) {
@ -755,13 +755,12 @@ void CefBrowserHostImpl::StartDownload(const CefString& url) {
if (!web_contents()) if (!web_contents())
return; return;
CefBrowserContext* context = auto browser_context = web_contents()->GetBrowserContext();
static_cast<CefBrowserContext*>(web_contents()->GetBrowserContext()); if (!browser_context)
if (!context)
return; return;
content::DownloadManager* manager = content::DownloadManager* manager =
content::BrowserContext::GetDownloadManager(context); content::BrowserContext::GetDownloadManager(browser_context);
if (!manager) if (!manager)
return; return;
@ -1588,9 +1587,9 @@ bool CefBrowserHostImpl::IsPrintPreviewSupported() const {
if (!actionable_contents) if (!actionable_contents)
return false; return false;
if (!CefBrowserContext::GetForContext( auto cef_browser_context = CefBrowserContext::FromBrowserContext(
actionable_contents->GetBrowserContext()) actionable_contents->GetBrowserContext());
->IsPrintPreviewSupported()) { if (!cef_browser_context->IsPrintPreviewSupported()) {
return false; return false;
} }
@ -2736,10 +2735,11 @@ void CefBrowserHostImpl::DidFinishNavigation(
} }
if (web_contents()) { if (web_contents()) {
CefBrowserContext* context = auto cef_browser_context = CefBrowserContext::FromBrowserContext(
static_cast<CefBrowserContext*>(web_contents()->GetBrowserContext()); web_contents()->GetBrowserContext());
if (context) { if (cef_browser_context) {
context->AddVisitedURLs(navigation_handle->GetRedirectChain()); cef_browser_context->AddVisitedURLs(
navigation_handle->GetRedirectChain());
} }
} }
} }

View File

@ -42,6 +42,10 @@ class Extension;
class ExtensionHost; class ExtensionHost;
} // namespace extensions } // namespace extensions
namespace gfx {
class ImageSkia;
}
#if defined(USE_AURA) #if defined(USE_AURA)
namespace views { namespace views {
class Widget; class Widget;

View File

@ -29,6 +29,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
@ -620,7 +621,8 @@ void CefDevToolsFrontend::AgentHostClosed(
} }
PrefService* CefDevToolsFrontend::GetPrefs() const { PrefService* CefDevToolsFrontend::GetPrefs() const {
return static_cast<CefBrowserContext*>( return CefBrowserContext::FromBrowserContext(
frontend_browser_->web_contents()->GetBrowserContext()) frontend_browser_->web_contents()->GetBrowserContext())
->AsProfile()
->GetPrefs(); ->GetPrefs();
} }

View File

@ -4,7 +4,6 @@
#include "libcef/browser/extension_impl.h" #include "libcef/browser/extension_impl.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/request_context_impl.h" #include "libcef/browser/request_context_impl.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/values_impl.h" #include "libcef/common/values_impl.h"
@ -89,7 +88,6 @@ void CefExtensionImpl::Unload() {
const bool result = static_cast<CefRequestContextImpl*>(loader_context_) const bool result = static_cast<CefRequestContextImpl*>(loader_context_)
->GetBrowserContext() ->GetBrowserContext()
->extension_system()
->UnloadExtension(id_); ->UnloadExtension(id_);
ALLOW_UNUSED_LOCAL(result); ALLOW_UNUSED_LOCAL(result);
DCHECK(result); DCHECK(result);

View File

@ -149,16 +149,16 @@ CefRefPtr<CefBrowserHostImpl> GetBrowserForTabId(
if (tab_id < 0 || !browser_context) if (tab_id < 0 || !browser_context)
return nullptr; return nullptr;
CefBrowserContext* browser_context_impl = auto cef_browser_context =
CefBrowserContext::GetForContext(browser_context); CefBrowserContext::FromBrowserContext(browser_context);
for (const auto& browser_info : for (const auto& browser_info :
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) { CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) {
CefRefPtr<CefBrowserHostImpl> current_browser = browser_info->browser(); CefRefPtr<CefBrowserHostImpl> current_browser = browser_info->browser();
if (current_browser && current_browser->GetIdentifier() == tab_id) { if (current_browser && current_browser->GetIdentifier() == tab_id) {
// Make sure we're operating in the same BrowserContextImpl. // Make sure we're operating in the same CefBrowserContext.
if (CefBrowserContext::GetForContext( if (CefBrowserContext::FromBrowserContext(
current_browser->GetBrowserContext()) == browser_context_impl) { current_browser->GetBrowserContext()) == cef_browser_context) {
return current_browser; return current_browser;
} else { } else {
LOG(WARNING) << "Browser with tabId " << tab_id LOG(WARNING) << "Browser with tabId " << tab_id

View File

@ -166,9 +166,10 @@ CefRefPtr<CefBrowserHostImpl> CefExtensionFunctionDetails::GetCurrentBrowser()
CefRefPtr<CefBrowserHostImpl> active_browser_impl = CefRefPtr<CefBrowserHostImpl> active_browser_impl =
static_cast<CefBrowserHostImpl*>(active_browser.get()); static_cast<CefBrowserHostImpl*>(active_browser.get());
// Make sure we're operating in the same BrowserContextImpl. // Make sure we're operating in the same CefBrowserContext.
if (CefBrowserContext::GetForContext(browser->GetBrowserContext()) == if (CefBrowserContext::FromBrowserContext(
CefBrowserContext::GetForContext( browser->GetBrowserContext()) ==
CefBrowserContext::FromBrowserContext(
active_browser_impl->GetBrowserContext())) { active_browser_impl->GetBrowserContext())) {
browser = active_browser_impl; browser = active_browser_impl;
} else { } else {
@ -347,13 +348,12 @@ base::DictionaryValue* CefExtensionFunctionDetails::OpenTab(
if (params.index.get()) if (params.index.get())
index = *params.index; index = *params.index;
CefBrowserContext* browser_context_impl = auto cef_browser_context = CefBrowserContext::FromBrowserContext(
CefBrowserContext::GetForContext(active_browser->GetBrowserContext()); active_browser->GetBrowserContext());
// A CEF representation should always exist. // A CEF representation should always exist.
CefRefPtr<CefExtension> cef_extension = CefRefPtr<CefExtension> cef_extension =
browser_context_impl->extension_system()->GetExtension( cef_browser_context->GetExtension(function()->extension()->id());
function()->extension()->id());
DCHECK(cef_extension); DCHECK(cef_extension);
if (!cef_extension) if (!cef_extension)
return nullptr; return nullptr;
@ -466,8 +466,7 @@ CefExtensionFunctionDetails::CreateMutedInfo(content::WebContents* contents) {
CefRefPtr<CefExtension> CefExtensionFunctionDetails::GetCefExtension() const { CefRefPtr<CefExtension> CefExtensionFunctionDetails::GetCefExtension() const {
if (!cef_extension_) { if (!cef_extension_) {
cef_extension_ = cef_extension_ =
static_cast<CefBrowserContext*>(function_->browser_context()) CefBrowserContext::FromBrowserContext(function_->browser_context())
->extension_system()
->GetExtension(function_->extension_id()); ->GetExtension(function_->extension_id());
DCHECK(cef_extension_); DCHECK(cef_extension_);
} }

View File

@ -36,8 +36,8 @@ CefExtensionsAPIClient::CreateGuestViewManagerDelegate(
// The GuestViewManager instance associated with the returned Delegate, which // The GuestViewManager instance associated with the returned Delegate, which
// will be retrieved in the future via GuestViewManager::FromBrowserContext, // will be retrieved in the future via GuestViewManager::FromBrowserContext,
// will be associated with the CefBrowserContext. // will be associated with the CefBrowserContext.
return base::WrapUnique(new extensions::ExtensionsGuestViewManagerDelegate( return base::WrapUnique(
CefBrowserContext::GetForContext(context))); new extensions::ExtensionsGuestViewManagerDelegate(context));
} }
std::unique_ptr<MimeHandlerViewGuestDelegate> std::unique_ptr<MimeHandlerViewGuestDelegate>

View File

@ -138,7 +138,10 @@ BrowserContext* CefExtensionsBrowserClient::GetOffTheRecordContext(
BrowserContext* CefExtensionsBrowserClient::GetOriginalContext( BrowserContext* CefExtensionsBrowserClient::GetOriginalContext(
BrowserContext* context) { BrowserContext* context) {
return CefBrowserContext::GetForContext(context); auto cef_browser_context = CefBrowserContext::FromBrowserContext(context);
if (cef_browser_context)
return cef_browser_context->AsBrowserContext();
return nullptr;
} }
bool CefExtensionsBrowserClient::IsGuestSession(BrowserContext* context) const { bool CefExtensionsBrowserClient::IsGuestSession(BrowserContext* context) const {
@ -200,7 +203,9 @@ bool CefExtensionsBrowserClient::AllowCrossRendererResourceLoad(
PrefService* CefExtensionsBrowserClient::GetPrefServiceForContext( PrefService* CefExtensionsBrowserClient::GetPrefServiceForContext(
BrowserContext* context) { BrowserContext* context) {
return static_cast<CefBrowserContext*>(context)->GetPrefs(); return CefBrowserContext::FromBrowserContext(context)
->AsProfile()
->GetPrefs();
} }
void CefExtensionsBrowserClient::GetEarlyExtensionPrefsObservers( void CefExtensionsBrowserClient::GetEarlyExtensionPrefsObservers(
@ -224,12 +229,12 @@ bool CefExtensionsBrowserClient::CreateBackgroundExtensionHost(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const GURL& url, const GURL& url,
ExtensionHost** host) { ExtensionHost** host) {
CefBrowserContext* browser_context_impl = auto cef_browser_context =
CefBrowserContext::GetForContext(browser_context); CefBrowserContext::FromBrowserContext(browser_context);
// A CEF representation should always exist. // A CEF representation should always exist.
CefRefPtr<CefExtension> cef_extension = CefRefPtr<CefExtension> cef_extension =
browser_context_impl->extension_system()->GetExtension(extension->id()); cef_browser_context->GetExtension(extension->id());
DCHECK(cef_extension); DCHECK(cef_extension);
if (!cef_extension) { if (!cef_extension) {
// Cancel the background host creation. // Cancel the background host creation.

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "libcef/browser/resource_context.h" #include "libcef/browser/iothread_state.h"
#include "libcef/browser/net/scheme_handler.h" #include "libcef/browser/net/scheme_handler.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
@ -15,36 +15,34 @@
#include "content/browser/resource_context_impl.h" #include "content/browser/resource_context_impl.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
CefResourceContext::CefResourceContext(bool is_off_the_record) CefIOThreadState::CefIOThreadState() {
: is_off_the_record_(is_off_the_record) {
// Using base::Unretained() is safe because both this callback and possible // Using base::Unretained() is safe because both this callback and possible
// deletion of |this| will execute on the IO thread, and this callback will // deletion of |this| will execute on the IO thread, and this callback will
// be executed first. // be executed first.
CEF_POST_TASK(CEF_IOT, base::Bind(&CefResourceContext::InitOnIOThread, CEF_POST_TASK(CEF_IOT, base::Bind(&CefIOThreadState::InitOnIOThread,
base::Unretained(this))); base::Unretained(this)));
} }
CefResourceContext::~CefResourceContext() {} CefIOThreadState::~CefIOThreadState() {}
void CefResourceContext::AddHandler( void CefIOThreadState::AddHandler(int render_process_id,
int render_process_id, int render_frame_id,
int render_frame_id, int frame_tree_node_id,
int frame_tree_node_id, CefRefPtr<CefRequestContextHandler> handler) {
CefRefPtr<CefRequestContextHandler> handler) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
handler_map_.AddHandler(render_process_id, render_frame_id, handler_map_.AddHandler(render_process_id, render_frame_id,
frame_tree_node_id, handler); frame_tree_node_id, handler);
} }
void CefResourceContext::RemoveHandler(int render_process_id, void CefIOThreadState::RemoveHandler(int render_process_id,
int render_frame_id, int render_frame_id,
int frame_tree_node_id) { int frame_tree_node_id) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
handler_map_.RemoveHandler(render_process_id, render_frame_id, handler_map_.RemoveHandler(render_process_id, render_frame_id,
frame_tree_node_id); frame_tree_node_id);
} }
CefRefPtr<CefRequestContextHandler> CefResourceContext::GetHandler( CefRefPtr<CefRequestContextHandler> CefIOThreadState::GetHandler(
int render_process_id, int render_process_id,
int render_frame_id, int render_frame_id,
int frame_tree_node_id, int frame_tree_node_id,
@ -54,7 +52,7 @@ CefRefPtr<CefRequestContextHandler> CefResourceContext::GetHandler(
frame_tree_node_id, require_frame_match); frame_tree_node_id, require_frame_match);
} }
void CefResourceContext::RegisterSchemeHandlerFactory( void CefIOThreadState::RegisterSchemeHandlerFactory(
const std::string& scheme_name, const std::string& scheme_name,
const std::string& domain_name, const std::string& domain_name,
CefRefPtr<CefSchemeHandlerFactory> factory) { CefRefPtr<CefSchemeHandlerFactory> factory) {
@ -83,7 +81,7 @@ void CefResourceContext::RegisterSchemeHandlerFactory(
} }
} }
void CefResourceContext::ClearSchemeHandlerFactories() { void CefIOThreadState::ClearSchemeHandlerFactories() {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
scheme_handler_factory_map_.clear(); scheme_handler_factory_map_.clear();
@ -92,7 +90,7 @@ void CefResourceContext::ClearSchemeHandlerFactories() {
scheme::RegisterInternalHandlers(this); scheme::RegisterInternalHandlers(this);
} }
CefRefPtr<CefSchemeHandlerFactory> CefResourceContext::GetSchemeHandlerFactory( CefRefPtr<CefSchemeHandlerFactory> CefIOThreadState::GetSchemeHandlerFactory(
const GURL& url) { const GURL& url) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
@ -123,7 +121,7 @@ CefRefPtr<CefSchemeHandlerFactory> CefResourceContext::GetSchemeHandlerFactory(
return nullptr; return nullptr;
} }
void CefResourceContext::InitOnIOThread() { void CefIOThreadState::InitOnIOThread() {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
// Add the default internal handlers. // Add the default internal handlers.

View File

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CEF_LIBCEF_BROWSER_RESOURCE_CONTEXT_H_ #ifndef CEF_LIBCEF_BROWSER_IOTHREAD_STATE_H_
#define CEF_LIBCEF_BROWSER_RESOURCE_CONTEXT_H_ #define CEF_LIBCEF_BROWSER_IOTHREAD_STATE_H_
#pragma once #pragma once
#include "include/cef_request_context.h" #include "include/cef_request_context.h"
@ -12,20 +12,15 @@
#include "libcef/browser/request_context_handler_map.h" #include "libcef/browser/request_context_handler_map.h"
#include "content/public/browser/resource_context.h"
class GURL; class GURL;
// Acts as a bridge for resource loading. Life span is controlled by // Stores state that will be accessed on the IO thread. Life span is controlled
// CefBrowserContext. Created on the UI thread but accessed and destroyed on the // by CefBrowserContext. Created on the UI thread but accessed and destroyed on
// IO thread. Network request objects are associated with the ResourceContext // the IO thread. See browser_context.h for an object relationship diagram.
// via ProxyURLLoaderFactory. When the ResourceContext is destroyed all class CefIOThreadState {
// outstanding network request objects will be canceled.
// See browser_context.h for an object relationship diagram.
class CefResourceContext : public content::ResourceContext {
public: public:
explicit CefResourceContext(bool is_off_the_record); CefIOThreadState();
~CefResourceContext() override; virtual ~CefIOThreadState();
// See comments in CefRequestContextHandlerMap. // See comments in CefRequestContextHandlerMap.
void AddHandler(int render_process_id, void AddHandler(int render_process_id,
@ -48,15 +43,9 @@ class CefResourceContext : public content::ResourceContext {
void ClearSchemeHandlerFactories(); void ClearSchemeHandlerFactories();
CefRefPtr<CefSchemeHandlerFactory> GetSchemeHandlerFactory(const GURL& url); CefRefPtr<CefSchemeHandlerFactory> GetSchemeHandlerFactory(const GURL& url);
// State transferred from the BrowserContext for use on the IO thread.
bool IsOffTheRecord() const { return is_off_the_record_; }
private: private:
void InitOnIOThread(); void InitOnIOThread();
// Only accessed on the IO thread.
const bool is_off_the_record_;
// Map IDs to CefRequestContextHandler objects. // Map IDs to CefRequestContextHandler objects.
CefRequestContextHandlerMap handler_map_; CefRequestContextHandlerMap handler_map_;
@ -66,7 +55,7 @@ class CefResourceContext : public content::ResourceContext {
SchemeHandlerFactoryMap; SchemeHandlerFactoryMap;
SchemeHandlerFactoryMap scheme_handler_factory_map_; SchemeHandlerFactoryMap scheme_handler_factory_map_;
DISALLOW_COPY_AND_ASSIGN(CefResourceContext); DISALLOW_COPY_AND_ASSIGN(CefIOThreadState);
}; };
#endif // CEF_LIBCEF_BROWSER_RESOURCE_CONTEXT_H_ #endif // CEF_LIBCEF_BROWSER_IOTHREAD_STATE_H_

View File

@ -121,7 +121,8 @@ class CefPresentationConnection : public blink::mojom::PresentationConnection {
DISALLOW_COPY_AND_ASSIGN(CefPresentationConnection); DISALLOW_COPY_AND_ASSIGN(CefPresentationConnection);
}; };
CefMediaRouterManager::CefMediaRouterManager(CefBrowserContext* browser_context) CefMediaRouterManager::CefMediaRouterManager(
content::BrowserContext* browser_context)
: browser_context_(browser_context), : browser_context_(browser_context),
query_result_manager_(GetMediaRouter()), query_result_manager_(GetMediaRouter()),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {

View File

@ -7,7 +7,6 @@
#pragma once #pragma once
#include "include/cef_media_router.h" #include "include/cef_media_router.h"
#include "libcef/browser/browser_context.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
@ -15,7 +14,10 @@
#include "chrome/browser/ui/media_router/query_result_manager.h" #include "chrome/browser/ui/media_router/query_result_manager.h"
#include "chrome/common/media_router/mojom/media_router.mojom.h" #include "chrome/common/media_router/mojom/media_router.mojom.h"
class CefBrowserContext; namespace content {
class BrowserContext;
}
class CefMediaRoutesObserver; class CefMediaRoutesObserver;
class CefPresentationConnection; class CefPresentationConnection;
class CefRouteMessageObserver; class CefRouteMessageObserver;
@ -46,7 +48,7 @@ class CefMediaRouterManager
~Observer() override {} ~Observer() override {}
}; };
explicit CefMediaRouterManager(CefBrowserContext* browser_context); explicit CefMediaRouterManager(content::BrowserContext* browser_context);
~CefMediaRouterManager() override; ~CefMediaRouterManager() override;
// |observer| must outlive this object or be removed. // |observer| must outlive this object or be removed.
@ -103,7 +105,7 @@ class CefMediaRouterManager
RouteState* GetRouteState(const media_router::MediaRoute::Id& route_id); RouteState* GetRouteState(const media_router::MediaRoute::Id& route_id);
void RemoveRouteState(const media_router::MediaRoute::Id& route_id); void RemoveRouteState(const media_router::MediaRoute::Id& route_id);
CefBrowserContext* const browser_context_; content::BrowserContext* const browser_context_;
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;

View File

@ -6,8 +6,8 @@
#include <string> #include <string>
#include "libcef/browser/iothread_state.h"
#include "libcef/browser/net/internal_scheme_handler.h" #include "libcef/browser/net/internal_scheme_handler.h"
#include "libcef/browser/resource_context.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
@ -40,8 +40,8 @@ class Delegate : public InternalHandlerDelegate {
} // namespace } // namespace
void RegisterChromeDevToolsHandler(CefResourceContext* resource_context) { void RegisterChromeDevToolsHandler(CefIOThreadState* iothread_state) {
resource_context->RegisterSchemeHandlerFactory( iothread_state->RegisterSchemeHandlerFactory(
content::kChromeDevToolsScheme, kChromeDevToolsHost, content::kChromeDevToolsScheme, kChromeDevToolsHost,
CreateInternalHandlerFactory(base::WrapUnique(new Delegate()))); CreateInternalHandlerFactory(base::WrapUnique(new Delegate())));
} }

View File

@ -6,14 +6,14 @@
#define CEF_LIBCEF_BROWSER_NET_DEVTOOLS_SCHEME_HANDLER_H_ #define CEF_LIBCEF_BROWSER_NET_DEVTOOLS_SCHEME_HANDLER_H_
#pragma once #pragma once
class CefResourceContext; class CefIOThreadState;
namespace scheme { namespace scheme {
extern const char kChromeDevToolsHost[]; extern const char kChromeDevToolsHost[];
// Register the chrome-devtools scheme handler. // Register the chrome-devtools scheme handler.
void RegisterChromeDevToolsHandler(CefResourceContext* resource_context); void RegisterChromeDevToolsHandler(CefIOThreadState* iothread_state);
} // namespace scheme } // namespace scheme

View File

@ -9,13 +9,17 @@
#include "libcef/browser/net/chrome_scheme_handler.h" #include "libcef/browser/net/chrome_scheme_handler.h"
#include "libcef/browser/net/devtools_scheme_handler.h" #include "libcef/browser/net/devtools_scheme_handler.h"
#include "libcef/common/net/scheme_registration.h" #include "libcef/common/net/scheme_registration.h"
#include "libcef/features/runtime.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
namespace scheme { namespace scheme {
void RegisterInternalHandlers(CefResourceContext* resource_context) { void RegisterInternalHandlers(CefIOThreadState* iothread_state) {
scheme::RegisterChromeDevToolsHandler(resource_context); if (!cef::IsAlloyRuntimeEnabled())
return;
scheme::RegisterChromeDevToolsHandler(iothread_state);
} }
void DidFinishLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url) { void DidFinishLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url) {

View File

@ -11,12 +11,12 @@
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "url/gurl.h" #include "url/gurl.h"
class CefResourceContext; class CefIOThreadState;
namespace scheme { namespace scheme {
// Register the internal scheme handlers that can be overridden. // Register the internal scheme handlers that can be overridden.
void RegisterInternalHandlers(CefResourceContext* resource_context); void RegisterInternalHandlers(CefIOThreadState* iothread_state);
// Used to fire any asynchronous content updates. // Used to fire any asynchronous content updates.
void DidFinishLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url); void DidFinishLoad(CefRefPtr<CefFrame> frame, const GURL& validated_url);

View File

@ -188,9 +188,9 @@ class CefBrowserURLRequest::Context
CefRefPtr<CefRequestContextImpl> request_context_impl = CefRefPtr<CefRequestContextImpl> request_context_impl =
CefRequestContextImpl::GetOrCreateForRequestContext(request_context); CefRequestContextImpl::GetOrCreateForRequestContext(request_context);
DCHECK(request_context_impl); DCHECK(request_context_impl);
CefBrowserContext* browser_context = CefBrowserContext* cef_browser_context =
request_context_impl->GetBrowserContext(); request_context_impl->GetBrowserContext();
DCHECK(browser_context); DCHECK(cef_browser_context);
int render_frame_id = MSG_ROUTING_NONE; int render_frame_id = MSG_ROUTING_NONE;
scoped_refptr<net_service::URLLoaderFactoryGetter> loader_factory_getter; scoped_refptr<net_service::URLLoaderFactoryGetter> loader_factory_getter;
@ -208,12 +208,12 @@ class CefBrowserURLRequest::Context
// network::mojom::kBrowserProcessId (value 0) for these requests. // network::mojom::kBrowserProcessId (value 0) for these requests.
render_frame_id = rfh->GetFrameTreeNodeId(); render_frame_id = rfh->GetFrameTreeNodeId();
loader_factory_getter = loader_factory_getter = net_service::URLLoaderFactoryGetter::Create(
net_service::URLLoaderFactoryGetter::Create(rfh, browser_context); rfh, cef_browser_context->AsBrowserContext());
} }
} else { } else {
loader_factory_getter = loader_factory_getter = net_service::URLLoaderFactoryGetter::Create(
net_service::URLLoaderFactoryGetter::Create(nullptr, browser_context); nullptr, cef_browser_context->AsBrowserContext());
} }
task_runner->PostTask( task_runner->PostTask(

View File

@ -30,7 +30,8 @@ CefBrowserContext* GetBrowserContext(const CefBrowserContext::Getter& getter) {
// Do not keep a reference to the object returned by this method. // Do not keep a reference to the object returned by this method.
CookieManager* GetCookieManager(CefBrowserContext* browser_context) { CookieManager* GetCookieManager(CefBrowserContext* browser_context) {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
return content::BrowserContext::GetDefaultStoragePartition(browser_context) return content::BrowserContext::GetDefaultStoragePartition(
browser_context->AsBrowserContext())
->GetCookieManagerForBrowserProcess(); ->GetCookieManagerForBrowserProcess();
} }

View File

@ -7,11 +7,11 @@
#include "libcef/browser/browser_host_impl.h" #include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/browser_platform_delegate.h" #include "libcef/browser/browser_platform_delegate.h"
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/iothread_state.h"
#include "libcef/browser/net_service/cookie_helper.h" #include "libcef/browser/net_service/cookie_helper.h"
#include "libcef/browser/net_service/proxy_url_loader_factory.h" #include "libcef/browser/net_service/proxy_url_loader_factory.h"
#include "libcef/browser/net_service/resource_handler_wrapper.h" #include "libcef/browser/net_service/resource_handler_wrapper.h"
#include "libcef/browser/net_service/response_filter_wrapper.h" #include "libcef/browser/net_service/response_filter_wrapper.h"
#include "libcef/browser/resource_context.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/app_manager.h" #include "libcef/common/app_manager.h"
#include "libcef/common/net/scheme_registration.h" #include "libcef/common/net/scheme_registration.h"
@ -19,6 +19,7 @@
#include "libcef/common/request_impl.h" #include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h" #include "libcef/common/response_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "components/language/core/browser/pref_names.h" #include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
@ -262,9 +263,10 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
browser_context_ = browser_context; browser_context_ = browser_context;
resource_context_ = static_cast<CefResourceContext*>( auto cef_browser_context =
browser_context->GetResourceContext()); CefBrowserContext::FromBrowserContext(browser_context);
DCHECK(resource_context_); iothread_state_ = cef_browser_context->iothread_state();
DCHECK(iothread_state_);
// We register to be notified of CEF context or browser destruction so // We register to be notified of CEF context or browser destruction so
// that we can stop accepting new requests and cancel pending/in-progress // that we can stop accepting new requests and cancel pending/in-progress
@ -312,7 +314,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
CefRefPtr<CefBrowserHostImpl> browser_; CefRefPtr<CefBrowserHostImpl> browser_;
CefRefPtr<CefFrame> frame_; CefRefPtr<CefFrame> frame_;
CefResourceContext* resource_context_ = nullptr; CefIOThreadState* iothread_state_ = nullptr;
int render_process_id_ = 0; int render_process_id_ = 0;
int render_frame_id_ = -1; int render_frame_id_ = -1;
int frame_tree_node_id_ = -1; int frame_tree_node_id_ = -1;
@ -450,7 +452,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
GetHandler(id, request, &intercept_only, requestPtr); GetHandler(id, request, &intercept_only, requestPtr);
CefRefPtr<CefSchemeHandlerFactory> scheme_factory = CefRefPtr<CefSchemeHandlerFactory> scheme_factory =
init_state_->resource_context_->GetSchemeHandlerFactory(request->url); init_state_->iothread_state_->GetSchemeHandlerFactory(request->url);
if (scheme_factory && !requestPtr) { if (scheme_factory && !requestPtr) {
requestPtr = MakeRequest(request, id.hash(), true); requestPtr = MakeRequest(request, id.hash(), true);
} }
@ -1055,7 +1057,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
if (!handler) { if (!handler) {
// Maybe the request context wants to handle it? // Maybe the request context wants to handle it?
CefRefPtr<CefRequestContextHandler> context_handler = CefRefPtr<CefRequestContextHandler> context_handler =
init_state_->resource_context_->GetHandler( init_state_->iothread_state_->GetHandler(
init_state_->render_process_id_, request->render_frame_id, init_state_->render_process_id_, request->render_frame_id,
init_state_->frame_tree_node_id_, false); init_state_->frame_tree_node_id_, false);
if (context_handler) { if (context_handler) {

View File

@ -88,8 +88,8 @@ bool CefPluginServiceFilter::IsPluginAvailable(
return true; return true;
} }
auto browser_context = CefBrowserContext::GetForIDs( auto browser_context =
render_process_id, render_frame_id, -1, false); CefBrowserContext::FromIDs(render_process_id, render_frame_id, -1, false);
CefRefPtr<CefRequestContextHandler> handler; CefRefPtr<CefRequestContextHandler> handler;
if (browser_context) { if (browser_context) {
handler = browser_context->GetHandler(render_process_id, render_frame_id, handler = browser_context->GetHandler(render_process_id, render_frame_id,

View File

@ -25,6 +25,7 @@
#include "chrome/browser/plugins/plugin_info_host_impl.h" #include "chrome/browser/plugins/plugin_info_host_impl.h"
#include "chrome/browser/prefs/chrome_command_line_pref_store.h" #include "chrome/browser/prefs/chrome_command_line_pref_store.h"
#include "chrome/browser/printing/print_preview_sticky_settings.h" #include "chrome/browser/printing/print_preview_sticky_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/pepper/device_id_fetcher.h" #include "chrome/browser/renderer_host/pepper/device_id_fetcher.h"
#include "chrome/browser/ssl/ssl_config_service_manager.h" #include "chrome/browser/ssl/ssl_config_service_manager.h"
#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service.h"
@ -73,7 +74,7 @@ namespace {
std::string GetAcceptLanguageList(Profile* profile) { std::string GetAcceptLanguageList(Profile* profile) {
const CefRequestContextSettings& context_settings = const CefRequestContextSettings& context_settings =
static_cast<CefBrowserContext*>(profile)->GetSettings(); CefBrowserContext::FromBrowserContext(profile)->settings();
if (context_settings.accept_language_list.length > 0) { if (context_settings.accept_language_list.length > 0) {
return CefString(&context_settings.accept_language_list); return CefString(&context_settings.accept_language_list);
} }

View File

@ -6,7 +6,6 @@
#include <string> #include <string>
#include "libcef/browser/browser_context.h"
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/extensions/browser_extensions_util.h" #include "libcef/browser/extensions/browser_extensions_util.h"
#include "libcef/common/cef_switches.h" #include "libcef/common/cef_switches.h"
@ -20,6 +19,7 @@
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
#include "chrome/browser/extensions/extension_webkit_preferences.h" #include "chrome/browser/extensions/extension_webkit_preferences.h"
#include "chrome/browser/font_family_cache.h" #include "chrome/browser/font_family_cache.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
@ -65,7 +65,7 @@ void SetDefaultPrefs(content::WebPreferences& web) {
// Chrome preferences. // Chrome preferences.
// Should match ChromeContentBrowserClient::OverrideWebkitPrefs. // Should match ChromeContentBrowserClient::OverrideWebkitPrefs.
void SetChromePrefs(CefBrowserContext* profile, content::WebPreferences& web) { void SetChromePrefs(Profile* profile, content::WebPreferences& web) {
PrefService* prefs = profile->GetPrefs(); PrefService* prefs = profile->GetPrefs();
// Fill per-script font preferences. // Fill per-script font preferences.
@ -334,7 +334,7 @@ void PopulateWebPreferences(content::RenderViewHost* rvh,
// Set preferences based on the context's PrefService. // Set preferences based on the context's PrefService.
if (browser) { if (browser) {
CefBrowserContext* profile = static_cast<CefBrowserContext*>( auto profile = Profile::FromBrowserContext(
browser->web_contents()->GetBrowserContext()); browser->web_contents()->GetBrowserContext());
SetChromePrefs(profile, web); SetChromePrefs(profile, web);
} }

View File

@ -5,10 +5,8 @@
#include "libcef/browser/request_context_impl.h" #include "libcef/browser/request_context_impl.h"
#include "libcef/browser/browser_context.h" #include "libcef/browser/browser_context.h"
#include "libcef/browser/context.h" #include "libcef/browser/context.h"
#include "libcef/browser/extensions/extension_system.h"
#include "libcef/browser/thread_util.h" #include "libcef/browser/thread_util.h"
#include "libcef/common/app_manager.h" #include "libcef/common/app_manager.h"
#include "libcef/common/extensions/extensions_util.h"
#include "libcef/common/task_runner_impl.h" #include "libcef/common/task_runner_impl.h"
#include "libcef/common/values_impl.h" #include "libcef/common/values_impl.h"
#include "libcef/features/runtime_checks.h" #include "libcef/features/runtime_checks.h"
@ -16,6 +14,7 @@
#include "base/atomic_sequence_num.h" #include "base/atomic_sequence_num.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/plugin_service.h" #include "content/public/browser/plugin_service.h"
@ -374,7 +373,7 @@ bool CefRequestContextImpl::HasPreference(const CefString& name) {
// Make sure the browser context exists. // Make sure the browser context exists.
EnsureBrowserContext(); EnsureBrowserContext();
PrefService* pref_service = browser_context()->GetPrefs(); PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
return (pref_service->FindPreference(name) != nullptr); return (pref_service->FindPreference(name) != nullptr);
} }
@ -389,7 +388,7 @@ CefRefPtr<CefValue> CefRequestContextImpl::GetPreference(
// Make sure the browser context exists. // Make sure the browser context exists.
EnsureBrowserContext(); EnsureBrowserContext();
PrefService* pref_service = browser_context()->GetPrefs(); PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
const PrefService::Preference* pref = pref_service->FindPreference(name); const PrefService::Preference* pref = pref_service->FindPreference(name);
if (!pref) if (!pref)
return nullptr; return nullptr;
@ -407,7 +406,7 @@ CefRefPtr<CefDictionaryValue> CefRequestContextImpl::GetAllPreferences(
// Make sure the browser context exists. // Make sure the browser context exists.
EnsureBrowserContext(); EnsureBrowserContext();
PrefService* pref_service = browser_context()->GetPrefs(); PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
std::unique_ptr<base::DictionaryValue> values = std::unique_ptr<base::DictionaryValue> values =
pref_service->GetPreferenceValues(include_defaults pref_service->GetPreferenceValues(include_defaults
@ -428,7 +427,7 @@ bool CefRequestContextImpl::CanSetPreference(const CefString& name) {
// Make sure the browser context exists. // Make sure the browser context exists.
EnsureBrowserContext(); EnsureBrowserContext();
PrefService* pref_service = browser_context()->GetPrefs(); PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
const PrefService::Preference* pref = pref_service->FindPreference(name); const PrefService::Preference* pref = pref_service->FindPreference(name);
return (pref && pref->IsUserModifiable()); return (pref && pref->IsUserModifiable());
} }
@ -445,7 +444,7 @@ bool CefRequestContextImpl::SetPreference(const CefString& name,
// Make sure the browser context exists. // Make sure the browser context exists.
EnsureBrowserContext(); EnsureBrowserContext();
PrefService* pref_service = browser_context()->GetPrefs(); PrefService* pref_service = browser_context()->AsProfile()->GetPrefs();
// The below validation logic should match PrefService::SetUserPrefValue. // The below validation logic should match PrefService::SetUserPrefValue.
@ -531,22 +530,10 @@ void CefRequestContextImpl::LoadExtension(
return; return;
} }
if (!extensions::ExtensionsEnabled()) { // Make sure the browser context exists.
if (handler) EnsureBrowserContext();
handler->OnExtensionLoadFailed(ERR_ABORTED);
return;
}
if (manifest && manifest->GetSize() > 0) { browser_context()->LoadExtension(root_directory, manifest, handler, this);
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) { bool CefRequestContextImpl::DidLoadExtension(const CefString& extension_id) {
@ -568,17 +555,10 @@ bool CefRequestContextImpl::GetExtensions(
return false; return false;
} }
if (!extensions::ExtensionsEnabled()) // Make sure the browser context exists.
return false; EnsureBrowserContext();
extensions::CefExtensionSystem::ExtensionMap extension_map = return browser_context()->GetExtensions(extension_ids);
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( CefRefPtr<CefExtension> CefRequestContextImpl::GetExtension(
@ -588,10 +568,10 @@ CefRefPtr<CefExtension> CefRequestContextImpl::GetExtension(
return nullptr; return nullptr;
} }
if (!extensions::ExtensionsEnabled()) // Make sure the browser context exists.
return nullptr; EnsureBrowserContext();
return GetBrowserContext()->extension_system()->GetExtension(extension_id); return browser_context()->GetExtension(extension_id);
} }
CefRefPtr<CefMediaRouter> CefRequestContextImpl::GetMediaRouter() { CefRefPtr<CefMediaRouter> CefRequestContextImpl::GetMediaRouter() {
@ -648,8 +628,7 @@ void CefRequestContextImpl::Initialize() {
if (config_.other) { if (config_.other) {
// Share storage with |config_.other|. // Share storage with |config_.other|.
browser_context_ = browser_context_ = config_.other->GetBrowserContext();
CefBrowserContext::GetForContext(config_.other->GetBrowserContext());
DCHECK(browser_context_); DCHECK(browser_context_);
} }
@ -664,7 +643,7 @@ void CefRequestContextImpl::Initialize() {
if (!cache_path.empty()) { if (!cache_path.empty()) {
// Check if a CefBrowserContext is already globally registered for // Check if a CefBrowserContext is already globally registered for
// the specified cache path. If so then use it. // the specified cache path. If so then use it.
browser_context_ = CefBrowserContext::GetForCachePath(cache_path); browser_context_ = CefBrowserContext::FromCachePath(cache_path);
} }
} }
@ -673,11 +652,11 @@ void CefRequestContextImpl::Initialize() {
// empty then this new instance will become the globally registered // empty then this new instance will become the globally registered
// CefBrowserContext for that path. Otherwise, this new instance will // CefBrowserContext for that path. Otherwise, this new instance will
// be a completely isolated "incognito mode" context. // be a completely isolated "incognito mode" context.
browser_context_ = new CefBrowserContext(config_.settings); browser_context_ =
browser_context_->Initialize(); CefAppManager::Get()->CreateNewBrowserContext(config_.settings);
} else { } else {
// Share the same settings as the existing context. // Share the same settings as the existing context.
config_.settings = browser_context_->GetSettings(); config_.settings = browser_context_->settings();
} }
// We'll disassociate from |browser_context_| on destruction. // We'll disassociate from |browser_context_| on destruction.
@ -728,8 +707,8 @@ void CefRequestContextImpl::PurgePluginListCacheInternal(
CefBrowserContext* browser_context) { CefBrowserContext* browser_context) {
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
browser_context->ClearPluginLoadDecision(-1); browser_context->ClearPluginLoadDecision(-1);
content::PluginService::GetInstance()->PurgePluginListCache(browser_context, content::PluginService::GetInstance()->PurgePluginListCache(
false); browser_context->AsBrowserContext(), false);
} }
void CefRequestContextImpl::ClearCertificateExceptionsInternal( void CefRequestContextImpl::ClearCertificateExceptionsInternal(
@ -738,7 +717,7 @@ void CefRequestContextImpl::ClearCertificateExceptionsInternal(
CEF_REQUIRE_UIT(); CEF_REQUIRE_UIT();
content::SSLHostStateDelegate* ssl_delegate = content::SSLHostStateDelegate* ssl_delegate =
browser_context->GetSSLHostStateDelegate(); browser_context->AsBrowserContext()->GetSSLHostStateDelegate();
if (ssl_delegate) if (ssl_delegate)
ssl_delegate->Clear(base::Callback<bool(const std::string&)>()); ssl_delegate->Clear(base::Callback<bool(const std::string&)>());

View File

@ -8,6 +8,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
#include "libcef/browser/alloy/alloy_browser_context.h"
#include "libcef/browser/alloy/alloy_content_browser_client.h" #include "libcef/browser/alloy/alloy_content_browser_client.h"
#include "libcef/common/cef_switches.h" #include "libcef/common/cef_switches.h"
#include "libcef/common/command_line_impl.h" #include "libcef/common/command_line_impl.h"
@ -723,6 +724,13 @@ CefRefPtr<CefRequestContext> AlloyMainDelegate::GetGlobalRequestContext() {
return browser_client_->request_context(); return browser_client_->request_context();
} }
CefBrowserContext* AlloyMainDelegate::CreateNewBrowserContext(
const CefRequestContextSettings& settings) {
auto context = new AlloyBrowserContext(settings);
context->Initialize();
return context;
}
scoped_refptr<base::SingleThreadTaskRunner> scoped_refptr<base::SingleThreadTaskRunner>
AlloyMainDelegate::GetBackgroundTaskRunner() { AlloyMainDelegate::GetBackgroundTaskRunner() {
if (browser_client_) if (browser_client_)

View File

@ -61,6 +61,8 @@ class AlloyMainDelegate : public content::ContentMainDelegate,
return &content_client_; return &content_client_;
} }
CefRefPtr<CefRequestContext> GetGlobalRequestContext() override; CefRefPtr<CefRequestContext> GetGlobalRequestContext() override;
CefBrowserContext* CreateNewBrowserContext(
const CefRequestContextSettings& settings) override;
// CefTaskRunnerManager overrides. // CefTaskRunnerManager overrides.
scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner()

View File

@ -19,6 +19,7 @@ namespace blink {
class WebURLLoaderFactory; class WebURLLoaderFactory;
} }
class CefBrowserContext;
struct CefSchemeInfo; struct CefSchemeInfo;
// Exposes global application state in the main and render processes. // Exposes global application state in the main and render processes.
@ -47,7 +48,10 @@ class CefAppManager {
// The following methods are only available in the main (browser) process. // The following methods are only available in the main (browser) process.
// Called from CefRequestContextImpl.
virtual CefRefPtr<CefRequestContext> GetGlobalRequestContext() = 0; virtual CefRefPtr<CefRequestContext> GetGlobalRequestContext() = 0;
virtual CefBrowserContext* CreateNewBrowserContext(
const CefRequestContextSettings& settings) = 0;
#if defined(OS_WIN) #if defined(OS_WIN)
// Returns the module name (usually libcef.dll). // Returns the module name (usually libcef.dll).

View File

@ -54,6 +54,13 @@ CefRefPtr<CefRequestContext> ChromeMainDelegateCef::GetGlobalRequestContext() {
return nullptr; return nullptr;
} }
CefBrowserContext* ChromeMainDelegateCef::CreateNewBrowserContext(
const CefRequestContextSettings& settings) {
// TODO(chrome-runtime): Implement this method.
NOTIMPLEMENTED();
return nullptr;
}
scoped_refptr<base::SingleThreadTaskRunner> scoped_refptr<base::SingleThreadTaskRunner>
ChromeMainDelegateCef::GetBackgroundTaskRunner() { ChromeMainDelegateCef::GetBackgroundTaskRunner() {
auto browser_client = content_browser_client(); auto browser_client = content_browser_client();

View File

@ -45,6 +45,8 @@ class ChromeMainDelegateCef : public ChromeMainDelegate,
return &chrome_content_client_cef_; return &chrome_content_client_cef_;
} }
CefRefPtr<CefRequestContext> GetGlobalRequestContext() override; CefRefPtr<CefRequestContext> GetGlobalRequestContext() override;
CefBrowserContext* CreateNewBrowserContext(
const CefRequestContextSettings& settings) override;
// CefTaskRunnerManager overrides. // CefTaskRunnerManager overrides.
scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner()

View File

@ -128,36 +128,35 @@ index d49a1df73622..9a389e4383f0 100644
// If we broke out of the loop, we have found an enabled plugin. // If we broke out of the loop, we have found an enabled plugin.
bool enabled = i < matching_plugins.size(); bool enabled = i < matching_plugins.size();
diff --git chrome/browser/plugins/plugin_utils.cc chrome/browser/plugins/plugin_utils.cc diff --git chrome/browser/plugins/plugin_utils.cc chrome/browser/plugins/plugin_utils.cc
index 4e64db143b8a..71322b0261a1 100644 index 4e64db143b8a..3dc127b7b992 100644
--- chrome/browser/plugins/plugin_utils.cc --- chrome/browser/plugins/plugin_utils.cc
+++ chrome/browser/plugins/plugin_utils.cc +++ chrome/browser/plugins/plugin_utils.cc
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
#include "chrome/browser/plugins/plugin_utils.h" #include "chrome/browser/plugins/plugin_utils.h"
#include "base/values.h" #include "base/values.h"
+#include "cef/libcef/features/features.h" +#include "cef/libcef/features/runtime.h"
#include "chrome/browser/profiles/profile_io_data.h" #include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/common/plugin_utils.h" #include "chrome/common/plugin_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
@@ -14,6 +15,11 @@ @@ -14,6 +15,10 @@
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h" #include "url/origin.h"
+#if BUILDFLAG(ENABLE_CEF) +#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/browser/resource_context.h"
+#include "cef/libcef/common/extensions/extensions_util.h" +#include "cef/libcef/common/extensions/extensions_util.h"
+#endif +#endif
+ +
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
@@ -182,6 +188,12 @@ base::flat_map<std::string, std::string> @@ -182,6 +187,12 @@ base::flat_map<std::string, std::string>
PluginUtils::GetMimeTypeToExtensionIdMap( PluginUtils::GetMimeTypeToExtensionIdMap(
content::BrowserContext* browser_context) { content::BrowserContext* browser_context) {
base::flat_map<std::string, std::string> mime_type_to_extension_id_map; base::flat_map<std::string, std::string> mime_type_to_extension_id_map;
+ +
+#if BUILDFLAG(ENABLE_CEF) +#if BUILDFLAG(ENABLE_CEF)
+ if (!extensions::ExtensionsEnabled()) + if (cef::IsAlloyRuntimeEnabled() && !extensions::ExtensionsEnabled())
+ return mime_type_to_extension_id_map; + return mime_type_to_extension_id_map;
+#endif +#endif
+ +

View File

@ -1,12 +1,12 @@
diff --git chrome/browser/download/download_prefs.cc chrome/browser/download/download_prefs.cc diff --git chrome/browser/download/download_prefs.cc chrome/browser/download/download_prefs.cc
index a996e15eeba1..76191e5ffa14 100644 index a996e15eeba1..cbc0ad1f9019 100644
--- chrome/browser/download/download_prefs.cc --- chrome/browser/download/download_prefs.cc
+++ chrome/browser/download/download_prefs.cc +++ chrome/browser/download/download_prefs.cc
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
+#include "cef/libcef/features/features.h" +#include "cef/libcef/features/runtime.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h" #include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_core_service_factory.h" #include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_core_service_impl.h" #include "chrome/browser/download/download_core_service_impl.h"
@ -15,24 +15,24 @@ index a996e15eeba1..76191e5ffa14 100644
#endif #endif
+#if BUILDFLAG(ENABLE_CEF) +#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/browser/browser_context.h" +#include "cef/libcef/browser/alloy/alloy_browser_context.h"
+#endif +#endif
+ +
using content::BrowserContext; using content::BrowserContext;
using content::BrowserThread; using content::BrowserThread;
using content::DownloadManager; using content::DownloadManager;
@@ -340,7 +345,11 @@ DownloadPrefs* DownloadPrefs::FromDownloadManager( @@ -340,6 +345,11 @@ DownloadPrefs* DownloadPrefs::FromDownloadManager(
// static // static
DownloadPrefs* DownloadPrefs::FromBrowserContext( DownloadPrefs* DownloadPrefs::FromBrowserContext(
content::BrowserContext* context) { content::BrowserContext* context) {
+#if !BUILDFLAG(ENABLE_CEF) +#if BUILDFLAG(ENABLE_CEF)
return FromDownloadManager(BrowserContext::GetDownloadManager(context)); + if (cef::IsAlloyRuntimeEnabled()) {
+#else + return static_cast<AlloyBrowserContext*>(context)->GetDownloadPrefs();
+ return CefBrowserContext::GetForContext(context)->GetDownloadPrefs(); + }
+#endif +#endif
return FromDownloadManager(BrowserContext::GetDownloadManager(context));
} }
bool DownloadPrefs::IsFromTrustedSource(const download::DownloadItem& item) {
diff --git chrome/browser/printing/print_preview_dialog_controller.cc chrome/browser/printing/print_preview_dialog_controller.cc diff --git chrome/browser/printing/print_preview_dialog_controller.cc chrome/browser/printing/print_preview_dialog_controller.cc
index 84818167bce1..cdbd3f7f6f27 100644 index 84818167bce1..cdbd3f7f6f27 100644
--- chrome/browser/printing/print_preview_dialog_controller.cc --- chrome/browser/printing/print_preview_dialog_controller.cc