From f5bdbdb1e84e029028fb4d55714e40166ceab5ee Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 4 Nov 2024 12:27:49 -0600 Subject: [PATCH] refactor: more inline constexpr string view (#44498) * chore: remove unused electron::kHidProductIdKey * refactor: make electron::kHidDeviceNameKey inline constexpr std::string_view refactor: make electron::kHidGuidKey inline constexpr std::string_view * refactor: make serial_chooser_context keys inline constexpr std::string_view * refactor: make native_window keys inline constexpr std::string_view * refactor: make electron::options keys inline constexpr std::string_view pt 1 * fixup! refactor: make electron::options keys inline constexpr std::string_view pt 1 chore: make kElectronNativeWindowKey a base::cstring_view ui::Widget::GetNativeWindowProperty requires a const char* * refactor: make electron::options keys inline constexpr std::string_view pt 2 * refactor: make electron::options keys inline constexpr std::string_view pt 3 * refactor: make electron::options keys inline constexpr std::string_view pt 4 * refactor: make electron::options keys inline constexpr std::string_view pt 5 * refactor: make electron::options keys inline constexpr std::string_view pt 6 * refactor: make electron::options keys inline constexpr std::string_view pt 7 * refactor: make electron::options keys inline constexpr std::string_view pt 8 * chore: remove unused file shell/common/options_switches.cc * docs: add code comment explaining use of base::cstring_view * fixup! fixup! refactor: make electron::options keys inline constexpr std::string_view pt 1 * chore: use consistent capitalization of the word 'fullscreen' --- filenames.gni | 1 - shell/browser/api/electron_api_protocol.cc | 2 +- .../api/electron_api_web_contents_view.cc | 7 +- shell/browser/electron_browser_client.cc | 16 +- shell/browser/hid/hid_chooser_context.cc | 3 - shell/browser/hid/hid_chooser_context.h | 6 +- shell/browser/native_window.cc | 2 - shell/browser/native_window.h | 5 +- shell/browser/native_window_mac.mm | 4 +- shell/browser/native_window_views.cc | 2 +- .../browser/serial/serial_chooser_context.cc | 14 - shell/browser/serial/serial_chooser_context.h | 19 +- shell/common/options_switches.cc | 263 ------------- shell/common/options_switches.h | 368 +++++++++++++----- shell/renderer/renderer_client_base.cc | 5 +- 15 files changed, 305 insertions(+), 412 deletions(-) delete mode 100644 shell/common/options_switches.cc diff --git a/filenames.gni b/filenames.gni index 039f60c9ac09..cdfbac8b434e 100644 --- a/filenames.gni +++ b/filenames.gni @@ -675,7 +675,6 @@ filenames = { "shell/common/node_includes.h", "shell/common/node_util.cc", "shell/common/node_util.h", - "shell/common/options_switches.cc", "shell/common/options_switches.h", "shell/common/platform_util.cc", "shell/common/platform_util.h", diff --git a/shell/browser/api/electron_api_protocol.cc b/shell/browser/api/electron_api_protocol.cc index 896570a40267..fdbea2c84831 100644 --- a/shell/browser/api/electron_api_protocol.cc +++ b/shell/browser/api/electron_api_protocol.cc @@ -162,7 +162,7 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower, } } - const auto AppendSchemesToCmdLine = [](const char* switch_name, + const auto AppendSchemesToCmdLine = [](const std::string_view switch_name, std::vector schemes) { if (schemes.empty()) return; diff --git a/shell/browser/api/electron_api_web_contents_view.cc b/shell/browser/api/electron_api_web_contents_view.cc index 639fdecf7701..6bc59fd7b69d 100644 --- a/shell/browser/api/electron_api_web_contents_view.cc +++ b/shell/browser/api/electron_api_web_contents_view.cc @@ -115,8 +115,9 @@ void WebContentsView::WebContentsDestroyed() { void WebContentsView::OnViewAddedToWidget(views::View* observed_view) { DCHECK_EQ(observed_view, view()); views::Widget* widget = view()->GetWidget(); - auto* native_window = static_cast( - widget->GetNativeWindowProperty(electron::kElectronNativeWindowKey)); + auto* native_window = + static_cast(widget->GetNativeWindowProperty( + electron::kElectronNativeWindowKey.c_str())); if (!native_window) return; // We don't need to call SetOwnerWindow(nullptr) in OnViewRemovedFromWidget @@ -130,7 +131,7 @@ void WebContentsView::OnViewRemovedFromWidget(views::View* observed_view) { DCHECK_EQ(observed_view, view()); views::Widget* widget = view()->GetWidget(); auto* native_window = static_cast( - widget->GetNativeWindowProperty(kElectronNativeWindowKey)); + widget->GetNativeWindowProperty(kElectronNativeWindowKey.c_str())); if (!native_window) return; native_window->RemoveDraggableRegionProvider(this); diff --git a/shell/browser/electron_browser_client.cc b/shell/browser/electron_browser_client.cc index f56fc8ac1087..482bfe5e9984 100644 --- a/shell/browser/electron_browser_client.cc +++ b/shell/browser/electron_browser_client.cc @@ -532,12 +532,16 @@ void ElectronBrowserClient::AppendExtraCommandLineSwitches( if (process_type == ::switches::kUtilityProcess || process_type == ::switches::kRendererProcess) { // Copy following switches to child process. - static const char* const kCommonSwitchNames[] = { - switches::kStandardSchemes, switches::kEnableSandbox, - switches::kSecureSchemes, switches::kBypassCSPSchemes, - switches::kCORSSchemes, switches::kFetchSchemes, - switches::kServiceWorkerSchemes, switches::kStreamingSchemes, - switches::kCodeCacheSchemes}; + static constexpr std::array kCommonSwitchNames = { + switches::kStandardSchemes.c_str(), + switches::kEnableSandbox.c_str(), + switches::kSecureSchemes.c_str(), + switches::kBypassCSPSchemes.c_str(), + switches::kCORSSchemes.c_str(), + switches::kFetchSchemes.c_str(), + switches::kServiceWorkerSchemes.c_str(), + switches::kStreamingSchemes.c_str(), + switches::kCodeCacheSchemes.c_str()}; command_line->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(), kCommonSwitchNames); if (process_type == ::switches::kUtilityProcess || diff --git a/shell/browser/hid/hid_chooser_context.cc b/shell/browser/hid/hid_chooser_context.cc index fa52c2f452fe..27c196e149ff 100644 --- a/shell/browser/hid/hid_chooser_context.cc +++ b/shell/browser/hid/hid_chooser_context.cc @@ -39,9 +39,6 @@ namespace electron { -const char kHidDeviceNameKey[] = "name"; -const char kHidGuidKey[] = "guid"; - HidChooserContext::HidChooserContext(ElectronBrowserContext* context) : browser_context_(context) {} diff --git a/shell/browser/hid/hid_chooser_context.h b/shell/browser/hid/hid_chooser_context.h index a9852961b4e0..1f3892934a47 100644 --- a/shell/browser/hid/hid_chooser_context.h +++ b/shell/browser/hid/hid_chooser_context.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "base/containers/queue.h" @@ -35,9 +36,8 @@ namespace electron { class ElectronBrowserContext; -extern const char kHidDeviceNameKey[]; -extern const char kHidGuidKey[]; -extern const char kHidProductIdKey[]; +inline constexpr std::string_view kHidDeviceNameKey = "name"; +inline constexpr std::string_view kHidGuidKey = "guid"; // Manages the internal state and connection to the device service for the // Human Interface Device (HID) chooser UI. diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index 625bfb831401..d1d46bd99b85 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -91,8 +91,6 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) { } // namespace -const char kElectronNativeWindowKey[] = "__ELECTRON_NATIVE_WINDOW__"; - NativeWindow::NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent) : widget_(std::make_unique()), parent_(parent) { diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index 6f521722e59f..b89123a10641 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -10,11 +10,13 @@ #include #include #include +#include #include #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" +#include "base/strings/cstring_view.h" #include "base/supports_user_data.h" #include "content/public/browser/desktop_media_id.h" #include "content/public/browser/web_contents_user_data.h" @@ -44,7 +46,8 @@ class PersistentDictionary; namespace electron { -extern const char kElectronNativeWindowKey[]; +inline constexpr base::cstring_view kElectronNativeWindowKey = + "__ELECTRON_NATIVE_WINDOW__"; class ElectronMenuModel; class BackgroundThrottlingSource; diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 45eef7e744f8..af548f4261bd 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -132,7 +132,7 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options, bool resizable = true; options.Get(options::kResizable, &resizable); options.Get(options::kZoomToPageWidth, &zoom_to_page_width_); - options.Get(options::kSimpleFullScreen, &always_simple_fullscreen_); + options.Get(options::kSimpleFullscreen, &always_simple_fullscreen_); options.GetOptional(options::kTrafficLightPosition, &traffic_light_position_); options.Get(options::kVisualEffectState, &visual_effect_state_); @@ -203,7 +203,7 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options, params.native_widget = new ElectronNativeWidgetMac(this, windowType, styleMask, widget()); widget()->Init(std::move(params)); - widget()->SetNativeWindowProperty(kElectronNativeWindowKey, this); + widget()->SetNativeWindowProperty(kElectronNativeWindowKey.c_str(), this); SetCanResize(resizable); window_ = static_cast( widget()->GetNativeWindow().GetNativeNSWindow()); diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 12617c1db777..1d2d8a3da4e3 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -310,7 +310,7 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, #endif widget()->Init(std::move(params)); - widget()->SetNativeWindowProperty(kElectronNativeWindowKey, this); + widget()->SetNativeWindowProperty(kElectronNativeWindowKey.c_str(), this); SetCanResize(resizable_); bool fullscreen = false; diff --git a/shell/browser/serial/serial_chooser_context.cc b/shell/browser/serial/serial_chooser_context.cc index c082d4f5f593..9d30e96f21ec 100644 --- a/shell/browser/serial/serial_chooser_context.cc +++ b/shell/browser/serial/serial_chooser_context.cc @@ -23,20 +23,6 @@ namespace electron { -constexpr char kPortNameKey[] = "name"; -constexpr char kTokenKey[] = "token"; -constexpr char kBluetoothDevicePathKey[] = "bluetooth_device_path"; -#if BUILDFLAG(IS_WIN) -constexpr char kDeviceInstanceIdKey[] = "device_instance_id"; -#else -constexpr char kVendorIdKey[] = "vendor_id"; -constexpr char kProductIdKey[] = "product_id"; -constexpr char kSerialNumberKey[] = "serial_number"; -#if BUILDFLAG(IS_MAC) -constexpr char kUsbDriverKey[] = "usb_driver"; -#endif // BUILDFLAG(IS_MAC) -#endif // BUILDFLAG(IS_WIN) - namespace { std::string EncodeToken(const base::UnguessableToken& token) { diff --git a/shell/browser/serial/serial_chooser_context.h b/shell/browser/serial/serial_chooser_context.h index 59eb98f4eefc..0dbeb15dc81f 100644 --- a/shell/browser/serial/serial_chooser_context.h +++ b/shell/browser/serial/serial_chooser_context.h @@ -7,6 +7,7 @@ #include #include +#include #include #include "base/memory/raw_ptr.h" @@ -35,16 +36,20 @@ namespace electron { class ElectronBrowserContext; +inline constexpr std::string_view kPortNameKey = "name"; +inline constexpr std::string_view kTokenKey = "token"; +inline constexpr std::string_view kBluetoothDevicePathKey = + "bluetooth_device_path"; #if BUILDFLAG(IS_WIN) -extern const char kDeviceInstanceIdKey[]; +inline constexpr std::string_view kDeviceInstanceIdKey = "device_instance_id"; #else -extern const char kVendorIdKey[]; -extern const char kProductIdKey[]; -extern const char kSerialNumberKey[]; -#if BUILDFLAG(IS_MAC) -extern const char kUsbDriverKey[]; -#endif // BUILDFLAG(IS_MAC) +inline constexpr std::string_view kVendorIdKey = "vendor_id"; +inline constexpr std::string_view kProductIdKey = "product_id"; +inline constexpr std::string_view kSerialNumberKey = "serial_number"; #endif // BUILDFLAG(IS_WIN) +#if BUILDFLAG(IS_MAC) +inline constexpr std::string_view kUsbDriverKey = "usb_driver"; +#endif // BUILDFLAG(IS_MAC) class SerialChooserContext : public KeyedService, public device::mojom::SerialPortManagerClient { diff --git a/shell/common/options_switches.cc b/shell/common/options_switches.cc deleted file mode 100644 index 918d5faf369c..000000000000 --- a/shell/common/options_switches.cc +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright (c) 2013 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "shell/common/options_switches.h" - -namespace electron { - -namespace options { - -const char kTitle[] = "title"; -const char kIcon[] = "icon"; -const char kFrame[] = "frame"; -const char kShow[] = "show"; -const char kCenter[] = "center"; -const char kX[] = "x"; -const char kY[] = "y"; -const char kWidth[] = "width"; -const char kHeight[] = "height"; -const char kMinWidth[] = "minWidth"; -const char kMinHeight[] = "minHeight"; -const char kMaxWidth[] = "maxWidth"; -const char kMaxHeight[] = "maxHeight"; -const char kResizable[] = "resizable"; -const char kMovable[] = "movable"; -const char kMinimizable[] = "minimizable"; -const char kMaximizable[] = "maximizable"; -const char kFullScreenable[] = "fullscreenable"; -const char kClosable[] = "closable"; -const char kFullscreen[] = "fullscreen"; -const char kTrafficLightPosition[] = "trafficLightPosition"; -const char kRoundedCorners[] = "roundedCorners"; - -// The color to use as the theme and symbol colors respectively for Window -// Controls Overlay if enabled on Windows. -const char kOverlayButtonColor[] = "color"; -const char kOverlaySymbolColor[] = "symbolColor"; - -// The custom height for Window Controls Overlay. -const char kOverlayHeight[] = "height"; - -// whether to keep the window out of mission control -const char kHiddenInMissionControl[] = "hiddenInMissionControl"; -// Whether the window should show in taskbar. -const char kSkipTaskbar[] = "skipTaskbar"; - -// Start with the kiosk mode, see Opera's page for description: -// http://www.opera.com/support/mastering/kiosk/ -const char kKiosk[] = "kiosk"; - -const char kSimpleFullScreen[] = "simpleFullscreen"; - -// Make windows stays on the top of all other windows. -const char kAlwaysOnTop[] = "alwaysOnTop"; - -// Enable the NSView to accept first mouse event. -const char kAcceptFirstMouse[] = "acceptFirstMouse"; - -// Whether window size should include window frame. -const char kUseContentSize[] = "useContentSize"; - -// Whether window zoom should be to page width. -const char kZoomToPageWidth[] = "zoomToPageWidth"; - -// The requested title bar style for the window -const char kTitleBarStyle[] = "titleBarStyle"; - -// Tabbing identifier for the window if native tabs are enabled on macOS. -const char kTabbingIdentifier[] = "tabbingIdentifier"; - -// The menu bar is hidden unless "Alt" is pressed. -const char kAutoHideMenuBar[] = "autoHideMenuBar"; - -// Enable window to be resized larger than screen. -const char kEnableLargerThanScreen[] = "enableLargerThanScreen"; - -// Forces to use dark theme on Linux. -const char kDarkTheme[] = "darkTheme"; - -// Whether the window should be transparent. -const char kTransparent[] = "transparent"; - -// Window type hint. -const char kType[] = "type"; - -// Disable auto-hiding cursor. -const char kDisableAutoHideCursor[] = "disableAutoHideCursor"; - -// Default browser window background color. -const char kBackgroundColor[] = "backgroundColor"; - -// Whether the window should have a shadow. -const char kHasShadow[] = "hasShadow"; - -// Browser window opacity -const char kOpacity[] = "opacity"; - -// Whether the window can be activated. -const char kFocusable[] = "focusable"; - -// The WebPreferences. -const char kWebPreferences[] = "webPreferences"; - -// Add a vibrancy effect to the browser window -const char kVibrancyType[] = "vibrancy"; - -// Add a vibrancy effect to the browser window. -const char kBackgroundMaterial[] = "backgroundMaterial"; - -// Specify how the material appearance should reflect window activity state on -// macOS. -const char kVisualEffectState[] = "visualEffectState"; - -// The factor of which page should be zoomed. -const char kZoomFactor[] = "zoomFactor"; - -// Script that will be loaded by guest WebContents before other scripts. -const char kPreloadScript[] = "preload"; - -// Enable the node integration. -const char kNodeIntegration[] = "nodeIntegration"; - -// Enable context isolation of Electron APIs and preload script -const char kContextIsolation[] = "contextIsolation"; - -// Web runtime features. -const char kExperimentalFeatures[] = "experimentalFeatures"; - -// Enable the rubber banding effect. -const char kScrollBounce[] = "scrollBounce"; - -// Enable blink features. -const char kEnableBlinkFeatures[] = "enableBlinkFeatures"; - -// Disable blink features. -const char kDisableBlinkFeatures[] = "disableBlinkFeatures"; - -// Enable the node integration in WebWorker. -const char kNodeIntegrationInWorker[] = "nodeIntegrationInWorker"; - -// Enable the web view tag. -const char kWebviewTag[] = "webviewTag"; - -const char kCustomArgs[] = "additionalArguments"; - -const char kPlugins[] = "plugins"; - -const char kSandbox[] = "sandbox"; - -const char kWebSecurity[] = "webSecurity"; - -const char kAllowRunningInsecureContent[] = "allowRunningInsecureContent"; - -const char kOffscreen[] = "offscreen"; - -const char kUseSharedTexture[] = "useSharedTexture"; - -const char kNodeIntegrationInSubFrames[] = "nodeIntegrationInSubFrames"; - -// Disable window resizing when HTML Fullscreen API is activated. -const char kDisableHtmlFullscreenWindowResize[] = - "disableHtmlFullscreenWindowResize"; - -// Enables JavaScript support. -const char kJavaScript[] = "javascript"; - -// Enables image support. -const char kImages[] = "images"; - -// Make TextArea elements resizable. -const char kTextAreasAreResizable[] = "textAreasAreResizable"; - -// Enables WebGL support. -const char kWebGL[] = "webgl"; - -// Whether dragging and dropping a file or link onto the page causes a -// navigation. -const char kNavigateOnDragDrop[] = "navigateOnDragDrop"; - -const char kHiddenPage[] = "hiddenPage"; - -#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) -const char kSpellcheck[] = "spellcheck"; -#endif - -const char kEnablePreferredSizeMode[] = "enablePreferredSizeMode"; - -const char ktitleBarOverlay[] = "titleBarOverlay"; - -} // namespace options - -namespace switches { - -// Enable chromium sandbox. -const char kEnableSandbox[] = "enable-sandbox"; - -// Disable HTTP cache. -const char kDisableHttpCache[] = "disable-http-cache"; - -// The list of standard schemes. -const char kStandardSchemes[] = "standard-schemes"; - -// Register schemes to handle service worker. -const char kServiceWorkerSchemes[] = "service-worker-schemes"; - -// Register schemes as secure. -const char kSecureSchemes[] = "secure-schemes"; - -// Register schemes as bypassing CSP. -const char kBypassCSPSchemes[] = "bypasscsp-schemes"; - -// Register schemes as support fetch API. -const char kFetchSchemes[] = "fetch-schemes"; - -// Register schemes as CORS enabled. -const char kCORSSchemes[] = "cors-schemes"; - -// Register schemes as streaming responses. -const char kStreamingSchemes[] = "streaming-schemes"; - -// Register schemes as supporting V8 code cache. -const char kCodeCacheSchemes[] = "code-cache-schemes"; - -// The browser process app model ID -const char kAppUserModelId[] = "app-user-model-id"; - -// The application path -const char kAppPath[] = "app-path"; - -// The command line switch versions of the options. -const char kScrollBounce[] = "scroll-bounce"; - -// Command switch passed to renderer process to control nodeIntegration. -const char kNodeIntegrationInWorker[] = "node-integration-in-worker"; - -// Widevine options -// Path to Widevine CDM binaries. -const char kWidevineCdmPath[] = "widevine-cdm-path"; -// Widevine CDM version. -const char kWidevineCdmVersion[] = "widevine-cdm-version"; - -// Forces the maximum disk space to be used by the disk cache, in bytes. -const char kDiskCacheSize[] = "disk-cache-size"; - -// Ignore the limit of 6 connections per host. -const char kIgnoreConnectionsLimit[] = "ignore-connections-limit"; - -// Whitelist containing servers for which Integrated Authentication is enabled. -const char kAuthServerWhitelist[] = "auth-server-whitelist"; - -// Whitelist containing servers for which Kerberos delegation is allowed. -const char kAuthNegotiateDelegateWhitelist[] = - "auth-negotiate-delegate-whitelist"; - -// If set, include the port in generated Kerberos SPNs. -const char kEnableAuthNegotiatePort[] = "enable-auth-negotiate-port"; - -// If set, NTLM v2 is disabled for POSIX platforms. -const char kDisableNTLMv2[] = "disable-ntlm-v2"; - -} // namespace switches - -} // namespace electron diff --git a/shell/common/options_switches.h b/shell/common/options_switches.h index 6b99e9e79dc3..d6b95fb3c4d0 100644 --- a/shell/common/options_switches.h +++ b/shell/common/options_switches.h @@ -5,127 +5,289 @@ #ifndef ELECTRON_SHELL_COMMON_OPTIONS_SWITCHES_H_ #define ELECTRON_SHELL_COMMON_OPTIONS_SWITCHES_H_ -#include "electron/buildflags/buildflags.h" +#include + +#include "base/strings/cstring_view.h" namespace electron { namespace options { -extern const char kTitle[]; -extern const char kIcon[]; -extern const char kFrame[]; -extern const char kShow[]; -extern const char kCenter[]; -extern const char kX[]; -extern const char kY[]; -extern const char kWidth[]; -extern const char kHeight[]; -extern const char kMinWidth[]; -extern const char kMinHeight[]; -extern const char kMaxWidth[]; -extern const char kMaxHeight[]; -extern const char kResizable[]; -extern const char kMovable[]; -extern const char kMinimizable[]; -extern const char kMaximizable[]; -extern const char kFullScreenable[]; -extern const char kClosable[]; -extern const char kHiddenInMissionControl[]; -extern const char kFullscreen[]; -extern const char kSkipTaskbar[]; -extern const char kKiosk[]; -extern const char kSimpleFullScreen[]; -extern const char kAlwaysOnTop[]; -extern const char kAcceptFirstMouse[]; -extern const char kUseContentSize[]; -extern const char kZoomToPageWidth[]; -extern const char kTitleBarStyle[]; -extern const char kTabbingIdentifier[]; -extern const char kAutoHideMenuBar[]; -extern const char kEnableLargerThanScreen[]; -extern const char kDarkTheme[]; -extern const char kTransparent[]; -extern const char kType[]; -extern const char kDisableAutoHideCursor[]; -extern const char kBackgroundColor[]; -extern const char kHasShadow[]; -extern const char kOpacity[]; -extern const char kFocusable[]; -extern const char kWebPreferences[]; -extern const char kVibrancyType[]; -extern const char kBackgroundMaterial[]; -extern const char kVisualEffectState[]; -extern const char kTrafficLightPosition[]; -extern const char kRoundedCorners[]; -extern const char ktitleBarOverlay[]; -extern const char kOverlayButtonColor[]; -extern const char kOverlaySymbolColor[]; -extern const char kOverlayHeight[]; +inline constexpr std::string_view kTitle = "title"; +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 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"; -// WebPreferences. -extern const char kZoomFactor[]; -extern const char kPreloadScript[]; -extern const char kNodeIntegration[]; -extern const char kContextIsolation[]; -extern const char kExperimentalFeatures[]; -extern const char kScrollBounce[]; -extern const char kEnableBlinkFeatures[]; -extern const char kDisableBlinkFeatures[]; -extern const char kNodeIntegrationInWorker[]; -extern const char kWebviewTag[]; -extern const char kCustomArgs[]; -extern const char kPlugins[]; -extern const char kSandbox[]; -extern const char kWebSecurity[]; -extern const char kAllowRunningInsecureContent[]; -extern const char kOffscreen[]; -extern const char kUseSharedTexture[]; -extern const char kNodeIntegrationInSubFrames[]; -extern const char kDisableHtmlFullscreenWindowResize[]; -extern const char kJavaScript[]; -extern const char kImages[]; -extern const char kTextAreasAreResizable[]; -extern const char kWebGL[]; -extern const char kNavigateOnDragDrop[]; -extern const char kEnablePreferredSizeMode[]; +// whether to keep the window out of mission control +inline constexpr std::string_view kHiddenInMissionControl = + "hiddenInMissionControl"; -extern const char kHiddenPage[]; +inline constexpr std::string_view kFullscreen = "fullscreen"; -#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) -extern const char kSpellcheck[]; -#endif +// 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"; + +// 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"; + +// 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"; + +// 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 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"; } // namespace options // Following are actually command line switches, should be moved to other files. namespace switches { -extern const char kEnableSandbox[]; -extern const char kDisableHttpCache[]; -extern const char kStandardSchemes[]; -extern const char kServiceWorkerSchemes[]; -extern const char kSecureSchemes[]; -extern const char kBypassCSPSchemes[]; -extern const char kFetchSchemes[]; -extern const char kCORSSchemes[]; -extern const char kStreamingSchemes[]; -extern const char kCodeCacheSchemes[]; -extern const char kAppUserModelId[]; -extern const char kAppPath[]; +// 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. -extern const char kScrollBounce[]; -extern const char kNodeIntegrationInWorker[]; +// Enable chromium sandbox. +inline constexpr base::cstring_view kEnableSandbox = "enable-sandbox"; -extern const char kWidevineCdmPath[]; -extern const char kWidevineCdmVersion[]; +// 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"; + +// 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"; + +// Command switch passed to renderer process to control nodeIntegration. +inline constexpr base::cstring_view kNodeIntegrationInWorker = + "node-integration-in-worker"; + +// 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"; -extern const char kDiskCacheSize[]; -extern const char kIgnoreConnectionsLimit[]; -extern const char kAuthServerWhitelist[]; -extern const char kAuthNegotiateDelegateWhitelist[]; -extern const char kEnableAuthNegotiatePort[]; -extern const char kDisableNTLMv2[]; } // namespace switches } // namespace electron diff --git a/shell/renderer/renderer_client_base.cc b/shell/renderer/renderer_client_base.cc index 30d18c8d07cb..102a986c3a3a 100644 --- a/shell/renderer/renderer_client_base.cc +++ b/shell/renderer/renderer_client_base.cc @@ -112,8 +112,9 @@ void SetIsWebView(v8::Isolate* isolate, v8::Local object) { dict.SetHidden("isWebView", true); } -std::vector ParseSchemesCLISwitch(base::CommandLine* command_line, - const char* switch_name) { +std::vector ParseSchemesCLISwitch( + base::CommandLine* command_line, + const std::string_view switch_name) { std::string custom_schemes = command_line->GetSwitchValueASCII(switch_name); return base::SplitString(custom_schemes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);