Skip to content

Commit

Permalink
Factor in workspace trust when installing/enabling an extension (#119069
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lszomoru committed Apr 1, 2021
1 parent ee2fd0e commit 5dc3db6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
}
});

Expand Down Expand Up @@ -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]);
}
}

Expand All @@ -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);
Expand Down
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 5dc3db6

Please sign in to comment.