2

I would like to do the following from my firefox addon:

a). Determine my addons folder location.

b). Prompt the user to initiate a download.

c). Download and save the download

All the code examples available are for older API's and I have no clue on how to get them working for recent E10 (multi-process) code changes.

Stacked
  • 841
  • 2
  • 12
  • 23

1 Answers1

2

A - Get addons folder location

var OSPath_addons = Services.dirsvc.get('XREUSysExt', Ci.nsIFile).path

B - Trigger download with path with no user notification

How to download image to desktop with OS.File

With user notification:

https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Downloads.jsm#createDownload%28%29

Community
  • 1
  • 1
Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • Great, how to initiate this from a "content script"? The addon has bootstrap.js, overlay.js and content.js. – Stacked Aug 13 '15 at 10:56
  • @Stacked Do `var {Cc, Cu, Ci} = require('chrome')` then you can access all that `Cu` stuff. Start by importnat Services.jsm: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm?redirectlocale=en-US&redirectslug=JavaScript_code_modules%2FServices.jsm – Noitidart Aug 14 '15 at 02:16
  • I meant to access/initiate the download from a user-script (loaded for a particular website only) after prompting the user to get the optional download in a injected iframe inside the webpage, I am sure `CU` won't work from there. I wanted to know how to call the function to start the download from the content-script? – Stacked Aug 15 '15 at 09:36
  • @Stacked you have to port.emit to you main.js script and he iwll have to do the download. https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/using_port#port.emit%28%29 – Noitidart Aug 15 '15 at 13:56