Download sheets as .bin when x2t is not available

This commit is contained in:
yflory 2021-08-18 12:29:36 +02:00
parent ab62b5f202
commit d6983a8b83
5 changed files with 32 additions and 33 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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]; }

View File

@ -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