mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
refactor: remove gin_helper::Arguments (#48374)
* refactor: make api::Clipboard::GetClipboardBuffer() private * refactor: move GetClipboadBuffer() into anonymous namespace * refactor: use gin::Arguments in StopRecording() * refactor: use gin::Arguments in ImageView::New() * refactor: use gin::Arguments in AppendSwitch() * refactor: use gin::Arguments WebContentsView::New() * refactor: make gin::Arguments arg const in WrappableBase::InitWithArgs() This makes explicit that we are using it for wrapper + isolate, not the args values * refactor: remove gin_helper::Arguments arg from ExposeAPI() refactor: remove gin_helper::Arguments arg from ExposeAPIInWorld() * refactor: remove gin_helper::Arguments arg from ElectronBindings::GetSystemMemoryInfo() * refactor: remove gin_helper::Arguments arg from preload_utils::GetBinding() * refactor: use gin::Arguments in OpenExternal() * refactor: use gin::Arguments in ExecuteInWorld() * refactor: use gin::Arguments in ExecuteJavaScript() * refactor: use gin::Arguments in InvokeNew() * refactor: use gin::Arguments in ExecuteJavaScriptInIsolatedWorld() * refactor: remove unused GetNextArgument() marshaller for gin_helper::Arguments * refactor: remove unused #include gin_helper/arguments.h * chore: remove unused gin_helper::Arguments * fixup! refactor: use gin::Arguments in ExecuteJavaScriptInIsolatedWorld() Xref: https://github.com/electron/electron/pull/48447
This commit is contained in:
@@ -739,14 +739,13 @@ void ExposeAPI(v8::Isolate* isolate,
|
||||
v8::Isolate* target_isolate,
|
||||
v8::Local<v8::Context> target_context,
|
||||
const std::string& key,
|
||||
v8::Local<v8::Value> api,
|
||||
gin_helper::Arguments* args) {
|
||||
v8::Local<v8::Value> api) {
|
||||
DCHECK(!target_context.IsEmpty());
|
||||
v8::Context::Scope target_context_scope(target_context);
|
||||
gin_helper::Dictionary global(target_isolate, target_context->Global());
|
||||
|
||||
if (global.Has(key)) {
|
||||
args->ThrowError(
|
||||
gin_helper::ErrorThrower{isolate}.ThrowError(
|
||||
"Cannot bind an API on top of an existing property on the window "
|
||||
"object");
|
||||
return;
|
||||
@@ -813,8 +812,7 @@ v8::MaybeLocal<v8::Context> GetTargetContext(v8::Isolate* isolate,
|
||||
void ExposeAPIInWorld(v8::Isolate* isolate,
|
||||
const int world_id,
|
||||
const std::string& key,
|
||||
v8::Local<v8::Value> api,
|
||||
gin_helper::Arguments* args) {
|
||||
v8::Local<v8::Value> api) {
|
||||
TRACE_EVENT2("electron", "ContextBridge::ExposeAPIInWorld", "key", key,
|
||||
"worldId", world_id);
|
||||
v8::Local<v8::Context> source_context = isolate->GetCurrentContext();
|
||||
@@ -825,8 +823,7 @@ void ExposeAPIInWorld(v8::Isolate* isolate,
|
||||
if (maybe_target_context.IsEmpty() || !target_isolate)
|
||||
return;
|
||||
v8::Local<v8::Context> target_context = maybe_target_context.ToLocalChecked();
|
||||
ExposeAPI(isolate, source_context, target_isolate, target_context, key, api,
|
||||
args);
|
||||
ExposeAPI(isolate, source_context, target_isolate, target_context, key, api);
|
||||
}
|
||||
|
||||
gin_helper::Dictionary TraceKeyPath(const gin_helper::Dictionary& start,
|
||||
@@ -923,24 +920,23 @@ bool OverrideGlobalPropertyFromIsolatedWorld(
|
||||
}
|
||||
|
||||
// Serialize script to be executed in the given world.
|
||||
v8::Local<v8::Value> ExecuteInWorld(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> ExecuteInWorld(v8::Isolate* const isolate,
|
||||
const int world_id,
|
||||
gin_helper::Arguments* args) {
|
||||
gin::Arguments* const args) {
|
||||
// Get context of caller
|
||||
v8::Local<v8::Context> source_context = isolate->GetCurrentContext();
|
||||
|
||||
// Get execution script argument
|
||||
gin_helper::Dictionary exec_script;
|
||||
if (args->Length() >= 1 && !args->GetNext(&exec_script)) {
|
||||
gin_helper::ErrorThrower(args->isolate()).ThrowError("Invalid script");
|
||||
args->ThrowTypeError("Invalid script");
|
||||
return v8::Undefined(isolate);
|
||||
}
|
||||
|
||||
// Get "func" from execution script
|
||||
v8::Local<v8::Function> func;
|
||||
if (!exec_script.Get("func", &func)) {
|
||||
gin_helper::ErrorThrower(isolate).ThrowError(
|
||||
"Function 'func' is required in script");
|
||||
args->ThrowTypeError("Function 'func' is required in script");
|
||||
return v8::Undefined(isolate);
|
||||
}
|
||||
|
||||
@@ -949,7 +945,7 @@ v8::Local<v8::Value> ExecuteInWorld(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> args_value;
|
||||
if (exec_script.Get("args", &args_value)) {
|
||||
if (!args_value->IsArray()) {
|
||||
gin_helper::ErrorThrower(isolate).ThrowError("'args' must be an array");
|
||||
args->ThrowTypeError("'args' must be an array");
|
||||
return v8::Undefined(isolate);
|
||||
}
|
||||
args_array = args_value.As<v8::Array>();
|
||||
@@ -961,7 +957,7 @@ v8::Local<v8::Value> ExecuteInWorld(v8::Isolate* isolate,
|
||||
v8::Local<v8::String> serialized_function;
|
||||
if (!func->FunctionProtoToString(isolate->GetCurrentContext())
|
||||
.ToLocal(&serialized_function)) {
|
||||
gin_helper::ErrorThrower(isolate).ThrowError(
|
||||
gin_helper::ErrorThrower{isolate}.ThrowError(
|
||||
"Failed to serialize function");
|
||||
return v8::Undefined(isolate);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/public/renderer/render_frame_observer.h"
|
||||
#include "content/public/renderer/render_frame_visitor.h"
|
||||
#include "gin/arguments.h"
|
||||
#include "gin/object_template_builder.h"
|
||||
#include "services/service_manager/public/cpp/interface_provider.h"
|
||||
#include "shell/common/api/api.mojom.h"
|
||||
@@ -637,12 +638,11 @@ class WebFrameRenderer final
|
||||
return !context->GetContentSecurityPolicy()->ShouldCheckEval();
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> ExecuteJavaScript(gin::Arguments* gin_args,
|
||||
// webFrame.executeJavaScript(code[, userGesture][, callback])
|
||||
v8::Local<v8::Promise> ExecuteJavaScript(gin::Arguments* const args,
|
||||
const std::u16string& code) {
|
||||
gin_helper::Arguments* args = static_cast<gin_helper::Arguments*>(gin_args);
|
||||
|
||||
v8::Isolate* isolate = args->isolate();
|
||||
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
|
||||
v8::Isolate* const isolate = args->isolate();
|
||||
gin_helper::Promise<v8::Local<v8::Value>> promise{isolate};
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
content::RenderFrame* render_frame;
|
||||
@@ -655,10 +655,14 @@ class WebFrameRenderer final
|
||||
const blink::WebScriptSource source{blink::WebString::FromUTF16(code)};
|
||||
|
||||
bool has_user_gesture = false;
|
||||
args->GetNext(&has_user_gesture);
|
||||
if (auto next = args->PeekNext(); !next.IsEmpty() && next->IsBoolean()) {
|
||||
args->GetNext(&has_user_gesture);
|
||||
}
|
||||
|
||||
ScriptExecutionCallback::CompletionCallback completion_callback;
|
||||
args->GetNext(&completion_callback);
|
||||
if (auto next = args->PeekNext(); !next.IsEmpty() && next->IsFunction()) {
|
||||
args->GetNext(&completion_callback);
|
||||
}
|
||||
|
||||
auto* self = new ScriptExecutionCallback(std::move(promise),
|
||||
std::move(completion_callback));
|
||||
@@ -679,14 +683,14 @@ class WebFrameRenderer final
|
||||
return handle;
|
||||
}
|
||||
|
||||
// executeJavaScriptInIsolatedWorld(
|
||||
// worldId, scripts[, userGesture][, callback])
|
||||
v8::Local<v8::Promise> ExecuteJavaScriptInIsolatedWorld(
|
||||
gin::Arguments* gin_args,
|
||||
int world_id,
|
||||
gin::Arguments* const args,
|
||||
const int world_id,
|
||||
const std::vector<gin_helper::Dictionary>& scripts) {
|
||||
gin_helper::Arguments* args = static_cast<gin_helper::Arguments*>(gin_args);
|
||||
|
||||
v8::Isolate* isolate = args->isolate();
|
||||
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
|
||||
v8::Isolate* const isolate = args->isolate();
|
||||
gin_helper::Promise<v8::Local<v8::Value>> promise{isolate};
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
content::RenderFrame* render_frame;
|
||||
@@ -698,10 +702,14 @@ class WebFrameRenderer final
|
||||
}
|
||||
|
||||
bool has_user_gesture = false;
|
||||
args->GetNext(&has_user_gesture);
|
||||
if (auto next = args->PeekNext(); !next.IsEmpty() && next->IsBoolean()) {
|
||||
args->GetNext(&has_user_gesture);
|
||||
}
|
||||
|
||||
ScriptExecutionCallback::CompletionCallback completion_callback;
|
||||
args->GetNext(&completion_callback);
|
||||
if (auto next = args->PeekNext(); !next.IsEmpty() && next->IsFunction()) {
|
||||
args->GetNext(&completion_callback);
|
||||
}
|
||||
|
||||
std::vector<blink::WebScriptSource> sources;
|
||||
sources.reserve(scripts.size());
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "base/process/process.h"
|
||||
#include "base/strings/strcat.h"
|
||||
#include "shell/common/gin_helper/arguments.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
#include "v8/include/v8-context.h"
|
||||
@@ -34,20 +33,19 @@ v8::Local<v8::Object> GetBindingCache(v8::Isolate* isolate) {
|
||||
|
||||
// adapted from node.cc
|
||||
v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
|
||||
v8::Local<v8::String> key,
|
||||
gin_helper::Arguments* margs) {
|
||||
v8::Local<v8::String> key) {
|
||||
v8::Local<v8::Object> exports;
|
||||
std::string binding_key = gin::V8ToString(isolate, key);
|
||||
const std::string binding_key = gin::V8ToString(isolate, key);
|
||||
gin_helper::Dictionary cache(isolate, GetBindingCache(isolate));
|
||||
|
||||
if (cache.Get(binding_key, &exports)) {
|
||||
return exports;
|
||||
}
|
||||
|
||||
auto* mod = node::binding::get_linked_module(binding_key.c_str());
|
||||
|
||||
auto* const mod = node::binding::get_linked_module(binding_key.c_str());
|
||||
if (!mod) {
|
||||
margs->ThrowError(base::StrCat({"No such binding: ", binding_key}));
|
||||
gin_helper::ErrorThrower{isolate}.ThrowError(
|
||||
base::StrCat({"No such binding: ", binding_key}));
|
||||
return exports;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ class Arguments;
|
||||
namespace electron::preload_utils {
|
||||
|
||||
v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
|
||||
v8::Local<v8::String> key,
|
||||
gin_helper::Arguments* margs);
|
||||
v8::Local<v8::String> key);
|
||||
|
||||
v8::Local<v8::Value> CreatePreloadScript(v8::Isolate* isolate,
|
||||
v8::Local<v8::String> source);
|
||||
|
||||
Reference in New Issue
Block a user