chore(vscode): update to 1.54.2
This commit is contained in:
@@ -35,17 +35,6 @@
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} channel
|
||||
* @param {any} message
|
||||
* @param {MessagePort[]} transfer
|
||||
*/
|
||||
postMessage(channel, message, transfer) {
|
||||
if (validateIPC(channel)) {
|
||||
ipcRenderer.postMessage(channel, message, transfer);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} channel
|
||||
* @param {any[]} args
|
||||
@@ -88,6 +77,33 @@
|
||||
}
|
||||
},
|
||||
|
||||
ipcMessagePort: {
|
||||
|
||||
/**
|
||||
* @param {string} channelRequest
|
||||
* @param {string} channelResponse
|
||||
* @param {string} requestNonce
|
||||
*/
|
||||
connect(channelRequest, channelResponse, requestNonce) {
|
||||
if (validateIPC(channelRequest) && validateIPC(channelResponse)) {
|
||||
const responseListener = (/** @type {import('electron').IpcRendererEvent} */ e, /** @type {string} */ responseNonce) => {
|
||||
// validate that the nonce from the response is the same
|
||||
// as when requested. and if so, use `postMessage` to
|
||||
// send the `MessagePort` safely over, even when context
|
||||
// isolation is enabled
|
||||
if (requestNonce === responseNonce) {
|
||||
ipcRenderer.off(channelResponse, responseListener);
|
||||
window.postMessage(requestNonce, '*', e.ports);
|
||||
}
|
||||
};
|
||||
|
||||
// request message port from main and await result
|
||||
ipcRenderer.on(channelResponse, responseListener);
|
||||
ipcRenderer.send(channelRequest, requestNonce);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Support for subset of methods of Electron's `webFrame` type.
|
||||
*/
|
||||
|
||||
@@ -15,10 +15,12 @@ export interface IpcRendererEvent extends Event {
|
||||
|
||||
// Docs: https://electronjs.org/docs/api/structures/ipc-renderer-event
|
||||
|
||||
/**
|
||||
* A list of MessagePorts that were transferred with this message
|
||||
*/
|
||||
ports: MessagePort[];
|
||||
// Note: API with `Transferable` intentionally commented out because you
|
||||
// cannot transfer these when `contextIsolation: true`.
|
||||
// /**
|
||||
// * A list of MessagePorts that were transferred with this message
|
||||
// */
|
||||
// ports: MessagePort[];
|
||||
/**
|
||||
* The `IpcRenderer` instance that emitted the event originally
|
||||
*/
|
||||
@@ -93,20 +95,23 @@ export interface IpcRenderer {
|
||||
* If you do not need a response to the message, consider using `ipcRenderer.send`.
|
||||
*/
|
||||
invoke(channel: string, ...args: any[]): Promise<any>;
|
||||
/**
|
||||
* Send a message to the main process, optionally transferring ownership of zero or
|
||||
* more `MessagePort` objects.
|
||||
*
|
||||
* The transferred `MessagePort` objects will be available in the main process as
|
||||
* `MessagePortMain` objects by accessing the `ports` property of the emitted
|
||||
* event.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* For more information on using `MessagePort` and `MessageChannel`, see the MDN
|
||||
* documentation.
|
||||
*/
|
||||
postMessage(channel: string, message: any, transfer?: MessagePort[]): void;
|
||||
|
||||
// Note: API with `Transferable` intentionally commented out because you
|
||||
// cannot transfer these when `contextIsolation: true`.
|
||||
// /**
|
||||
// * Send a message to the main process, optionally transferring ownership of zero or
|
||||
// * more `MessagePort` objects.
|
||||
// *
|
||||
// * The transferred `MessagePort` objects will be available in the main process as
|
||||
// * `MessagePortMain` objects by accessing the `ports` property of the emitted
|
||||
// * event.
|
||||
// *
|
||||
// * For example:
|
||||
// *
|
||||
// * For more information on using `MessagePort` and `MessageChannel`, see the MDN
|
||||
// * documentation.
|
||||
// */
|
||||
// postMessage(channel: string, message: any): void;
|
||||
}
|
||||
|
||||
export interface WebFrame {
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { globals, INodeProcess, IProcessEnvironment } from 'vs/base/common/platform';
|
||||
import { globals, IProcessEnvironment } from 'vs/base/common/platform';
|
||||
import { ProcessMemoryInfo, CrashReporter, IpcRenderer, WebFrame } from 'vs/base/parts/sandbox/electron-sandbox/electronTypes';
|
||||
|
||||
export interface ISandboxNodeProcess extends INodeProcess {
|
||||
/**
|
||||
* In sandboxed renderers we cannot expose all of the `process` global of node.js
|
||||
*/
|
||||
export interface IPartialNodeProcess {
|
||||
|
||||
/**
|
||||
* The process.platform property returns a string identifying the operating system platform
|
||||
@@ -40,24 +43,6 @@ export interface ISandboxNodeProcess extends INodeProcess {
|
||||
*/
|
||||
readonly execPath: string;
|
||||
|
||||
/**
|
||||
* Resolve the true process environment to use and apply it to `process.env`.
|
||||
*
|
||||
* There are different layers of environment that will apply:
|
||||
* - `process.env`: this is the actual environment of the process before this method
|
||||
* - `shellEnv` : if the program was not started from a terminal, we resolve all shell
|
||||
* variables to get the same experience as if the program was started from
|
||||
* a terminal (Linux, macOS)
|
||||
* - `userEnv` : this is instance specific environment, e.g. if the user started the program
|
||||
* from a terminal and changed certain variables
|
||||
*
|
||||
* The order of overwrites is `process.env` < `shellEnv` < `userEnv`.
|
||||
*
|
||||
* It is critical that every process awaits this method early on startup to get the right
|
||||
* set of environment in `process.env`.
|
||||
*/
|
||||
resolveEnv(userEnv: IProcessEnvironment): Promise<void>;
|
||||
|
||||
/**
|
||||
* A listener on the process. Only a small subset of listener types are allowed.
|
||||
*/
|
||||
@@ -79,6 +64,28 @@ export interface ISandboxNodeProcess extends INodeProcess {
|
||||
getProcessMemoryInfo: () => Promise<ProcessMemoryInfo>;
|
||||
}
|
||||
|
||||
export interface ISandboxNodeProcess extends IPartialNodeProcess {
|
||||
|
||||
/**
|
||||
* A custom method we add to `process`: Resolve the true process environment to use and
|
||||
* apply it to `process.env`.
|
||||
*
|
||||
* There are different layers of environment that will apply:
|
||||
* - `process.env`: this is the actual environment of the process before this method
|
||||
* - `shellEnv` : if the program was not started from a terminal, we resolve all shell
|
||||
* variables to get the same experience as if the program was started from
|
||||
* a terminal (Linux, macOS)
|
||||
* - `userEnv` : this is instance specific environment, e.g. if the user started the program
|
||||
* from a terminal and changed certain variables
|
||||
*
|
||||
* The order of overwrites is `process.env` < `shellEnv` < `userEnv`.
|
||||
*
|
||||
* It is critical that every process awaits this method early on startup to get the right
|
||||
* set of environment in `process.env`.
|
||||
*/
|
||||
resolveEnv(userEnv: IProcessEnvironment): Promise<void>;
|
||||
}
|
||||
|
||||
export interface ISandboxContext {
|
||||
|
||||
/**
|
||||
@@ -87,7 +94,23 @@ export interface ISandboxContext {
|
||||
sandbox: boolean;
|
||||
}
|
||||
|
||||
export interface IpcMessagePort {
|
||||
|
||||
/**
|
||||
* Establish a connection via `MessagePort` to a target. The main process
|
||||
* will need to transfer the port over to the `channelResponse` after listening
|
||||
* to `channelRequest` with a payload of `requestNonce` so that the
|
||||
* source can correlate the response.
|
||||
*
|
||||
* The source should install a `window.on('message')` listener, ensuring `e.data`
|
||||
* matches `requestNonce`, `e.source` matches `window` and then receiving the
|
||||
* `MessagePort` via `e.ports[0]`.
|
||||
*/
|
||||
connect(channelRequest: string, channelResponse: string, requestNonce: string): void;
|
||||
}
|
||||
|
||||
export const ipcRenderer: IpcRenderer = globals.vscode.ipcRenderer;
|
||||
export const ipcMessagePort: IpcMessagePort = globals.vscode.ipcMessagePort;
|
||||
export const webFrame: WebFrame = globals.vscode.webFrame;
|
||||
export const crashReporter: CrashReporter = globals.vscode.crashReporter;
|
||||
export const process: ISandboxNodeProcess = globals.vscode.process;
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { ipcRenderer, crashReporter, webFrame } from 'vs/base/parts/sandbox/electron-sandbox/globals';
|
||||
import { ipcRenderer, crashReporter, webFrame, process } from 'vs/base/parts/sandbox/electron-sandbox/globals';
|
||||
|
||||
suite('Sandbox', () => {
|
||||
test('globals', () => {
|
||||
assert.ok(ipcRenderer);
|
||||
assert.ok(crashReporter);
|
||||
assert.ok(webFrame);
|
||||
assert.ok(typeof ipcRenderer.invoke === 'function');
|
||||
assert.ok(typeof crashReporter.addExtraParameter === 'function');
|
||||
assert.ok(typeof webFrame.setZoomLevel === 'function');
|
||||
assert.ok(typeof process.platform === 'string');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user