Skip to content

Move the webview port mapping from renderer to main process#100342

Merged
mjbvz merged 2 commits intomicrosoft:masterfrom
mjbvz:webview-port-mapping-on-main
Jun 17, 2020
Merged

Move the webview port mapping from renderer to main process#100342
mjbvz merged 2 commits intomicrosoft:masterfrom
mjbvz:webview-port-mapping-on-main

Conversation

@mjbvz
Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz commented Jun 17, 2020

Fixes #95955

Our port mapping implementation for webviews currently relies on getWebContents to handle port mapping in the renderer process. This API has been deprecated by electron. See #95955 for details

This change instead moves the webview port mapping handler to the main process. To support this, I also realized that the tunnel service needed to be moved from vs/workbench to vs/platform so that we could consume it from the main process

Other changes made as part of this refactoring:

  • Register all webview in a webview partition. This ensures that our port mapping manger only intercepts requests made inside webviews.

  • Send the webContentsId to the main process. This is required to implement onBeforeRequest. Unfortunatly the referrer always seems to be undefined for these requests

  • Have the tunnel service take a resolved authority instead of taking the raw authority. This was required due to the tunnel service moving to vs/platform

@mjbvz mjbvz requested review from alexr00, bpasero and deepak1556 June 17, 2020 01:05
@mjbvz mjbvz self-assigned this Jun 17, 2020
@mjbvz mjbvz added this to the June 2020 milestone Jun 17, 2020
Copy link
Copy Markdown
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

I only looked at main.ts and workbench.main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be removed.

Copy link
Copy Markdown
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

I focused my review on tunnel service and remote explorer related files. Thanks for making sure I saw the changes!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this a temporary partition on purpose, because is only to intercept requests in a isolated way and not for persisting data to disk ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes we use partition to make sure that our onBeforeRequest handler only intercepts requests from webviews instead of being fired for all requests

I've also added a filter so that we only intercept localhost requests from webviews

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just to note, if the partition is not persistent that is, if it doesn't start with persist:webview, then the storage for webviews will be temporary, cookies, web storage etc, network auth cache etc or any user data related to the browsing context will not be persisted to disk. Is that the intention here ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, right now webviews are supposed to be entirely ephemeral

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

got it, thanks for confirming!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should use sess.protocol otherwise the unregistration happens on the default session.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch :)

mjbvz added 2 commits June 17, 2020 15:06
Fixes microsoft#95955

Our port mapping impl for webview currently relies on `getWebContents` to handle port mapping in the renderer process. This API has been deprecated by electron.

This change instead moves the webview port mapping handler to the main process. To make this change, I also realized that the tunnel service needed to be moved from `vs/workbench` to `vs/platform` so that we could consume it from the main process

Other changes made as part of this refactoring:

-  Register all webview in a `webview` partition. This ensures that our port mapping manger only intercepts requests made inside webviews.

- Send the `webContentsId` to the main process. This is required to implement `onBeforeRequest`. Unfortunatly the referrer always seems to be undefined for these requests

- Have the tunnel service take a resolved authority instead of taking the raw authority. This was required due to the tunnel service moving to `vs/platform`
@mjbvz mjbvz force-pushed the webview-port-mapping-on-main branch from 2597b45 to 8c4eaa1 Compare June 17, 2020 22:06
@mjbvz mjbvz merged commit f7ec17d into microsoft:master Jun 17, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'webview.getWebContents()' is deprecated and will be removed

4 participants