@lvce-editor/iframe-worker 5.6.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 +109 -1
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -1162,6 +1162,9 @@ const getHost = () => {
|
|
|
1162
1162
|
const getProtocol = () => {
|
|
1163
1163
|
return location.protocol;
|
|
1164
1164
|
};
|
|
1165
|
+
const getPort = () => {
|
|
1166
|
+
return location.port;
|
|
1167
|
+
};
|
|
1165
1168
|
|
|
1166
1169
|
const invoke$1 = async (method, ...params) => {
|
|
1167
1170
|
return invoke$3('WebView.compatRendererProcessInvoke', method, ...params);
|
|
@@ -1316,8 +1319,113 @@ const create2 = async ({
|
|
|
1316
1319
|
};
|
|
1317
1320
|
};
|
|
1318
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);
|
|
1414
|
+
const savedState = await getSavedWebViewState(webViewId);
|
|
1415
|
+
await invoke$2('ExtensionHostWebView.load', webViewId, savedState);
|
|
1416
|
+
return {
|
|
1417
|
+
srcDoc,
|
|
1418
|
+
iframeSrc,
|
|
1419
|
+
sandbox,
|
|
1420
|
+
portId,
|
|
1421
|
+
origin,
|
|
1422
|
+
csp: iframeCsp
|
|
1423
|
+
};
|
|
1424
|
+
};
|
|
1425
|
+
|
|
1319
1426
|
const commandMap = {
|
|
1320
|
-
'WebView.create2': create2
|
|
1427
|
+
'WebView.create2': create2,
|
|
1428
|
+
'WebView.create3': create3
|
|
1321
1429
|
};
|
|
1322
1430
|
|
|
1323
1431
|
const listen = async () => {
|