// 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" #include "libcef/browser/media_router/media_router_impl.h" #include "libcef/browser/net_service/cookie_manager_impl.h" #include "libcef/browser/thread_util.h" class CefBrowserContext; // Implementation of the CefRequestContext interface. All methods are thread- // safe unless otherwise indicated. Will be deleted on the UI thread. class CefRequestContextImpl : public CefRequestContext { public: ~CefRequestContextImpl() override; // Creates the singleton global RequestContext. Called from // CefBrowserMainParts::PreMainMessageLoopRun. static CefRefPtr CreateGlobalRequestContext( const CefRequestContextSettings& settings); // Returns a CefRequestContextImpl for the specified |request_context|. // Will return the global context if |request_context| is NULL. static CefRefPtr GetOrCreateForRequestContext( CefRefPtr request_context); // Returns the browser context object. Can only be called on the UI thread. CefBrowserContext* 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); bool IsSame(CefRefPtr other) override; bool IsSharingWith(CefRefPtr other) override; bool IsGlobal() override; CefRefPtr GetHandler() override; CefString GetCachePath() override; CefRefPtr GetCookieManager( 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 ClearHttpAuthCredentials( CefRefPtr callback) override; void CloseAllConnections(CefRefPtr callback) override; void ResolveHost(const CefString& origin, CefRefPtr callback) override; void LoadExtension(const CefString& root_directory, CefRefPtr manifest, CefRefPtr handler) override; bool DidLoadExtension(const CefString& extension_id) override; bool HasExtension(const CefString& extension_id) override; bool GetExtensions(std::vector& extension_ids) override; CefRefPtr GetExtension(const CefString& extension_id) override; CefRefPtr GetMediaRouter() override; const CefRequestContextSettings& settings() const { return config_.settings; } // Called from CefBrowserHostImpl::RenderFrameCreated or // CefMimeHandlerViewGuestDelegate::OnGuestAttached when a render frame is // created. void OnRenderFrameCreated(int render_process_id, int render_frame_id, int frame_tree_node_id, bool is_main_frame, bool is_guest_view); // Called from CefBrowserHostImpl::FrameDeleted or // CefMimeHandlerViewGuestDelegate::OnGuestDetached when a render frame is // deleted. void OnRenderFrameDeleted(int render_process_id, int render_frame_id, int frame_tree_node_id, bool is_main_frame, bool is_guest_view); private: friend class CefRequestContext; struct Config { // True if wrapping the global context. bool is_global = false; // |settings| or |other| will be set when creating a new CefRequestContext // via the API. When wrapping an existing CefBrowserContext* both will be // empty and Initialize(CefBrowserContext*) will be called immediately after // CefRequestContextImpl construction. CefRequestContextSettings settings; CefRefPtr other; // Optionally use this handler. CefRefPtr handler; // Used to uniquely identify CefRequestContext objects before an associated // CefBrowserContext has been created. Should be set when a new // CefRequestContext via the API. int unique_id = -1; }; static CefRefPtr GetOrCreateRequestContext( const Config& config); explicit CefRequestContextImpl(const Config& config); void Initialize(); // Make sure the browser context exists. Only called on the UI thread. void EnsureBrowserContext(); void GetBrowserContextOnUIThread( scoped_refptr task_runner, const BrowserContextCallback& callback); void PurgePluginListCacheInternal(bool reload_pages, CefBrowserContext* browser_context); void ClearCertificateExceptionsInternal( CefRefPtr callback, CefBrowserContext* browser_context); void ClearHttpAuthCredentialsInternal( CefRefPtr callback, CefBrowserContext* browser_context); void CloseAllConnectionsInternal(CefRefPtr callback, CefBrowserContext* browser_context); void ResolveHostInternal(const CefString& origin, CefRefPtr callback, CefBrowserContext* browser_context); void InitializeCookieManagerOnUIThread( CefRefPtr cookie_manager, CefRefPtr callback); void InitializeMediaRouterOnUIThread( CefRefPtr media_router); CefBrowserContext* browser_context() const; // We must disassociate from this on destruction. CefBrowserContext* browser_context_ = nullptr; Config config_; IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefRequestContextImpl); DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl); }; #endif // CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_