mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Add support for Alloy style browsers and windows (see #3681)
Split the Alloy runtime into bootstrap and style components. Support creation of Alloy style browsers and windows with the Chrome runtime. Chrome runtime (`--enable-chrome-runtime`) + Alloy style (`--use-alloy-style`) supports Views (`--use-views`), native parent (`--use-native`) and windowless rendering (`--off-screen-rendering-enabled`). Print preview is supported in all cases except with windowless rendering on all platforms and native parent on MacOS. It is disabled by default with Alloy style for legacy compatibility. Where supported it can be enabled or disabled globally using `--[enable|disable]-print-preview` or configured on a per-RequestContext basis using the `printing.print_preview_disabled` preference. It also behaves as expected when triggered via the PDF viewer print button. Chrome runtime + Alloy style behavior differs from Alloy runtime in the following significant ways: - Supports Chrome error pages by default. - DevTools popups are Chrome style only (cannot be windowless). - The Alloy extension API will not supported. Chrome runtime + Alloy style passes all expected Alloy ceftests except the following: - `DisplayTest.AutoResize` (Alloy extension API not supported) - `DownloadTest.*` (Download API not yet supported) - `ExtensionTest.*` (Alloy extension API not supported) This change also adds Chrome runtime support for CefContextMenuHandler::RunContextMenu (see #3293). This change also explicitly blocks (and doesn't retry) FrameAttached requests from PDF viewer and print preview excluded frames (see #3664). Known issues specific to Chrome runtime + Alloy style: - DevTools popup with windowless rendering doesn't load successfully. Use windowed rendering or remote debugging as a workaround. - Chrome style Window with Alloy style BrowserView (`--use-alloy-style --use-chrome-style-window`) does not show Chrome theme changes. To test: - Run `ceftests --enable-chrome-runtime --use-alloy-style [--use-chrome-style-window] [--use-views|--use-native] --gtest_filter=...` - Run `cefclient --enable-chrome-runtime --use-alloy-style [--use-chrome-style-window] [--use-views|--use-native|--off-screen-rendering-enabled]` - Run `cefsimple --enable-chrome-runtime --use-alloy-style [--use-views]`
This commit is contained in:
@@ -6,11 +6,9 @@
|
||||
|
||||
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
|
||||
#include "libcef/browser/browser_context.h"
|
||||
#include "libcef/browser/browser_host_base.h"
|
||||
#include "libcef/browser/browser_info_manager.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/extensions/extensions_util.h"
|
||||
#include "libcef/common/frame_util.h"
|
||||
#include "libcef/features/runtime_checks.h"
|
||||
|
||||
#include "chrome/browser/browser_process.h"
|
||||
@@ -19,111 +17,60 @@
|
||||
#include "content/browser/web_contents/web_contents_impl.h"
|
||||
#include "content/public/browser/browser_context.h"
|
||||
#include "content/public/browser/browser_plugin_guest_manager.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
void GetAllGuestsForOwnerContents(content::WebContents* owner,
|
||||
std::vector<content::WebContents*>* guests) {
|
||||
content::BrowserPluginGuestManager* plugin_guest_manager =
|
||||
owner->GetBrowserContext()->GetGuestManager();
|
||||
plugin_guest_manager->ForEachGuest(
|
||||
owner, [guests](content::WebContents* web_contents) {
|
||||
guests->push_back(web_contents);
|
||||
return false; // Continue iterating.
|
||||
});
|
||||
}
|
||||
namespace {
|
||||
|
||||
content::WebContents* GetOwnerForGuestContents(content::WebContents* guest) {
|
||||
content::WebContentsImpl* guest_impl =
|
||||
static_cast<content::WebContentsImpl*>(guest);
|
||||
content::WebContents* GetOwnerForBrowserPluginGuest(
|
||||
const content::WebContents* guest) {
|
||||
auto* guest_impl = static_cast<const content::WebContentsImpl*>(guest);
|
||||
content::BrowserPluginGuest* plugin_guest =
|
||||
guest_impl->GetBrowserPluginGuest();
|
||||
if (plugin_guest) {
|
||||
return plugin_guest->owner_web_contents();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Maybe it's a print preview dialog.
|
||||
content::WebContents* GetInitiatorForPrintPreviewDialog(
|
||||
const content::WebContents* guest) {
|
||||
auto print_preview_controller =
|
||||
g_browser_process->print_preview_dialog_controller();
|
||||
return print_preview_controller->GetInitiator(guest);
|
||||
return print_preview_controller->GetInitiator(
|
||||
const_cast<content::WebContents*>(guest));
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForGlobalId(
|
||||
const content::GlobalRenderFrameHostId& global_id,
|
||||
bool* is_guest_view) {
|
||||
if (CEF_CURRENTLY_ON_UIT()) {
|
||||
// Use the non-thread-safe but potentially faster approach.
|
||||
content::RenderFrameHost* host =
|
||||
content::RenderFrameHost::FromID(global_id);
|
||||
if (host) {
|
||||
return GetOwnerBrowserForHost(host, is_guest_view);
|
||||
}
|
||||
return nullptr;
|
||||
} else {
|
||||
// Use the thread-safe approach.
|
||||
scoped_refptr<CefBrowserInfo> info =
|
||||
CefBrowserInfoManager::GetInstance()->GetBrowserInfo(global_id,
|
||||
is_guest_view);
|
||||
if (info.get()) {
|
||||
CefRefPtr<CefBrowserHostBase> browser = info->browser();
|
||||
if (!browser.get()) {
|
||||
LOG(WARNING) << "Found browser id " << info->browser_id()
|
||||
<< " but no browser object matching frame "
|
||||
<< frame_util::GetFrameDebugString(global_id);
|
||||
}
|
||||
return browser;
|
||||
}
|
||||
return nullptr;
|
||||
} // namespace
|
||||
|
||||
content::WebContents* GetOwnerForGuestContents(
|
||||
const content::WebContents* guest) {
|
||||
// Maybe it's a guest view. This occurs while loading the PDF viewer.
|
||||
if (auto* owner = GetOwnerForBrowserPluginGuest(guest)) {
|
||||
return owner;
|
||||
}
|
||||
|
||||
// Maybe it's a print preview dialog. This occurs while loading the print
|
||||
// preview dialog.
|
||||
if (auto* initiator = GetInitiatorForPrintPreviewDialog(guest)) {
|
||||
// Maybe the dialog is parented to a guest view. This occurs while loading
|
||||
// the print preview dialog from inside the PDF viewer.
|
||||
if (auto* owner = GetOwnerForBrowserPluginGuest(initiator)) {
|
||||
return owner;
|
||||
}
|
||||
return initiator;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
|
||||
content::RenderViewHost* host,
|
||||
bool* is_guest_view) {
|
||||
if (is_guest_view) {
|
||||
*is_guest_view = false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostBase> browser =
|
||||
CefBrowserHostBase::GetBrowserForHost(host);
|
||||
if (!browser.get() && ExtensionsEnabled()) {
|
||||
// Retrieve the owner browser, if any.
|
||||
content::WebContents* owner = GetOwnerForGuestContents(
|
||||
content::WebContents::FromRenderViewHost(host));
|
||||
if (owner) {
|
||||
browser = CefBrowserHostBase::GetBrowserForContents(owner);
|
||||
if (browser.get() && is_guest_view) {
|
||||
*is_guest_view = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return browser;
|
||||
bool IsBrowserPluginGuest(const content::WebContents* web_contents) {
|
||||
return !!GetOwnerForBrowserPluginGuest(web_contents);
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
|
||||
content::RenderFrameHost* host,
|
||||
bool* is_guest_view) {
|
||||
if (is_guest_view) {
|
||||
*is_guest_view = false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostBase> browser =
|
||||
CefBrowserHostBase::GetBrowserForHost(host);
|
||||
if (!browser.get() && ExtensionsEnabled()) {
|
||||
// Retrieve the owner browser, if any.
|
||||
content::WebContents* owner = GetOwnerForGuestContents(
|
||||
content::WebContents::FromRenderFrameHost(host));
|
||||
if (owner) {
|
||||
browser = CefBrowserHostBase::GetBrowserForContents(owner);
|
||||
if (browser.get() && is_guest_view) {
|
||||
*is_guest_view = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return browser;
|
||||
bool IsPrintPreviewDialog(const content::WebContents* web_contents) {
|
||||
return !!GetInitiatorForPrintPreviewDialog(web_contents);
|
||||
}
|
||||
|
||||
CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
|
||||
@@ -141,8 +88,8 @@ CefRefPtr<AlloyBrowserHostImpl> GetBrowserForTabId(
|
||||
|
||||
for (const auto& browser_info :
|
||||
CefBrowserInfoManager::GetInstance()->GetBrowserInfoList()) {
|
||||
CefRefPtr<AlloyBrowserHostImpl> current_browser =
|
||||
static_cast<AlloyBrowserHostImpl*>(browser_info->browser().get());
|
||||
auto current_browser =
|
||||
AlloyBrowserHostImpl::FromBaseChecked(browser_info->browser());
|
||||
if (current_browser && current_browser->GetIdentifier() == tab_id) {
|
||||
// Make sure we're operating in the same CefBrowserContext.
|
||||
if (CefBrowserContext::FromBrowserContext(
|
||||
|
@@ -13,45 +13,22 @@
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
struct GlobalRenderFrameHostId;
|
||||
class RenderFrameHost;
|
||||
class RenderViewHost;
|
||||
class WebContents;
|
||||
} // namespace content
|
||||
|
||||
class CefBrowserHostBase;
|
||||
class AlloyBrowserHostImpl;
|
||||
|
||||
namespace extensions {
|
||||
|
||||
class Extension;
|
||||
|
||||
// Populates |guests| with all guest WebContents with the specified |owner|.
|
||||
void GetAllGuestsForOwnerContents(content::WebContents* owner,
|
||||
std::vector<content::WebContents*>* guests);
|
||||
|
||||
// Returns the WebContents that owns the specified |guest|, if any.
|
||||
content::WebContents* GetOwnerForGuestContents(content::WebContents* guest);
|
||||
content::WebContents* GetOwnerForGuestContents(
|
||||
const content::WebContents* guest);
|
||||
|
||||
// Returns the CefBrowserHostBase that owns the host identified by the specified
|
||||
// global ID, if any. |is_guest_view| will be set to true if the ID
|
||||
// matches a guest view associated with the returned browser instead of the
|
||||
// browser itself.
|
||||
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForGlobalId(
|
||||
const content::GlobalRenderFrameHostId& global_id,
|
||||
bool* is_guest_view);
|
||||
|
||||
// Returns the CefBrowserHostBase that owns the specified |host|, if any.
|
||||
// |is_guest_view| will be set to true if the host matches a guest view
|
||||
// associated with the returned browser instead of the browser itself.
|
||||
// TODO(cef): Delete the RVH variant once the remaining use case
|
||||
// (via AlloyContentBrowserClient::OverrideWebkitPrefs) has been removed.
|
||||
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
|
||||
content::RenderViewHost* host,
|
||||
bool* is_guest_view);
|
||||
CefRefPtr<CefBrowserHostBase> GetOwnerBrowserForHost(
|
||||
content::RenderFrameHost* host,
|
||||
bool* is_guest_view);
|
||||
// Test for different types of guest contents.
|
||||
bool IsBrowserPluginGuest(const content::WebContents* web_contents);
|
||||
bool IsPrintPreviewDialog(const content::WebContents* web_contents);
|
||||
|
||||
// Returns the browser matching |tab_id| and |browser_context|. Returns false if
|
||||
// |tab_id| is < 0 or a matching browser cannot be found within
|
||||
|
@@ -28,9 +28,9 @@ bool CefBrowserPlatformDelegateBackground::CreateHostWindow() {
|
||||
void CefBrowserPlatformDelegateBackground::CloseHostWindow() {
|
||||
// No host window, so continue browser destruction now. Do it asynchronously
|
||||
// so the call stack has a chance to unwind.
|
||||
CEF_POST_TASK(CEF_UIT,
|
||||
base::BindOnce(&AlloyBrowserHostImpl::WindowDestroyed,
|
||||
static_cast<AlloyBrowserHostImpl*>(browser_)));
|
||||
CEF_POST_TASK(
|
||||
CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::WindowDestroyed,
|
||||
AlloyBrowserHostImpl::FromBaseChecked(browser_)));
|
||||
}
|
||||
|
||||
CefWindowHandle CefBrowserPlatformDelegateBackground::GetHostWindowHandle()
|
||||
|
@@ -168,8 +168,8 @@ CefRefPtr<AlloyBrowserHostImpl> CefExtensionFunctionDetails::GetCurrentBrowser()
|
||||
handler->GetActiveBrowser(GetCefExtension(), browser.get(),
|
||||
function_->include_incognito_information());
|
||||
if (active_browser && active_browser != browser) {
|
||||
CefRefPtr<AlloyBrowserHostImpl> active_browser_impl =
|
||||
static_cast<AlloyBrowserHostImpl*>(active_browser.get());
|
||||
auto active_browser_impl = AlloyBrowserHostImpl::FromBaseChecked(
|
||||
CefBrowserHostBase::FromBrowser(active_browser));
|
||||
|
||||
// Make sure we're operating in the same CefBrowserContext.
|
||||
if (CefBrowserContext::FromBrowserContext(
|
||||
@@ -371,11 +371,9 @@ std::unique_ptr<api::tabs::Tab> CefExtensionFunctionDetails::OpenTab(
|
||||
CefBrowserCreateParams create_params;
|
||||
create_params.url = url.spec();
|
||||
create_params.request_context = request_context;
|
||||
create_params.window_info = std::make_unique<CefWindowInfo>();
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
create_params.window_info->SetAsPopup(nullptr, CefString());
|
||||
#endif
|
||||
CefWindowInfo windowInfo;
|
||||
CefBrowserCreateParams::InitWindowInfo(&windowInfo, active_browser.get());
|
||||
|
||||
// Start with the active browser's settings.
|
||||
create_params.client = active_browser->GetClient();
|
||||
@@ -391,10 +389,12 @@ std::unique_ptr<api::tabs::Tab> CefExtensionFunctionDetails::OpenTab(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
create_params.MaybeSetWindowInfo(windowInfo, /*allow_alloy_style=*/true,
|
||||
/*allow_chrome_style=*/false);
|
||||
|
||||
if (active_browser->is_views_hosted()) {
|
||||
// The new browser will also be Views hosted.
|
||||
create_params.popup_with_views_hosted_opener = true;
|
||||
create_params.window_info.reset();
|
||||
}
|
||||
|
||||
// Browser creation may fail under certain rare circumstances.
|
||||
|
@@ -13,7 +13,7 @@
|
||||
#include "libcef/browser/extensions/mime_handler_view_guest_delegate.h"
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "chrome/browser/printing/print_view_manager.h"
|
||||
#include "chrome/browser/printing/printing_init.h"
|
||||
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
|
||||
#include "components/zoom/zoom_controller.h"
|
||||
#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
|
||||
@@ -47,7 +47,7 @@ CefExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
|
||||
void CefExtensionsAPIClient::AttachWebContentsHelpers(
|
||||
content::WebContents* web_contents) const {
|
||||
PrefsTabHelper::CreateForWebContents(web_contents);
|
||||
printing::PrintViewManager::CreateForWebContents(web_contents);
|
||||
printing::InitializePrintingForWebContents(web_contents);
|
||||
|
||||
// Used by the tabs extension API.
|
||||
zoom::ZoomController::CreateForWebContents(web_contents);
|
||||
|
Reference in New Issue
Block a user