Skip to content

Commit a607d36

Browse files
committed
fix: issue 901
1 parent e110046 commit a607d36

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

common/content/io.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ const IO = Module("io", {
333333
// XXX: nsIDownloadManager is deprecated on Firefox 26
334334
// FIXME: need to listen to download state ? -- teramako
335335
// FIXME: need to adapt to Download.jsm instead of nsIDownloadManager
336-
try {
336+
if (services.get("vc").compare(Application.version, "26.0a1") < 0) {
337337
this.downloadListener = {
338338
onDownloadStateChange: function (state, download) {
339339
if (download.state == services.get("downloads").DOWNLOAD_FINISHED) {
@@ -351,13 +351,50 @@ const IO = Module("io", {
351351
onSecurityChange: function () {}
352352
};
353353
services.get("downloads").addListener(this.downloadListener);
354-
} catch (e) {
355-
Cu.reportError(e);
354+
} else {
355+
let downloadListener = this.downloadListener = {
356+
onDownloadChanged: function (download) {
357+
if (download.succeeded) {
358+
let {
359+
source: { url },
360+
target: {path: file},
361+
totalBytes: size,
362+
} = download;
363+
let title = File(file).leafName;
364+
liberator.echomsg("Download of " + title + " to " + file + " finished");
365+
autocommands.trigger("DownloadPost", { url: url, title: title, file: file, size: size });
366+
}
367+
},
368+
};
369+
let {Downloads} = Cu.import("resource://gre/modules/Downloads.jsm", {});
370+
//let listName = (window.QueryInterface(Ci.nsIInterfaceRequestor)
371+
// .getInterface(Ci.nsIWebNavigation)
372+
// .QueryInterface(Ci.nsILoadContext)
373+
// .usePrivateBrowsing)
374+
// ? "getPrivateDownloadList"
375+
// : "getPublicDownloadList";
376+
for (let listName of ["getPrivateDownloadList", "getPublicDownloadList"]) {
377+
Downloads[listName]()
378+
.then(function (downloadList) {
379+
downloadList.addView(downloadListener);
380+
});
381+
}
356382
}
357383
},
358384

359385
destroy: function () {
360-
services.get("downloads").removeListener(this.downloadListener);
386+
if (services.get("vc").compare(Application.version, "26.0a1") < 0) {
387+
services.get("downloads").removeListener(this.downloadListener);
388+
} else {
389+
let {Downloads} = Cu.import("resource://gre/modules/Downloads.jsm", {});
390+
let downloadListener = this.downloadListener;
391+
for (let listName of ["getPrivateDownloadList", "getPublicDownloadList"]) {
392+
Downloads[listName]()
393+
.then(function (downloadList) {
394+
downloadList.removeView(downloadListener);
395+
});
396+
}
397+
}
361398
for (let [, plugin] in Iterator(plugins.contexts))
362399
if (plugin.onUnload)
363400
plugin.onUnload();

0 commit comments

Comments
 (0)