Visit Mozilla.org

nsIDownloadProgressListener

From MDC

The nsIDownloadProgressListener interface gives applications and extensions a way to monitor the status of downloads being processed by the Download Manager; simply implement this interface in your code, then call the nsIDownloadManager function addListener() to start listening.

When you no longer need to listen to the Download Manager's state, call removeListener() on nsIDownloadManager to stop listening.

As the states of downloads change, the methods described here are called by the Download Manager so your code can take whatever steps it needs to.

This interface works very similarly to the nsIWebProgress interface.

Contents

nsIDownloadProgressListener is defined in toolkit/components/downloads/public/nsIDownloadProgressListener.idl. It is scriptable and unfrozen (hasn't changed since Mozilla 1.9).

Inherits from: nsISupports

[edit] Method overview

void onDownloadStateChange(in short aState, in nsIDownload aDownload)
void onProgressChange(in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long long aCurSelfProgress, in long long aMaxSelfProgress, in long long aCurTotalProgress, in long long aMaxTotalProgress, in nsIDownload aDownload)
Obsolete void onStatusChange(in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage, in nsIDownload aDownload)
Obsolete void onLocationChange(in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI aLocation, in nsIDownload aDownload)x
void onSecurityChange(in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aState, in nsIDownload aDownload)

[edit] Attributes

Attribute Type Description
document nsIDOMDocument The document object representing the Download Manager's window.

[edit] Methods

[edit] onDownloadStateChange()

Called when the status of a particular download changes.

 void onDownloadStateChange(
   in short aState,
   in nsIDownload aDownload
 );
[edit] Parameters
aState
The previous state of the download. See nsIDownloadManager for a list of possible values.
aDownload
The nsIDownload object representing the file whose download status has changed. You can get the new state of the download from this object.

[edit] onStateChange()

Called when the state of a particular download changes.

 void onStateChange(
   in nsIWebProgress aWebProgress,
   in nsIRequest aRequest,
   in unsigned long aStateFlags,
   in nsresult aStatus,
   in nsIDownload aDownload
 );
[edit] Parameters
aWebProgress
The nsIWebProgress instance used by the Download Manager to monitor downloads.
aRequest
The nsIChannel that changed state. This parameter will not be NULL.
aStateFlags
Flags indicating the download's new state. This value is a combination of one of the state transition flags documented in the nsIWebProgressListener section.
aStatus
The new state information for the download. See onStateChange() in nsIWebProgressListener for details. This can also be one of the nsIDownloadManager state constants.
aDownload
The download whose state changed.

[edit] onProgressChange()

Called when the download progress level changes for a download.

 void onProgressChange(
   in nsIWebProgress aWebProgress,
   in nsIRequest aRequest,
   in long long aCurSelfProgress,
   in long long aMaxSelfProgress,
   in long long aCurTotalProgress,
   in long long aMaxTotalProgress,
   in nsIDownload aDownload
 );
[edit] Parameters
aWebProgress
The nsIWebProgress instance used by the Download Manager to monitor downloads.
aRequest
The nsIChannel that changed state. This parameter will not be NULL.
aCurSelfProgress
The current amount of progress that's been made on the download specified by aDownload.
aMaxSelfProgress
The value that the self progress needs to reach to indicate that the download is complete.
aCurTotalProgress
The current amount of progress that's been made on all downloads.
aMaxTotalProgress
The value that the total progress needs to reach to indicate that all downloads are complete.
aDownload
The nsIDownload object whose progress is represented by the aCurSelfProgress and aMaxSelfProgress parameters.

[edit] onStatusChange()

Called when the status of a download request has changed. The received status message is intended to be displayed visibly to the user.

Warning: This method was removed in Firefox 3 (Gecko 1.9). In earlier versions, this method was never called.
 void onStatusChange(
   in nsIWebProgress aWebProgress,
   in nsIRequest aRequest,
   in nsresult aStatus,
   in wstring aMessage,
   in nsIDownload aDownload
 );
[edit] Parameters
aWebProgress
The nsIWebProgress instance used by the Download Manager to monitor downloads.
nsIChannel
The nsIRequest that changed state. This parameter will not be NULL.
aStatus
The new state information for the download. See onStateChange() in nsIWebProgressListener for details.
aMessage
A user-readable status message intended to be displayed visibly on the screen.
aDownload
The download whose status changed.

[edit] onLocationChange()

Warning: This method was removed in Firefox 3 (Gecko 1.9). In earlier versions, this method was never called.
 void onLocationChange(
   in nsIWebProgress aWebProgress,
   in nsIRequest aRequest,
   in nsIURI aLocation,
   in nsIDownload aDownload
 );


[edit] Parameters
aWebProgress
The nsIWebProgress instance used by the Download Manager to monitor downloads.
aRequest
The nsIChannel that changed state. This parameter will not be NULL.
aLocation
The URI of the file being downloaded.
aDownload
The nsIDownload object representing the file being downloaded.

[edit] onSecurityChange()

Called when the level of security being used while downloading changes; for example, if the initial request is made via HTTPS but the download switches to HTTP, this function gets called to notify you of that transition.

 void onSecurityChange(
   in nsIWebProgress aWebProgress,
   in nsIRequest aRequest,
   in unsigned long aState,
   in nsIDownload aDownload
 );
 
[edit] Parameters
aWebProgress
The nsIWebProgress instance used by the Download Manager to monitor downloads.
aRequest
The nsIChannel that changed state. This parameter will not be NULL.
aState
The new state of the download. See nsIDownloadManager for a list of possible values.
aDownload
The download whose security level is changing.

[edit] See also

nsIDownloadManager, nsIDownload, nsIWebProgressListener