refactor: use gin_helper::Dictionary::CreateEmpty() helper (#40140)
This commit is contained in:
parent
47beca1d2a
commit
563c370d51
17 changed files with 30 additions and 42 deletions
|
@ -1180,8 +1180,7 @@ void BaseWindow::RemoveFromParentChildWindows() {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
gin_helper::WrappableBase* BaseWindow::New(gin_helper::Arguments* args) {
|
gin_helper::WrappableBase* BaseWindow::New(gin_helper::Arguments* args) {
|
||||||
gin_helper::Dictionary options =
|
auto options = gin_helper::Dictionary::CreateEmpty(args->isolate());
|
||||||
gin::Dictionary::CreateEmpty(args->isolate());
|
|
||||||
args->GetNext(&options);
|
args->GetNext(&options);
|
||||||
|
|
||||||
return new BaseWindow(args, options);
|
return new BaseWindow(args, options);
|
||||||
|
|
|
@ -74,8 +74,7 @@ gin::WrapperInfo BrowserView::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||||
BrowserView::BrowserView(gin::Arguments* args,
|
BrowserView::BrowserView(gin::Arguments* args,
|
||||||
const gin_helper::Dictionary& options)
|
const gin_helper::Dictionary& options)
|
||||||
: id_(GetNextId()) {
|
: id_(GetNextId()) {
|
||||||
gin_helper::Dictionary web_preferences =
|
auto web_preferences = gin_helper::Dictionary::CreateEmpty(args->isolate());
|
||||||
gin::Dictionary::CreateEmpty(args->isolate());
|
|
||||||
options.Get(options::kWebPreferences, &web_preferences);
|
options.Get(options::kWebPreferences, &web_preferences);
|
||||||
web_preferences.Set("type", "browserView");
|
web_preferences.Set("type", "browserView");
|
||||||
|
|
||||||
|
@ -143,7 +142,7 @@ gin::Handle<BrowserView> BrowserView::New(gin_helper::ErrorThrower thrower,
|
||||||
return gin::Handle<BrowserView>();
|
return gin::Handle<BrowserView>();
|
||||||
}
|
}
|
||||||
|
|
||||||
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
|
auto options = gin::Dictionary::CreateEmpty(args->isolate());
|
||||||
args->GetNext(&options);
|
args->GetNext(&options);
|
||||||
|
|
||||||
auto handle =
|
auto handle =
|
||||||
|
|
|
@ -152,7 +152,7 @@ void OnTraceBufferUsageAvailable(
|
||||||
gin_helper::Promise<gin_helper::Dictionary> promise,
|
gin_helper::Promise<gin_helper::Dictionary> promise,
|
||||||
float percent_full,
|
float percent_full,
|
||||||
size_t approximate_count) {
|
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("percentage", percent_full);
|
||||||
dict.Set("value", approximate_count);
|
dict.Set("value", approximate_count);
|
||||||
|
|
||||||
|
|
|
@ -448,8 +448,8 @@ v8::Local<v8::Promise> Session::ResolveHost(
|
||||||
DCHECK(addrs.has_value() && !addrs->empty());
|
DCHECK(addrs.has_value() && !addrs->empty());
|
||||||
|
|
||||||
v8::HandleScope handle_scope(promise.isolate());
|
v8::HandleScope handle_scope(promise.isolate());
|
||||||
gin_helper::Dictionary dict =
|
auto dict =
|
||||||
gin::Dictionary::CreateEmpty(promise.isolate());
|
gin_helper::Dictionary::CreateEmpty(promise.isolate());
|
||||||
dict.Set("endpoints", addrs->endpoints());
|
dict.Set("endpoints", addrs->endpoints());
|
||||||
promise.Resolve(dict);
|
promise.Resolve(dict);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1658,8 +1658,7 @@ void WebContents::RenderFrameCreated(
|
||||||
if (lifecycle_state == content::RenderFrameHost::LifecycleState::kActive) {
|
if (lifecycle_state == content::RenderFrameHost::LifecycleState::kActive) {
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
gin_helper::Dictionary details =
|
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||||
gin_helper::Dictionary::CreateEmpty(isolate);
|
|
||||||
details.SetGetter("frame", render_frame_host);
|
details.SetGetter("frame", render_frame_host);
|
||||||
Emit("frame-created", details);
|
Emit("frame-created", details);
|
||||||
}
|
}
|
||||||
|
@ -1731,7 +1730,7 @@ void WebContents::PrimaryMainFrameRenderProcessGone(
|
||||||
base::TerminationStatus status) {
|
base::TerminationStatus status) {
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope handle_scope(isolate);
|
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("reason", status);
|
||||||
details.Set("exitCode", web_contents()->GetCrashedErrorCode());
|
details.Set("exitCode", web_contents()->GetCrashedErrorCode());
|
||||||
Emit("render-process-gone", details);
|
Emit("render-process-gone", details);
|
||||||
|
@ -2529,7 +2528,7 @@ v8::Local<v8::Value> WebContents::GetWebRTCUDPPortRange(
|
||||||
v8::Isolate* isolate) const {
|
v8::Isolate* isolate) const {
|
||||||
auto* prefs = web_contents()->GetMutableRendererPrefs();
|
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<uint32_t>(prefs->webrtc_udp_min_port));
|
dict.Set("min", static_cast<uint32_t>(prefs->webrtc_udp_min_port));
|
||||||
dict.Set("max", static_cast<uint32_t>(prefs->webrtc_udp_max_port));
|
dict.Set("max", static_cast<uint32_t>(prefs->webrtc_udp_max_port));
|
||||||
return dict.GetHandle();
|
return dict.GetHandle();
|
||||||
|
@ -2907,8 +2906,7 @@ void WebContents::OnGetDeviceNameToUse(
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::Print(gin::Arguments* args) {
|
void WebContents::Print(gin::Arguments* args) {
|
||||||
gin_helper::Dictionary options =
|
auto options = gin_helper::Dictionary::CreateEmpty(args->isolate());
|
||||||
gin::Dictionary::CreateEmpty(args->isolate());
|
|
||||||
base::Value::Dict settings;
|
base::Value::Dict settings;
|
||||||
|
|
||||||
if (args->Length() >= 1 && !args->GetNext(&options)) {
|
if (args->Length() >= 1 && !args->GetNext(&options)) {
|
||||||
|
@ -2933,8 +2931,7 @@ void WebContents::Print(gin::Arguments* args) {
|
||||||
settings.Set(printing::kSettingShouldPrintBackgrounds, print_background);
|
settings.Set(printing::kSettingShouldPrintBackgrounds, print_background);
|
||||||
|
|
||||||
// Set custom margin settings
|
// Set custom margin settings
|
||||||
gin_helper::Dictionary margins =
|
auto margins = gin_helper::Dictionary::CreateEmpty(args->isolate());
|
||||||
gin::Dictionary::CreateEmpty(args->isolate());
|
|
||||||
if (options.Get("margins", &margins)) {
|
if (options.Get("margins", &margins)) {
|
||||||
printing::mojom::MarginType margin_type =
|
printing::mojom::MarginType margin_type =
|
||||||
printing::mojom::MarginType::kDefaultMargins;
|
printing::mojom::MarginType::kDefaultMargins;
|
||||||
|
|
|
@ -169,8 +169,7 @@ void ElectronBluetoothDelegate::ShowDevicePairPrompt(
|
||||||
|
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
gin_helper::Dictionary details =
|
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||||
gin_helper::Dictionary::CreateEmpty(isolate);
|
|
||||||
details.Set("deviceId", device_identifier);
|
details.Set("deviceId", device_identifier);
|
||||||
details.Set("pairingKind", pairing_kind);
|
details.Set("pairingKind", pairing_kind);
|
||||||
details.SetGetter("frame", frame);
|
details.SetGetter("frame", frame);
|
||||||
|
|
|
@ -119,8 +119,7 @@ void HidChooserContext::RevokeDevicePermission(
|
||||||
if (session) {
|
if (session) {
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
gin_helper::Dictionary details =
|
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||||
gin_helper::Dictionary::CreateEmpty(isolate);
|
|
||||||
details.Set("device", device.Clone());
|
details.Set("device", device.Clone());
|
||||||
details.Set("origin", origin.Serialize());
|
details.Set("origin", origin.Serialize());
|
||||||
session->Emit("hid-device-revoked", details);
|
session->Emit("hid-device-revoked", details);
|
||||||
|
|
|
@ -114,8 +114,8 @@ NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
|
||||||
} else if (titlebar_overlay->IsObject()) {
|
} else if (titlebar_overlay->IsObject()) {
|
||||||
titlebar_overlay_ = true;
|
titlebar_overlay_ = true;
|
||||||
|
|
||||||
gin_helper::Dictionary titlebar_overlay_dict =
|
auto titlebar_overlay_dict =
|
||||||
gin::Dictionary::CreateEmpty(options.isolate());
|
gin_helper::Dictionary::CreateEmpty(options.isolate());
|
||||||
options.Get(options::ktitleBarOverlay, &titlebar_overlay_dict);
|
options.Get(options::ktitleBarOverlay, &titlebar_overlay_dict);
|
||||||
int height;
|
int height;
|
||||||
if (titlebar_overlay_dict.Get(options::kOverlayHeight, &height))
|
if (titlebar_overlay_dict.Get(options::kOverlayHeight, &height))
|
||||||
|
|
|
@ -231,8 +231,8 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
|
||||||
v8::Local<v8::Value> titlebar_overlay;
|
v8::Local<v8::Value> titlebar_overlay;
|
||||||
if (options.Get(options::ktitleBarOverlay, &titlebar_overlay) &&
|
if (options.Get(options::ktitleBarOverlay, &titlebar_overlay) &&
|
||||||
titlebar_overlay->IsObject()) {
|
titlebar_overlay->IsObject()) {
|
||||||
gin_helper::Dictionary titlebar_overlay_obj =
|
auto titlebar_overlay_obj =
|
||||||
gin::Dictionary::CreateEmpty(options.isolate());
|
gin_helper::Dictionary::CreateEmpty(options.isolate());
|
||||||
options.Get(options::ktitleBarOverlay, &titlebar_overlay_obj);
|
options.Get(options::ktitleBarOverlay, &titlebar_overlay_obj);
|
||||||
|
|
||||||
std::string overlay_color_string;
|
std::string overlay_color_string;
|
||||||
|
|
|
@ -158,8 +158,7 @@ void SerialChooserContext::RevokePortPermissionWebInitiated(
|
||||||
if (session) {
|
if (session) {
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
gin_helper::Dictionary details =
|
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||||
gin_helper::Dictionary::CreateEmpty(isolate);
|
|
||||||
details.Set("port", it->second);
|
details.Set("port", it->second);
|
||||||
details.SetGetter("frame", render_frame_host);
|
details.SetGetter("frame", render_frame_host);
|
||||||
details.Set("origin", origin.Serialize());
|
details.Set("origin", origin.Serialize());
|
||||||
|
|
|
@ -246,8 +246,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
|
||||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
if (save_promise_) {
|
if (save_promise_) {
|
||||||
gin_helper::Dictionary dict =
|
auto dict = gin_helper::Dictionary::CreateEmpty(save_promise_->isolate());
|
||||||
gin::Dictionary::CreateEmpty(save_promise_->isolate());
|
|
||||||
if (response == GTK_RESPONSE_ACCEPT) {
|
if (response == GTK_RESPONSE_ACCEPT) {
|
||||||
dict.Set("canceled", false);
|
dict.Set("canceled", false);
|
||||||
dict.Set("filePath", GetFileName());
|
dict.Set("filePath", GetFileName());
|
||||||
|
@ -257,8 +256,7 @@ void FileChooserDialog::OnFileDialogResponse(GtkWidget* widget, int response) {
|
||||||
}
|
}
|
||||||
save_promise_->Resolve(dict);
|
save_promise_->Resolve(dict);
|
||||||
} else if (open_promise_) {
|
} else if (open_promise_) {
|
||||||
gin_helper::Dictionary dict =
|
auto dict = gin_helper::Dictionary::CreateEmpty(open_promise_->isolate());
|
||||||
gin::Dictionary::CreateEmpty(open_promise_->isolate());
|
|
||||||
if (response == GTK_RESPONSE_ACCEPT) {
|
if (response == GTK_RESPONSE_ACCEPT) {
|
||||||
dict.Set("canceled", false);
|
dict.Set("canceled", false);
|
||||||
dict.Set("filePaths", GetFileNames());
|
dict.Set("filePaths", GetFileNames());
|
||||||
|
|
|
@ -353,7 +353,7 @@ void OpenDialogCompletion(int chosen,
|
||||||
bool security_scoped_bookmarks,
|
bool security_scoped_bookmarks,
|
||||||
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
||||||
v8::HandleScope scope(promise.isolate());
|
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) {
|
if (chosen == NSModalResponseCancel) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePaths", std::vector<base::FilePath>());
|
dict.Set("filePaths", std::vector<base::FilePath>());
|
||||||
|
@ -431,7 +431,7 @@ void SaveDialogCompletion(int chosen,
|
||||||
bool security_scoped_bookmarks,
|
bool security_scoped_bookmarks,
|
||||||
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
gin_helper::Promise<gin_helper::Dictionary> promise) {
|
||||||
v8::HandleScope scope(promise.isolate());
|
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) {
|
if (chosen == NSModalResponseCancel) {
|
||||||
dict.Set("canceled", true);
|
dict.Set("canceled", true);
|
||||||
dict.Set("filePath", base::FilePath());
|
dict.Set("filePath", base::FilePath());
|
||||||
|
|
|
@ -220,7 +220,7 @@ void ShowOpenDialog(const DialogSettings& settings,
|
||||||
auto done = [](gin_helper::Promise<gin_helper::Dictionary> promise,
|
auto done = [](gin_helper::Promise<gin_helper::Dictionary> promise,
|
||||||
bool success, std::vector<base::FilePath> result) {
|
bool success, std::vector<base::FilePath> result) {
|
||||||
v8::HandleScope handle_scope(promise.isolate());
|
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("canceled", !success);
|
||||||
dict.Set("filePaths", result);
|
dict.Set("filePaths", result);
|
||||||
promise.Resolve(dict);
|
promise.Resolve(dict);
|
||||||
|
@ -269,7 +269,7 @@ void ShowSaveDialog(const DialogSettings& settings,
|
||||||
auto done = [](gin_helper::Promise<gin_helper::Dictionary> promise,
|
auto done = [](gin_helper::Promise<gin_helper::Dictionary> promise,
|
||||||
bool success, base::FilePath result) {
|
bool success, base::FilePath result) {
|
||||||
v8::HandleScope handle_scope(promise.isolate());
|
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("canceled", !success);
|
||||||
dict.Set("filePath", result);
|
dict.Set("filePath", result);
|
||||||
promise.Resolve(dict);
|
promise.Resolve(dict);
|
||||||
|
|
|
@ -203,8 +203,7 @@ void UsbChooserContext::RevokeObjectPermissionInternal(
|
||||||
if (session) {
|
if (session) {
|
||||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
gin_helper::Dictionary details =
|
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||||
gin_helper::Dictionary::CreateEmpty(isolate);
|
|
||||||
details.Set("device", object);
|
details.Set("device", object);
|
||||||
details.Set("origin", origin.Serialize());
|
details.Set("origin", origin.Serialize());
|
||||||
session->Emit("usb-device-revoked", details);
|
session->Emit("usb-device-revoked", details);
|
||||||
|
|
|
@ -204,8 +204,7 @@ void Clipboard::WriteHTML(const std::u16string& html,
|
||||||
v8::Local<v8::Value> Clipboard::ReadBookmark(gin_helper::Arguments* args) {
|
v8::Local<v8::Value> Clipboard::ReadBookmark(gin_helper::Arguments* args) {
|
||||||
std::u16string title;
|
std::u16string title;
|
||||||
std::string url;
|
std::string url;
|
||||||
gin_helper::Dictionary dict =
|
auto dict = gin_helper::Dictionary::CreateEmpty(args->isolate());
|
||||||
gin_helper::Dictionary::CreateEmpty(args->isolate());
|
|
||||||
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
|
||||||
clipboard->ReadBookmark(/* data_dst = */ nullptr, &title, &url);
|
clipboard->ReadBookmark(/* data_dst = */ nullptr, &title, &url);
|
||||||
dict.Set("title", title);
|
dict.Set("title", title);
|
||||||
|
|
|
@ -111,7 +111,7 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path,
|
||||||
base::win::ShortcutOperation operation =
|
base::win::ShortcutOperation operation =
|
||||||
base::win::ShortcutOperation::kCreateAlways;
|
base::win::ShortcutOperation::kCreateAlways;
|
||||||
args->GetNext(&operation);
|
args->GetNext(&operation);
|
||||||
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
|
auto options = gin::Dictionary::CreateEmpty(args->isolate());
|
||||||
if (!args->GetNext(&options)) {
|
if (!args->GetNext(&options)) {
|
||||||
args->ThrowError();
|
args->ThrowError();
|
||||||
return false;
|
return false;
|
||||||
|
@ -146,7 +146,7 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path,
|
||||||
v8::Local<v8::Value> ReadShortcutLink(gin_helper::ErrorThrower thrower,
|
v8::Local<v8::Value> ReadShortcutLink(gin_helper::ErrorThrower thrower,
|
||||||
const base::FilePath& path) {
|
const base::FilePath& path) {
|
||||||
using base::win::ShortcutProperties;
|
using base::win::ShortcutProperties;
|
||||||
gin::Dictionary options = gin::Dictionary::CreateEmpty(thrower.isolate());
|
auto options = gin::Dictionary::CreateEmpty(thrower.isolate());
|
||||||
electron::ScopedAllowBlockingForElectron allow_blocking;
|
electron::ScopedAllowBlockingForElectron allow_blocking;
|
||||||
base::win::ScopedCOMInitializer com_initializer;
|
base::win::ScopedCOMInitializer com_initializer;
|
||||||
base::win::ShortcutProperties properties;
|
base::win::ShortcutProperties properties;
|
||||||
|
|
|
@ -573,8 +573,8 @@ v8::MaybeLocal<v8::Object> CreateProxyForAPI(
|
||||||
|
|
||||||
{
|
{
|
||||||
v8::Context::Scope destination_context_scope(destination_context);
|
v8::Context::Scope destination_context_scope(destination_context);
|
||||||
gin_helper::Dictionary proxy =
|
auto proxy =
|
||||||
gin::Dictionary::CreateEmpty(destination_context->GetIsolate());
|
gin_helper::Dictionary::CreateEmpty(destination_context->GetIsolate());
|
||||||
object_cache->CacheProxiedObject(api.GetHandle(), proxy.GetHandle());
|
object_cache->CacheProxiedObject(api.GetHandle(), proxy.GetHandle());
|
||||||
auto maybe_keys = api.GetHandle()->GetOwnPropertyNames(
|
auto maybe_keys = api.GetHandle()->GetOwnPropertyNames(
|
||||||
source_context, static_cast<v8::PropertyFilter>(v8::ONLY_ENUMERABLE));
|
source_context, static_cast<v8::PropertyFilter>(v8::ONLY_ENUMERABLE));
|
||||||
|
|
Loading…
Reference in a new issue