diff options
| author | Xavier Morel <xmo@odoo.com> | 2018-07-12 10:19:37 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2018-07-13 17:31:22 +0200 |
| commit | 35d452cffbb1554c70f0acba85dfc4ef472f544c (patch) | |
| tree | b08e860394367234966e7e99b078370ed2645735 /odoo/modules/loading.py | |
| parent | ccbfa94d32158b8df383df54f3eced38e602e5ef (diff) | |
[IMP] web: replace iframe-based get_file by XHR
The error handling in get_file has always been somewhat problematic
(sarcasm ho!). Pending PR #24854 attempts to add special handling for
gateway timeout aside from its base stuff, and that's really quite
terrible due to get_file's limitation of only being able to read the
content of the document loaded in the iframe (no proper access to status
codes & al).
That was the occasion to look up modern API and see if we could do
file downloads in JS without iframe crap.
Turns out we can: xhr2 is well supported so we can POST, get a blob
back, and create a "local download" for that in-memory blob using either
a[download] (most browsers) or msSaveBlob (IE10+, that's actually a
convenient-to-great API and it's a shame there's nothing like it in the
standard).
The changes are not trivial but save ~30LOC and most of the overhead
is replicating the old/weird error handling as that requires
additionally decoding the blob to a string & parsing that string to
a document before being able to get the content (whereas before we'd
just access to the document loaded in the iframe).
OTOH we can now properly forward non-200 status codes to the
crash manager (as name) which will allow using regular CM hooks to
provide custom warning and error messages.
Note that this requires two libraries:
* a stripped down version of the content-disposition NPM lib, as
download file names are provided via that header and parsing the
header is decidedly non-trivial
* the download.js library as it handles the various edge cases from
different browsers, I'm don't think all of it is necessary for our
use case but the library is not that big so no real point in trying
to strip it out and potentially break it in the process
Diffstat (limited to 'odoo/modules/loading.py')
0 files changed, 0 insertions, 0 deletions
