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-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/resource_context.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "libcef/browser/url_request_context_getter_impl.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
|
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
|
|
|
|
// URCGI. Life span controlled by RCI and (for the global context)
|
|
|
|
// 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
|
|
|
|
// URCGP. Life span controlled by RCI.
|
|
|
|
//
|
|
|
|
// 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
|
2015-03-02 21:25:14 +01:00
|
|
|
// Creates and owns the URCI. Life span is controlled by RC and (for the
|
|
|
|
// global context) CefBrowserMainParts.
|
2015-02-14 00:17:08 +01:00
|
|
|
//
|
|
|
|
// URCGP = CefURLRequestContextGetterProxy
|
|
|
|
// Creates and owns the URCP. Life span is controlled by RC.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
2015-03-02 21:25:14 +01:00
|
|
|
// CefBrowserMainParts isolated cookie manager, etc...
|
2015-02-14 00:17:08 +01:00
|
|
|
// | | ^
|
|
|
|
// ref ref ref/own
|
|
|
|
// v v |
|
|
|
|
// /---> BCI -ref-> URCGI --own-> URCI <-ptr-- CSP
|
|
|
|
// / ^ ^ ^
|
|
|
|
// ptr ref ref /
|
|
|
|
// / | | /
|
|
|
|
// BHI -own-> WC -ptr-> BCP -ref-> URCGP -own-> URCP --ref-/
|
|
|
|
//
|
|
|
|
// 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-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
|
|
|
|
: public content::BrowserContext,
|
|
|
|
public base::RefCountedThreadSafe<
|
|
|
|
CefBrowserContext, content::BrowserThread::DeleteOnUIThread> {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
2015-02-14 00:17:08 +01:00
|
|
|
CefBrowserContext();
|
|
|
|
|
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;
|
|
|
|
|
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-02-14 00:17:08 +01:00
|
|
|
// Called from CefContentBrowserClient to create the URLRequestContextGetter.
|
2013-09-03 18:43:31 +02:00
|
|
|
virtual net::URLRequestContextGetter* CreateRequestContext(
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-06-12 22:28:58 +02:00
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors) = 0;
|
2013-09-03 18:43:31 +02:00
|
|
|
virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
|
2013-02-27 18:56:03 +01:00
|
|
|
const base::FilePath& partition_path,
|
2013-02-23 01:43:28 +01:00
|
|
|
bool in_memory,
|
2014-04-04 18:50:38 +02:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-06-12 22:28:58 +02:00
|
|
|
content::URLRequestInterceptorScopedVector request_interceptors) = 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;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Only allow deletion via scoped_refptr().
|
|
|
|
friend struct content::BrowserThread::DeleteOnThread<
|
|
|
|
content::BrowserThread::UI>;
|
|
|
|
friend class base::DeleteHelper<CefBrowserContext>;
|
|
|
|
|
|
|
|
scoped_ptr<CefResourceContext> resource_context_;
|
|
|
|
|
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_
|