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 a getScopedToSender API on ipcMain #17489

Closed
wants to merge 2 commits into from

Conversation

MarshallOfSound
Copy link
Member

Description of Change

This solves the usecase where folks for either security or use-case reasons only want to listen for message X coming from webContents Y.

Instead of checking the sender or sender.id each time and hoping you don't miss a listener or writing your own abstraction around IPC (let's be real a lot of us have done that before) this provides a low-overhead first-party API for solving this problem.

This use-case has actually come up in internal core code as well so we can benefit from this API internally. E.g. #17416

I'll add tests and such if we're happy with this approach.

Release Notes

Notes: Added a new ipcMain.getScopedToSender API to create ipcMain instances that only emit IPC messages from a specific webContents

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Mar 20, 2019
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Mar 21, 2019
This solves the usecase where folks for either security or use-case
reasons only want to listen for message X coming from webContents Y.

Instead of checking the `sender` or `sender.id` each time and hoping
you don't miss a listener or writing your own abstraction around IPC
(let's be real we've all done that before) this provides a low-overhead
first-party API for solving this problem.

This use-case has actually come up in internal core code as well so
we can benefit from this API internally.
@MarshallOfSound MarshallOfSound changed the title RFC: feat: add a getScopedToSender API on ipcMain feat: add a getScopedToSender API on ipcMain Mar 21, 2019
@MarshallOfSound MarshallOfSound added the semver/minor backwards-compatible functionality label Mar 21, 2019
@MarshallOfSound MarshallOfSound changed the title feat: add a getScopedToSender API on ipcMain RFC: feat: add a getScopedToSender API on ipcMain Mar 21, 2019
@zcbenz
Copy link
Member

zcbenz commented Mar 26, 2019

The code looks good to me, but I don't have experiences with securing IPC messages so I'm not sure whether the API design is reasonable.

I think we should have actual users commenting whether they would use this API.

@MarshallOfSound MarshallOfSound changed the title RFC: feat: add a getScopedToSender API on ipcMain feat: add a getScopedToSender API on ipcMain Mar 27, 2019
@MarshallOfSound MarshallOfSound changed the title feat: add a getScopedToSender API on ipcMain RFC: feat: add a getScopedToSender API on ipcMain Mar 27, 2019
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

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

This seems like it adds significant complexity and I'm not sure I understand the use case fully. Could you elaborate on the problem you're aiming to solve & maybe list some alternative solutions?

@MarshallOfSound
Copy link
Member Author

@nornagon The high level use-case is the opposite end of targeted sending of messages.

Currently we can say: Send this message to exactly this webContents
But there is no easy way to say: Only notify be about messages from this webContents

Example use cases for caring about that are per-webcontents features or security scoping of IPC messages (you only expect a particular webContents to respond to a certain message).

Either you get messages from all webConents with ipcMain.on('X') or you have to manually filter IPC messages with webContents.on('ipc-message').

The intention of this API is to provide a minimal overhead way to subscribe to a given message from a given webContents.

@MarshallOfSound MarshallOfSound changed the title RFC: feat: add a getScopedToSender API on ipcMain feat: add a getScopedToSender API on ipcMain Apr 30, 2019
@miniak
Copy link
Contributor

miniak commented May 1, 2019

@MarshallOfSound any progress on this?

let handled = false
// If this is the root instance of IpcMain and we have an event with a valid sender
// we should try emit the event on the scoped IpcMain instance
if (this.heirachy === IpcMainHeirachy.ROOT && event && event.sender && event.sender.id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to check event.sender.id anymore

@codebytere
Copy link
Member

Is this ready to be merged @MarshallOfSound?

@miniak
Copy link
Contributor

miniak commented Jun 16, 2019

@MarshallOfSound can you please rebase and resolve the conflicts?

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

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

I'm still somewhat concerned about the complexity here, but separately from that, I think the API should rather be something like

webContents.ipc.on(channel, handler)

rather than being a method on ipcMain.

@miniak
Copy link
Contributor

miniak commented Jun 22, 2019

@nornagon I was proposing webContents.ipc

@miniak
Copy link
Contributor

miniak commented Aug 25, 2019

@nornagon #16420

Copy link
Contributor

@miniak miniak left a comment

Choose a reason for hiding this comment

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

It needs to be updated to support invoke/handle

@zcbenz
Copy link
Member

zcbenz commented Dec 16, 2019

According to the discussions at #16420 and #16468, it seems that this PR is no longer needed since webContents.ipc was proposed to replace this and then webContents.ipc was replaced by the ipc-message event.

So I'm closing this PR. Please reopen this if anyone still wants to continue this direction.

@zcbenz zcbenz closed this Dec 16, 2019
@zcbenz zcbenz deleted the feat/scoped-ipc branch December 16, 2019 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants