@codingame/monaco-vscode-views-service-override 4.4.1 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,457 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License. See License.txt in the project root for license information.
4
- *--------------------------------------------------------------------------------------------*/
5
- // @ts-check
6
-
7
- /// <reference no-default-lib="true"/>
8
- /// <reference lib="webworker" />
9
-
10
- const sw = /** @type {ServiceWorkerGlobalScope} */ (/** @type {any} */ (self));
11
-
12
- const VERSION = 4;
13
-
14
- const resourceCacheName = `vscode-resource-cache-${VERSION}`;
15
-
16
- const rootPath = sw.location.pathname.replace(/\/service-worker.js$/, '');
17
-
18
- const searchParams = new URL(location.toString()).searchParams;
19
-
20
- const remoteAuthority = searchParams.get('remoteAuthority');
21
-
22
- /**
23
- * Origin used for resources
24
- */
25
- const resourceBaseAuthority = searchParams.get('vscode-resource-base-authority');
26
-
27
- const resolveTimeout = 30_000;
28
-
29
- /**
30
- * @template T
31
- * @typedef {{ status: 'ok'; value: T } | { status: 'timeout' }} RequestStoreResult
32
- */
33
-
34
- /**
35
- * @template T
36
- * @typedef {{
37
- * resolve: (x: RequestStoreResult<T>) => void,
38
- * promise: Promise<RequestStoreResult<T>>
39
- * }} RequestStoreEntry
40
- */
41
-
42
- /**
43
- * Caches
44
- * @template T
45
- */
46
- class RequestStore {
47
- constructor() {
48
- /** @type {Map<number, RequestStoreEntry<T>>} */
49
- this.map = new Map();
50
-
51
- this.requestPool = 0;
52
- }
53
-
54
- /**
55
- * @returns {{ requestId: number, promise: Promise<RequestStoreResult<T>> }}
56
- */
57
- create() {
58
- const requestId = ++this.requestPool;
59
-
60
- /** @type {undefined | ((x: RequestStoreResult<T>) => void)} */
61
- let resolve;
62
-
63
- /** @type {Promise<RequestStoreResult<T>>} */
64
- const promise = new Promise(r => resolve = r);
65
-
66
- /** @type {RequestStoreEntry<T>} */
67
- const entry = { resolve: /** @type {(x: RequestStoreResult<T>) => void} */ (resolve), promise };
68
-
69
- this.map.set(requestId, entry);
70
-
71
- const dispose = () => {
72
- clearTimeout(timeout);
73
- const existingEntry = this.map.get(requestId);
74
- if (existingEntry === entry) {
75
- existingEntry.resolve({ status: 'timeout' });
76
- this.map.delete(requestId);
77
- return;
78
- }
79
- };
80
- const timeout = setTimeout(dispose, resolveTimeout);
81
- return { requestId, promise };
82
- }
83
-
84
- /**
85
- * @param {number} requestId
86
- * @param {T} result
87
- * @return {boolean}
88
- */
89
- resolve(requestId, result) {
90
- const entry = this.map.get(requestId);
91
- if (!entry) {
92
- return false;
93
- }
94
- entry.resolve({ status: 'ok', value: result });
95
- this.map.delete(requestId);
96
- return true;
97
- }
98
- }
99
-
100
- /**
101
- * @typedef {{ readonly status: 200; id: number; path: string; mime: string; data: Uint8Array; etag: string | undefined; mtime: number | undefined; }
102
- * | { readonly status: 304; id: number; path: string; mime: string; mtime: number | undefined }
103
- * | { readonly status: 401; id: number; path: string }
104
- * | { readonly status: 404; id: number; path: string }} ResourceResponse
105
- */
106
-
107
- /**
108
- * Map of requested paths to responses.
109
- *
110
- * @type {RequestStore<ResourceResponse>}
111
- */
112
- const resourceRequestStore = new RequestStore();
113
-
114
- /**
115
- * Map of requested localhost origins to optional redirects.
116
- *
117
- * @type {RequestStore<string | undefined>}
118
- */
119
- const localhostRequestStore = new RequestStore();
120
-
121
- const unauthorized = () =>
122
- new Response('Unauthorized', { status: 401, });
123
-
124
- const notFound = () =>
125
- new Response('Not Found', { status: 404, });
126
-
127
- const methodNotAllowed = () =>
128
- new Response('Method Not Allowed', { status: 405, });
129
-
130
- const requestTimeout = () =>
131
- new Response('Request Timeout', { status: 408, });
132
-
133
- sw.addEventListener('message', async (event) => {
134
- switch (event.data.channel) {
135
- case 'version': {
136
- const source = /** @type {Client} */ (event.source);
137
- sw.clients.get(source.id).then(client => {
138
- if (client) {
139
- client.postMessage({
140
- channel: 'version',
141
- version: VERSION
142
- });
143
- }
144
- });
145
- return;
146
- }
147
- case 'did-load-resource': {
148
- /** @type {ResourceResponse} */
149
- const response = event.data.data;
150
- if (!resourceRequestStore.resolve(response.id, response)) {
151
- console.log('Could not resolve unknown resource', response.path);
152
- }
153
- return;
154
- }
155
- case 'did-load-localhost': {
156
- const data = event.data.data;
157
- if (!localhostRequestStore.resolve(data.id, data.location)) {
158
- console.log('Could not resolve unknown localhost', data.origin);
159
- }
160
- return;
161
- }
162
- default: {
163
- console.log('Unknown message');
164
- return;
165
- }
166
- }
167
- });
168
-
169
- sw.addEventListener('fetch', (event) => {
170
- const requestUrl = new URL(event.request.url);
171
- if (requestUrl.protocol === 'https:' && requestUrl.hostname.endsWith('.' + resourceBaseAuthority)) {
172
- switch (event.request.method) {
173
- case 'GET':
174
- case 'HEAD': {
175
- const firstHostSegment = requestUrl.hostname.slice(0, requestUrl.hostname.length - (resourceBaseAuthority.length + 1));
176
- const scheme = firstHostSegment.split('+', 1)[0];
177
- const authority = firstHostSegment.slice(scheme.length + 1); // may be empty
178
- return event.respondWith(processResourceRequest(event, {
179
- scheme,
180
- authority,
181
- path: requestUrl.pathname,
182
- query: requestUrl.search.replace(/^\?/, ''),
183
- }));
184
- }
185
- default: {
186
- return event.respondWith(methodNotAllowed());
187
- }
188
- }
189
- }
190
-
191
- // If we're making a request against the remote authority, we want to go
192
- // through VS Code itself so that we are authenticated properly. If the
193
- // service worker is hosted on the same origin we will have cookies and
194
- // authentication will not be an issue.
195
- if (requestUrl.origin !== sw.origin && requestUrl.host === remoteAuthority) {
196
- switch (event.request.method) {
197
- case 'GET':
198
- case 'HEAD': {
199
- return event.respondWith(processResourceRequest(event, {
200
- path: requestUrl.pathname,
201
- scheme: requestUrl.protocol.slice(0, requestUrl.protocol.length - 1),
202
- authority: requestUrl.host,
203
- query: requestUrl.search.replace(/^\?/, ''),
204
- }));
205
- }
206
- default: {
207
- return event.respondWith(methodNotAllowed());
208
- }
209
- }
210
- }
211
-
212
- // See if it's a localhost request
213
- if (requestUrl.origin !== sw.origin && requestUrl.host.match(/^(localhost|127.0.0.1|0.0.0.0):(\d+)$/)) {
214
- return event.respondWith(processLocalhostRequest(event, requestUrl));
215
- }
216
- });
217
-
218
- sw.addEventListener('install', (event) => {
219
- event.waitUntil(sw.skipWaiting()); // Activate worker immediately
220
- });
221
-
222
- sw.addEventListener('activate', (event) => {
223
- event.waitUntil(sw.clients.claim()); // Become available to all pages
224
- });
225
-
226
- /**
227
- * @param {FetchEvent} event
228
- * @param {{
229
- * scheme: string;
230
- * authority: string;
231
- * path: string;
232
- * query: string;
233
- * }} requestUrlComponents
234
- */
235
- async function processResourceRequest(event, requestUrlComponents) {
236
- const client = await sw.clients.get(event.clientId);
237
- if (!client) {
238
- console.error('Could not find inner client for request');
239
- return notFound();
240
- }
241
-
242
- const webviewId = getWebviewIdForClient(client);
243
- if (!webviewId) {
244
- console.error('Could not resolve webview id');
245
- return notFound();
246
- }
247
-
248
- const shouldTryCaching = (event.request.method === 'GET');
249
-
250
- /**
251
- * @param {RequestStoreResult<ResourceResponse>} result
252
- * @param {Response | undefined} cachedResponse
253
- */
254
- const resolveResourceEntry = (result, cachedResponse) => {
255
- if (result.status === 'timeout') {
256
- return requestTimeout();
257
- }
258
-
259
- const entry = result.value;
260
- if (entry.status === 304) { // Not modified
261
- if (cachedResponse) {
262
- return cachedResponse.clone();
263
- } else {
264
- throw new Error('No cache found');
265
- }
266
- }
267
-
268
- if (entry.status === 401) {
269
- return unauthorized();
270
- }
271
-
272
- if (entry.status !== 200) {
273
- return notFound();
274
- }
275
-
276
- /** @type {Record<string, string>} */
277
- const commonHeaders = {
278
- 'Access-Control-Allow-Origin': '*',
279
- };
280
-
281
- const byteLength = entry.data.byteLength;
282
-
283
- const range = event.request.headers.get('range');
284
- if (range) {
285
- // To support seeking for videos, we need to handle range requests
286
- const bytes = range.match(/^bytes\=(\d+)\-(\d+)?$/g);
287
- if (bytes) {
288
- // TODO: Right now we are always reading the full file content. This is a bad idea
289
- // for large video files :)
290
-
291
- const start = Number(bytes[1]);
292
- const end = Number(bytes[2]) || byteLength - 1;
293
- return new Response(entry.data.slice(start, end + 1), {
294
- status: 206,
295
- headers: {
296
- ...commonHeaders,
297
- 'Content-range': `bytes 0-${end}/${byteLength}`,
298
- }
299
- });
300
- } else {
301
- // We don't understand the requested bytes
302
- return new Response(null, {
303
- status: 416,
304
- headers: {
305
- ...commonHeaders,
306
- 'Content-range': `*/${byteLength}`
307
- }
308
- });
309
- }
310
- }
311
-
312
- /** @type {Record<string, string>} */
313
- const headers = {
314
- ...commonHeaders,
315
- 'Content-Type': entry.mime,
316
- 'Content-Length': byteLength.toString(),
317
- };
318
-
319
- if (entry.etag) {
320
- headers['ETag'] = entry.etag;
321
- headers['Cache-Control'] = 'no-cache';
322
- }
323
- if (entry.mtime) {
324
- headers['Last-Modified'] = new Date(entry.mtime).toUTCString();
325
- }
326
-
327
- // support COI requests, see network.ts#COI.getHeadersFromQuery(...)
328
- const coiRequest = new URL(event.request.url).searchParams.get('vscode-coi');
329
- if (coiRequest === '3') {
330
- headers['Cross-Origin-Opener-Policy'] = 'same-origin';
331
- headers['Cross-Origin-Embedder-Policy'] = 'require-corp';
332
- } else if (coiRequest === '2') {
333
- headers['Cross-Origin-Embedder-Policy'] = 'require-corp';
334
- } else if (coiRequest === '1') {
335
- headers['Cross-Origin-Opener-Policy'] = 'same-origin';
336
- }
337
-
338
- const response = new Response(entry.data, {
339
- status: 200,
340
- headers
341
- });
342
-
343
- if (shouldTryCaching && entry.etag) {
344
- caches.open(resourceCacheName).then(cache => {
345
- return cache.put(event.request, response);
346
- });
347
- }
348
- return response.clone();
349
- };
350
-
351
- const parentClients = await getOuterIframeClient(webviewId);
352
- if (!parentClients.length) {
353
- console.log('Could not find parent client for request');
354
- return notFound();
355
- }
356
-
357
- /** @type {Response | undefined} */
358
- let cached;
359
- if (shouldTryCaching) {
360
- const cache = await caches.open(resourceCacheName);
361
- cached = await cache.match(event.request);
362
- }
363
-
364
- const { requestId, promise } = resourceRequestStore.create();
365
-
366
- for (const parentClient of parentClients) {
367
- parentClient.postMessage({
368
- channel: 'load-resource',
369
- id: requestId,
370
- scheme: requestUrlComponents.scheme,
371
- authority: requestUrlComponents.authority,
372
- path: requestUrlComponents.path,
373
- query: requestUrlComponents.query,
374
- ifNoneMatch: cached?.headers.get('ETag'),
375
- });
376
- }
377
-
378
- return promise.then(entry => resolveResourceEntry(entry, cached));
379
- }
380
-
381
- /**
382
- * @param {FetchEvent} event
383
- * @param {URL} requestUrl
384
- * @return {Promise<Response>}
385
- */
386
- async function processLocalhostRequest(event, requestUrl) {
387
- const client = await sw.clients.get(event.clientId);
388
- if (!client) {
389
- // This is expected when requesting resources on other localhost ports
390
- // that are not spawned by vs code
391
- return fetch(event.request);
392
- }
393
- const webviewId = getWebviewIdForClient(client);
394
- if (!webviewId) {
395
- console.error('Could not resolve webview id');
396
- return fetch(event.request);
397
- }
398
-
399
- const origin = requestUrl.origin;
400
-
401
- /**
402
- * @param {RequestStoreResult<string | undefined>} result
403
- * @return {Promise<Response>}
404
- */
405
- const resolveRedirect = async (result) => {
406
- if (result.status !== 'ok' || !result.value) {
407
- return fetch(event.request);
408
- }
409
-
410
- const redirectOrigin = result.value;
411
- const location = event.request.url.replace(new RegExp(`^${requestUrl.origin}(/|$)`), `${redirectOrigin}$1`);
412
- return new Response(null, {
413
- status: 302,
414
- headers: {
415
- Location: location
416
- }
417
- });
418
- };
419
-
420
- const parentClients = await getOuterIframeClient(webviewId);
421
- if (!parentClients.length) {
422
- console.log('Could not find parent client for request');
423
- return notFound();
424
- }
425
-
426
- const { requestId, promise } = localhostRequestStore.create();
427
- for (const parentClient of parentClients) {
428
- parentClient.postMessage({
429
- channel: 'load-localhost',
430
- origin: origin,
431
- id: requestId,
432
- });
433
- }
434
-
435
- return promise.then(resolveRedirect);
436
- }
437
-
438
- /**
439
- * @param {Client} client
440
- * @returns {string | null}
441
- */
442
- function getWebviewIdForClient(client) {
443
- const requesterClientUrl = new URL(client.url);
444
- return requesterClientUrl.searchParams.get('id');
445
- }
446
-
447
- /**
448
- * @param {string} webviewId
449
- * @returns {Promise<Client[]>}
450
- */
451
- async function getOuterIframeClient(webviewId) {
452
- const allClients = await sw.clients.matchAll({ includeUncontrolled: true });
453
- return allClients.filter(client => {
454
- const clientUrl = new URL(client.url);
455
- return clientUrl.searchParams.get('id') === webviewId;
456
- });
457
- }
@@ -1,10 +0,0 @@
1
- export { AbstractDialogHandler, IDialogService, IFileDialogService, getFileNamesMessage } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
2
-
3
- var ConfirmResult;
4
- ( (function(ConfirmResult) {
5
- ConfirmResult[ConfirmResult["SAVE"] = 0] = "SAVE";
6
- ConfirmResult[ConfirmResult["DONT_SAVE"] = 1] = "DONT_SAVE";
7
- ConfirmResult[ConfirmResult["CANCEL"] = 2] = "CANCEL";
8
- })(ConfirmResult || (ConfirmResult = {})));
9
-
10
- export { ConfirmResult };
@@ -1,4 +0,0 @@
1
- import pngAssets from 'vscode/vscode/vs/workbench/contrib/debug/browser/media/all.png';
2
- import { registerAssets } from 'vscode/assets';
3
-
4
- registerAssets(pngAssets);
package/tools/url.js DELETED
@@ -1,10 +0,0 @@
1
- function changeUrlDomain(url, domain) {
2
- if (domain == null) {
3
- return url;
4
- }
5
- const _url = new URL(url, domain);
6
- _url.host = new URL(domain).hostname;
7
- return ( _url.toString());
8
- }
9
-
10
- export { changeUrlDomain };