Factor in workspace trust when installing/enabling an extension (#119069)

This commit is contained in:
Ladislau Szomoru
2021-04-01 14:13:05 +02:00
committed by GitHub
parent ee2fd0ea63
commit 5dc3db6ca2
2 changed files with 28 additions and 12 deletions
@@ -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 { IWorkspaceTrustService, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust';
import { IWorkspaceTrustService, WorkspaceTrustState, WorkspaceTrustStateChangeEvent } from 'vs/platform/workspace/common/workspaceTrust';
import { Promises } from 'vs/base/common/async';
const SOURCE = 'IWorkbenchExtensionEnablementService';
@@ -64,18 +64,13 @@ 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.workspaceTrustService.onDidChangeTrustState(this._onDidChangeTrustState, this));
// Trusted extensions notification
// TODO: Confirm that this is the right lifecycle phase
this.lifecycleService.when(LifecyclePhase.Eventually).then(() => {
if (this.extensionsDisabledByTrustRequirement.length > 0) {
this.workspaceTrustService.requireWorkspaceTrust({ modal: false })
.then(trustState => {
if (trustState === WorkspaceTrustState.Trusted) {
this._onEnablementChanged.fire(this.extensionsDisabledByTrustRequirement);
this.extensionsDisabledByTrustRequirement = [];
}
});
this.workspaceTrustService.requireWorkspaceTrust({ modal: false });
}
});
@@ -447,7 +442,8 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
private _onDidInstallExtension({ local, error }: DidInstallExtensionEvent): void {
if (local && !error && this._isDisabledByTrustRequirement(local)) {
this.workspaceTrustService.requireWorkspaceTrust();
this.workspaceTrustService.requireWorkspaceTrust({ modal: false });
this._onEnablementChanged.fire([local]);
}
}
@@ -457,6 +453,13 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
}
}
private _onDidChangeTrustState({ currentTrustState }: WorkspaceTrustStateChangeEvent): void {
if (currentTrustState === WorkspaceTrustState.Trusted && this.extensionsDisabledByTrustRequirement.length > 0) {
this._onEnablementChanged.fire(this.extensionsDisabledByTrustRequirement);
this.extensionsDisabledByTrustRequirement = [];
}
}
private _reset(extension: IExtensionIdentifier) {
this._removeFromWorkspaceDisabledExtensions(extension);
this._removeFromWorkspaceEnabledExtensions(extension);
@@ -25,7 +25,7 @@ import Severity from 'vs/base/common/severity';
import { canceled } from 'vs/base/common/errors';
import { IUserDataAutoSyncEnablementService, IUserDataSyncResourceEnablementService, SyncResource } from 'vs/platform/userDataSync/common/userDataSync';
import { Promises } from 'vs/base/common/async';
import { IWorkspaceTrustService, WorkspaceTrustState } from 'vs/platform/workspace/common/workspaceTrust';
import { IWorkspaceTrustService } from 'vs/platform/workspace/common/workspaceTrust';
export class ExtensionManagementService extends Disposable implements IWorkbenchExtensionManagementService {
@@ -362,8 +362,21 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
protected async checkForWorkspaceTrust(manifest: IExtensionManifest): Promise<void> {
if (getExtensionWorkspaceTrustRequirement(manifest) === 'onStart') {
const trustState = await this.workspaceTrustService.requireWorkspaceTrust();
return trustState === WorkspaceTrustState.Trusted ? Promise.resolve() : Promise.reject(canceled());
try {
await this.workspaceTrustService.requireWorkspaceTrust({
modal: true,
message: localize('extensionInstallWorkspaceTrustMessage', "Enabling this extension requires a trusted workspace."),
buttons: [
{ label: localize('extensionInstallWorkspaceTrustButton', "Trust Workspace & Install"), type: 'ContinueWithTrust' },
{ label: localize('extensionInstallWorkspaceTrustContinueButton', "Install"), type: 'ContinueWithoutTrust' },
{ label: localize('extensionInstallWorkspaceTrustManageButton', "Learn More"), type: 'Manage' }
]
});
return Promise.resolve();
}
catch (error) {
return Promise.reject(error);
}
}
return Promise.resolve();
}