Skip to content

Commit 0358d08

Browse files
committed
Re-use extractLocalHostUriMetaDataForPortMapping for openUri
1 parent d27ab54 commit 0358d08

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

src/vs/workbench/api/browser/mainThreadWindow.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
1111
import { ExtHostContext, ExtHostWindowShape, IExtHostContext, MainContext, MainThreadWindowShape, IOpenUriOptions } from '../common/extHost.protocol';
1212
import { ITunnelService, RemoteTunnel } from 'vs/platform/remote/common/tunnel';
1313
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
14+
import { extractLocalHostUriMetaDataForPortMapping } from 'vs/workbench/contrib/webview/common/portMapping';
1415

1516
@extHostNamedCustomer(MainContext.MainThreadWindow)
1617
export 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 = /^localhost:(\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

Comments
 (0)