@lvce-editor/iframe-worker 4.0.0 → 5.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 +39 -24
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -948,9 +948,7 @@ const getWebViewUri = (webViews, webViewId) => {
|
|
|
948
948
|
return webViewPath;
|
|
949
949
|
};
|
|
950
950
|
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform, assetDir) => {
|
|
951
|
+
const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform$1 = platform, assetDir, webViewScheme) => {
|
|
954
952
|
const webView = getWebView(webViews, webViewId);
|
|
955
953
|
const webViewUri = getWebViewUri(webViews, webViewId);
|
|
956
954
|
if (!webViewUri) {
|
|
@@ -959,23 +957,18 @@ const getIframeSrcRemote = (webViews, webViewPort, webViewId, locationProtocol,
|
|
|
959
957
|
let iframeSrc = webViewUri;
|
|
960
958
|
let webViewRoot = webViewUri;
|
|
961
959
|
|
|
962
|
-
// TODO
|
|
963
|
-
|
|
960
|
+
// TODO when running in remote, try scope webviews by path or if possible by domain
|
|
964
961
|
if (platform$1 === Electron) {
|
|
965
|
-
const
|
|
966
|
-
iframeSrc = `${
|
|
967
|
-
// TODO
|
|
962
|
+
const webViewId = webView.id;
|
|
963
|
+
iframeSrc = `${webViewScheme}://${webViewId}/`;
|
|
968
964
|
} else if (platform$1 === Remote) {
|
|
969
965
|
webViewRoot = webView.uri;
|
|
970
966
|
iframeSrc = createLocalHostUrl(locationProtocol, locationHost, isGitpod, webViewPort);
|
|
971
967
|
}
|
|
972
|
-
|
|
968
|
+
const iframeContent = getWebViewHtml('', '', webView.elements, assetDir);
|
|
973
969
|
// TODO either
|
|
974
970
|
// - load webviews the same as in web using blob urls
|
|
975
971
|
// - load webviews from a pattern like /webviews/:id/:fileName
|
|
976
|
-
if (!webView.path) {
|
|
977
|
-
iframeContent = iframeContent.replaceAll('/media/', '/').replaceAll('//', '/');
|
|
978
|
-
}
|
|
979
972
|
return {
|
|
980
973
|
srcDoc: '',
|
|
981
974
|
iframeSrc,
|
|
@@ -1034,13 +1027,13 @@ const getIframeSrc$1 = (webView, locationOrigin, assetDir) => {
|
|
|
1034
1027
|
return undefined;
|
|
1035
1028
|
};
|
|
1036
1029
|
|
|
1037
|
-
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir) => {
|
|
1030
|
+
const getIframeSrc = (webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir, webViewScheme) => {
|
|
1038
1031
|
try {
|
|
1039
1032
|
const webView = getWebView(webViews, webViewId);
|
|
1040
1033
|
if (platform === Web) {
|
|
1041
1034
|
return getIframeSrc$1(webView, locationOrigin, assetDir);
|
|
1042
1035
|
}
|
|
1043
|
-
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform, assetDir);
|
|
1036
|
+
return getIframeSrcRemote(webViews, webViewPort, webViewId, locationProtocol, locationHost, isGitpod, root, platform, assetDir, webViewScheme);
|
|
1044
1037
|
} catch (error) {
|
|
1045
1038
|
throw new VError(error, `Failed to construct webview iframe src`);
|
|
1046
1039
|
}
|
|
@@ -1101,11 +1094,11 @@ const getWebViewFrameAncestors = (locationProtocol, locationHost) => {
|
|
|
1101
1094
|
return frameAncestors;
|
|
1102
1095
|
};
|
|
1103
1096
|
|
|
1104
|
-
const getWebViewOrigin = (webViewPort, platform) => {
|
|
1097
|
+
const getWebViewOrigin = (webViewPort, platform, webViewScheme) => {
|
|
1105
1098
|
// TODO don't hardcode protocol
|
|
1106
1099
|
let origin = '';
|
|
1107
1100
|
if (platform === Electron) {
|
|
1108
|
-
origin = `${
|
|
1101
|
+
origin = `${webViewScheme}://-/`;
|
|
1109
1102
|
} else if (platform === Remote) {
|
|
1110
1103
|
origin = `http://localhost:${webViewPort}`;
|
|
1111
1104
|
} else {
|
|
@@ -1137,6 +1130,17 @@ const getIframeSandbox = (webView, platform) => {
|
|
|
1137
1130
|
return [AllowScripts, AllowSameOrigin, ...extensionSandbox];
|
|
1138
1131
|
};
|
|
1139
1132
|
|
|
1133
|
+
const getWebViewTitle = webView => {
|
|
1134
|
+
if (webView && webView.elements && Array.isArray(webView.elements)) {
|
|
1135
|
+
for (const item of webView.elements) {
|
|
1136
|
+
if (item && item.type === 'title' && typeof item.value === 'string') {
|
|
1137
|
+
return item.value;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
return 'WebView';
|
|
1142
|
+
};
|
|
1143
|
+
|
|
1140
1144
|
const state = {
|
|
1141
1145
|
id: 0
|
|
1142
1146
|
};
|
|
@@ -1161,6 +1165,8 @@ const invokeAndTransfer = async (method, ...params) => {
|
|
|
1161
1165
|
return invokeAndTransfer$2('WebView.compatRendererProcessInvokeAndTransfer', method, ...params);
|
|
1162
1166
|
};
|
|
1163
1167
|
|
|
1168
|
+
const WebView = 'lvce-oss-webview';
|
|
1169
|
+
|
|
1164
1170
|
const setPort = async (uid, port, origin, portType) => {
|
|
1165
1171
|
await invokeAndTransfer('WebView.setPort', uid, port, origin, portType);
|
|
1166
1172
|
};
|
|
@@ -1182,9 +1188,17 @@ const setHandler = async (previewServerId, frameAncestors, webViewRoot, contentS
|
|
|
1182
1188
|
await invoke('WebViewServer.setHandler', previewServerId, frameAncestors, webViewRoot, contentSecurityPolicy, iframeContent);
|
|
1183
1189
|
};
|
|
1184
1190
|
|
|
1185
|
-
const register$3 = async previewServerId => {
|
|
1191
|
+
const register$3 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
|
|
1186
1192
|
await registerProtocol();
|
|
1187
1193
|
await create(previewServerId); // TODO move this up
|
|
1194
|
+
|
|
1195
|
+
// TODO send info to electron which domain maps to which webview root.
|
|
1196
|
+
// for example, video-preview maps to domain lvce-oss-webview://video-preview
|
|
1197
|
+
// and webview root /home/user/lvce/extensions/video-preview
|
|
1198
|
+
// Then the request handler can decide by domain which webview root to use.
|
|
1199
|
+
// Another option would be in electron to check what iframe (webContents)
|
|
1200
|
+
// responds to which webviewRoot and setting a webviewRoot per webContents instance
|
|
1201
|
+
// await WebViewServer.setInfo(previewServerId)
|
|
1188
1202
|
};
|
|
1189
1203
|
|
|
1190
1204
|
const register$2 = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
|
|
@@ -1214,7 +1228,7 @@ const getModule = platform => {
|
|
|
1214
1228
|
}
|
|
1215
1229
|
};
|
|
1216
1230
|
|
|
1217
|
-
const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent) => {
|
|
1231
|
+
const register = async (previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform) => {
|
|
1218
1232
|
const fn = getModule(platform);
|
|
1219
1233
|
return fn(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
|
|
1220
1234
|
};
|
|
@@ -1227,7 +1241,8 @@ const create2 = async ({
|
|
|
1227
1241
|
uri,
|
|
1228
1242
|
platform,
|
|
1229
1243
|
isGitpod,
|
|
1230
|
-
assetDir: assetDir$1 = assetDir
|
|
1244
|
+
assetDir: assetDir$1 = assetDir,
|
|
1245
|
+
webViewScheme = WebView
|
|
1231
1246
|
}) => {
|
|
1232
1247
|
let root = '';
|
|
1233
1248
|
if (platform === Remote) {
|
|
@@ -1237,7 +1252,7 @@ const create2 = async ({
|
|
|
1237
1252
|
const locationProtocol = getProtocol();
|
|
1238
1253
|
const locationHost = getHost();
|
|
1239
1254
|
const locationOrigin = getOrigin();
|
|
1240
|
-
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir$1);
|
|
1255
|
+
const iframeResult = getIframeSrc(webViews, webViewId, webViewPort, root, isGitpod, locationProtocol, locationHost, locationOrigin, platform, assetDir$1, webViewScheme);
|
|
1241
1256
|
if (!iframeResult) {
|
|
1242
1257
|
return undefined;
|
|
1243
1258
|
}
|
|
@@ -1251,7 +1266,7 @@ const create2 = async ({
|
|
|
1251
1266
|
iframeContent
|
|
1252
1267
|
} = iframeResult;
|
|
1253
1268
|
const frameAncestors = getWebViewFrameAncestors(locationProtocol, locationHost);
|
|
1254
|
-
|
|
1269
|
+
const frameTitle = getWebViewTitle(webView);
|
|
1255
1270
|
// TODO figure out order for events, e.g.
|
|
1256
1271
|
// 1. activate extension, create webview and ports in parallel
|
|
1257
1272
|
// 2. wait for webview to load (?)
|
|
@@ -1270,10 +1285,10 @@ const create2 = async ({
|
|
|
1270
1285
|
port2
|
|
1271
1286
|
} = getPortTuple();
|
|
1272
1287
|
const portId = create$1();
|
|
1273
|
-
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent);
|
|
1274
|
-
await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString);
|
|
1288
|
+
await register(previewServerId, webViewPort, frameAncestors, webViewRoot, csp, iframeContent, platform);
|
|
1289
|
+
await invoke$1('WebView.create', id, iframeSrc, sandbox, iframeCsp, credentialless, permissionPolicyString, frameTitle);
|
|
1275
1290
|
await invoke$1('WebView.load', id);
|
|
1276
|
-
const origin = getWebViewOrigin(webViewPort, platform);
|
|
1291
|
+
const origin = getWebViewOrigin(webViewPort, platform, webViewScheme);
|
|
1277
1292
|
const portType = '';
|
|
1278
1293
|
await setPort(id, port1, origin, portType);
|
|
1279
1294
|
await invokeAndTransfer$1('ExtensionHostWebView.create', webViewId, port2, uri, id, origin);
|