@lvce-editor/iframe-worker 5.5.0 → 5.7.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 +115 -3
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -1108,9 +1108,13 @@ const getWebViewOrigin = (webViewPort, platform, webViewScheme, webViewId) => {
|
|
|
1108
1108
|
}
|
|
1109
1109
|
};
|
|
1110
1110
|
|
|
1111
|
+
const CrossOriginIsolated = 'cross-origin-isolated';
|
|
1111
1112
|
const getIframePermissionPolicy = webView => {
|
|
1112
1113
|
const extensionAllow = webView.allow || [];
|
|
1113
|
-
|
|
1114
|
+
if (extensionAllow.includes(CrossOriginIsolated)) {
|
|
1115
|
+
return extensionAllow;
|
|
1116
|
+
}
|
|
1117
|
+
return [CrossOriginIsolated, ...extensionAllow];
|
|
1114
1118
|
};
|
|
1115
1119
|
|
|
1116
1120
|
const getWebViews = async () => {
|
|
@@ -1158,6 +1162,9 @@ const getHost = () => {
|
|
|
1158
1162
|
const getProtocol = () => {
|
|
1159
1163
|
return location.protocol;
|
|
1160
1164
|
};
|
|
1165
|
+
const getPort = () => {
|
|
1166
|
+
return location.port;
|
|
1167
|
+
};
|
|
1161
1168
|
|
|
1162
1169
|
const invoke$1 = async (method, ...params) => {
|
|
1163
1170
|
return invoke$3('WebView.compatRendererProcessInvoke', method, ...params);
|
|
@@ -1299,7 +1306,111 @@ const create2 = async ({
|
|
|
1299
1306
|
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1300
1307
|
const portType = '';
|
|
1301
1308
|
await setPort(id, port1, origin, portType);
|
|
1302
|
-
await invokeAndTransfer$1('ExtensionHostWebView.create', webViewId, port2, uri, id, origin);
|
|
1309
|
+
await invokeAndTransfer$1('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
|
|
1310
|
+
const savedState = await getSavedWebViewState(webViewId);
|
|
1311
|
+
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1312
|
+
return {
|
|
1313
|
+
srcDoc,
|
|
1314
|
+
iframeSrc,
|
|
1315
|
+
sandbox,
|
|
1316
|
+
portId,
|
|
1317
|
+
origin,
|
|
1318
|
+
csp: iframeCsp
|
|
1319
|
+
};
|
|
1320
|
+
};
|
|
1321
|
+
|
|
1322
|
+
const getPreviewServerId = () => {
|
|
1323
|
+
// TODO
|
|
1324
|
+
return 1;
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
const getWebViewId = (webViews, uri) => {
|
|
1328
|
+
if (uri.startsWith('webview://')) {
|
|
1329
|
+
const webViewId = uri.slice('webview://'.length);
|
|
1330
|
+
return webViewId;
|
|
1331
|
+
}
|
|
1332
|
+
for (const webView of webViews) {
|
|
1333
|
+
for (const selector of webView.selector || []) {
|
|
1334
|
+
if (uri.endsWith(selector)) {
|
|
1335
|
+
return webView.id;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
return '';
|
|
1340
|
+
};
|
|
1341
|
+
|
|
1342
|
+
const getWebViewPort = (platform, locationPort) => {
|
|
1343
|
+
if (platform === Web) {
|
|
1344
|
+
return locationPort;
|
|
1345
|
+
}
|
|
1346
|
+
// TODO make port configurable
|
|
1347
|
+
return '3002';
|
|
1348
|
+
};
|
|
1349
|
+
|
|
1350
|
+
const create3 = async ({
|
|
1351
|
+
id,
|
|
1352
|
+
uri,
|
|
1353
|
+
isGitpod,
|
|
1354
|
+
platform,
|
|
1355
|
+
assetDir,
|
|
1356
|
+
webViewScheme
|
|
1357
|
+
}) => {
|
|
1358
|
+
let root = '';
|
|
1359
|
+
if (platform === Remote) {
|
|
1360
|
+
root = await invoke('Platform.getRoot');
|
|
1361
|
+
}
|
|
1362
|
+
const webViews = await getWebViews();
|
|
1363
|
+
const webViewId = getWebViewId(webViews, uri);
|
|
1364
|
+
const locationProtocol = getProtocol();
|
|
1365
|
+
const locationHost = getHost();
|
|
1366
|
+
const locationOrigin = getOrigin();
|
|
1367
|
+
const locationPort = getPort();
|
|
1368
|
+
const webViewPort = getWebViewPort(platform, locationPort);
|
|
1369
|
+
const previewServerId = getPreviewServerId();
|
|
1370
|
+
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir, webViewScheme);
|
|
1371
|
+
if (!iframeResult) {
|
|
1372
|
+
return undefined;
|
|
1373
|
+
}
|
|
1374
|
+
const webView = getWebView(webViews, webViewId);
|
|
1375
|
+
|
|
1376
|
+
// TODO move all of this to iframe worker
|
|
1377
|
+
const {
|
|
1378
|
+
iframeSrc,
|
|
1379
|
+
webViewRoot,
|
|
1380
|
+
srcDoc,
|
|
1381
|
+
iframeContent
|
|
1382
|
+
} = iframeResult;
|
|
1383
|
+
const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
|
|
1384
|
+
const frameTitle = getWebViewTitle(webView);
|
|
1385
|
+
// TODO figure out order for events, e.g.
|
|
1386
|
+
// 1. activate extension, create webview and ports in parallel
|
|
1387
|
+
// 2. wait for webview to load (?)
|
|
1388
|
+
// 3. setup extension host worker rpc
|
|
1389
|
+
// 4. create webview in extension host worker and load content
|
|
1390
|
+
|
|
1391
|
+
const csp = getWebViewCsp(webView);
|
|
1392
|
+
const sandbox = getIframeSandbox(webView, platform);
|
|
1393
|
+
const permissionPolicy = getIframePermissionPolicy(webView);
|
|
1394
|
+
const permissionPolicyString = permissionPolicy.join('; ');
|
|
1395
|
+
const iframeCsp = platform === Web ? csp : '';
|
|
1396
|
+
const credentialless = getCredentialLess(locationHost);
|
|
1397
|
+
await invoke$3('ExtensionHostManagement.activateByEvent', `onWebView:${webViewId}`);
|
|
1398
|
+
const {
|
|
1399
|
+
port1,
|
|
1400
|
+
port2
|
|
1401
|
+
} = getPortTuple();
|
|
1402
|
+
const portId = create$1();
|
|
1403
|
+
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform, webViewId);
|
|
1404
|
+
await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1405
|
+
|
|
1406
|
+
// TODO maybe iframe waitForLoad is not needed. since it cannot be used detect errors anyway
|
|
1407
|
+
// and causes flash of unstyled content, maybe a better way would be to just send the
|
|
1408
|
+
// port and wait for the first port message
|
|
1409
|
+
await invoke$1('WebView.load', id);
|
|
1410
|
+
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme, webViewId);
|
|
1411
|
+
const portType = '';
|
|
1412
|
+
await setPort(id, port1, origin, portType);
|
|
1413
|
+
await invokeAndTransfer$1('ExtensionHostWebView.create', webViewId, port2, uri, id, origin, webView);
|
|
1303
1414
|
const savedState = await getSavedWebViewState(webViewId);
|
|
1304
1415
|
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1305
1416
|
return {
|
|
@@ -1313,7 +1424,8 @@ const create2 = async ({
|
|
|
1313
1424
|
};
|
|
1314
1425
|
|
|
1315
1426
|
const commandMap = {
|
|
1316
|
-
'WebView.create2': create2
|
|
1427
|
+
'WebView.create2': create2,
|
|
1428
|
+
'WebView.create3': create3
|
|
1317
1429
|
};
|
|
1318
1430
|
|
|
1319
1431
|
const listen = async () => {
|