Merge from vscode 2cd495805cf99b31b6926f08ff4348124b2cf73d

This commit is contained in:
ADS Merger
2020-06-30 04:40:21 +00:00
committed by AzureDataStudio
parent a8a7559229
commit 1388493cc1
602 changed files with 16375 additions and 12940 deletions

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { VSBuffer, VSBufferReadableStream } from 'vs/base/common/buffer';
import { VSBufferReadableStream } from 'vs/base/common/buffer';
import { CancellationToken } from 'vs/base/common/cancellation';
import { isUNC } from 'vs/base/common/extpath';
import { Schemas } from 'vs/base/common/network';
@@ -11,14 +11,12 @@ import { sep } from 'vs/base/common/path';
import { URI } from 'vs/base/common/uri';
import { IFileService } from 'vs/platform/files/common/files';
import { IRemoteConnectionData } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
import { IRequestService } from 'vs/platform/request/common/request';
import { getWebviewContentMimeType } from 'vs/platform/webview/common/mimeTypes';
export const webviewPartitionId = 'webview';
export namespace WebviewResourceResponse {
export enum Type { Success, Failed, AccessDenied }
@@ -31,73 +29,41 @@ export namespace WebviewResourceResponse {
) { }
}
export class BufferSuccess {
readonly type = Type.Success;
constructor(
public readonly buffer: VSBuffer,
public readonly mimeType: string
) { }
}
export const Failed = { type: Type.Failed } as const;
export const AccessDenied = { type: Type.AccessDenied } as const;
export type BufferResponse = BufferSuccess | typeof Failed | typeof AccessDenied;
export type StreamResponse = StreamSuccess | typeof Failed | typeof AccessDenied;
}
export async function loadLocalResource(
requestUri: URI,
fileService: IFileService,
extensionLocation: URI | undefined,
roots: ReadonlyArray<URI>
): Promise<WebviewResourceResponse.BufferResponse> {
const resourceToLoad = getResourceToLoad(requestUri, extensionLocation, roots);
if (!resourceToLoad) {
return WebviewResourceResponse.AccessDenied;
}
try {
const data = await fileService.readFile(resourceToLoad);
const mime = getWebviewContentMimeType(requestUri); // Use the original path for the mime
return new WebviewResourceResponse.BufferSuccess(data.value, mime);
} catch (err) {
console.log(err);
return WebviewResourceResponse.Failed;
}
}
export async function loadLocalResourceStream(
requestUri: URI,
options: {
extensionLocation: URI | undefined;
roots: ReadonlyArray<URI>;
remoteConnectionData?: IRemoteConnectionData | null;
rewriteUri?: (uri: URI) => URI,
},
fileService: IFileService,
requestService: IRequestService,
): Promise<WebviewResourceResponse.StreamResponse> {
const resourceToLoad = getResourceToLoad(requestUri, options.extensionLocation, options.roots);
let resourceToLoad = getResourceToLoad(requestUri, options.roots);
if (!resourceToLoad) {
return WebviewResourceResponse.AccessDenied;
}
const mime = getWebviewContentMimeType(requestUri); // Use the original path for the mime
if (options.remoteConnectionData) {
// Remote uris must go to the resolved server.
if (resourceToLoad.scheme === Schemas.vscodeRemote || (options.extensionLocation?.scheme === REMOTE_HOST_SCHEME)) {
const uri = URI.parse(`http://${options.remoteConnectionData.host}:${options.remoteConnectionData.port}`).with({
path: '/vscode-remote-resource',
query: `tkn=${options.remoteConnectionData.connectionToken}&path=${encodeURIComponent(resourceToLoad.path)}`,
});
// Perform extra normalization if needed
if (options.rewriteUri) {
resourceToLoad = options.rewriteUri(resourceToLoad);
}
const response = await requestService.request({ url: uri.toString(true) }, CancellationToken.None);
if (response.res.statusCode === 200) {
return new WebviewResourceResponse.StreamSuccess(response.stream, mime);
}
return WebviewResourceResponse.Failed;
if (resourceToLoad.scheme === Schemas.http || resourceToLoad.scheme === Schemas.https) {
const response = await requestService.request({ url: resourceToLoad.toString(true) }, CancellationToken.None);
if (response.res.statusCode === 200) {
return new WebviewResourceResponse.StreamSuccess(response.stream, mime);
}
return WebviewResourceResponse.Failed;
}
try {
@@ -111,7 +77,6 @@ export async function loadLocalResourceStream(
function getResourceToLoad(
requestUri: URI,
extensionLocation: URI | undefined,
roots: ReadonlyArray<URI>
): URI | undefined {
const normalizedPath = normalizeRequestPath(requestUri);

View File

@@ -13,7 +13,7 @@ export const IWebviewManagerService = createDecorator<IWebviewManagerService>('w
export interface IWebviewManagerService {
_serviceBrand: unknown;
registerWebview(id: string, webContentsId: number, metadata: RegisterWebviewMetadata): Promise<void>;
registerWebview(id: string, webContentsId: number | undefined, metadata: RegisterWebviewMetadata): Promise<void>;
unregisterWebview(id: string): Promise<void>;
updateWebviewMetadata(id: string, metadataDelta: Partial<RegisterWebviewMetadata>): Promise<void>;

View File

@@ -72,7 +72,7 @@ export class WebviewPortMappingManager implements IDisposable {
if (existing) {
return existing;
}
const tunnel = this.tunnelService.openTunnel(remoteAuthority, undefined, remotePort);
const tunnel = this.tunnelService.openTunnel({ getAddress: async () => remoteAuthority }, undefined, remotePort);
if (tunnel) {
this._tunnels.set(remotePort, tunnel);
}