From 44f7b57e7945589bfffd68ab848fa303ab78d924 Mon Sep 17 00:00:00 2001
From: Marshall Greenblatt <magreenblatt@gmail.com>
Date: Thu, 9 May 2024 12:18:57 -0400
Subject: [PATCH] cefsimple: Enable Chrome runtime by default (see #3685)

Run with `--disable-chrome-runtime` to use the Alloy runtime.
---
 tests/cefsimple/cefsimple_linux.cc | 12 +++++-------
 tests/cefsimple/cefsimple_mac.mm   | 13 ++++++-------
 tests/cefsimple/cefsimple_win.cc   | 12 +++++-------
 tests/cefsimple/simple_app.cc      | 19 ++++++++++++++-----
 4 files changed, 30 insertions(+), 26 deletions(-)

diff --git a/tests/cefsimple/cefsimple_linux.cc b/tests/cefsimple/cefsimple_linux.cc
index ca09f25e2..7765ef075 100644
--- a/tests/cefsimple/cefsimple_linux.cc
+++ b/tests/cefsimple/cefsimple_linux.cc
@@ -58,13 +58,11 @@ int main(int argc, char* argv[]) {
   // Specify CEF global settings here.
   CefSettings settings;
 
-  // Use the CEF Chrome runtime if "--enable-chrome-runtime" is specified via
-  // the command-line. Otherwise, use the CEF Alloy runtime. For more
-  // information about CEF runtimes see
-  // https://bitbucket.org/chromiumembedded/cef/wiki/Architecture.md#markdown-header-cef3
-  if (command_line->HasSwitch("enable-chrome-runtime")) {
-    settings.chrome_runtime = true;
-  }
+  // Use the CEF Chrome bootstrap unless "--disable-chrome-runtime" is specified
+  // via the command-line. Otherwise, use the CEF Alloy bootstrap. The Alloy
+  // bootstrap is deprecated and will be removed in ~M127. See
+  // https://github.com/chromiumembedded/cef/issues/3685
+  settings.chrome_runtime = !command_line->HasSwitch("disable-chrome-runtime");
 
 // When generating projects with CMake the CEF_USE_SANDBOX value will be defined
 // automatically. Pass -DUSE_SANDBOX=OFF to the CMake command-line to disable
diff --git a/tests/cefsimple/cefsimple_mac.mm b/tests/cefsimple/cefsimple_mac.mm
index 4f2233e1c..6748e8822 100644
--- a/tests/cefsimple/cefsimple_mac.mm
+++ b/tests/cefsimple/cefsimple_mac.mm
@@ -150,13 +150,12 @@ int main(int argc, char* argv[]) {
     // Specify CEF global settings here.
     CefSettings settings;
 
-    // Use the CEF Chrome runtime if "--enable-chrome-runtime" is specified via
-    // the command-line. Otherwise, use the CEF Alloy runtime. For more
-    // information about CEF runtimes see
-    // https://bitbucket.org/chromiumembedded/cef/wiki/Architecture.md#markdown-header-cef3
-    if (command_line->HasSwitch("enable-chrome-runtime")) {
-      settings.chrome_runtime = true;
-    }
+    // Use the CEF Chrome bootstrap unless "--disable-chrome-runtime" is
+    // specified via the command-line. Otherwise, use the CEF Alloy bootstrap.
+    // The Alloy bootstrap is deprecated and will be removed in ~M127. See
+    // https://github.com/chromiumembedded/cef/issues/3685
+    settings.chrome_runtime =
+        !command_line->HasSwitch("disable-chrome-runtime");
 
     // When generating projects with CMake the CEF_USE_SANDBOX value will be
     // defined automatically. Pass -DUSE_SANDBOX=OFF to the CMake command-line
diff --git a/tests/cefsimple/cefsimple_win.cc b/tests/cefsimple/cefsimple_win.cc
index f036626e3..dfec6797b 100644
--- a/tests/cefsimple/cefsimple_win.cc
+++ b/tests/cefsimple/cefsimple_win.cc
@@ -74,13 +74,11 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
   // Specify CEF global settings here.
   CefSettings settings;
 
-  // Use the CEF Chrome runtime if "--enable-chrome-runtime" is specified via
-  // the command-line. Otherwise, use the CEF Alloy runtime. For more
-  // information about CEF runtimes see
-  // https://bitbucket.org/chromiumembedded/cef/wiki/Architecture.md#markdown-header-cef3
-  if (command_line->HasSwitch("enable-chrome-runtime")) {
-    settings.chrome_runtime = true;
-  }
+  // Use the CEF Chrome bootstrap unless "--disable-chrome-runtime" is specified
+  // via the command-line. Otherwise, use the CEF Alloy bootstrap. The Alloy
+  // bootstrap is deprecated and will be removed in ~M127. See
+  // https://github.com/chromiumembedded/cef/issues/3685
+  settings.chrome_runtime = !command_line->HasSwitch("disable-chrome-runtime");
 
 #if !defined(CEF_USE_SANDBOX)
   settings.no_sandbox = true;
diff --git a/tests/cefsimple/simple_app.cc b/tests/cefsimple/simple_app.cc
index d7a608380..88926b3f0 100644
--- a/tests/cefsimple/simple_app.cc
+++ b/tests/cefsimple/simple_app.cc
@@ -113,11 +113,14 @@ void SimpleApp::OnContextInitialized() {
   CefRefPtr<CefCommandLine> command_line =
       CefCommandLine::GetGlobalCommandLine();
 
+  const bool enable_chrome_runtime =
+      !command_line->HasSwitch("disable-chrome-runtime");
+
   // Check if Alloy style will be used. Alloy style is always used with the
   // Alloy runtime bootstrap and optional with the Chrome runtime bootstrap.
   bool use_alloy_style = true;
   cef_runtime_style_t runtime_style = CEF_RUNTIME_STYLE_DEFAULT;
-  if (command_line->HasSwitch("enable-chrome-runtime")) {
+  if (enable_chrome_runtime) {
     use_alloy_style = command_line->HasSwitch("use-alloy-style");
     if (use_alloy_style) {
       runtime_style = CEF_RUNTIME_STYLE_ALLOY;
@@ -139,10 +142,16 @@ void SimpleApp::OnContextInitialized() {
     url = "http://www.google.com";
   }
 
-  // Create the browser using the Views framework if "--use-views" is specified
-  // via the command-line. Otherwise, create the browser using the native
-  // platform framework.
-  if (command_line->HasSwitch("use-views")) {
+  // Views is enabled by default with the Chrome bootstrap (add `--use-native`
+  // to disable). Views is disabled by default with the Alloy bootstrap (add
+  // `--use-views` to enable).
+  const bool use_views =
+      (enable_chrome_runtime && !command_line->HasSwitch("use-native")) ||
+      (!enable_chrome_runtime && command_line->HasSwitch("use-views"));
+
+  // If using Views create the browser using the Views framework, otherwise
+  // create the browser using the native platform framework.
+  if (use_views) {
     // Create the BrowserView.
     CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
         handler, url, browser_settings, nullptr, nullptr,