From 2abe187f67b07f6e0328ab3dbacb24e1b9119b05 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 19 Oct 2021 13:23:08 +0200 Subject: [PATCH] Run x2t in an iframe --- www/common/onlyoffice/main.js | 11 +-- www/common/onlyoffice/ooiframe.js | 11 +-- www/common/sframe-common-outer.js | 25 +++++- www/convert/main.js | 11 +-- www/unsafeiframe/inner.html | 13 +++ www/unsafeiframe/inner.js | 79 ++++++++++++++++++ www/unsafeiframe/main.js | 134 ++++++++++++++++++++++++++++++ 7 files changed, 256 insertions(+), 28 deletions(-) create mode 100644 www/unsafeiframe/inner.html create mode 100644 www/unsafeiframe/inner.js create mode 100644 www/unsafeiframe/main.js diff --git a/www/common/onlyoffice/main.js b/www/common/onlyoffice/main.js index 8b79474ae..6a7d81a4b 100644 --- a/www/common/onlyoffice/main.js +++ b/www/common/onlyoffice/main.js @@ -145,16 +145,9 @@ define([ }); // X2T - var x2t; - var onConvert = function (obj, cb) { - x2t.convert(obj, cb); - }; sframeChan.on('Q_OO_CONVERT', function (obj, cb) { - if (x2t) { return void onConvert(obj, cb); } - require(['/common/outer/x2t.js'], function (X2T) { - x2t = X2T.start(); - onConvert(obj, cb); - }); + obj.modal = 'x2t'; + Utils.initUnsafeIframe(obj, cb); }); diff --git a/www/common/onlyoffice/ooiframe.js b/www/common/onlyoffice/ooiframe.js index 097d21e5e..23c6424e3 100644 --- a/www/common/onlyoffice/ooiframe.js +++ b/www/common/onlyoffice/ooiframe.js @@ -145,16 +145,9 @@ define([ }); // X2T - var x2t; - var onConvert = function (obj, cb) { - x2t.convert(obj, cb); - }; sframeChan.on('Q_OO_CONVERT', function (obj, cb) { - if (x2t) { return void onConvert(obj, cb); } - require(['/common/outer/x2t.js'], function (X2T) { - x2t = X2T.start(); - onConvert(obj, cb); - }); + obj.modal = 'x2t'; + Utils.initUnsafeIframe(obj, cb); }); sframeChan.onReady(function () { diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 3139aa4f0..95b6c52b9 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -72,6 +72,7 @@ define([ var SFrameChannel; var sframeChan; var SecureIframe; + var UnsafeIframe; var OOIframe; var Messaging; var Notifier; @@ -99,6 +100,7 @@ define([ '/common/cryptget.js', '/common/outer/worker-channel.js', '/secureiframe/main.js', + '/unsafeiframe/main.js', '/common/onlyoffice/ooiframe.js', '/common/common-messaging.js', '/common/common-notifier.js', @@ -114,7 +116,7 @@ define([ '/common/test.js', '/common/userObject.js', ], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel, - _SecureIframe, _OOIframe, _Messaging, _Notifier, _Hash, _Util, _Realtime, _Notify, + _SecureIframe, _UnsafeIframe, _OOIframe, _Messaging, _Notifier, _Hash, _Util, _Realtime, _Notify, _Constants, _Feedback, _LocalStore, _Cache, _AppConfig, _Test, _UserObject) { CpNfOuter = _CpNfOuter; Cryptpad = _Cryptpad; @@ -122,6 +124,7 @@ define([ Cryptget = _Cryptget; SFrameChannel = _SFrameChannel; SecureIframe = _SecureIframe; + UnsafeIframe = _UnsafeIframe; OOIframe = _OOIframe; Messaging = _Messaging; Notifier = _Notifier; @@ -1503,6 +1506,26 @@ define([ initSecureModal('share', data || {}); }); + // Unsafe iframe + var UnsafeObject = {}; + Utils.initUnsafeIframe = function (cfg, cb) { + if (!UnsafeObject.$iframe) { + var config = {}; + config.addCommonRpc = addCommonRpc; + config.modules = { + Cryptpad: Cryptpad, + SFrameChannel: SFrameChannel, + Utils: Utils + }; + UnsafeObject.$iframe = $('