mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-15 08:23:37 +01:00
Add resourceUriProvider API
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)}`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ResolverResult> {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user