diff --git a/libcef/browser/browser_platform_delegate.cc b/libcef/browser/browser_platform_delegate.cc index 5a9727a00..9da6ba9f1 100644 --- a/libcef/browser/browser_platform_delegate.cc +++ b/libcef/browser/browser_platform_delegate.cc @@ -195,8 +195,9 @@ void CefBrowserPlatformDelegate::PopupWebContentsCreated( } CefRefPtr new_delegate; - CefRefPtr opener_delegate; + cef_runtime_style_t opener_runtime_style = CEF_RUNTIME_STYLE_DEFAULT; + auto browser_view = GetBrowserView(); if (browser_view) { // When |this| (the popup opener) is Views-hosted use the current delegate. @@ -212,9 +213,16 @@ void CefBrowserPlatformDelegate::PopupWebContentsCreated( browser_view, settings, client, is_devtools); } + if (browser_view) { + opener_runtime_style = browser_view->GetRuntimeStyle(); + } else if (opener_delegate) { + opener_runtime_style = opener_delegate->GetBrowserRuntimeStyle(); + } + // Create a new BrowserView for the popup. CefRefPtr new_browser_view = - CefBrowserViewImpl::CreateForPopup(settings, new_delegate, is_devtools); + CefBrowserViewImpl::CreateForPopup(settings, new_delegate, is_devtools, + opener_runtime_style); // Associate the PlatformDelegate with the new BrowserView. new_platform_delegate->SetBrowserView(new_browser_view); diff --git a/libcef/browser/views/browser_view_impl.cc b/libcef/browser/views/browser_view_impl.cc index feead0781..72927bc88 100644 --- a/libcef/browser/views/browser_view_impl.cc +++ b/libcef/browser/views/browser_view_impl.cc @@ -35,30 +35,39 @@ std::optional GetGestureCommand( return std::nullopt; } -bool ComputeAlloyStyle(CefBrowserViewDelegate* cef_delegate, - bool is_devtools_popup) { - // Alloy style is not supported with Chrome DevTools popups. - const bool supports_alloy_style = !is_devtools_popup; - const auto default_style = CEF_RUNTIME_STYLE_CHROME; - - auto result_style = default_style; - - if (cef_delegate) { - auto requested_style = cef_delegate->GetBrowserRuntimeStyle(); - if (requested_style == CEF_RUNTIME_STYLE_ALLOY) { - if (supports_alloy_style) { - result_style = requested_style; - } else { - LOG(ERROR) << "GetBrowserRuntimeStyle() requested Alloy style; only " - "Chrome style is supported"; - } - } else if (requested_style == CEF_RUNTIME_STYLE_CHROME) { - // Chrome style is always supported. - result_style = requested_style; +bool ComputeAlloyStyle( + CefBrowserViewDelegate* cef_delegate, + bool is_devtools_popup, + std::optional opener_runtime_style) { + if (is_devtools_popup) { + // Alloy style is not supported with Chrome DevTools popups. + if (cef_delegate && + cef_delegate->GetBrowserRuntimeStyle() == CEF_RUNTIME_STYLE_ALLOY) { + LOG(ERROR) << "GetBrowserRuntimeStyle() requested Alloy style; only " + "Chrome style is supported for DevTools popups"; } + return false; } - return result_style == CEF_RUNTIME_STYLE_ALLOY; + if (opener_runtime_style) { + // Popup style must match the opener style. + const bool opener_alloy_style = + *opener_runtime_style == CEF_RUNTIME_STYLE_ALLOY; + if (cef_delegate) { + const auto requested_style = cef_delegate->GetBrowserRuntimeStyle(); + if (requested_style != CEF_RUNTIME_STYLE_DEFAULT && + requested_style != (opener_alloy_style ? CEF_RUNTIME_STYLE_ALLOY + : CEF_RUNTIME_STYLE_CHROME)) { + LOG(ERROR) + << "GetBrowserRuntimeStyle() for popups must match opener style"; + } + } + return opener_alloy_style; + } + + // Chrome style is the default unless Alloy is specifically requested. + return cef_delegate && + cef_delegate->GetBrowserRuntimeStyle() == CEF_RUNTIME_STYLE_ALLOY; } } // namespace @@ -111,7 +120,8 @@ CefRefPtr CefBrowserViewImpl::Create( } CefRefPtr browser_view = - new CefBrowserViewImpl(delegate, /*is_devtools_popup=*/false); + new CefBrowserViewImpl(delegate, /*is_devtools_popup=*/false, + /*opener_runtime_style=*/std::nullopt); browser_view->SetPendingBrowserCreateParams( window_info, client, url, settings, extra_info, request_context); browser_view->Initialize(); @@ -123,11 +133,12 @@ CefRefPtr CefBrowserViewImpl::Create( CefRefPtr CefBrowserViewImpl::CreateForPopup( const CefBrowserSettings& settings, CefRefPtr delegate, - bool is_devtools) { + bool is_devtools, + cef_runtime_style_t opener_runtime_style) { CEF_REQUIRE_UIT_RETURN(nullptr); CefRefPtr browser_view = - new CefBrowserViewImpl(delegate, is_devtools); + new CefBrowserViewImpl(delegate, is_devtools, opener_runtime_style); browser_view->Initialize(); browser_view->SetDefaults(settings); return browser_view; @@ -337,9 +348,12 @@ bool CefBrowserViewImpl::OnGestureEvent(ui::GestureEvent* event) { CefBrowserViewImpl::CefBrowserViewImpl( CefRefPtr delegate, - bool is_devtools_popup) + bool is_devtools_popup, + std::optional opener_runtime_style) : ParentClass(delegate), - is_alloy_style_(ComputeAlloyStyle(delegate.get(), is_devtools_popup)), + is_alloy_style_(ComputeAlloyStyle(delegate.get(), + is_devtools_popup, + opener_runtime_style)), weak_ptr_factory_(this) {} void CefBrowserViewImpl::SetPendingBrowserCreateParams( diff --git a/libcef/browser/views/browser_view_impl.h b/libcef/browser/views/browser_view_impl.h index 91bec3c18..565c242eb 100644 --- a/libcef/browser/views/browser_view_impl.h +++ b/libcef/browser/views/browser_view_impl.h @@ -6,6 +6,8 @@ #define CEF_LIBCEF_BROWSER_VIEWS_BROWSER_VIEW_IMPL_H_ #pragma once +#include + #include "base/functional/callback_forward.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" @@ -49,7 +51,8 @@ class CefBrowserViewImpl static CefRefPtr CreateForPopup( const CefBrowserSettings& settings, CefRefPtr delegate, - bool is_devtools); + bool is_devtools, + cef_runtime_style_t opener_runtime_style); // Called from CefBrowserPlatformDelegate[Chrome]Views. void WebContentsCreated(content::WebContents* web_contents); @@ -101,7 +104,8 @@ class CefBrowserViewImpl // Always call Initialize() after creation. // |delegate| may be nullptr. CefBrowserViewImpl(CefRefPtr delegate, - bool is_devtools_popup); + bool is_devtools_popup, + std::optional opener_runtime_style); void SetPendingBrowserCreateParams( const CefWindowInfo& window_info,