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:
Marshall Greenblatt
2024-04-17 12:01:26 -04:00
parent 62c93f01f4
commit dca0435d2f
216 changed files with 3388 additions and 1565 deletions

View File

@@ -113,11 +113,11 @@ void AddFileMenuItems(CefRefPtr<CefMenuModel> file_menu) {
}
CefBrowserViewDelegate::ChromeToolbarType CalculateChromeToolbarType(
bool use_alloy_style,
const std::string& toolbar_type,
bool hide_toolbar,
bool with_overlay_controls) {
if (!MainContext::Get()->UseChromeRuntime() || toolbar_type == "none" ||
hide_toolbar) {
if (use_alloy_style || toolbar_type == "none" || hide_toolbar) {
return CEF_CTT_NONE;
}
@@ -152,15 +152,24 @@ CefRefPtr<ViewsWindow> ViewsWindow::Create(
CefRefPtr<ViewsWindow> views_window =
new ViewsWindow(type, delegate, nullptr, command_line);
const auto expected_browser_runtime_style = views_window->use_alloy_style_
? CEF_RUNTIME_STYLE_ALLOY
: CEF_RUNTIME_STYLE_CHROME;
const auto expected_window_runtime_style =
views_window->use_alloy_style_window_ ? CEF_RUNTIME_STYLE_ALLOY
: CEF_RUNTIME_STYLE_CHROME;
// Create a new BrowserView.
CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
client, url, settings, nullptr, request_context, views_window);
CHECK_EQ(expected_browser_runtime_style, browser_view->GetRuntimeStyle());
// Associate the BrowserView with the ViewsWindow.
views_window->SetBrowserView(browser_view);
// Create a new top-level Window. It will show itself after creation.
CefWindow::CreateTopLevelWindow(views_window);
auto window = CefWindow::CreateTopLevelWindow(views_window);
CHECK_EQ(expected_window_runtime_style, window->GetRuntimeStyle());
return views_window;
}
@@ -292,15 +301,15 @@ void ViewsWindow::SetFavicon(CefRefPtr<CefImage> image) {
void ViewsWindow::SetFullscreen(bool fullscreen) {
CEF_REQUIRE_UI_THREAD();
// For Chrome runtime we ignore this notification from
// ClientHandler::OnFullscreenModeChange(). Chrome runtime will trigger
// For Chrome style we ignore this notification from
// ClientHandler::OnFullscreenModeChange(). Chrome style will trigger
// the fullscreen change internally and then call
// OnWindowFullscreenTransition().
if (MainContext::Get()->UseChromeRuntime()) {
if (!use_alloy_style_) {
return;
}
// For Alloy runtime we need to explicitly trigger the fullscreen change.
// For Alloy style we need to explicitly trigger the fullscreen change.
if (window_) {
// Results in a call to OnWindowFullscreenTransition().
window_->SetFullscreen(fullscreen);
@@ -531,6 +540,13 @@ bool ViewsWindow::UseFramelessWindowForPictureInPicture(
return hide_pip_frame_;
}
cef_runtime_style_t ViewsWindow::GetBrowserRuntimeStyle() {
if (use_alloy_style_) {
return CEF_RUNTIME_STYLE_ALLOY;
}
return CEF_RUNTIME_STYLE_DEFAULT;
}
void ViewsWindow::OnButtonPressed(CefRefPtr<CefButton> button) {
CEF_REQUIRE_UI_THREAD();
DCHECK(with_controls_);
@@ -680,10 +696,9 @@ void ViewsWindow::OnWindowFullscreenTransition(CefRefPtr<CefWindow> window,
ShowTopControls(!window->IsFullscreen());
}
// With Alloy runtime we need to explicitly exit browser fullscreen when
// exiting window fullscreen. Chrome runtime handles this internally.
if (!MainContext::Get()->UseChromeRuntime() && should_change &&
!window->IsFullscreen()) {
// With Alloy style we need to explicitly exit browser fullscreen when
// exiting window fullscreen. Chrome style handles this internally.
if (use_alloy_style_ && should_change && !window->IsFullscreen()) {
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
if (browser && browser->GetHost()->IsFullscreen()) {
// Will not cause a resize because the fullscreen transition has already
@@ -707,6 +722,13 @@ void ViewsWindow::OnThemeColorsChanged(CefRefPtr<CefWindow> window,
views_style::ApplyTo(window);
}
cef_runtime_style_t ViewsWindow::GetWindowRuntimeStyle() {
if (use_alloy_style_window_) {
return CEF_RUNTIME_STYLE_ALLOY;
}
return CEF_RUNTIME_STYLE_DEFAULT;
}
void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) {
CEF_REQUIRE_UI_THREAD();
DCHECK(browser_view_);
@@ -1100,13 +1122,26 @@ ViewsWindow::ViewsWindow(WindowType type,
Delegate* delegate,
CefRefPtr<CefBrowserView> browser_view,
CefRefPtr<CefCommandLine> command_line)
: type_(type), delegate_(delegate), command_line_(command_line) {
: type_(type),
delegate_(delegate),
use_alloy_style_(delegate->UseAlloyStyle()),
command_line_(command_line) {
DCHECK(delegate_);
if (browser_view) {
SetBrowserView(browser_view);
}
if (MainContext::Get()->UseChromeBootstrap()) {
use_alloy_style_window_ =
use_alloy_style_ &&
!command_line_->HasSwitch(switches::kUseChromeStyleWindow);
} else {
// Alloy bootstrap requires Alloy style.
DCHECK(use_alloy_style_);
use_alloy_style_window_ = true;
}
const bool is_normal_type = type_ == WindowType::NORMAL;
with_controls_ = is_normal_type && delegate_->WithControls();
@@ -1139,8 +1174,8 @@ ViewsWindow::ViewsWindow(WindowType type,
const std::string& toolbar_type =
command_line->GetSwitchValue(switches::kShowChromeToolbar);
chrome_toolbar_type_ = CalculateChromeToolbarType(toolbar_type, hide_toolbar,
with_overlay_controls_);
chrome_toolbar_type_ = CalculateChromeToolbarType(
use_alloy_style_, toolbar_type, hide_toolbar, with_overlay_controls_);
use_bottom_controls_ = command_line->HasSwitch(switches::kUseBottomControls);