@lvce-editor/iframe-worker 5.6.0 → 5.8.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 +121 -8
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -893,6 +893,16 @@ const createLocalHostUrl = (locationProtocol, locationHost, isGitpod, webViewPor
|
|
|
893
893
|
return `http://localhost:${webViewPort}`;
|
|
894
894
|
};
|
|
895
895
|
|
|
896
|
+
const getIframeSrcRemoteBaseUrl = (webViewRoot, locationOrigin) => {
|
|
897
|
+
if (webViewRoot && (webViewRoot.startsWith('http:') || webViewRoot.startsWith('https:'))) {
|
|
898
|
+
if (webViewRoot.startsWith(locationOrigin)) {
|
|
899
|
+
return webViewRoot.slice(locationOrigin.length);
|
|
900
|
+
}
|
|
901
|
+
return webViewRoot;
|
|
902
|
+
}
|
|
903
|
+
return '';
|
|
904
|
+
};
|
|
905
|
+
|
|
896
906
|
const getWebView = (webViews, webViewId) => {
|
|
897
907
|
for (const webView of webViews) {
|
|
898
908
|
if (webView.id === webViewId) {
|
|
@@ -948,7 +958,7 @@ const getWebViewUri = (webViews, webViewId) => {
|
|
|
948
958
|
return webViewPath;
|
|
949
959
|
};
|
|
950
960
|
|
|
951
|
-
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform, assetDir, webViewScheme) => {
|
|
961
|
+
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationOrigin, locationHost, isGitpod, root, platform$1 = platform, assetDir, webViewScheme) => {
|
|
952
962
|
const webView = getWebView(webViews, webViewId);
|
|
953
963
|
const webViewUri = getWebViewUri(webViews, webViewId);
|
|
954
964
|
if (!webViewUri) {
|
|
@@ -965,12 +975,12 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
|
|
|
965
975
|
webViewRoot = webView.uri;
|
|
966
976
|
iframeSrc = createLocalHostUrl(locationProtocol, locationHost, isGitpod, webViewPort);
|
|
967
977
|
}
|
|
968
|
-
const
|
|
978
|
+
const baseUrl = getIframeSrcRemoteBaseUrl(webViewRoot, locationOrigin);
|
|
979
|
+
const iframeContent = getWebViewHtml(baseUrl, '', webView.elements, assetDir);
|
|
969
980
|
// TODO either
|
|
970
981
|
// - load webviews the same as in web using blob urls
|
|
971
982
|
// - load webviews from a pattern like /webviews/:id/:fileName
|
|
972
983
|
return {
|
|
973
|
-
srcDoc: '',
|
|
974
984
|
iframeSrc,
|
|
975
985
|
webViewRoot,
|
|
976
986
|
iframeContent
|
|
@@ -1019,7 +1029,6 @@ const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
|
|
|
1019
1029
|
if (srcHtml) {
|
|
1020
1030
|
const blobUrl = getBlobUrl(srcHtml, 'text/html');
|
|
1021
1031
|
return {
|
|
1022
|
-
srcDoc: '',
|
|
1023
1032
|
iframeSrc: blobUrl,
|
|
1024
1033
|
webViewRoot: '',
|
|
1025
1034
|
iframeContent: ''
|
|
@@ -1034,7 +1043,7 @@ const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, location
|
|
|
1034
1043
|
if (platform === Web) {
|
|
1035
1044
|
return getIframeSrc$1(webView, locationOrigin, assetDir);
|
|
1036
1045
|
}
|
|
1037
|
-
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform, assetDir, webViewScheme);
|
|
1046
|
+
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationOrigin, locationHost, isGitpod, root, platform, assetDir, webViewScheme);
|
|
1038
1047
|
} catch (error) {
|
|
1039
1048
|
throw new VError(error, `Failed to construct webview iframe src`);
|
|
1040
1049
|
}
|
|
@@ -1162,6 +1171,9 @@ const getHost = () => {
|
|
|
1162
1171
|
const getProtocol = () => {
|
|
1163
1172
|
return location.protocol;
|
|
1164
1173
|
};
|
|
1174
|
+
const getPort = () => {
|
|
1175
|
+
return location.port;
|
|
1176
|
+
};
|
|
1165
1177
|
|
|
1166
1178
|
const invoke$1 = async (method, ...params) => {
|
|
1167
1179
|
return invoke$3('WebView.compatRendererProcessInvoke', method, ...params);
|
|
@@ -1270,7 +1282,6 @@ const create2 = async ({
|
|
|
1270
1282
|
const {
|
|
1271
1283
|
iframeSrc,
|
|
1272
1284
|
webViewRoot,
|
|
1273
|
-
srcDoc,
|
|
1274
1285
|
iframeContent
|
|
1275
1286
|
} = iframeResult;
|
|
1276
1287
|
const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
|
|
@@ -1307,7 +1318,108 @@ const create2 = async ({
|
|
|
1307
1318
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1308
1319
|
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1309
1320
|
return {
|
|
1310
|
-
|
|
1321
|
+
iframeSrc,
|
|
1322
|
+
sandbox,
|
|
1323
|
+
portId,
|
|
1324
|
+
origin,
|
|
1325
|
+
csp: iframeCsp
|
|
1326
|
+
};
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
const getPreviewServerId = () => {
|
|
1330
|
+
// TODO
|
|
1331
|
+
return 1;
|
|
1332
|
+
};
|
|
1333
|
+
|
|
1334
|
+
const getWebViewId = (webViews, uri) => {
|
|
1335
|
+
if (uri.startsWith('webview://')) {
|
|
1336
|
+
const webViewId = uri.slice('webview://'.length);
|
|
1337
|
+
return webViewId;
|
|
1338
|
+
}
|
|
1339
|
+
for (const webView of webViews) {
|
|
1340
|
+
for (const selector of webView.selector || []) {
|
|
1341
|
+
if (uri.endsWith(selector)) {
|
|
1342
|
+
return webView.id;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
return '';
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
const getWebViewPort = (platform, locationPort) => {
|
|
1350
|
+
if (platform === Web) {
|
|
1351
|
+
return locationPort;
|
|
1352
|
+
}
|
|
1353
|
+
// TODO make port configurable
|
|
1354
|
+
return '3002';
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
const create3 = async ({
|
|
1358
|
+
id,
|
|
1359
|
+
uri,
|
|
1360
|
+
isGitpod,
|
|
1361
|
+
platform,
|
|
1362
|
+
assetDir,
|
|
1363
|
+
webViewScheme
|
|
1364
|
+
}) => {
|
|
1365
|
+
let root = '';
|
|
1366
|
+
if (platform === Remote) {
|
|
1367
|
+
root = await invoke('Platform.getRoot');
|
|
1368
|
+
}
|
|
1369
|
+
const webViews = await getWebViews();
|
|
1370
|
+
const webViewId = getWebViewId(webViews, uri);
|
|
1371
|
+
const locationProtocol = getProtocol();
|
|
1372
|
+
const locationHost = getHost();
|
|
1373
|
+
const locationOrigin = getOrigin();
|
|
1374
|
+
const locationPort = getPort();
|
|
1375
|
+
const webViewPort = getWebViewPort(platform, locationPort);
|
|
1376
|
+
const previewServerId = getPreviewServerId();
|
|
1377
|
+
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir, webViewScheme);
|
|
1378
|
+
if (!iframeResult) {
|
|
1379
|
+
return undefined;
|
|
1380
|
+
}
|
|
1381
|
+
const webView = getWebView(webViews, webViewId);
|
|
1382
|
+
|
|
1383
|
+
// TODO move all of this to iframe worker
|
|
1384
|
+
const {
|
|
1385
|
+
iframeSrc,
|
|
1386
|
+
webViewRoot,
|
|
1387
|
+
iframeContent
|
|
1388
|
+
} = iframeResult;
|
|
1389
|
+
const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
|
|
1390
|
+
const frameTitle = getWebViewTitle(webView);
|
|
1391
|
+
// TODO figure out order for events, e.g.
|
|
1392
|
+
// 1. activate extension, create webview and ports in parallel
|
|
1393
|
+
// 2. wait for webview to load (?)
|
|
1394
|
+
// 3. setup extension host worker rpc
|
|
1395
|
+
// 4. create webview in extension host worker and load content
|
|
1396
|
+
|
|
1397
|
+
const csp = getWebViewCsp(webView);
|
|
1398
|
+
const sandbox = getIframeSandbox(webView, platform);
|
|
1399
|
+
const permissionPolicy = getIframePermissionPolicy(webView);
|
|
1400
|
+
const permissionPolicyString = permissionPolicy.join('; ');
|
|
1401
|
+
const iframeCsp = platform === Web ? csp : '';
|
|
1402
|
+
const credentialless = getCredentialLess(locationHost);
|
|
1403
|
+
await invoke$3('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1404
|
+
const {
|
|
1405
|
+
port1,
|
|
1406
|
+
port2
|
|
1407
|
+
} = getPortTuple();
|
|
1408
|
+
const portId = create$1();
|
|
1409
|
+
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId);
|
|
1410
|
+
await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1411
|
+
|
|
1412
|
+
// TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
|
|
1413
|
+
// and causes flash of unstyled content, maybe a better way would be to just send the
|
|
1414
|
+
// port and wait for the first port message
|
|
1415
|
+
await invoke$1('WebView.load', id);
|
|
1416
|
+
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1417
|
+
const portType = '';
|
|
1418
|
+
await setPort(id, port1, origin, portType);
|
|
1419
|
+
await invokeAndTransfer$1('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
|
|
1420
|
+
const savedState = await getSavedWebViewState(webViewId);
|
|
1421
|
+
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1422
|
+
return {
|
|
1311
1423
|
iframeSrc,
|
|
1312
1424
|
sandbox,
|
|
1313
1425
|
portId,
|
|
@@ -1317,7 +1429,8 @@ const create2 = async ({
|
|
|
1317
1429
|
};
|
|
1318
1430
|
|
|
1319
1431
|
const commandMap = {
|
|
1320
|
-
'WebView.create2': create2
|
|
1432
|
+
'WebView.create2': create2,
|
|
1433
|
+
'WebView.create3': create3
|
|
1321
1434
|
};
|
|
1322
1435
|
|
|
1323
1436
|
const listen = async () => {
|