Download sheets as .bin when x2t is not available

pull/1/head
yflory 3 years ago
parent ab62b5f202
commit d6983a8b83

@ -616,8 +616,30 @@
getColor().toString(16); 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 () { 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) { if (typeof(module) !== 'undefined' && module.exports) {

@ -41,8 +41,8 @@ define([
} }
var path = '/' + type + '/export.js'; var path = '/' + type + '/export.js';
require([path], function (Exporter) { require([path], function (Exporter) {
Exporter.main(json, function (data) { Exporter.main(json, function (data, _ext) {
result.ext = Exporter.ext || ''; result.ext = _ext || Exporter.ext || '';
result.data = data; result.data = data;
cb(result); cb(result);
}, null, ctx.sframeChan, padData); }, null, ctx.sframeChan, padData);

@ -74,34 +74,6 @@ define([
return JSONSortify(obj); 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 toolbar;
var cursor; var cursor;
@ -1553,8 +1525,10 @@ define([
if (APP.isDownload) { if (APP.isDownload) {
var bin = getContent(); var bin = getContent();
if (!supportsXLSX()) {
return void sframeChan.event('EV_OOIFRAME_DONE', bin, {raw: true});
}
x2tConvertData(bin, 'filename.bin', file.type, function (xlsData) { x2tConvertData(bin, 'filename.bin', file.type, function (xlsData) {
var sframeChan = common.getSframeChannel();
sframeChan.event('EV_OOIFRAME_DONE', xlsData, {raw: true}); sframeChan.event('EV_OOIFRAME_DONE', xlsData, {raw: true});
}); });
return; return;

@ -116,6 +116,7 @@ define([
pathname: window.location.pathname, pathname: window.location.pathname,
feedbackAllowed: Utils.Feedback.state, feedbackAllowed: Utils.Feedback.state,
secureIframe: true, secureIframe: true,
supportsWasm: Utils.Util.supportsWasm()
}; };
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; } for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }

@ -11,8 +11,10 @@ define([], function () {
padData: padData padData: padData
}, function (err, u8) { }, function (err, u8) {
if (!u8) { return void cb(''); } 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"}); var blob = new Blob([u8], {type: "application/bin;charset=utf-8"});
cb(blob); cb(blob, ext);
}, { }, {
timeout: 600000, timeout: 600000,
raw: true raw: true

Loading…
Cancel
Save