From 0358d08196cece5b0652cd87528b0ebc409e0d7f Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 21 Jun 2019 17:39:02 -0700 Subject: [PATCH] Re-use extractLocalHostUriMetaDataForPortMapping for openUri --- .../workbench/api/browser/mainThreadWindow.ts | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadWindow.ts b/src/vs/workbench/api/browser/mainThreadWindow.ts index c9a212e4863..533dbb62eae 100644 --- a/src/vs/workbench/api/browser/mainThreadWindow.ts +++ b/src/vs/workbench/api/browser/mainThreadWindow.ts @@ -11,6 +11,7 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; import { ExtHostContext, ExtHostWindowShape, IExtHostContext, MainContext, MainThreadWindowShape, IOpenUriOptions } from '../common/extHost.protocol'; import { ITunnelService, RemoteTunnel } from 'vs/platform/remote/common/tunnel'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; +import { extractLocalHostUriMetaDataForPortMapping } from 'vs/workbench/contrib/webview/common/portMapping'; @extHostNamedCustomer(MainContext.MainThreadWindow) export class MainThreadWindow implements MainThreadWindowShape { @@ -48,13 +49,11 @@ export class MainThreadWindow implements MainThreadWindowShape { async $openUri(uriComponent: UriComponents, options: IOpenUriOptions): Promise { let uri = URI.revive(uriComponent); if (options.allowTunneling && !!this.environmentService.configuration.remoteAuthority) { - if (uri.scheme === 'http' || uri.scheme === 'https') { - const port = this.getLocalhostPort(uri); - if (typeof port === 'number') { - const tunnel = await this.getOrCreateTunnel(port); - if (tunnel) { - uri = uri.with({ authority: `localhost:${tunnel.tunnelLocalPort}` }); - } + const portMappingRequest = extractLocalHostUriMetaDataForPortMapping(uri); + if (portMappingRequest) { + const tunnel = await this.getOrCreateTunnel(portMappingRequest.port); + if (tunnel) { + uri = uri.with({ authority: `127.0.0.1:${tunnel.tunnelLocalPort}` }); } } } @@ -62,14 +61,6 @@ export class MainThreadWindow implements MainThreadWindowShape { return this.windowsService.openExternal(uri.toString()); } - private getLocalhostPort(uri: URI): number | undefined { - const match = /^localhost:(\d+)$/.exec(uri.authority); - if (match) { - return +match[1]; - } - return undefined; - } - private getOrCreateTunnel(remotePort: number): Promise | undefined { const existing = this._tunnels.get(remotePort); if (existing) { -- GitLab