aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJagua2015-02-16 00:21:12 +0900
committerJagua2015-02-16 00:21:12 +0900
commit0e98b023e7cd0448a2ad4134dd0c382d76c85cf1 (patch)
tree9d420d7c7ce5343fcaff2e2a9e38ed54aadbd0ce
parentba6103661a2807c0e615e28a4566fb27537debd3 (diff)
downloadvimperator-plugins-0e98b023e7cd0448a2ad4134dd0c382d76c85cf1.tar.bz2
don't use nsIDownloadManager. (use Downloads.jsm)
-rw-r--r--stella.js19
1 files changed, 10 insertions, 9 deletions
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;
},