mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 289540 - download manager takes only one listener. r=mconnor
This commit is contained in:
parent
97c8ba1e03
commit
eb3a5b4b69
@ -51,7 +51,7 @@ interface nsIDownloadProgressListener;
|
||||
interface nsISimpleEnumerator;
|
||||
interface mozIStorageConnection;
|
||||
|
||||
[scriptable, uuid(541712be-f582-4e1c-a85e-7b4652c4f392)]
|
||||
[scriptable, uuid(1c015a52-c4e3-4c1c-9071-2c2eaeed8bfc)]
|
||||
interface nsIDownloadManager : nsISupports {
|
||||
// Download States
|
||||
const short DOWNLOAD_NOTSTARTED = -1;
|
||||
@ -165,11 +165,6 @@ interface nsIDownloadManager : nsISupports {
|
||||
*/
|
||||
readonly attribute mozIStorageConnection DBConnection;
|
||||
|
||||
/**
|
||||
* The Download Manager's progress listener.
|
||||
*/
|
||||
attribute nsIDownloadProgressListener listener;
|
||||
|
||||
/**
|
||||
* Whether or not there are downloads that can be cleaned up (removed)
|
||||
* i.e. downloads that have completed, have failed or have been canceled.
|
||||
@ -190,6 +185,16 @@ interface nsIDownloadManager : nsISupports {
|
||||
* An enumeration of active nsIDownloads
|
||||
*/
|
||||
readonly attribute nsISimpleEnumerator activeDownloads;
|
||||
|
||||
/**
|
||||
* Adds a listener from the download manager.
|
||||
*/
|
||||
void addListener(in nsIDownloadProgressListener aListener);
|
||||
|
||||
/**
|
||||
* Removes a listener from the download manager.
|
||||
*/
|
||||
void removeListener(in nsIDownloadProgressListener aListener);
|
||||
};
|
||||
|
||||
|
||||
|
@ -681,22 +681,6 @@ nsDownloadManager::GetCanCleanUp(PRBool *aResult)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::SetListener(nsIDownloadProgressListener *aListener)
|
||||
{
|
||||
mListener = aListener;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::GetListener(nsIDownloadProgressListener** aListener)
|
||||
{
|
||||
NS_IF_ADDREF(*aListener = mListener);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::PauseDownload(PRUint32 aID)
|
||||
{
|
||||
@ -851,6 +835,57 @@ nsDownloadManager::GetDBConnection(mozIStorageConnection **aDBConn)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::AddListener(nsIDownloadProgressListener *aListener)
|
||||
{
|
||||
mListeners.AppendObject(aListener);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::RemoveListener(nsIDownloadProgressListener *aListener)
|
||||
{
|
||||
mListeners.RemoveObject(aListener);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsDownloadManager::NotifyListenersOnDownloadStateChange(PRInt16 aOldState,
|
||||
nsIDownload *aDownload)
|
||||
{
|
||||
for (PRInt32 i = mListeners.Count() - 1; i >= 0; --i)
|
||||
mListeners[i]->OnDownloadStateChange(aOldState, aDownload);
|
||||
}
|
||||
|
||||
void
|
||||
nsDownloadManager::NotifyListenersOnProgressChange(nsIWebProgress *aProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt64 aCurSelfProgress,
|
||||
PRInt64 aMaxSelfProgress,
|
||||
PRInt64 aCurTotalProgress,
|
||||
PRInt64 aMaxTotalProgress,
|
||||
nsIDownload *aDownload)
|
||||
{
|
||||
for (PRInt32 i = mListeners.Count() - 1; i >= 0; --i)
|
||||
mListeners[i]->OnProgressChange(aProgress, aRequest, aCurSelfProgress,
|
||||
aMaxSelfProgress, aCurTotalProgress,
|
||||
aMaxTotalProgress, aDownload);
|
||||
}
|
||||
|
||||
void
|
||||
nsDownloadManager::NotifyListenersOnStateChange(nsIWebProgress *aProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRUint32 aStateFlags,
|
||||
nsresult aStatus,
|
||||
nsIDownload *aDownload)
|
||||
{
|
||||
for (PRInt32 i = mListeners.Count() - 1; i >= 0; --i)
|
||||
mListeners[i]->OnStateChange(aProgress, aRequest, aStateFlags, aStatus,
|
||||
aDownload);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIObserver
|
||||
|
||||
@ -1178,8 +1213,7 @@ nsDownload::SetState(DownloadState aState)
|
||||
nsresult rv = UpdateDB();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mDownloadManager->mListener)
|
||||
mDownloadManager->mListener->OnDownloadStateChange(oldState, this);
|
||||
mDownloadManager->NotifyListenersOnDownloadStateChange(oldState, this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1248,14 +1282,9 @@ nsDownload::OnProgressChange64(nsIWebProgress *aWebProgress,
|
||||
mCurrBytes = aCurTotalProgress;
|
||||
mMaxBytes = aMaxTotalProgress;
|
||||
|
||||
if (mDownloadManager->NeedsUIUpdate()) {
|
||||
nsIDownloadProgressListener* dpl = mDownloadManager->mListener;
|
||||
if (dpl) {
|
||||
dpl->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress,
|
||||
aMaxSelfProgress, aCurTotalProgress,
|
||||
aMaxTotalProgress, this);
|
||||
}
|
||||
}
|
||||
mDownloadManager->NotifyListenersOnProgressChange(
|
||||
aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress,
|
||||
aCurTotalProgress, aMaxTotalProgress, this);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1454,11 +1483,8 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
|
||||
mDownloadManager->RemoveDownload(mID);
|
||||
}
|
||||
|
||||
if (mDownloadManager->NeedsUIUpdate()) {
|
||||
nsIDownloadProgressListener* dpl = mDownloadManager->mListener;
|
||||
if (dpl)
|
||||
dpl->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus, this);
|
||||
}
|
||||
mDownloadManager->NotifyListenersOnStateChange(aWebProgress, aRequest,
|
||||
aStateFlags, aStatus, this);
|
||||
|
||||
return UpdateDB();
|
||||
}
|
||||
|
@ -110,6 +110,21 @@ protected:
|
||||
PRInt64 aEndTime,
|
||||
PRInt32 aState);
|
||||
|
||||
void NotifyListenersOnDownloadStateChange(PRInt16 aOldState,
|
||||
nsIDownload *aDownload);
|
||||
void NotifyListenersOnProgressChange(nsIWebProgress *aProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt64 aCurSelfProgress,
|
||||
PRInt64 aMaxSelfProgress,
|
||||
PRInt64 aCurTotalProgress,
|
||||
PRInt64 aMaxTotalProgress,
|
||||
nsIDownload *aDownload);
|
||||
void NotifyListenersOnStateChange(nsIWebProgress *aProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRUint32 aStateFlags,
|
||||
nsresult aStatus,
|
||||
nsIDownload *aDownload);
|
||||
|
||||
nsDownload *FindDownload(PRUint32 aID);
|
||||
nsresult PauseResumeDownload(PRUint32 aID, PRBool aPause);
|
||||
nsresult CancelAllDownloads();
|
||||
@ -131,7 +146,6 @@ protected:
|
||||
nsIDownload* aDownload,
|
||||
nsIDOMWindow* aParent);
|
||||
|
||||
PRBool NeedsUIUpdate() { return mListener != nsnull; }
|
||||
PRInt32 GetRetentionBehavior();
|
||||
|
||||
static PRBool IsInFinalStage(DownloadState aState)
|
||||
@ -157,7 +171,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIDownloadProgressListener> mListener;
|
||||
nsCOMArray<nsIDownloadProgressListener> mListeners;
|
||||
nsCOMPtr<nsIXPIProgressDialog> mXPIProgress;
|
||||
nsCOMPtr<nsIStringBundle> mBundle;
|
||||
nsCOMPtr<nsITimer> mDMOpenTimer;
|
||||
|
@ -206,7 +206,7 @@ function run_test()
|
||||
onLocationChange: function(a, b, c, d) { },
|
||||
onSecurityChange: function(a, b, c, d) { }
|
||||
};
|
||||
dm.listener = listener;
|
||||
dm.addListener(listener);
|
||||
|
||||
print("Try creating observer...");
|
||||
var observer = {
|
||||
|
@ -520,7 +520,7 @@ function Startup()
|
||||
// notifications.
|
||||
var downloadStrings = document.getElementById("downloadStrings");
|
||||
gDownloadListener = new DownloadProgressListener(document, downloadStrings);
|
||||
gDownloadManager.listener = gDownloadListener;
|
||||
gDownloadManager.addListener(gDownloadListener);
|
||||
|
||||
// The active downloads list is created by the front end only when the download starts,
|
||||
// so we need to pre-populate it with any downloads that were already going.
|
||||
@ -580,7 +580,7 @@ function Startup()
|
||||
|
||||
function Shutdown()
|
||||
{
|
||||
gDownloadManager.listener = null;
|
||||
gDownloadManager.removeListener(gDownloadListener);
|
||||
|
||||
var pbi = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch2);
|
||||
|
Loading…
Reference in New Issue
Block a user