Files
electron/shell/common/options_switches.h
T
Samuel AttardandClaude 0edcdc47c0 feat: add app shims on macOS (#54932)
* feat: add app shims on macOS

An app shim is a small app, in a bundle of its own, that shows windows on
behalf of a host Electron app. The host still creates each window, loads
its page and handles its events, but the NSWindow belongs to the shim's
process, so the Dock, the app switcher, Mission Control and Stage Manager
attribute the window to the shim and not to the host.

- `app.startAppShimServer()` / `app.stopAppShimServer()` and the
  `app-shim-connected` event, which hands over an `AppShimHost`.
- A `BaseWindow` / `BrowserWindow` created with the `appShim` option has
  its native window made in that shim's process, through Chromium's
  remote_cocoa. Such a window is a new NativeWindow implementation that
  only goes through views::Widget; what remote_cocoa has no call for is
  a no-op (see docs/api/app-shim-host.md).
- The shim's executable is `Helpers/app_shim_loader` from the framework
  bundle. It links nothing from Electron: it loads the host's framework
  and calls the new `ElectronAppShimMain` export, which runs an
  `app-shim` process that connects back to the host over a Mach
  bootstrap server.
- Electron Framework gains an rpath to the folder it is in, so that it
  finds its sibling frameworks when an executable in another bundle
  loads it.

Not available in Mac App Store builds.

Co-Authored-By: Claude <noreply@anthropic.com>

* feat: app shim menus, dialogs, window chrome and review fixes

Follow-up to the first app shim commit.

Fixes from review:
- A window torn down from one of its own listeners (shim.quit() or
  win.destroy() in `show`) no longer frees the native host that is
  notifying.
- The native close button no longer leaves the shim waiting on an answer
  that was dropped with the window.
- Keys the page does not handle go back to the shim, whose menu they are
  shortcuts of, and not to the host's menu.
- stopAppShimServer() drops shims that have connected and not said hello.
- Quitting a shim asks the host without blocking and without cancelling a
  logout; quit-requested can now be answered with "no".
- Size limits and useContentSize are in content sizes; restore() and
  unmaximize() each do one thing; webContents.isFocused() works.

New:
- shim.setMenu(): a menu bar of the shim's own, built in the shim from a
  description of the Menu, with clicks sent back.
- Message boxes and open and save dialogs are sheets of the window in the
  shim's process.
- titleBarStyle, traffic light position and visibility, vibrancy, tabs and
  Quick Look, applied in the shim to the NSWindow that remote_cocoa made.
- A Chromium patch for what remote_cocoa has no call for: movable,
  closable, minimizable and fullscreenable, clearing an aspect ratio, and
  yielding activation to the hosting process by pid.
- A shim that loaded another build of Electron than the running host
  tells the host and quits: app-shim-version-mismatch.

The API is marked experimental in the docs.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: address review of app shims

- A window in an app shim can't be given a parent, at construction or
  with setParentWindow(), as the docs say.
- shim.setMenu() is now shim.setApplicationMenu().
- A message box that is showing under an id makes way for a new one with
  that id, whichever process shows it.
- Mac App Store builds no longer export the shim's entry point; they
  already had no loader.
- setProgressBar() and setHasShadow() are listed among what does nothing
  on a window in a shim.
- The spec no longer asserts inside an event listener.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: clang-tidy findings in app shim code

* docs: reword the app shim docs for clarity

* chore: update patches

Re-exported after rebasing onto Chromium 158.0.8105.0; only line offsets
changed.

Co-Authored-By: Claude <noreply@anthropic.com>

* test: use vitest matchers in the app shim spec

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-16 14:03:19 -07:00

343 lines
12 KiB
C++

// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_COMMON_OPTIONS_SWITCHES_H_
#define ELECTRON_SHELL_COMMON_OPTIONS_SWITCHES_H_
#include <string_view>
#include "base/strings/cstring_view.h"
namespace electron {
namespace options {
inline constexpr std::string_view kTitle = "title";
inline constexpr std::string_view kAppShim = "appShim";
inline constexpr std::string_view kIcon = "icon";
inline constexpr std::string_view kFrame = "frame";
inline constexpr std::string_view kShow = "show";
inline constexpr std::string_view kCenter = "center";
inline constexpr std::string_view kX = "x";
inline constexpr std::string_view kY = "y";
inline constexpr std::string_view kWidth = "width";
inline constexpr std::string_view kHeight = "height";
inline constexpr std::string_view kMinWidth = "minWidth";
inline constexpr std::string_view kMinHeight = "minHeight";
inline constexpr std::string_view kMaxWidth = "maxWidth";
inline constexpr std::string_view kMaxHeight = "maxHeight";
inline constexpr std::string_view kinnerWidth = "innerWidth";
inline constexpr std::string_view kinnerHeight = "innerHeight";
inline constexpr std::string_view kResizable = "resizable";
inline constexpr std::string_view kMovable = "movable";
inline constexpr std::string_view kMinimizable = "minimizable";
inline constexpr std::string_view kMaximizable = "maximizable";
inline constexpr std::string_view kFullScreenable = "fullscreenable";
inline constexpr std::string_view kClosable = "closable";
// Whether to paint when the window is initially hidden.
inline constexpr std::string_view kPaintWhenInitiallyHidden =
"paintWhenInitiallyHidden";
// whether to keep the window out of mission control
inline constexpr std::string_view kHiddenInMissionControl =
"hiddenInMissionControl";
inline constexpr std::string_view kFullscreen = "fullscreen";
// Whether the window should show in taskbar.
inline constexpr std::string_view kSkipTaskbar = "skipTaskbar";
// Start with the kiosk mode, see Opera's page for description:
// http://www.opera.com/support/mastering/kiosk/
inline constexpr std::string_view kKiosk = "kiosk";
inline constexpr std::string_view kSimpleFullscreen = "simpleFullscreen";
// Make windows stays on the top of all other windows.
inline constexpr std::string_view kAlwaysOnTop = "alwaysOnTop";
// Enable the NSView to accept first mouse event.
inline constexpr std::string_view kAcceptFirstMouse = "acceptFirstMouse";
// Whether window size should include window frame.
inline constexpr std::string_view kUseContentSize = "useContentSize";
// Whether window zoom should be to page width.
inline constexpr std::string_view kZoomToPageWidth = "zoomToPageWidth";
// The requested title bar style for the window
inline constexpr std::string_view kTitleBarStyle = "titleBarStyle";
// Tabbing identifier for the window if native tabs are enabled on macOS.
inline constexpr std::string_view kTabbingIdentifier = "tabbingIdentifier";
// The menu bar is hidden unless "Alt" is pressed.
inline constexpr std::string_view kAutoHideMenuBar = "autoHideMenuBar";
// Enable window to be resized larger than screen.
inline constexpr std::string_view kEnableLargerThanScreen =
"enableLargerThanScreen";
// Forces to use dark theme on Linux.
inline constexpr std::string_view kDarkTheme = "darkTheme";
// Whether the window should be transparent.
inline constexpr std::string_view kTransparent = "transparent";
// Window type hint.
inline constexpr std::string_view kType = "type";
// Disable auto-hiding cursor.
inline constexpr std::string_view kDisableAutoHideCursor =
"disableAutoHideCursor";
// Default browser window background color.
inline constexpr std::string_view kBackgroundColor = "backgroundColor";
// Whether the window should have a shadow.
inline constexpr std::string_view kHasShadow = "hasShadow";
// Browser window opacity
inline constexpr std::string_view kOpacity = "opacity";
// Whether the window can be activated.
inline constexpr std::string_view kFocusable = "focusable";
// The WebPreferences.
inline constexpr std::string_view kWebPreferences = "webPreferences";
// Window state persistence for BaseWindow
inline constexpr std::string_view kWindowStatePersistence =
"windowStatePersistence";
// Identifier for the window provided by the application
inline constexpr std::string_view kName = "name";
// Whether to save the window bounds
inline constexpr std::string_view kBounds = "bounds";
// Whether to save the window display mode
inline constexpr std::string_view kDisplayMode = "displayMode";
// Add a vibrancy effect to the browser window
inline constexpr std::string_view kVibrancyType = "vibrancy";
// Add a vibrancy effect to the browser window.
inline constexpr std::string_view kBackgroundMaterial = "backgroundMaterial";
// Specify how the material appearance should reflect window activity state on
// macOS.
inline constexpr std::string_view kVisualEffectState = "visualEffectState";
inline constexpr std::string_view kTrafficLightPosition =
"trafficLightPosition";
inline constexpr std::string_view kRoundedCorners = "roundedCorners";
inline constexpr std::string_view ktitleBarOverlay = "titleBarOverlay";
inline constexpr std::string_view kAccentColor = "accentColor";
// The color to use as the theme and symbol colors respectively for Window
// Controls Overlay if enabled on Windows.
inline constexpr std::string_view kOverlayButtonColor = "color";
inline constexpr std::string_view kOverlaySymbolColor = "symbolColor";
// The custom height for Window Controls Overlay.
inline constexpr std::string_view kOverlayHeight = "height";
/// WebPreferences.
// The factor of which page should be zoomed.
inline constexpr std::string_view kZoomFactor = "zoomFactor";
// The zoom mode for the web contents.
inline constexpr std::string_view kZoomMode = "zoomMode";
// Script that will be loaded by guest WebContents before other scripts.
inline constexpr std::string_view kPreloadScript = "preload";
// Enable the node integration.
inline constexpr std::string_view kNodeIntegration = "nodeIntegration";
// Enable context isolation of Electron APIs and preload script
inline constexpr std::string_view kContextIsolation = "contextIsolation";
// Web runtime features.
inline constexpr std::string_view kExperimentalFeatures =
"experimentalFeatures";
// Enable the rubber banding effect.
inline constexpr std::string_view kScrollBounce = "scrollBounce";
// Enable blink features.
inline constexpr std::string_view kEnableBlinkFeatures = "enableBlinkFeatures";
// Disable blink features.
inline constexpr std::string_view kDisableBlinkFeatures =
"disableBlinkFeatures";
// Enable the node integration in WebWorker.
inline constexpr std::string_view kNodeIntegrationInWorker =
"nodeIntegrationInWorker";
// Enable the web view tag.
inline constexpr std::string_view kWebviewTag = "webviewTag";
inline constexpr std::string_view kCustomArgs = "additionalArguments";
inline constexpr std::string_view kPlugins = "plugins";
inline constexpr std::string_view kSandbox = "sandbox";
inline constexpr std::string_view kWebSecurity = "webSecurity";
inline constexpr std::string_view kAllowRunningInsecureContent =
"allowRunningInsecureContent";
inline constexpr std::string_view kOffscreen = "offscreen";
inline constexpr std::string_view kUseSharedTexture = "useSharedTexture";
inline constexpr std::string_view kSharedTexturePixelFormat =
"sharedTexturePixelFormat";
inline constexpr std::string_view kDeviceScaleFactor = "deviceScaleFactor";
inline constexpr std::string_view kNodeIntegrationInSubFrames =
"nodeIntegrationInSubFrames";
// Disable window resizing when HTML Fullscreen API is activated.
inline constexpr std::string_view kDisableHtmlFullscreenWindowResize =
"disableHtmlFullscreenWindowResize";
// Enables JavaScript support.
inline constexpr std::string_view kJavaScript = "javascript";
// Enables image support.
inline constexpr std::string_view kImages = "images";
// Make TextArea elements resizable.
inline constexpr std::string_view kTextAreasAreResizable =
"textAreasAreResizable";
// Enables WebGL support.
inline constexpr std::string_view kWebGL = "webgl";
// Whether dragging and dropping a file or link onto the page causes a
// navigation.
inline constexpr std::string_view kNavigateOnDragDrop = "navigateOnDragDrop";
inline constexpr std::string_view kEnablePreferredSizeMode =
"enablePreferredSizeMode";
inline constexpr std::string_view kHiddenPage = "hiddenPage";
inline constexpr std::string_view kSpellcheck = "spellcheck";
// Enables the permission managed support for
// document.execCommand("paste").
inline constexpr std::string_view kEnableDeprecatedPaste =
"enableDeprecatedPaste";
// Whether to focus the webContents on navigation.
inline constexpr std::string_view kFocusOnNavigation = "focusOnNavigation";
// Whether to disable the wake lock for this WebContents
inline constexpr std::string_view kDisableWakeLocks = "disableWakeLocks";
inline constexpr std::string_view kModal = "modal";
} // namespace options
// Following are actually command line switches, should be moved to other files.
namespace switches {
// Implementation detail: base::cstring_view used for switches because
// base::CommandLine::CopySwitchesFrom() still needs C-style strings.
// These constants can migrate to std::string_view if that function does.
// Enable chromium sandbox.
inline constexpr base::cstring_view kEnableSandbox = "enable-sandbox";
// Disable HTTP cache.
inline constexpr base::cstring_view kDisableHttpCache = "disable-http-cache";
// The list of standard schemes.
inline constexpr base::cstring_view kStandardSchemes = "standard-schemes";
// Register schemes to handle service worker.
inline constexpr base::cstring_view kServiceWorkerSchemes =
"service-worker-schemes";
// Register schemes as secure.
inline constexpr base::cstring_view kSecureSchemes = "secure-schemes";
// Register schemes as bypassing CSP.
inline constexpr base::cstring_view kBypassCSPSchemes = "bypasscsp-schemes";
// Register schemes as support fetch API.
inline constexpr base::cstring_view kFetchSchemes = "fetch-schemes";
// Register schemes as CORS enabled.
inline constexpr base::cstring_view kCORSSchemes = "cors-schemes";
// Register schemes as streaming responses.
inline constexpr base::cstring_view kStreamingSchemes = "streaming-schemes";
// Register schemes as supporting V8 code cache.
inline constexpr base::cstring_view kCodeCacheSchemes = "code-cache-schemes";
// Register schemes as supporting extensions.
inline constexpr base::cstring_view kExtensionSchemes = "extension-schemes";
// The browser process app model ID
inline constexpr base::cstring_view kAppUserModelId = "app-user-model-id";
// The application path
inline constexpr base::cstring_view kAppPath = "app-path";
// The command line switch versions of the options.
inline constexpr base::cstring_view kScrollBounce = "scroll-bounce";
// Widevine options
// Path to Widevine CDM binaries.
inline constexpr base::cstring_view kWidevineCdmPath = "widevine-cdm-path";
// Widevine CDM version.
inline constexpr base::cstring_view kWidevineCdmVersion =
"widevine-cdm-version";
// Forces the maximum disk space to be used by the disk cache, in bytes.
inline constexpr base::cstring_view kDiskCacheSize = "disk-cache-size";
// Ignore the limit of 6 connections per host.
inline constexpr base::cstring_view kIgnoreConnectionsLimit =
"ignore-connections-limit";
// Whitelist containing servers for which Integrated Authentication is enabled.
inline constexpr base::cstring_view kAuthServerWhitelist =
"auth-server-whitelist";
// Whitelist containing servers for which Kerberos delegation is allowed.
inline constexpr base::cstring_view kAuthNegotiateDelegateWhitelist =
"auth-negotiate-delegate-whitelist";
// If set, include the port in generated Kerberos SPNs.
inline constexpr base::cstring_view kEnableAuthNegotiatePort =
"enable-auth-negotiate-port";
// If set, NTLM v2 is disabled for POSIX platforms.
inline constexpr base::cstring_view kDisableNTLMv2 = "disable-ntlm-v2";
// If set, flag node::ProcessInitializationFlags::kNoStdioInitialization would
// be set for node initialization.
inline constexpr base::cstring_view kNoStdioInit = "no-stdio-init";
} // namespace switches
} // namespace electron
#endif // ELECTRON_SHELL_COMMON_OPTIONS_SWITCHES_H_