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

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

Merged
merged 2 commits into from
Jun 17, 2020

Conversation

mjbvz
Copy link
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 bpasero, deepak1556 and alexr00 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
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

@@ -468,10 +470,12 @@ export class NativeWindow extends Disposable {
// Register external URI resolver
this.openerService.registerExternalUriResolver({
resolveExternalUri: async (uri: URI, options?: OpenOptions) => {
console.log('xxxxxxx');
Copy link
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
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!

@@ -15,6 +15,10 @@ import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
import { IRequestService } from 'vs/platform/request/common/request';
import { getWebviewContentMimeType } from 'vs/platform/webview/common/mimeTypes';


export const webviewPartitionId = 'webview';
Copy link
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
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
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
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
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!

return callback(redirect ? { redirectURL: redirect } : {});
});

this._register(toDisposable(() => protocol.unregisterProtocol(Schemas.vscodeWebviewResource)));
Copy link
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
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