Question

I am trying to develop a Firefox extension for the android mobile version of Firefox. My code contains the following snippet:

var target = Cc["@mozilla.org/file/directory_service;1"]
             .getService(Ci.nsIProperties)
             .get("DfltDwnld", Ci.nsIFile);

This works perfectly on the current Firefox on Windows, the Nightlies on Android but not on the current Firefox version on Android. The latter gives the following error:

I/stdout  (17182): ************************************************************
I/stdout  (17182): * Call to xpconnect wrapped JSObject produced this error:  *
I/stdout  (17182): [Exception... "Component returned failure code: 0x80004005 (N
S_ERROR_FAILURE) [nsIProperties.get]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"
  location: "JS frame :: resource://gre/modules/XPIProvider.jsm -> jar:file:///m
nt/sdcard/jetpack-profile/extensions/jid1-deaye7pPKgPbLg@jetpack.xpi!/bootstrap.
js -> resource://gre/modules/commonjs/toolkit/loader.js -> resource://jid1-deaye
7ppkgpblg-at-jetpack/my-addon/lib/main.js :: extractFile :: line 109"  data: no]

I/stdout  (17182): ************************************************************

Similarly, when I try a different was to create the file, I get a similar results:

Code:

Cu.import("resource://gre/modules/FileUtils.jsm");
var target = FileUtils.getFile("DfltDwnld", entryName);

Result:

E/GeckoConsole( 2157): [JavaScript Error: "[Exception... "Component returned fai
lure code: 0x80004005 (NS_ERROR_FAILURE) [nsIProperties.get]"  nsresult: "0x8000
4005 (NS_ERROR_FAILURE)"  location: "JS frame :: resource://gre/modules/FileUtil
s.jsm :: FileUtils_getDir :: line 63"  data: no]" {file: "resource://gre/modules
/FileUtils.jsm" line: 63}]

Any idea what is going on and what I can do? It is as if the script did not have permission to write to the download directory.

Was it helpful?

Solution

DfltDwnld is left out of Fennec's directory provider.

Still, you can get the default directory with the following line

var dDD = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager).defaultDownloadsDirectory;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top