// 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. #ifndef CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_ #define CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_ #pragma once #include "include/cef_request_context.h" #include "libcef/browser/browser_context.h" // Implementation of the CefRequestContext interface. All methods are thread- // safe unless otherwise indicated. class CefRequestContextImpl : public CefRequestContext { public: ~CefRequestContextImpl() override; // Returns a CefRequestContextImpl for the specified |request_context|. // Will return the global context if |request_context| is NULL. static CefRefPtr GetForRequestContext( CefRefPtr request_context); // Returns a CefRequestContextImpl for the specified |browser_context|. // |browser_context| must be non-NULL. static CefRefPtr GetForBrowserContext( scoped_refptr browser_context); // Returns the browser context object. Can only be called on the UI thread. scoped_refptr GetBrowserContext(); // Executes |callback| either synchronously or asynchronously with the browser // context object when it's available. If |task_runner| is NULL the callback // will be executed on the originating thread. The resulting context object // can only be accessed on the UI thread. typedef base::Callback)> BrowserContextCallback; void GetBrowserContext( scoped_refptr task_runner, const BrowserContextCallback& callback); // Executes |callback| either synchronously or asynchronously with the request // context object when it's available. If |task_runner| is NULL the callback // will be executed on the originating thread. The resulting context object // can only be accessed on the IO thread. typedef base::Callback)> RequestContextCallback; void GetRequestContextImpl( scoped_refptr task_runner, const RequestContextCallback& callback); bool IsSame(CefRefPtr other) override; bool IsSharingWith(CefRefPtr other) override; bool IsGlobal() override; CefRefPtr GetHandler() override; CefString GetCachePath() override; CefRefPtr GetDefaultCookieManager( CefRefPtr callback) override; bool RegisterSchemeHandlerFactory( const CefString& scheme_name, const CefString& domain_name, CefRefPtr factory) override; bool ClearSchemeHandlerFactories() override; void PurgePluginListCache(bool reload_pages) override; bool HasPreference(const CefString& name) override; CefRefPtr GetPreference(const CefString& name) override; CefRefPtr GetAllPreferences( bool include_defaults) override; bool CanSetPreference(const CefString& name) override; bool SetPreference(const CefString& name, CefRefPtr value, CefString& error) override; void ClearCertificateExceptions( CefRefPtr callback) override; void CloseAllConnections(CefRefPtr callback) override; void ResolveHost( const CefString& origin, CefRefPtr callback) override; cef_errorcode_t ResolveHostCached( const CefString& origin, std::vector& resolved_ips) override; const CefRequestContextSettings& settings() const { return settings_; } private: friend class CefRequestContext; explicit CefRequestContextImpl( scoped_refptr browser_context); CefRequestContextImpl(const CefRequestContextSettings& settings, CefRefPtr handler); CefRequestContextImpl(CefRefPtr other, CefRefPtr handler); // Make sure the browser context exists. Only called on the UI thread. void EnsureBrowserContext(); void GetBrowserContextOnUIThread( scoped_refptr task_runner, const BrowserContextCallback& callback); void GetRequestContextImplOnIOThread( scoped_refptr task_runner, const RequestContextCallback& callback, scoped_refptr browser_context); void RegisterSchemeHandlerFactoryInternal( const CefString& scheme_name, const CefString& domain_name, CefRefPtr factory, scoped_refptr request_context); void ClearSchemeHandlerFactoriesInternal( scoped_refptr request_context); void PurgePluginListCacheInternal( bool reload_pages, scoped_refptr browser_context); void ClearCertificateExceptionsInternal( CefRefPtr callback, scoped_refptr browser_context); void CloseAllConnectionsInternal( CefRefPtr callback, scoped_refptr request_context); void ResolveHostInternal( const CefString& origin, CefRefPtr callback, scoped_refptr request_context); scoped_refptr browser_context_; CefRequestContextSettings settings_; CefRefPtr other_; CefRefPtr handler_; // Used to uniquely identify CefRequestContext objects before an associated // CefBrowserContext has been created. int unique_id_; // Owned by the CefBrowserContext. CefURLRequestContextGetterImpl* request_context_impl_; IMPLEMENT_REFCOUNTING(CefRequestContextImpl); DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl); }; #endif // CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_