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
|
2016-08-24 11:28:52 +02:00
|
|
|
// SPI indirectly. Life span controlled by RCI and (for the global context)
|
2015-03-02 21:25:14 +01:00
|
|
|
// CefBrowserMainParts.
|
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
|
2016-08-24 11:28:52 +02:00
|
|
|
// URCGP and SPP. Life span controlled by RCI.
|
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
// own = ownership (scoped_ptr)
|
|
|
|
// ptr = raw pointer
|
|
|
|
//
|
2016-08-24 11:28:52 +02:00
|
|
|
// CefBrowserMainParts----\ isolated cookie manager, etc.
|
|
|
|
// | \ ^
|
|
|
|
// ref ref ref/own
|
|
|
|
// v v |
|
|
|
|
// /---> BCI -own-> SPI -ref-> URCGI --own-> URCI <-ptr-- CSP
|
|
|
|
// / ^ ^ ^ ^
|
|
|
|
// ptr ref ptr ref /
|
|
|
|
// / | | | /
|
|
|
|
// BHI -own-> WC -ptr-> BCP -own-> SPP -ref-> URCGP -own-> URCP --ref-/
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
// BHI -ref-> RCI -ref-> BCI/BCP -own-> RC -ref-> URCGI/URCGP
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// How shutdown works:
|
|
|
|
// 1. CefBrowserHostImpl is destroyed on any thread due to browser close,
|
|
|
|
// ref release, etc.
|
|
|
|
// 2. CefRequestContextImpl is destroyed on any thread due to
|
|
|
|
// CefBrowserHostImpl destruction, ref release, etc.
|
|
|
|
// 3. CefBrowserContext* is destroyed on the UI thread due to
|
|
|
|
// CefRequestContextImpl destruction (*Impl, *Proxy) or ref release in
|
|
|
|
// 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
|
|
|
|
// CefURLRequestContextGetter* destruction.
|
|
|
|
*/
|
|
|
|
|
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.
|
2015-02-14 00:17:08 +01:00
|
|
|
class CefBrowserContext
|
2015-10-17 02:44:00 +02:00
|
|
|
: public ChromeProfileStub,
|
2015-02-14 00:17:08 +01:00
|
|
|
public base::RefCountedThreadSafe<
|
|
|
|
CefBrowserContext, content::BrowserThread::DeleteOnUIThread> {
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Simple tracking of allocated objects.
|
|
|
|
static base::AtomicRefCount DebugObjCt; // NOLINT(runtime/int)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~CefBrowserContext() override;
|
|
|
|
|
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:
|
|
|
|
// Only allow deletion via scoped_refptr().
|
|
|
|
friend struct content::BrowserThread::DeleteOnThread<
|
|
|
|
content::BrowserThread::UI>;
|
|
|
|
friend class base::DeleteHelper<CefBrowserContext>;
|
|
|
|
|
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_
|