From 5a0e1ccf73435ffa753d9a19c6ca68075cd9a2c5 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:55:19 -0500 Subject: [PATCH] fix: modernize-avoid-c-arrays (#44834) use string_view for constants used in methods that take string_view args Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/app/electron_main_delegate.cc | 2 +- .../extensions/api/scripting/scripting_api.cc | 6 +- shell/browser/extensions/api/tabs/tabs_api.cc | 3 +- .../file_system_access_permission_context.cc | 8 +-- .../ui/devtools_ui_theme_data_source.cc | 3 +- shell/browser/ui/inspectable_web_contents.cc | 21 +++--- shell/browser/ui/webui/accessibility_ui.cc | 71 ++++++++++--------- shell/browser/usb/usb_chooser_context.cc | 4 +- shell/browser/zoom_level_delegate.cc | 6 +- shell/renderer/electron_api_service_impl.cc | 3 +- .../electron_sandboxed_renderer_client.cc | 4 +- 11 files changed, 69 insertions(+), 62 deletions(-) diff --git a/shell/app/electron_main_delegate.cc b/shell/app/electron_main_delegate.cc index c093db68016..a66e140a1ec 100644 --- a/shell/app/electron_main_delegate.cc +++ b/shell/app/electron_main_delegate.cc @@ -79,7 +79,7 @@ namespace electron { namespace { -const char kRelauncherProcess[] = "relauncher"; +constexpr std::string_view kRelauncherProcess = "relauncher"; constexpr std::string_view kElectronDisableSandbox{"ELECTRON_DISABLE_SANDBOX"}; constexpr std::string_view kElectronEnableStackDumping{ diff --git a/shell/browser/extensions/api/scripting/scripting_api.cc b/shell/browser/extensions/api/scripting/scripting_api.cc index 1bfb0b011fa..4745cc874b4 100644 --- a/shell/browser/extensions/api/scripting/scripting_api.cc +++ b/shell/browser/extensions/api/scripting/scripting_api.cc @@ -49,10 +49,10 @@ namespace extensions { namespace { -constexpr char kCouldNotLoadFileError[] = "Could not load file: '*'."; -constexpr char kDuplicateFileSpecifiedError[] = +constexpr std::string_view kCouldNotLoadFileError = "Could not load file: '*'."; +constexpr std::string_view kDuplicateFileSpecifiedError = "Duplicate file specified: '*'."; -constexpr char kEmptyMatchesError[] = +constexpr std::string_view kEmptyMatchesError = "Script with ID '*' must specify 'matches'."; constexpr char kExactlyOneOfCssAndFilesError[] = "Exactly one of 'css' and 'files' must be specified."; diff --git a/shell/browser/extensions/api/tabs/tabs_api.cc b/shell/browser/extensions/api/tabs/tabs_api.cc index a8e6fb52a2c..aa57c2c8c6e 100644 --- a/shell/browser/extensions/api/tabs/tabs_api.cc +++ b/shell/browser/extensions/api/tabs/tabs_api.cc @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -39,7 +40,7 @@ namespace extensions { namespace tabs = api::tabs; -const char kFrameNotFoundError[] = "No frame with id * in tab *."; +constexpr std::string_view kFrameNotFoundError = "No frame with id * in tab *."; const char kPerOriginOnlyInAutomaticError[] = "Can only set scope to " "\"per-origin\" in \"automatic\" mode."; diff --git a/shell/browser/file_system_access/file_system_access_permission_context.cc b/shell/browser/file_system_access/file_system_access_permission_context.cc index 4addf43708a..46c9c3be195 100644 --- a/shell/browser/file_system_access/file_system_access_permission_context.cc +++ b/shell/browser/file_system_access/file_system_access_permission_context.cc @@ -90,10 +90,10 @@ using blink::mojom::PermissionStatus; // } const char kDefaultLastPickedDirectoryKey[] = "default-id"; const char kCustomLastPickedDirectoryKey[] = "custom-id"; -const char kPathKey[] = "path"; -const char kPathTypeKey[] = "path-type"; -const char kDisplayNameKey[] = "display-name"; -const char kTimestampKey[] = "timestamp"; +constexpr std::string_view kPathKey = "path"; +constexpr std::string_view kPathTypeKey = "path-type"; +constexpr std::string_view kDisplayNameKey = "display-name"; +constexpr std::string_view kTimestampKey = "timestamp"; constexpr base::TimeDelta kPermissionRevocationTimeout = base::Seconds(5); diff --git a/shell/browser/ui/devtools_ui_theme_data_source.cc b/shell/browser/ui/devtools_ui_theme_data_source.cc index ac4e82b5d10..8aed429e557 100644 --- a/shell/browser/ui/devtools_ui_theme_data_source.cc +++ b/shell/browser/ui/devtools_ui_theme_data_source.cc @@ -6,6 +6,7 @@ #include #include +#include #include #include "base/memory/ref_counted_memory.h" @@ -97,7 +98,7 @@ void ThemeDataSource::StartDataRequest( // kColorsCssPath should stay consistent with COLORS_CSS_SELECTOR in // colors_css_updater.js. - constexpr char kColorsCssPath[] = "colors.css"; + constexpr std::string_view kColorsCssPath = "colors.css"; if (parsed_path == kColorsCssPath) { SendColorsCss(url, wc_getter, std::move(callback)); return; diff --git a/shell/browser/ui/inspectable_web_contents.cc b/shell/browser/ui/inspectable_web_contents.cc index d70e9765c73..432b62fade9 100644 --- a/shell/browser/ui/inspectable_web_contents.cc +++ b/shell/browser/ui/inspectable_web_contents.cc @@ -70,25 +70,26 @@ namespace electron { namespace { -const char kChromeUIDevToolsURL[] = +constexpr std::string_view kChromeUIDevToolsURL = "devtools://devtools/bundled/devtools_app.html?" "remoteBase=%s&" "can_dock=%s&" "toolbarColor=rgba(223,223,223,1)&" "textColor=rgba(0,0,0,1)&" "experiments=true"; -const char kChromeUIDevToolsRemoteFrontendBase[] = +constexpr std::string_view kChromeUIDevToolsRemoteFrontendBase = "https://chrome-devtools-frontend.appspot.com/"; -const char kChromeUIDevToolsRemoteFrontendPath[] = "serve_file"; +constexpr std::string_view kChromeUIDevToolsRemoteFrontendPath = "serve_file"; -const char kDevToolsBoundsPref[] = "electron.devtools.bounds"; -const char kDevToolsZoomPref[] = "electron.devtools.zoom"; -const char kDevToolsPreferences[] = "electron.devtools.preferences"; +constexpr std::string_view kDevToolsBoundsPref = "electron.devtools.bounds"; +constexpr std::string_view kDevToolsZoomPref = "electron.devtools.zoom"; +constexpr std::string_view kDevToolsPreferences = + "electron.devtools.preferences"; -const char kFrontendHostId[] = "id"; -const char kFrontendHostMethod[] = "method"; -const char kFrontendHostParams[] = "params"; -const char kTitleFormat[] = "Developer Tools - %s"; +constexpr std::string_view kFrontendHostId = "id"; +constexpr std::string_view kFrontendHostMethod = "method"; +constexpr std::string_view kFrontendHostParams = "params"; +constexpr std::string_view kTitleFormat = "Developer Tools - %s"; const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; diff --git a/shell/browser/ui/webui/accessibility_ui.cc b/shell/browser/ui/webui/accessibility_ui.cc index 67fdc50c97e..02d53363f85 100644 --- a/shell/browser/ui/webui/accessibility_ui.cc +++ b/shell/browser/ui/webui/accessibility_ui.cc @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -50,49 +51,49 @@ namespace { -static const char kTargetsDataFile[] = "targets-data.json"; +constexpr std::string_view kTargetsDataFile = "targets-data.json"; -static const char kAccessibilityModeField[] = "a11yMode"; -static const char kBrowsersField[] = "browsers"; -static const char kErrorField[] = "error"; -static const char kFaviconUrlField[] = "faviconUrl"; -static const char kNameField[] = "name"; -static const char kPagesField[] = "pages"; -static const char kPidField[] = "pid"; -static const char kProcessIdField[] = "processId"; -static const char kRequestTypeField[] = "requestType"; -static const char kRoutingIdField[] = "routingId"; -static const char kSessionIdField[] = "sessionId"; -static const char kSupportedApiTypesField[] = "supportedApiTypes"; -static const char kTreeField[] = "tree"; -static const char kTypeField[] = "type"; -static const char kUrlField[] = "url"; -static const char kWidgetsField[] = "widgets"; -static const char kApiTypeField[] = "apiType"; +constexpr std::string_view kAccessibilityModeField = "a11yMode"; +constexpr std::string_view kBrowsersField = "browsers"; +constexpr std::string_view kErrorField = "error"; +constexpr std::string_view kFaviconUrlField = "faviconUrl"; +constexpr std::string_view kNameField = "name"; +constexpr std::string_view kPagesField = "pages"; +constexpr std::string_view kPidField = "pid"; +constexpr std::string_view kProcessIdField = "processId"; +constexpr std::string_view kRequestTypeField = "requestType"; +constexpr std::string_view kRoutingIdField = "routingId"; +constexpr std::string_view kSessionIdField = "sessionId"; +constexpr std::string_view kSupportedApiTypesField = "supportedApiTypes"; +constexpr std::string_view kTreeField = "tree"; +constexpr std::string_view kTypeField = "type"; +constexpr std::string_view kUrlField = "url"; +constexpr std::string_view kWidgetsField = "widgets"; +constexpr std::string_view kApiTypeField = "apiType"; #if defined(USE_AURA) -static const char kWidgetIdField[] = "widgetId"; -static const char kWidget[] = "widget"; +constexpr std::string_view kWidgetIdField = "widgetId"; +constexpr std::string_view kWidget = "widget"; #endif // Global flags -static const char kBrowser[] = "browser"; -static const char kCopyTree[] = "copyTree"; -static const char kHTML[] = "html"; -static const char kLocked[] = "locked"; -static const char kNative[] = "native"; -static const char kPage[] = "page"; -static const char kPDFPrinting[] = "pdfPrinting"; -static const char kScreenReader[] = "screenreader"; -static const char kShowOrRefreshTree[] = "showOrRefreshTree"; -static const char kText[] = "text"; -static const char kViewsAccessibility[] = "viewsAccessibility"; -static const char kWeb[] = "web"; +constexpr std::string_view kBrowser = "browser"; +constexpr std::string_view kCopyTree = "copyTree"; +constexpr std::string_view kHTML = "html"; +constexpr std::string_view kLocked = "locked"; +constexpr std::string_view kNative = "native"; +constexpr std::string_view kPage = "page"; +constexpr std::string_view kPDFPrinting = "pdfPrinting"; +constexpr std::string_view kScreenReader = "screenreader"; +constexpr std::string_view kShowOrRefreshTree = "showOrRefreshTree"; +constexpr std::string_view kText = "text"; +constexpr std::string_view kViewsAccessibility = "viewsAccessibility"; +constexpr std::string_view kWeb = "web"; // Possible global flag values -static const char kDisabled[] = "disabled"; -static const char kOff[] = "off"; -static const char kOn[] = "on"; +constexpr std::string_view kDisabled = "disabled"; +constexpr std::string_view kOff = "off"; +constexpr std::string_view kOn = "on"; base::Value::Dict BuildTargetDescriptor( const GURL& url, diff --git a/shell/browser/usb/usb_chooser_context.cc b/shell/browser/usb/usb_chooser_context.cc index 2c7451c872f..22c6bf80b0c 100644 --- a/shell/browser/usb/usb_chooser_context.cc +++ b/shell/browser/usb/usb_chooser_context.cc @@ -27,8 +27,8 @@ namespace { -constexpr char kDeviceNameKey[] = "productName"; -constexpr char kDeviceIdKey[] = "deviceId"; +constexpr std::string_view kDeviceNameKey = "productName"; +constexpr std::string_view kDeviceIdKey = "deviceId"; constexpr int kUsbClassMassStorage = 0x08; bool CanStorePersistentEntry(const device::mojom::UsbDeviceInfo& device_info) { diff --git a/shell/browser/zoom_level_delegate.cc b/shell/browser/zoom_level_delegate.cc index cccbb37d20e..5b3838bd942 100644 --- a/shell/browser/zoom_level_delegate.cc +++ b/shell/browser/zoom_level_delegate.cc @@ -22,11 +22,13 @@ namespace electron { namespace { // Double that indicates the default zoom level. -const char kPartitionDefaultZoomLevel[] = "partition.default_zoom_level"; +constexpr std::string_view kPartitionDefaultZoomLevel = + "partition.default_zoom_level"; // Dictionary that maps hostnames to zoom levels. Hosts not in this pref will // be displayed at the default zoom level. -const char kPartitionPerHostZoomLevels[] = "partition.per_host_zoom_levels"; +constexpr std::string_view kPartitionPerHostZoomLevels = + "partition.per_host_zoom_levels"; std::string GetHash(const base::FilePath& partition_path) { size_t int_key = std::hash()(partition_path); diff --git a/shell/renderer/electron_api_service_impl.cc b/shell/renderer/electron_api_service_impl.cc index 1b48c4a9814..034b59ad718 100644 --- a/shell/renderer/electron_api_service_impl.cc +++ b/shell/renderer/electron_api_service_impl.cc @@ -5,6 +5,7 @@ #include "electron/shell/renderer/electron_api_service_impl.h" #include +#include #include #include #include @@ -32,7 +33,7 @@ namespace electron { namespace { -const char kIpcKey[] = "ipcNative"; +constexpr std::string_view kIpcKey = "ipcNative"; // Gets the private object under kIpcKey v8::Local GetIpcObject(v8::Local context) { diff --git a/shell/renderer/electron_sandboxed_renderer_client.cc b/shell/renderer/electron_sandboxed_renderer_client.cc index 4d578f51ed6..000d37848ea 100644 --- a/shell/renderer/electron_sandboxed_renderer_client.cc +++ b/shell/renderer/electron_sandboxed_renderer_client.cc @@ -33,8 +33,8 @@ namespace electron { namespace { -const char kEmitProcessEventKey[] = "emit-process-event"; -const char kBindingCacheKey[] = "native-binding-cache"; +constexpr std::string_view kEmitProcessEventKey = "emit-process-event"; +constexpr std::string_view kBindingCacheKey = "native-binding-cache"; v8::Local GetBindingCache(v8::Isolate* isolate) { auto context = isolate->GetCurrentContext();