feat: add event.senderId property to IPCs sent via ipcRenderer.sendTo (#14395)
This commit is contained in:
parent
b89848d683
commit
c17a1b37ea
11 changed files with 90 additions and 31 deletions
|
@ -1556,10 +1556,17 @@ void WebContents::TabTraverse(bool reverse) {
|
|||
bool WebContents::SendIPCMessage(bool all_frames,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args) {
|
||||
return SendIPCMessageWithSender(all_frames, channel, args);
|
||||
}
|
||||
|
||||
bool WebContents::SendIPCMessageWithSender(bool all_frames,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id) {
|
||||
auto* frame_host = web_contents()->GetMainFrame();
|
||||
if (frame_host) {
|
||||
return frame_host->Send(new AtomFrameMsg_Message(
|
||||
frame_host->GetRoutingID(), all_frames, channel, args));
|
||||
frame_host->GetRoutingID(), all_frames, channel, args, sender_id));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -2090,7 +2097,7 @@ void WebContents::OnRendererMessageTo(content::RenderFrameHost* frame_host,
|
|||
isolate(), web_contents_id);
|
||||
|
||||
if (web_contents) {
|
||||
web_contents->SendIPCMessage(send_to_all, channel, args);
|
||||
web_contents->SendIPCMessageWithSender(send_to_all, channel, args, ID());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -181,6 +181,11 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
const std::string& channel,
|
||||
const base::ListValue& args);
|
||||
|
||||
bool SendIPCMessageWithSender(bool all_frames,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id = 0);
|
||||
|
||||
// Send WebInputEvent to the page.
|
||||
void SendInputEvent(v8::Isolate* isolate, v8::Local<v8::Value> input_event);
|
||||
|
||||
|
|
|
@ -39,10 +39,11 @@ IPC_MESSAGE_ROUTED4(AtomFrameHostMsg_Message_To,
|
|||
std::string /* channel */,
|
||||
base::ListValue /* arguments */)
|
||||
|
||||
IPC_MESSAGE_ROUTED3(AtomFrameMsg_Message,
|
||||
IPC_MESSAGE_ROUTED4(AtomFrameMsg_Message,
|
||||
bool /* send_to_all */,
|
||||
std::string /* channel */,
|
||||
base::ListValue /* arguments */)
|
||||
base::ListValue /* arguments */,
|
||||
int32_t /* sender_id */)
|
||||
|
||||
IPC_MESSAGE_ROUTED0(AtomViewMsg_Offscreen)
|
||||
|
||||
|
|
|
@ -36,12 +36,13 @@ RemoteCallbackFreer::~RemoteCallbackFreer() {}
|
|||
void RemoteCallbackFreer::RunDestructor() {
|
||||
auto* channel = "ELECTRON_RENDERER_RELEASE_CALLBACK";
|
||||
base::ListValue args;
|
||||
int32_t sender_id = 0;
|
||||
args.AppendString(context_id_);
|
||||
args.AppendInteger(object_id_);
|
||||
auto* frame_host = web_contents()->GetMainFrame();
|
||||
if (frame_host) {
|
||||
frame_host->Send(new AtomFrameMsg_Message(frame_host->GetRoutingID(), false,
|
||||
channel, args));
|
||||
channel, args, sender_id));
|
||||
}
|
||||
|
||||
Observe(nullptr);
|
||||
|
|
|
@ -169,7 +169,8 @@ bool AtomRenderFrameObserver::OnMessageReceived(const IPC::Message& message) {
|
|||
|
||||
void AtomRenderFrameObserver::OnBrowserMessage(bool send_to_all,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args) {
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id) {
|
||||
// Don't handle browser messages before document element is created.
|
||||
// When we receive a message from the browser, we try to transfer it
|
||||
// to a web page, and when we do that Blink creates an empty
|
||||
|
@ -182,21 +183,22 @@ void AtomRenderFrameObserver::OnBrowserMessage(bool send_to_all,
|
|||
if (!frame || !render_frame_->IsMainFrame())
|
||||
return;
|
||||
|
||||
EmitIPCEvent(frame, channel, args);
|
||||
EmitIPCEvent(frame, channel, args, sender_id);
|
||||
|
||||
// Also send the message to all sub-frames.
|
||||
if (send_to_all) {
|
||||
for (blink::WebFrame* child = frame->FirstChild(); child;
|
||||
child = child->NextSibling())
|
||||
if (child->IsWebLocalFrame()) {
|
||||
EmitIPCEvent(child->ToWebLocalFrame(), channel, args);
|
||||
EmitIPCEvent(child->ToWebLocalFrame(), channel, args, sender_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AtomRenderFrameObserver::EmitIPCEvent(blink::WebLocalFrame* frame,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args) {
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id) {
|
||||
if (!frame)
|
||||
return;
|
||||
|
||||
|
@ -218,6 +220,7 @@ void AtomRenderFrameObserver::EmitIPCEvent(blink::WebLocalFrame* frame,
|
|||
// Insert the Event object, event.sender is ipc.
|
||||
mate::Dictionary event = mate::Dictionary::CreateEmpty(isolate);
|
||||
event.Set("sender", ipc);
|
||||
event.Set("senderId", sender_id);
|
||||
args_vector.insert(args_vector.begin(), event.GetHandle());
|
||||
mate::EmitEvent(isolate, ipc, channel, args_vector);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
|
|||
protected:
|
||||
virtual void EmitIPCEvent(blink::WebLocalFrame* frame,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args);
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id);
|
||||
|
||||
private:
|
||||
bool ShouldNotifyClient(int world_id);
|
||||
|
@ -54,7 +55,8 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
|
|||
bool IsIsolatedWorld(int world_id);
|
||||
void OnBrowserMessage(bool send_to_all,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args);
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id);
|
||||
|
||||
content::RenderFrame* render_frame_;
|
||||
RendererClientBase* renderer_client_;
|
||||
|
|
|
@ -107,7 +107,8 @@ class AtomSandboxedRenderFrameObserver : public AtomRenderFrameObserver {
|
|||
protected:
|
||||
void EmitIPCEvent(blink::WebLocalFrame* frame,
|
||||
const std::string& channel,
|
||||
const base::ListValue& args) override {
|
||||
const base::ListValue& args,
|
||||
int32_t sender_id) override {
|
||||
if (!frame)
|
||||
return;
|
||||
|
||||
|
@ -116,7 +117,8 @@ class AtomSandboxedRenderFrameObserver : public AtomRenderFrameObserver {
|
|||
auto context = frame->MainWorldScriptContext();
|
||||
v8::Context::Scope context_scope(context);
|
||||
v8::Local<v8::Value> argv[] = {mate::ConvertToV8(isolate, channel),
|
||||
mate::ConvertToV8(isolate, args)};
|
||||
mate::ConvertToV8(isolate, args),
|
||||
mate::ConvertToV8(isolate, sender_id)};
|
||||
renderer_client_->InvokeIpcCallback(
|
||||
context, "onMessage",
|
||||
std::vector<v8::Local<v8::Value>>(argv, argv + node::arraysize(argv)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue