www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 2b00a53e0211370d81bac66b1e0211d00e6fb0b6
parent 3ff6626c12ea9b9ddfcef31c9a28e4f8e03a2b20
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu, 29 Oct 2015 02:42:44 -0400

Accept headers and string path in Zotero.Utilities.Internal.saveURI()

Diffstat:
Mchrome/content/zotero/xpcom/utilities_internal.js | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js @@ -307,21 +307,25 @@ Zotero.Utilities.Internal = { /** * saveURI wrapper function * @param {nsIWebBrowserPersist} nsIWebBrowserPersist - * @param {nsIURI} source URL - * @param {nsISupports} target file + * @param {nsIURI} uri URL + * @param {nsIFile|string path} target file + * @param {Object} [headers] */ - saveURI: function (wbp, source, target) { + saveURI: function (wbp, uri, target, headers) { // Handle gzip encoding wbp.persistFlags |= Ci.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION; - // Firefox 35 and below - try { - wbp.saveURI(source, null, null, null, null, target, null); + if (typeof uri == 'string') { + uri = Services.io.newURI(uri, null, null); } - // Firefox 36+ needs one more parameter - catch (e if e.name === "NS_ERROR_XPC_NOT_ENOUGH_ARGS") { - wbp.saveURI(source, null, null, null, null, null, target, null); + + target = Zotero.File.pathToFile(target); + + if (headers) { + headers = Object.keys(headers).map(x => x + ": " + headers[x]).join("\r\n") + "\r\n"; } + + wbp.saveURI(uri, null, null, null, null, headers, target, null); },