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.
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
#ifndef CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_IMPL_H_
|
2013-09-03 18:43:31 +02:00
|
|
|
#pragma once
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_request_context.h"
|
|
|
|
#include "cef/libcef/browser/browser_context.h"
|
|
|
|
#include "cef/libcef/browser/media_router/media_router_impl.h"
|
|
|
|
#include "cef/libcef/browser/net_service/cookie_manager_impl.h"
|
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
2017-02-14 23:27:19 +01:00
|
|
|
|
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);
|
|
|
|
|
2024-02-08 19:41:18 +01:00
|
|
|
// Returns a CefRequestContextImpl for the specified |browser_context| and
|
|
|
|
// optional |handler|. If |handler| is nullptr, and a CefRequestContextImpl
|
|
|
|
// without a handler currently exists for |browser_context|, then that
|
|
|
|
// existing CefRequestContextImpl will be returned. Otherwise, a new
|
|
|
|
// CefRequestContextImpl will be created with the specified |handler|. Must be
|
|
|
|
// called on the UI thread.
|
|
|
|
static CefRefPtr<CefRequestContextImpl> GetOrCreateForBrowserContext(
|
|
|
|
CefBrowserContext* browser_context,
|
|
|
|
CefRefPtr<CefRequestContextHandler> handler);
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
// Returns the BrowserContext for the specified |request_context|. Will return
|
|
|
|
// the global BrowserContext if |request_context| is NULL.
|
|
|
|
static content::BrowserContext* GetBrowserContext(
|
|
|
|
CefRefPtr<CefRequestContext> request_context);
|
|
|
|
|
|
|
|
// Returns the Profile for the specified |request_context|. Will return the
|
|
|
|
// global Profile if |request_context| is NULL.
|
|
|
|
static Profile* GetProfile(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;
|
2021-04-15 01:28:22 +02:00
|
|
|
CefRefPtr<CefMediaRouter> GetMediaRouter(
|
|
|
|
CefRefPtr<CefCompletionCallback> callback) override;
|
2023-05-25 13:15:06 +02:00
|
|
|
CefRefPtr<CefValue> GetWebsiteSetting(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type) override;
|
|
|
|
void SetWebsiteSetting(const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type,
|
|
|
|
CefRefPtr<CefValue> value) override;
|
|
|
|
cef_content_setting_values_t GetContentSetting(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type) override;
|
|
|
|
void SetContentSetting(const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type,
|
|
|
|
cef_content_setting_values_t value) override;
|
2024-03-29 17:48:33 +01:00
|
|
|
void SetChromeColorScheme(cef_color_variant_t variant,
|
|
|
|
cef_color_t user_color) override;
|
|
|
|
cef_color_variant_t GetChromeColorSchemeMode() override;
|
|
|
|
cef_color_t GetChromeColorSchemeColor() override;
|
|
|
|
cef_color_variant_t GetChromeColorSchemeVariant() 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
|
|
|
|
2024-04-24 23:23:47 +02:00
|
|
|
// Called from CefBrowserContentsDelegate::RenderFrameCreated when a render
|
|
|
|
// frame is created.
|
2021-08-19 23:07:44 +02:00
|
|
|
void OnRenderFrameCreated(const content::GlobalRenderFrameHostId& global_id,
|
2024-04-24 23:23:47 +02:00
|
|
|
bool is_main_frame);
|
2019-03-24 00:40:32 +01:00
|
|
|
|
2024-04-24 23:23:47 +02:00
|
|
|
// Called from CefBrowserContentsDelegate::RenderFrameDeleted when a render
|
|
|
|
// frame is deleted.
|
2021-08-19 23:07:44 +02:00
|
|
|
void OnRenderFrameDeleted(const content::GlobalRenderFrameHostId& global_id,
|
2024-04-24 23:23:47 +02:00
|
|
|
bool is_main_frame);
|
2019-03-24 00:40:32 +01:00
|
|
|
|
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;
|
|
|
|
|
2024-02-08 19:41:18 +01:00
|
|
|
// Wrap an existing (non-global) browser context. When specifying this value
|
|
|
|
// GetOrCreateRequestContext() must be called on the UI thread.
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<CefBrowserContext> browser_context = nullptr;
|
2024-02-08 19:41:18 +01:00
|
|
|
|
2017-02-14 23:27:19 +01:00
|
|
|
// |settings| or |other| will be set when creating a new CefRequestContext
|
2024-02-08 19:41:18 +01:00
|
|
|
// via the API.
|
2017-02-14 23:27:19 +01:00
|
|
|
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
|
2024-02-08 19:41:18 +01:00
|
|
|
// CefBrowserContext has been created. Should be set when creating a new
|
2017-02-14 23:27:19 +01:00
|
|
|
// CefRequestContext via the API.
|
|
|
|
int unique_id = -1;
|
|
|
|
};
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
static CefRefPtr<CefRequestContextImpl> GetOrCreateRequestContext(
|
2024-02-08 19:41:18 +01:00
|
|
|
Config&& config);
|
2017-05-04 23:53:27 +02:00
|
|
|
|
2024-02-08 19:41:18 +01:00
|
|
|
explicit CefRequestContextImpl(Config&& config);
|
2017-02-14 23:27:19 +01:00
|
|
|
|
|
|
|
void Initialize();
|
2021-04-07 00:09:45 +02:00
|
|
|
void BrowserContextInitialized();
|
2015-03-02 21:25:14 +01:00
|
|
|
|
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);
|
2023-05-25 13:15:06 +02:00
|
|
|
void SetWebsiteSettingInternal(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type,
|
|
|
|
CefRefPtr<CefValue> value,
|
|
|
|
CefBrowserContext::Getter browser_context_getter);
|
|
|
|
void SetContentSettingInternal(
|
|
|
|
const CefString& requesting_url,
|
|
|
|
const CefString& top_level_url,
|
|
|
|
cef_content_setting_types_t content_type,
|
|
|
|
cef_content_setting_values_t value,
|
|
|
|
CefBrowserContext::Getter browser_context_getter);
|
2024-03-29 17:48:33 +01:00
|
|
|
void SetChromeColorSchemeInternal(
|
|
|
|
cef_color_variant_t variant,
|
|
|
|
cef_color_t user_color,
|
|
|
|
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.
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<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
|
|
|
};
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
#endif // CEF_LIBCEF_BROWSER_REQUEST_CONTEXT_IMPL_H_
|