diff --git a/www/common/common-util.js b/www/common/common-util.js index 3419b5160..22b374ad3 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -616,8 +616,30 @@ getColor().toString(16); }; + /* Chrome 92 dropped support for SharedArrayBuffer in cross-origin contexts + where window.crossOriginIsolated is false. + + Their blog (https://blog.chromium.org/2021/02/restriction-on-sharedarraybuffers.html) + isn't clear about why they're doing this, but since it's related to site-isolation + it seems they're trying to do vague security things. + + In any case, there seems to be a workaround where you can still create them + by using `new WebAssembly.Memory({shared: true, ...})` instead of `new SharedArrayBuffer`. + + This seems unreliable, but it's better than not being able to export, since + we actively rely on postMessage between iframes and therefore can't afford + to opt for full isolation. + */ + var supportsSharedArrayBuffers = function () { + try { + return Object.prototype.toString.call(new window.WebAssembly.Memory({shared: true, initial: 0, maximum: 0}).buffer) === '[object SharedArrayBuffer]'; + } catch (err) { + console.error(err); + } + return false; + }; Util.supportsWasm = function () { - return !(typeof(Atomics) === "undefined" || typeof (SharedArrayBuffer) === "undefined" || typeof(WebAssembly) === 'undefined'); + return !(typeof(Atomics) === "undefined" || !supportsSharedArrayBuffers() || typeof(WebAssembly) === 'undefined'); }; if (typeof(module) !== 'undefined' && module.exports) { diff --git a/www/common/make-backup.js b/www/common/make-backup.js index 4805aaba5..a80663677 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -41,8 +41,8 @@ define([ } var path = '/' + type + '/export.js'; require([path], function (Exporter) { - Exporter.main(json, function (data) { - result.ext = Exporter.ext || ''; + Exporter.main(json, function (data, _ext) { + result.ext = _ext || Exporter.ext || ''; result.data = data; cb(result); }, null, ctx.sframeChan, padData); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 9e31fa998..1ea9f5000 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -74,34 +74,6 @@ define([ return JSONSortify(obj); }; - /* Chrome 92 dropped support for SharedArrayBuffer in cross-origin contexts - where window.crossOriginIsolated is false. - - Their blog (https://blog.chromium.org/2021/02/restriction-on-sharedarraybuffers.html) - isn't clear about why they're doing this, but since it's related to site-isolation - it seems they're trying to do vague security things. - - In any case, there seems to be a workaround where you can still create them - by using `new WebAssembly.Memory({shared: true, ...})` instead of `new SharedArrayBuffer`. - - This seems unreliable, but it's better than not being able to export, since - we actively rely on postMessage between iframes and therefore can't afford - to opt for full isolation. - */ - var supportsSharedArrayBuffers = function () { - try { - return Object.prototype.toString.call(new window.WebAssembly.Memory({shared: true, initial: 0, maximum: 0}).buffer) === '[object SharedArrayBuffer]'; - } catch (err) { - console.error(err); - } - return false; - }; - - var supportsXLSX = function () { - return !(typeof(Atomics) === "undefined" || !supportsSharedArrayBuffers() /* || typeof (SharedArrayBuffer) === "undefined" */ || typeof(WebAssembly) === 'undefined'); - }; - - var toolbar; var cursor; @@ -1553,8 +1525,10 @@ define([ if (APP.isDownload) { var bin = getContent(); + if (!supportsXLSX()) { + return void sframeChan.event('EV_OOIFRAME_DONE', bin, {raw: true}); + } x2tConvertData(bin, 'filename.bin', file.type, function (xlsData) { - var sframeChan = common.getSframeChannel(); sframeChan.event('EV_OOIFRAME_DONE', xlsData, {raw: true}); }); return; diff --git a/www/common/onlyoffice/ooiframe.js b/www/common/onlyoffice/ooiframe.js index 87d5adfed..097d21e5e 100644 --- a/www/common/onlyoffice/ooiframe.js +++ b/www/common/onlyoffice/ooiframe.js @@ -116,6 +116,7 @@ define([ pathname: window.location.pathname, feedbackAllowed: Utils.Feedback.state, secureIframe: true, + supportsWasm: Utils.Util.supportsWasm() }; for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; } diff --git a/www/sheet/export.js b/www/sheet/export.js index 58ef4a712..3d23be19c 100644 --- a/www/sheet/export.js +++ b/www/sheet/export.js @@ -11,8 +11,10 @@ define([], function () { padData: padData }, function (err, u8) { if (!u8) { return void cb(''); } + var ext; + if (typeof(u8) === "string") { ext = '.bin'; } // x2t not supported var blob = new Blob([u8], {type: "application/bin;charset=utf-8"}); - cb(blob); + cb(blob, ext); }, { timeout: 600000, raw: true