@lvce-editor/iframe-worker 2.2.0 → 3.0.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 +71 -108
- 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$2 = {
|
|
3
3
|
callbacks: Object.create(null)
|
|
4
4
|
};
|
|
5
5
|
const set = (id, fn) => {
|
|
6
|
-
state$
|
|
6
|
+
state$2.callbacks[id] = fn;
|
|
7
7
|
};
|
|
8
8
|
const get = id => {
|
|
9
|
-
return state$
|
|
9
|
+
return state$2.callbacks[id];
|
|
10
10
|
};
|
|
11
11
|
const remove = id => {
|
|
12
|
-
delete state$
|
|
12
|
+
delete state$2.callbacks[id];
|
|
13
13
|
};
|
|
14
14
|
let id = 0;
|
|
15
15
|
const create$3 = () => {
|
|
@@ -328,10 +328,10 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
328
328
|
const responseMessage = await promise;
|
|
329
329
|
return unwrapJsonRpcResult(responseMessage);
|
|
330
330
|
};
|
|
331
|
-
const invoke$
|
|
331
|
+
const invoke$4 = (ipc, method, ...params) => {
|
|
332
332
|
return invokeHelper(ipc, method, params, false);
|
|
333
333
|
};
|
|
334
|
-
const invokeAndTransfer$
|
|
334
|
+
const invokeAndTransfer$3 = (ipc, method, ...params) => {
|
|
335
335
|
return invokeHelper(ipc, method, params, true);
|
|
336
336
|
};
|
|
337
337
|
|
|
@@ -736,10 +736,10 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
736
736
|
const createRpc = ipc => {
|
|
737
737
|
const rpc = {
|
|
738
738
|
invoke(method, ...params) {
|
|
739
|
-
return invoke$
|
|
739
|
+
return invoke$4(ipc, method, ...params);
|
|
740
740
|
},
|
|
741
741
|
invokeAndTransfer(method, ...params) {
|
|
742
|
-
return invokeAndTransfer$
|
|
742
|
+
return invokeAndTransfer$3(ipc, method, ...params);
|
|
743
743
|
}
|
|
744
744
|
};
|
|
745
745
|
return rpc;
|
|
@@ -782,8 +782,28 @@ const WebWorkerRpcClient = {
|
|
|
782
782
|
create: create$1$1
|
|
783
783
|
};
|
|
784
784
|
|
|
785
|
+
const state$1 = {
|
|
786
|
+
rpc: undefined
|
|
787
|
+
};
|
|
788
|
+
const invoke$3 = (method, ...params) => {
|
|
789
|
+
const rpc = state$1.rpc;
|
|
790
|
+
// @ts-ignore
|
|
791
|
+
return rpc.invoke(method, ...params);
|
|
792
|
+
};
|
|
793
|
+
const invokeAndTransfer$2 = (method, ...params) => {
|
|
794
|
+
const rpc = state$1.rpc;
|
|
795
|
+
// @ts-ignore
|
|
796
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
797
|
+
};
|
|
798
|
+
const setRpc = rpc => {
|
|
799
|
+
state$1.rpc = rpc;
|
|
800
|
+
};
|
|
801
|
+
|
|
785
802
|
const invoke$2 = async (method, ...params) => {
|
|
786
|
-
|
|
803
|
+
return invoke$3('WebView.compatExtensionHostWorkerInvoke', method, ...params);
|
|
804
|
+
};
|
|
805
|
+
const invokeAndTransfer$1 = async (method, ...params) => {
|
|
806
|
+
return invokeAndTransfer$2('WebView.compatExtensionHostWorkerInvokeAndTransfer', method, ...params);
|
|
787
807
|
};
|
|
788
808
|
|
|
789
809
|
const createUrl = (protocol, host) => {
|
|
@@ -900,19 +920,23 @@ const getWebViewUri = (webViews, webViewId) => {
|
|
|
900
920
|
}
|
|
901
921
|
return webViewPath;
|
|
902
922
|
};
|
|
903
|
-
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root) => {
|
|
923
|
+
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform) => {
|
|
904
924
|
const webView = getWebView$1(webViews, webViewId);
|
|
905
925
|
const webViewUri = getWebViewUri(webViews, webViewId);
|
|
926
|
+
console.log({
|
|
927
|
+
webViews,
|
|
928
|
+
webViewId
|
|
929
|
+
});
|
|
906
930
|
if (!webViewUri) {
|
|
907
931
|
return undefined;
|
|
908
932
|
}
|
|
909
933
|
let iframeSrc = webViewUri;
|
|
910
934
|
let webViewRoot = webViewUri;
|
|
911
|
-
if (platform === Electron) {
|
|
935
|
+
if (platform$1 === Electron) {
|
|
912
936
|
const relativePath = new URL(webViewUri).pathname.replace('/index.html', '');
|
|
913
937
|
iframeSrc = `${WebView}://-${relativePath}/`;
|
|
914
938
|
// TODO
|
|
915
|
-
} else if (platform === Remote) {
|
|
939
|
+
} else if (platform$1 === Remote) {
|
|
916
940
|
const relativePath = new URL(webViewUri).pathname.replace('/index.html', '');
|
|
917
941
|
if (webViewUri.startsWith('file://')) {
|
|
918
942
|
// ignore
|
|
@@ -1047,10 +1071,10 @@ class VError extends Error {
|
|
|
1047
1071
|
}
|
|
1048
1072
|
}
|
|
1049
1073
|
|
|
1050
|
-
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin) => {
|
|
1074
|
+
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform$1 = platform) => {
|
|
1051
1075
|
try {
|
|
1052
1076
|
const webView = getWebView(webViews, webViewId);
|
|
1053
|
-
if (platform === Web) {
|
|
1077
|
+
if (platform$1 === Web) {
|
|
1054
1078
|
return getIframeSrc$1(webView, locationOrigin);
|
|
1055
1079
|
}
|
|
1056
1080
|
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root);
|
|
@@ -1070,11 +1094,8 @@ const getPortTuple = () => {
|
|
|
1070
1094
|
};
|
|
1071
1095
|
};
|
|
1072
1096
|
|
|
1073
|
-
const getJson = async () => {};
|
|
1074
|
-
|
|
1075
1097
|
const getSavedState = async () => {
|
|
1076
|
-
|
|
1077
|
-
return value;
|
|
1098
|
+
return invoke$3('WebView.getSavedState');
|
|
1078
1099
|
};
|
|
1079
1100
|
|
|
1080
1101
|
const getSavedWebViewState = async id => {
|
|
@@ -1117,7 +1138,7 @@ const getWebViewFrameAncestors = (locationProtocol, locationHost) => {
|
|
|
1117
1138
|
return frameAncestors;
|
|
1118
1139
|
};
|
|
1119
1140
|
|
|
1120
|
-
const getWebViewOrigin = webViewPort => {
|
|
1141
|
+
const getWebViewOrigin = (webViewPort, platform) => {
|
|
1121
1142
|
// TODO don't hardcode protocol
|
|
1122
1143
|
let origin = '';
|
|
1123
1144
|
if (platform === Electron) {
|
|
@@ -1130,40 +1151,8 @@ const getWebViewOrigin = webViewPort => {
|
|
|
1130
1151
|
return origin;
|
|
1131
1152
|
};
|
|
1132
1153
|
|
|
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
1154
|
const getWebViews = async () => {
|
|
1162
|
-
|
|
1163
|
-
// TODO ask renderer worker for webviews
|
|
1164
|
-
// const registeredWebViews = WebViews.get()
|
|
1165
|
-
const allWebViews = [...nodeWebViews];
|
|
1166
|
-
return allWebViews;
|
|
1155
|
+
return invoke$3('WebView.getWebViews');
|
|
1167
1156
|
};
|
|
1168
1157
|
|
|
1169
1158
|
const AllowScripts = 'allow-scripts';
|
|
@@ -1197,28 +1186,32 @@ const getProtocol = () => {
|
|
|
1197
1186
|
return location.protocol;
|
|
1198
1187
|
};
|
|
1199
1188
|
|
|
1200
|
-
const invoke = async (method, ...params) => {
|
|
1201
|
-
|
|
1189
|
+
const invoke$1 = async (method, ...params) => {
|
|
1190
|
+
return invoke$3('WebView.compatRendererProcessInvoke', method, ...params);
|
|
1202
1191
|
};
|
|
1203
1192
|
const invokeAndTransfer = async (method, ...params) => {
|
|
1204
|
-
|
|
1193
|
+
return invokeAndTransfer$2('WebView.compatRendererProcessInvokeAndTransfer', method, ...params);
|
|
1205
1194
|
};
|
|
1206
1195
|
|
|
1207
1196
|
const setPort = async (uid, port, origin, portType) => {
|
|
1208
1197
|
await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
|
|
1209
1198
|
};
|
|
1210
1199
|
|
|
1200
|
+
const invoke = async (method, ...params) => {
|
|
1201
|
+
return invoke$3('WebView.compatSharedProcessInvoke', method, ...params);
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1211
1204
|
const registerProtocol = async () => {
|
|
1212
|
-
await invoke
|
|
1205
|
+
await invoke('WebViewServer.registerProtocol');
|
|
1213
1206
|
};
|
|
1214
1207
|
const create = async previewServerId => {
|
|
1215
|
-
await invoke
|
|
1208
|
+
await invoke('WebViewServer.create', previewServerId);
|
|
1216
1209
|
};
|
|
1217
1210
|
const start = async (previewServerId, webViewPort) => {
|
|
1218
|
-
await invoke
|
|
1211
|
+
await invoke('WebViewServer.start', previewServerId, webViewPort);
|
|
1219
1212
|
};
|
|
1220
1213
|
const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent) => {
|
|
1221
|
-
await invoke
|
|
1214
|
+
await invoke('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1222
1215
|
};
|
|
1223
1216
|
|
|
1224
1217
|
const register$3 = async previewServerId => {
|
|
@@ -1226,11 +1219,6 @@ const register$3 = async previewServerId => {
|
|
|
1226
1219
|
await create(previewServerId); // TODO move this up
|
|
1227
1220
|
};
|
|
1228
1221
|
|
|
1229
|
-
const WebViewProtocolElectron = {
|
|
1230
|
-
__proto__: null,
|
|
1231
|
-
register: register$3
|
|
1232
|
-
};
|
|
1233
|
-
|
|
1234
1222
|
const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
|
|
1235
1223
|
// TODO apply something similar for electron
|
|
1236
1224
|
// TODO pass webview root, so that only these resources can be accessed
|
|
@@ -1242,34 +1230,24 @@ const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewR
|
|
|
1242
1230
|
// TODO make this work in gitpod also
|
|
1243
1231
|
};
|
|
1244
1232
|
|
|
1245
|
-
const WebViewProtocolRemote = {
|
|
1246
|
-
__proto__: null,
|
|
1247
|
-
register: register$2
|
|
1248
|
-
};
|
|
1249
|
-
|
|
1250
1233
|
const register$1 = async () => {
|
|
1251
1234
|
// noop
|
|
1252
1235
|
};
|
|
1253
1236
|
|
|
1254
|
-
const WebViewProtocolWeb = {
|
|
1255
|
-
__proto__: null,
|
|
1256
|
-
register: register$1
|
|
1257
|
-
};
|
|
1258
|
-
|
|
1259
1237
|
const getModule = platform => {
|
|
1260
1238
|
switch (platform) {
|
|
1261
1239
|
case Remote:
|
|
1262
|
-
return
|
|
1240
|
+
return register$2;
|
|
1263
1241
|
case Electron:
|
|
1264
|
-
return
|
|
1242
|
+
return register$3;
|
|
1265
1243
|
case Web:
|
|
1266
1244
|
default:
|
|
1267
|
-
return
|
|
1245
|
+
return register$1;
|
|
1268
1246
|
}
|
|
1269
1247
|
};
|
|
1270
1248
|
const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
|
|
1271
|
-
const
|
|
1272
|
-
return
|
|
1249
|
+
const fn = getModule(platform);
|
|
1250
|
+
return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
|
|
1273
1251
|
};
|
|
1274
1252
|
|
|
1275
1253
|
const create2 = async ({
|
|
@@ -1278,18 +1256,18 @@ const create2 = async ({
|
|
|
1278
1256
|
webViewId,
|
|
1279
1257
|
previewServerId,
|
|
1280
1258
|
uri,
|
|
1281
|
-
platform
|
|
1259
|
+
platform,
|
|
1282
1260
|
isGitpod
|
|
1283
1261
|
}) => {
|
|
1284
1262
|
let root = '';
|
|
1285
1263
|
if (platform === Remote) {
|
|
1286
|
-
root = await invoke
|
|
1264
|
+
root = await invoke('Platform.getRoot');
|
|
1287
1265
|
}
|
|
1288
1266
|
const webViews = await getWebViews();
|
|
1289
1267
|
const locationProtocol = getProtocol();
|
|
1290
1268
|
const locationHost = getHost();
|
|
1291
1269
|
const locationOrigin = getOrigin();
|
|
1292
|
-
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin);
|
|
1270
|
+
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform);
|
|
1293
1271
|
if (!iframeResult) {
|
|
1294
1272
|
return undefined;
|
|
1295
1273
|
}
|
|
@@ -1311,26 +1289,22 @@ const create2 = async ({
|
|
|
1311
1289
|
// 4. create webview in extension host worker and load content
|
|
1312
1290
|
|
|
1313
1291
|
const csp = getWebViewCsp(webView);
|
|
1314
|
-
const sandbox = getIframeSandbox(webView, platform
|
|
1315
|
-
const iframeCsp = platform
|
|
1292
|
+
const sandbox = getIframeSandbox(webView, platform);
|
|
1293
|
+
const iframeCsp = platform === Web ? csp : '';
|
|
1316
1294
|
const credentialless = true;
|
|
1317
|
-
|
|
1318
|
-
// TODO ask renderer worker to activate
|
|
1319
|
-
// await ExtensionHostManagement.activateByEvent(`onWebView:${webViewId}`)
|
|
1295
|
+
await invoke$3('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1320
1296
|
const {
|
|
1321
|
-
port1
|
|
1297
|
+
port1,
|
|
1298
|
+
port2
|
|
1322
1299
|
} = getPortTuple();
|
|
1323
1300
|
const portId = create$1();
|
|
1324
1301
|
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);
|
|
1302
|
+
await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless);
|
|
1303
|
+
await invoke$1('WebView.load', id);
|
|
1304
|
+
const origin = getWebViewOrigin(webViewPort, platform);
|
|
1328
1305
|
const portType = '';
|
|
1329
1306
|
await setPort(id, port1, origin, portType);
|
|
1330
|
-
|
|
1331
|
-
// TODO
|
|
1332
|
-
// await ExtensionHostWorker.invokeAndTransfer('ExtensionHostWebView.create', webViewId, port2, uri, id, origin)
|
|
1333
|
-
|
|
1307
|
+
await invokeAndTransfer$1('ExtensionHostWebView.create', webViewId, port2, uri, id, origin);
|
|
1334
1308
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1335
1309
|
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1336
1310
|
return {
|
|
@@ -1344,25 +1318,14 @@ const create2 = async ({
|
|
|
1344
1318
|
};
|
|
1345
1319
|
|
|
1346
1320
|
const commandMap = {
|
|
1347
|
-
// deprecated
|
|
1348
|
-
'Location.getHost': getHost,
|
|
1349
|
-
'Location.getOrigin': getOrigin,
|
|
1350
|
-
'Location.getProtocol': getProtocol,
|
|
1351
|
-
'WebView.getBaseUrl': getWebViewBaseUrl,
|
|
1352
|
-
'WebView.getFrameAncestors': getWebViewFrameAncestors,
|
|
1353
|
-
'WebView.getHtml': getWebViewHtml,
|
|
1354
|
-
'WebView.getIframeSrc': getIframeSrc,
|
|
1355
|
-
'WebView.getOrigin': getWebViewOrigin,
|
|
1356
|
-
'WebView.getSandbox': getIframeSandbox,
|
|
1357
|
-
'WebView.getWebViewCsp': getWebViewCsp,
|
|
1358
|
-
// new
|
|
1359
1321
|
'WebView.create2': create2
|
|
1360
1322
|
};
|
|
1361
1323
|
|
|
1362
1324
|
const listen = async () => {
|
|
1363
|
-
await WebWorkerRpcClient.create({
|
|
1325
|
+
const rpc = await WebWorkerRpcClient.create({
|
|
1364
1326
|
commandMap: commandMap
|
|
1365
1327
|
});
|
|
1328
|
+
setRpc(rpc);
|
|
1366
1329
|
};
|
|
1367
1330
|
|
|
1368
1331
|
const main = async () => {
|