refactor: dispatch IPC messages from Session (#45452)

* refactor: dispatch IPC messages from Session

* refactor: move MessageHost to Session
This commit is contained in:
Sam Maddock 2025-02-17 16:36:28 -05:00 committed by GitHub
parent e9ba5876d1
commit c0422d7cc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 250 additions and 341 deletions

View file

@ -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>