Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

downloadManager

This class simplifies the access of the Download Manager window for Firefox.

Method overview

downloadManager();
cancelActiveDownloads();
cleanAll();
cleanUp();
close(in boolean force);
deleteDownloadedFiles(in array nsIDownload downloads);
array nsIDownload getAllDownloads();
downloadState getDownloadState(in ElemBase download);
ElemBase getElement(in object spec);
open(in MozMillController controller, in boolean shortcut);
waitForDownloadState(in ElemBase download, in downloadState state, in number timeout);
waitForOpened(in MozMillController controller);

Attributes

Attribute Type Description
controller MozMillController Controller of the current Download Manager window
activeDownloadCount number Count of currently active downloads.

Methods

downloadManager()

The constructor of the class.

downloadManager();

cancelActiveDownloads()

Cancel all active downloads.

cancelActiveDownloads();

cleanAll()

Cancels any active downloads, removes any downloaded files, and cleans up the Download Manager database.

cleanAll();

cleanUp()

Remove all downloads from the database.

cleanUp();

close()

Close the Download Manager window.

close(in boolean force);
Parameters
force
Force the closing of the DM window. When set to true the window will be closed by calling window.close().

deleteDownloadedFiles()

Delete all the downloaded files from the local drive.

deleteDownloadedFiles(
in array
nsIDownload downloads
);
Parameters
downloads
List of nsIDownload instances which specify the to be removed downloads.

getAllDownloads()

Get the list of all downloaded files from the sqlite3 database.

array nsIDownload getAllDownloads();
Return value

A list of nsIDownload instances from the database.

getDownloadState()

Retrieves the download state of the given download.

downloadState getDownloadState(
in ElemBase download
);
Parameters
download
Download which state should be checked
Return value

The download state of the given download.

getElement()

Retrieve an UI element based on the given spec object.

ElemBase getElement(
in object spec
);
Parameters
spec
JSON object which specifies the element to retrieve. Use its attributes to specify the exact element. This example will show the correct usage.
spec.type  (string)
spec.subtype (string) spec.value (mixed) Description
"download" nodeName
nodeValue (string)
Get the download specified by any node of the richtlistbox entry.
"download_button" "cancel"
Download (ElemBase)
Get the cancel button of the specified download.
"download_button" "pause" Download (ElemBase) Get the pause button of the specified download.
"download_button" "resume"
Download (ElemBase) Get the resume button of the specified download.
"download_button" "retry"
Download (ElemBase) Get the retry button of the specified download.
Return value

ElemBase instance of the requested element which matches the specifications.

open()

Open the Download Manager.

open(
in MozMillController controller,
in boolean shortcut
);
Parameters
controller
MozMillController of the browser window to operate on
shortcut
If true the keyboard shortcut is used to open the Download Manager window.

waitForDownloadState()

Waits until the given download has the expected download state or a timeout occurs.

getDownloadState(
in ElemBase download,
in
downloadState state,
in number timeout
);
Parameters
download
Download which state should be checked
state
The download state to wait for.
timeout
(Optional) Maximal duration to wait before a timeout occurs.
Return value

None.

waitForOpened()

Wait until the Download Manager window has been opened.

waitForOpened(
in MozMillController controller
);
Parameters
controller
MozMillController of the Download Manager window to operate on.

Examples

In the example below the Download Manager gets opened by using the keyboard shortcut. Afterward the download with the specified URL is retrieved and used to get its resume button. With the click the download will be resumed. Finally the Download Manager gets closed again.

var RELATIVE_ROOT = '../../shared-modules';
var MODULE_REQUIRES = ['DownloadsAPI'];

var setupModule = function(module)
{
  module.controller = mozmill.getBrowserController();
  module.dm = new DownloadsAPI.downloadManager();
}

var testResumeDownload = function()
{
  dm.open(controller, true);

  var download = dm.getElement({type: "download", subtype: "uri", value: "https://www.mozilla.org/favicon.ico"});
  var resumeButton = dm.getElement({type: "download_button", subtype: "resume", value: download});

  controller.click(resumeButton);

  dm.close();
}

Document Tags and Contributors

 Contributors to this page: Sheppy, Whimboo, Ashughes
 Last updated by: Sheppy,