refactor: migrates util::Promise to gin (#20871)

* refactor: use gin in Promise

* refactor: separate Promise impl that returns nothing

* refactor: use Promise<void> for promise that returns nothing

* fix: methods should be able to run on both browser and renderer process

* fix: should not pass base::StringPiece across threads

* refactor: no more need to use different ResolvePromise for empty Promise

* refactor: move Promise to gin_helper
This commit is contained in:
Cheng Zhao 2019-11-01 15:10:32 +09:00 committed by GitHub
parent bff113760a
commit eaf2c61bef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 483 additions and 479 deletions

View file

@ -18,8 +18,8 @@
#include "shell/common/gin_converters/blink_converter.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_includes.h"
#include "shell/common/promise_util.h"
#include "shell/renderer/api/context_bridge/render_frame_context_bridge_store.h"
#include "shell/renderer/atom_render_frame_observer.h"
#include "third_party/blink/public/web/web_local_frame.h"
@ -153,10 +153,10 @@ v8::MaybeLocal<v8::Value> PassValueToOtherContext(
v8::Context::Scope source_scope(source_context);
{
source_context->GetIsolate()->ThrowException(v8::Exception::TypeError(
mate::StringToV8(source_context->GetIsolate(),
"Electron contextBridge recursion depth exceeded. "
"Nested objects "
"deeper than 1000 are not supported.")));
gin::StringToV8(source_context->GetIsolate(),
"Electron contextBridge recursion depth exceeded. "
"Nested objects "
"deeper than 1000 are not supported.")));
return v8::MaybeLocal<v8::Value>();
}
}
@ -195,13 +195,13 @@ v8::MaybeLocal<v8::Value> PassValueToOtherContext(
v8::Context::Scope destination_scope(destination_context);
{
auto source_promise = v8::Local<v8::Promise>::Cast(value);
auto* proxied_promise = new util::Promise<v8::Local<v8::Value>>(
auto* proxied_promise = new gin_helper::Promise<v8::Local<v8::Value>>(
destination_context->GetIsolate());
v8::Local<v8::Promise> proxied_promise_handle =
proxied_promise->GetHandle();
auto then_cb = base::BindOnce(
[](util::Promise<v8::Local<v8::Value>>* proxied_promise,
[](gin_helper::Promise<v8::Local<v8::Value>>* proxied_promise,
v8::Isolate* isolate,
v8::Global<v8::Context> global_source_context,
v8::Global<v8::Context> global_destination_context,
@ -220,7 +220,7 @@ v8::MaybeLocal<v8::Value> PassValueToOtherContext(
destination_context),
store);
auto catch_cb = base::BindOnce(
[](util::Promise<v8::Local<v8::Value>>* proxied_promise,
[](gin_helper::Promise<v8::Local<v8::Value>>* proxied_promise,
v8::Isolate* isolate,
v8::Global<v8::Context> global_source_context,
v8::Global<v8::Context> global_destination_context,

View file

@ -15,9 +15,9 @@
#include "shell/common/api/api.mojom.h"
#include "shell/common/gin_converters/blink_converter.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_bindings.h"
#include "shell/common/node_includes.h"
#include "shell/common/promise_util.h"
#include "third_party/blink/public/web/web_local_frame.h"
using blink::WebLocalFrame;
@ -90,14 +90,14 @@ class IPCRenderer : public gin::Wrappable<IPCRenderer> {
if (!gin::ConvertFromV8(isolate, arguments, &message)) {
return v8::Local<v8::Promise>();
}
electron::util::Promise<blink::CloneableMessage> p(isolate);
gin_helper::Promise<blink::CloneableMessage> p(isolate);
auto handle = p.GetHandle();
electron_browser_ptr_->get()->Invoke(
internal, channel, std::move(message),
base::BindOnce(
[](electron::util::Promise<blink::CloneableMessage> p,
blink::CloneableMessage result) { p.ResolveWithGin(result); },
[](gin_helper::Promise<blink::CloneableMessage> p,
blink::CloneableMessage result) { p.Resolve(result); },
std::move(p)));
return handle;

View file

@ -16,8 +16,8 @@
#include "shell/common/api/api.mojom.h"
#include "shell/common/gin_converters/blink_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/promise.h"
#include "shell/common/node_includes.h"
#include "shell/common/promise_util.h"
#include "shell/renderer/api/atom_api_spell_check_client.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/blink/public/common/web_cache/web_cache_resource_type_stats.h"
@ -111,7 +111,7 @@ class RenderFrameStatus final : public content::RenderFrameObserver {
class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
public:
explicit ScriptExecutionCallback(
electron::util::Promise<v8::Local<v8::Value>> promise)
gin_helper::Promise<v8::Local<v8::Value>> promise)
: promise_(std::move(promise)) {}
~ScriptExecutionCallback() override = default;
@ -135,7 +135,7 @@ class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
}
private:
electron::util::Promise<v8::Local<v8::Value>> promise_;
gin_helper::Promise<v8::Local<v8::Value>> promise_;
DISALLOW_COPY_AND_ASSIGN(ScriptExecutionCallback);
};
@ -378,7 +378,7 @@ v8::Local<v8::Promise> ExecuteJavaScript(gin_helper::Arguments* args,
v8::Local<v8::Value> window,
const base::string16& code) {
v8::Isolate* isolate = args->isolate();
util::Promise<v8::Local<v8::Value>> promise(isolate);
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
bool has_user_gesture = false;
@ -397,7 +397,7 @@ v8::Local<v8::Promise> ExecuteJavaScriptInIsolatedWorld(
int world_id,
const std::vector<gin_helper::Dictionary>& scripts) {
v8::Isolate* isolate = args->isolate();
util::Promise<v8::Local<v8::Value>> promise(isolate);
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
std::vector<blink::WebScriptSource> sources;