nsISupports
Last changed in Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)To use simply implement this interface in your code, then call nsIDownloadManager.addListener()
to start listening.
When you no longer need to listen to the Download Manager's state, call nsIDownloadManager.removeListener()
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. It is important to note that there is no service for this listener. Rather, the developer must create an object with the methods provided below to implement it.
void onDownloadStateChange(in short aState, in nsIDownload aDownload); |
void onLocationChange(in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI aLocation, in nsIDownload aDownload); Obsolete since Gecko 1.9.1 |
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); |
void onSecurityChange(in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aState, in nsIDownload aDownload); |
void onStateChange(in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus, in nsIDownload aDownload); |
void onStatusChange(in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage, in nsIDownload aDownload); Obsolete since Gecko 1.9.1 |
Attribute | Type | Description |
document |
|
document The document of the download manager frontend. |
Called when the status of a particular download changes.
void onDownloadStateChange( in short aState, in nsIDownload aDownload );
aState
nsIDownloadManager.Constants
for a list of possible values.aDownload
nsIDownload
object representing the file whose download status has changed. You can get the new state of the download from this object.void onLocationChange( in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI aLocation, in nsIDownload aDownload );
aWebProgress
nsIWebProgress
instance used by the Download Manager to monitor downloads.aRequest
nsIChannel
that changed state. This parameter will not be null
.aLocation
aDownload
nsIDownload
object representing the file being downloaded.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 );
aWebProgress
nsIWebProgress
instance used by the Download Manager to monitor downloads.aRequest
nsIChannel
that changed state. This parameter will not be null
.aCurSelfProgress
aDownload
.aMaxSelfProgress
aCurTotalProgress
aMaxTotalProgress
aDownload
nsIDownload
object whose progress is represented by the aCurSelfProgress
and aMaxSelfProgress
parameters.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 );
aWebProgress
nsIWebProgress
instance used by the Download Manager to monitor downloads.aRequest
nsIChannel
that changed state. This parameter will not be null
.aState
nsIDownloadManager.Constants
for a list of possible values.aDownload
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 );
aWebProgress
nsIWebProgress
instance used by the Download Manager to monitor downloads.aRequest
nsIChannel
that changed state. This parameter will not be null
.aStateFlags
nsIWebProgressListener.State_Transition_Flags
.aStatus
nsIWebProgressListener.onStateChange()
for details. This can also be one of the nsIDownloadManager.Constants
.aDownload
Called when the status of a download request has changed. The received status message is intended to be displayed visibly to the user.
Note: If source and destination are identical, which is possible in case of file URLs or chrome URLs, this is called even in Gecko 1.9.2. In such a situation no further event handlers are called and the stop flag is set; if there are more pending downloads in such a situation not yet started they never start. In normal situations this is never called. The method even if never called must be implemented in the listener, because the WebProgress used to do the physical part of the download requires it and uses the listener instance provided to the download manager.
void onStatusChange( in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage, in nsIDownload aDownload );
aWebProgress
nsIWebProgress
instance used by the Download Manager to monitor downloads.aRequest
nsIRequest
that changed state. This parameter will not be null
.aStatus
nsIWebProgressListener.onStateChange()
for details.aMessage
aDownload
var dm = Components.classes["@mozilla.org/download-manager;1"] .getService(Components.interfaces.nsIDownloadManager); dm.addListener({ onSecurityChange : function(prog, req, state, dl) { }, onProgressChange : function(prog, req, prog, progMax, tProg, tProgMax, dl) { }, onStateChange : function(prog, req, flags, status, dl) { }, onDownloadStateChange : function(state, dl) { } });
Even if you do not want to use some of the listeners, you must include all of them. An exception will be thrown if one of them is missing. Rather, only fill in the code for the ones you need, and leave the others blank as shown.