8000 chore: remove private webContents.getId() API by zcbenz · Pull Request #13674 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: remove private webContents.getId() API #13674

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

Merged
merged 1 commit into from
Jul 23, 2018

Conversation

zcbenz
Copy link
Contributor
@zcbenz zcbenz commented Jul 16, 2018

With #13603, there is no need to have the private webContents.getId() API, which is very easy to be confused with the public webContents.id property.

The webContents.getId() API has never been documented, after doing a search in GitHub I did not found any app code that used the API, the only users were Electron itself and its forks. So this change will not break apps.

@zcbenz zcbenz requested a review from a team July 16, 2018 07:53
@zcbenz zcbenz force-pushed the remove-web-contents-get-id branch from 1c6226b to 5d22f68 Compare July 16, 2018 07:54
@@ -210,9 +210,9 @@ const unwrapArgs = function (sender, contextId, args) {
return rendererFunctions.get(objectId)
}

const webContentsId = sender.getId()
Copy link
Member

Choose a reason for hiding this comment

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

Should we use sender.id here given some people might be using affinity 🤔 Idk if remote even works properly with affinity but this stands out as being an incompat point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of check here is to ensure that message is not sent to the old page, the WebContents is guaranteed to be the same one so there is no need to compare the sender.id, and messages sent to one WebContents won't be sent to other WebContents with same affinity.

The ID returned by sender.getId() is changed when renderer process is restarted, comparing the processId has the same behavior with the old code. And it is the reason we used sender.getId() instead of sender.id.

The check in main process however can not tell when a WebContents have multiple pages in it, and it is silently checked in the renderer process:

ipcRenderer.on('ELECTRON_RENDERER_CALLBACK', (event, passedContextId, id, args) => {
if (passedContextId !== contextId) {
// The invoked callback belongs to an old page in this renderer.
return
}
callbacksRegistry.apply(id, metaToValue(args))
})

@PalmerAL
Copy link
Contributor

Our app actually does use getId: https://github.com/minbrowser/min/search?q=getid. It doesn't look like it's too hard to migrate, but it might be nice to mention this in the release notes in case other apps are using this as well.

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.

3 participants
0