@@ -11,6 +11,7 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
1111import { ExtHostContext , ExtHostWindowShape , IExtHostContext , MainContext , MainThreadWindowShape , IOpenUriOptions } from '../common/extHost.protocol' ;
1212import { ITunnelService , RemoteTunnel } from 'vs/platform/remote/common/tunnel' ;
1313import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
14+ import { extractLocalHostUriMetaDataForPortMapping } from 'vs/workbench/contrib/webview/common/portMapping' ;
1415
1516@extHostNamedCustomer ( MainContext . MainThreadWindow )
1617export class MainThreadWindow implements MainThreadWindowShape {
@@ -48,28 +49,18 @@ export class MainThreadWindow implements MainThreadWindowShape {
4849 async $openUri ( uriComponent : UriComponents , options : IOpenUriOptions ) : Promise < boolean > {
4950 let uri = URI . revive ( uriComponent ) ;
5051 if ( options . allowTunneling && ! ! this . environmentService . configuration . remoteAuthority ) {
51- if ( uri . scheme === 'http' || uri . scheme === 'https' ) {
52- const port = this . getLocalhostPort ( uri ) ;
53- if ( typeof port === 'number' ) {
54- const tunnel = await this . getOrCreateTunnel ( port ) ;
55- if ( tunnel ) {
56- uri = uri . with ( { authority : `localhost:${ tunnel . tunnelLocalPort } ` } ) ;
57- }
52+ const portMappingRequest = extractLocalHostUriMetaDataForPortMapping ( uri ) ;
53+ if ( portMappingRequest ) {
54+ const tunnel = await this . getOrCreateTunnel ( portMappingRequest . port ) ;
55+ if ( tunnel ) {
56+ uri = uri . with ( { authority : `127.0.0.1:${ tunnel . tunnelLocalPort } ` } ) ;
5857 }
5958 }
6059 }
6160
6261 return this . windowsService . openExternal ( uri . toString ( ) ) ;
6362 }
6463
65- private getLocalhostPort ( uri : URI ) : number | undefined {
66- const match = / ^ l o c a l h o s t : ( \d + ) $ / . exec ( uri . authority ) ;
67- if ( match ) {
68- return + match [ 1 ] ;
69- }
70- return undefined ;
71- }
72-
7364 private getOrCreateTunnel ( remotePort : number ) : Promise < RemoteTunnel > | undefined {
7465 const existing = this . _tunnels . get ( remotePort ) ;
7566 if ( existing ) {
0 commit comments