1

I am a new user of Firefox's plugin system. I wanted to create a plugin that will download multiple files in a que, and then open them for practice.

My question is if there is a way to download a file from the Internet in the plugin. I am aware of os.file's existence (though it is not easy for me to understand how to use it from the examples provided). Next I would like to know if there is a way to execute the file using the default program for it.

Makyen
  • 31,849
  • 12
  • 86
  • 121
Aurora
  • 13
  • 4
  • Good practice for a first addon. So to start enable developer preferences : https://developer.mozilla.org/en-US/Add-ons/Setting_up_extension_development_environment?redirectlocale=en-US&redirectslug=Setting_up_extension_development_environment#Development_preferences then open the scratchpad with Shift + F4 and then set Environment menu to Browser. Now you can run code in the privelaged scope. Then start pasting examples from MDN like from here: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm#Examples – Noitidart Dec 26 '14 at 21:08

1 Answers1

1

As of Firefox 26, in Add-on SDK, restartless/bootstrap, or overlay based extensions, the most appropriate way to download a file from within an add-on is to use the Downloads.jsm JavaScript code module.

Downloading to a local file example from MDN Downloads.jsm page:

Components.utils.import("resource://gre/modules/Downloads.jsm");
Components.utils.import("resource://gre/modules/osfile.jsm")
Components.utils.import("resource://gre/modules/Task.jsm");

Task.spawn(function () {
  yield Downloads.fetch("http://www.mozilla.org/",
                        OS.Path.join(OS.Constants.Path.tmpDir,
                                     "example-download.html"));
  console.log("example-download.html has been downloaded.");
}).then(null, Components.utils.reportError);

If you want to initiate a download exactly as if the user had initiated it, then you should see my answer to How to launch a normal download from an addon.

Community
  • 1
  • 1
Makyen
  • 31,849
  • 12
  • 86
  • 121