From c5fab4faa3719bfa382f26e3c8fd8e46a82a7b40 Mon Sep 17 00:00:00 2001 From: SteVen Batten <6561887+sbatten@users.noreply.github.com> Date: Tue, 13 Apr 2021 12:54:52 -0700 Subject: [PATCH] Boolean Trust State (#121141) * move to boolean-based trust state * update api based on feedback --- .../src/tsServer/versionManager.ts | 18 +- .../workspace/common/workspaceTrust.ts | 47 ++-- src/vs/vscode.proposed.d.ts | 46 +--- .../api/browser/mainThreadWorkspace.ts | 18 +- .../workbench/api/common/extHost.api.impl.ts | 8 +- .../workbench/api/common/extHost.protocol.ts | 10 +- .../workbench/api/common/extHostWorkspace.ts | 27 +-- .../browser/preferencesRenderers.ts | 6 +- .../preferences/browser/settingsEditor2.ts | 12 +- .../preferences/browser/settingsTreeModels.ts | 23 +- .../tasks/browser/abstractTaskService.ts | 4 +- .../tasks/browser/runAutomaticTasks.ts | 6 +- .../browser/workspace.contribution.ts | 63 +++--- .../workspace/browser/workspaceTrustEditor.ts | 104 ++++----- .../workspace/browser/workspaceTrustTree.ts | 13 +- .../configuration/browser/configuration.ts | 27 +-- .../browser/configurationService.ts | 26 +-- .../test/browser/configurationService.test.ts | 27 ++- .../browser/extensionEnablementService.ts | 18 +- .../workspaces/common/workspaceTrust.ts | 201 +++++++----------- .../test/common/testWorkspaceTrustService.ts | 26 +-- .../browser/api/extHostConfiguration.test.ts | 9 +- .../test/browser/api/extHostWorkspace.test.ts | 3 +- 23 files changed, 306 insertions(+), 436 deletions(-) diff --git a/extensions/typescript-language-features/src/tsServer/versionManager.ts b/extensions/typescript-language-features/src/tsServer/versionManager.ts index 0115ced57c1..edf1540252d 100644 --- a/extensions/typescript-language-features/src/tsServer/versionManager.ts +++ b/extensions/typescript-language-features/src/tsServer/versionManager.ts @@ -32,7 +32,7 @@ export class TypeScriptVersionManager extends Disposable { this._currentVersion = this.versionProvider.defaultVersion; if (this.useWorkspaceTsdkSetting) { - if (this.isWorkspaceTrusted) { + if (vscode.workspace.isTrusted) { const localVersion = this.versionProvider.localVersion; if (localVersion) { this._currentVersion = localVersion; @@ -40,8 +40,8 @@ export class TypeScriptVersionManager extends Disposable { } else { setImmediate(() => { vscode.workspace.requestWorkspaceTrust({ modal: false }) - .then(trustState => { - if (trustState === vscode.WorkspaceTrustState.Trusted && this.versionProvider.localVersion) { + .then(trusted => { + if (trusted && this.versionProvider.localVersion) { this.updateActiveVersion(this.versionProvider.localVersion); } else { this.updateActiveVersion(this.versionProvider.defaultVersion); @@ -99,7 +99,7 @@ export class TypeScriptVersionManager extends Disposable { private getBundledPickItem(): QuickPickItem { const bundledVersion = this.versionProvider.defaultVersion; return { - label: (!this.useWorkspaceTsdkSetting || !this.isWorkspaceTrusted + label: (!this.useWorkspaceTsdkSetting || !vscode.workspace.isTrusted ? '• ' : '') + localize('useVSCodeVersionOption', "Use VS Code's Version"), description: bundledVersion.displayName, @@ -114,14 +114,14 @@ export class TypeScriptVersionManager extends Disposable { private getLocalPickItems(): QuickPickItem[] { return this.versionProvider.localVersions.map(version => { return { - label: (this.useWorkspaceTsdkSetting && this.isWorkspaceTrusted && this.currentVersion.eq(version) + label: (this.useWorkspaceTsdkSetting && vscode.workspace.isTrusted && this.currentVersion.eq(version) ? '• ' : '') + localize('useWorkspaceVersionOption', "Use Workspace Version"), description: version.displayName, detail: version.pathLabel, run: async () => { - const trustState = await vscode.workspace.requestWorkspaceTrust(); - if (trustState === vscode.WorkspaceTrustState.Trusted) { + const trusted = await vscode.workspace.requestWorkspaceTrust({ modal: true }); + if (trusted) { await this.workspaceState.update(useWorkspaceTsdkStorageKey, true); const tsConfig = vscode.workspace.getConfiguration('typescript'); await tsConfig.update('tsdk', version.pathLabel, false); @@ -165,10 +165,6 @@ export class TypeScriptVersionManager extends Disposable { } } - private get isWorkspaceTrusted(): boolean { - return vscode.workspace.trustState === vscode.WorkspaceTrustState.Trusted; - } - private get useWorkspaceTsdkSetting(): boolean { return this.workspaceState.get(useWorkspaceTsdkStorageKey, false); } diff --git a/src/vs/platform/workspace/common/workspaceTrust.ts b/src/vs/platform/workspace/common/workspaceTrust.ts index e9fe74304d6..2bd4b56fd01 100644 --- a/src/vs/platform/workspace/common/workspaceTrust.ts +++ b/src/vs/platform/workspace/common/workspaceTrust.ts @@ -13,21 +13,11 @@ export enum WorkspaceTrustScope { Remote = 1 } -export enum WorkspaceTrustState { - Untrusted = 0, - Trusted = 1, - Unspecified = 2 -} - -export function workspaceTrustStateToString(trustState: WorkspaceTrustState) { - switch (trustState) { - case WorkspaceTrustState.Trusted: - return localize('trusted', "Trusted"); - case WorkspaceTrustState.Untrusted: - return localize('untrusted', "Untrusted"); - case WorkspaceTrustState.Unspecified: - default: - return localize('unspecified', "Unspecified"); +export function workspaceTrustToString(trustState: boolean) { + if (trustState) { + return localize('trusted', "Trusted"); + } else { + return localize('untrusted', "Untrusted"); } } @@ -42,13 +32,7 @@ export interface WorkspaceTrustRequestOptions { readonly modal: boolean; } -export interface WorkspaceTrustStateChangeEvent { - readonly previousTrustState: WorkspaceTrustState; - readonly currentTrustState: WorkspaceTrustState; -} - -export type WorkspaceTrustChangeEvent = Event; - +export type WorkspaceTrustChangeEvent = Event; export const IWorkspaceTrustStorageService = createDecorator('workspaceTrustStorageService'); export interface IWorkspaceTrustStorageService { @@ -56,11 +40,10 @@ export interface IWorkspaceTrustStorageService { readonly onDidStorageChange: Event; - setFoldersTrustState(folder: URI[], trustState: WorkspaceTrustState): void; - getFoldersTrustState(folder: URI[]): WorkspaceTrustState; + setFoldersTrust(folders: URI[], trusted: boolean): void; + getFoldersTrust(folders: URI[]): boolean; setTrustedFolders(folders: URI[]): void; - setUntrustedFolders(folders: URI[]): void; getFolderTrustStateInfo(folder: URI): IWorkspaceTrustUriInfo; getTrustStateInfo(): IWorkspaceTrustStateInfo; @@ -71,9 +54,9 @@ export const IWorkspaceTrustManagementService = createDecorator; - readonly onDidCompleteWorkspaceTrustRequest: Event; + readonly onDidCompleteWorkspaceTrustRequest: Event; cancelRequest(): void; - completeRequest(trustState?: WorkspaceTrustState): void; - requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise; + completeRequest(trusted?: boolean): void; + requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise; } export interface IWorkspaceTrustUriInfo { uri: URI, - trustState: WorkspaceTrustState + trusted: boolean } export interface IWorkspaceTrustStateInfo { diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 5bb17c3890a..6960ad4bf1d 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -2832,66 +2832,34 @@ declare module 'vscode' { //#endregion //#region https://github.com/microsoft/vscode/issues/120173 - - export enum WorkspaceTrustState { - /** - * The workspace is untrusted, and it will have limited functionality. - */ - Untrusted = 0, - - /** - * The workspace is trusted, and all functionality will be available. - */ - Trusted = 1, - - /** - * The initial state of the workspace. - * - * If trust will be required, users will be prompted to make a choice. - */ - Unspecified = 2 - } - - /** - * The event data that is fired when the trust state of the workspace changes. - * When trust is revoked, the workspace will be reloaded. Therefore, extensions are - * not expected to handle transitions out of a trusted state. - */ - export interface WorkspaceTrustStateChangeEvent { - /** - * New trust state of the workspace - */ - readonly newTrustState: WorkspaceTrustState; - } - /** * The object describing the properties of the workspace trust request */ export interface WorkspaceTrustRequestOptions { /** * When true, a modal dialog will be used to request workspace trust. - * When false, a badge will be displayed on the Setting activity bar item + * When false, a badge will be displayed on the settings gear activity bar item. */ readonly modal: boolean; } export namespace workspace { /** - * The trust state of the current workspace + * When true, the user has explicitly trusted the contents of the workspace. */ - export const trustState: WorkspaceTrustState; + export const isTrusted: boolean; /** * Prompt the user to chose whether to trust the current workspace * @param options Optional object describing the properties of the - * workspace trust request + * workspace trust request. Defaults to { modal: false } */ - export function requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Thenable; + export function requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Thenable; /** - * Event that fires when the trust state of the current workspace changes + * Event that fires when the current workspace has been trusted. */ - export const onDidChangeWorkspaceTrustState: Event; + export const onDidReceiveWorkspaceTrust: Event; } //#endregion diff --git a/src/vs/workbench/api/browser/mainThreadWorkspace.ts b/src/vs/workbench/api/browser/mainThreadWorkspace.ts index 0b7a0897491..046b15b9db0 100644 --- a/src/vs/workbench/api/browser/mainThreadWorkspace.ts +++ b/src/vs/workbench/api/browser/mainThreadWorkspace.ts @@ -16,7 +16,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { ILabelService } from 'vs/platform/label/common/label'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { IRequestService } from 'vs/platform/request/common/request'; -import { WorkspaceTrustStateChangeEvent, WorkspaceTrustRequestOptions, WorkspaceTrustState, IWorkspaceTrustManagementService, IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust'; +import { WorkspaceTrustRequestOptions, IWorkspaceTrustManagementService, IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust'; import { IWorkspace, IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { isUntitledWorkspace } from 'vs/platform/workspaces/common/workspaces'; import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers'; @@ -55,13 +55,13 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape { // The workspace file is provided be a unknown file system provider. It might come // from the extension host. So initialize now knowing that `rootPath` is undefined. if (workspace.configuration && !isNative && !fileService.canHandleResource(workspace.configuration)) { - this._proxy.$initializeWorkspace(this.getWorkspaceData(workspace), this.getWorkspaceTrustState()); + this._proxy.$initializeWorkspace(this.getWorkspaceData(workspace), this.isWorkspaceTrusted()); } else { - this._contextService.getCompleteWorkspace().then(workspace => this._proxy.$initializeWorkspace(this.getWorkspaceData(workspace), this.getWorkspaceTrustState())); + this._contextService.getCompleteWorkspace().then(workspace => this._proxy.$initializeWorkspace(this.getWorkspaceData(workspace), this.isWorkspaceTrusted())); } this._contextService.onDidChangeWorkspaceFolders(this._onDidChangeWorkspace, this, this._toDispose); this._contextService.onDidChangeWorkbenchState(this._onDidChangeWorkspace, this, this._toDispose); - this._workspaceTrustManagementService.onDidChangeTrustState(this._onDidChangeWorkspaceTrustState, this, this._toDispose); + this._workspaceTrustManagementService.onDidChangeTrust(this._onDidReceiveWorkspaceTrust, this, this._toDispose); } dispose(): void { @@ -209,15 +209,15 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape { // --- trust --- - $requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise { + $requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise { return this._workspaceTrustRequestService.requestWorkspaceTrust(options); } - private getWorkspaceTrustState(): WorkspaceTrustState { - return this._workspaceTrustManagementService.getWorkspaceTrustState(); + private isWorkspaceTrusted(): boolean { + return this._workspaceTrustManagementService.isWorkpaceTrusted(); } - private _onDidChangeWorkspaceTrustState(state: WorkspaceTrustStateChangeEvent): void { - this._proxy.$onDidChangeWorkspaceTrustState(state); + private _onDidReceiveWorkspaceTrust(): void { + this._proxy.$onDidReceiveWorkspaceTrust(); } } diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 3c70a7a439c..ef6d28b19a4 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -916,16 +916,16 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I checkProposedApiEnabled(extension); return extHostTimeline.registerTimelineProvider(scheme, provider, extension.identifier, extHostCommands.converter); }, - get trustState() { + get isTrusted() { checkProposedApiEnabled(extension); - return extHostWorkspace.trustState; + return extHostWorkspace.trusted; }, requestWorkspaceTrust: (options?: vscode.WorkspaceTrustRequestOptions) => { checkProposedApiEnabled(extension); return extHostWorkspace.requestWorkspaceTrust(options); }, - onDidChangeWorkspaceTrustState: (listener, thisArgs?, disposables?) => { - return extHostWorkspace.onDidChangeWorkspaceTrustState(listener, thisArgs, disposables); + onDidReceiveWorkspaceTrust: (listener, thisArgs?, disposables?) => { + return extHostWorkspace.onDidReceiveWorkspaceTrust(listener, thisArgs, disposables); } }; diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 4c32b731674..70faea5a357 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -53,12 +53,12 @@ import { revive } from 'vs/base/common/marshalling'; import { NotebookCellMetadata, NotebookDocumentMetadata, ICellEditOperation, NotebookCellsChangedEventDto, NotebookDataDto, IMainCellDto, INotebookDocumentFilter, TransientMetadata, INotebookCellStatusBarEntry, ICellRange, INotebookDecorationRenderOptions, INotebookExclusiveDocumentFilter, IOutputDto, TransientOptions, IImmediateCellEditOperation } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy'; import { Dto } from 'vs/base/common/types'; -import { DebugConfigurationProviderTriggerKind, TestResultState, WorkspaceTrustState } from 'vs/workbench/api/common/extHostTypes'; +import { DebugConfigurationProviderTriggerKind, TestResultState } from 'vs/workbench/api/common/extHostTypes'; import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility'; import { IExtensionIdWithVersion } from 'vs/platform/userDataSync/common/extensionsStorageSync'; import { InternalTestItem, RunTestForProviderRequest, RunTestsRequest, TestIdWithSrc, TestsDiff, ISerializedTestResults, ITestMessage } from 'vs/workbench/contrib/testing/common/testCollection'; import { CandidatePort } from 'vs/workbench/services/remote/common/remoteExplorerService'; -import { WorkspaceTrustRequestOptions, WorkspaceTrustStateChangeEvent } from 'vs/platform/workspace/common/workspaceTrust'; +import { WorkspaceTrustRequestOptions } from 'vs/platform/workspace/common/workspaceTrust'; import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable'; import { IShellLaunchConfig, IShellLaunchConfigDto, ITerminalDimensions, ITerminalEnvironment, ITerminalLaunchError } from 'vs/platform/terminal/common/terminal'; import { ITerminalProfile } from 'vs/workbench/contrib/terminal/common/terminal'; @@ -951,7 +951,7 @@ export interface MainThreadWorkspaceShape extends IDisposable { $saveAll(includeUntitled?: boolean): Promise; $updateWorkspaceFolders(extensionName: string, index: number, deleteCount: number, workspaceFoldersToAdd: { uri: UriComponents, name?: string; }[]): Promise; $resolveProxy(url: string): Promise; - $requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise; + $requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise; } export interface IFileChangeDto { @@ -1230,10 +1230,10 @@ export interface ExtHostTreeViewsShape { } export interface ExtHostWorkspaceShape { - $initializeWorkspace(workspace: IWorkspaceData | null, trustState: WorkspaceTrustState): void; + $initializeWorkspace(workspace: IWorkspaceData | null, trusted: boolean): void; $acceptWorkspaceData(workspace: IWorkspaceData | null): void; $handleTextSearchResult(result: search.IRawFileMatch2, requestId: number): void; - $onDidChangeWorkspaceTrustState(state: WorkspaceTrustStateChangeEvent): void; + $onDidReceiveWorkspaceTrust(): void; } export interface ExtHostFileSystemInfoShape { diff --git a/src/vs/workbench/api/common/extHostWorkspace.ts b/src/vs/workbench/api/common/extHostWorkspace.ts index ec03b94d47e..e89ad13926b 100644 --- a/src/vs/workbench/api/common/extHostWorkspace.ts +++ b/src/vs/workbench/api/common/extHostWorkspace.ts @@ -20,12 +20,11 @@ import { FileSystemProviderCapabilities } from 'vs/platform/files/common/files'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { ILogService } from 'vs/platform/log/common/log'; import { Severity } from 'vs/platform/notification/common/notification'; -import { WorkspaceTrustStateChangeEvent } from 'vs/platform/workspace/common/workspaceTrust'; import { Workspace, WorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo'; import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService'; import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; -import { Range, RelativePattern, WorkspaceTrustState } from 'vs/workbench/api/common/extHostTypes'; +import { Range, RelativePattern } from 'vs/workbench/api/common/extHostTypes'; import { ITextQueryBuilderOptions } from 'vs/workbench/contrib/search/common/queryBuilder'; import { IRawFileMatch2, resultIsMatch } from 'vs/workbench/services/search/common/search'; import * as vscode from 'vscode'; @@ -169,8 +168,8 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac private readonly _onDidChangeWorkspace = new Emitter(); readonly onDidChangeWorkspace: Event = this._onDidChangeWorkspace.event; - private readonly _onDidChangeWorkspaceTrustState = new Emitter(); - readonly onDidChangeWorkspaceTrustState: Event = this._onDidChangeWorkspaceTrustState.event; + private readonly _onDidReceieveWorkspaceTrust = new Emitter(); + readonly onDidReceiveWorkspaceTrust: Event = this._onDidReceieveWorkspaceTrust.event; private readonly _logService: ILogService; private readonly _requestIdProvider: Counter; @@ -185,7 +184,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac private readonly _activeSearchCallbacks: ((match: IRawFileMatch2) => any)[] = []; - private _workspaceTrustState: WorkspaceTrustState = WorkspaceTrustState.Unspecified; + private _trusted: boolean = false; constructor( @IExtHostRpcService extHostRpc: IExtHostRpcService, @@ -204,8 +203,8 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac this._confirmedWorkspace = data ? new ExtHostWorkspaceImpl(data.id, data.name, [], data.configuration ? URI.revive(data.configuration) : null, !!data.isUntitled, uri => ignorePathCasing(uri, extHostFileSystemInfo)) : undefined; } - $initializeWorkspace(data: IWorkspaceData | null, trustState: WorkspaceTrustState): void { - this._workspaceTrustState = trustState; + $initializeWorkspace(data: IWorkspaceData | null, trusted: boolean): void { + this._trusted = trusted; this.$acceptWorkspaceData(data); this._barrier.open(); } @@ -559,17 +558,19 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac // --- trust --- - get trustState(): WorkspaceTrustState { - return this._workspaceTrustState; + get trusted(): boolean { + return this._trusted; } - requestWorkspaceTrust(options?: vscode.WorkspaceTrustRequestOptions): Promise { + requestWorkspaceTrust(options?: vscode.WorkspaceTrustRequestOptions): Promise { return this._proxy.$requestWorkspaceTrust(options); } - $onDidChangeWorkspaceTrustState(state: WorkspaceTrustStateChangeEvent): void { - this._workspaceTrustState = state.currentTrustState; - this._onDidChangeWorkspaceTrustState.fire(Object.freeze({ newTrustState: state.currentTrustState })); + $onDidReceiveWorkspaceTrust(): void { + if (!this._trusted) { + this._trusted = true; + this._onDidReceieveWorkspaceTrust.fire(); + } } } diff --git a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts index fba0b91f2c3..8a78a702829 100644 --- a/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts +++ b/src/vs/workbench/contrib/preferences/browser/preferencesRenderers.ts @@ -34,7 +34,7 @@ import { EditorOption } from 'vs/editor/common/config/editorOptions'; import { FindDecorations } from 'vs/editor/contrib/find/findDecorations'; import { ThemeIcon } from 'vs/platform/theme/common/themeService'; import { settingsEditIcon } from 'vs/workbench/contrib/preferences/browser/preferencesIcons'; -import { IWorkspaceTrustManagementService, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; +import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust'; import * as modes from 'vs/editor/common/modes'; import { CancellationToken } from 'vs/base/common/cancellation'; import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; @@ -1059,7 +1059,7 @@ class UnsupportedSettingsRenderer extends Disposable implements modes.CodeAction markerData.push(this.generateUnsupportedMachineSettingMarker(setting)); } - if (this.workspaceTrustManagementService.getWorkspaceTrustState() !== WorkspaceTrustState.Trusted && configuration.requireTrust) { + if (!this.workspaceTrustManagementService.isWorkpaceTrusted() && configuration.requireTrust) { const marker = this.generateUntrustedSettingMarker(setting); markerData.push(marker); const codeActions = this.generateUntrustedSettingCodeActions([marker]); @@ -1085,7 +1085,7 @@ class UnsupportedSettingsRenderer extends Disposable implements modes.CodeAction }); } - if (this.workspaceTrustManagementService.getWorkspaceTrustState() !== WorkspaceTrustState.Trusted && configuration.requireTrust) { + if (!this.workspaceTrustManagementService.isWorkpaceTrusted() && configuration.requireTrust) { const marker = this.generateUntrustedSettingMarker(setting); markerData.push(marker); const codeActions = this.generateUntrustedSettingCodeActions([marker]); diff --git a/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts b/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts index c3d87f4de5e..2b35defd7ce 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsEditor2.ts @@ -204,13 +204,13 @@ export class SettingsEditor2 extends EditorPane { } })); - this._register(workspaceTrustManagementService.onDidChangeTrustState(() => { + this._register(workspaceTrustManagementService.onDidChangeTrust(() => { if (this.searchResultModel) { - this.searchResultModel.updateWorkspaceTrustState(workspaceTrustManagementService.getWorkspaceTrustState()); + this.searchResultModel.updateWorkspaceTrust(workspaceTrustManagementService.isWorkpaceTrusted()); } if (this.settingsTreeModel) { - this.settingsTreeModel.updateWorkspaceTrustState(workspaceTrustManagementService.getWorkspaceTrustState()); + this.settingsTreeModel.updateWorkspaceTrust(workspaceTrustManagementService.isWorkpaceTrusted()); } })); @@ -1012,7 +1012,7 @@ export class SettingsEditor2 extends EditorPane { this.refreshTOCTree(); this.renderTree(undefined, forceRefresh); } else { - this.settingsTreeModel = this.instantiationService.createInstance(SettingsTreeModel, this.viewState, this.workspaceTrustManagementService.getWorkspaceTrustState()); + this.settingsTreeModel = this.instantiationService.createInstance(SettingsTreeModel, this.viewState, this.workspaceTrustManagementService.isWorkpaceTrusted()); this.settingsTreeModel.update(resolvedSettingsRoot); this.tocTreeModel.settingsTreeRoot = this.settingsTreeModel.root as SettingsTreeGroupElement; @@ -1205,7 +1205,7 @@ export class SettingsEditor2 extends EditorPane { * Return a fake SearchResultModel which can hold a flat list of all settings, to be filtered (@modified etc) */ private createFilterModel(): SearchResultModel { - const filterModel = this.instantiationService.createInstance(SearchResultModel, this.viewState, this.workspaceTrustManagementService.getWorkspaceTrustState()); + const filterModel = this.instantiationService.createInstance(SearchResultModel, this.viewState, this.workspaceTrustManagementService.isWorkpaceTrusted()); const fullResult: ISearchResult = { filterMatches: [] @@ -1311,7 +1311,7 @@ export class SettingsEditor2 extends EditorPane { } if (!this.searchResultModel) { - this.searchResultModel = this.instantiationService.createInstance(SearchResultModel, this.viewState, this.workspaceTrustManagementService.getWorkspaceTrustState()); + this.searchResultModel = this.instantiationService.createInstance(SearchResultModel, this.viewState, this.workspaceTrustManagementService.isWorkpaceTrusted()); this.searchResultModel.setResult(type, result); this.tocTreeModel.currentSearchModel = this.searchResultModel; this.onSearchModeToggled(); diff --git a/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts b/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts index f298d392635..c81447a943d 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts @@ -18,7 +18,6 @@ import { FOLDER_SCOPES, WORKSPACE_SCOPES, REMOTE_MACHINE_SCOPES, LOCAL_MACHINE_S import { IJSONSchema } from 'vs/base/common/jsonSchema'; import { Disposable } from 'vs/base/common/lifecycle'; import { Emitter } from 'vs/base/common/event'; -import { WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; export const ONLINE_SERVICES_SETTING_TAG = 'usesOnlineServices'; @@ -141,12 +140,12 @@ export class SettingsTreeSettingElement extends SettingsTreeElement { description!: string; valueType!: SettingValueType; - constructor(setting: ISetting, parent: SettingsTreeGroupElement, inspectResult: IInspectResult, workspaceTrustState: WorkspaceTrustState) { + constructor(setting: ISetting, parent: SettingsTreeGroupElement, inspectResult: IInspectResult, isWorkspaceTrusted: boolean) { super(sanitizeId(parent.id + '_' + setting.key)); this.setting = setting; this.parent = parent; - this.update(inspectResult, workspaceTrustState); + this.update(inspectResult, isWorkspaceTrusted); } get displayCategory(): string { @@ -171,13 +170,13 @@ export class SettingsTreeSettingElement extends SettingsTreeElement { this._displayCategory = displayKeyFormat.category; } - update(inspectResult: IInspectResult, workspaceTrustState: WorkspaceTrustState): void { + update(inspectResult: IInspectResult, isWorkspaceTrusted: boolean): void { const { isConfigured, inspected, targetSelector } = inspectResult; switch (targetSelector) { case 'workspaceFolderValue': case 'workspaceValue': - this.isUntrusted = !!this.setting.requireTrust && workspaceTrustState !== WorkspaceTrustState.Trusted; + this.isUntrusted = !!this.setting.requireTrust && !isWorkspaceTrusted; break; } @@ -353,7 +352,7 @@ export class SettingsTreeModel { constructor( protected _viewState: ISettingsEditorViewState, - private _workspaceTrustState: WorkspaceTrustState, + private _isWorkspaceTrusted: boolean, @IConfigurationService private readonly _configurationService: IConfigurationService, ) { } @@ -378,8 +377,8 @@ export class SettingsTreeModel { } } - updateWorkspaceTrustState(workspaceTrustState: WorkspaceTrustState): void { - this._workspaceTrustState = workspaceTrustState; + updateWorkspaceTrust(workspaceTrusted: boolean): void { + this._isWorkspaceTrusted = workspaceTrusted; this.updateRequireTrustedTargetElements(); } @@ -416,7 +415,7 @@ export class SettingsTreeModel { private updateSettings(settings: SettingsTreeSettingElement[]): void { settings.forEach(element => { const inspectResult = inspectSetting(element.setting.key, this._viewState.settingsTarget, this._configurationService); - element.update(inspectResult, this._workspaceTrustState); + element.update(inspectResult, this._isWorkspaceTrusted); }); } @@ -452,7 +451,7 @@ export class SettingsTreeModel { private createSettingsTreeSettingElement(setting: ISetting, parent: SettingsTreeGroupElement): SettingsTreeSettingElement { const inspectResult = inspectSetting(setting.key, this._viewState.settingsTarget, this._configurationService); - const element = new SettingsTreeSettingElement(setting, parent, inspectResult, this._workspaceTrustState); + const element = new SettingsTreeSettingElement(setting, parent, inspectResult, this._isWorkspaceTrusted); const nameElements = this._treeElementsBySettingName.get(setting.key) || []; nameElements.push(element); @@ -622,11 +621,11 @@ export class SearchResultModel extends SettingsTreeModel { constructor( viewState: ISettingsEditorViewState, - workspaceTrustState: WorkspaceTrustState, + isWorkspaceTrusted: boolean, @IConfigurationService configurationService: IConfigurationService, @IWorkbenchEnvironmentService private environmentService: IWorkbenchEnvironmentService, ) { - super(viewState, workspaceTrustState, configurationService); + super(viewState, isWorkspaceTrusted, configurationService); this.update({ id: 'searchResultModel', label: '' }); } diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index e147713673a..92d99cb0501 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -80,7 +80,7 @@ import { isWorkspaceFolder, TaskQuickPickEntry, QUICKOPEN_DETAIL_CONFIG, TaskQui import { ILogService } from 'vs/platform/log/common/log'; import { once } from 'vs/base/common/functional'; import { ThemeIcon } from 'vs/platform/theme/common/themeService'; -import { IWorkspaceTrustRequestService, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; +import { IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust'; const QUICKOPEN_HISTORY_LIMIT_CONFIG = 'task.quickOpen.history'; const PROBLEM_MATCHER_NEVER_CONFIG = 'task.problemMatchers.neverPrompt'; @@ -2457,7 +2457,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer { modal: true, message: nls.localize('TaskService.requestTrust', "Listing and running tasks requires that some of the files in this workspace be executed as code.") - })) === WorkspaceTrustState.Trusted; + })) === true; } private runTaskCommand(arg?: any): void { diff --git a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts index 6af8fdcff7f..5d47d73a4ab 100644 --- a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts +++ b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts @@ -15,7 +15,7 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/ import { IQuickPickItem, IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; import { Action2 } from 'vs/platform/actions/common/actions'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; -import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; +import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust'; import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; import { IOpenerService } from 'vs/platform/opener/common/opener'; import { URI } from 'vs/base/common/uri'; @@ -30,7 +30,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut @IWorkspaceTrustRequestService workspaceTrustRequestService: IWorkspaceTrustRequestService) { super(); const isFolderAutomaticAllowed = storageService.getBoolean(ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE, StorageScope.WORKSPACE, undefined); - const isWorkspaceTrusted = workspaceTrustManagementService.getWorkspaceTrustState() === WorkspaceTrustState.Trusted; + const isWorkspaceTrusted = workspaceTrustManagementService.isWorkpaceTrusted(); this.tryRunTasks(isFolderAutomaticAllowed && isWorkspaceTrusted); } @@ -117,7 +117,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut public static async promptForPermission(taskService: ITaskService, storageService: IStorageService, notificationService: INotificationService, workspaceTrustRequestService: IWorkspaceTrustRequestService, openerService: IOpenerService, workspaceTaskResult: Map) { - const isWorkspaceTrusted = await workspaceTrustRequestService.requestWorkspaceTrust({ modal: false }) === WorkspaceTrustState.Trusted; + const isWorkspaceTrusted = await workspaceTrustRequestService.requestWorkspaceTrust({ modal: false }); if (!isWorkspaceTrusted) { return; } diff --git a/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts b/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts index 44bb94f3a77..c9cb1b14575 100644 --- a/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts +++ b/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts @@ -13,7 +13,7 @@ import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { Severity } from 'vs/platform/notification/common/notification'; import { Registry } from 'vs/platform/registry/common/platform'; -import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService, WorkspaceTrustState, WorkspaceTrustStateChangeEvent, workspaceTrustStateToString } from 'vs/platform/workspace/common/workspaceTrust'; +import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService, workspaceTrustToString } from 'vs/platform/workspace/common/workspaceTrust'; import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; import { IActivityService, IconBadge } from 'vs/workbench/services/activity/common/activity'; import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; @@ -132,7 +132,7 @@ export class WorkspaceTrustRequestHandler extends Disposable implements IWorkben // Dialog result switch (buttons[result.choice].type) { case 'ContinueWithTrust': - this.workspaceTrustRequestService.completeRequest(WorkspaceTrustState.Trusted); + this.workspaceTrustRequestService.completeRequest(true); break; case 'ContinueWithoutTrust': this.workspaceTrustRequestService.completeRequest(undefined); @@ -148,38 +148,35 @@ export class WorkspaceTrustRequestHandler extends Disposable implements IWorkben } })); - this._register(this.workspaceTrustRequestService.onDidCompleteWorkspaceTrustRequest(trustState => { - if (trustState !== undefined && trustState !== WorkspaceTrustState.Unspecified) { + this._register(this.workspaceTrustRequestService.onDidCompleteWorkspaceTrustRequest(trusted => { + if (trusted) { this.toggleRequestBadge(false); } })); - this._register(this.workspaceTrustManagementService.onDidChangeTrustState(async (trustState) => { + this._register(this.workspaceTrustManagementService.onDidChangeTrust(async (trusted) => { type WorkspaceTrustStateChangedEvent = { workspaceId: string, - previousState: WorkspaceTrustState, - newState: WorkspaceTrustState + trusted: boolean }; type WorkspaceTrustStateChangedEventClassification = { workspaceId: { classification: 'SystemMetaData', purpose: 'FeatureInsight' }; - previousState: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true }; - newState: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true }; + trusted: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true }; }; this.telemetryService.publicLog2('workspaceTrustStateChanged', { workspaceId: this.workspaceContextService.getWorkspace().id, - previousState: trustState.previousTrustState, - newState: trustState.currentTrustState + trusted: trusted }); - // Transition from Trusted -> Untrusted/Unknown - if (trustState.previousTrustState === WorkspaceTrustState.Trusted && trustState.currentTrustState !== WorkspaceTrustState.Trusted) { + // Transition from Trusted -> Untrusted + if (!trusted) { this.hostService.reload(); } // Hide soft request badge - if (trustState.currentTrustState !== undefined && trustState.currentTrustState !== WorkspaceTrustState.Unspecified) { + if (trusted) { this.toggleRequestBadge(false); } })); @@ -210,27 +207,27 @@ class WorkspaceTrustStatusbarItem extends Disposable implements IWorkbenchContri this.statusBarEntryAccessor = this._register(new MutableDisposable()); if (this.workspaceTrustManagementService.isWorkspaceTrustEnabled()) { - const entry = this.getStatusbarEntry(this.workspaceTrustManagementService.getWorkspaceTrustState()); + const entry = this.getStatusbarEntry(this.workspaceTrustManagementService.isWorkpaceTrusted()); this.statusBarEntryAccessor.value = this.statusbarService.addEntry(entry, WorkspaceTrustStatusbarItem.ID, localize('status.WorkspaceTrust', "Workspace Trust"), StatusbarAlignment.LEFT, 0.99 * Number.MAX_VALUE /* Right of remote indicator */); - this._register(this.workspaceTrustManagementService.onDidChangeTrustState(trustState => this.updateStatusbarEntry(trustState))); + this._register(this.workspaceTrustManagementService.onDidChangeTrust(trusted => this.updateStatusbarEntry(trusted))); this._register(this.contextKeyService.onDidChangeContext((contextChange) => { if (contextChange.affectsSome(this.contextKeys)) { - this.updateVisibility(this.workspaceTrustManagementService.getWorkspaceTrustState()); + this.updateVisibility(this.workspaceTrustManagementService.isWorkpaceTrusted()); } })); - this.updateVisibility(this.workspaceTrustManagementService.getWorkspaceTrustState()); + this.updateVisibility(this.workspaceTrustManagementService.isWorkpaceTrusted()); } } - private getStatusbarEntry(state: WorkspaceTrustState): IStatusbarEntry { - const text = workspaceTrustStateToString(state); - const backgroundColor = state === WorkspaceTrustState.Trusted ? + private getStatusbarEntry(trusted: boolean): IStatusbarEntry { + const text = workspaceTrustToString(trusted); + const backgroundColor = trusted ? 'transparent' : new ThemeColor('statusBarItem.prominentBackground'); - const color = state === WorkspaceTrustState.Trusted ? '#00dd3b' : '#ff5462'; + const color = trusted ? '#00dd3b' : '#ff5462'; return { - text: state === WorkspaceTrustState.Trusted ? `$(shield)` : `$(shield) ${text}`, + text: trusted ? `$(shield)` : `$(shield) ${text}`, ariaLabel: localize('status.WorkspaceTrust', "Workspace Trust"), tooltip: localize('status.WorkspaceTrust', "Workspace Trust"), command: 'workbench.trust.manage', @@ -239,14 +236,14 @@ class WorkspaceTrustStatusbarItem extends Disposable implements IWorkbenchContri }; } - private updateVisibility(trustState: WorkspaceTrustState): void { + private updateVisibility(trusted: boolean): void { const pendingRequest = this.contextKeyService.getContextKeyValue(this.pendingRequestContextKey) === true; - this.statusbarService.updateEntryVisibility(WorkspaceTrustStatusbarItem.ID, trustState === WorkspaceTrustState.Untrusted || pendingRequest); + this.statusbarService.updateEntryVisibility(WorkspaceTrustStatusbarItem.ID, !trusted || pendingRequest); } - private updateStatusbarEntry(trustStateChange: WorkspaceTrustStateChangeEvent): void { - this.statusBarEntryAccessor.value?.update(this.getStatusbarEntry(trustStateChange.currentTrustState)); - this.updateVisibility(trustStateChange.currentTrustState); + private updateStatusbarEntry(trusted: boolean): void { + this.statusBarEntryAccessor.value?.update(this.getStatusbarEntry(trusted)); + this.updateVisibility(trusted); } } @@ -302,7 +299,7 @@ registerAction2(class extends Action2 { }, category: localize('workspacesCategory', "Workspaces"), f1: true, - precondition: WorkspaceTrustContext.TrustState.isEqualTo(WorkspaceTrustState.Trusted).negate(), + precondition: WorkspaceTrustContext.IsTrusted.negate(), menu: { id: MenuId.GlobalActivity, when: WorkspaceTrustContext.PendingRequest, @@ -324,7 +321,7 @@ registerAction2(class extends Action2 { }); if (result.confirmed) { - workspaceTrustRequestService.completeRequest(WorkspaceTrustState.Trusted); + workspaceTrustRequestService.completeRequest(true); } return; @@ -342,10 +339,10 @@ registerAction2(class extends Action2 { }, category: localize('workspacesCategory', "Workspaces"), f1: true, - precondition: WorkspaceTrustContext.TrustState.isEqualTo(WorkspaceTrustState.Untrusted).negate(), + precondition: WorkspaceTrustContext.IsTrusted, menu: { id: MenuId.GlobalActivity, - when: WorkspaceTrustContext.PendingRequest, + when: WorkspaceTrustContext.IsTrusted, group: '6_workspace_trust', order: 20 }, @@ -364,7 +361,7 @@ registerAction2(class extends Action2 { }); if (result.confirmed) { - workspaceTrustRequestService.completeRequest(WorkspaceTrustState.Untrusted); + workspaceTrustRequestService.completeRequest(false); } return; } diff --git a/src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts b/src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts index 147d01d6d99..307b8f1f02c 100644 --- a/src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts +++ b/src/vs/workbench/contrib/workspace/browser/workspaceTrustEditor.ts @@ -34,7 +34,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { attachButtonStyler, attachLinkStyler, attachStylerCallback } from 'vs/platform/theme/common/styler'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; -import { IWorkspaceTrustManagementService, IWorkspaceTrustStorageService, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; +import { IWorkspaceTrustManagementService, IWorkspaceTrustStorageService } from 'vs/platform/workspace/common/workspaceTrust'; import { isSingleFolderWorkspaceIdentifier, toWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane'; import { EditorOptions, IEditorOpenContext } from 'vs/workbench/common/editor'; @@ -48,7 +48,6 @@ import { WorkspaceTrustEditorInput } from 'vs/workbench/services/workspaces/brow const untrustedIcon = registerCodicon('workspace-untrusted-icon', Codicon.workspaceUntrusted); const trustedIcon = registerCodicon('workspace-trusted-icon', Codicon.workspaceTrusted); -const unspecified = registerCodicon('workspace-unspecified-icon', Codicon.workspaceUnspecified); const checkListIcon = registerCodicon('workspace-trusted-check-icon', Codicon.check); const xListIcon = registerCodicon('workspace-trusted-x-icon', Codicon.x); @@ -121,52 +120,42 @@ export class WorkspaceTrustEditor extends EditorPane { } private registerListeners(): void { - this._register(this.workspaceTrustManagementService.onDidChangeTrustState(() => this.render())); + this._register(this.workspaceTrustManagementService.onDidChangeTrust(() => this.render())); this._register(this.extensionWorkbenchService.onChange(() => this.render())); const configurationRegistry = Registry.as(Extensions.Configuration); this._register(Event.any(configurationRegistry.onDidUpdateConfiguration, configurationRegistry.onDidSchemaChange)(() => this.render())); } - private getHeaderContainerClass(trustState: WorkspaceTrustState): string { - switch (trustState) { - case WorkspaceTrustState.Trusted: - return 'workspace-trust-header workspace-trust-trusted'; - case WorkspaceTrustState.Untrusted: - return 'workspace-trust-header workspace-trust-untrusted'; - case WorkspaceTrustState.Unspecified: - return 'workspace-trust-header workspace-trust-unknown'; + private getHeaderContainerClass(trusted: boolean): string { + if (trusted) { + return 'workspace-trust-header workspace-trust-trusted'; } + + return 'workspace-trust-header workspace-trust-untrusted'; } - private getHeaderTitleText(trustState: WorkspaceTrustState): string { - switch (trustState) { - case WorkspaceTrustState.Trusted: - return localize('trustedHeader', "This workspace is trusted"); - case WorkspaceTrustState.Untrusted: - return localize('untrustedHeader', "This workspace is not trusted"); - case WorkspaceTrustState.Unspecified: - return localize('unspecifiedHeader', "Do you want to trust this workspace?"); + private getHeaderTitleText(trusted: boolean): string { + if (trusted) { + return localize('trustedHeader', "This workspace is trusted"); } + + return localize('untrustedHeader', "This workspace is not trusted"); } - private getHeaderDescriptionText(trustState: WorkspaceTrustState): string { - switch (trustState) { - case WorkspaceTrustState.Trusted: - case WorkspaceTrustState.Untrusted: - case WorkspaceTrustState.Unspecified: - return localize('unknownSpecifiedDescription', "Some features are disabled until trust is granted to the workspace. [Learn more](https://aka.ms/vscode-workspace-trust)."); + private getHeaderDescriptionText(trusted: boolean): string { + if (trusted) { + return localize('trustedDescription', "All features are enabled because trust has been granted to the workspace. [Learn more](https://aka.ms/vscode-workspace-trust)."); } + + return localize('untrustedDescription', "Some features are disabled until trust is granted to the workspace. [Learn more](https://aka.ms/vscode-workspace-trust)."); } - private getHeaderTitleIconClassNames(trustState: WorkspaceTrustState): string[] { - switch (trustState) { - case WorkspaceTrustState.Trusted: - return trustedIcon.classNamesArray; - case WorkspaceTrustState.Untrusted: - return untrustedIcon.classNamesArray; - case WorkspaceTrustState.Unspecified: - return unspecified.classNamesArray; + private getHeaderTitleIconClassNames(trusted: boolean): string[] { + if (trusted) { + return trustedIcon.classNamesArray; } + + return untrustedIcon.classNamesArray; } private rendering = false; @@ -180,17 +169,17 @@ export class WorkspaceTrustEditor extends EditorPane { this.rendering = true; this.rerenderDisposables.clear(); - const currentTrustState = this.workspaceTrustManagementService.getWorkspaceTrustState(); - this.rootElement.classList.toggle('trusted', currentTrustState === WorkspaceTrustState.Trusted); - this.rootElement.classList.toggle('untrusted', currentTrustState === WorkspaceTrustState.Untrusted); + const isWorkspaceTrusted = this.workspaceTrustManagementService.isWorkpaceTrusted(); + this.rootElement.classList.toggle('trusted', isWorkspaceTrusted); + this.rootElement.classList.toggle('untrusted', !isWorkspaceTrusted); // Header Section - this.headerTitleText.innerText = this.getHeaderTitleText(currentTrustState); + this.headerTitleText.innerText = this.getHeaderTitleText(isWorkspaceTrusted); this.headerTitleIcon.className = 'workspace-trust-title-icon'; - this.headerTitleIcon.classList.add(...this.getHeaderTitleIconClassNames(currentTrustState)); + this.headerTitleIcon.classList.add(...this.getHeaderTitleIconClassNames(isWorkspaceTrusted)); this.headerDescription.innerText = ''; - const linkedText = parseLinkedText(this.getHeaderDescriptionText(currentTrustState)); + const linkedText = parseLinkedText(this.getHeaderDescriptionText(isWorkspaceTrusted)); const p = append(this.headerDescription, $('p')); for (const node of linkedText.nodes) { if (typeof node === 'string') { @@ -203,7 +192,7 @@ export class WorkspaceTrustEditor extends EditorPane { } } - this.headerContainer.className = this.getHeaderContainerClass(currentTrustState); + this.headerContainer.className = this.getHeaderContainerClass(isWorkspaceTrusted); // Settings const settingsRequiringTrustedWorkspaceCount = this.getSettingsRequiringTrustedTargetCount(); @@ -273,8 +262,7 @@ export class WorkspaceTrustEditor extends EditorPane { private renderAffectedFeatures(numSettings: number, numExtensions: number): void { clearNode(this.affectedFeaturesContainer); const trustedContainer = append(this.affectedFeaturesContainer, $('.workspace-trust-limitations.trusted')); - this.renderLimitationsHeaderElement(trustedContainer, localize('trustedWorkspace', "Trusted Workspace"), this.getHeaderTitleIconClassNames(WorkspaceTrustState.Trusted)); - + this.renderLimitationsHeaderElement(trustedContainer, localize('trustedWorkspace', "Trusted Workspace"), this.getHeaderTitleIconClassNames(true)); this.renderLimitationsListElement(trustedContainer, [ localize('trustedTasks', "Tasks will be allowed to run"), localize('trustedDebugging', "Debugging will be enabled"), @@ -283,7 +271,7 @@ export class WorkspaceTrustEditor extends EditorPane { ], checkListIcon.classNamesArray); const untrustedContainer = append(this.affectedFeaturesContainer, $('.workspace-trust-limitations.untrusted')); - this.renderLimitationsHeaderElement(untrustedContainer, localize('untrustedWorkspace', "Untrusted Workspace"), this.getHeaderTitleIconClassNames(WorkspaceTrustState.Untrusted)); + this.renderLimitationsHeaderElement(untrustedContainer, localize('untrustedWorkspace', "Untrusted Workspace"), this.getHeaderTitleIconClassNames(false)); this.renderLimitationsListElement(untrustedContainer, [ localize('untrustedTasks', "Tasks will be disabled"), @@ -292,11 +280,11 @@ export class WorkspaceTrustEditor extends EditorPane { localize('untrustedExtensions', "[{0} extensions](command:{1}) will be disabled or limit functionality", numExtensions, 'workbench.extensions.action.listTrustRequiredExtensions') ], xListIcon.classNamesArray); - this.addButtonToLimitationsElement(trustedContainer, WorkspaceTrustState.Trusted); - this.addButtonToLimitationsElement(untrustedContainer, WorkspaceTrustState.Untrusted); + this.addButtonToLimitationsElement(trustedContainer, true); + this.addButtonToLimitationsElement(untrustedContainer, false); } - private addButtonToLimitationsElement(parent: HTMLElement, targetState: WorkspaceTrustState): void { + private addButtonToLimitationsElement(parent: HTMLElement, targetTrust: boolean): void { const workspaceFolders = this.workspaceService.getWorkspace().folders; @@ -329,8 +317,8 @@ export class WorkspaceTrustEditor extends EditorPane { this.rerenderDisposables.add(attachButtonStyler(button, this.themeService)); }; - const setTrustState = async (state: WorkspaceTrustState, uris?: URI[]) => { - if (state !== WorkspaceTrustState.Trusted) { + const setTrustForUris = async (trusted: boolean, uris?: URI[]) => { + if (!trusted) { const message = localize('workspaceTrustTransitionMessage', "Deny Workspace Trust"); const detail = localize('workspaceTrustTransitionDetail', "In order to safely complete this action, all affected windows will have to be reloaded. Are you sure you want to proceed with this action?"); const primaryButton = localize('workspaceTrustTransitionPrimaryButton', "Yes"); @@ -343,7 +331,7 @@ export class WorkspaceTrustEditor extends EditorPane { } const folderURIs = uris || this.workspaceService.getWorkspace().folders.map(folder => folder.uri); - this.workspaceTrustStorageService.setFoldersTrustState(folderURIs, state); + this.workspaceTrustStorageService.setFoldersTrust(folderURIs, trusted); }; @@ -352,7 +340,7 @@ export class WorkspaceTrustEditor extends EditorPane { label: localize('trustButton', "Trust"), menu: [], run: () => { - setTrustState(WorkspaceTrustState.Trusted); + setTrustForUris(true); } }; @@ -364,20 +352,20 @@ export class WorkspaceTrustEditor extends EditorPane { trustChoiceWithMenu.menu.push({ label: localize('trustParentButton', "Trust All in {0}", name), run: () => { - setTrustState(WorkspaceTrustState.Trusted, [URI.file(parentPath)]); + setTrustForUris(true, [URI.file(parentPath)]); } }); } } - const currentTrustState = this.workspaceTrustManagementService.getWorkspaceTrustState(); + const isWorkspaceTrusted = this.workspaceTrustManagementService.isWorkpaceTrusted(); - if (targetState === WorkspaceTrustState.Trusted) { - createButton(new ChoiceAction('workspace.trust.button.action', trustChoiceWithMenu), currentTrustState !== WorkspaceTrustState.Trusted); + if (targetTrust === true) { + createButton(new ChoiceAction('workspace.trust.button.action', trustChoiceWithMenu), !isWorkspaceTrusted); } - if (targetState === WorkspaceTrustState.Untrusted) { - createButton(new Action('workspace.trust.button.deny', localize('doNotTrustButton', "Don't Trust"), undefined, currentTrustState !== WorkspaceTrustState.Untrusted, async () => { setTrustState(WorkspaceTrustState.Untrusted); })); + if (targetTrust === false) { + createButton(new Action('workspace.trust.button.deny', localize('doNotTrustButton', "Don't Trust"), undefined, isWorkspaceTrusted, async () => { setTrustForUris(false); })); } } } @@ -439,10 +427,6 @@ export class WorkspaceTrustEditor extends EditorPane { if (change.key === 'trustedFolders') { applyChangesWithPrompt(change.type === 'changed' || change.type === 'removed', () => this.workspaceTrustStorageService.setTrustedFolders(change.value!)); } - - if (change.key === 'untrustedFolders') { - applyChangesWithPrompt(change.type === 'changed' || change.type === 'added', () => this.workspaceTrustStorageService.setUntrustedFolders(change.value!)); - } } } diff --git a/src/vs/workbench/contrib/workspace/browser/workspaceTrustTree.ts b/src/vs/workbench/contrib/workspace/browser/workspaceTrustTree.ts index 45cff46da33..5138c594a06 100644 --- a/src/vs/workbench/contrib/workspace/browser/workspaceTrustTree.ts +++ b/src/vs/workbench/contrib/workspace/browser/workspaceTrustTree.ts @@ -28,7 +28,7 @@ import { NonCollapsibleObjectTreeModel } from 'vs/workbench/contrib/preferences/ import { AbstractListSettingWidget, focusedRowBackground, focusedRowBorder, ISettingListChangeEvent, rowHoverBackground, settingsHeaderForeground, settingsSelectBackground, settingsTextInputBorder, settingsTextInputForeground } from 'vs/workbench/contrib/preferences/browser/settingsWidgets'; import { attachButtonStyler, attachInputBoxStyler, attachStyler } from 'vs/platform/theme/common/styler'; import { CachedListVirtualDelegate } from 'vs/base/browser/ui/list/list'; -import { IWorkspaceTrustStateInfo, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; +import { IWorkspaceTrustStateInfo } from 'vs/platform/workspace/common/workspaceTrust'; import { IAction } from 'vs/base/common/actions'; import { settingsEditIcon, settingsRemoveIcon } from 'vs/workbench/contrib/preferences/browser/preferencesIcons'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; @@ -576,20 +576,13 @@ export class WorkspaceTrustTreeModel { update(trustInfo: IWorkspaceTrustStateInfo): void { this.settings = []; if (trustInfo.uriTrustInfo) { - const trustedFolders = trustInfo.uriTrustInfo.filter(folder => folder.trustState === WorkspaceTrustState.Trusted).map(folder => folder.uri); - const untrustedFolders = trustInfo.uriTrustInfo.filter(folder => folder.trustState === WorkspaceTrustState.Untrusted).map(folder => folder.uri); + const trustedFolders = trustInfo.uriTrustInfo.filter(folder => folder.trusted).map(folder => folder.uri); this.settings.push(new WorkspaceTrustSettingsTreeEntry( 'trustedFolders', localize('trustedFolders', "Trusted Folders"), - localize('trustedFoldersDescription', "All workspaces under the following folders will be trusted. In the event of a conflict with untrusted folders, the nearest parent will determine trust."), + localize('trustedFoldersDescription', "All workspaces under the following folders will be trusted."), trustedFolders)); - - this.settings.push(new WorkspaceTrustSettingsTreeEntry( - 'untrustedFolders', - localize('untrustedFolders', "Untrusted Folders"), - localize('untrustedFoldersDescription', "All workspaces under the following folders will not be trusted. In the event of a conflict with trusted folders, the nearest parent will determine trust."), - untrustedFolders)); } } } diff --git a/src/vs/workbench/services/configuration/browser/configuration.ts b/src/vs/workbench/services/configuration/browser/configuration.ts index 8c8989b7352..de88c56a8e6 100644 --- a/src/vs/workbench/services/configuration/browser/configuration.ts +++ b/src/vs/workbench/services/configuration/browser/configuration.ts @@ -23,11 +23,6 @@ import { hash } from 'vs/base/common/hash'; import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; import { ILogService } from 'vs/platform/log/common/log'; import { IStringDictionary } from 'vs/base/common/collections'; -import { WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; - -function isUntrusted(workspaceTrustState: WorkspaceTrustState): boolean { - return workspaceTrustState !== WorkspaceTrustState.Trusted; -} export class UserConfiguration extends Disposable { @@ -473,7 +468,7 @@ export class WorkspaceConfiguration extends Disposable { private _workspaceConfiguration: CachedWorkspaceConfiguration | FileServiceBasedWorkspaceConfiguration; private _workspaceConfigurationDisposables = this._register(new DisposableStore()); private _workspaceIdentifier: IWorkspaceIdentifier | null = null; - private _workspaceTrustState: WorkspaceTrustState | null = null; + private _isWorkspaceTrusted: boolean = false; private readonly _onDidUpdateConfiguration: Emitter = this._register(new Emitter()); public readonly onDidUpdateConfiguration: Event = this._onDidUpdateConfiguration.event; @@ -489,9 +484,9 @@ export class WorkspaceConfiguration extends Disposable { this._workspaceConfiguration = this._cachedConfiguration = new CachedWorkspaceConfiguration(configurationCache); } - async initialize(workspaceIdentifier: IWorkspaceIdentifier, workspaceTrustState: WorkspaceTrustState): Promise { + async initialize(workspaceIdentifier: IWorkspaceIdentifier, workspaceTrusted: boolean): Promise { this._workspaceIdentifier = workspaceIdentifier; - this._workspaceTrustState = workspaceTrustState; + this._isWorkspaceTrusted = workspaceTrusted; if (!this._initialized) { if (this.configurationCache.needsCaching(this._workspaceIdentifier.configPath)) { this._workspaceConfiguration = this._cachedConfiguration; @@ -525,8 +520,8 @@ export class WorkspaceConfiguration extends Disposable { return this._workspaceConfiguration.getWorkspaceSettings(); } - updateWorkspaceTrustState(workspaceTrustState: WorkspaceTrustState): ConfigurationModel { - this._workspaceTrustState = workspaceTrustState; + updateWorkspaceTrust(trusted: boolean): ConfigurationModel { + this._isWorkspaceTrusted = trusted; return this.reparseWorkspaceSettings(); } @@ -556,8 +551,8 @@ export class WorkspaceConfiguration extends Disposable { this._initialized = true; } - private isUntrusted(): boolean | undefined { - return this._workspaceTrustState !== null ? isUntrusted(this._workspaceTrustState) : undefined; + private isUntrusted(): boolean { + return !this._isWorkspaceTrusted; } private async onDidWorkspaceConfigurationChange(reload: boolean): Promise { @@ -839,7 +834,7 @@ export class FolderConfiguration extends Disposable { readonly workspaceFolder: IWorkspaceFolder, configFolderRelativePath: string, private readonly workbenchState: WorkbenchState, - private workspaceTrustState: WorkspaceTrustState, + private workspaceTrusted: boolean, fileService: IFileService, uriIdentityService: IUriIdentityService, logService: ILogService, @@ -868,8 +863,8 @@ export class FolderConfiguration extends Disposable { return this.folderConfiguration.loadConfiguration(); } - updateWorkspaceTrustState(workspaceTrustState: WorkspaceTrustState): ConfigurationModel { - this.workspaceTrustState = workspaceTrustState; + updateWorkspaceTrust(trusted: boolean): ConfigurationModel { + this.workspaceTrusted = trusted; return this.reparse(); } @@ -884,7 +879,7 @@ export class FolderConfiguration extends Disposable { } private isUntrusted(): boolean { - return isUntrusted(this.workspaceTrustState); + return !this.workspaceTrusted; } private onDidFolderConfigurationChange(): void { diff --git a/src/vs/workbench/services/configuration/browser/configurationService.ts b/src/vs/workbench/services/configuration/browser/configurationService.ts index a765410fe23..b2bbd858922 100644 --- a/src/vs/workbench/services/configuration/browser/configurationService.ts +++ b/src/vs/workbench/services/configuration/browser/configurationService.ts @@ -32,7 +32,7 @@ import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle import { ILogService } from 'vs/platform/log/common/log'; import { toErrorMessage } from 'vs/base/common/errorMessage'; import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; -import { IWorkspaceTrustManagementService, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; +import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust'; import { delta, distinct } from 'vs/base/common/arrays'; import { forEach, IStringDictionary } from 'vs/base/common/collections'; @@ -76,7 +76,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat private readonly _onDidChangeUntrustedSettings = this._register(new Emitter()); public readonly onDidChangeUntrustdSettings = this._onDidChangeUntrustedSettings.event; - private workspaceTrustState: WorkspaceTrustState = WorkspaceTrustState.Trusted; + private isWorkspaceTrusted: boolean = true; private _unTrustedSettings: UntrustedSettings = {}; get unTrustedSettings() { return this._unTrustedSettings; } @@ -399,16 +399,16 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat mark('code/didInitWorkspaceService'); } - updateWorkspaceTrustState(workspaceTrustState: WorkspaceTrustState): void { - if (this.workspaceTrustState !== workspaceTrustState) { - this.workspaceTrustState = workspaceTrustState; + updateWorkspaceTrust(trusted: boolean): void { + if (this.isWorkspaceTrusted !== trusted) { + this.isWorkspaceTrusted = trusted; const data = this._configuration.toData(); const folderConfigurationModels: (ConfigurationModel | undefined)[] = []; for (const folder of this.workspace.folders) { const folderConfiguration = this.cachedFolderConfigs.get(folder.uri); let configurationModel: ConfigurationModel | undefined; if (folderConfiguration) { - configurationModel = folderConfiguration.updateWorkspaceTrustState(this.workspaceTrustState); + configurationModel = folderConfiguration.updateWorkspaceTrust(this.isWorkspaceTrusted); this._configuration.updateFolderConfiguration(folder.uri, configurationModel); } folderConfigurationModels.push(configurationModel); @@ -418,7 +418,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat this._configuration.updateWorkspaceConfiguration(folderConfigurationModels[0]); } } else { - this._configuration.updateWorkspaceConfiguration(this.workspaceConfiguration.updateWorkspaceTrustState(this.workspaceTrustState)); + this._configuration.updateWorkspaceConfiguration(this.workspaceConfiguration.updateWorkspaceTrust(this.isWorkspaceTrusted)); } const keys = this.updateUntrustedSettings(); if (keys.length) { @@ -451,7 +451,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat } private async createMultiFolderWorkspace(workspaceIdentifier: IWorkspaceIdentifier): Promise { - await this.workspaceConfiguration.initialize({ id: workspaceIdentifier.id, configPath: workspaceIdentifier.configPath }, this.workspaceTrustState); + await this.workspaceConfiguration.initialize({ id: workspaceIdentifier.id, configPath: workspaceIdentifier.configPath }, this.isWorkspaceTrusted); const workspaceConfigPath = workspaceIdentifier.configPath; const workspaceFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), workspaceConfigPath, this.uriIdentityService.extUri); const workspaceId = workspaceIdentifier.id; @@ -788,7 +788,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat return Promise.all([...folders.map(folder => { let folderConfiguration = this.cachedFolderConfigs.get(folder.uri); if (!folderConfiguration) { - folderConfiguration = new FolderConfiguration(folder, FOLDER_CONFIG_FOLDER_NAME, this.getWorkbenchState(), this.workspaceTrustState, this.fileService, this.uriIdentityService, this.logService, this.configurationCache); + folderConfiguration = new FolderConfiguration(folder, FOLDER_CONFIG_FOLDER_NAME, this.getWorkbenchState(), this.isWorkspaceTrusted, this.fileService, this.uriIdentityService, this.logService, this.configurationCache); this._register(folderConfiguration.onDidChange(() => this.onWorkspaceFolderConfigurationChanged(folder))); this.cachedFolderConfigs.set(folder.uri, this._register(folderConfiguration)); } @@ -945,8 +945,8 @@ class ConfigurationWorkspaceTrustContribution extends Disposable implements IWor @IConfigurationService configurationService: WorkspaceService ) { super(); - configurationService.updateWorkspaceTrustState(workspaceTrustManagementService.getWorkspaceTrustState()); - this._register(workspaceTrustManagementService.onDidChangeTrustState(e => configurationService.updateWorkspaceTrustState(workspaceTrustManagementService.getWorkspaceTrustState()))); + configurationService.updateWorkspaceTrust(workspaceTrustManagementService.isWorkpaceTrusted()); + this._register(workspaceTrustManagementService.onDidChangeTrust(e => configurationService.updateWorkspaceTrust(workspaceTrustManagementService.isWorkpaceTrusted()))); } } @@ -961,7 +961,7 @@ class RegisterConfigurationSchemasContribution extends Disposable implements IWo const configurationRegistry = Registry.as(Extensions.Configuration); this._register(configurationRegistry.onDidUpdateConfiguration(e => this.registerConfigurationSchemas())); this._register(configurationRegistry.onDidSchemaChange(e => this.registerConfigurationSchemas())); - this._register(workspaceTrustManagementService.onDidChangeTrustState(e => this.registerConfigurationSchemas())); + this._register(workspaceTrustManagementService.onDidChangeTrust(() => this.registerConfigurationSchemas())); } private registerConfigurationSchemas(): void { @@ -1056,7 +1056,7 @@ class RegisterConfigurationSchemasContribution extends Disposable implements IWo } private checkAndFilterPropertiesRequiringTrust(properties: IStringDictionary): IStringDictionary { - if (this.workspaceTrustManagementService.getWorkspaceTrustState() === WorkspaceTrustState.Trusted) { + if (this.workspaceTrustManagementService.isWorkpaceTrusted()) { return properties; } diff --git a/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts b/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts index bcd1ac06c26..2af0024dfea 100644 --- a/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts +++ b/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts @@ -45,7 +45,6 @@ import { BrowserWorkbenchEnvironmentService } from 'vs/workbench/services/enviro import { RemoteAgentService } from 'vs/workbench/services/remote/browser/remoteAgentServiceImpl'; import { RemoteAuthorityResolverService } from 'vs/platform/remote/browser/remoteAuthorityResolverService'; import { hash } from 'vs/base/common/hash'; -import { WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; function convertToWorkspacePayload(folder: URI): ISingleFolderWorkspaceIdentifier { return { @@ -1110,7 +1109,7 @@ suite('WorkspaceConfigurationService - Folder', () => { }); test('untrusted setting is read from workspace when workspace is trusted', async () => { - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Trusted); + testObject.updateWorkspaceTrust(true); await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "userValue" }')); await fileService.writeFile(joinPath(workspaceService.getWorkspace().folders[0].uri, '.vscode', 'settings.json'), VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "workspaceValue" }')); @@ -1125,13 +1124,13 @@ suite('WorkspaceConfigurationService - Folder', () => { }); test('untrusted setting is not read from workspace when workspace is changed to trusted', async () => { - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Trusted); + testObject.updateWorkspaceTrust(true); await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "userValue" }')); await fileService.writeFile(joinPath(workspaceService.getWorkspace().folders[0].uri, '.vscode', 'settings.json'), VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "workspaceValue" }')); await testObject.reloadConfiguration(); - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Untrusted); + testObject.updateWorkspaceTrust(false); assert.strictEqual(testObject.getValue('configurationService.folder.untrustedSetting', { resource: workspaceService.getWorkspace().folders[0].uri }), 'userValue'); assert.deepStrictEqual(testObject.unTrustedSettings.all, ['configurationService.folder.untrustedSetting']); @@ -1143,14 +1142,14 @@ suite('WorkspaceConfigurationService - Folder', () => { }); test('change event is triggered when workspace is changed to untrusted', async () => { - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Trusted); + testObject.updateWorkspaceTrust(true); await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "userValue" }')); await fileService.writeFile(joinPath(workspaceService.getWorkspace().folders[0].uri, '.vscode', 'settings.json'), VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "workspaceValue" }')); await testObject.reloadConfiguration(); const promise = Event.toPromise(testObject.onDidChangeConfiguration); - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Untrusted); + testObject.updateWorkspaceTrust(false); const event = await promise; assert.deepStrictEqual(event.affectedKeys, ['configurationService.folder.untrustedSetting']); @@ -1158,7 +1157,7 @@ suite('WorkspaceConfigurationService - Folder', () => { }); test('untrusted setting is not read from workspace when workspace is not trusted', async () => { - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Untrusted); + testObject.updateWorkspaceTrust(false); await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "userValue" }')); await fileService.writeFile(joinPath(workspaceService.getWorkspace().folders[0].uri, '.vscode', 'settings.json'), VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "workspaceValue" }')); @@ -1174,13 +1173,13 @@ suite('WorkspaceConfigurationService - Folder', () => { }); test('untrusted setting is read when workspace is changed to trusted', async () => { - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Untrusted); + testObject.updateWorkspaceTrust(false); await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "userValue" }')); await fileService.writeFile(joinPath(workspaceService.getWorkspace().folders[0].uri, '.vscode', 'settings.json'), VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "workspaceValue" }')); await testObject.reloadConfiguration(); - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Trusted); + testObject.updateWorkspaceTrust(true); assert.strictEqual(testObject.getValue('configurationService.folder.untrustedSetting', { resource: workspaceService.getWorkspace().folders[0].uri }), 'workspaceValue'); assert.strictEqual(testObject.unTrustedSettings.all, undefined); @@ -1191,14 +1190,14 @@ suite('WorkspaceConfigurationService - Folder', () => { }); test('change event is triggered when workspace is changed to trusted', async () => { - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Untrusted); + testObject.updateWorkspaceTrust(false); await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "userValue" }')); await fileService.writeFile(joinPath(workspaceService.getWorkspace().folders[0].uri, '.vscode', 'settings.json'), VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "workspaceValue" }')); await testObject.reloadConfiguration(); const promise = Event.toPromise(testObject.onDidChangeConfiguration); - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Trusted); + testObject.updateWorkspaceTrust(true); const event = await promise; assert.deepStrictEqual(event.affectedKeys, ['configurationService.folder.untrustedSetting']); @@ -1207,7 +1206,7 @@ suite('WorkspaceConfigurationService - Folder', () => { test('adding an untrusted setting triggers change event', async () => { await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "userValue" }')); - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Untrusted); + testObject.updateWorkspaceTrust(false); const promise = Event.toPromise(testObject.onDidChangeUntrustdSettings); await fileService.writeFile(joinPath(workspaceService.getWorkspace().folders[0].uri, '.vscode', 'settings.json'), VSBuffer.fromString('{ "configurationService.folder.untrustedSetting": "workspaceValue" }')); @@ -1829,7 +1828,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => { }); test('untrusted setting is read from workspace folders when workspace is trusted', async () => { - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Trusted); + testObject.updateWorkspaceTrust(true); await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.workspace.testUntrustedSetting1": "userValue", "configurationService.workspace.testUntrustedSetting2": "userValue" }')); await jsonEditingServce.write((workspaceContextService.getWorkspace().configuration!), [{ path: ['settings'], value: { 'configurationService.workspace.testUntrustedSetting1': 'workspaceValue' } }], true); @@ -1846,7 +1845,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => { }); test('untrusted setting is not read from workspace when workspace is not trusted', async () => { - testObject.updateWorkspaceTrustState(WorkspaceTrustState.Untrusted); + testObject.updateWorkspaceTrust(false); await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString('{ "configurationService.workspace.testUntrustedSetting1": "userValue", "configurationService.workspace.testUntrustedSetting2": "userValue" }')); await jsonEditingServce.write((workspaceContextService.getWorkspace().configuration!), [{ path: ['settings'], value: { 'configurationService.workspace.testUntrustedSetting1': 'workspaceValue' } }], true); diff --git a/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts b/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts index 2b41f0c0ec1..4a5c18c6ced 100644 --- a/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts +++ b/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts @@ -25,7 +25,7 @@ import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecyc import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { IHostService } from 'vs/workbench/services/host/browser/host'; import { IExtensionBisectService } from 'vs/workbench/services/extensionManagement/browser/extensionBisect'; -import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService, WorkspaceTrustState, WorkspaceTrustStateChangeEvent } from 'vs/platform/workspace/common/workspaceTrust'; +import { IWorkspaceTrustManagementService, IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/workspaceTrust'; import { Promises } from 'vs/base/common/async'; import { IExtensionWorkspaceTrustRequestService } from 'vs/workbench/services/extensions/common/extensionWorkspaceTrustRequest'; @@ -67,7 +67,7 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench this._register(this.globalExtensionEnablementService.onDidChangeEnablement(({ extensions, source }) => this.onDidChangeExtensions(extensions, source))); this._register(extensionManagementService.onDidInstallExtension(this._onDidInstallExtension, this)); this._register(extensionManagementService.onDidUninstallExtension(this._onDidUninstallExtension, this)); - this._register(this.workspaceTrustManagementService.onDidChangeTrustState(this._onDidChangeTrustState, this)); + this._register(this.workspaceTrustManagementService.onDidChangeTrust(this._onDidChangeTrust, this)); // Trusted extensions notification // TODO: Confirm that this is the right lifecycle phase @@ -172,9 +172,9 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench const result = await Promises.settled(extensions.map(e => { if (this._isDisabledByTrustRequirement(e)) { - return this.workspaceTrustRequestService.requestWorkspaceTrust() + return this.workspaceTrustRequestService.requestWorkspaceTrust({ modal: true }) .then(trustState => { - if (trustState === WorkspaceTrustState.Trusted) { + if (trustState) { return this._setEnablement(e, newState); } else { return Promise.resolve(false); @@ -277,13 +277,13 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench } private _isDisabledByTrustRequirement(extension: IExtension): boolean { - const workspaceTrustState = this.workspaceTrustManagementService.getWorkspaceTrustState(); + const isWorkspaceTrusted = this.workspaceTrustManagementService.isWorkpaceTrusted(); if (this.extensionWorkspaceTrustRequestService.getExtensionWorkspaceTrustRequestType(extension.manifest) === 'onStart') { - if (workspaceTrustState !== WorkspaceTrustState.Trusted) { + if (!isWorkspaceTrusted) { this._addToWorkspaceDisabledExtensionsByTrustRequirement(extension); } - return workspaceTrustState !== WorkspaceTrustState.Trusted; + return !isWorkspaceTrusted; } return false; } @@ -456,8 +456,8 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench } } - private _onDidChangeTrustState({ currentTrustState }: WorkspaceTrustStateChangeEvent): void { - if (currentTrustState === WorkspaceTrustState.Trusted && this.extensionsDisabledByTrustRequirement.length > 0) { + private _onDidChangeTrust(trusted: boolean): void { + if (trusted && this.extensionsDisabledByTrustRequirement.length > 0) { this._onEnablementChanged.fire(this.extensionsDisabledByTrustRequirement); this.extensionsDisabledByTrustRequirement = []; } diff --git a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts index 7d6bd27b024..c9b80311f89 100644 --- a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts +++ b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts @@ -13,7 +13,7 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; -import { WorkspaceTrustRequestOptions, IWorkspaceTrustManagementService, IWorkspaceTrustStateInfo, WorkspaceTrustState, WorkspaceTrustStateChangeEvent, IWorkspaceTrustUriInfo, IWorkspaceTrustRequestService, IWorkspaceTrustStorageService as IWorkspaceTrustStorageService } from 'vs/platform/workspace/common/workspaceTrust'; +import { WorkspaceTrustRequestOptions, IWorkspaceTrustManagementService, IWorkspaceTrustStateInfo, IWorkspaceTrustUriInfo, IWorkspaceTrustRequestService, IWorkspaceTrustStorageService as IWorkspaceTrustStorageService } from 'vs/platform/workspace/common/workspaceTrust'; import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; export const WORKSPACE_TRUST_ENABLED = 'security.workspace.trust.enabled'; @@ -22,7 +22,7 @@ export const WORKSPACE_TRUST_STORAGE_KEY = 'content.trust.model.key'; export const WorkspaceTrustContext = { PendingRequest: new RawContextKey('workspaceTrustPendingRequest', false), - TrustState: new RawContextKey('workspaceTrustState', WorkspaceTrustState.Unspecified) + IsTrusted: new RawContextKey('isWorkspaceTrusted', false) }; export class WorkspaceTrustStorageService extends Disposable implements IWorkspaceTrustStorageService { @@ -69,7 +69,8 @@ export class WorkspaceTrustStorageService extends Disposable implements IWorkspa result.uriTrustInfo = []; } - result.uriTrustInfo = result.uriTrustInfo.map(info => { return { uri: URI.revive(info.uri), trustState: info.trustState }; }); + result.uriTrustInfo = result.uriTrustInfo.map(info => { return { uri: URI.revive(info.uri), trusted: info.trusted }; }); + result.uriTrustInfo = result.uriTrustInfo.filter(info => info.trusted); return result; } @@ -79,7 +80,7 @@ export class WorkspaceTrustStorageService extends Disposable implements IWorkspa } getFolderTrustStateInfo(folder: URI): IWorkspaceTrustUriInfo { - let resultState = WorkspaceTrustState.Unspecified; + let resultState = false; let maxLength = -1; let resultUri = folder; @@ -89,50 +90,35 @@ export class WorkspaceTrustStorageService extends Disposable implements IWorkspa const fsPath = trustInfo.uri.fsPath; if (fsPath.length > maxLength) { maxLength = fsPath.length; - resultState = trustInfo.trustState; + resultState = trustInfo.trusted; resultUri = trustInfo.uri; } } } - return { trustState: resultState, uri: resultUri }; + return { trusted: resultState, uri: resultUri }; } - private setFolderTrustState(folder: URI, trustState: WorkspaceTrustState): boolean { - let changed = false; - - if (trustState === WorkspaceTrustState.Unspecified) { - const before = this.trustStateInfo.uriTrustInfo.length; - this.trustStateInfo.uriTrustInfo = this.trustStateInfo.uriTrustInfo.filter(info => this.uriIdentityService.extUri.isEqual(info.uri, folder)); - - if (this.trustStateInfo.uriTrustInfo.length !== before) { - changed = true; + private setFolderTrustState(folder: URI, trusted: boolean): boolean { + if (trusted) { + const foundItem = this.trustStateInfo.uriTrustInfo.find(trustInfo => this.uriIdentityService.extUri.isEqual(trustInfo.uri, folder)); + if (!foundItem) { + this.trustStateInfo.uriTrustInfo.push({ uri: folder, trusted: true }); + return true; } } else { - let found = false; - for (const trustInfo of this.trustStateInfo.uriTrustInfo) { - if (this.uriIdentityService.extUri.isEqual(trustInfo.uri, folder)) { - found = true; - if (trustInfo.trustState !== trustState) { - trustInfo.trustState = trustState; - changed = true; - } - } - } - - if (!found) { - this.trustStateInfo.uriTrustInfo.push({ uri: folder, trustState }); - changed = true; - } + const previousLength = this.trustStateInfo.uriTrustInfo.length; + this.trustStateInfo.uriTrustInfo = this.trustStateInfo.uriTrustInfo.filter(trustInfo => !this.uriIdentityService.extUri.isEqual(trustInfo.uri, folder)); + return previousLength !== this.trustStateInfo.uriTrustInfo.length; } - return changed; + return false; } - setFoldersTrustState(folders: URI[], trustState: WorkspaceTrustState): void { + setFoldersTrust(folders: URI[], trusted: boolean): void { let changed = false; for (const folder of folders) { - changed = this.setFolderTrustState(folder, trustState) || changed; + changed = this.setFolderTrustState(folder, trusted) || changed; } if (changed) { @@ -140,45 +126,25 @@ export class WorkspaceTrustStorageService extends Disposable implements IWorkspa } } - getFoldersTrustState(folders: URI[]): WorkspaceTrustState { - let state = undefined; + getFoldersTrust(folders: URI[]): boolean { + let state = true; for (const folder of folders) { - const { trustState } = this.getFolderTrustStateInfo(folder); + const { trusted } = this.getFolderTrustStateInfo(folder); - switch (trustState) { - case WorkspaceTrustState.Untrusted: - return WorkspaceTrustState.Untrusted; - case WorkspaceTrustState.Unspecified: - state = trustState; - break; - case WorkspaceTrustState.Trusted: - if (state === undefined) { - state = trustState; - } - break; + if (!trusted) { + state = trusted; + return state; } } - return state ?? WorkspaceTrustState.Unspecified; + return state; } setTrustedFolders(folders: URI[]): void { - this.trustStateInfo.uriTrustInfo = this.trustStateInfo.uriTrustInfo.filter(folder => folder.trustState !== WorkspaceTrustState.Trusted); + this.trustStateInfo.uriTrustInfo = []; for (const folder of folders) { this.trustStateInfo.uriTrustInfo.push({ - trustState: WorkspaceTrustState.Trusted, - uri: folder - }); - } - - this.saveTrustInfo(); - } - - setUntrustedFolders(folders: URI[]): void { - this.trustStateInfo.uriTrustInfo = this.trustStateInfo.uriTrustInfo.filter(folder => folder.trustState !== WorkspaceTrustState.Untrusted); - for (const folder of folders) { - this.trustStateInfo.uriTrustInfo.push({ - trustState: WorkspaceTrustState.Untrusted, + trusted: true, uri: folder }); } @@ -195,10 +161,10 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork _serviceBrand: undefined; - private readonly _onDidChangeTrustState = this._register(new Emitter()); - readonly onDidChangeTrustState = this._onDidChangeTrustState.event; + private readonly _onDidChangeTrust = this._register(new Emitter()); + readonly onDidChangeTrust = this._onDidChangeTrust.event; - private _currentTrustState: WorkspaceTrustState = WorkspaceTrustState.Unspecified; + private _isWorkspaceTrusted: boolean = false; constructor( @IConfigurationService readonly configurationService: IConfigurationService, @@ -208,24 +174,19 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork ) { super(); - this._currentTrustState = this.calculateWorkspaceTrustState(); + this._isWorkspaceTrusted = this.calculateWorkspaceTrust(); - this._register(this.workspaceService.onDidChangeWorkspaceFolders(() => this.currentTrustState = this.calculateWorkspaceTrustState())); - this._register(this.workspaceTrustStorageService.onDidStorageChange(() => this.currentTrustState = this.calculateWorkspaceTrustState())); + this._register(this.workspaceService.onDidChangeWorkspaceFolders(() => this.currentTrustState = this.calculateWorkspaceTrust())); + this._register(this.workspaceTrustStorageService.onDidStorageChange(() => this.currentTrustState = this.calculateWorkspaceTrust())); this.logInitialWorkspaceTrustInfo(); } - private get currentTrustState(): WorkspaceTrustState { - return this._currentTrustState; - } + private set currentTrustState(trusted: boolean) { + if (this._isWorkspaceTrusted === trusted) { return; } + this._isWorkspaceTrusted = trusted; - private set currentTrustState(trustState: WorkspaceTrustState) { - if (this._currentTrustState === trustState) { return; } - const previousState = this._currentTrustState; - this._currentTrustState = trustState; - - this._onDidChangeTrustState.fire({ previousTrustState: previousState, currentTrustState: this._currentTrustState }); + this._onDidChangeTrust.fire(trusted); } private logInitialWorkspaceTrustInfo(): void { @@ -245,8 +206,8 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork const trustStateInfo = this.workspaceTrustStorageService.getTrustStateInfo(); this.telemetryService.publicLog2('workspaceTrustFolderCounts', { - trustedFoldersCount: trustStateInfo.uriTrustInfo.filter(item => item.trustState === WorkspaceTrustState.Trusted).length, - untrustedFoldersCount: trustStateInfo.uriTrustInfo.filter(item => item.trustState === WorkspaceTrustState.Untrusted).length + trustedFoldersCount: trustStateInfo.uriTrustInfo.filter(item => item.trusted).length, + untrustedFoldersCount: trustStateInfo.uriTrustInfo.filter(item => !item.trusted).length }); } @@ -280,8 +241,8 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork }; for (const folder of this.workspaceService.getWorkspace().folders) { - const { trustState, uri } = this.workspaceTrustStorageService.getFolderTrustStateInfo(folder.uri); - if (trustState !== WorkspaceTrustState.Trusted) { + const { trusted, uri } = this.workspaceTrustStorageService.getFolderTrustStateInfo(folder.uri); + if (!trusted) { continue; } @@ -293,30 +254,30 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork } } - private calculateWorkspaceTrustState(): WorkspaceTrustState { + private calculateWorkspaceTrust(): boolean { if (!this.isWorkspaceTrustEnabled()) { - return WorkspaceTrustState.Trusted; + return true; } if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) { - return WorkspaceTrustState.Trusted; + return true; } const folderURIs = this.workspaceService.getWorkspace().folders.map(f => f.uri); - const trustState = this.workspaceTrustStorageService.getFoldersTrustState(folderURIs); + const trusted = this.workspaceTrustStorageService.getFoldersTrust(folderURIs); this.logWorkspaceTrustFolderInfo(); - return trustState; + return trusted; } - getWorkspaceTrustState(): WorkspaceTrustState { - return this.currentTrustState; + isWorkpaceTrusted(): boolean { + return this._isWorkspaceTrusted; } - setWorkspaceTrustState(trustState: WorkspaceTrustState): void { + setWorkspaceTrust(trusted: boolean): void { const folderURIs = this.workspaceService.getWorkspace().folders.map(f => f.uri); - this.workspaceTrustStorageService.setFoldersTrustState(folderURIs, trustState); + this.workspaceTrustStorageService.setFoldersTrust(folderURIs, trusted); } isWorkspaceTrustEnabled(): boolean { @@ -327,18 +288,18 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork export class WorkspaceTrustRequestService extends Disposable implements IWorkspaceTrustRequestService { _serviceBrand: undefined; - private _currentTrustState!: WorkspaceTrustState; - private _trustRequestPromise?: Promise; - private _trustRequestResolver?: (trustState?: WorkspaceTrustState) => void; - private _modalTrustRequestPromise?: Promise; - private _modalTrustRequestResolver?: (trustState?: WorkspaceTrustState) => void; - private readonly _ctxWorkspaceTrustState: IContextKey; + private _trusted!: boolean; + private _trustRequestPromise?: Promise; + private _trustRequestResolver?: (trusted: boolean) => void; + private _modalTrustRequestPromise?: Promise; + private _modalTrustRequestResolver?: (trusted: boolean) => void; + private readonly _ctxWorkspaceTrustState: IContextKey; private readonly _ctxWorkspaceTrustPendingRequest: IContextKey; private readonly _onDidInitiateWorkspaceTrustRequest = this._register(new Emitter()); readonly onDidInitiateWorkspaceTrustRequest = this._onDidInitiateWorkspaceTrustRequest.event; - private readonly _onDidCompleteWorkspaceTrustRequest = this._register(new Emitter()); + private readonly _onDidCompleteWorkspaceTrustRequest = this._register(new Emitter()); readonly onDidCompleteWorkspaceTrustRequest = this._onDidCompleteWorkspaceTrustRequest.event; constructor( @@ -347,27 +308,27 @@ export class WorkspaceTrustRequestService extends Disposable implements IWorkspa ) { super(); - this._register(this.workspaceTrustManagementService.onDidChangeTrustState(trustState => this.onTrustStateChanged(trustState.currentTrustState))); + this._register(this.workspaceTrustManagementService.onDidChangeTrust(trusted => this.onTrustStateChanged(trusted))); - this._ctxWorkspaceTrustState = WorkspaceTrustContext.TrustState.bindTo(contextKeyService); + this._ctxWorkspaceTrustState = WorkspaceTrustContext.IsTrusted.bindTo(contextKeyService); this._ctxWorkspaceTrustPendingRequest = WorkspaceTrustContext.PendingRequest.bindTo(contextKeyService); - this.currentTrustState = this.workspaceTrustManagementService.getWorkspaceTrustState(); + this.trusted = this.workspaceTrustManagementService.isWorkpaceTrusted(); } - private get currentTrustState(): WorkspaceTrustState { - return this._currentTrustState; + private get trusted(): boolean { + return this._trusted; } - private set currentTrustState(trustState: WorkspaceTrustState) { - this._currentTrustState = trustState; - this._ctxWorkspaceTrustState.set(trustState); + private set trusted(trusted: boolean) { + this._trusted = trusted; + this._ctxWorkspaceTrustState.set(trusted); } - private onTrustStateChanged(trustState: WorkspaceTrustState): void { + private onTrustStateChanged(trusted: boolean): void { // Resolve any pending soft requests for workspace trust if (this._trustRequestResolver) { - this._trustRequestResolver(trustState); + this._trustRequestResolver(trusted); this._trustRequestResolver = undefined; this._trustRequestPromise = undefined; @@ -378,48 +339,44 @@ export class WorkspaceTrustRequestService extends Disposable implements IWorkspa this._ctxWorkspaceTrustPendingRequest.set(false); } - this.currentTrustState = trustState; + this.trusted = trusted; } cancelRequest(): void { if (this._modalTrustRequestResolver) { - this._modalTrustRequestResolver(undefined); + this._modalTrustRequestResolver(this.trusted); this._modalTrustRequestResolver = undefined; this._modalTrustRequestPromise = undefined; } } - completeRequest(trustState?: WorkspaceTrustState): void { + completeRequest(trusted?: boolean): void { if (this._modalTrustRequestResolver) { - this._modalTrustRequestResolver(trustState ?? this.currentTrustState); + this._modalTrustRequestResolver(trusted ?? this.trusted); this._modalTrustRequestResolver = undefined; this._modalTrustRequestPromise = undefined; } if (this._trustRequestResolver) { - this._trustRequestResolver(trustState ?? this.currentTrustState); + this._trustRequestResolver(trusted ?? this.trusted); this._trustRequestResolver = undefined; this._trustRequestPromise = undefined; } - if (trustState === undefined) { + if (trusted === undefined) { return; } - this.workspaceTrustManagementService.setWorkspaceTrustState(trustState); - this._onDidCompleteWorkspaceTrustRequest.fire(trustState); + this.workspaceTrustManagementService.setWorkspaceTrust(trusted); + this._onDidCompleteWorkspaceTrustRequest.fire(trusted); } - async requestWorkspaceTrust(options: WorkspaceTrustRequestOptions = { modal: true }): Promise { + async requestWorkspaceTrust(options: WorkspaceTrustRequestOptions = { modal: true }): Promise { // Trusted workspace - if (this.currentTrustState === WorkspaceTrustState.Trusted) { - return this.currentTrustState; - } - // Untrusted workspace - soft request - if (this.currentTrustState === WorkspaceTrustState.Untrusted && !options.modal) { - return this.currentTrustState; + if (this.trusted) { + return this.trusted; } if (options.modal) { diff --git a/src/vs/workbench/services/workspaces/test/common/testWorkspaceTrustService.ts b/src/vs/workbench/services/workspaces/test/common/testWorkspaceTrustService.ts index 7566447a11d..47698da6b99 100644 --- a/src/vs/workbench/services/workspaces/test/common/testWorkspaceTrustService.ts +++ b/src/vs/workbench/services/workspaces/test/common/testWorkspaceTrustService.ts @@ -5,18 +5,18 @@ import { Event } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; -import { WorkspaceTrustRequestOptions, IWorkspaceTrustManagementService, WorkspaceTrustChangeEvent, WorkspaceTrustState, IWorkspaceTrustRequestService, IWorkspaceTrustStorageService, IWorkspaceTrustStateInfo, IWorkspaceTrustUriInfo } from 'vs/platform/workspace/common/workspaceTrust'; +import { WorkspaceTrustRequestOptions, IWorkspaceTrustManagementService, WorkspaceTrustChangeEvent, IWorkspaceTrustRequestService, IWorkspaceTrustStorageService, IWorkspaceTrustStateInfo, IWorkspaceTrustUriInfo } from 'vs/platform/workspace/common/workspaceTrust'; export class TestWorkspaceTrustStorageService implements IWorkspaceTrustStorageService { _serviceBrand: undefined; onDidStorageChange: Event = Event.None; - setFoldersTrustState(folder: URI[], trustState: WorkspaceTrustState): void { + setFoldersTrust(folder: URI[], trusted: boolean): void { throw new Error('Method not implemented.'); } - getFoldersTrustState(folder: URI[]): WorkspaceTrustState { + getFoldersTrust(folder: URI[]): boolean { throw new Error('Method not implemented.'); } @@ -40,13 +40,13 @@ export class TestWorkspaceTrustStorageService implements IWorkspaceTrustStorageS export class TestWorkspaceTrustManagementService implements IWorkspaceTrustManagementService { _serviceBrand: undefined; - onDidChangeTrustState: WorkspaceTrustChangeEvent = Event.None; + onDidChangeTrust: WorkspaceTrustChangeEvent = Event.None; - getWorkspaceTrustState(): WorkspaceTrustState { - return WorkspaceTrustState.Trusted; + isWorkpaceTrusted(): boolean { + return true; } - setWorkspaceTrustState(trustState: WorkspaceTrustState): void { + setWorkspaceTrust(trusted: boolean): void { throw new Error('Method not implemented.'); } @@ -54,8 +54,8 @@ export class TestWorkspaceTrustManagementService implements IWorkspaceTrustManag return true; } - requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise { - return Promise.resolve(WorkspaceTrustState.Trusted); + requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise { + return Promise.resolve(true); } } @@ -63,18 +63,18 @@ export class TestWorkspaceTrustRequestService implements IWorkspaceTrustRequestS _serviceBrand: undefined; onDidInitiateWorkspaceTrustRequest: Event = Event.None; - onDidCompleteWorkspaceTrustRequest: Event = Event.None; + onDidCompleteWorkspaceTrustRequest: Event = Event.None; cancelRequest(): void { throw new Error('Method not implemented.'); } - completeRequest(trustState?: WorkspaceTrustState): void { + completeRequest(trusted?: boolean): void { throw new Error('Method not implemented.'); } - requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise { - return Promise.resolve(WorkspaceTrustState.Trusted); + requestWorkspaceTrust(options?: WorkspaceTrustRequestOptions): Promise { + return Promise.resolve(true); } } diff --git a/src/vs/workbench/test/browser/api/extHostConfiguration.test.ts b/src/vs/workbench/test/browser/api/extHostConfiguration.test.ts index 99888cc64c3..ed9d51dd34f 100644 --- a/src/vs/workbench/test/browser/api/extHostConfiguration.test.ts +++ b/src/vs/workbench/test/browser/api/extHostConfiguration.test.ts @@ -18,7 +18,6 @@ import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitData import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo'; import { FileSystemProviderCapabilities } from 'vs/platform/files/common/files'; import { isLinux } from 'vs/base/common/platform'; -import { WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; suite('ExtHostConfiguration', function () { @@ -319,7 +318,7 @@ suite('ExtHostConfiguration', function () { 'id': 'foo', 'folders': [aWorkspaceFolder(URI.file('foo'), 0)], 'name': 'foo' - }, WorkspaceTrustState.Trusted); + }, true); const testObject = new ExtHostConfigProvider( new class extends mock() { }, extHostWorkspace, @@ -395,7 +394,7 @@ suite('ExtHostConfiguration', function () { 'id': 'foo', 'folders': [aWorkspaceFolder(firstRoot, 0), aWorkspaceFolder(secondRoot, 1)], 'name': 'foo' - }, WorkspaceTrustState.Trusted); + }, true); const testObject = new ExtHostConfigProvider( new class extends mock() { }, extHostWorkspace, @@ -498,7 +497,7 @@ suite('ExtHostConfiguration', function () { 'id': 'foo', 'folders': [aWorkspaceFolder(firstRoot, 0), aWorkspaceFolder(secondRoot, 1)], 'name': 'foo' - }, WorkspaceTrustState.Trusted); + }, true); const testObject = new ExtHostConfigProvider( new class extends mock() { }, extHostWorkspace, @@ -676,7 +675,7 @@ suite('ExtHostConfiguration', function () { 'id': 'foo', 'folders': [workspaceFolder], 'name': 'foo' - }, WorkspaceTrustState.Trusted); + }, true); const testObject = new ExtHostConfigProvider( new class extends mock() { }, extHostWorkspace, diff --git a/src/vs/workbench/test/browser/api/extHostWorkspace.test.ts b/src/vs/workbench/test/browser/api/extHostWorkspace.test.ts index a70427a872c..7abb980a9c4 100644 --- a/src/vs/workbench/test/browser/api/extHostWorkspace.test.ts +++ b/src/vs/workbench/test/browser/api/extHostWorkspace.test.ts @@ -23,7 +23,6 @@ import { IPatternInfo } from 'vs/workbench/services/search/common/search'; import { isLinux, isWindows } from 'vs/base/common/platform'; import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo'; import { FileSystemProviderCapabilities } from 'vs/platform/files/common/files'; -import { WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust'; function createExtHostWorkspace(mainContext: IMainContext, data: IWorkspaceData, logService: ILogService): ExtHostWorkspace { const result = new ExtHostWorkspace( @@ -32,7 +31,7 @@ function createExtHostWorkspace(mainContext: IMainContext, data: IWorkspaceData, new class extends mock() { override getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } }, logService, ); - result.$initializeWorkspace(data, WorkspaceTrustState.Trusted); + result.$initializeWorkspace(data, true); return result; }