2013-09-03 18:43:31 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
|
|
|
|
#pragma once
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "include/cef_request_context_handler.h"
|
2015-10-17 02:44:00 +02:00
|
|
|
#include "libcef/browser/chrome_profile_stub.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/url_request_context_getter_impl.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/resource_context.h"
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
#include "content/public/browser/content_browser_client.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
|
|
|
|
// popups) and owned by BHI. Keeps a pointer to BCI/BCP.
|
|
|
|
//
|
|
|
|
// 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 CefContentBrowserClient.
|
|
|
|
//
|
|
|
|
// RCI = CefRequestContextImpl
|
|
|
|
// Implements the CefRequestContext interface which is exposed to clients.
|
2015-03-02 21:25:14 +01:00
|
|
|
// References the isolated BCI or creates a new BCP.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
// BCI = CefBrowserContextImpl
|
2015-03-02 21:25:14 +01:00
|
|
|
// Entry point from WC when using an isolated RCI. Owns the RC and creates the
|
2017-02-14 23:27:19 +01:00
|
|
|
// SPI indirectly. Owned by CefBrowserMainParts for the global context or RCI
|
|
|
|
// for non-global contexts.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
// BCP = CefBrowserContextProxy
|
|
|
|
// Entry point from WC when using a custom RCI. Owns the RC and creates the
|
2017-02-14 23:27:19 +01:00
|
|
|
// URCGP and SPP. Owned by RCI.
|
2016-08-24 11:28:52 +02:00
|
|
|
//
|
|
|
|
// SPI = content::StoragePartitionImpl
|
|
|
|
// Owns storage-related objects like Quota, IndexedDB, Cache, etc. Created by
|
|
|
|
// StoragePartitionImplMap::Get(). Provides access to the URCGI. Life span is
|
|
|
|
// controlled indirectly by BCI.
|
|
|
|
//
|
|
|
|
// SPP = CefStoragePartitionProxy
|
|
|
|
// Forwards requests for storage-related objects to SPI. Created by
|
|
|
|
// GetStoragePartitionFromConfig() calling BCI::GetStoragePartitionProxy().
|
|
|
|
// Provides access to the URCGP. Life span is controlled by BCP.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
// RC = CefResourceContext
|
|
|
|
// Acts as a bridge for resource loading. URLRequest life span is tied to this
|
|
|
|
// object. Must be destroyed before the associated URCGI/URCGP. Life span is
|
|
|
|
// controlled by BCI/BCP.
|
|
|
|
//
|
|
|
|
// URCGI = CefURLRequestContextGetterImpl
|
2016-08-24 11:28:52 +02:00
|
|
|
// Creates and owns the URCI. Created by StoragePartitionImplMap::Get()
|
|
|
|
// calling BCI::CreateRequestContext(). Life span is controlled by RC and (for
|
|
|
|
// the global context) CefBrowserMainParts, and SPI.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
// URCGP = CefURLRequestContextGetterProxy
|
2016-08-24 11:28:52 +02:00
|
|
|
// Creates and owns the URCP. Created by GetStoragePartitionFromConfig()
|
|
|
|
// calling BCI::GetStoragePartitionProxy(). Life span is controlled by RC and
|
|
|
|
// SPP.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
// URCI = CefURLRequestContextImpl
|
2015-03-02 21:25:14 +01:00
|
|
|
// Owns various network-related objects including the isolated cookie manager.
|
2015-02-14 00:17:08 +01:00
|
|
|
// Owns URLRequest objects which must be destroyed first. Life span is
|
|
|
|
// controlled by URCGI.
|
|
|
|
//
|
|
|
|
// URCP = CefURLRequestContextProxy
|
|
|
|
// Creates the CSP and forwards requests to the objects owned by URCI. Owns
|
|
|
|
// URLRequest objects which must be destroyed first. Life span is controlled
|
|
|
|
// by URCGP.
|
|
|
|
//
|
|
|
|
// CSP = CefCookieStoreProxy
|
|
|
|
// Gives the CefCookieManager instance retrieved via CefRequestContextHandler
|
|
|
|
// an opportunity to handle cookie requests. Otherwise forwards requests via
|
2015-03-02 21:25:14 +01:00
|
|
|
// URCI to the isolated cookie manager. Life span is controlled by URCP.
|
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
|
|
|
|
//
|
2016-08-24 11:28:52 +02:00
|
|
|
// CefBrowserMainParts----\ isolated cookie manager, etc.
|
|
|
|
// | \ ^
|
2017-02-14 23:27:19 +01:00
|
|
|
// own ref ref/own
|
2016-08-24 11:28:52 +02:00
|
|
|
// v v |
|
|
|
|
// /---> BCI -own-> SPI -ref-> URCGI --own-> URCI <-ptr-- CSP
|
|
|
|
// / ^ ^ ^ ^
|
2017-02-14 23:27:19 +01:00
|
|
|
// ptr ptr ptr ref /
|
2016-08-24 11:28:52 +02:00
|
|
|
// / | | | /
|
|
|
|
// BHI -own-> WC -ptr-> BCP -own-> SPP -ref-> URCGP -own-> URCP --ref-/
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
2017-02-14 23:27:19 +01:00
|
|
|
// BHI -ref-> RCI -own-> BCI/BCP -own-> RC -ref-> URCGI/URCGP
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// How shutdown works:
|
|
|
|
// 1. CefBrowserHostImpl is destroyed on any thread due to browser close,
|
|
|
|
// ref release, etc.
|
2017-02-14 23:27:19 +01:00
|
|
|
// 2. CefRequestContextImpl is destroyed (possibly asynchronously) on the UI
|
|
|
|
// thread due to CefBrowserHostImpl destruction, ref release, etc.
|
2015-02-14 00:17:08 +01:00
|
|
|
// 3. CefBrowserContext* is destroyed on the UI thread due to
|
2017-02-14 23:27:19 +01:00
|
|
|
// CefRequestContextImpl destruction (*Impl, *Proxy) or deletion in
|
2015-02-14 00:17:08 +01:00
|
|
|
// CefBrowserMainParts::PostMainMessageLoopRun() (*Impl).
|
|
|
|
// 4. CefResourceContext is destroyed asynchronously on the IO thread due to
|
|
|
|
// CefBrowserContext* destruction. This cancels/destroys any pending
|
|
|
|
// URLRequests.
|
|
|
|
// 5. CefURLRequestContextGetter* is destroyed asynchronously on the IO thread
|
|
|
|
// due to CefResourceContext destruction (*Impl, *Proxy) or ref release in
|
|
|
|
// CefBrowserMainParts::PostMainMessageLoopRun() (*Impl). This may be delayed
|
|
|
|
// if other network-related objects still have a reference to it.
|
|
|
|
// 6. CefURLRequestContext* is destroyed on the IO thread due to
|
2017-05-17 11:29:28 +02:00
|
|
|
// CefURLRequestContextGetter* destruction.
|
2015-02-14 00:17:08 +01:00
|
|
|
*/
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
class CefRequestContextImpl;
|
2015-09-09 16:05:39 +02:00
|
|
|
class HostContentSettingsMap;
|
|
|
|
class PrefService;
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
namespace extensions {
|
|
|
|
class CefExtensionSystem;
|
|
|
|
}
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
// Main entry point for configuring behavior on a per-browser basis. An instance
|
|
|
|
// of this class is passed to WebContents::Create in CefBrowserHostImpl::
|
2015-03-02 21:25:14 +01:00
|
|
|
// CreateInternal. Only accessed on the UI thread unless otherwise indicated.
|
2017-02-14 23:27:19 +01:00
|
|
|
class CefBrowserContext : public ChromeProfileStub {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2016-08-31 13:25:56 +02:00
|
|
|
explicit CefBrowserContext(bool is_proxy);
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// Must be called immediately after this object is created.
|
|
|
|
virtual void Initialize();
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
// BrowserContext methods.
|
|
|
|
content::ResourceContext* GetResourceContext() override;
|
2016-05-25 01:35:43 +02:00
|
|
|
net::URLRequestContextGetter* GetRequestContext() override;
|
|
|
|
net::URLRequestContextGetter* CreateMediaRequestContext() override;
|
|
|
|
net::URLRequestContextGetter* CreateMediaRequestContextForStoragePartition(
|
|
|
|
const base::FilePath& partition_path,
|
|
|
|
bool in_memory) override;
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// Profile methods.
|
|
|
|
ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
|
2018-07-24 00:32:02 +02:00
|
|
|
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
|
2015-10-17 02:44:00 +02:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
// Returns a RequestContext associated with this object. If this object is a
|
|
|
|
// *Proxy then it will return the single associated proxy RequestContext. If
|
|
|
|
// this object is an *Impl then it will return the first non-proxy
|
|
|
|
// RequestContext, if one exists, otherwise the first proxy RequestContext.
|
|
|
|
virtual CefRequestContextImpl* GetCefRequestContext() const = 0;
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Returns the settings associated with this object. Safe to call from any
|
|
|
|
// thread.
|
|
|
|
virtual const CefRequestContextSettings& GetSettings() const = 0;
|
|
|
|
|
|
|
|
// Returns the handler associated with this object. Safe to call from any
|
|
|
|
// thread.
|
|
|
|
virtual CefRefPtr<CefRequestContextHandler> GetHandler() const = 0;
|
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
// Settings for plugins and extensions.
|
|
|
|
virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0;
|
|
|
|
|
2016-01-12 01:19:51 +01:00
|
|
|
// Called from CefBrowserHostImpl::DidNavigateAnyFrame to update the table of
|
|
|
|
// visited links.
|
|
|
|
virtual void AddVisitedURLs(const std::vector<GURL>& urls) = 0;
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
// Called from CefBrowserHostImpl::RenderFrameDeleted or
|
|
|
|
// CefMimeHandlerViewGuestDelegate::OnGuestDetached when a render frame is
|
|
|
|
// deleted.
|
|
|
|
void OnRenderFrameDeleted(int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view);
|
|
|
|
|
|
|
|
// Called from CefRequestContextImpl::PurgePluginListCacheInternal when the
|
|
|
|
// plugin list cache should be purged.
|
|
|
|
void OnPurgePluginListCache();
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
CefResourceContext* resource_context() const {
|
2015-07-16 23:40:01 +02:00
|
|
|
return resource_context_.get();
|
|
|
|
}
|
|
|
|
extensions::CefExtensionSystem* extension_system() const {
|
|
|
|
return extension_system_;
|
2015-02-14 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool is_proxy() const { return is_proxy_; }
|
2015-02-14 00:17:08 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
~CefBrowserContext() override;
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
// Must be called after all services have been initialized.
|
|
|
|
void PostInitialize();
|
|
|
|
|
2015-10-17 02:44:00 +02:00
|
|
|
// Must be called before the child object destructor has completed.
|
|
|
|
void Shutdown();
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
private:
|
2016-08-31 13:25:56 +02:00
|
|
|
// True if this CefBrowserContext is a CefBrowserContextProxy.
|
|
|
|
const bool is_proxy_;
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefResourceContext> resource_context_;
|
2015-02-14 00:17:08 +01:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
// Owned by the KeyedService system.
|
|
|
|
extensions::CefExtensionSystem* extension_system_;
|
|
|
|
|
2015-02-14 00:17:08 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefBrowserContext);
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_BROWSER_CONTEXT_H_
|