window - use IPC to transport window config and drop URL query param (#120096)

This commit is contained in:
Benjamin Pasero
2021-03-31 09:42:41 +02:00
parent 45f061b9c8
commit d35df4a3ef
21 changed files with 442 additions and 365 deletions

View File

@@ -25,19 +25,21 @@
const preloadGlobals = globals();
const webFrame = preloadGlobals.webFrame;
const safeProcess = preloadGlobals.process;
const configuration = parseWindowConfiguration();
const useCustomProtocol = safeProcess.sandboxed || typeof safeProcess.env['ENABLE_VSCODE_BROWSER_CODE_LOADING'] === 'string';
// Start to resolve process.env before anything gets load
// so that we can run loading and resolving in parallel
const whenEnvResolved = safeProcess.resolveEnv(configuration.userEnv);
const whenEnvResolved = safeProcess.resolveEnv();
/**
* @param {string[]} modulePaths
* @param {(result: unknown, configuration: object) => Promise<unknown> | undefined} resultCallback
* @param {{ forceEnableDeveloperKeybindings?: boolean, disallowReloadKeybinding?: boolean, removeDeveloperKeybindingsAfterLoad?: boolean, canModifyDOM?: (config: object) => void, beforeLoaderConfig?: (config: object, loaderConfig: object) => void, beforeRequire?: () => void }=} options
*/
function load(modulePaths, resultCallback, options) {
async function load(modulePaths, resultCallback, options) {
performance.mark('code/willWaitForWindowConfig');
const configuration = await preloadGlobals.context.configuration;
performance.mark('code/didWaitForWindowConfig');
// Apply zoom level early before even building the
// window DOM elements to avoid UI flicker. We always
@@ -180,30 +182,6 @@
}, onUnexpectedError);
}
/**
* Parses the contents of the window condiguration that
* is passed into the URL from the `electron-main` side.
*
* @returns {{
* isInitialStartup?: boolean,
* zoomLevel?: number,
* extensionDevelopmentPath?: string[],
* extensionTestsPath?: string,
* userEnv?: { [key: string]: string | undefined },
* appRoot: string,
* nodeCachedDataDir?: string
* }}
*/
function parseWindowConfiguration() {
const rawConfiguration = (window.location.search || '').split(/[?&]/)
.filter(function (param) { return !!param; })
.map(function (param) { return param.split('='); })
.filter(function (param) { return param.length === 2; })
.reduce(function (r, param) { r[param[0]] = decodeURIComponent(param[1]); return r; }, {});
return JSON.parse(rawConfiguration['config'] || '{}') || {};
}
/**
* @param {boolean | undefined} disallowReloadKeybinding
* @returns {() => void}