From 0e98b023e7cd0448a2ad4134dd0c382d76c85cf1 Mon Sep 17 00:00:00 2001 From: Jagua Date: Mon, 16 Feb 2015 00:21:12 +0900 Subject: don't use nsIDownloadManager. (use Downloads.jsm) --- stella.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'stella.js') diff --git a/stella.js b/stella.js index c041e5e..bb81b9c 100644 --- a/stella.js +++ b/stella.js @@ -313,14 +313,12 @@ Thanks: return mis; } - let dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager); - let wbp = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist); let file; if (filepath) { file = io.File(io.expandPath(filepath)); } else { - file = dm.userDownloadsDirectory; + file = io.File(FileUtils.getDir("DfltDwnld", [""])); } if (file.exists() && file.isDirectory() && title) @@ -329,12 +327,15 @@ Thanks: if (file.exists()) return U.echoError('The file already exists! -> ' + file.path); - file = makeFileURI(file); - - let dl = dm.addDownload(0, U.makeURL(url, null, null), file, title, null, null, null, null, wbp); - wbp.progressListener = dl; - wbp.persistFlags |= wbp.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION; - wbp.saveURI(U.makeURL(url), null, null, postData && makePostStream(postData), null, file); + Task.spawn(function () { + if (postData) { + yield U.httpRequest(url, postData, function (xhr) { + file.write(xhr.response); + }); + } else { + yield Downloads.fetch(url, file); + } + }).then(null, Cu.reportError); return file; }, -- cgit v1.2.3