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
Conversation
47e7126
to
588fa2c
Compare
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.
588fa2c
to
07ef952
Compare
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. |
There was a problem hiding this 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?
@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 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 The intention of this API is to provide a minimal overhead way to subscribe to a given message from a given webContents. |
@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) { |
There was a problem hiding this comment.
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
Is this ready to be merged @MarshallOfSound? |
@MarshallOfSound can you please rebase and resolve the conflicts? |
There was a problem hiding this 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
.
@nornagon I was proposing |
There was a problem hiding this 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
According to the discussions at #16420 and #16468, it seems that this PR is no longer needed since So I'm closing this PR. Please reopen this if anyone still wants to continue this direction. |
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
orsender.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 createipcMain
instances that only emit IPC messages from a specificwebContents