From 5d94a7c95508c8a9f73dfdbac9b0cc68d2506ac8 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Tue, 6 Apr 2021 12:27:34 +0200 Subject: [PATCH] Refactor worksspace trust setting --- .../preferences/browser/settingsLayout.ts | 11 ++++++ .../browser/relauncher.contribution.ts | 8 +++++ .../browser/workspace.contribution.ts | 34 +++++++++---------- .../workspaces/common/workspaceTrust.ts | 2 +- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/contrib/preferences/browser/settingsLayout.ts b/src/vs/workbench/contrib/preferences/browser/settingsLayout.ts index 1e0aa90941626..de10a05a9e67c 100644 --- a/src/vs/workbench/contrib/preferences/browser/settingsLayout.ts +++ b/src/vs/workbench/contrib/preferences/browser/settingsLayout.ts @@ -224,6 +224,17 @@ export const tocData: ITOCEntry = { settings: ['settingsSync.*'] } ] + }, + { + id: 'security', + label: localize('security', "Security"), + children: [ + { + id: 'security/workspace', + label: localize('workspace', "Workspace"), + settings: ['security.workspace.*'] + } + ] } ] }; diff --git a/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts b/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts index 5a26733a76a57..fe6cad7894620 100644 --- a/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts +++ b/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts @@ -25,6 +25,7 @@ interface IConfiguration extends IWindowsConfiguration { update: { mode: string; }; debug: { console: { wordWrap: boolean } }; editor: { accessibilitySupport: 'on' | 'off' | 'auto' }; + security: { workspace: { trust: { enabled: boolean } } } } export class SettingsChangeRelauncher extends Disposable implements IWorkbenchContribution { @@ -35,6 +36,7 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo private clickThroughInactive: boolean | undefined; private updateMode: string | undefined; private accessibilitySupport: 'on' | 'off' | 'auto' | undefined; + private workspaceTrustEnabled: boolean | undefined; constructor( @IHostService private readonly hostService: IHostService, @@ -90,6 +92,12 @@ export class SettingsChangeRelauncher extends Disposable implements IWorkbenchCo changed = true; } } + + // Workspace trust + if (typeof config.security?.workspace.trust.enabled === 'boolean' && config.security?.workspace.trust.enabled !== this.workspaceTrustEnabled) { + this.workspaceTrustEnabled = config.security.workspace.trust.enabled; + changed = true; + } } // Notify only when changed and we are the focused window (avoids notification spam across windows) diff --git a/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts b/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts index c35a5b063d339..9e2e5adab8344 100644 --- a/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts +++ b/src/vs/workbench/contrib/workspace/browser/workspace.contribution.ts @@ -8,6 +8,7 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle'; import { localize } from 'vs/nls'; import { Action2, MenuId, MenuRegistry, registerAction2 } from 'vs/platform/actions/common/actions'; +import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry'; 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'; @@ -22,7 +23,6 @@ import { ThemeColor } from 'vs/workbench/api/common/extHostTypes'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { ICommandService } from 'vs/platform/commands/common/commands'; -import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IHostService } from 'vs/workbench/services/host/browser/host'; import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from 'vs/workbench/services/statusbar/common/statusbar'; import { IEditorRegistry, Extensions as EditorExtensions, EditorDescriptor } from 'vs/workbench/browser/editor'; @@ -50,7 +50,6 @@ export class WorkspaceTrustRequestHandler extends Disposable implements IWorkben @IDialogService private readonly dialogService: IDialogService, @IActivityService private readonly activityService: IActivityService, @ICommandService private readonly commandService: ICommandService, - @IConfigurationService private readonly configurationService: IConfigurationService, @ITelemetryService private readonly telemetryService: ITelemetryService, @IExtensionService private readonly extensionService: IExtensionService, @IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService, @@ -185,21 +184,6 @@ export class WorkspaceTrustRequestHandler extends Disposable implements IWorkben } })); - this._register(this.configurationService.onDidChangeConfiguration(e => { - if (e.affectsConfiguration(WORKSPACE_TRUST_ENABLED)) { - const isEnabled = this.configurationService.inspect(WORKSPACE_TRUST_ENABLED).userValue; - if (!isEnabled || typeof isEnabled === 'boolean') { - this.dialogService.confirm({ - message: localize('trustConfigurationChangeMessage', "In order for this change to take effect, the window needs to be reloaded. Do you want to reload the window now?") - }).then(result => { - if (result.confirmed) { - this.hostService.reload(); - } - }); - } - } - })); - // Don't auto-show the UX editor if the request is 5 seconds after startup setTimeout(() => { this.shouldShowManagementEditor = false; }, 5000); } @@ -425,3 +409,19 @@ MenuRegistry.appendMenuItem(MenuId.GlobalActivity, { order: 40, when: ContextKeyExpr.and(ContextKeyExpr.equals(`config.${WORKSPACE_TRUST_ENABLED}`, true), WorkspaceTrustContext.PendingRequest) }); + +// Configuration +Registry.as(ConfigurationExtensions.Configuration) + .registerConfiguration({ + id: 'security', + order: 7, + title: localize('securityConfigurationTitle', "Security"), + type: 'object', + properties: { + [WORKSPACE_TRUST_ENABLED]: { + type: 'boolean', + default: false, + description: localize('workspace.trust.description', "Controls whether or not workspace trust is enabled within VS Code."), + } + } + }); diff --git a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts index c234b5fcea7c5..8783c4d867600 100644 --- a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts +++ b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts @@ -17,7 +17,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { dirname, resolve } from 'vs/base/common/path'; import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; -export const WORKSPACE_TRUST_ENABLED = 'workspace.trustEnabled'; +export const WORKSPACE_TRUST_ENABLED = 'security.workspace.trust.enabled'; export const WORKSPACE_TRUST_STORAGE_KEY = 'content.trust.model.key'; export const WorkspaceTrustContext = {