refactor: dispatch IPC messages from Session (#45452)
* refactor: dispatch IPC messages from Session * refactor: move MessageHost to Session
This commit is contained in:
parent
e9ba5876d1
commit
c0422d7cc9
11 changed files with 250 additions and 341 deletions
|
@ -2005,30 +2005,6 @@ bool WebContents::EmitNavigationEvent(
|
|||
return event->GetDefaultPrevented();
|
||||
}
|
||||
|
||||
void WebContents::Message(bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
TRACE_EVENT1("electron", "WebContents::Message", "channel", channel);
|
||||
// webContents.emit('-ipc-message', new Event(), internal, channel,
|
||||
// arguments);
|
||||
EmitWithSender("-ipc-message", render_frame_host,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback(), internal,
|
||||
channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void WebContents::Invoke(
|
||||
bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
TRACE_EVENT1("electron", "WebContents::Invoke", "channel", channel);
|
||||
// webContents.emit('-ipc-invoke', new Event(), internal, channel, arguments);
|
||||
EmitWithSender("-ipc-invoke", render_frame_host, std::move(callback),
|
||||
internal, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void WebContents::OnFirstNonEmptyLayout(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
if (render_frame_host == web_contents()->GetPrimaryMainFrame()) {
|
||||
|
@ -2036,73 +2012,6 @@ void WebContents::OnFirstNonEmptyLayout(
|
|||
}
|
||||
}
|
||||
|
||||
gin::Handle<gin_helper::internal::Event> WebContents::MakeEventWithSender(
|
||||
v8::Isolate* isolate,
|
||||
content::RenderFrameHost* frame,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback) {
|
||||
v8::Local<v8::Object> wrapper;
|
||||
if (!GetWrapper(isolate).ToLocal(&wrapper)) {
|
||||
if (callback) {
|
||||
// We must always invoke the callback if present.
|
||||
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
|
||||
->SendError("WebContents was destroyed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
gin_helper::internal::Event::New(isolate);
|
||||
gin_helper::Dictionary dict(isolate, event.ToV8().As<v8::Object>());
|
||||
dict.Set("type", "frame");
|
||||
if (callback)
|
||||
dict.Set("_replyChannel", gin_helper::internal::ReplyChannel::Create(
|
||||
isolate, std::move(callback)));
|
||||
if (frame) {
|
||||
dict.SetGetter("senderFrame", frame);
|
||||
dict.Set("frameId", frame->GetRoutingID());
|
||||
dict.Set("processId", frame->GetProcess()->GetID().GetUnsafeValue());
|
||||
dict.Set("frameTreeNodeId", frame->GetFrameTreeNodeId());
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
void WebContents::ReceivePostMessage(
|
||||
const std::string& channel,
|
||||
blink::TransferableMessage message,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto wrapped_ports =
|
||||
MessagePort::EntanglePorts(isolate, std::move(message.ports));
|
||||
v8::Local<v8::Value> message_value =
|
||||
electron::DeserializeV8Value(isolate, message);
|
||||
EmitWithSender("-ipc-ports", render_frame_host,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback(), false,
|
||||
channel, message_value, std::move(wrapped_ports));
|
||||
}
|
||||
|
||||
void WebContents::MessageSync(
|
||||
bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
electron::mojom::ElectronApiIPC::MessageSyncCallback callback,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
TRACE_EVENT1("electron", "WebContents::MessageSync", "channel", channel);
|
||||
// webContents.emit('-ipc-message-sync', new Event(sender, message), internal,
|
||||
// channel, arguments);
|
||||
EmitWithSender("-ipc-message-sync", render_frame_host, std::move(callback),
|
||||
internal, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void WebContents::MessageHost(const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
TRACE_EVENT1("electron", "WebContents::MessageHost", "channel", channel);
|
||||
// webContents.emit('ipc-message-host', new Event(), channel, args);
|
||||
EmitWithSender("ipc-message-host", render_frame_host,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback(), channel,
|
||||
std::move(arguments));
|
||||
}
|
||||
|
||||
void WebContents::DraggableRegionsChanged(
|
||||
const std::vector<blink::mojom::DraggableRegionPtr>& regions,
|
||||
content::WebContents* contents) {
|
||||
|
|
|
@ -393,29 +393,6 @@ class WebContents final : public ExclusiveAccessContext,
|
|||
bool EmitNavigationEvent(const std::string& event,
|
||||
content::NavigationHandle* navigation_handle);
|
||||
|
||||
// this.emit(name, new Event(sender, message), args...);
|
||||
template <typename... Args>
|
||||
bool EmitWithSender(const std::string_view name,
|
||||
content::RenderFrameHost* frame,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback,
|
||||
Args&&... args) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
MakeEventWithSender(isolate, frame, std::move(callback));
|
||||
if (event.IsEmpty())
|
||||
return false;
|
||||
EmitWithoutEvent(name, event, std::forward<Args>(args)...);
|
||||
return event->GetDefaultPrevented();
|
||||
}
|
||||
|
||||
gin::Handle<gin_helper::internal::Event> MakeEventWithSender(
|
||||
v8::Isolate* isolate,
|
||||
content::RenderFrameHost* frame,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback);
|
||||
|
||||
WebContents* embedder() { return embedder_; }
|
||||
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
|
@ -448,29 +425,6 @@ class WebContents final : public ExclusiveAccessContext,
|
|||
fullscreen_frame_ = rfh;
|
||||
}
|
||||
|
||||
// mojom::ElectronApiIPC
|
||||
void Message(bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
void Invoke(bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback,
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
void ReceivePostMessage(const std::string& channel,
|
||||
blink::TransferableMessage message,
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
void MessageSync(
|
||||
bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
electron::mojom::ElectronApiIPC::MessageSyncCallback callback,
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
void MessageHost(const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
content::RenderFrameHost* render_frame_host);
|
||||
|
||||
// mojom::ElectronWebContentsUtility
|
||||
void OnFirstNonEmptyLayout(content::RenderFrameHost* render_frame_host);
|
||||
void SetTemporaryZoomLevel(double level);
|
||||
|
|
|
@ -35,15 +35,8 @@ class IpcDispatcher {
|
|||
|
||||
void Invoke(gin::Handle<gin_helper::internal::Event>& event,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback) {
|
||||
TRACE_EVENT1("electron", "IpcHelper::Invoke", "channel", channel);
|
||||
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
gin_helper::Dictionary dict(isolate, event.ToV8().As<v8::Object>());
|
||||
dict.Set("_replyChannel", gin_helper::internal::ReplyChannel::Create(
|
||||
isolate, std::move(callback)));
|
||||
|
||||
blink::CloneableMessage arguments) {
|
||||
TRACE_EVENT1("electron", "IpcDispatcher::Invoke", "channel", channel);
|
||||
emitter()->EmitWithoutEvent("-ipc-invoke", event, channel,
|
||||
std::move(arguments));
|
||||
}
|
||||
|
@ -51,6 +44,8 @@ class IpcDispatcher {
|
|||
void ReceivePostMessage(gin::Handle<gin_helper::internal::Event>& event,
|
||||
const std::string& channel,
|
||||
blink::TransferableMessage message) {
|
||||
TRACE_EVENT1("electron", "IpcDispatcher::ReceivePostMessage", "channel",
|
||||
channel);
|
||||
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto wrapped_ports =
|
||||
|
@ -61,22 +56,22 @@ class IpcDispatcher {
|
|||
std::move(wrapped_ports));
|
||||
}
|
||||
|
||||
void MessageSync(
|
||||
gin::Handle<gin_helper::internal::Event>& event,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
electron::mojom::ElectronApiIPC::MessageSyncCallback callback) {
|
||||
TRACE_EVENT1("electron", "IpcHelper::MessageSync", "channel", channel);
|
||||
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
gin_helper::Dictionary dict(isolate, event.ToV8().As<v8::Object>());
|
||||
dict.Set("_replyChannel", gin_helper::internal::ReplyChannel::Create(
|
||||
isolate, std::move(callback)));
|
||||
|
||||
void MessageSync(gin::Handle<gin_helper::internal::Event>& event,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments) {
|
||||
TRACE_EVENT1("electron", "IpcDispatcher::MessageSync", "channel", channel);
|
||||
emitter()->EmitWithoutEvent("-ipc-message-sync", event, channel,
|
||||
std::move(arguments));
|
||||
}
|
||||
|
||||
void MessageHost(gin::Handle<gin_helper::internal::Event>& event,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments) {
|
||||
TRACE_EVENT1("electron", "IpcDispatcher::MessageHost", "channel", channel);
|
||||
emitter()->EmitWithoutEvent("-ipc-message-host", event, channel,
|
||||
std::move(arguments));
|
||||
}
|
||||
|
||||
private:
|
||||
inline T* emitter() {
|
||||
// T must inherit from gin_helper::EventEmitterMixin<T>
|
||||
|
|
|
@ -8,7 +8,12 @@
|
|||
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "gin/handle.h"
|
||||
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
||||
#include "shell/browser/api/electron_api_session.h"
|
||||
#include "shell/common/gin_converters/content_converter.h"
|
||||
#include "shell/common/gin_converters/frame_converter.h"
|
||||
#include "shell/common/gin_helper/event.h"
|
||||
|
||||
namespace electron {
|
||||
ElectronApiIPCHandlerImpl::ElectronApiIPCHandlerImpl(
|
||||
|
@ -38,57 +43,128 @@ void ElectronApiIPCHandlerImpl::OnConnectionError() {
|
|||
void ElectronApiIPCHandlerImpl::Message(bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments) {
|
||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||
if (api_web_contents) {
|
||||
api_web_contents->Message(internal, channel, std::move(arguments),
|
||||
GetRenderFrameHost());
|
||||
}
|
||||
auto* session = GetSession();
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, internal);
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->Message(event, channel, std::move(arguments));
|
||||
}
|
||||
void ElectronApiIPCHandlerImpl::Invoke(bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
InvokeCallback callback) {
|
||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||
if (api_web_contents) {
|
||||
api_web_contents->Invoke(internal, channel, std::move(arguments),
|
||||
std::move(callback), GetRenderFrameHost());
|
||||
}
|
||||
auto* session = GetSession();
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, internal, std::move(callback));
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->Invoke(event, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void ElectronApiIPCHandlerImpl::ReceivePostMessage(
|
||||
const std::string& channel,
|
||||
blink::TransferableMessage message) {
|
||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||
if (api_web_contents) {
|
||||
api_web_contents->ReceivePostMessage(channel, std::move(message),
|
||||
GetRenderFrameHost());
|
||||
}
|
||||
auto* session = GetSession();
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, false);
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->ReceivePostMessage(event, channel, std::move(message));
|
||||
}
|
||||
|
||||
void ElectronApiIPCHandlerImpl::MessageSync(bool internal,
|
||||
const std::string& channel,
|
||||
blink::CloneableMessage arguments,
|
||||
MessageSyncCallback callback) {
|
||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||
if (api_web_contents) {
|
||||
api_web_contents->MessageSync(internal, channel, std::move(arguments),
|
||||
std::move(callback), GetRenderFrameHost());
|
||||
}
|
||||
auto* session = GetSession();
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, internal, std::move(callback));
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->MessageSync(event, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void ElectronApiIPCHandlerImpl::MessageHost(const std::string& channel,
|
||||
blink::CloneableMessage arguments) {
|
||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||
if (api_web_contents) {
|
||||
api_web_contents->MessageHost(channel, std::move(arguments),
|
||||
GetRenderFrameHost());
|
||||
}
|
||||
auto* session = GetSession();
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, false);
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->MessageHost(event, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
content::RenderFrameHost* ElectronApiIPCHandlerImpl::GetRenderFrameHost() {
|
||||
return content::RenderFrameHost::FromID(render_frame_host_id_);
|
||||
}
|
||||
|
||||
api::Session* ElectronApiIPCHandlerImpl::GetSession() {
|
||||
auto* rfh = GetRenderFrameHost();
|
||||
return rfh ? api::Session::FromBrowserContext(rfh->GetBrowserContext())
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
gin::Handle<gin_helper::internal::Event>
|
||||
ElectronApiIPCHandlerImpl::MakeIPCEvent(
|
||||
v8::Isolate* isolate,
|
||||
api::Session* session,
|
||||
bool internal,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback) {
|
||||
if (!session) {
|
||||
if (callback) {
|
||||
// We must always invoke the callback if present.
|
||||
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
|
||||
->SendError("Session does not exist");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
api::WebContents* api_web_contents = api::WebContents::From(web_contents());
|
||||
if (!api_web_contents) {
|
||||
if (callback) {
|
||||
// We must always invoke the callback if present.
|
||||
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
|
||||
->SendError("WebContents does not exist");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> wrapper;
|
||||
if (!api_web_contents->GetWrapper(isolate).ToLocal(&wrapper)) {
|
||||
if (callback) {
|
||||
// We must always invoke the callback if present.
|
||||
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
|
||||
->SendError("WebContents was destroyed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
content::RenderFrameHost* frame = GetRenderFrameHost();
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
gin_helper::internal::Event::New(isolate);
|
||||
gin_helper::Dictionary dict(isolate, event.ToV8().As<v8::Object>());
|
||||
dict.Set("type", "frame");
|
||||
dict.Set("sender", web_contents());
|
||||
if (internal)
|
||||
dict.SetHidden("internal", internal);
|
||||
if (callback)
|
||||
dict.Set("_replyChannel", gin_helper::internal::ReplyChannel::Create(
|
||||
isolate, std::move(callback)));
|
||||
if (frame) {
|
||||
dict.SetGetter("senderFrame", frame);
|
||||
dict.Set("frameId", frame->GetRoutingID());
|
||||
dict.Set("processId", frame->GetProcess()->GetID().GetUnsafeValue());
|
||||
dict.Set("frameTreeNodeId", frame->GetFrameTreeNodeId());
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
// static
|
||||
void ElectronApiIPCHandlerImpl::Create(
|
||||
content::RenderFrameHost* frame_host,
|
||||
|
|
|
@ -65,6 +65,14 @@ class ElectronApiIPCHandlerImpl : public mojom::ElectronApiIPC,
|
|||
void OnConnectionError();
|
||||
|
||||
content::RenderFrameHost* GetRenderFrameHost();
|
||||
api::Session* GetSession();
|
||||
|
||||
gin::Handle<gin_helper::internal::Event> MakeIPCEvent(
|
||||
v8::Isolate* isolate,
|
||||
api::Session* session,
|
||||
bool internal,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback =
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback());
|
||||
|
||||
content::GlobalRenderFrameHostId render_frame_host_id_;
|
||||
|
||||
|
|
|
@ -71,13 +71,12 @@ void ElectronApiSWIPCHandlerImpl::Message(bool internal,
|
|||
const std::string& channel,
|
||||
blink::CloneableMessage arguments) {
|
||||
auto* session = GetSession();
|
||||
if (session) {
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
MakeIPCEvent(isolate, internal);
|
||||
session->Message(event, channel, std::move(arguments));
|
||||
}
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, internal);
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->Message(event, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void ElectronApiSWIPCHandlerImpl::Invoke(bool internal,
|
||||
|
@ -85,26 +84,24 @@ void ElectronApiSWIPCHandlerImpl::Invoke(bool internal,
|
|||
blink::CloneableMessage arguments,
|
||||
InvokeCallback callback) {
|
||||
auto* session = GetSession();
|
||||
if (session) {
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
MakeIPCEvent(isolate, internal);
|
||||
session->Invoke(event, channel, std::move(arguments), std::move(callback));
|
||||
}
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, internal, std::move(callback));
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->Invoke(event, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void ElectronApiSWIPCHandlerImpl::ReceivePostMessage(
|
||||
const std::string& channel,
|
||||
blink::TransferableMessage message) {
|
||||
auto* session = GetSession();
|
||||
if (session) {
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
MakeIPCEvent(isolate, false);
|
||||
session->ReceivePostMessage(event, channel, std::move(message));
|
||||
}
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, false);
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->ReceivePostMessage(event, channel, std::move(message));
|
||||
}
|
||||
|
||||
void ElectronApiSWIPCHandlerImpl::MessageSync(bool internal,
|
||||
|
@ -112,14 +109,12 @@ void ElectronApiSWIPCHandlerImpl::MessageSync(bool internal,
|
|||
blink::CloneableMessage arguments,
|
||||
MessageSyncCallback callback) {
|
||||
auto* session = GetSession();
|
||||
if (session) {
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
MakeIPCEvent(isolate, internal);
|
||||
session->MessageSync(event, channel, std::move(arguments),
|
||||
std::move(callback));
|
||||
}
|
||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
auto event = MakeIPCEvent(isolate, session, internal, std::move(callback));
|
||||
if (event.IsEmpty())
|
||||
return;
|
||||
session->MessageSync(event, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void ElectronApiSWIPCHandlerImpl::MessageHost(
|
||||
|
@ -139,7 +134,20 @@ api::Session* ElectronApiSWIPCHandlerImpl::GetSession() {
|
|||
}
|
||||
|
||||
gin::Handle<gin_helper::internal::Event>
|
||||
ElectronApiSWIPCHandlerImpl::MakeIPCEvent(v8::Isolate* isolate, bool internal) {
|
||||
ElectronApiSWIPCHandlerImpl::MakeIPCEvent(
|
||||
v8::Isolate* isolate,
|
||||
api::Session* session,
|
||||
bool internal,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback) {
|
||||
if (!session) {
|
||||
if (callback) {
|
||||
// We must always invoke the callback if present.
|
||||
gin_helper::internal::ReplyChannel::Create(isolate, std::move(callback))
|
||||
->SendError("Session does not exist");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
gin::Handle<gin_helper::internal::Event> event =
|
||||
gin_helper::internal::Event::New(isolate);
|
||||
v8::Local<v8::Object> event_object = event.ToV8().As<v8::Object>();
|
||||
|
@ -150,7 +158,11 @@ ElectronApiSWIPCHandlerImpl::MakeIPCEvent(v8::Isolate* isolate, bool internal) {
|
|||
dict.Set("processId", render_process_host_->GetID().GetUnsafeValue());
|
||||
|
||||
// Set session to provide context for getting preloads
|
||||
dict.Set("session", GetSession());
|
||||
dict.Set("session", session);
|
||||
|
||||
if (callback)
|
||||
dict.Set("_replyChannel", gin_helper::internal::ReplyChannel::Create(
|
||||
isolate, std::move(callback)));
|
||||
|
||||
if (internal)
|
||||
dict.SetHidden("internal", internal);
|
||||
|
|
|
@ -70,8 +70,12 @@ class ElectronApiSWIPCHandlerImpl : public mojom::ElectronApiIPC,
|
|||
ElectronBrowserContext* GetBrowserContext();
|
||||
api::Session* GetSession();
|
||||
|
||||
gin::Handle<gin_helper::internal::Event> MakeIPCEvent(v8::Isolate* isolate,
|
||||
bool internal);
|
||||
gin::Handle<gin_helper::internal::Event> MakeIPCEvent(
|
||||
v8::Isolate* isolate,
|
||||
api::Session* session,
|
||||
bool internal,
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback callback =
|
||||
electron::mojom::ElectronApiIPC::InvokeCallback());
|
||||
|
||||
// content::RenderProcessHostObserver
|
||||
void RenderProcessExited(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue