Skip to content

Commit

Permalink
Merge pull request #163414 from microsoft/sandy081/dangerous-catfish
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Oct 12, 2022
2 parents 4ca6830 + d769a2f commit d045a5e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
*--------------------------------------------------------------------------------------------*/

import { localize } from 'vs/nls';
import { ExtensionInstallLocation, IExtensionManagementServer, IExtensionManagementServerService, IProfileAwareExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { ExtensionInstallLocation, IExtensionManagementServer, IExtensionManagementServerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { Schemas } from 'vs/base/common/network';
import { Event } from 'vs/base/common/event';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ILabelService } from 'vs/platform/label/common/label';
import { isWeb } from 'vs/base/common/platform';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { WebExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/webExtensionManagementService';
import { IExtension } from 'vs/platform/extensions/common/extensions';
import { ExtensionManagementChannelClient } from 'vs/platform/extensionManagement/common/extensionManagementIpc';
import { RemoteExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/remoteExtensionManagementService';

export class ExtensionManagementServerService implements IExtensionManagementServerService {

Expand All @@ -32,13 +31,7 @@ export class ExtensionManagementServerService implements IExtensionManagementSer
) {
const remoteAgentConnection = remoteAgentService.getConnection();
if (remoteAgentConnection) {
const extensionManagementService = new class extends ExtensionManagementChannelClient implements IProfileAwareExtensionManagementService {
get onProfileAwareInstallExtension() { return super.onInstallExtension; }
get onProfileAwareDidInstallExtensions() { return super.onDidInstallExtensions; }
get onProfileAwareUninstallExtension() { return super.onUninstallExtension; }
get onProfileAwareDidUninstallExtension() { return super.onDidUninstallExtension; }
readonly onDidChangeProfile = Event.None;
}(remoteAgentConnection.getChannel<IChannel>('extensions'));
const extensionManagementService = instantiationService.createInstance(RemoteExtensionManagementService, remoteAgentConnection.getChannel<IChannel>('extensions'));
this.remoteExtensionManagementServer = {
id: 'remote',
extensionManagementService,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { Event } from 'vs/base/common/event';
import { ILocalExtension, IGalleryExtension, InstallOptions, InstallVSIXOptions, UninstallOptions } from 'vs/platform/extensionManagement/common/extensionManagement';
import { URI } from 'vs/base/common/uri';
import { ExtensionType } from 'vs/platform/extensions/common/extensions';
import { IProfileAwareExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { ExtensionManagementChannelClient } from 'vs/platform/extensionManagement/common/extensionManagementIpc';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';

export class RemoteExtensionManagementService extends ExtensionManagementChannelClient implements IProfileAwareExtensionManagementService {

readonly onDidChangeProfile = Event.None;
get onProfileAwareInstallExtension() { return super.onInstallExtension; }
get onProfileAwareDidInstallExtensions() { return super.onDidInstallExtensions; }
get onProfileAwareUninstallExtension() { return super.onUninstallExtension; }
get onProfileAwareDidUninstallExtension() { return super.onDidUninstallExtension; }

constructor(
channel: IChannel,
@IUserDataProfilesService private readonly userDataProfileService: IUserDataProfilesService,
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService,
) {
super(channel);
}

override getInstalled(type: ExtensionType | null = null, profileLocation?: URI): Promise<ILocalExtension[]> {
this.validateProfileLocation({ profileLocation });
return super.getInstalled(type);
}

override uninstall(extension: ILocalExtension, options?: UninstallOptions): Promise<void> {
options = this.validateProfileLocation(options);
return super.uninstall(extension, options);
}

override async install(vsix: URI, options?: InstallVSIXOptions): Promise<ILocalExtension> {
options = this.validateProfileLocation(options);
return super.install(vsix, options);
}

override async installFromGallery(extension: IGalleryExtension, options?: InstallOptions): Promise<ILocalExtension> {
options = this.validateProfileLocation(options);
return super.installFromGallery(extension, options);
}

private validateProfileLocation<T extends { profileLocation?: URI }>(options?: T): T | undefined {
if (options?.profileLocation) {
if (!this.uriIdentityService.extUri.isEqual(options?.profileLocation, this.userDataProfileService.defaultProfile.extensionsResource)) {
throw new Error('This operataion is not supported in remote scenario');
}
options = { ...options, profileLocation: undefined };
}
return options;
}

}

0 comments on commit d045a5e

Please sign in to comment.