| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-2EBQn+AFduI8Wb0riLwbeshEGP4dJlHornyvuFAgYnA=' blob: 'unsafe-eval' 'wasm-unsafe-eval'; worker-src blob:; child-src blob:; connect-src blob: data:; img-src blob: data:; font-src blob: data:; media-src 'none'; object-src 'none'; manifest-src 'none'; base-uri 'none'; form-action 'none'"/> |
| 5 | </head> |
| 6 | <body> |
| 7 | <script> |
| 8 | (function () { |
| 9 | const searchParams = new URL(document.location.href).searchParams; |
| 10 | const vscodeWebWorkerExtHostId = searchParams.get('vscodeWebWorkerExtHostId') || ''; |
| 11 | const name = searchParams.get('debugged') ? 'DebugExtensionHostWorker' : 'ExtensionHostWorker'; |
| 12 | const parentOriginParam = searchParams.get('parentOrigin'); |
| 13 | const parentOrigin = parentOriginParam || window.origin; |
| 14 | const salt = searchParams.get('salt'); |
| 15 | |
| 16 | (async function () { |
| 17 | return start(); |
| 18 | })(); |
| 19 | |
| 20 | function sendError(error) { |
| 21 | window.parent.postMessage({ |
| 22 | vscodeWebWorkerExtHostId, |
| 23 | error: { |
| 24 | name: error ? error.name : '', |
| 25 | message: error ? error.message : '', |
| 26 | stack: error ? error.stack : [] |
| 27 | } |
| 28 | }, '*'); |
| 29 | } |
| 30 | |
| 31 | function start() { |
| 32 | |
| 33 | // Before we can load the worker, we need to get the current set of NLS |
| 34 | // configuration into this iframe. We ask the parent window to send it |
| 35 | // together with the necessary information to load the worker via Blob. |
| 36 | |
| 37 | const bootstrapNlsType = 'vscode.bootstrap.nls'; |
| 38 | |
| 39 | self.onmessage = (event) => { |
| 40 | if (event.origin !== parentOrigin || event.data.type !== bootstrapNlsType) { |
| 41 | return; |
| 42 | } |
| 43 | const { data } = event.data; |
| 44 | createWorker(data.workerUrl, data.workerOptions, data.fileRoot, data.nls.messages, data.nls.language); |
| 45 | }; |
| 46 | |
| 47 | window.parent.postMessage({ |
| 48 | vscodeWebWorkerExtHostId, |
| 49 | type: bootstrapNlsType |
| 50 | }, '*'); |
| 51 | } |
| 52 | |
| 53 | function createWorker(workerUrl, workerOptions, fileRoot, nlsMessages, nlsLanguage) { |
| 54 | try { |
| 55 | if (globalThis.crossOriginIsolated) { |
| 56 | workerUrl += '?vscode-coi=2'; // COEP |
| 57 | } |
| 58 | |
| 59 | // In below blob code, we are using JSON.stringify to ensure the passed |
| 60 | // in values are not breaking our script. The values may contain string |
| 61 | // terminating characters (such as ' or "). |
| 62 | |
| 63 | const blob = new Blob([[ |
| 64 | `/*extensionHostWorker*/`, |
| 65 | `globalThis._VSCODE_NLS_MESSAGES = ${JSON.stringify(nlsMessages)};`, |
| 66 | `globalThis._VSCODE_NLS_LANGUAGE = ${JSON.stringify(nlsLanguage)};`, |
| 67 | `globalThis._VSCODE_FILE_ROOT = ${JSON.stringify(fileRoot)};`, |
| 68 | (workerOptions?.type === 'module') ? `await import('${workerUrl}');` : `importScripts('${workerUrl}');`, |
| 69 | `/*extensionHostWorker*/` |
| 70 | ].join('')], { type: 'application/javascript' }); |
| 71 | |
| 72 | const worker = new Worker(URL.createObjectURL(blob), { name, ...workerOptions }); |
| 73 | const nestedWorkers = new Map(); |
| 74 | |
| 75 | worker.onmessage = (event) => { |
| 76 | const { data } = event; |
| 77 | |
| 78 | if (data?.type === '_newWorker') { |
| 79 | const { id, port, url, options } = data; |
| 80 | const newWorker = new Worker(url, options); |
| 81 | newWorker.postMessage(port, [port]); |
| 82 | newWorker.onerror = console.error.bind(console); |
| 83 | nestedWorkers.set(id, newWorker); |
| 84 | |
| 85 | } else if (data?.type === '_terminateWorker') { |
| 86 | const { id } = data; |
| 87 | if (nestedWorkers.has(id)) { |
| 88 | nestedWorkers.get(id).terminate(); |
| 89 | nestedWorkers.delete(id); |
| 90 | } |
| 91 | } else { |
| 92 | worker.onerror = console.error.bind(console); |
| 93 | window.parent.postMessage({ |
| 94 | vscodeWebWorkerExtHostId, |
| 95 | data |
| 96 | }, parentOrigin, [data]); |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | worker.onerror = (event) => { |
| 101 | console.error(event.message, event.error); |
| 102 | sendError(event.error); |
| 103 | }; |
| 104 | |
| 105 | self.onmessage = (event) => { |
| 106 | if (event.origin !== parentOrigin) { |
| 107 | return; |
| 108 | } |
| 109 | worker.postMessage(event.data, event.ports); |
| 110 | }; |
| 111 | } catch (err) { |
| 112 | console.error(err); |
| 113 | sendError(err); |
| 114 | } |
| 115 | } |
| 116 | })(); |
| 117 | </script> |
| 118 | </body> |
| 119 | </html> |