mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Enforce matching context for new user and incognito profiles
Selecting a new user or incognito profile via Chrome UI may result in the creation of a new Profile object. If that occurs, we should find or create a matching CefBrowserContext and CefRequestContext instead of reusing an existing mismatched context (e.g. using the original context for an incognito window would be a mismatch). If a new CefRequestContext will be created the client can now implement CefBrowserProcessHandler::GetDefaultRequestContextHandler() to provide the handler for that context. To test with a new user profile: 1. Click "Profile" icon, select "Add". Now you have 2+ profiles. 2. Click "Profile" icon, select the other user name to create a new window using the other user profile. 3. The new window should launch successfully. To test with a new incognito profile: 1. Select "New Incognito window" from the 3-dot menu. 2. The new window should launch successfully. To test DevTools window creation for the new profile: 1. Right-click in the new window, select Inspect. 2. The DevTools window should launch successfully.
This commit is contained in:
@ -33,7 +33,7 @@
|
|||||||
// by hand. See the translator.README.txt file in the tools directory for
|
// by hand. See the translator.README.txt file in the tools directory for
|
||||||
// more information.
|
// more information.
|
||||||
//
|
//
|
||||||
// $hash=f844d2a1e39d822129d0733f33c14d27481c36b7$
|
// $hash=d958d5bed7f909f6313facef3440fb8ba07a5c01$
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_PROCESS_HANDLER_CAPI_H_
|
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_PROCESS_HANDLER_CAPI_H_
|
||||||
@ -44,6 +44,7 @@
|
|||||||
#include "include/capi/cef_client_capi.h"
|
#include "include/capi/cef_client_capi.h"
|
||||||
#include "include/capi/cef_command_line_capi.h"
|
#include "include/capi/cef_command_line_capi.h"
|
||||||
#include "include/capi/cef_preference_capi.h"
|
#include "include/capi/cef_preference_capi.h"
|
||||||
|
#include "include/capi/cef_request_context_handler_capi.h"
|
||||||
#include "include/capi/cef_values_capi.h"
|
#include "include/capi/cef_values_capi.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -147,14 +148,26 @@ typedef struct _cef_browser_process_handler_t {
|
|||||||
int64_t delay_ms);
|
int64_t delay_ms);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Return the default client for use with a newly created browser window. If
|
/// Return the default client for use with a newly created browser window
|
||||||
/// null is returned the browser will be unmanaged (no callbacks will be
|
/// (cef_browser_t object). If null is returned the cef_browser_t will be
|
||||||
/// executed for that browser) and application shutdown will be blocked until
|
/// unmanaged (no callbacks will be executed for that cef_browser_t) and
|
||||||
/// the browser window is closed manually. This function is currently only
|
/// application shutdown will be blocked until the browser window is closed
|
||||||
/// used with the chrome runtime.
|
/// manually. This function is currently only used with the Chrome runtime
|
||||||
|
/// when creating new browser windows via Chrome UI.
|
||||||
///
|
///
|
||||||
struct _cef_client_t*(CEF_CALLBACK* get_default_client)(
|
struct _cef_client_t*(CEF_CALLBACK* get_default_client)(
|
||||||
struct _cef_browser_process_handler_t* self);
|
struct _cef_browser_process_handler_t* self);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Return the default handler for use with a new user or incognito profile
|
||||||
|
/// (cef_request_context_t object). If null is returned the
|
||||||
|
/// cef_request_context_t will be unmanaged (no callbacks will be executed for
|
||||||
|
/// that cef_request_context_t). This function is currently only used with the
|
||||||
|
/// Chrome runtime when creating new browser windows via Chrome UI.
|
||||||
|
///
|
||||||
|
struct _cef_request_context_handler_t*(
|
||||||
|
CEF_CALLBACK* get_default_request_context_handler)(
|
||||||
|
struct _cef_browser_process_handler_t* self);
|
||||||
} cef_browser_process_handler_t;
|
} cef_browser_process_handler_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -42,13 +42,13 @@
|
|||||||
// way that may cause binary incompatibility with other builds. The universal
|
// way that may cause binary incompatibility with other builds. The universal
|
||||||
// hash value will change if any platform is affected whereas the platform hash
|
// hash value will change if any platform is affected whereas the platform hash
|
||||||
// values will change only if that particular platform is affected.
|
// values will change only if that particular platform is affected.
|
||||||
#define CEF_API_HASH_UNIVERSAL "60ecc3c751154b2b2b41e5d3ac0ccbeba588918d"
|
#define CEF_API_HASH_UNIVERSAL "afb63c581ad6ef9b3d3ebed472cc66f75ce4647f"
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
#define CEF_API_HASH_PLATFORM "7819cee8508a9b048ccfa80acea7351a5b549c45"
|
#define CEF_API_HASH_PLATFORM "504dbb53deeebd11a16ea01533c5d9ecfa6be555"
|
||||||
#elif defined(OS_MAC)
|
#elif defined(OS_MAC)
|
||||||
#define CEF_API_HASH_PLATFORM "f2bb2e5a9d14dcad463fd3fc8ed4af16b6fe6196"
|
#define CEF_API_HASH_PLATFORM "dc3cf1d007fec844ab287dac384c8b00366d46fc"
|
||||||
#elif defined(OS_LINUX)
|
#elif defined(OS_LINUX)
|
||||||
#define CEF_API_HASH_PLATFORM "bcf76490ddea85c12ea8feeee9190ffe24dedcc6"
|
#define CEF_API_HASH_PLATFORM "2b47d389c64db81913818b708b78868a22e65b66"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "include/cef_client.h"
|
#include "include/cef_client.h"
|
||||||
#include "include/cef_command_line.h"
|
#include "include/cef_command_line.h"
|
||||||
#include "include/cef_preference.h"
|
#include "include/cef_preference.h"
|
||||||
|
#include "include/cef_request_context_handler.h"
|
||||||
#include "include/cef_values.h"
|
#include "include/cef_values.h"
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -139,14 +140,28 @@ class CefBrowserProcessHandler : public virtual CefBaseRefCounted {
|
|||||||
virtual void OnScheduleMessagePumpWork(int64_t delay_ms) {}
|
virtual void OnScheduleMessagePumpWork(int64_t delay_ms) {}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Return the default client for use with a newly created browser window. If
|
/// Return the default client for use with a newly created browser window
|
||||||
/// null is returned the browser will be unmanaged (no callbacks will be
|
/// (CefBrowser object). If null is returned the CefBrowser will be unmanaged
|
||||||
/// executed for that browser) and application shutdown will be blocked until
|
/// (no callbacks will be executed for that CefBrowser) and application
|
||||||
/// the browser window is closed manually. This method is currently only used
|
/// shutdown will be blocked until the browser window is closed manually. This
|
||||||
/// with the chrome runtime.
|
/// method is currently only used with the Chrome runtime when creating new
|
||||||
|
/// browser windows via Chrome UI.
|
||||||
///
|
///
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual CefRefPtr<CefClient> GetDefaultClient() { return nullptr; }
|
virtual CefRefPtr<CefClient> GetDefaultClient() { return nullptr; }
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Return the default handler for use with a new user or incognito profile
|
||||||
|
/// (CefRequestContext object). If null is returned the CefRequestContext will
|
||||||
|
/// be unmanaged (no callbacks will be executed for that CefRequestContext).
|
||||||
|
/// This method is currently only used with the Chrome runtime when creating
|
||||||
|
/// new browser windows via Chrome UI.
|
||||||
|
///
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual CefRefPtr<CefRequestContextHandler>
|
||||||
|
GetDefaultRequestContextHandler() {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CEF_INCLUDE_CEF_BROWSER_PROCESS_HANDLER_H_
|
#endif // CEF_INCLUDE_CEF_BROWSER_PROCESS_HANDLER_H_
|
||||||
|
@ -273,22 +273,7 @@ CefBrowserContext* CefBrowserContext::FromBrowserContext(
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
CefBrowserContext* CefBrowserContext::FromProfile(const Profile* profile) {
|
CefBrowserContext* CefBrowserContext::FromProfile(const Profile* profile) {
|
||||||
auto* cef_context = FromBrowserContext(profile);
|
return FromBrowserContext(profile);
|
||||||
if (cef_context) {
|
|
||||||
return cef_context;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cef::IsChromeRuntimeEnabled()) {
|
|
||||||
auto* original_profile = profile->GetOriginalProfile();
|
|
||||||
if (original_profile != profile) {
|
|
||||||
// With the Chrome runtime if the user launches an incognito window via
|
|
||||||
// the UI we might be associated with the original Profile instead of the
|
|
||||||
// (current) incognito profile.
|
|
||||||
return FromBrowserContext(original_profile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -430,6 +415,24 @@ CefMediaRouterManager* CefBrowserContext::GetMediaRouterManager() {
|
|||||||
return media_router_manager_.get();
|
return media_router_manager_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CefRefPtr<CefRequestContextImpl> CefBrowserContext::GetAnyRequestContext(
|
||||||
|
bool prefer_no_handler) const {
|
||||||
|
CEF_REQUIRE_UIT();
|
||||||
|
if (request_context_set_.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefer_no_handler) {
|
||||||
|
for (const auto& request_context : request_context_set_) {
|
||||||
|
if (!request_context->GetHandler()) {
|
||||||
|
return request_context;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *request_context_set_.begin();
|
||||||
|
}
|
||||||
|
|
||||||
CefBrowserContext::CookieableSchemes CefBrowserContext::GetCookieableSchemes()
|
CefBrowserContext::CookieableSchemes CefBrowserContext::GetCookieableSchemes()
|
||||||
const {
|
const {
|
||||||
CEF_REQUIRE_UIT();
|
CEF_REQUIRE_UIT();
|
||||||
|
@ -104,7 +104,7 @@ class CefBrowserContext {
|
|||||||
const content::GlobalRenderFrameHostId& global_id,
|
const content::GlobalRenderFrameHostId& global_id,
|
||||||
bool require_frame_match);
|
bool require_frame_match);
|
||||||
|
|
||||||
// Returns the underlying CefBrowserContext if any.
|
// Returns the underlying CefBrowserContext, if any.
|
||||||
static CefBrowserContext* FromBrowserContext(
|
static CefBrowserContext* FromBrowserContext(
|
||||||
const content::BrowserContext* context);
|
const content::BrowserContext* context);
|
||||||
static CefBrowserContext* FromProfile(const Profile* profile);
|
static CefBrowserContext* FromProfile(const Profile* profile);
|
||||||
@ -179,6 +179,14 @@ class CefBrowserContext {
|
|||||||
|
|
||||||
CefMediaRouterManager* GetMediaRouterManager();
|
CefMediaRouterManager* GetMediaRouterManager();
|
||||||
|
|
||||||
|
// Returns any CefRequestContext associated with this object, or nullptr if
|
||||||
|
// none exist. If |prefer_no_handler| is true this method will try to return a
|
||||||
|
// context without an associated CefRequestContextHandler. Use
|
||||||
|
// CefRequestContextImpl::GetOrCreateForBrowserContext() instead of calling
|
||||||
|
// this method directly.
|
||||||
|
CefRefPtr<CefRequestContextImpl> GetAnyRequestContext(
|
||||||
|
bool prefer_no_handler) const;
|
||||||
|
|
||||||
using CookieableSchemes = absl::optional<std::vector<std::string>>;
|
using CookieableSchemes = absl::optional<std::vector<std::string>>;
|
||||||
|
|
||||||
// Returns the schemes associated with this context specifically, or the
|
// Returns the schemes associated with this context specifically, or the
|
||||||
|
@ -38,6 +38,28 @@ ChromeBrowserContext::ChromeBrowserContext(
|
|||||||
|
|
||||||
ChromeBrowserContext::~ChromeBrowserContext() = default;
|
ChromeBrowserContext::~ChromeBrowserContext() = default;
|
||||||
|
|
||||||
|
// static
|
||||||
|
ChromeBrowserContext* ChromeBrowserContext::GetOrCreateForProfile(
|
||||||
|
Profile* profile) {
|
||||||
|
DCHECK(profile);
|
||||||
|
|
||||||
|
if (auto existing_context = FromProfile(profile)) {
|
||||||
|
return static_cast<ChromeBrowserContext*>(existing_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
CefRequestContextSettings settings;
|
||||||
|
if (!profile->IsOffTheRecord()) {
|
||||||
|
// Become the primary context associated with |cache_path|.
|
||||||
|
CefString(&settings.cache_path) = profile->GetPath().value();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* new_context = new ChromeBrowserContext(settings);
|
||||||
|
new_context->Initialize();
|
||||||
|
new_context->ProfileCreated(Profile::CreateStatus::CREATE_STATUS_INITIALIZED,
|
||||||
|
profile);
|
||||||
|
return new_context;
|
||||||
|
}
|
||||||
|
|
||||||
content::BrowserContext* ChromeBrowserContext::AsBrowserContext() {
|
content::BrowserContext* ChromeBrowserContext::AsBrowserContext() {
|
||||||
CHECK(!destroyed_);
|
CHECK(!destroyed_);
|
||||||
return profile_;
|
return profile_;
|
||||||
@ -146,8 +168,10 @@ void ChromeBrowserContext::ProfileCreated(Profile::CreateStatus status,
|
|||||||
// exists.
|
// exists.
|
||||||
profile_ = profile;
|
profile_ = profile;
|
||||||
profile_->AddObserver(this);
|
profile_->AddObserver(this);
|
||||||
profile_keep_alive_ = std::make_unique<ScopedProfileKeepAlive>(
|
if (!profile_->IsOffTheRecord()) {
|
||||||
profile_, ProfileKeepAliveOrigin::kAppWindow);
|
profile_keep_alive_ = std::make_unique<ScopedProfileKeepAlive>(
|
||||||
|
profile_, ProfileKeepAliveOrigin::kAppWindow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == Profile::CreateStatus::CREATE_STATUS_INITIALIZED) {
|
if (status == Profile::CreateStatus::CREATE_STATUS_INITIALIZED) {
|
||||||
|
@ -23,6 +23,9 @@ class ChromeBrowserContext : public CefBrowserContext, public ProfileObserver {
|
|||||||
ChromeBrowserContext(const ChromeBrowserContext&) = delete;
|
ChromeBrowserContext(const ChromeBrowserContext&) = delete;
|
||||||
ChromeBrowserContext& operator=(const ChromeBrowserContext&) = delete;
|
ChromeBrowserContext& operator=(const ChromeBrowserContext&) = delete;
|
||||||
|
|
||||||
|
// Returns a ChromeBrowserContext for the specified |profile|.
|
||||||
|
static ChromeBrowserContext* GetOrCreateForProfile(Profile* profile);
|
||||||
|
|
||||||
void InitializeAsync(base::OnceClosure initialized_cb);
|
void InitializeAsync(base::OnceClosure initialized_cb);
|
||||||
|
|
||||||
// CefBrowserContext overrides.
|
// CefBrowserContext overrides.
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "libcef/browser/browser_host_base.h"
|
#include "libcef/browser/browser_host_base.h"
|
||||||
#include "libcef/browser/browser_info_manager.h"
|
#include "libcef/browser/browser_info_manager.h"
|
||||||
#include "libcef/browser/browser_platform_delegate.h"
|
#include "libcef/browser/browser_platform_delegate.h"
|
||||||
|
#include "libcef/browser/chrome/chrome_browser_context.h"
|
||||||
#include "libcef/browser/chrome/chrome_browser_host_impl.h"
|
#include "libcef/browser/chrome/chrome_browser_host_impl.h"
|
||||||
#include "libcef/browser/chrome/views/chrome_browser_view.h"
|
#include "libcef/browser/chrome/views/chrome_browser_view.h"
|
||||||
#include "libcef/browser/chrome/views/chrome_child_window.h"
|
#include "libcef/browser/chrome/views/chrome_child_window.h"
|
||||||
@ -67,9 +68,7 @@ Browser* ChromeBrowserDelegate::CreateDevToolsBrowser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We expect openers and popups to have the same Profile.
|
// We expect openers and popups to have the same Profile.
|
||||||
CHECK_EQ(
|
CHECK_EQ(opener->profile(), profile);
|
||||||
CefRequestContextImpl::GetProfile(opener_browser_host->request_context()),
|
|
||||||
profile);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 1. Get configuration settings from the user and create the new platform
|
// 1. Get configuration settings from the user and create the new platform
|
||||||
@ -608,12 +607,25 @@ CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserDelegate::CreateBrowserHost(
|
|||||||
LOG(WARNING) << "Creating a chrome browser without a client";
|
LOG(WARNING) << "Creating a chrome browser without a client";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if chrome and CEF are using the same browser context.
|
// Get or create a ChromeBrowserContext for the browser Profile. Creation may
|
||||||
// TODO(chrome-runtime): Verify if/when this might occur.
|
// be necessary when selecting a new or incognito Profile for the first time
|
||||||
|
// via the Chrome UI.
|
||||||
auto chrome_browser_context =
|
auto chrome_browser_context =
|
||||||
CefBrowserContext::FromBrowserContext(browser_->create_params().profile);
|
ChromeBrowserContext::GetOrCreateForProfile(browser_->profile());
|
||||||
|
|
||||||
|
// If the provided CefRequestContext matches the ChromeBrowserContext then use
|
||||||
|
// the provided one, as it will have the preferred CefRequestContextHandler.
|
||||||
|
// Otherwise, get or create a CefRequestContext that matches.
|
||||||
if (chrome_browser_context != request_context_impl->GetBrowserContext()) {
|
if (chrome_browser_context != request_context_impl->GetBrowserContext()) {
|
||||||
LOG(WARNING) << "Creating a chrome browser with mismatched context";
|
CefRefPtr<CefRequestContextHandler> handler;
|
||||||
|
if (auto app = CefAppManager::Get()->GetApplication()) {
|
||||||
|
if (auto bph = app->GetBrowserProcessHandler()) {
|
||||||
|
handler = bph->GetDefaultRequestContextHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request_context_impl = CefRequestContextImpl::GetOrCreateForBrowserContext(
|
||||||
|
chrome_browser_context, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remains alive until the associated WebContents is destroyed.
|
// Remains alive until the associated WebContents is destroyed.
|
||||||
|
@ -601,6 +601,10 @@ void ChromeBrowserHostImpl::SetBrowser(Browser* browser) {
|
|||||||
static_cast<CefBrowserPlatformDelegateChrome*>(platform_delegate_.get())
|
static_cast<CefBrowserPlatformDelegateChrome*>(platform_delegate_.get())
|
||||||
->set_chrome_browser(browser);
|
->set_chrome_browser(browser);
|
||||||
if (browser_) {
|
if (browser_) {
|
||||||
|
// We expect the Browser and CefRequestContext to have the same Profile.
|
||||||
|
CHECK_EQ(browser_->profile(),
|
||||||
|
request_context()->GetBrowserContext()->AsProfile());
|
||||||
|
|
||||||
host_window_handle_ = platform_delegate_->GetHostWindowHandle();
|
host_window_handle_ = platform_delegate_->GetHostWindowHandle();
|
||||||
} else {
|
} else {
|
||||||
host_window_handle_ = kNullWindowHandle;
|
host_window_handle_ = kNullWindowHandle;
|
||||||
|
@ -115,7 +115,7 @@ CefRefPtr<CefRequestContext> CefRequestContext::GetGlobalContext() {
|
|||||||
|
|
||||||
CefRequestContextImpl::Config config;
|
CefRequestContextImpl::Config config;
|
||||||
config.is_global = true;
|
config.is_global = true;
|
||||||
return CefRequestContextImpl::GetOrCreateRequestContext(config);
|
return CefRequestContextImpl::GetOrCreateRequestContext(std::move(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -132,7 +132,7 @@ CefRefPtr<CefRequestContext> CefRequestContext::CreateContext(
|
|||||||
config.settings = settings;
|
config.settings = settings;
|
||||||
config.handler = handler;
|
config.handler = handler;
|
||||||
config.unique_id = g_next_id.GetNext();
|
config.unique_id = g_next_id.GetNext();
|
||||||
return CefRequestContextImpl::GetOrCreateRequestContext(config);
|
return CefRequestContextImpl::GetOrCreateRequestContext(std::move(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -153,7 +153,7 @@ CefRefPtr<CefRequestContext> CefRequestContext::CreateContext(
|
|||||||
config.other = static_cast<CefRequestContextImpl*>(other.get());
|
config.other = static_cast<CefRequestContextImpl*>(other.get());
|
||||||
config.handler = handler;
|
config.handler = handler;
|
||||||
config.unique_id = g_next_id.GetNext();
|
config.unique_id = g_next_id.GetNext();
|
||||||
return CefRequestContextImpl::GetOrCreateRequestContext(config);
|
return CefRequestContextImpl::GetOrCreateRequestContext(std::move(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
// CefRequestContextImpl
|
// CefRequestContextImpl
|
||||||
@ -176,7 +176,8 @@ CefRequestContextImpl::CreateGlobalRequestContext(
|
|||||||
Config config;
|
Config config;
|
||||||
config.is_global = true;
|
config.is_global = true;
|
||||||
config.settings = settings;
|
config.settings = settings;
|
||||||
CefRefPtr<CefRequestContextImpl> impl = new CefRequestContextImpl(config);
|
CefRefPtr<CefRequestContextImpl> impl =
|
||||||
|
new CefRequestContextImpl(std::move(config));
|
||||||
impl->Initialize();
|
impl->Initialize();
|
||||||
return impl;
|
return impl;
|
||||||
}
|
}
|
||||||
@ -193,7 +194,21 @@ CefRequestContextImpl::GetOrCreateForRequestContext(
|
|||||||
// Use the global context.
|
// Use the global context.
|
||||||
Config config;
|
Config config;
|
||||||
config.is_global = true;
|
config.is_global = true;
|
||||||
return CefRequestContextImpl::GetOrCreateRequestContext(config);
|
return CefRequestContextImpl::GetOrCreateRequestContext(std::move(config));
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
CefRefPtr<CefRequestContextImpl>
|
||||||
|
CefRequestContextImpl::GetOrCreateForBrowserContext(
|
||||||
|
CefBrowserContext* browser_context,
|
||||||
|
CefRefPtr<CefRequestContextHandler> handler) {
|
||||||
|
DCHECK(browser_context);
|
||||||
|
|
||||||
|
Config config;
|
||||||
|
config.browser_context = browser_context;
|
||||||
|
config.handler = handler;
|
||||||
|
config.unique_id = g_next_id.GetNext();
|
||||||
|
return CefRequestContextImpl::GetOrCreateRequestContext(std::move(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
content::BrowserContext* CefRequestContextImpl::GetBrowserContext(
|
content::BrowserContext* CefRequestContextImpl::GetBrowserContext(
|
||||||
@ -241,7 +256,6 @@ void CefRequestContextImpl::ExecuteWhenBrowserContextInitialized(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsureBrowserContext();
|
|
||||||
browser_context()->StoreOrTriggerInitCallback(std::move(callback));
|
browser_context()->StoreOrTriggerInitCallback(std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,7 +652,32 @@ void CefRequestContextImpl::OnRenderFrameDeleted(
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
CefRefPtr<CefRequestContextImpl>
|
CefRefPtr<CefRequestContextImpl>
|
||||||
CefRequestContextImpl::GetOrCreateRequestContext(const Config& config) {
|
CefRequestContextImpl::GetOrCreateRequestContext(Config&& config) {
|
||||||
|
if (config.browser_context) {
|
||||||
|
// CefBrowserContext is only accessed on the UI thread.
|
||||||
|
CEF_REQUIRE_UIT();
|
||||||
|
DCHECK(!config.is_global);
|
||||||
|
DCHECK(!config.other);
|
||||||
|
|
||||||
|
// Retrieve any request context that currently exists for the browser
|
||||||
|
// context. If |config.handler| is nullptr, and the returned request context
|
||||||
|
// does not have a handler, then we can just return that existing context.
|
||||||
|
// Otherwise, we'll need to create a new request context with
|
||||||
|
// |config.handler|.
|
||||||
|
if (auto other = config.browser_context->GetAnyRequestContext(
|
||||||
|
/*prefer_no_handler=*/!config.handler)) {
|
||||||
|
if (!config.handler && !other->GetHandler()) {
|
||||||
|
// Safe to return the existing context.
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the existing request context as a starting point. It may be the
|
||||||
|
// global context. This is functionally equivalent to calling
|
||||||
|
// `CefRequestContext::CreateContext(other, handler)`.
|
||||||
|
config.other = other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (config.is_global ||
|
if (config.is_global ||
|
||||||
(config.other && config.other->IsGlobal() && !config.handler)) {
|
(config.other && config.other->IsGlobal() && !config.handler)) {
|
||||||
// Return the singleton global context.
|
// Return the singleton global context.
|
||||||
@ -646,8 +685,8 @@ CefRequestContextImpl::GetOrCreateRequestContext(const Config& config) {
|
|||||||
CefAppManager::Get()->GetGlobalRequestContext().get());
|
CefAppManager::Get()->GetGlobalRequestContext().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// The new context will be initialized later by EnsureBrowserContext().
|
CefRefPtr<CefRequestContextImpl> context =
|
||||||
CefRefPtr<CefRequestContextImpl> context = new CefRequestContextImpl(config);
|
new CefRequestContextImpl(std::move(config));
|
||||||
|
|
||||||
// Initialize ASAP so that any tasks blocked on initialization will execute.
|
// Initialize ASAP so that any tasks blocked on initialization will execute.
|
||||||
if (CEF_CURRENTLY_ON_UIT()) {
|
if (CEF_CURRENTLY_ON_UIT()) {
|
||||||
@ -661,8 +700,8 @@ CefRequestContextImpl::GetOrCreateRequestContext(const Config& config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CefRequestContextImpl::CefRequestContextImpl(
|
CefRequestContextImpl::CefRequestContextImpl(
|
||||||
const CefRequestContextImpl::Config& config)
|
CefRequestContextImpl::Config&& config)
|
||||||
: config_(config) {}
|
: config_(std::move(config)) {}
|
||||||
|
|
||||||
void CefRequestContextImpl::Initialize() {
|
void CefRequestContextImpl::Initialize() {
|
||||||
CEF_REQUIRE_UIT();
|
CEF_REQUIRE_UIT();
|
||||||
@ -673,6 +712,9 @@ void CefRequestContextImpl::Initialize() {
|
|||||||
// Share storage with |config_.other|.
|
// Share storage with |config_.other|.
|
||||||
browser_context_ = config_.other->browser_context();
|
browser_context_ = config_.other->browser_context();
|
||||||
CHECK(browser_context_);
|
CHECK(browser_context_);
|
||||||
|
} else if (config_.browser_context) {
|
||||||
|
browser_context_ = config_.browser_context;
|
||||||
|
config_.browser_context = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!browser_context_) {
|
if (!browser_context_) {
|
||||||
@ -710,9 +752,10 @@ void CefRequestContextImpl::Initialize() {
|
|||||||
browser_context_->AddCefRequestContext(this);
|
browser_context_->AddCefRequestContext(this);
|
||||||
|
|
||||||
if (config_.other) {
|
if (config_.other) {
|
||||||
// Clear the reference to |config_.other| after setting
|
// Clear the reference to |config_.other| after adding the new assocation
|
||||||
// |request_context_getter_|. This is the reverse order of checks in
|
// with |browser_context_| as this may result in |other| being released
|
||||||
// IsSharedWith().
|
// and we don't want the browser context to be destroyed prematurely.
|
||||||
|
// This is the also the reverse order of checks in IsSharingWith().
|
||||||
config_.other = nullptr;
|
config_.other = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -727,14 +770,6 @@ void CefRequestContextImpl::BrowserContextInitialized() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRequestContextImpl::EnsureBrowserContext() {
|
|
||||||
CEF_REQUIRE_UIT();
|
|
||||||
if (!browser_context()) {
|
|
||||||
Initialize();
|
|
||||||
}
|
|
||||||
DCHECK(browser_context());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CefRequestContextImpl::ClearCertificateExceptionsInternal(
|
void CefRequestContextImpl::ClearCertificateExceptionsInternal(
|
||||||
CefRefPtr<CefCompletionCallback> callback,
|
CefRefPtr<CefCompletionCallback> callback,
|
||||||
CefBrowserContext::Getter browser_context_getter) {
|
CefBrowserContext::Getter browser_context_getter) {
|
||||||
|
@ -38,6 +38,16 @@ class CefRequestContextImpl : public CefRequestContext {
|
|||||||
static CefRefPtr<CefRequestContextImpl> GetOrCreateForRequestContext(
|
static CefRefPtr<CefRequestContextImpl> GetOrCreateForRequestContext(
|
||||||
CefRefPtr<CefRequestContext> request_context);
|
CefRefPtr<CefRequestContext> request_context);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
// Returns the BrowserContext for the specified |request_context|. Will return
|
// Returns the BrowserContext for the specified |request_context|. Will return
|
||||||
// the global BrowserContext if |request_context| is NULL.
|
// the global BrowserContext if |request_context| is NULL.
|
||||||
static content::BrowserContext* GetBrowserContext(
|
static content::BrowserContext* GetBrowserContext(
|
||||||
@ -145,10 +155,12 @@ class CefRequestContextImpl : public CefRequestContext {
|
|||||||
// True if wrapping the global context.
|
// True if wrapping the global context.
|
||||||
bool is_global = false;
|
bool is_global = false;
|
||||||
|
|
||||||
|
// Wrap an existing (non-global) browser context. When specifying this value
|
||||||
|
// GetOrCreateRequestContext() must be called on the UI thread.
|
||||||
|
CefBrowserContext* browser_context = nullptr;
|
||||||
|
|
||||||
// |settings| or |other| will be set when creating a new CefRequestContext
|
// |settings| or |other| will be set when creating a new CefRequestContext
|
||||||
// via the API. When wrapping an existing CefBrowserContext* both will be
|
// via the API.
|
||||||
// empty and Initialize(CefBrowserContext*) will be called immediately after
|
|
||||||
// CefRequestContextImpl construction.
|
|
||||||
CefRequestContextSettings settings;
|
CefRequestContextSettings settings;
|
||||||
CefRefPtr<CefRequestContextImpl> other;
|
CefRefPtr<CefRequestContextImpl> other;
|
||||||
|
|
||||||
@ -156,22 +168,19 @@ class CefRequestContextImpl : public CefRequestContext {
|
|||||||
CefRefPtr<CefRequestContextHandler> handler;
|
CefRefPtr<CefRequestContextHandler> handler;
|
||||||
|
|
||||||
// Used to uniquely identify CefRequestContext objects before an associated
|
// Used to uniquely identify CefRequestContext objects before an associated
|
||||||
// CefBrowserContext has been created. Should be set when a new
|
// CefBrowserContext has been created. Should be set when creating a new
|
||||||
// CefRequestContext via the API.
|
// CefRequestContext via the API.
|
||||||
int unique_id = -1;
|
int unique_id = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static CefRefPtr<CefRequestContextImpl> GetOrCreateRequestContext(
|
static CefRefPtr<CefRequestContextImpl> GetOrCreateRequestContext(
|
||||||
const Config& config);
|
Config&& config);
|
||||||
|
|
||||||
explicit CefRequestContextImpl(const Config& config);
|
explicit CefRequestContextImpl(Config&& config);
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void BrowserContextInitialized();
|
void BrowserContextInitialized();
|
||||||
|
|
||||||
// Make sure the browser context exists. Only called on the UI thread.
|
|
||||||
void EnsureBrowserContext();
|
|
||||||
|
|
||||||
void ClearCertificateExceptionsInternal(
|
void ClearCertificateExceptionsInternal(
|
||||||
CefRefPtr<CefCompletionCallback> callback,
|
CefRefPtr<CefCompletionCallback> callback,
|
||||||
CefBrowserContext::Getter browser_context_getter);
|
CefBrowserContext::Getter browser_context_getter);
|
||||||
|
@ -9,11 +9,12 @@
|
|||||||
// implementations. See the translator.README.txt file in the tools directory
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=11604cc40431cd047990f92e86495c9ccd7ded29$
|
// $hash=5703528ee112474079bd5d04f5ca9f2f290238fa$
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "libcef_dll/cpptoc/browser_process_handler_cpptoc.h"
|
#include "libcef_dll/cpptoc/browser_process_handler_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/client_cpptoc.h"
|
#include "libcef_dll/cpptoc/client_cpptoc.h"
|
||||||
|
#include "libcef_dll/cpptoc/request_context_handler_cpptoc.h"
|
||||||
#include "libcef_dll/ctocpp/command_line_ctocpp.h"
|
#include "libcef_dll/ctocpp/command_line_ctocpp.h"
|
||||||
#include "libcef_dll/ctocpp/preference_registrar_ctocpp.h"
|
#include "libcef_dll/ctocpp/preference_registrar_ctocpp.h"
|
||||||
|
|
||||||
@ -138,6 +139,25 @@ struct _cef_client_t* CEF_CALLBACK browser_process_handler_get_default_client(
|
|||||||
return CefClientCppToC::Wrap(_retval);
|
return CefClientCppToC::Wrap(_retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct _cef_request_context_handler_t* CEF_CALLBACK
|
||||||
|
browser_process_handler_get_default_request_context_handler(
|
||||||
|
struct _cef_browser_process_handler_t* self) {
|
||||||
|
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||||
|
|
||||||
|
DCHECK(self);
|
||||||
|
if (!self) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
CefRefPtr<CefRequestContextHandler> _retval =
|
||||||
|
CefBrowserProcessHandlerCppToC::Get(self)
|
||||||
|
->GetDefaultRequestContextHandler();
|
||||||
|
|
||||||
|
// Return type: refptr_same
|
||||||
|
return CefRequestContextHandlerCppToC::Wrap(_retval);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// CONSTRUCTOR - Do not edit by hand.
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
@ -154,6 +174,8 @@ CefBrowserProcessHandlerCppToC::CefBrowserProcessHandlerCppToC() {
|
|||||||
GetStruct()->on_schedule_message_pump_work =
|
GetStruct()->on_schedule_message_pump_work =
|
||||||
browser_process_handler_on_schedule_message_pump_work;
|
browser_process_handler_on_schedule_message_pump_work;
|
||||||
GetStruct()->get_default_client = browser_process_handler_get_default_client;
|
GetStruct()->get_default_client = browser_process_handler_get_default_client;
|
||||||
|
GetStruct()->get_default_request_context_handler =
|
||||||
|
browser_process_handler_get_default_request_context_handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DESTRUCTOR - Do not edit by hand.
|
// DESTRUCTOR - Do not edit by hand.
|
||||||
|
@ -9,13 +9,14 @@
|
|||||||
// implementations. See the translator.README.txt file in the tools directory
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=1d072dd56acd042383f193e1986606ebb2bb9ee1$
|
// $hash=1487ab43138b7c4bee2b05064a91ed051ff2533e$
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "libcef_dll/ctocpp/browser_process_handler_ctocpp.h"
|
#include "libcef_dll/ctocpp/browser_process_handler_ctocpp.h"
|
||||||
#include "libcef_dll/cpptoc/command_line_cpptoc.h"
|
#include "libcef_dll/cpptoc/command_line_cpptoc.h"
|
||||||
#include "libcef_dll/cpptoc/preference_registrar_cpptoc.h"
|
#include "libcef_dll/cpptoc/preference_registrar_cpptoc.h"
|
||||||
#include "libcef_dll/ctocpp/client_ctocpp.h"
|
#include "libcef_dll/ctocpp/client_ctocpp.h"
|
||||||
|
#include "libcef_dll/ctocpp/request_context_handler_ctocpp.h"
|
||||||
|
|
||||||
// VIRTUAL METHODS - Body may be edited by hand.
|
// VIRTUAL METHODS - Body may be edited by hand.
|
||||||
|
|
||||||
@ -136,6 +137,24 @@ CefRefPtr<CefClient> CefBrowserProcessHandlerCToCpp::GetDefaultClient() {
|
|||||||
return CefClientCToCpp::Wrap(_retval);
|
return CefClientCToCpp::Wrap(_retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NO_SANITIZE("cfi-icall")
|
||||||
|
CefRefPtr<CefRequestContextHandler>
|
||||||
|
CefBrowserProcessHandlerCToCpp::GetDefaultRequestContextHandler() {
|
||||||
|
cef_browser_process_handler_t* _struct = GetStruct();
|
||||||
|
if (CEF_MEMBER_MISSING(_struct, get_default_request_context_handler)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
cef_request_context_handler_t* _retval =
|
||||||
|
_struct->get_default_request_context_handler(_struct);
|
||||||
|
|
||||||
|
// Return type: refptr_same
|
||||||
|
return CefRequestContextHandlerCToCpp::Wrap(_retval);
|
||||||
|
}
|
||||||
|
|
||||||
// CONSTRUCTOR - Do not edit by hand.
|
// CONSTRUCTOR - Do not edit by hand.
|
||||||
|
|
||||||
CefBrowserProcessHandlerCToCpp::CefBrowserProcessHandlerCToCpp() {}
|
CefBrowserProcessHandlerCToCpp::CefBrowserProcessHandlerCToCpp() {}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// implementations. See the translator.README.txt file in the tools directory
|
// implementations. See the translator.README.txt file in the tools directory
|
||||||
// for more information.
|
// for more information.
|
||||||
//
|
//
|
||||||
// $hash=adc863edb83f2bb42719a92c410289ee338acb0f$
|
// $hash=1212f57d4d21fbb85deba5fc02bfe0a38a6d1a04$
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_BROWSER_PROCESS_HANDLER_CTOCPP_H_
|
#ifndef CEF_LIBCEF_DLL_CTOCPP_BROWSER_PROCESS_HANDLER_CTOCPP_H_
|
||||||
@ -45,6 +45,8 @@ class CefBrowserProcessHandlerCToCpp
|
|||||||
const CefString& current_directory) override;
|
const CefString& current_directory) override;
|
||||||
void OnScheduleMessagePumpWork(int64_t delay_ms) override;
|
void OnScheduleMessagePumpWork(int64_t delay_ms) override;
|
||||||
CefRefPtr<CefClient> GetDefaultClient() override;
|
CefRefPtr<CefClient> GetDefaultClient() override;
|
||||||
|
CefRefPtr<CefRequestContextHandler> GetDefaultRequestContextHandler()
|
||||||
|
override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CEF_LIBCEF_DLL_CTOCPP_BROWSER_PROCESS_HANDLER_CTOCPP_H_
|
#endif // CEF_LIBCEF_DLL_CTOCPP_BROWSER_PROCESS_HANDLER_CTOCPP_H_
|
||||||
|
Reference in New Issue
Block a user