From 563c370d51f302b6d4a7fee8b47e1cc3e1ca2fe3 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 10 Oct 2023 12:45:44 +0200 Subject: [PATCH] refactor: use gin_helper::Dictionary::CreateEmpty() helper (#40140) --- shell/browser/api/electron_api_base_window.cc | 3 +-- shell/browser/api/electron_api_browser_view.cc | 5 ++--- shell/browser/api/electron_api_content_tracing.cc | 2 +- shell/browser/api/electron_api_session.cc | 4 ++-- shell/browser/api/electron_api_web_contents.cc | 13 +++++-------- .../bluetooth/electron_bluetooth_delegate.cc | 3 +-- shell/browser/hid/hid_chooser_context.cc | 3 +-- shell/browser/native_window.cc | 4 ++-- shell/browser/native_window_views.cc | 4 ++-- shell/browser/serial/serial_chooser_context.cc | 3 +-- shell/browser/ui/file_dialog_gtk.cc | 6 ++---- shell/browser/ui/file_dialog_mac.mm | 4 ++-- shell/browser/ui/file_dialog_win.cc | 4 ++-- shell/browser/usb/usb_chooser_context.cc | 3 +-- shell/common/api/electron_api_clipboard.cc | 3 +-- shell/common/api/electron_api_shell.cc | 4 ++-- shell/renderer/api/electron_api_context_bridge.cc | 4 ++-- 17 files changed, 30 insertions(+), 42 deletions(-) diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index 373a536a46c2..071ebe320051 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -1180,8 +1180,7 @@ void BaseWindow::RemoveFromParentChildWindows() { // static gin_helper::WrappableBase* BaseWindow::New(gin_helper::Arguments* args) { - gin_helper::Dictionary options = - gin::Dictionary::CreateEmpty(args->isolate()); + auto options = gin_helper::Dictionary::CreateEmpty(args->isolate()); args->GetNext(&options); return new BaseWindow(args, options); diff --git a/shell/browser/api/electron_api_browser_view.cc b/shell/browser/api/electron_api_browser_view.cc index 9f703f1ec647..cc0641e34710 100644 --- a/shell/browser/api/electron_api_browser_view.cc +++ b/shell/browser/api/electron_api_browser_view.cc @@ -74,8 +74,7 @@ gin::WrapperInfo BrowserView::kWrapperInfo = {gin::kEmbedderNativeGin}; BrowserView::BrowserView(gin::Arguments* args, const gin_helper::Dictionary& options) : id_(GetNextId()) { - gin_helper::Dictionary web_preferences = - gin::Dictionary::CreateEmpty(args->isolate()); + auto web_preferences = gin_helper::Dictionary::CreateEmpty(args->isolate()); options.Get(options::kWebPreferences, &web_preferences); web_preferences.Set("type", "browserView"); @@ -143,7 +142,7 @@ gin::Handle BrowserView::New(gin_helper::ErrorThrower thrower, return gin::Handle(); } - gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate()); + auto options = gin::Dictionary::CreateEmpty(args->isolate()); args->GetNext(&options); auto handle = diff --git a/shell/browser/api/electron_api_content_tracing.cc b/shell/browser/api/electron_api_content_tracing.cc index f44f2d849417..4a5f373b69c6 100644 --- a/shell/browser/api/electron_api_content_tracing.cc +++ b/shell/browser/api/electron_api_content_tracing.cc @@ -152,7 +152,7 @@ void OnTraceBufferUsageAvailable( gin_helper::Promise promise, float percent_full, size_t approximate_count) { - gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate()); + auto dict = gin_helper::Dictionary::CreateEmpty(promise.isolate()); dict.Set("percentage", percent_full); dict.Set("value", approximate_count); diff --git a/shell/browser/api/electron_api_session.cc b/shell/browser/api/electron_api_session.cc index 660b9b730a82..bfe8db94566c 100644 --- a/shell/browser/api/electron_api_session.cc +++ b/shell/browser/api/electron_api_session.cc @@ -448,8 +448,8 @@ v8::Local Session::ResolveHost( DCHECK(addrs.has_value() && !addrs->empty()); v8::HandleScope handle_scope(promise.isolate()); - gin_helper::Dictionary dict = - gin::Dictionary::CreateEmpty(promise.isolate()); + auto dict = + gin_helper::Dictionary::CreateEmpty(promise.isolate()); dict.Set("endpoints", addrs->endpoints()); promise.Resolve(dict); } diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 4bd23d5b7b16..cb6cdaacc7c9 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1658,8 +1658,7 @@ void WebContents::RenderFrameCreated( if (lifecycle_state == content::RenderFrameHost::LifecycleState::kActive) { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin_helper::Dictionary details = - gin_helper::Dictionary::CreateEmpty(isolate); + auto details = gin_helper::Dictionary::CreateEmpty(isolate); details.SetGetter("frame", render_frame_host); Emit("frame-created", details); } @@ -1731,7 +1730,7 @@ void WebContents::PrimaryMainFrameRenderProcessGone( base::TerminationStatus status) { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope handle_scope(isolate); - gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate); + auto details = gin_helper::Dictionary::CreateEmpty(isolate); details.Set("reason", status); details.Set("exitCode", web_contents()->GetCrashedErrorCode()); Emit("render-process-gone", details); @@ -2529,7 +2528,7 @@ v8::Local WebContents::GetWebRTCUDPPortRange( v8::Isolate* isolate) const { auto* prefs = web_contents()->GetMutableRendererPrefs(); - gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate); + auto dict = gin_helper::Dictionary::CreateEmpty(isolate); dict.Set("min", static_cast(prefs->webrtc_udp_min_port)); dict.Set("max", static_cast(prefs->webrtc_udp_max_port)); return dict.GetHandle(); @@ -2907,8 +2906,7 @@ void WebContents::OnGetDeviceNameToUse( } void WebContents::Print(gin::Arguments* args) { - gin_helper::Dictionary options = - gin::Dictionary::CreateEmpty(args->isolate()); + auto options = gin_helper::Dictionary::CreateEmpty(args->isolate()); base::Value::Dict settings; if (args->Length() >= 1 && !args->GetNext(&options)) { @@ -2933,8 +2931,7 @@ void WebContents::Print(gin::Arguments* args) { settings.Set(printing::kSettingShouldPrintBackgrounds, print_background); // Set custom margin settings - gin_helper::Dictionary margins = - gin::Dictionary::CreateEmpty(args->isolate()); + auto margins = gin_helper::Dictionary::CreateEmpty(args->isolate()); if (options.Get("margins", &margins)) { printing::mojom::MarginType margin_type = printing::mojom::MarginType::kDefaultMargins; diff --git a/shell/browser/bluetooth/electron_bluetooth_delegate.cc b/shell/browser/bluetooth/electron_bluetooth_delegate.cc index b95b3f351aa5..94e7a3b2a6e2 100644 --- a/shell/browser/bluetooth/electron_bluetooth_delegate.cc +++ b/shell/browser/bluetooth/electron_bluetooth_delegate.cc @@ -169,8 +169,7 @@ void ElectronBluetoothDelegate::ShowDevicePairPrompt( v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope scope(isolate); - gin_helper::Dictionary details = - gin_helper::Dictionary::CreateEmpty(isolate); + auto details = gin_helper::Dictionary::CreateEmpty(isolate); details.Set("deviceId", device_identifier); details.Set("pairingKind", pairing_kind); details.SetGetter("frame", frame); diff --git a/shell/browser/hid/hid_chooser_context.cc b/shell/browser/hid/hid_chooser_context.cc index 1a01be443b85..1ca309be62ea 100644 --- a/shell/browser/hid/hid_chooser_context.cc +++ b/shell/browser/hid/hid_chooser_context.cc @@ -119,8 +119,7 @@ void HidChooserContext::RevokeDevicePermission( if (session) { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope scope(isolate); - gin_helper::Dictionary details = - gin_helper::Dictionary::CreateEmpty(isolate); + auto details = gin_helper::Dictionary::CreateEmpty(isolate); details.Set("device", device.Clone()); details.Set("origin", origin.Serialize()); session->Emit("hid-device-revoked", details); diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index 12e8e3678266..90540c268901 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -114,8 +114,8 @@ NativeWindow::NativeWindow(const gin_helper::Dictionary& options, } else if (titlebar_overlay->IsObject()) { titlebar_overlay_ = true; - gin_helper::Dictionary titlebar_overlay_dict = - gin::Dictionary::CreateEmpty(options.isolate()); + auto titlebar_overlay_dict = + gin_helper::Dictionary::CreateEmpty(options.isolate()); options.Get(options::ktitleBarOverlay, &titlebar_overlay_dict); int height; if (titlebar_overlay_dict.Get(options::kOverlayHeight, &height)) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index d67f31388c4c..e895ffc2c024 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -231,8 +231,8 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, v8::Local titlebar_overlay; if (options.Get(options::ktitleBarOverlay, &titlebar_overlay) && titlebar_overlay->IsObject()) { - gin_helper::Dictionary titlebar_overlay_obj = - gin::Dictionary::CreateEmpty(options.isolate()); + auto titlebar_overlay_obj = + gin_helper::Dictionary::CreateEmpty(options.isolate()); options.Get(options::ktitleBarOverlay, &titlebar_overlay_obj); std::string overlay_color_string; diff --git a/shell/browser/serial/serial_chooser_context.cc b/shell/browser/serial/serial_chooser_context.cc index e2dd32d61933..521fe7c53ade 100644 --- a/shell/browser/serial/serial_chooser_context.cc +++ b/shell/browser/serial/serial_chooser_context.cc @@ -158,8 +158,7 @@ void SerialChooserContext::RevokePortPermissionWebInitiated( if (session) { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope scope(isolate); - gin_helper::Dictionary details = - gin_helper::Dictionary::CreateEmpty(isolate); + auto details = gin_helper::Dictionary::CreateEmpty(isolate); details.Set("port", it->second); details.SetGetter("frame", render_frame_host); details.Set("origin", origin.Serialize()); diff --git a/shell/browser/ui/file_dialog_gtk.cc b/shell/browser/ui/file_dialog_gtk.cc index c8a81553c4c2..ffe2e7a86f78 100644 --- a/shell/browser/ui/file_dialog_gtk.cc +++ b/shell/browser/ui/file_dialog_gtk.cc @@ -246,8 +246,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) { v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate(); v8::HandleScope scope(isolate); if (save_promise_) { - gin_helper::Dictionary dict = - gin::Dictionary::CreateEmpty(save_promise_->isolate()); + auto dict = gin_helper::Dictionary::CreateEmpty(save_promise_->isolate()); if (response == GTK_RESPONSE_ACCEPT) { dict.Set("canceled", false); dict.Set("filePath", GetFileName()); @@ -257,8 +256,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) { } save_promise_->Resolve(dict); } else if (open_promise_) { - gin_helper::Dictionary dict = - gin::Dictionary::CreateEmpty(open_promise_->isolate()); + auto dict = gin_helper::Dictionary::CreateEmpty(open_promise_->isolate()); if (response == GTK_RESPONSE_ACCEPT) { dict.Set("canceled", false); dict.Set("filePaths", GetFileNames()); diff --git a/shell/browser/ui/file_dialog_mac.mm b/shell/browser/ui/file_dialog_mac.mm index 045260036aea..1c9a044e013f 100644 --- a/shell/browser/ui/file_dialog_mac.mm +++ b/shell/browser/ui/file_dialog_mac.mm @@ -353,7 +353,7 @@ void OpenDialogCompletion(int chosen, bool security_scoped_bookmarks, gin_helper::Promise promise) { v8::HandleScope scope(promise.isolate()); - gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate()); + auto dict = gin_helper::Dictionary::CreateEmpty(promise.isolate()); if (chosen == NSModalResponseCancel) { dict.Set("canceled", true); dict.Set("filePaths", std::vector()); @@ -431,7 +431,7 @@ void SaveDialogCompletion(int chosen, bool security_scoped_bookmarks, gin_helper::Promise promise) { v8::HandleScope scope(promise.isolate()); - gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate()); + auto dict = gin_helper::Dictionary::CreateEmpty(promise.isolate()); if (chosen == NSModalResponseCancel) { dict.Set("canceled", true); dict.Set("filePath", base::FilePath()); diff --git a/shell/browser/ui/file_dialog_win.cc b/shell/browser/ui/file_dialog_win.cc index cefe30f245bf..3e82b9cfad68 100644 --- a/shell/browser/ui/file_dialog_win.cc +++ b/shell/browser/ui/file_dialog_win.cc @@ -220,7 +220,7 @@ void ShowOpenDialog(const DialogSettings& settings, auto done = [](gin_helper::Promise promise, bool success, std::vector result) { v8::HandleScope handle_scope(promise.isolate()); - gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate()); + auto dict = gin::Dictionary::CreateEmpty(promise.isolate()); dict.Set("canceled", !success); dict.Set("filePaths", result); promise.Resolve(dict); @@ -269,7 +269,7 @@ void ShowSaveDialog(const DialogSettings& settings, auto done = [](gin_helper::Promise promise, bool success, base::FilePath result) { v8::HandleScope handle_scope(promise.isolate()); - gin::Dictionary dict = gin::Dictionary::CreateEmpty(promise.isolate()); + auto dict = gin::Dictionary::CreateEmpty(promise.isolate()); dict.Set("canceled", !success); dict.Set("filePath", result); promise.Resolve(dict); diff --git a/shell/browser/usb/usb_chooser_context.cc b/shell/browser/usb/usb_chooser_context.cc index 53df5c666f53..78289af41bd7 100644 --- a/shell/browser/usb/usb_chooser_context.cc +++ b/shell/browser/usb/usb_chooser_context.cc @@ -203,8 +203,7 @@ void UsbChooserContext::RevokeObjectPermissionInternal( if (session) { v8::Isolate* isolate = JavascriptEnvironment::GetIsolate(); v8::HandleScope scope(isolate); - gin_helper::Dictionary details = - gin_helper::Dictionary::CreateEmpty(isolate); + auto details = gin_helper::Dictionary::CreateEmpty(isolate); details.Set("device", object); details.Set("origin", origin.Serialize()); session->Emit("usb-device-revoked", details); diff --git a/shell/common/api/electron_api_clipboard.cc b/shell/common/api/electron_api_clipboard.cc index 84a3a1337f7e..ea1c8d5f912f 100644 --- a/shell/common/api/electron_api_clipboard.cc +++ b/shell/common/api/electron_api_clipboard.cc @@ -204,8 +204,7 @@ void Clipboard::WriteHTML(const std::u16string& html, v8::Local Clipboard::ReadBookmark(gin_helper::Arguments* args) { std::u16string title; std::string url; - gin_helper::Dictionary dict = - gin_helper::Dictionary::CreateEmpty(args->isolate()); + auto dict = gin_helper::Dictionary::CreateEmpty(args->isolate()); ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); clipboard->ReadBookmark(/* data_dst = */ nullptr, &title, &url); dict.Set("title", title); diff --git a/shell/common/api/electron_api_shell.cc b/shell/common/api/electron_api_shell.cc index 1055cb73d402..b05b5216b575 100644 --- a/shell/common/api/electron_api_shell.cc +++ b/shell/common/api/electron_api_shell.cc @@ -111,7 +111,7 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path, base::win::ShortcutOperation operation = base::win::ShortcutOperation::kCreateAlways; args->GetNext(&operation); - gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate()); + auto options = gin::Dictionary::CreateEmpty(args->isolate()); if (!args->GetNext(&options)) { args->ThrowError(); return false; @@ -146,7 +146,7 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path, v8::Local ReadShortcutLink(gin_helper::ErrorThrower thrower, const base::FilePath& path) { using base::win::ShortcutProperties; - gin::Dictionary options = gin::Dictionary::CreateEmpty(thrower.isolate()); + auto options = gin::Dictionary::CreateEmpty(thrower.isolate()); electron::ScopedAllowBlockingForElectron allow_blocking; base::win::ScopedCOMInitializer com_initializer; base::win::ShortcutProperties properties; diff --git a/shell/renderer/api/electron_api_context_bridge.cc b/shell/renderer/api/electron_api_context_bridge.cc index 674a503eb9bb..2a5e22728b94 100644 --- a/shell/renderer/api/electron_api_context_bridge.cc +++ b/shell/renderer/api/electron_api_context_bridge.cc @@ -573,8 +573,8 @@ v8::MaybeLocal CreateProxyForAPI( { v8::Context::Scope destination_context_scope(destination_context); - gin_helper::Dictionary proxy = - gin::Dictionary::CreateEmpty(destination_context->GetIsolate()); + auto proxy = + gin_helper::Dictionary::CreateEmpty(destination_context->GetIsolate()); object_cache->CacheProxiedObject(api.GetHandle(), proxy.GetHandle()); auto maybe_keys = api.GetHandle()->GetOwnPropertyNames( source_context, static_cast(v8::ONLY_ENUMERABLE));