diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 28fbfc82f45..2b42d7f00a2 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -1193,7 +1193,7 @@ export function asDomUri(uri: URI): URI { return uri; } if (Schemas.vscodeRemote === uri.scheme) { - return RemoteAuthorities.rewrite(uri.authority, uri.path); + return RemoteAuthorities.rewrite(uri); } return uri; } diff --git a/src/vs/base/common/network.ts b/src/vs/base/common/network.ts index 4f93e06df0b..01c7df0fdda 100644 --- a/src/vs/base/common/network.ts +++ b/src/vs/base/common/network.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { URI } from 'vs/base/common/uri'; +import { URI, UriComponents } from 'vs/base/common/uri'; import * as platform from 'vs/base/common/platform'; export namespace Schemas { @@ -60,18 +60,24 @@ class RemoteAuthoritiesImpl { private readonly _ports: { [authority: string]: number; }; private readonly _connectionTokens: { [authority: string]: string; }; private _preferredWebSchema: 'http' | 'https'; + private _delegate: ((uri: URI) => UriComponents) | null; constructor() { this._hosts = Object.create(null); this._ports = Object.create(null); this._connectionTokens = Object.create(null); this._preferredWebSchema = 'http'; + this._delegate = null; } public setPreferredWebSchema(schema: 'http' | 'https') { this._preferredWebSchema = schema; } + public setDelegate(delegate: (uri: URI) => UriComponents): void { + this._delegate = delegate; + } + public set(authority: string, host: string, port: number): void { this._hosts[authority] = host; this._ports[authority] = port; @@ -81,7 +87,12 @@ class RemoteAuthoritiesImpl { this._connectionTokens[authority] = connectionToken; } - public rewrite(authority: string, path: string): URI { + public rewrite(uri: URI): URI { + if (this._delegate) { + const result = this._delegate(uri); + return URI.revive(result); + } + const authority = uri.authority; const host = this._hosts[authority]; const port = this._ports[authority]; const connectionToken = this._connectionTokens[authority]; @@ -89,7 +100,7 @@ class RemoteAuthoritiesImpl { scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource, authority: `${host}:${port}`, path: `/vscode-remote-resource`, - query: `path=${encodeURIComponent(path)}&tkn=${encodeURIComponent(connectionToken)}` + query: `path=${encodeURIComponent(uri.path)}&tkn=${encodeURIComponent(connectionToken)}` }); } } diff --git a/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts b/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts index 17bded22f29..fa22819f880 100644 --- a/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts +++ b/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts @@ -5,12 +5,18 @@ import { ResolvedAuthority, IRemoteAuthorityResolverService, ResolverResult } from 'vs/platform/remote/common/remoteAuthorityResolver'; import { RemoteAuthorities } from 'vs/base/common/network'; +import { URI, UriComponents } from 'vs/base/common/uri'; export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverService { _serviceBrand: undefined; - constructor() { + constructor( + resourceUriProvider: ((uri: URI) => UriComponents) | undefined + ) { + if (resourceUriProvider) { + RemoteAuthorities.setDelegate(resourceUriProvider); + } } resolveAuthority(authority: string): Promise { diff --git a/src/vs/workbench/browser/web.main.ts b/src/vs/workbench/browser/web.main.ts index 7d214b18c39..bddde603d45 100644 --- a/src/vs/workbench/browser/web.main.ts +++ b/src/vs/workbench/browser/web.main.ts @@ -142,7 +142,7 @@ class CodeRendererMain extends Disposable { serviceCollection.set(IProductService, productService); // Remote - const remoteAuthorityResolverService = new RemoteAuthorityResolverService(); + const remoteAuthorityResolverService = new RemoteAuthorityResolverService(this.configuration.resourceUriProvider); serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService); // Signing diff --git a/src/vs/workbench/workbench.web.api.ts b/src/vs/workbench/workbench.web.api.ts index 845c3ac35b0..ece8a708cbb 100644 --- a/src/vs/workbench/workbench.web.api.ts +++ b/src/vs/workbench/workbench.web.api.ts @@ -5,7 +5,7 @@ import 'vs/workbench/workbench.web.main'; import { main } from 'vs/workbench/browser/web.main'; -import { UriComponents } from 'vs/base/common/uri'; +import { UriComponents, URI } from 'vs/base/common/uri'; import { IFileSystemProvider } from 'vs/platform/files/common/files'; import { IWebSocketFactory } from 'vs/platform/remote/browser/browserSocketFactory'; import { ICredentialsProvider } from 'vs/workbench/services/credentials/browser/credentialsService'; @@ -53,6 +53,11 @@ export interface IWorkbenchConstructionOptions { */ webSocketFactory?: IWebSocketFactory; + /** + * A provider for resource URIs. + */ + resourceUriProvider?: (uri: URI) => UriComponents; + /** * Experimental: Whether to enable the smoke test driver. */