2019-03-22 23:11:51 +01:00
|
|
|
// 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.
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
|
2012-04-03 03:34:16 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
#include <set>
|
2020-07-01 02:57:00 +02:00
|
|
|
#include <vector>
|
2019-10-01 15:55:16 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "include/cef_request_context_handler.h"
|
2021-04-07 22:58:43 +02:00
|
|
|
#include "libcef/browser/iothread_state.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "libcef/browser/request_context_handler_map.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2020-03-19 16:34:15 +01:00
|
|
|
#include "base/callback.h"
|
2019-03-22 23:11:51 +01:00
|
|
|
#include "base/files/file_path.h"
|
2020-03-19 16:34:15 +01:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2020-07-01 02:57:00 +02:00
|
|
|
#include "base/optional.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "chrome/common/plugin.mojom.h"
|
2020-07-01 02:57:00 +02:00
|
|
|
#include "services/network/public/mojom/network_context.mojom.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "url/origin.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
/*
|
|
|
|
// Classes used in request processing (network, storage, service, etc.):
|
|
|
|
//
|
|
|
|
// WC = WebContents
|
|
|
|
// Content API representation of a browser. Created by BHI or the system (for
|
2020-07-01 02:57:00 +02:00
|
|
|
// popups) and owned by BHI. Keeps a pointer to the content::BrowserContext.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
2020-09-22 21:54:02 +02:00
|
|
|
// BHI = AlloyBrowserHostImpl
|
2015-02-14 00:17:08 +01:00
|
|
|
// Implements the CefBrowser and CefBrowserHost interfaces which are exposed
|
2020-07-01 02:57:00 +02:00
|
|
|
// to clients. References an RCI instance. Owns a WC. Lifespan is controlled
|
|
|
|
// by client references and CefBrowserInfoManager (until the browser has
|
|
|
|
// closed).
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
// RCI = CefRequestContextImpl
|
|
|
|
// Implements the CefRequestContext interface which is exposed to clients.
|
2020-07-01 02:57:00 +02:00
|
|
|
// Creates or references a BC. Lifespan is controlled by client references and
|
|
|
|
// BrowserMainParts (for the global RCI).
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
2019-03-22 23:11:51 +01:00
|
|
|
// BC = CefBrowserContext
|
2020-07-01 02:57:00 +02:00
|
|
|
// 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.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
2016-08-24 11:28:52 +02:00
|
|
|
// SPI = content::StoragePartitionImpl
|
|
|
|
// Owns storage-related objects like Quota, IndexedDB, Cache, etc. Created by
|
2020-07-01 02:57:00 +02:00
|
|
|
// StoragePartitionImplMap::Get(). Life span is controlled indirectly by BC.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
2020-07-01 02:57:00 +02:00
|
|
|
// IOTS = CefIOThreadState
|
|
|
|
// Stores state for access on the IO thread. Life span is controlled by BC.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// Relationship diagram:
|
|
|
|
// ref = reference (CefRefPtr/scoped_refptr)
|
2017-02-14 23:27:19 +01:00
|
|
|
// own = ownership (std::unique_ptr)
|
2015-02-14 00:17:08 +01:00
|
|
|
// ptr = raw pointer
|
|
|
|
//
|
2020-07-01 02:57:00 +02:00
|
|
|
// BHI -ref-> RCI -ptr-> BC -own-> SPI, IOTS
|
|
|
|
// ^
|
|
|
|
// BHI -own-> WC -ptr--/
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// How shutdown works:
|
2020-09-22 21:54:02 +02:00
|
|
|
// 1. AlloyBrowserHostImpl::DestroyBrowser is called on the UI thread after the
|
2020-07-01 02:57:00 +02:00
|
|
|
// browser is closed and deletes the WebContents.
|
2020-09-22 21:54:02 +02:00
|
|
|
// 1. AlloyBrowserHostImpl is destroyed on any thread when the last reference
|
2020-07-01 02:57:00 +02:00
|
|
|
// is released.
|
2017-02-14 23:27:19 +01:00
|
|
|
// 2. CefRequestContextImpl is destroyed (possibly asynchronously) on the UI
|
2020-07-01 02:57:00 +02:00
|
|
|
// 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.
|
2015-02-14 00:17:08 +01:00
|
|
|
*/
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
namespace content {
|
|
|
|
class BrowserContext;
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
class CefMediaRouterManager;
|
|
|
|
class CefRequestContextImpl;
|
|
|
|
class Profile;
|
|
|
|
|
|
|
|
// Main entry point for configuring behavior on a per-RequestContext basis. The
|
|
|
|
// content::BrowserContext represented by this class is passed to
|
2020-09-22 21:54:02 +02:00
|
|
|
// WebContents::Create in AlloyBrowserHostImpl::CreateInternal. Only accessed on
|
2020-07-01 02:57:00 +02:00
|
|
|
// the UI thread unless otherwise indicated.
|
|
|
|
class CefBrowserContext {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2019-03-22 23:11:51 +01:00
|
|
|
// Returns the existing instance, if any, associated with the specified
|
|
|
|
// |cache_path|.
|
2020-07-01 02:57:00 +02:00
|
|
|
static CefBrowserContext* FromCachePath(const base::FilePath& cache_path);
|
2019-03-22 23:11:51 +01:00
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
// Returns the existing instance, if any, associated with the specified IDs.
|
|
|
|
// See comments on IsAssociatedContext() for usage.
|
2020-07-01 02:57:00 +02:00
|
|
|
static CefBrowserContext* FromIDs(int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
int frame_tree_node_id,
|
|
|
|
bool require_frame_match);
|
2019-10-01 15:55:16 +02:00
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
// Returns the underlying CefBrowserContext if any.
|
2020-07-01 02:57:00 +02:00
|
|
|
static CefBrowserContext* FromBrowserContext(
|
|
|
|
const content::BrowserContext* context);
|
2021-04-07 00:09:45 +02:00
|
|
|
static CefBrowserContext* FromProfile(const Profile* profile);
|
2019-03-22 23:11:51 +01:00
|
|
|
|
|
|
|
// Returns all existing CefBrowserContext.
|
|
|
|
static std::vector<CefBrowserContext*> GetAll();
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
// Returns the content and chrome layer representations of the context.
|
|
|
|
virtual content::BrowserContext* AsBrowserContext() = 0;
|
|
|
|
virtual Profile* AsProfile() = 0;
|
2019-03-22 23:11:51 +01:00
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
// Returns true if the context is fully initialized.
|
|
|
|
virtual bool IsInitialized() const = 0;
|
|
|
|
|
|
|
|
// If the context is fully initialized execute |callback|, otherwise
|
|
|
|
// store it until the context is fully initialized.
|
|
|
|
virtual void StoreOrTriggerInitCallback(base::OnceClosure callback) = 0;
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
// Called from CefRequestContextImpl to track associated objects. This
|
|
|
|
// object will delete itself when the count reaches zero.
|
2019-03-22 23:11:51 +01:00
|
|
|
void AddCefRequestContext(CefRequestContextImpl* context);
|
2020-07-01 02:57:00 +02:00
|
|
|
virtual void RemoveCefRequestContext(CefRequestContextImpl* context);
|
2016-01-12 01:19:51 +01:00
|
|
|
|
2019-03-24 00:40:32 +01:00
|
|
|
// Called from CefRequestContextImpl::OnRenderFrameCreated.
|
|
|
|
void OnRenderFrameCreated(CefRequestContextImpl* request_context,
|
|
|
|
int render_process_id,
|
|
|
|
int render_frame_id,
|
2019-04-24 04:50:25 +02:00
|
|
|
int frame_tree_node_id,
|
2019-03-24 00:40:32 +01:00
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view);
|
|
|
|
|
|
|
|
// Called from CefRequestContextImpl::OnRenderFrameDeleted.
|
|
|
|
void OnRenderFrameDeleted(CefRequestContextImpl* request_context,
|
|
|
|
int render_process_id,
|
2016-10-17 20:14:44 +02:00
|
|
|
int render_frame_id,
|
2019-04-24 04:50:25 +02:00
|
|
|
int frame_tree_node_id,
|
2016-10-17 20:14:44 +02:00
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view);
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
// Returns the handler that matches the specified IDs. Pass -1 for unknown
|
|
|
|
// values. If |require_frame_match| is true only exact matches will be
|
|
|
|
// returned. If |require_frame_match| is false, and there is not an exact
|
|
|
|
// match, then the first handler for the same |render_process_id| will be
|
|
|
|
// returned.
|
|
|
|
CefRefPtr<CefRequestContextHandler> GetHandler(
|
|
|
|
int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
int frame_tree_node_id,
|
|
|
|
bool require_frame_match) const;
|
|
|
|
|
|
|
|
// Returns true if this context is associated with the specified IDs. Pass -1
|
|
|
|
// for unknown values. If |require_frame_match| is true only exact matches
|
|
|
|
// will qualify. If |require_frame_match| is false, and there is not an exact
|
|
|
|
// match, then any match for |render_process_id| will qualify.
|
|
|
|
bool IsAssociatedContext(int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
int frame_tree_node_id,
|
|
|
|
bool require_frame_match) const;
|
|
|
|
|
|
|
|
// Remember the plugin load decision for plugin status requests that arrive
|
|
|
|
// via CefPluginServiceFilter::IsPluginAvailable.
|
|
|
|
void AddPluginLoadDecision(int render_process_id,
|
|
|
|
const base::FilePath& plugin_path,
|
|
|
|
bool is_main_frame,
|
|
|
|
const url::Origin& main_frame_origin,
|
|
|
|
chrome::mojom::PluginStatus status);
|
|
|
|
bool HasPluginLoadDecision(int render_process_id,
|
|
|
|
const base::FilePath& plugin_path,
|
|
|
|
bool is_main_frame,
|
|
|
|
const url::Origin& main_frame_origin,
|
|
|
|
chrome::mojom::PluginStatus* status) const;
|
|
|
|
|
|
|
|
// Clear the plugin load decisions associated with |render_process_id|, or all
|
|
|
|
// plugin load decisions if |render_process_id| is -1.
|
|
|
|
void ClearPluginLoadDecision(int render_process_id);
|
2016-10-17 20:14:44 +02:00
|
|
|
|
2019-04-24 04:50:25 +02:00
|
|
|
// Called from CefRequestContextImpl methods of the same name.
|
2020-07-01 02:57:00 +02:00
|
|
|
void RegisterSchemeHandlerFactory(const CefString& scheme_name,
|
|
|
|
const CefString& domain_name,
|
2019-04-24 04:50:25 +02:00
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory);
|
|
|
|
void ClearSchemeHandlerFactories();
|
2020-07-01 02:57:00 +02:00
|
|
|
// 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;
|
|
|
|
|
2019-05-18 19:41:14 +02:00
|
|
|
network::mojom::NetworkContext* GetNetworkContext();
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
CefMediaRouterManager* GetMediaRouterManager();
|
|
|
|
|
2020-09-04 21:08:55 +02:00
|
|
|
using CookieableSchemes = base::Optional<std::vector<std::string>>;
|
2020-09-25 03:40:47 +02:00
|
|
|
|
|
|
|
// Returns the schemes associated with this context specifically, or the
|
|
|
|
// global configuration if unset.
|
|
|
|
CookieableSchemes GetCookieableSchemes() const;
|
2021-04-09 20:34:45 +02:00
|
|
|
static CookieableSchemes GetGlobalCookieableSchemes();
|
2019-04-24 04:50:25 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
// 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_; }
|
2021-04-07 22:58:43 +02:00
|
|
|
scoped_refptr<CefIOThreadState> iothread_state() const {
|
|
|
|
return iothread_state_;
|
|
|
|
}
|
2019-07-17 20:47:27 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
// Used to hold a WeakPtr reference to this this object. The Getter returns
|
|
|
|
// nullptr if this object has already been destroyed.
|
2020-03-19 16:34:15 +01:00
|
|
|
using Getter = base::RepeatingCallback<CefBrowserContext*()>;
|
|
|
|
Getter getter() const { return getter_; }
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
protected:
|
|
|
|
explicit CefBrowserContext(const CefRequestContextSettings& settings);
|
|
|
|
virtual ~CefBrowserContext();
|
|
|
|
|
|
|
|
// Will be called immediately after this object is created.
|
|
|
|
virtual void Initialize();
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
// Will be called immediately before this object is deleted.
|
|
|
|
virtual void Shutdown();
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
// Members initialized during construction or Initialize() are safe to access
|
|
|
|
// from any thread.
|
2020-04-23 23:45:04 +02:00
|
|
|
const CefRequestContextSettings settings_;
|
2019-03-22 23:11:51 +01:00
|
|
|
base::FilePath cache_path_;
|
2017-04-20 21:28:17 +02:00
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
private:
|
2021-04-07 22:58:43 +02:00
|
|
|
scoped_refptr<CefIOThreadState> iothread_state_;
|
2020-09-04 21:08:55 +02:00
|
|
|
CookieableSchemes cookieable_schemes_;
|
2020-03-19 16:34:15 +01:00
|
|
|
std::unique_ptr<CefMediaRouterManager> media_router_manager_;
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
// CefRequestContextImpl objects referencing this object.
|
|
|
|
std::set<CefRequestContextImpl*> request_context_set_;
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
// Map IDs to CefRequestContextHandler objects.
|
|
|
|
CefRequestContextHandlerMap handler_map_;
|
|
|
|
|
|
|
|
// Map (render_process_id, plugin_path, is_main_frame, main_frame_origin) to
|
|
|
|
// plugin load decision.
|
|
|
|
typedef std::map<
|
|
|
|
std::pair<std::pair<int, base::FilePath>, std::pair<bool, url::Origin>>,
|
|
|
|
chrome::mojom::PluginStatus>
|
|
|
|
PluginLoadDecisionMap;
|
|
|
|
PluginLoadDecisionMap plugin_load_decision_map_;
|
|
|
|
|
|
|
|
// Set of (render_process_id, render_frame_id) associated with this context.
|
|
|
|
typedef std::set<std::pair<int, int>> RenderIdSet;
|
|
|
|
RenderIdSet render_id_set_;
|
|
|
|
|
|
|
|
// Set of frame_tree_node_id associated with this context. Keeping this list
|
|
|
|
// is necessary because, when navigating the main frame, a new (pre-commit)
|
|
|
|
// network request will be created before the RenderFrameHost. Consequently we
|
|
|
|
// can't rely on valid render IDs. See https://crbug.com/776884 for
|
|
|
|
// background.
|
|
|
|
typedef std::set<int> NodeIdSet;
|
|
|
|
NodeIdSet node_id_set_;
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
#if DCHECK_IS_ON()
|
|
|
|
bool is_shutdown_ = false;
|
|
|
|
#endif
|
|
|
|
|
2020-03-19 16:34:15 +01:00
|
|
|
Getter getter_;
|
|
|
|
base::WeakPtrFactory<CefBrowserContext> weak_ptr_factory_;
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefBrowserContext);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_IMPL_H_
|