|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= <loic@coderpad.io> |
| 3 | +Date: Tue, 11 Feb 2025 16:33:43 +0100 |
| 4 | +Subject: [PATCH] feat: add a way to override extension host config |
| 5 | + |
| 6 | +--- |
| 7 | + .../services/extensions/browser/extensionService.ts | 11 +++++++++-- |
| 8 | + .../extensions/browser/webWorkerExtensionHost.ts | 5 ++++- |
| 9 | + .../electron-sandbox/nativeExtensionService.ts | 10 ++++++++-- |
| 10 | + .../worker/webWorkerExtensionHostIframe.html | 10 +++++----- |
| 11 | + 4 files changed, 26 insertions(+), 10 deletions(-) |
| 12 | + |
| 13 | +diff --git a/src/vs/workbench/services/extensions/browser/extensionService.ts b/src/vs/workbench/services/extensions/browser/extensionService.ts |
| 14 | +index cea72fd2225..c2aa0d65072 100644 |
| 15 | +--- a/src/vs/workbench/services/extensions/browser/extensionService.ts |
| 16 | ++++ b/src/vs/workbench/services/extensions/browser/extensionService.ts |
| 17 | +@@ -4,7 +4,7 @@ |
| 18 | + *--------------------------------------------------------------------------------------------*/ |
| 19 | + |
| 20 | + import { mainWindow } from '../../../../base/browser/window.js'; |
| 21 | +-import { Schemas } from '../../../../base/common/network.js'; |
| 22 | ++import { FileAccess, Schemas } from '../../../../base/common/network.js'; |
| 23 | + import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js'; |
| 24 | + import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js'; |
| 25 | + import { ExtensionKind } from '../../../../platform/environment/common/environment.js'; |
| 26 | +@@ -235,7 +235,14 @@ export class BrowserExtensionHostFactory implements IExtensionHostFactory { |
| 27 | + ? ExtensionHostStartup.EagerManualStart |
| 28 | + : ExtensionHostStartup.EagerAutoStart |
| 29 | + ); |
| 30 | +- return this._instantiationService.createInstance(WebWorkerExtensionHost, runningLocation, startup, this._createLocalExtensionHostDataProvider(runningLocations, runningLocation, isInitialStart)); |
| 31 | ++ return this._instantiationService.createInstance( |
| 32 | ++ WebWorkerExtensionHost, |
| 33 | ++ runningLocation, |
| 34 | ++ startup, |
| 35 | ++ this._createLocalExtensionHostDataProvider(runningLocations, runningLocation, isInitialStart), |
| 36 | ++ FileAccess.asBrowserUri('vs/workbench/api/worker/extensionHostWorkerMain.js').toString(true), |
| 37 | ++ { type: 'module' } |
| 38 | ++ ); |
| 39 | + } |
| 40 | + case ExtensionHostKind.Remote: { |
| 41 | + const remoteAgentConnection = this._remoteAgentService.getConnection(); |
| 42 | +diff --git a/src/vs/workbench/services/extensions/browser/webWorkerExtensionHost.ts b/src/vs/workbench/services/extensions/browser/webWorkerExtensionHost.ts |
| 43 | +index fb3c8cbfb57..eade34150d1 100644 |
| 44 | +--- a/src/vs/workbench/services/extensions/browser/webWorkerExtensionHost.ts |
| 45 | ++++ b/src/vs/workbench/services/extensions/browser/webWorkerExtensionHost.ts |
| 46 | +@@ -59,6 +59,8 @@ export class WebWorkerExtensionHost extends Disposable implements IExtensionHost |
| 47 | + public readonly runningLocation: LocalWebWorkerRunningLocation, |
| 48 | + public readonly startup: ExtensionHostStartup, |
| 49 | + private readonly _initDataProvider: IWebWorkerExtensionHostDataProvider, |
| 50 | ++ private readonly workerUrl: string, |
| 51 | ++ private readonly workerOptions: WorkerOptions | undefined, |
| 52 | + @ITelemetryService private readonly _telemetryService: ITelemetryService, |
| 53 | + @IWorkspaceContextService private readonly _contextService: IWorkspaceContextService, |
| 54 | + @ILabelService private readonly _labelService: ILabelService, |
| 55 | +@@ -184,7 +186,8 @@ export class WebWorkerExtensionHost extends Disposable implements IExtensionHost |
| 56 | + iframe.contentWindow!.postMessage({ |
| 57 | + type: event.data.type, |
| 58 | + data: { |
| 59 | +- workerUrl: FileAccess.asBrowserUri('vs/workbench/api/worker/extensionHostWorkerMain.js').toString(true), |
| 60 | ++ workerUrl: this.workerUrl, |
| 61 | ++ workerOptions: this.workerOptions, |
| 62 | + fileRoot: globalThis._VSCODE_FILE_ROOT, |
| 63 | + nls: { |
| 64 | + messages: getNLSMessages(), |
| 65 | +diff --git a/src/vs/workbench/services/extensions/electron-sandbox/nativeExtensionService.ts b/src/vs/workbench/services/extensions/electron-sandbox/nativeExtensionService.ts |
| 66 | +index d38ab6b10ae..2dd06f6eef0 100644 |
| 67 | +--- a/src/vs/workbench/services/extensions/electron-sandbox/nativeExtensionService.ts |
| 68 | ++++ b/src/vs/workbench/services/extensions/electron-sandbox/nativeExtensionService.ts |
| 69 | +@@ -6,7 +6,7 @@ |
| 70 | + import { runWhenWindowIdle } from '../../../../base/browser/dom.js'; |
| 71 | + import { mainWindow } from '../../../../base/browser/window.js'; |
| 72 | + import { CancellationToken } from '../../../../base/common/cancellation.js'; |
| 73 | +-import { Schemas } from '../../../../base/common/network.js'; |
| 74 | ++import { FileAccess, Schemas } from '../../../../base/common/network.js'; |
| 75 | + import * as performance from '../../../../base/common/performance.js'; |
| 76 | + import { isCI } from '../../../../base/common/platform.js'; |
| 77 | + import { URI } from '../../../../base/common/uri.js'; |
| 78 | +@@ -552,7 +552,13 @@ class NativeExtensionHostFactory implements IExtensionHostFactory { |
| 79 | + ? (this._webWorkerExtHostEnablement === LocalWebWorkerExtHostEnablement.Lazy ? ExtensionHostStartup.Lazy : ExtensionHostStartup.EagerManualStart) |
| 80 | + : ExtensionHostStartup.EagerAutoStart |
| 81 | + ); |
| 82 | +- return this._instantiationService.createInstance(WebWorkerExtensionHost, runningLocation, startup, this._createWebWorkerExtensionHostDataProvider(runningLocations, runningLocation)); |
| 83 | ++ return this._instantiationService.createInstance( |
| 84 | ++ WebWorkerExtensionHost, |
| 85 | ++ runningLocation, |
| 86 | ++ startup, |
| 87 | ++ this._createWebWorkerExtensionHostDataProvider(runningLocations, runningLocation), |
| 88 | ++ FileAccess.asBrowserUri('vs/workbench/api/worker/extensionHostWorkerMain.js').toString(true), |
| 89 | ++ { type: 'module' }); |
| 90 | + } |
| 91 | + return null; |
| 92 | + } |
| 93 | +diff --git a/src/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html b/src/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html |
| 94 | +index eff43dcde6c..59a3292e302 100644 |
| 95 | +--- a/src/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html |
| 96 | ++++ b/src/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html |
| 97 | +@@ -4,7 +4,7 @@ |
| 98 | + <meta http-equiv="Content-Security-Policy" content=" |
| 99 | + default-src 'none'; |
| 100 | + child-src 'self' data: blob:; |
| 101 | +- script-src 'self' 'unsafe-eval' 'sha256-xM2KVDKIoeb8vVxk4ezEUsxdTZh5wFnKO3YmFhy9tkk=' data: extension-file: https: http://localhost:* blob:; |
| 102 | ++ script-src 'self' 'unsafe-eval' 'sha256-O8NK++6jfjVooqQN8mkcEKUM19Yc4nx5RZXws6U2sao=' data: extension-file: https: http://localhost:* blob:; |
| 103 | + connect-src 'self' data: extension-file: https: wss: http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:*;"/> |
| 104 | + </head> |
| 105 | + <body> |
| 106 | +@@ -78,7 +78,7 @@ |
| 107 | + return; |
| 108 | + } |
| 109 | + const { data } = event.data; |
| 110 | +- createWorker(data.workerUrl, data.fileRoot, data.nls.messages, data.nls.language); |
| 111 | ++ createWorker(data.workerUrl, data.workerOptions, data.fileRoot, data.nls.messages, data.nls.language); |
| 112 | + }; |
| 113 | + |
| 114 | + window.parent.postMessage({ |
| 115 | +@@ -87,7 +87,7 @@ |
| 116 | + }, '*'); |
| 117 | + } |
| 118 | + |
| 119 | +- function createWorker(workerUrl, fileRoot, nlsMessages, nlsLanguage) { |
| 120 | ++ function createWorker(workerUrl, workerOptions, fileRoot, nlsMessages, nlsLanguage) { |
| 121 | + try { |
| 122 | + if (globalThis.crossOriginIsolated) { |
| 123 | + workerUrl += '?vscode-coi=2'; // COEP |
| 124 | +@@ -102,11 +102,11 @@ |
| 125 | + `globalThis._VSCODE_NLS_MESSAGES = ${JSON.stringify(nlsMessages)};`, |
| 126 | + `globalThis._VSCODE_NLS_LANGUAGE = ${JSON.stringify(nlsLanguage)};`, |
| 127 | + `globalThis._VSCODE_FILE_ROOT = ${JSON.stringify(fileRoot)};`, |
| 128 | +- `await import(${JSON.stringify(workerUrl)});`, |
| 129 | ++ (workerOptions.type === 'module') ? `await import('${workerUrl}');` : `importScripts('${workerUrl}');`, |
| 130 | + `/*extensionHostWorker*/` |
| 131 | + ].join('')], { type: 'application/javascript' }); |
| 132 | + |
| 133 | +- const worker = new Worker(URL.createObjectURL(blob), { name, type: 'module' }); |
| 134 | ++ const worker = new Worker(URL.createObjectURL(blob), { name, ...workerOptions }); |
| 135 | + const nestedWorkers = new Map(); |
| 136 | + |
| 137 | + worker.onmessage = (event) => { |
0 commit comments