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"
|
2020-03-19 16:34:15 +01:00
|
|
|
#include "libcef/browser/media_router/media_router_impl.h"
|
2020-03-27 21:00:36 +01:00
|
|
|
#include "libcef/browser/net_service/cookie_manager_impl.h"
|
2017-02-14 23:27:19 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
2021-08-19 23:07:44 +02:00
|
|
|
namespace content {
|
|
|
|
struct GlobalRenderFrameHostId;
|
|
|
|
}
|
|
|
|
|
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:
|
2021-12-06 21:40:25 +01:00
|
|
|
CefRequestContextImpl(const CefRequestContextImpl&) = delete;
|
|
|
|
CefRequestContextImpl& operator=(const CefRequestContextImpl&) = delete;
|
|
|
|
|
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
|
2022-08-23 03:37:40 +02:00
|
|
|
// AlloyBrowserMainParts::PreMainMessageLoopRun and
|
2022-08-23 18:20:45 +02:00
|
|
|
// ChromeBrowserMainExtraPartsCef::PostProfileInit.
|
2017-05-04 23:53:27 +02:00
|
|
|
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);
|
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
// Verify that the browser context can be directly accessed (e.g. on the UI
|
|
|
|
// thread and initialized).
|
|
|
|
bool VerifyBrowserContext() const;
|
|
|
|
|
|
|
|
// Returns the browser context object. Can only be called on the UI thread
|
|
|
|
// after the browser context has been initialized.
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* GetBrowserContext();
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
// If the context is fully initialized execute |callback|, otherwise
|
|
|
|
// store it until the context is fully initialized.
|
|
|
|
void ExecuteWhenBrowserContextInitialized(base::OnceClosure callback);
|
|
|
|
|
|
|
|
// Executes |callback| either synchronously or asynchronously after the
|
|
|
|
// browser context object has been initialized. If |task_runner| is NULL the
|
|
|
|
// callback will be executed on the originating thread. The resulting getter
|
|
|
|
// can only be executed on the UI thread.
|
|
|
|
using BrowserContextCallback =
|
|
|
|
base::OnceCallback<void(CefBrowserContext::Getter)>;
|
2015-03-02 21:25:14 +01:00
|
|
|
void GetBrowserContext(
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
2021-04-15 01:28:22 +02:00
|
|
|
BrowserContextCallback callback);
|
2015-03-02 21:25:14 +01: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-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;
|
2019-07-12 22:44:43 +02:00
|
|
|
void ClearHttpAuthCredentials(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) override;
|
2016-02-23 20:29:18 +01:00
|
|
|
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;
|
2021-04-15 01:28:22 +02:00
|
|
|
CefRefPtr<CefMediaRouter> GetMediaRouter(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) 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
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// Called from CefBrowserContentsDelegate::RenderFrameCreated or
|
2019-03-24 00:40:32 +01:00
|
|
|
// CefMimeHandlerViewGuestDelegate::OnGuestAttached when a render frame is
|
|
|
|
// created.
|
2021-08-19 23:07:44 +02:00
|
|
|
void OnRenderFrameCreated(const content::GlobalRenderFrameHostId& global_id,
|
2019-03-24 00:40:32 +01:00
|
|
|
bool is_main_frame,
|
|
|
|
bool is_guest_view);
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// Called from CefBrowserContentsDelegate::RenderFrameDeleted or
|
2019-03-24 00:40:32 +01:00
|
|
|
// CefMimeHandlerViewGuestDelegate::OnGuestDetached when a render frame is
|
|
|
|
// deleted.
|
2021-08-19 23:07:44 +02:00
|
|
|
void OnRenderFrameDeleted(const content::GlobalRenderFrameHostId& global_id,
|
2019-03-24 00:40:32 +01:00
|
|
|
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();
|
2021-04-07 00:09:45 +02:00
|
|
|
void BrowserContextInitialized();
|
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();
|
|
|
|
|
2016-02-23 20:29:18 +01:00
|
|
|
void ClearCertificateExceptionsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2021-04-15 01:28:22 +02:00
|
|
|
CefBrowserContext::Getter browser_context_getter);
|
2019-07-12 22:44:43 +02:00
|
|
|
void ClearHttpAuthCredentialsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
2021-04-15 01:28:22 +02:00
|
|
|
CefBrowserContext::Getter browser_context_getter);
|
|
|
|
void CloseAllConnectionsInternal(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback,
|
|
|
|
CefBrowserContext::Getter browser_context_getter);
|
2019-05-18 19:41:14 +02:00
|
|
|
void ResolveHostInternal(const CefString& origin,
|
|
|
|
CefRefPtr<CefResolveCallback> callback,
|
2021-04-15 01:28:22 +02:00
|
|
|
CefBrowserContext::Getter browser_context_getter);
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2021-04-15 01:28:22 +02:00
|
|
|
void InitializeCookieManagerInternal(
|
2020-03-27 21:00:36 +01:00
|
|
|
CefRefPtr<CefCookieManagerImpl> cookie_manager,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback);
|
2021-04-15 01:28:22 +02:00
|
|
|
void InitializeMediaRouterInternal(CefRefPtr<CefMediaRouterImpl> media_router,
|
|
|
|
CefRefPtr<CefCompletionCallback> callback);
|
2020-03-19 16:34:15 +01: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
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefRequestContextImpl);
|
2013-09-03 18:43:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_REQUEST_CONTEXT_IMPL_H_
|