Path: blob/main/src/vs/base/parts/sandbox/electron-browser/globals.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { INodeProcess, IProcessEnvironment } from '../../../common/platform.js';6import { ISandboxConfiguration } from '../common/sandboxTypes.js';7import { IpcRenderer, ProcessMemoryInfo, WebFrame, WebUtils } from './electronTypes.js';89/**10* In Electron renderers we cannot expose all of the `process` global of node.js11*/12export interface ISandboxNodeProcess extends INodeProcess {1314/**15* The process.platform property returns a string identifying the operating system platform16* on which the Node.js process is running.17*/18readonly platform: string;1920/**21* The process.arch property returns a string identifying the CPU architecture22* on which the Node.js process is running.23*/24readonly arch: string;2526/**27* The type will always be `renderer`.28*/29readonly type: string;3031/**32* A list of versions for the current node.js/electron configuration.33*/34readonly versions: { [key: string]: string | undefined };3536/**37* The process.env property returns an object containing the user environment.38*/39readonly env: IProcessEnvironment;4041/**42* The `execPath` will be the location of the executable of this application.43*/44readonly execPath: string;4546/**47* A listener on the process. Only a small subset of listener types are allowed.48*/49on: (type: string, callback: Function) => void;5051/**52* The current working directory of the process.53*/54cwd: () => string;5556/**57* Resolves with a ProcessMemoryInfo58*59* Returns an object giving memory usage statistics about the current process. Note60* that all statistics are reported in Kilobytes. This api should be called after61* app ready.62*63* Chromium does not provide `residentSet` value for macOS. This is because macOS64* performs in-memory compression of pages that haven't been recently used. As a65* result the resident set size value is not what one would expect. `private`66* memory is more representative of the actual pre-compression memory usage of the67* process on macOS.68*/69getProcessMemoryInfo: () => Promise<ProcessMemoryInfo>;7071/**72* Returns a process environment that includes all shell environment variables even if73* the application was not started from a shell / terminal / console.74*75* There are different layers of environment that will apply:76* - `process.env`: this is the actual environment of the process before this method77* - `shellEnv` : if the program was not started from a terminal, we resolve all shell78* variables to get the same experience as if the program was started from79* a terminal (Linux, macOS)80* - `userEnv` : this is instance specific environment, e.g. if the user started the program81* from a terminal and changed certain variables82*83* The order of overwrites is `process.env` < `shellEnv` < `userEnv`.84*/85shellEnv(): Promise<IProcessEnvironment>;86}8788export interface IpcMessagePort {8990/**91* Acquire a `MessagePort`. The main process will transfer the port over to92* the `responseChannel` with a payload of `requestNonce` so that the source can93* correlate the response.94*95* The source should install a `window.on('message')` listener, ensuring `e.data`96* matches `nonce`, `e.source` matches `window` and then receiving the `MessagePort`97* via `e.ports[0]`.98*/99acquire(responseChannel: string, nonce: string): void;100}101102export interface ISandboxContext {103104/**105* A configuration object made accessible from the main side106* to configure the sandbox browser window. Will be `undefined`107* for as long as `resolveConfiguration` is not awaited.108*/109configuration(): ISandboxConfiguration | undefined;110111/**112* Allows to await the resolution of the configuration object.113*/114resolveConfiguration(): Promise<ISandboxConfiguration>;115}116117const vscodeGlobal = (globalThis as any).vscode;118export const ipcRenderer: IpcRenderer = vscodeGlobal.ipcRenderer;119export const ipcMessagePort: IpcMessagePort = vscodeGlobal.ipcMessagePort;120export const webFrame: WebFrame = vscodeGlobal.webFrame;121export const process: ISandboxNodeProcess = vscodeGlobal.process;122export const context: ISandboxContext = vscodeGlobal.context;123export const webUtils: WebUtils = vscodeGlobal.webUtils;124125/**126* A set of globals only available to main windows that depend127* on `preload.js`.128*/129export interface IMainWindowSandboxGlobals {130readonly ipcRenderer: IpcRenderer;131readonly ipcMessagePort: IpcMessagePort;132readonly webFrame: WebFrame;133readonly process: ISandboxNodeProcess;134readonly context: ISandboxContext;135readonly webUtils: WebUtils;136}137138/**139* A set of globals that are available in all windows that either140* depend on `preload.js` or `preload-aux.js`.141*/142export interface ISandboxGlobals {143readonly ipcRenderer: Pick<import('./electronTypes.js').IpcRenderer, 'send' | 'invoke'>;144readonly webFrame: import('./electronTypes.js').WebFrame;145}146147148