diff --git a/src/vs/workbench/api/browser/mainThreadWorkspace.ts b/src/vs/workbench/api/browser/mainThreadWorkspace.ts index 062c43408a0..30ebb309289 100644 --- a/src/vs/workbench/api/browser/mainThreadWorkspace.ts +++ b/src/vs/workbench/api/browser/mainThreadWorkspace.ts @@ -70,6 +70,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape { this._contextService.onDidChangeWorkspaceFolders(this._onDidChangeWorkspace, this, this._toDispose); this._contextService.onDidChangeWorkbenchState(this._onDidChangeWorkspace, this, this._toDispose); this._workspaceTrustManagementService.onDidChangeTrust(this._onDidGrantWorkspaceTrust, this, this._toDispose); + this._workspaceTrustManagementService.onDidChangeTrustedFolders(this._onDidChangeWorkspaceTrustedFolders, this, this._toDispose); } dispose(): void { @@ -251,6 +252,12 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape { return this._workspaceTrustRequestService.requestWorkspaceTrust(options); } + async $isResourceTrusted(resource: UriComponents): Promise { + const uri = URI.revive(resource); + const trustInfo = await this._workspaceTrustManagementService.getUriTrustInfo(uri); + return trustInfo.trusted; + } + private isWorkspaceTrusted(): boolean { return this._workspaceTrustManagementService.isWorkspaceTrusted(); } @@ -259,6 +266,10 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape { this._proxy.$onDidGrantWorkspaceTrust(); } + private _onDidChangeWorkspaceTrustedFolders(): void { + this._proxy.$onDidChangeWorkspaceTrustedFolders(); + } + // --- edit sessions --- private registeredEditSessionProviders = new Map(); diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 21cb7bb1839..0f9b9ec6e87 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1271,6 +1271,14 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I checkProposedApiEnabled(extension, 'workspaceTrust'); return extHostWorkspace.requestWorkspaceTrust(options); }, + isResourceTrusted: (resource: vscode.Uri) => { + checkProposedApiEnabled(extension, 'workspaceTrust'); + return extHostWorkspace.isResourceTrusted(resource); + }, + onDidChangeWorkspaceTrustedFolders: (listener, thisArgs?, disposables?) => { + checkProposedApiEnabled(extension, 'workspaceTrust'); + return _asExtensionEvent(extHostWorkspace.onDidChangeWorkspaceTrustedFolders)(listener, thisArgs, disposables); + }, onDidGrantWorkspaceTrust: (listener, thisArgs?, disposables?) => { return _asExtensionEvent(extHostWorkspace.onDidGrantWorkspaceTrust)(listener, thisArgs, disposables); }, diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index cb2b3cd4b1f..305568f3b3d 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1613,6 +1613,7 @@ export interface MainThreadWorkspaceShape extends IDisposable { $loadCertificates(): Promise; $requestResourceTrust(options: ResourceTrustRequestOptionsDto): Promise; $requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise; + $isResourceTrusted(resource: UriComponents): Promise; $registerEditSessionIdentityProvider(handle: number, scheme: string): void; $unregisterEditSessionIdentityProvider(handle: number): void; $registerCanonicalUriProvider(handle: number, scheme: string): void; @@ -2096,6 +2097,7 @@ export interface ExtHostWorkspaceShape { $acceptWorkspaceData(workspace: IWorkspaceData | null): void; $handleTextSearchResult(result: search.IRawFileMatch2, requestId: number): void; $onDidGrantWorkspaceTrust(): void; + $onDidChangeWorkspaceTrustedFolders(): void; $getEditSessionIdentifier(folder: UriComponents, token: CancellationToken): Promise; $provideEditSessionIdentityMatch(folder: UriComponents, identity1: string, identity2: string, token: CancellationToken): Promise; $onWillCreateEditSessionIdentity(folder: UriComponents, token: CancellationToken, timeout: number): Promise; diff --git a/src/vs/workbench/api/common/extHostWorkspace.ts b/src/vs/workbench/api/common/extHostWorkspace.ts index 89b4ecf179a..55ca51e9a64 100644 --- a/src/vs/workbench/api/common/extHostWorkspace.ts +++ b/src/vs/workbench/api/common/extHostWorkspace.ts @@ -189,6 +189,9 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac private readonly _onDidGrantWorkspaceTrust = new Emitter(); readonly onDidGrantWorkspaceTrust: Event = this._onDidGrantWorkspaceTrust.event; + private readonly _onDidChangeWorkspaceTrustedFolders = new Emitter(); + readonly onDidChangeWorkspaceTrustedFolders: Event = this._onDidChangeWorkspaceTrustedFolders.event; + private readonly _logService: ILogService; private readonly _requestIdProvider: Counter; private readonly _barrier: Barrier; @@ -821,6 +824,14 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac } } + $onDidChangeWorkspaceTrustedFolders(): void { + this._onDidChangeWorkspaceTrustedFolders.fire(); + } + + isResourceTrusted(resource: vscode.Uri): Promise { + return this._proxy.$isResourceTrusted(resource); + } + // --- edit sessions --- private _providerHandlePool = 0; diff --git a/src/vscode-dts/vscode.proposed.workspaceTrust.d.ts b/src/vscode-dts/vscode.proposed.workspaceTrust.d.ts index 2c8edbd9d18..aad6987c2b5 100644 --- a/src/vscode-dts/vscode.proposed.workspaceTrust.d.ts +++ b/src/vscode-dts/vscode.proposed.workspaceTrust.d.ts @@ -34,6 +34,17 @@ declare module 'vscode' { } export namespace workspace { + /** + * Event fired when the list of workspace trusted folders changes. + */ + export const onDidChangeWorkspaceTrustedFolders: Event; + + /** + * Check whether the given resource is trusted + * @param resource + */ + export function isResourceTrusted(resource: Uri): Thenable; + /** * Prompt the user to chose whether to trust the specified resource (ex: folder) * @param options Object describing the properties of the resource trust request.