@lvce-editor/iframe-worker 5.11.0 → 5.13.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.
- package/dist/iframeWorkerMain.js +361 -106
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -54,27 +54,6 @@ class VError extends Error {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
const walkValue = (value, transferrables, isTransferrable) => {
|
|
58
|
-
if (!value) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (isTransferrable(value)) {
|
|
62
|
-
transferrables.push(value);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (Array.isArray(value)) {
|
|
66
|
-
for (const item of value) {
|
|
67
|
-
walkValue(item, transferrables, isTransferrable);
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (typeof value === 'object') {
|
|
72
|
-
for (const property of Object.values(value)) {
|
|
73
|
-
walkValue(property, transferrables, isTransferrable);
|
|
74
|
-
}
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
57
|
const isMessagePort = value => {
|
|
79
58
|
return value && value instanceof MessagePort;
|
|
80
59
|
};
|
|
@@ -99,6 +78,27 @@ const isTransferrable = value => {
|
|
|
99
78
|
}
|
|
100
79
|
return false;
|
|
101
80
|
};
|
|
81
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
82
|
+
if (!value) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (isTransferrable(value)) {
|
|
86
|
+
transferrables.push(value);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
for (const item of value) {
|
|
91
|
+
walkValue(item, transferrables, isTransferrable);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (typeof value === 'object') {
|
|
96
|
+
for (const property of Object.values(value)) {
|
|
97
|
+
walkValue(property, transferrables, isTransferrable);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
102
|
const getTransferrables = value => {
|
|
103
103
|
const transferrables = [];
|
|
104
104
|
walkValue(value, transferrables, isTransferrable);
|
|
@@ -131,30 +131,35 @@ const NewLine$1 = '\n';
|
|
|
131
131
|
const joinLines$1 = lines => {
|
|
132
132
|
return lines.join(NewLine$1);
|
|
133
133
|
};
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
134
|
+
const RE_AT = /^\s+at/;
|
|
135
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
136
|
+
const isNormalStackLine = line => {
|
|
137
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
139
138
|
};
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
const getDetails = lines => {
|
|
140
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
141
|
+
if (index === -1) {
|
|
142
|
+
return {
|
|
143
|
+
actualMessage: joinLines$1(lines),
|
|
144
|
+
rest: []
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
let lastIndex = index - 1;
|
|
148
|
+
while (++lastIndex < lines.length) {
|
|
149
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
144
153
|
return {
|
|
145
|
-
|
|
146
|
-
|
|
154
|
+
actualMessage: lines[index - 1],
|
|
155
|
+
rest: lines.slice(index, lastIndex)
|
|
147
156
|
};
|
|
148
157
|
};
|
|
149
|
-
const
|
|
150
|
-
|
|
158
|
+
const splitLines$1 = lines => {
|
|
159
|
+
return lines.split(NewLine$1);
|
|
160
|
+
};
|
|
151
161
|
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
152
162
|
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
153
|
-
const RE_AT = /^\s+at/;
|
|
154
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
155
|
-
const isUnhelpfulNativeModuleError = stderr => {
|
|
156
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
157
|
-
};
|
|
158
163
|
const isMessageCodeBlockStartIndex = line => {
|
|
159
164
|
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
160
165
|
};
|
|
@@ -169,51 +174,46 @@ const getMessageCodeBlock = stderr => {
|
|
|
169
174
|
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
170
175
|
return relevantMessage;
|
|
171
176
|
};
|
|
172
|
-
const
|
|
173
|
-
|
|
177
|
+
const isModuleNotFoundMessage = line => {
|
|
178
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
179
|
+
};
|
|
180
|
+
const getModuleNotFoundError = stderr => {
|
|
181
|
+
const lines = splitLines$1(stderr);
|
|
182
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
183
|
+
const message = lines[messageIndex];
|
|
174
184
|
return {
|
|
175
|
-
message
|
|
176
|
-
code:
|
|
185
|
+
message,
|
|
186
|
+
code: ERR_MODULE_NOT_FOUND
|
|
177
187
|
};
|
|
178
188
|
};
|
|
179
|
-
const
|
|
189
|
+
const isModuleNotFoundError = stderr => {
|
|
180
190
|
if (!stderr) {
|
|
181
191
|
return false;
|
|
182
192
|
}
|
|
183
|
-
return stderr.includes('
|
|
184
|
-
};
|
|
185
|
-
const getModuleSyntaxError = () => {
|
|
186
|
-
return {
|
|
187
|
-
message: `ES Modules are not supported in electron`,
|
|
188
|
-
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
189
|
-
};
|
|
193
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
190
194
|
};
|
|
191
|
-
const
|
|
195
|
+
const isModulesSyntaxError = stderr => {
|
|
192
196
|
if (!stderr) {
|
|
193
197
|
return false;
|
|
194
198
|
}
|
|
195
|
-
return stderr.includes('
|
|
199
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
196
200
|
};
|
|
197
|
-
const
|
|
198
|
-
|
|
201
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
202
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
203
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
204
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
199
205
|
};
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
if (index === -1) {
|
|
203
|
-
return {
|
|
204
|
-
actualMessage: joinLines$1(lines),
|
|
205
|
-
rest: []
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
let lastIndex = index - 1;
|
|
209
|
-
while (++lastIndex < lines.length) {
|
|
210
|
-
if (!isNormalStackLine(lines[lastIndex])) {
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
206
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
207
|
+
const message = getMessageCodeBlock(stderr);
|
|
214
208
|
return {
|
|
215
|
-
|
|
216
|
-
|
|
209
|
+
message: `Incompatible native node module: ${message}`,
|
|
210
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
const getModuleSyntaxError = () => {
|
|
214
|
+
return {
|
|
215
|
+
message: `ES Modules are not supported in electron`,
|
|
216
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
217
217
|
};
|
|
218
218
|
};
|
|
219
219
|
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
@@ -232,7 +232,7 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
232
232
|
rest
|
|
233
233
|
} = getDetails(lines);
|
|
234
234
|
return {
|
|
235
|
-
message:
|
|
235
|
+
message: actualMessage,
|
|
236
236
|
code: '',
|
|
237
237
|
stack: rest
|
|
238
238
|
};
|
|
@@ -274,7 +274,7 @@ const listen$7 = () => {
|
|
|
274
274
|
}
|
|
275
275
|
return globalThis;
|
|
276
276
|
};
|
|
277
|
-
const signal$
|
|
277
|
+
const signal$8 = global => {
|
|
278
278
|
global.postMessage(readyMessage);
|
|
279
279
|
};
|
|
280
280
|
class IpcChildWithModuleWorker extends Ipc {
|
|
@@ -300,7 +300,7 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
300
300
|
this._rawIpc.addEventListener('message', callback);
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
-
const wrap$
|
|
303
|
+
const wrap$f = global => {
|
|
304
304
|
return new IpcChildWithModuleWorker(global);
|
|
305
305
|
};
|
|
306
306
|
const withResolvers = () => {
|
|
@@ -309,6 +309,7 @@ const withResolvers = () => {
|
|
|
309
309
|
_resolve = resolve;
|
|
310
310
|
});
|
|
311
311
|
return {
|
|
312
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
312
313
|
resolve: _resolve,
|
|
313
314
|
promise
|
|
314
315
|
};
|
|
@@ -327,8 +328,8 @@ const waitForFirstMessage = async port => {
|
|
|
327
328
|
};
|
|
328
329
|
const listen$6 = async () => {
|
|
329
330
|
const parentIpcRaw = listen$7();
|
|
330
|
-
signal$
|
|
331
|
-
const parentIpc = wrap$
|
|
331
|
+
signal$8(parentIpcRaw);
|
|
332
|
+
const parentIpc = wrap$f(parentIpcRaw);
|
|
332
333
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
333
334
|
if (firstMessage.method !== 'initialize') {
|
|
334
335
|
throw new IpcError('unexpected first message');
|
|
@@ -347,9 +348,6 @@ const listen$6 = async () => {
|
|
|
347
348
|
return globalThis;
|
|
348
349
|
};
|
|
349
350
|
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
350
|
-
constructor(port) {
|
|
351
|
-
super(port);
|
|
352
|
-
}
|
|
353
351
|
getData(event) {
|
|
354
352
|
return getData$2(event);
|
|
355
353
|
}
|
|
@@ -373,13 +371,107 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
373
371
|
this._rawIpc.start();
|
|
374
372
|
}
|
|
375
373
|
}
|
|
376
|
-
const wrap$
|
|
374
|
+
const wrap$e = port => {
|
|
377
375
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
378
376
|
};
|
|
379
377
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
380
378
|
__proto__: null,
|
|
381
379
|
listen: listen$6,
|
|
382
|
-
wrap: wrap$
|
|
380
|
+
wrap: wrap$e
|
|
381
|
+
};
|
|
382
|
+
const addListener = (emitter, type, callback) => {
|
|
383
|
+
if ('addEventListener' in emitter) {
|
|
384
|
+
emitter.addEventListener(type, callback);
|
|
385
|
+
} else {
|
|
386
|
+
emitter.on(type, callback);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const removeListener = (emitter, type, callback) => {
|
|
390
|
+
if ('removeEventListener' in emitter) {
|
|
391
|
+
emitter.removeEventListener(type, callback);
|
|
392
|
+
} else {
|
|
393
|
+
emitter.off(type, callback);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
397
|
+
const {
|
|
398
|
+
resolve,
|
|
399
|
+
promise
|
|
400
|
+
} = withResolvers();
|
|
401
|
+
const listenerMap = Object.create(null);
|
|
402
|
+
const cleanup = value => {
|
|
403
|
+
for (const event of Object.keys(eventMap)) {
|
|
404
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
405
|
+
}
|
|
406
|
+
resolve(value);
|
|
407
|
+
};
|
|
408
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
409
|
+
const listener = event => {
|
|
410
|
+
cleanup({
|
|
411
|
+
type,
|
|
412
|
+
event
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
addListener(eventEmitter, event, listener);
|
|
416
|
+
listenerMap[event] = listener;
|
|
417
|
+
}
|
|
418
|
+
return promise;
|
|
419
|
+
};
|
|
420
|
+
const Message$1 = 3;
|
|
421
|
+
const create$5$1 = async ({
|
|
422
|
+
messagePort,
|
|
423
|
+
isMessagePortOpen
|
|
424
|
+
}) => {
|
|
425
|
+
if (!isMessagePort(messagePort)) {
|
|
426
|
+
throw new IpcError('port must be of type MessagePort');
|
|
427
|
+
}
|
|
428
|
+
if (isMessagePortOpen) {
|
|
429
|
+
return messagePort;
|
|
430
|
+
}
|
|
431
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
432
|
+
message: Message$1
|
|
433
|
+
});
|
|
434
|
+
messagePort.start();
|
|
435
|
+
const {
|
|
436
|
+
type,
|
|
437
|
+
event
|
|
438
|
+
} = await eventPromise;
|
|
439
|
+
if (type !== Message$1) {
|
|
440
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
441
|
+
}
|
|
442
|
+
if (event.data !== readyMessage) {
|
|
443
|
+
throw new IpcError('unexpected first message');
|
|
444
|
+
}
|
|
445
|
+
return messagePort;
|
|
446
|
+
};
|
|
447
|
+
const signal$1 = messagePort => {
|
|
448
|
+
messagePort.start();
|
|
449
|
+
};
|
|
450
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
451
|
+
getData = getData$2;
|
|
452
|
+
send(message) {
|
|
453
|
+
this._rawIpc.postMessage(message);
|
|
454
|
+
}
|
|
455
|
+
sendAndTransfer(message) {
|
|
456
|
+
const transfer = getTransferrables(message);
|
|
457
|
+
this._rawIpc.postMessage(message, transfer);
|
|
458
|
+
}
|
|
459
|
+
dispose() {
|
|
460
|
+
this._rawIpc.close();
|
|
461
|
+
}
|
|
462
|
+
onMessage(callback) {
|
|
463
|
+
this._rawIpc.addEventListener('message', callback);
|
|
464
|
+
}
|
|
465
|
+
onClose(callback) {}
|
|
466
|
+
}
|
|
467
|
+
const wrap$5 = messagePort => {
|
|
468
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
469
|
+
};
|
|
470
|
+
const IpcParentWithMessagePort$1 = {
|
|
471
|
+
__proto__: null,
|
|
472
|
+
create: create$5$1,
|
|
473
|
+
signal: signal$1,
|
|
474
|
+
wrap: wrap$5
|
|
383
475
|
};
|
|
384
476
|
|
|
385
477
|
const Two = '2.0';
|
|
@@ -391,7 +483,7 @@ const create$4 = (method, params) => {
|
|
|
391
483
|
};
|
|
392
484
|
};
|
|
393
485
|
const callbacks = Object.create(null);
|
|
394
|
-
const set = (id, fn) => {
|
|
486
|
+
const set$1 = (id, fn) => {
|
|
395
487
|
callbacks[id] = fn;
|
|
396
488
|
};
|
|
397
489
|
const get = id => {
|
|
@@ -410,7 +502,7 @@ const registerPromise = () => {
|
|
|
410
502
|
resolve,
|
|
411
503
|
promise
|
|
412
504
|
} = Promise.withResolvers();
|
|
413
|
-
set(id, resolve);
|
|
505
|
+
set$1(id, resolve);
|
|
414
506
|
return {
|
|
415
507
|
id,
|
|
416
508
|
promise
|
|
@@ -619,7 +711,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
|
619
711
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
620
712
|
return create$1$1(message, errorProperty);
|
|
621
713
|
};
|
|
622
|
-
const create$
|
|
714
|
+
const create$6 = (message, result) => {
|
|
623
715
|
return {
|
|
624
716
|
jsonrpc: Two,
|
|
625
717
|
id: message.id,
|
|
@@ -628,7 +720,7 @@ const create$5 = (message, result) => {
|
|
|
628
720
|
};
|
|
629
721
|
const getSuccessResponse = (message, result) => {
|
|
630
722
|
const resultProperty = result ?? null;
|
|
631
|
-
return create$
|
|
723
|
+
return create$6(message, resultProperty);
|
|
632
724
|
};
|
|
633
725
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
634
726
|
try {
|
|
@@ -724,7 +816,7 @@ const send = (transport, method, ...params) => {
|
|
|
724
816
|
const invoke$4 = (ipc, method, ...params) => {
|
|
725
817
|
return invokeHelper(ipc, method, params, false);
|
|
726
818
|
};
|
|
727
|
-
const invokeAndTransfer$
|
|
819
|
+
const invokeAndTransfer$4 = (ipc, method, ...params) => {
|
|
728
820
|
return invokeHelper(ipc, method, params, true);
|
|
729
821
|
};
|
|
730
822
|
|
|
@@ -745,6 +837,8 @@ const execute = (command, ...args) => {
|
|
|
745
837
|
|
|
746
838
|
const createRpc = ipc => {
|
|
747
839
|
const rpc = {
|
|
840
|
+
// @ts-ignore
|
|
841
|
+
ipc,
|
|
748
842
|
/**
|
|
749
843
|
* @deprecated
|
|
750
844
|
*/
|
|
@@ -755,7 +849,7 @@ const createRpc = ipc => {
|
|
|
755
849
|
return invoke$4(ipc, method, ...params);
|
|
756
850
|
},
|
|
757
851
|
invokeAndTransfer(method, ...params) {
|
|
758
|
-
return invokeAndTransfer$
|
|
852
|
+
return invokeAndTransfer$4(ipc, method, ...params);
|
|
759
853
|
}
|
|
760
854
|
};
|
|
761
855
|
return rpc;
|
|
@@ -771,7 +865,8 @@ const logError = () => {
|
|
|
771
865
|
};
|
|
772
866
|
const handleMessage = event => {
|
|
773
867
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
774
|
-
|
|
868
|
+
const actualExecute = event?.target?.execute || execute;
|
|
869
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
775
870
|
};
|
|
776
871
|
const handleIpc = ipc => {
|
|
777
872
|
if ('addEventListener' in ipc) {
|
|
@@ -789,6 +884,26 @@ const listen$1 = async (module, options) => {
|
|
|
789
884
|
const ipc = module.wrap(rawIpc);
|
|
790
885
|
return ipc;
|
|
791
886
|
};
|
|
887
|
+
const create$5 = async ({
|
|
888
|
+
commandMap,
|
|
889
|
+
messagePort,
|
|
890
|
+
isMessagePortOpen
|
|
891
|
+
}) => {
|
|
892
|
+
// TODO create a commandMap per rpc instance
|
|
893
|
+
register$4(commandMap);
|
|
894
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
895
|
+
messagePort,
|
|
896
|
+
isMessagePortOpen
|
|
897
|
+
});
|
|
898
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
899
|
+
handleIpc(ipc);
|
|
900
|
+
const rpc = createRpc(ipc);
|
|
901
|
+
return rpc;
|
|
902
|
+
};
|
|
903
|
+
const MessagePortRpcParent = {
|
|
904
|
+
__proto__: null,
|
|
905
|
+
create: create$5
|
|
906
|
+
};
|
|
792
907
|
const create$2 = async ({
|
|
793
908
|
commandMap
|
|
794
909
|
}) => {
|
|
@@ -859,7 +974,7 @@ const invoke$3 = (method, ...params) => {
|
|
|
859
974
|
const rpc = state$1.rpc;
|
|
860
975
|
return rpc.invoke(method, ...params);
|
|
861
976
|
};
|
|
862
|
-
const invokeAndTransfer$
|
|
977
|
+
const invokeAndTransfer$3 = (method, ...params) => {
|
|
863
978
|
const rpc = state$1.rpc;
|
|
864
979
|
return rpc.invokeAndTransfer(method, ...params);
|
|
865
980
|
};
|
|
@@ -870,8 +985,8 @@ const setRpc = rpc => {
|
|
|
870
985
|
const invoke$2 = async (method, ...params) => {
|
|
871
986
|
return invoke$3('WebView.compatExtensionHostWorkerInvoke', method, ...params);
|
|
872
987
|
};
|
|
873
|
-
const invokeAndTransfer$
|
|
874
|
-
return invokeAndTransfer$
|
|
988
|
+
const invokeAndTransfer$2 = async (method, ...params) => {
|
|
989
|
+
return invokeAndTransfer$3('WebView.compatExtensionHostWorkerInvokeAndTransfer', method, ...params);
|
|
875
990
|
};
|
|
876
991
|
|
|
877
992
|
const getCredentialLess = locationHost => {
|
|
@@ -1175,7 +1290,7 @@ const getOrigin = () => {
|
|
|
1175
1290
|
const getHost = () => {
|
|
1176
1291
|
return location.host;
|
|
1177
1292
|
};
|
|
1178
|
-
const getProtocol = () => {
|
|
1293
|
+
const getProtocol$1 = () => {
|
|
1179
1294
|
return location.protocol;
|
|
1180
1295
|
};
|
|
1181
1296
|
const getPort = () => {
|
|
@@ -1185,14 +1300,14 @@ const getPort = () => {
|
|
|
1185
1300
|
const invoke$1 = async (method, ...params) => {
|
|
1186
1301
|
return invoke$3('WebView.compatRendererProcessInvoke', method, ...params);
|
|
1187
1302
|
};
|
|
1188
|
-
const invokeAndTransfer = async (method, ...params) => {
|
|
1189
|
-
return invokeAndTransfer$
|
|
1303
|
+
const invokeAndTransfer$1 = async (method, ...params) => {
|
|
1304
|
+
return invokeAndTransfer$3('WebView.compatRendererProcessInvokeAndTransfer', method, ...params);
|
|
1190
1305
|
};
|
|
1191
1306
|
|
|
1192
1307
|
const WebView = 'lvce-oss-webview';
|
|
1193
1308
|
|
|
1194
1309
|
const setPort = async (uid, port, origin, portType) => {
|
|
1195
|
-
await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
|
|
1310
|
+
await invokeAndTransfer$1('WebView.setPort', uid, port, origin, portType);
|
|
1196
1311
|
};
|
|
1197
1312
|
|
|
1198
1313
|
const invoke = async (method, ...params) => {
|
|
@@ -1289,7 +1404,7 @@ const create2 = async ({
|
|
|
1289
1404
|
root = await invoke('Platform.getRoot');
|
|
1290
1405
|
}
|
|
1291
1406
|
const webViews = await getWebViews();
|
|
1292
|
-
const locationProtocol = getProtocol();
|
|
1407
|
+
const locationProtocol = getProtocol$1();
|
|
1293
1408
|
const locationHost = getHost();
|
|
1294
1409
|
const locationOrigin = getOrigin();
|
|
1295
1410
|
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir$1, webViewScheme, false);
|
|
@@ -1335,7 +1450,7 @@ const create2 = async ({
|
|
|
1335
1450
|
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1336
1451
|
const portType = '';
|
|
1337
1452
|
await setPort(id, port1, origin, portType);
|
|
1338
|
-
await invokeAndTransfer$
|
|
1453
|
+
await invokeAndTransfer$2('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
|
|
1339
1454
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1340
1455
|
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1341
1456
|
return {
|
|
@@ -1347,6 +1462,140 @@ const create2 = async ({
|
|
|
1347
1462
|
};
|
|
1348
1463
|
};
|
|
1349
1464
|
|
|
1465
|
+
const invokeAndTransfer = async (method, ...params) => {
|
|
1466
|
+
return invokeAndTransfer$3('WebView.compatRendererWorkerInvokeAndTransfer', method, ...params);
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1469
|
+
const createSecondaryWebViewConnection = async (uid, origin, port) => {
|
|
1470
|
+
const portType = 'application';
|
|
1471
|
+
await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
|
|
1472
|
+
};
|
|
1473
|
+
|
|
1474
|
+
const createWebViewConnection = async (uid, origin) => {
|
|
1475
|
+
const {
|
|
1476
|
+
port1,
|
|
1477
|
+
port2
|
|
1478
|
+
} = getPortTuple();
|
|
1479
|
+
const rpcPromise = MessagePortRpcParent.create({
|
|
1480
|
+
messagePort: port2,
|
|
1481
|
+
isMessagePortOpen: false,
|
|
1482
|
+
commandMap: {}
|
|
1483
|
+
});
|
|
1484
|
+
const portType = 'test';
|
|
1485
|
+
await invokeAndTransfer('WebView.setPort', uid, port1, origin, portType);
|
|
1486
|
+
// TODO dispose rpc to avoid memory leak
|
|
1487
|
+
const rpc = await rpcPromise;
|
|
1488
|
+
return rpc;
|
|
1489
|
+
};
|
|
1490
|
+
|
|
1491
|
+
const RE_PROTOCOL = /^([a-z-]+):\/\//;
|
|
1492
|
+
const getProtocol = uri => {
|
|
1493
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1494
|
+
if (protocolMatch) {
|
|
1495
|
+
return protocolMatch[1];
|
|
1496
|
+
}
|
|
1497
|
+
return '';
|
|
1498
|
+
};
|
|
1499
|
+
|
|
1500
|
+
// TODO if webViewId is provided,
|
|
1501
|
+
// 1. read file as blob
|
|
1502
|
+
// 2. send blob to webview
|
|
1503
|
+
// 3. create objecturl in webview
|
|
1504
|
+
// 4. send back objecturl to extension host worker
|
|
1505
|
+
// 5. provide objectUrl to extension
|
|
1506
|
+
|
|
1507
|
+
const getRemoteUrlForWebView = async options => {
|
|
1508
|
+
throw new Error('not implemented');
|
|
1509
|
+
// TODO webviews should be stored in iframe worker
|
|
1510
|
+
// const webView = ExtensionHostWebViewState.getWebView(options.webViewId as string)
|
|
1511
|
+
// if (!webView) {
|
|
1512
|
+
// throw new Error(`webview ${options.webViewId} not found`)
|
|
1513
|
+
// }
|
|
1514
|
+
// const [rpc, blob] = await Promise.all([CreateWebViewIpc.createWebViewIpc(webView), Rpc.invoke('FileSystem.getBlob', uri)])
|
|
1515
|
+
// const objectUrl = await rpc.invoke('createObjectUrl', blob)
|
|
1516
|
+
// return objectUrl
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
const getRemoteUrl = async options => {
|
|
1520
|
+
const {
|
|
1521
|
+
uri
|
|
1522
|
+
} = options;
|
|
1523
|
+
// TODO uri should always have protocol
|
|
1524
|
+
// then ask file system provider for remote url, for example disk file system provider or html file system provider
|
|
1525
|
+
const protocol = getProtocol(uri);
|
|
1526
|
+
if (platform === Remote && !protocol) {
|
|
1527
|
+
if (uri.startsWith('/')) {
|
|
1528
|
+
return `/remote${uri}`;
|
|
1529
|
+
}
|
|
1530
|
+
return `/remote/${uri}`;
|
|
1531
|
+
}
|
|
1532
|
+
if (platform === Electron && !protocol) {
|
|
1533
|
+
if (uri.startsWith('/')) {
|
|
1534
|
+
return `/remote${uri}`;
|
|
1535
|
+
}
|
|
1536
|
+
return `/remote/${uri}`;
|
|
1537
|
+
}
|
|
1538
|
+
return getRemoteUrlForWebView();
|
|
1539
|
+
};
|
|
1540
|
+
|
|
1541
|
+
const commandMap$1 = {
|
|
1542
|
+
'WebView.getRemoteUrl': getRemoteUrl
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1545
|
+
const getWebViewWorkerRpc = async rpcInfo => {
|
|
1546
|
+
const {
|
|
1547
|
+
port1,
|
|
1548
|
+
port2
|
|
1549
|
+
} = getPortTuple();
|
|
1550
|
+
const rpcPromise = MessagePortRpcParent.create({
|
|
1551
|
+
commandMap: commandMap$1,
|
|
1552
|
+
messagePort: port2,
|
|
1553
|
+
isMessagePortOpen: true
|
|
1554
|
+
});
|
|
1555
|
+
await invokeAndTransfer$2('WebView.createWebViewWorkerRpc', rpcInfo, port1);
|
|
1556
|
+
const rpc = await rpcPromise;
|
|
1557
|
+
// TODO rpc module should start the port
|
|
1558
|
+
port2.start();
|
|
1559
|
+
return rpc;
|
|
1560
|
+
};
|
|
1561
|
+
|
|
1562
|
+
const rpcs = Object.create(null);
|
|
1563
|
+
const set = (id, rpc) => {
|
|
1564
|
+
rpcs[id] = rpc;
|
|
1565
|
+
};
|
|
1566
|
+
|
|
1567
|
+
const createWebViewRpc = async (webView, savedState, uri, portId, webViewUid, origin) => {
|
|
1568
|
+
if (!webView || !webView.rpc || typeof webView.rpc !== 'string') {
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
const rpcInfo = await invoke$2('WebView.getRpcInfo', webView.rpc);
|
|
1572
|
+
if (rpcInfo.type !== 'web-worker') {
|
|
1573
|
+
throw new Error(`only web worker rpc is supported for webviews`);
|
|
1574
|
+
}
|
|
1575
|
+
const rpc = await getWebViewWorkerRpc(rpcInfo);
|
|
1576
|
+
const webViewInfo = {
|
|
1577
|
+
rpc,
|
|
1578
|
+
webViewId: webView.id
|
|
1579
|
+
};
|
|
1580
|
+
set(portId, webViewInfo);
|
|
1581
|
+
await rpc.invoke('LoadFile.loadFile', rpcInfo.url);
|
|
1582
|
+
|
|
1583
|
+
// TODO this connection might not be needed
|
|
1584
|
+
await createWebViewConnection(webViewUid, origin);
|
|
1585
|
+
const {
|
|
1586
|
+
port1,
|
|
1587
|
+
port2
|
|
1588
|
+
} = getPortTuple();
|
|
1589
|
+
await createSecondaryWebViewConnection(webViewUid, origin, port1);
|
|
1590
|
+
await rpc.invokeAndTransfer('_WebView.setPort', portId, port2);
|
|
1591
|
+
await rpc.invoke('_WebView.create', {
|
|
1592
|
+
id: portId,
|
|
1593
|
+
savedState,
|
|
1594
|
+
webViewId: webView.id,
|
|
1595
|
+
uri
|
|
1596
|
+
});
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1350
1599
|
const getPreviewServerId = () => {
|
|
1351
1600
|
// TODO
|
|
1352
1601
|
return 1;
|
|
@@ -1390,7 +1639,7 @@ const create3 = async ({
|
|
|
1390
1639
|
}
|
|
1391
1640
|
const webViews = await getWebViews();
|
|
1392
1641
|
const webViewId = getWebViewId(webViews, uri);
|
|
1393
|
-
const locationProtocol = getProtocol();
|
|
1642
|
+
const locationProtocol = getProtocol$1();
|
|
1394
1643
|
const locationHost = getHost();
|
|
1395
1644
|
const locationOrigin = getOrigin();
|
|
1396
1645
|
const locationPort = getPort();
|
|
@@ -1423,10 +1672,6 @@ const create3 = async ({
|
|
|
1423
1672
|
const iframeCsp = platform === Web ? csp : '';
|
|
1424
1673
|
const credentialless = getCredentialLess(locationHost);
|
|
1425
1674
|
await invoke$3('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1426
|
-
const {
|
|
1427
|
-
port1,
|
|
1428
|
-
port2
|
|
1429
|
-
} = getPortTuple();
|
|
1430
1675
|
const portId = create$1();
|
|
1431
1676
|
const remotePathPrefix = '/remote';
|
|
1432
1677
|
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId, remotePathPrefix, useNewWebViewHandler);
|
|
@@ -1437,11 +1682,21 @@ const create3 = async ({
|
|
|
1437
1682
|
// port and wait for the first port message
|
|
1438
1683
|
await invoke$1('WebView.load', id);
|
|
1439
1684
|
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1440
|
-
const
|
|
1441
|
-
|
|
1442
|
-
|
|
1685
|
+
const hasOldRpc = !webView || !webView.rpc || typeof webView.rpc !== 'string';
|
|
1686
|
+
if (hasOldRpc) {
|
|
1687
|
+
const {
|
|
1688
|
+
port1,
|
|
1689
|
+
port2
|
|
1690
|
+
} = getPortTuple();
|
|
1691
|
+
const portType = '';
|
|
1692
|
+
await setPort(id, port1, origin, portType);
|
|
1693
|
+
await invokeAndTransfer$2('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
|
|
1694
|
+
}
|
|
1443
1695
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1444
|
-
|
|
1696
|
+
if (hasOldRpc) {
|
|
1697
|
+
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1698
|
+
}
|
|
1699
|
+
await createWebViewRpc(webView, savedState, uri, portId, id, origin);
|
|
1445
1700
|
return {
|
|
1446
1701
|
iframeSrc,
|
|
1447
1702
|
sandbox,
|