mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
Enable IPC API for web (#138054)
* wip: ipc api * wip: send message ports upfront * address both inside and outside iframe * fix build * relay MessagePort to worker * address api discussion feedback * check for proposed api * fix layer breakage Co-authored-by: Alex Dima <alexdima@microsoft.com>
This commit is contained in:
@@ -98,6 +98,12 @@ export interface IWorkspaceData extends IStaticWorkspaceData {
|
||||
folders: { uri: UriComponents, name: string, index: number; }[];
|
||||
}
|
||||
|
||||
export interface MessagePortLike {
|
||||
postMessage(message: any, transfer?: any[]): void;
|
||||
addEventListener(type: 'message', listener: (e: any) => any): void;
|
||||
removeEventListener(type: 'message', listener: (e: any) => any): void;
|
||||
}
|
||||
|
||||
export interface IInitData {
|
||||
version: string;
|
||||
commit?: string;
|
||||
@@ -114,6 +120,7 @@ export interface IInitData {
|
||||
autoStart: boolean;
|
||||
remote: { isRemote: boolean; authority: string | undefined; connectionData: IRemoteConnectionData | null; };
|
||||
uiKind: UIKind;
|
||||
messagePorts?: ReadonlyMap<string, MessagePortLike>;
|
||||
}
|
||||
|
||||
export interface IConfigurationInitData extends IConfigurationData {
|
||||
@@ -2260,7 +2267,7 @@ export const MainContext = {
|
||||
MainThreadTheming: createMainId<MainThreadThemingShape>('MainThreadTheming'),
|
||||
MainThreadTunnelService: createMainId<MainThreadTunnelServiceShape>('MainThreadTunnelService'),
|
||||
MainThreadTimeline: createMainId<MainThreadTimelineShape>('MainThreadTimeline'),
|
||||
MainThreadTesting: createMainId<MainThreadTestingShape>('MainThreadTesting')
|
||||
MainThreadTesting: createMainId<MainThreadTestingShape>('MainThreadTesting'),
|
||||
};
|
||||
|
||||
export const ExtHostContext = {
|
||||
|
||||
@@ -17,7 +17,7 @@ import { ExtHostConfiguration, IExtHostConfiguration } from 'vs/workbench/api/co
|
||||
import { ActivatedExtension, EmptyExtension, ExtensionActivationReason, ExtensionActivationTimes, ExtensionActivationTimesBuilder, ExtensionsActivator, IExtensionAPI, IExtensionModule, HostExtension, ExtensionActivationTimesFragment } from 'vs/workbench/api/common/extHostExtensionActivator';
|
||||
import { ExtHostStorage, IExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
|
||||
import { ExtHostWorkspace, IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
|
||||
import { MissingExtensionDependency, ActivationKind, checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { MissingExtensionDependency, ActivationKind, checkProposedApiEnabled, isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
|
||||
import * as errors from 'vs/base/common/errors';
|
||||
import type * as vscode from 'vscode';
|
||||
@@ -424,6 +424,10 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
|
||||
const that = this;
|
||||
let extension: vscode.Extension<any> | undefined;
|
||||
|
||||
const messagePort = isProposedApiEnabled(extensionDescription, 'ipc')
|
||||
? this._initData.messagePorts?.get(ExtensionIdentifier.toKey(extensionDescription.identifier))
|
||||
: undefined;
|
||||
|
||||
return Object.freeze<vscode.ExtensionContext>({
|
||||
globalState,
|
||||
workspaceState,
|
||||
@@ -449,7 +453,11 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
|
||||
checkProposedApiEnabled(extensionDescription, 'extensionRuntime');
|
||||
return that.extensionRuntime;
|
||||
},
|
||||
get environmentVariableCollection() { return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); }
|
||||
get environmentVariableCollection() { return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); },
|
||||
messagePassingProtocol: messagePort && {
|
||||
onDidReceiveMessage: Event.fromDOMEventEmitter(messagePort, 'message', e => e.data),
|
||||
postMessage: messagePort.postMessage.bind(messagePort) as any
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user