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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "include/cef_request_context.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/browser_context.h"
|
2017-02-14 23:27:19 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
class CefBrowserContext;
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Implementation of the CefRequestContext interface. All methods are thread-
|
2017-02-14 23:27:19 +01:00
|
|
|
// safe unless otherwise indicated. Will be deleted on the UI thread.
|
2013-09-03 18:43:31 +02:00
|
|
|
class CefRequestContextImpl : public CefRequestContext {
|
|
|
|
public:
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefRequestContextImpl() override;
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
// Creates the singleton global RequestContext. Called from
|
|
|
|
// CefBrowserMainParts::PreMainMessageLoopRun.
|
|
|
|
static CefRefPtr<CefRequestContextImpl> CreateGlobalRequestContext(
|
|
|
|
const CefRequestContextSettings& settings);
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Returns a CefRequestContextImpl for the specified |request_context|.
|
|
|
|
// Will return the global context if |request_context| is NULL.
|
2017-02-14 23:27:19 +01:00
|
|
|
static CefRefPtr<CefRequestContextImpl> GetOrCreateForRequestContext(
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context);
|
|
|
|
|
|
|
|
// Returns the browser context object. Can only be called on the UI thread.
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* GetBrowserContext();
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
// 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.
|
2017-02-14 23:27:19 +01:00
|
|
|
typedef base::Callback<void(CefBrowserContext*)> BrowserContextCallback;
|
2015-03-02 21:25:14 +01:00
|
|
|
void GetBrowserContext(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> 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.
|
2019-03-22 23:11:51 +01:00
|
|
|
typedef base::Callback<void(scoped_refptr<CefURLRequestContextGetter>)>
|
2015-03-02 21:25:14 +01:00
|
|
|
RequestContextCallback;
|
|
|
|
void GetRequestContextImpl(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
const RequestContextCallback& callback);
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsSame(CefRefPtr<CefRequestContext> other) override;
|
2015-03-02 21:25:14 +01:00
|
|
|
bool IsSharingWith(CefRefPtr<CefRequestContext> other) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
bool IsGlobal() override;
|
|
|
|
CefRefPtr<CefRequestContextHandler> GetHandler() override;
|
2015-03-02 21:25:14 +01:00
|
|
|
CefString GetCachePath() override;
|
2019-03-22 23:11:51 +01:00
|
|
|
CefRefPtr<CefCookieManager> GetCookieManager(
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefCompletionCallback> callback) override;
|
|
|
|
bool RegisterSchemeHandlerFactory(
|
|
|
|
const CefString& scheme_name,
|
|
|
|
const CefString& domain_name,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory) override;
|
|
|
|
bool ClearSchemeHandlerFactories() override;
|
2015-09-25 13:59:30 +02:00
|
|
|
void PurgePluginListCache(bool reload_pages) override;
|
2015-10-03 01:03:16 +02:00
|
|
|
bool HasPreference(const CefString& name) override;
|
|
|
|
CefRefPtr<CefValue> GetPreference(const CefString& name) override;
|
|
|
|
CefRefPtr<CefDictionaryValue> GetAllPreferences(
|
|
|
|
bool include_defaults) override;
|
|
|
|
bool CanSetPreference(const CefString& name) override;
|
|
|
|
bool SetPreference(const CefString& name,
|
|
|
|
CefRefPtr<CefValue> value,
|
|
|
|
CefString& error) override;
|
2016-02-23 20:29:18 +01:00
|
|
|
void ClearCertificateExceptions(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) override;
|
|
|
|
void CloseAllConnections(CefRefPtr<CefCompletionCallback> callback) override;
|
2017-05-17 11:29:28 +02:00
|
|
|
void ResolveHost(const CefString& origin,
|
|
|
|
CefRefPtr<CefResolveCallback> callback) override;
|
2017-08-04 00:55:19 +02:00
|
|
|
void LoadExtension(const CefString& root_directory,
|
|
|
|
CefRefPtr<CefDictionaryValue> manifest,
|
|
|
|
CefRefPtr<CefExtensionHandler> handler) override;
|
|
|
|
bool DidLoadExtension(const CefString& extension_id) override;
|
|
|
|
bool HasExtension(const CefString& extension_id) override;
|
|
|
|
bool GetExtensions(std::vector<CefString>& extension_ids) override;
|
|
|
|
CefRefPtr<CefExtension> GetExtension(const CefString& extension_id) override;
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
const CefRequestContextSettings& settings() const { return config_.settings; }
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2019-03-24 00:40:32 +01:00
|
|
|
// Called from CefBrowserHostImpl::RenderFrameCreated or
|
|
|
|
// CefMimeHandlerViewGuestDelegate::OnGuestAttached when a render frame is
|
|
|
|
// created.
|
|
|
|
void OnRenderFrameCreated(int render_process_id,
|
|
|
|
int render_frame_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,
|
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view);
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
private:
|
|
|
|
friend class CefRequestContext;
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
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<CefRequestContextImpl> other;
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
// Optionally use this handler.
|
2017-02-14 23:27:19 +01:00
|
|
|
CefRefPtr<CefRequestContextHandler> 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;
|
|
|
|
};
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
static CefRefPtr<CefRequestContextImpl> GetOrCreateRequestContext(
|
|
|
|
const Config& config);
|
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
explicit CefRequestContextImpl(const Config& config);
|
|
|
|
|
|
|
|
void Initialize();
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
// Make sure the browser context exists. Only called on the UI thread.
|
|
|
|
void EnsureBrowserContext();
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void GetBrowserContextOnUIThread(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
const BrowserContextCallback& callback);
|
|
|
|
void GetRequestContextImplOnIOThread(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
|
|
|
const RequestContextCallback& callback,
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* browser_context);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
void RegisterSchemeHandlerFactoryInternal(
|
|
|
|
const CefString& scheme_name,
|
|
|
|
const CefString& domain_name,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory,
|
2019-03-22 23:11:51 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> request_context);
|
2015-03-02 21:25:14 +01:00
|
|
|
void ClearSchemeHandlerFactoriesInternal(
|
2019-03-22 23:11:51 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> request_context);
|
2017-05-17 11:29:28 +02:00
|
|
|
void PurgePluginListCacheInternal(bool reload_pages,
|
|
|
|
CefBrowserContext* browser_context);
|
2016-02-23 20:29:18 +01:00
|
|
|
void ClearCertificateExceptionsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* browser_context);
|
2016-02-23 20:29:18 +01:00
|
|
|
void CloseAllConnectionsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2019-03-22 23:11:51 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> request_context);
|
2016-02-24 00:27:05 +01:00
|
|
|
void ResolveHostInternal(
|
|
|
|
const CefString& origin,
|
|
|
|
CefRefPtr<CefResolveCallback> callback,
|
2019-03-22 23:11:51 +01:00
|
|
|
scoped_refptr<CefURLRequestContextGetter> request_context);
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* browser_context() const;
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
// We must disassociate from this on destruction.
|
|
|
|
CefBrowserContext* browser_context_ = nullptr;
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
Config config_;
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
// Owned by the CefBrowserContext.
|
2019-03-22 23:11:51 +01:00
|
|
|
CefURLRequestContextGetter* request_context_getter_ = nullptr;
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefRequestContextImpl);
|
2013-09-03 18:43:31 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefRequestContextImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_
|