Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add event.senderId property to IPCs sent via ipcRenderer.sendTo #14395

Merged
merged 1 commit into from Sep 1, 2018

Conversation

miniak
Copy link
Contributor

@miniak miniak commented Aug 30, 2018

Description of Change

Currently, it's not possible to tell whether an IPC was sent directly from the main process or from another renderer via renderer.sendTo. This PR adds event.senderId property, which identifies the originating webContents. If the IPC was sent directly from the main process, the value is 0.

The modified spec/api-ipc-renderer-spec.js demonstrates this.

Checklist
  • PR description included and stakeholders cc'd
  • npm test passes
  • tests are changed or added
  • relevant documentation is changed or added
  • PR title follows semantic commit guidelines
Release Notes

Notes: Added event.senderId property to IPCs sent via ipcRenderer.sendTo.

@miniak miniak force-pushed the miniak/sender-id branch 5 times, most recently from fca3fc7 to 618de55 Compare August 30, 2018 23:55
@alexeykuzmin alexeykuzmin removed their request for review August 31, 2018 10:18
@@ -41,7 +41,7 @@ void RemoteCallbackFreer::RunDestructor() {
auto* frame_host = web_contents()->GetMainFrame();
if (frame_host) {
frame_host->Send(new AtomFrameMsg_Message(frame_host->GetRoutingID(), false,
channel, args));
channel, args, 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<...>, args, /* sender_id */ 0));

const {ipcRenderer} = require('electron')
ipcRenderer.on('ping', function (event, id) {
ipcRenderer.sendTo(id, 'pong', id)
ipcRenderer.on('ping', function (event, payload) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipcRenderer is probably undefined here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's exposed by the preload script

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preload: path.join(fixtures, 'module', 'preload-inject-ipc.js'),

@miniak miniak requested a review from a team August 31, 2018 16:26
bool SendIPCMessageWithSender(bool all_frames,
const std::string& channel,
const base::ListValue& args,
int32_t sender_id = 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add this default fourth arg to SendIPCMessage() instead of adding a new function -- do we need both functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not work for methods exposed to JS via mate. The default arguments are ignored. It has to be a separate method unfortunatelly

@ckerr ckerr merged commit c17a1b3 into master Sep 1, 2018
@release-clerk
Copy link

release-clerk bot commented Sep 1, 2018

Release Notes Persisted

Added event.senderId property to IPCs sent via ipcRenderer.sendTo.

@ckerr ckerr deleted the miniak/sender-id branch September 1, 2018 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants