mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
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:
@@ -7,23 +7,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#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/resource_context.h"
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/ref_counted.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 "components/proxy_config/pref_proxy_config_tracker.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 "services/network/public/mojom/network_context.mojom.h"
|
||||
#include "url/origin.h"
|
||||
|
||||
/*
|
||||
@@ -31,32 +25,30 @@
|
||||
//
|
||||
// WC = WebContents
|
||||
// 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
|
||||
// Implements the CefBrowser and CefBrowserHost interfaces which are exposed
|
||||
// to clients. References an RCI instance. Owns a WC. Life span is controlled
|
||||
// by client references and AlloyContentBrowserClient.
|
||||
// to clients. References an RCI instance. Owns a WC. Lifespan is controlled
|
||||
// by client references and CefBrowserInfoManager (until the browser has
|
||||
// closed).
|
||||
//
|
||||
// RCI = CefRequestContextImpl
|
||||
// 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
|
||||
// Entry point from WC when using an isolated RCI. Owns the RC and creates the
|
||||
// SPI indirectly. Owned by AlloyBrowserMainParts for the global context or
|
||||
RCI
|
||||
// for non-global contexts.
|
||||
// Is/owns the content::BrowserContext which is the entry point from WC.
|
||||
// Owns the IOTS and creates the SPI indirectly. Potentially shared by
|
||||
// multiple RCI. Deletes itself when no longer needed by RCI.
|
||||
//
|
||||
// SPI = content::StoragePartitionImpl
|
||||
// Owns storage-related objects like Quota, IndexedDB, Cache, etc. Created by
|
||||
// StoragePartitionImplMap::Get(). Provides access to the URCG. Life span is
|
||||
// controlled indirectly by BC.
|
||||
// StoragePartitionImplMap::Get(). Life span is controlled indirectly by BC.
|
||||
//
|
||||
// RC = CefResourceContext
|
||||
// Acts as a bridge for resource loading. Network request life span is tied to
|
||||
// this object. Must be destroyed before the associated URCG. Life span is
|
||||
// controlled by BC.
|
||||
// IOTS = CefIOThreadState
|
||||
// Stores state for access on the IO thread. Life span is controlled by BC.
|
||||
//
|
||||
//
|
||||
// Relationship diagram:
|
||||
@@ -64,142 +56,65 @@ RCI
|
||||
// own = ownership (std::unique_ptr)
|
||||
// ptr = raw pointer
|
||||
//
|
||||
// AlloyBrowserMainParts
|
||||
// |
|
||||
// own
|
||||
// v
|
||||
// BHI -own-> WC -ptr-> BC -own-> SPI
|
||||
//
|
||||
// BHI -ref-> RCI -own-> BC -own-> RC
|
||||
// BHI -ref-> RCI -ptr-> BC -own-> SPI, IOTS
|
||||
// ^
|
||||
// BHI -own-> WC -ptr--/
|
||||
//
|
||||
//
|
||||
// How shutdown works:
|
||||
// 1. CefBrowserHostImpl is destroyed on any thread due to browser close,
|
||||
// ref release, etc.
|
||||
// 1. CefBrowserHostImpl::DestroyBrowser is called on the UI thread after the
|
||||
// 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
|
||||
// thread due to CefBrowserHostImpl destruction, ref release, etc.
|
||||
// 3. CefBrowserContext is destroyed on the UI thread due to
|
||||
// CefRequestContextImpl destruction or deletion in
|
||||
// AlloyBrowserMainParts::PostMainMessageLoopRun().
|
||||
// 4. CefResourceContext is destroyed asynchronously on the IO thread due to
|
||||
// CefBrowserContext destruction. This cancels/destroys any pending
|
||||
// network requests.
|
||||
// thread when the last reference is released.
|
||||
// 3. CefBrowserContext is destroyed on the UI thread when no longer needed
|
||||
// by any CefRequestContextImpl (via RemoveCefRequestContext).
|
||||
// 4. CefIOThreadState is destroyed asynchronously on the IO thread after
|
||||
// the owning CefBrowserContext is destroyed.
|
||||
*/
|
||||
|
||||
class CefDownloadManagerDelegate;
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
}
|
||||
|
||||
class CefMediaRouterManager;
|
||||
class CefRequestContextImpl;
|
||||
class CefSSLHostStateDelegate;
|
||||
class CefVisitedLinkListener;
|
||||
class HostContentSettingsMap;
|
||||
class PrefService;
|
||||
class CefIOThreadState;
|
||||
class Profile;
|
||||
|
||||
namespace extensions {
|
||||
class CefExtensionSystem;
|
||||
}
|
||||
|
||||
namespace visitedlink {
|
||||
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 {
|
||||
// Main entry point for configuring behavior on a per-RequestContext basis. The
|
||||
// content::BrowserContext represented by this class is passed to
|
||||
// WebContents::Create in CefBrowserHostImpl::CreateInternal. Only accessed on
|
||||
// the UI thread unless otherwise indicated.
|
||||
class CefBrowserContext {
|
||||
public:
|
||||
explicit CefBrowserContext(const CefRequestContextSettings& settings);
|
||||
|
||||
// Returns the existing instance, if any, associated with the specified
|
||||
// |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.
|
||||
// See comments on IsAssociatedContext() for usage.
|
||||
static CefBrowserContext* GetForIDs(int render_process_id,
|
||||
int render_frame_id,
|
||||
int frame_tree_node_id,
|
||||
bool require_frame_match);
|
||||
static CefBrowserContext* FromIDs(int render_process_id,
|
||||
int render_frame_id,
|
||||
int frame_tree_node_id,
|
||||
bool require_frame_match);
|
||||
|
||||
// Returns the underlying CefBrowserContext if any.
|
||||
static CefBrowserContext* GetForContext(content::BrowserContext* context);
|
||||
static CefBrowserContext* FromBrowserContext(
|
||||
const content::BrowserContext* context);
|
||||
|
||||
// Returns all existing CefBrowserContext.
|
||||
static std::vector<CefBrowserContext*> GetAll();
|
||||
|
||||
// Must be called immediately after this object is created.
|
||||
void Initialize();
|
||||
// Returns the content and chrome layer representations of the context.
|
||||
virtual content::BrowserContext* AsBrowserContext() = 0;
|
||||
virtual Profile* AsProfile() = 0;
|
||||
|
||||
// Track associated CefRequestContextImpl objects. This object will delete
|
||||
// itself when the count reaches zero.
|
||||
// Called from CefRequestContextImpl to track associated objects. This
|
||||
// object will delete itself when the count reaches zero.
|
||||
void AddCefRequestContext(CefRequestContextImpl* context);
|
||||
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);
|
||||
virtual void RemoveCefRequestContext(CefRequestContextImpl* context);
|
||||
|
||||
// Called from CefRequestContextImpl::OnRenderFrameCreated.
|
||||
void OnRenderFrameCreated(CefRequestContextImpl* request_context,
|
||||
@@ -255,79 +170,72 @@ class CefBrowserContext : public ChromeProfileAlloy,
|
||||
void ClearPluginLoadDecision(int render_process_id);
|
||||
|
||||
// Called from CefRequestContextImpl methods of the same name.
|
||||
void RegisterSchemeHandlerFactory(const std::string& scheme_name,
|
||||
const std::string& domain_name,
|
||||
void RegisterSchemeHandlerFactory(const CefString& scheme_name,
|
||||
const CefString& domain_name,
|
||||
CefRefPtr<CefSchemeHandlerFactory> factory);
|
||||
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();
|
||||
|
||||
void set_should_persist_session_cookies(bool value) {
|
||||
should_persist_session_cookies_ = value;
|
||||
}
|
||||
CefMediaRouterManager* GetMediaRouterManager();
|
||||
|
||||
void set_cookieable_schemes(
|
||||
base::Optional<std::vector<std::string>> schemes) {
|
||||
cookieable_schemes_ = schemes;
|
||||
}
|
||||
|
||||
CefResourceContext* resource_context() const {
|
||||
return resource_context_.get();
|
||||
}
|
||||
extensions::CefExtensionSystem* extension_system() const {
|
||||
return extension_system_;
|
||||
}
|
||||
// These accessors are safe to call from any thread because the values don't
|
||||
// change during this object's lifespan.
|
||||
const CefRequestContextSettings& settings() const { return settings_; }
|
||||
base::FilePath cache_path() const { return cache_path_; }
|
||||
CefIOThreadState* iothread_state() const { return iothread_state_.get(); }
|
||||
|
||||
// Called from DownloadPrefs::FromBrowserContext.
|
||||
DownloadPrefs* GetDownloadPrefs();
|
||||
|
||||
// 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.
|
||||
// Used to hold a WeakPtr reference to this this object. The Getter returns
|
||||
// nullptr if this object has already been destroyed.
|
||||
using Getter = base::RepeatingCallback<CefBrowserContext*()>;
|
||||
Getter getter() const { return getter_; }
|
||||
|
||||
private:
|
||||
// Allow deletion via std::unique_ptr().
|
||||
friend std::default_delete<CefBrowserContext>;
|
||||
protected:
|
||||
explicit CefBrowserContext(const CefRequestContextSettings& settings);
|
||||
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_;
|
||||
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_;
|
||||
|
||||
std::unique_ptr<CefResourceContext> resource_context_;
|
||||
|
||||
// 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_;
|
||||
|
||||
private:
|
||||
std::unique_ptr<CefIOThreadState> iothread_state_;
|
||||
std::unique_ptr<CefMediaRouterManager> media_router_manager_;
|
||||
|
||||
// CefRequestContextImpl objects referencing this object.
|
||||
std::set<CefRequestContextImpl*> request_context_set_;
|
||||
|
||||
// Map IDs to CefRequestContextHandler objects.
|
||||
CefRequestContextHandlerMap handler_map_;
|
||||
|
||||
@@ -351,6 +259,10 @@ class CefBrowserContext : public ChromeProfileAlloy,
|
||||
typedef std::set<int> NodeIdSet;
|
||||
NodeIdSet node_id_set_;
|
||||
|
||||
#if DCHECK_IS_ON()
|
||||
bool is_shutdown_ = false;
|
||||
#endif
|
||||
|
||||
Getter getter_;
|
||||
base::WeakPtrFactory<CefBrowserContext> weak_ptr_factory_;
|
||||
|
||||
|
Reference in New Issue
Block a user