sandbox - ensure to validate vscode-window-config ipc call

This commit is contained in:
Benjamin Pasero 2021-03-31 14:04:18 +02:00
parent 203f1cb56b
commit 141ac31cdc
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
2 changed files with 32 additions and 21 deletions

View file

@ -43,16 +43,18 @@
* }} [options] * }} [options]
*/ */
async function load(modulePaths, resultCallback, options) { async function load(modulePaths, resultCallback, options) {
performance.mark('code/willWaitForWindowConfig');
/** @type {import('./vs/base/parts/sandbox/common/sandboxTypes').ISandboxConfiguration} */
const configuration = await preloadGlobals.context.configuration;
performance.mark('code/didWaitForWindowConfig');
// Error handler // Error handler
safeProcess.on('uncaughtException', function (/** @type {string | Error} */ error) { safeProcess.on('uncaughtException', function (/** @type {string | Error} */ error) {
onUnexpectedError(error, enableDeveloperKeybindings); onUnexpectedError(error, enableDeveloperKeybindings);
}); });
// Await window configuration from preload
performance.mark('code/willWaitForWindowConfig');
/** @type {import('./vs/base/parts/sandbox/common/sandboxTypes').ISandboxConfiguration} */
const configuration = await preloadGlobals.context.configuration;
performance.mark('code/didWaitForWindowConfig');
// Developer tools // Developer tools
const enableDeveloperKeybindings = safeProcess.env['VSCODE_DEV'] || configuration.forceEnableDeveloperKeybindings || options?.forceEnableDeveloperKeybindings; const enableDeveloperKeybindings = safeProcess.env['VSCODE_DEV'] || configuration.forceEnableDeveloperKeybindings || options?.forceEnableDeveloperKeybindings;
let developerDeveloperKeybindingsDisposable; let developerDeveloperKeybindingsDisposable;
@ -63,6 +65,7 @@
// Enable ASAR support // Enable ASAR support
globalThis.MonacoBootstrap.enableASARSupport(configuration.appRoot); globalThis.MonacoBootstrap.enableASARSupport(configuration.appRoot);
// Signal DOM modifications are now OK
if (typeof options?.canModifyDOM === 'function') { if (typeof options?.canModifyDOM === 'function') {
options.canModifyDOM(configuration); options.canModifyDOM(configuration);
} }
@ -79,24 +82,22 @@
window.document.documentElement.setAttribute('lang', locale); window.document.documentElement.setAttribute('lang', locale);
// do not advertise AMD to avoid confusing UMD modules loaded with nodejs // Do not advertise AMD to avoid confusing UMD modules loaded with nodejs
if (!useCustomProtocol) { if (!useCustomProtocol) {
window['define'] = undefined; window['define'] = undefined;
} }
// replace the patched electron fs with the original node fs for all AMD code (TODO@sandbox non-sandboxed only) // Replace the patched electron fs with the original node fs for all AMD code (TODO@sandbox non-sandboxed only)
if (!safeProcess.sandboxed) { if (!safeProcess.sandboxed) {
require.define('fs', [], function () { return require.__$__nodeRequire('original-fs'); }); require.define('fs', [], function () { return require.__$__nodeRequire('original-fs'); });
} }
window['MonacoEnvironment'] = {}; window['MonacoEnvironment'] = {};
const baseUrl = useCustomProtocol ?
`${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out` :
`${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32' })}/out`;
const loaderConfig = { const loaderConfig = {
baseUrl, baseUrl: useCustomProtocol ?
`${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out` :
`${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32' })}/out`,
'vs/nls': nlsConfig, 'vs/nls': nlsConfig,
preferScriptTags: useCustomProtocol preferScriptTags: useCustomProtocol
}; };
@ -132,7 +133,7 @@
loaderConfig.amdModulesPattern = /^vs\//; loaderConfig.amdModulesPattern = /^vs\//;
} }
// cached data config // Cached data config
if (configuration.nodeCachedDataDir) { if (configuration.nodeCachedDataDir) {
loaderConfig.nodeCachedData = { loaderConfig.nodeCachedData = {
path: configuration.nodeCachedDataDir, path: configuration.nodeCachedDataDir,
@ -140,22 +141,27 @@
}; };
} }
// Signal before require.config()
if (typeof options?.beforeLoaderConfig === 'function') { if (typeof options?.beforeLoaderConfig === 'function') {
options.beforeLoaderConfig(configuration, loaderConfig); options.beforeLoaderConfig(configuration, loaderConfig);
} }
// Configure loader
require.config(loaderConfig); require.config(loaderConfig);
// Handle pseudo NLS
if (nlsConfig.pseudo) { if (nlsConfig.pseudo) {
require(['vs/nls'], function (nlsPlugin) { require(['vs/nls'], function (nlsPlugin) {
nlsPlugin.setPseudoTranslation(nlsConfig.pseudo); nlsPlugin.setPseudoTranslation(nlsConfig.pseudo);
}); });
} }
// Signal before require()
if (typeof options?.beforeRequire === 'function') { if (typeof options?.beforeRequire === 'function') {
options.beforeRequire(); options.beforeRequire();
} }
// Actually require the main module as specified
require(modulePaths, async result => { require(modulePaths, async result => {
try { try {

View file

@ -17,6 +17,9 @@
// ### ### // ### ###
// ####################################################################### // #######################################################################
/**
* @type {import('../electron-sandbox/globals')}
*/
const globals = { const globals = {
/** /**
@ -234,17 +237,19 @@
} }
try { try {
const configuration = await ipcRenderer.invoke(windowConfigIpcChannel); if (validateIPC(windowConfigIpcChannel)) {
const configuration = await ipcRenderer.invoke(windowConfigIpcChannel);
// Apply zoom level early before even building the // Apply zoom level early before even building the
// window DOM elements to avoid UI flicker. We always // window DOM elements to avoid UI flicker. We always
// have to set the zoom level from within the window // have to set the zoom level from within the window
// because Chrome has it's own way of remembering zoom // because Chrome has it's own way of remembering zoom
// settings per origin (if vscode-file:// is used) and // settings per origin (if vscode-file:// is used) and
// we want to ensure that the user configuration wins. // we want to ensure that the user configuration wins.
webFrame.setZoomLevel(configuration.zoomLevel ?? 0); webFrame.setZoomLevel(configuration.zoomLevel ?? 0);
return configuration; return configuration;
}
} catch (error) { } catch (error) {
throw new Error(`Preload: unable to fetch vscode-window-config: ${error}`); throw new Error(`Preload: unable to fetch vscode-window-config: ${error}`);
} }