@lvce-editor/iframe-worker 2.1.0 → 2.2.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 +247 -17
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const Two = '2.0';
|
|
2
|
-
const state = {
|
|
2
|
+
const state$1 = {
|
|
3
3
|
callbacks: Object.create(null)
|
|
4
4
|
};
|
|
5
5
|
const set = (id, fn) => {
|
|
6
|
-
state.callbacks[id] = fn;
|
|
6
|
+
state$1.callbacks[id] = fn;
|
|
7
7
|
};
|
|
8
8
|
const get = id => {
|
|
9
|
-
return state.callbacks[id];
|
|
9
|
+
return state$1.callbacks[id];
|
|
10
10
|
};
|
|
11
11
|
const remove = id => {
|
|
12
|
-
delete state.callbacks[id];
|
|
12
|
+
delete state$1.callbacks[id];
|
|
13
13
|
};
|
|
14
14
|
let id = 0;
|
|
15
15
|
const create$3 = () => {
|
|
@@ -217,7 +217,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
217
217
|
}
|
|
218
218
|
};
|
|
219
219
|
};
|
|
220
|
-
const create$1$
|
|
220
|
+
const create$1$2 = (message, error) => {
|
|
221
221
|
return {
|
|
222
222
|
jsonrpc: Two,
|
|
223
223
|
id: message.id,
|
|
@@ -228,9 +228,9 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
|
228
228
|
const prettyError = preparePrettyError(error);
|
|
229
229
|
logError(error, prettyError);
|
|
230
230
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
231
|
-
return create$1$
|
|
231
|
+
return create$1$2(message, errorProperty);
|
|
232
232
|
};
|
|
233
|
-
const create = (message, result) => {
|
|
233
|
+
const create$4 = (message, result) => {
|
|
234
234
|
return {
|
|
235
235
|
jsonrpc: Two,
|
|
236
236
|
id: message.id,
|
|
@@ -239,7 +239,7 @@ const create = (message, result) => {
|
|
|
239
239
|
};
|
|
240
240
|
const getSuccessResponse = (message, result) => {
|
|
241
241
|
const resultProperty = result ?? null;
|
|
242
|
-
return create(message, resultProperty);
|
|
242
|
+
return create$4(message, resultProperty);
|
|
243
243
|
};
|
|
244
244
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
245
245
|
try {
|
|
@@ -328,15 +328,15 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
328
328
|
const responseMessage = await promise;
|
|
329
329
|
return unwrapJsonRpcResult(responseMessage);
|
|
330
330
|
};
|
|
331
|
-
const invoke = (ipc, method, ...params) => {
|
|
331
|
+
const invoke$3 = (ipc, method, ...params) => {
|
|
332
332
|
return invokeHelper(ipc, method, params, false);
|
|
333
333
|
};
|
|
334
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
334
|
+
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
335
335
|
return invokeHelper(ipc, method, params, true);
|
|
336
336
|
};
|
|
337
337
|
|
|
338
338
|
const commands = Object.create(null);
|
|
339
|
-
const register = commandMap => {
|
|
339
|
+
const register$4 = commandMap => {
|
|
340
340
|
Object.assign(commands, commandMap);
|
|
341
341
|
};
|
|
342
342
|
const getCommand = key => {
|
|
@@ -736,10 +736,10 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
736
736
|
const createRpc = ipc => {
|
|
737
737
|
const rpc = {
|
|
738
738
|
invoke(method, ...params) {
|
|
739
|
-
return invoke(ipc, method, ...params);
|
|
739
|
+
return invoke$3(ipc, method, ...params);
|
|
740
740
|
},
|
|
741
741
|
invokeAndTransfer(method, ...params) {
|
|
742
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
742
|
+
return invokeAndTransfer$1(ipc, method, ...params);
|
|
743
743
|
}
|
|
744
744
|
};
|
|
745
745
|
return rpc;
|
|
@@ -767,11 +767,11 @@ const listen$1 = async () => {
|
|
|
767
767
|
const ipc = module.wrap(rawIpc);
|
|
768
768
|
return ipc;
|
|
769
769
|
};
|
|
770
|
-
const create$1 = async ({
|
|
770
|
+
const create$1$1 = async ({
|
|
771
771
|
commandMap
|
|
772
772
|
}) => {
|
|
773
773
|
// TODO create a commandMap per rpc instance
|
|
774
|
-
register(commandMap);
|
|
774
|
+
register$4(commandMap);
|
|
775
775
|
const ipc = await listen$1();
|
|
776
776
|
handleIpc(ipc);
|
|
777
777
|
const rpc = createRpc(ipc);
|
|
@@ -779,7 +779,11 @@ const create$1 = async ({
|
|
|
779
779
|
};
|
|
780
780
|
const WebWorkerRpcClient = {
|
|
781
781
|
__proto__: null,
|
|
782
|
-
create: create$1
|
|
782
|
+
create: create$1$1
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
const invoke$2 = async (method, ...params) => {
|
|
786
|
+
// TODO
|
|
783
787
|
};
|
|
784
788
|
|
|
785
789
|
const createUrl = (protocol, host) => {
|
|
@@ -1055,6 +1059,40 @@ const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, location
|
|
|
1055
1059
|
}
|
|
1056
1060
|
};
|
|
1057
1061
|
|
|
1062
|
+
const getPortTuple = () => {
|
|
1063
|
+
const {
|
|
1064
|
+
port1,
|
|
1065
|
+
port2
|
|
1066
|
+
} = new MessageChannel();
|
|
1067
|
+
return {
|
|
1068
|
+
port1,
|
|
1069
|
+
port2
|
|
1070
|
+
};
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
const getJson = async () => {};
|
|
1074
|
+
|
|
1075
|
+
const getSavedState = async () => {
|
|
1076
|
+
const value = await getJson();
|
|
1077
|
+
return value;
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
const getSavedWebViewState = async id => {
|
|
1081
|
+
const states = await getSavedState();
|
|
1082
|
+
if (!states) {
|
|
1083
|
+
return undefined;
|
|
1084
|
+
}
|
|
1085
|
+
if (!Array.isArray(states)) {
|
|
1086
|
+
return undefined;
|
|
1087
|
+
}
|
|
1088
|
+
for (const item of states) {
|
|
1089
|
+
if (item && item.key && item.key === id && item.value && item.value.state) {
|
|
1090
|
+
return item.value.state;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return undefined;
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1058
1096
|
const SemiColon = ';';
|
|
1059
1097
|
const Space = ' ';
|
|
1060
1098
|
|
|
@@ -1092,6 +1130,42 @@ const getWebViewOrigin = webViewPort => {
|
|
|
1092
1130
|
return origin;
|
|
1093
1131
|
};
|
|
1094
1132
|
|
|
1133
|
+
const invoke$1 = async (method, ...params) => {
|
|
1134
|
+
// TODO
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
const getWebViewsNode = async () => {
|
|
1138
|
+
const webViews = await invoke$1();
|
|
1139
|
+
return webViews;
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
const getWebViewsWeb = async () => {
|
|
1143
|
+
// const url = `${AssetDir.assetDir}/config/webViews.json`
|
|
1144
|
+
// TODO move this to shared-process-web / network-process-web
|
|
1145
|
+
// TODO handle error ?
|
|
1146
|
+
// TODO use parent rpc invoke
|
|
1147
|
+
// return Command.execute(/* Ajax.getJson */ 'Ajax.getJson', /* url */ url)
|
|
1148
|
+
return [];
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
const getWebViewsDefault = async () => {
|
|
1152
|
+
switch (platform) {
|
|
1153
|
+
case Web:
|
|
1154
|
+
return getWebViewsWeb();
|
|
1155
|
+
case Test:
|
|
1156
|
+
return [];
|
|
1157
|
+
default:
|
|
1158
|
+
return getWebViewsNode();
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
const getWebViews = async () => {
|
|
1162
|
+
const nodeWebViews = await getWebViewsDefault();
|
|
1163
|
+
// TODO ask renderer worker for webviews
|
|
1164
|
+
// const registeredWebViews = WebViews.get()
|
|
1165
|
+
const allWebViews = [...nodeWebViews];
|
|
1166
|
+
return allWebViews;
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1095
1169
|
const AllowScripts = 'allow-scripts';
|
|
1096
1170
|
const AllowSameOrigin = 'allow-same-origin';
|
|
1097
1171
|
|
|
@@ -1106,6 +1180,13 @@ const getIframeSandbox = (webView, platform) => {
|
|
|
1106
1180
|
return [AllowScripts, AllowSameOrigin, ...extensionSandbox];
|
|
1107
1181
|
};
|
|
1108
1182
|
|
|
1183
|
+
const state = {
|
|
1184
|
+
id: 0
|
|
1185
|
+
};
|
|
1186
|
+
const create$1 = () => {
|
|
1187
|
+
return ++state.id;
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1109
1190
|
const getOrigin = () => {
|
|
1110
1191
|
return location.origin;
|
|
1111
1192
|
};
|
|
@@ -1116,7 +1197,154 @@ const getProtocol = () => {
|
|
|
1116
1197
|
return location.protocol;
|
|
1117
1198
|
};
|
|
1118
1199
|
|
|
1200
|
+
const invoke = async (method, ...params) => {
|
|
1201
|
+
// TODO
|
|
1202
|
+
};
|
|
1203
|
+
const invokeAndTransfer = async (method, ...params) => {
|
|
1204
|
+
// TODO
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
const setPort = async (uid, port, origin, portType) => {
|
|
1208
|
+
await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
|
|
1209
|
+
};
|
|
1210
|
+
|
|
1211
|
+
const registerProtocol = async () => {
|
|
1212
|
+
await invoke$1();
|
|
1213
|
+
};
|
|
1214
|
+
const create = async previewServerId => {
|
|
1215
|
+
await invoke$1('WebViewServer.create', previewServerId);
|
|
1216
|
+
};
|
|
1217
|
+
const start = async (previewServerId, webViewPort) => {
|
|
1218
|
+
await invoke$1('WebViewServer.start', previewServerId, webViewPort);
|
|
1219
|
+
};
|
|
1220
|
+
const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent) => {
|
|
1221
|
+
await invoke$1('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
const register$3 = async previewServerId => {
|
|
1225
|
+
await registerProtocol();
|
|
1226
|
+
await create(previewServerId); // TODO move this up
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
const WebViewProtocolElectron = {
|
|
1230
|
+
__proto__: null,
|
|
1231
|
+
register: register$3
|
|
1232
|
+
};
|
|
1233
|
+
|
|
1234
|
+
const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
|
|
1235
|
+
// TODO apply something similar for electron
|
|
1236
|
+
// TODO pass webview root, so that only these resources can be accessed
|
|
1237
|
+
// TODO pass csp configuration to server
|
|
1238
|
+
// TODO pass coop / coep configuration to server
|
|
1239
|
+
await create(previewServerId); // TODO move this up
|
|
1240
|
+
await start(previewServerId, webViewPort); // TODO move this up
|
|
1241
|
+
await setHandler(previewServerId, frameAncestors, webViewRoot, csp, iframeContent);
|
|
1242
|
+
// TODO make this work in gitpod also
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
const WebViewProtocolRemote = {
|
|
1246
|
+
__proto__: null,
|
|
1247
|
+
register: register$2
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1250
|
+
const register$1 = async () => {
|
|
1251
|
+
// noop
|
|
1252
|
+
};
|
|
1253
|
+
|
|
1254
|
+
const WebViewProtocolWeb = {
|
|
1255
|
+
__proto__: null,
|
|
1256
|
+
register: register$1
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
const getModule = platform => {
|
|
1260
|
+
switch (platform) {
|
|
1261
|
+
case Remote:
|
|
1262
|
+
return WebViewProtocolRemote;
|
|
1263
|
+
case Electron:
|
|
1264
|
+
return WebViewProtocolElectron;
|
|
1265
|
+
case Web:
|
|
1266
|
+
default:
|
|
1267
|
+
return WebViewProtocolWeb;
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
|
|
1271
|
+
const module = getModule(platform);
|
|
1272
|
+
return module.register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
|
|
1273
|
+
};
|
|
1274
|
+
|
|
1275
|
+
const create2 = async ({
|
|
1276
|
+
id,
|
|
1277
|
+
webViewPort,
|
|
1278
|
+
webViewId,
|
|
1279
|
+
previewServerId,
|
|
1280
|
+
uri,
|
|
1281
|
+
platform: platform$1,
|
|
1282
|
+
isGitpod
|
|
1283
|
+
}) => {
|
|
1284
|
+
let root = '';
|
|
1285
|
+
if (platform === Remote) {
|
|
1286
|
+
root = await invoke$1();
|
|
1287
|
+
}
|
|
1288
|
+
const webViews = await getWebViews();
|
|
1289
|
+
const locationProtocol = getProtocol();
|
|
1290
|
+
const locationHost = getHost();
|
|
1291
|
+
const locationOrigin = getOrigin();
|
|
1292
|
+
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin);
|
|
1293
|
+
if (!iframeResult) {
|
|
1294
|
+
return undefined;
|
|
1295
|
+
}
|
|
1296
|
+
const webView = getWebView(webViews, webViewId);
|
|
1297
|
+
|
|
1298
|
+
// TODO move all of this to iframe worker
|
|
1299
|
+
const {
|
|
1300
|
+
iframeSrc,
|
|
1301
|
+
webViewRoot,
|
|
1302
|
+
srcDoc,
|
|
1303
|
+
iframeContent
|
|
1304
|
+
} = iframeResult;
|
|
1305
|
+
const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
|
|
1306
|
+
|
|
1307
|
+
// TODO figure out order for events, e.g.
|
|
1308
|
+
// 1. activate extension, create webview and ports in parallel
|
|
1309
|
+
// 2. wait for webview to load (?)
|
|
1310
|
+
// 3. setup extension host worker rpc
|
|
1311
|
+
// 4. create webview in extension host worker and load content
|
|
1312
|
+
|
|
1313
|
+
const csp = getWebViewCsp(webView);
|
|
1314
|
+
const sandbox = getIframeSandbox(webView, platform$1);
|
|
1315
|
+
const iframeCsp = platform$1 === Web ? csp : '';
|
|
1316
|
+
const credentialless = true;
|
|
1317
|
+
|
|
1318
|
+
// TODO ask renderer worker to activate
|
|
1319
|
+
// await ExtensionHostManagement.activateByEvent(`onWebView:${webViewId}`)
|
|
1320
|
+
const {
|
|
1321
|
+
port1
|
|
1322
|
+
} = getPortTuple();
|
|
1323
|
+
const portId = create$1();
|
|
1324
|
+
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
|
|
1325
|
+
await invoke('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless);
|
|
1326
|
+
await invoke('WebView.load', id);
|
|
1327
|
+
const origin = getWebViewOrigin(webViewPort);
|
|
1328
|
+
const portType = '';
|
|
1329
|
+
await setPort(id, port1, origin, portType);
|
|
1330
|
+
|
|
1331
|
+
// TODO
|
|
1332
|
+
// await ExtensionHostWorker.invokeAndTransfer('ExtensionHostWebView.create', webViewId, port2, uri, id, origin)
|
|
1333
|
+
|
|
1334
|
+
const savedState = await getSavedWebViewState(webViewId);
|
|
1335
|
+
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1336
|
+
return {
|
|
1337
|
+
srcDoc,
|
|
1338
|
+
iframeSrc,
|
|
1339
|
+
sandbox,
|
|
1340
|
+
portId,
|
|
1341
|
+
origin,
|
|
1342
|
+
csp: iframeCsp
|
|
1343
|
+
};
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1119
1346
|
const commandMap = {
|
|
1347
|
+
// deprecated
|
|
1120
1348
|
'Location.getHost': getHost,
|
|
1121
1349
|
'Location.getOrigin': getOrigin,
|
|
1122
1350
|
'Location.getProtocol': getProtocol,
|
|
@@ -1126,7 +1354,9 @@ const commandMap = {
|
|
|
1126
1354
|
'WebView.getIframeSrc': getIframeSrc,
|
|
1127
1355
|
'WebView.getOrigin': getWebViewOrigin,
|
|
1128
1356
|
'WebView.getSandbox': getIframeSandbox,
|
|
1129
|
-
'WebView.getWebViewCsp': getWebViewCsp
|
|
1357
|
+
'WebView.getWebViewCsp': getWebViewCsp,
|
|
1358
|
+
// new
|
|
1359
|
+
'WebView.create2': create2
|
|
1130
1360
|
};
|
|
1131
1361
|
|
|
1132
1362
|
const listen = async () => {
|