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
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue