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'
This commit is contained in:
Charles Kerr 2024-11-04 12:27:49 -06:00 committed by GitHub
parent 48801be8e9
commit f5bdbdb1e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 305 additions and 412 deletions

View file

@ -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<std::string> schemes) {
if (schemes.empty())
return;

View file

@ -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<NativeWindow*>(
widget->GetNativeWindowProperty(electron::kElectronNativeWindowKey));
auto* native_window =
static_cast<NativeWindow*>(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<NativeWindow*>(
widget->GetNativeWindowProperty(kElectronNativeWindowKey));
widget->GetNativeWindowProperty(kElectronNativeWindowKey.c_str()));
if (!native_window)
return;
native_window->RemoveDraggableRegionProvider(this);

View file

@ -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<const char*, 9U> 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 ||

View file

@ -39,9 +39,6 @@
namespace electron {
const char kHidDeviceNameKey[] = "name";
const char kHidGuidKey[] = "guid";
HidChooserContext::HidChooserContext(ElectronBrowserContext* context)
: browser_context_(context) {}

View file

@ -8,6 +8,7 @@
#include <map>
#include <set>
#include <string>
#include <string_view>
#include <vector>
#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.

View file

@ -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<views::Widget>()), parent_(parent) {

View file

@ -10,11 +10,13 @@
#include <optional>
#include <queue>
#include <string>
#include <string_view>
#include <vector>
#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;

View file

@ -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<ElectronNSWindow*>(
widget()->GetNativeWindow().GetNativeNSWindow());

View file

@ -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;

View file

@ -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) {

View file

@ -7,6 +7,7 @@
#include <map>
#include <set>
#include <string_view>
#include <vector>
#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 {