2

Can somebody tell me how to register a Mozilla/Firefox DownloadList view?

This is what I am using:, but it completely breaks the download manager:

const {Cc,Ci,Cu} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm");

let view = {
    onDownloadAdded: download => console.log("Added", download),
    onDownloadChanged: download => console.log("Changed", download),
    onDownloadRemoved: download => console.log("Removed", download),
};

console.log('Test1');
Downloads.getList(Downloads.ALL)
         .then(list => {
             console.log('Test2');
             list.addView(view);
             console.log('Test3');
         });

Unfortunately, after executing this code, downloading seems to be thoroughly broken: it does not even allow downloading any more.

Everything seems to go well:

I/GeckoConsole( 8723): Test1
I/GeckoConsole( 8723): Test2
I/GeckoConsole( 8723): Test3

But I am not seeing the Downloads in the DownloadList which should also have been logged.

When I then try to download another file, I get:

W/GeckoConsole( 8723): [JavaScript Error: "[Exception... "Component returned fai
lure code: 0x80004005 (NS_ERROR_FAILURE) [nsITransfer.init]"  nsresult: "0x80004
005 (NS_ERROR_FAILURE)"  location: "JS frame :: chrome://global/content/contentA
reaUtils.js :: internalPersist :: line 47"  data: no]" {file: "resource://gre/mo
dules/Promise.jsm -> resource://gre/modules/Promise-backend.js" line: 79}]
paa
  • 5,048
  • 1
  • 18
  • 22
ARF
  • 7,420
  • 8
  • 45
  • 72
  • 1
    hmm. Interesting. I tried your code in Desktop Firefox 35 just now and it works (via `cfx run` and installing from an XPI). Seems you're trying that on Android, judging from your console output? – nmaier Jan 26 '15 at 12:56
  • @nmaier Indeed I was developing on Firefox mobile for Android. (Also with cfx run.) – ARF Jan 26 '15 at 15:28
  • Cannot test at the moment, but my guess would be that `console.log(..., download)` is the culprit. I could e.g. imagine it touches some getter property that throws when trying to build the "pretty-print" string of the `download` object. – nmaier Jan 26 '15 at 15:45

0 Answers0