2003-11-27 00:54:33 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2005-02-01 17:07:35 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2003-11-27 00:54:33 +00:00
|
|
|
*
|
2005-02-01 17:07:35 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2003-11-27 00:54:33 +00:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2005-02-01 17:07:35 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2003-11-27 00:54:33 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Blake Ross <blaker@netscape.com>
|
|
|
|
* Ben Goodger <ben@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2005-02-01 17:07:35 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2003-11-27 00:54:33 +00:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2005-02-01 17:07:35 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2003-11-27 00:54:33 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2005-02-01 17:07:35 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2003-11-27 00:54:33 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef downloadmanager___h___
|
|
|
|
#define downloadmanager___h___
|
|
|
|
|
|
|
|
#include "nsIDownloadManager.h"
|
2003-12-09 05:55:09 +00:00
|
|
|
#include "nsIXPInstallManagerUI.h"
|
2003-11-27 00:54:33 +00:00
|
|
|
#include "nsIDownloadProgressListener.h"
|
|
|
|
#include "nsIDownload.h"
|
|
|
|
#include "nsIRDFDataSource.h"
|
|
|
|
#include "nsIRDFRemoteDataSource.h"
|
|
|
|
#include "nsIRDFService.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIRDFContainerUtils.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
2005-04-05 23:24:23 +00:00
|
|
|
#include "nsIWebProgressListener2.h"
|
2003-12-09 05:55:09 +00:00
|
|
|
#include "nsIXPIProgressDialog.h"
|
2003-11-27 00:54:33 +00:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIWebBrowserPersist.h"
|
|
|
|
#include "nsILocalFile.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsIRequest.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIStringBundle.h"
|
2003-12-02 00:59:58 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2003-11-27 00:54:33 +00:00
|
|
|
#include "nsIProgressDialog.h"
|
|
|
|
#include "nsIMIMEInfo.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "nsIAlertsService.h"
|
|
|
|
#endif
|
|
|
|
|
2003-12-09 05:55:09 +00:00
|
|
|
typedef PRInt16 DownloadState;
|
2003-12-10 21:59:41 +00:00
|
|
|
typedef PRInt16 DownloadType;
|
2003-12-09 05:55:09 +00:00
|
|
|
|
|
|
|
class nsXPIProgressListener;
|
|
|
|
class nsDownload;
|
2003-11-27 00:54:33 +00:00
|
|
|
|
|
|
|
class nsDownloadManager : public nsIDownloadManager,
|
2003-12-09 05:55:09 +00:00
|
|
|
public nsIXPInstallManagerUI,
|
2003-11-27 00:54:33 +00:00
|
|
|
public nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOWNLOADMANAGER
|
2003-12-09 05:55:09 +00:00
|
|
|
NS_DECL_NSIXPINSTALLMANAGERUI
|
2003-11-27 00:54:33 +00:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
|
|
|
|
nsDownloadManager();
|
|
|
|
virtual ~nsDownloadManager();
|
|
|
|
|
|
|
|
static PRInt32 PR_CALLBACK CancelAllDownloads(nsHashKey* aKey, void* aData, void* aClosure);
|
|
|
|
static PRInt32 PR_CALLBACK BuildActiveDownloadsList(nsHashKey* aKey, void* aData, void* aClosure);
|
|
|
|
nsresult DownloadEnded(const PRUnichar* aPersistentDescriptor, const PRUnichar* aMessage);
|
|
|
|
|
2003-12-09 05:55:09 +00:00
|
|
|
public:
|
|
|
|
nsresult AssertProgressInfoFor(const PRUnichar* aPersistentDescriptor);
|
|
|
|
|
2003-11-27 00:54:33 +00:00
|
|
|
protected:
|
|
|
|
nsresult GetDownloadsContainer(nsIRDFContainer** aResult);
|
|
|
|
nsresult GetProfileDownloadsFileURL(nsCString& aDownloadsFileURL);
|
|
|
|
nsresult GetDataSource(nsIRDFDataSource** aDataSource);
|
|
|
|
nsresult DownloadStarted(const PRUnichar* aPersistentDescriptor);
|
|
|
|
nsresult GetInternalListener(nsIDownloadProgressListener** aListener);
|
|
|
|
nsresult PauseResumeDownload(const PRUnichar* aPath, PRBool aPause);
|
|
|
|
nsresult RemoveDownload(nsIRDFResource* aDownload);
|
|
|
|
nsresult ValidateDownloadsContainer();
|
|
|
|
|
2003-12-02 00:59:58 +00:00
|
|
|
void ConfirmCancelDownloads(PRInt32 aCount, nsISupportsPRBool* aCancelDownloads,
|
|
|
|
const PRUnichar* aTitle,
|
|
|
|
const PRUnichar* aCancelMessageMultiple,
|
2003-12-03 06:26:07 +00:00
|
|
|
const PRUnichar* aCancelMessageSingle,
|
|
|
|
const PRUnichar* aDontCancelButton);
|
2003-12-02 00:59:58 +00:00
|
|
|
|
2003-11-27 00:54:33 +00:00
|
|
|
static void OpenTimerCallback(nsITimer* aTimer, void* aClosure);
|
2004-02-11 03:48:16 +00:00
|
|
|
static nsresult OpenDownloadManager(PRBool aShouldFocus, PRInt32 aFlashCount, nsIDownload* aDownload, nsIDOMWindow* aParent);
|
2003-11-27 00:54:33 +00:00
|
|
|
|
|
|
|
PRBool NeedsUIUpdate() { return mListener != nsnull; }
|
|
|
|
PRInt32 GetRetentionBehavior();
|
|
|
|
|
2003-12-09 05:55:09 +00:00
|
|
|
static PRBool IsInFinalStage(DownloadState aState)
|
|
|
|
{
|
|
|
|
return aState == nsIDownloadManager::DOWNLOAD_NOTSTARTED ||
|
|
|
|
aState == nsIDownloadManager::DOWNLOAD_DOWNLOADING ||
|
|
|
|
aState == nsIXPInstallManagerUI::INSTALL_INSTALLING;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool IsInProgress(DownloadState aState)
|
|
|
|
{
|
|
|
|
return aState == nsIDownloadManager::DOWNLOAD_NOTSTARTED ||
|
|
|
|
aState == nsIDownloadManager::DOWNLOAD_DOWNLOADING ||
|
|
|
|
aState == nsIDownloadManager::DOWNLOAD_PAUSED ||
|
|
|
|
aState == nsIXPInstallManagerUI::INSTALL_DOWNLOADING ||
|
|
|
|
aState == nsIXPInstallManagerUI::INSTALL_INSTALLING;
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRBool CompletedSuccessfully(DownloadState aState)
|
|
|
|
{
|
|
|
|
return aState == nsIDownloadManager::DOWNLOAD_FINISHED ||
|
|
|
|
aState == nsIXPInstallManagerUI::INSTALL_FINISHED;
|
|
|
|
};
|
|
|
|
|
2003-11-27 00:54:33 +00:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDownloadProgressListener> mListener;
|
|
|
|
nsCOMPtr<nsIRDFDataSource> mDataSource;
|
2003-12-11 00:41:00 +00:00
|
|
|
nsCOMPtr<nsIXPIProgressDialog> mXPIProgress;
|
2003-11-27 00:54:33 +00:00
|
|
|
nsCOMPtr<nsIRDFContainer> mDownloadsContainer;
|
|
|
|
nsCOMPtr<nsIRDFContainerUtils> mRDFContainerUtils;
|
|
|
|
nsCOMPtr<nsIStringBundle> mBundle;
|
|
|
|
nsCOMPtr<nsITimer> mDMOpenTimer;
|
|
|
|
PRInt32 mBatches;
|
|
|
|
nsHashtable mCurrDownloads;
|
|
|
|
|
|
|
|
friend class nsDownload;
|
|
|
|
};
|
|
|
|
|
2003-12-09 05:55:09 +00:00
|
|
|
class nsXPIProgressListener : public nsIXPIProgressDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIXPIPROGRESSDIALOG
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsXPIProgressListener() { };
|
|
|
|
nsXPIProgressListener(nsDownloadManager* aManager);
|
|
|
|
virtual ~nsXPIProgressListener();
|
|
|
|
|
|
|
|
void AddDownload(nsIDownload* aDownload);
|
2003-12-10 21:59:41 +00:00
|
|
|
|
2003-12-09 05:55:09 +00:00
|
|
|
PRBool HasActiveXPIOperations();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void RemoveDownloadAtIndex(PRUint32 aIndex);
|
|
|
|
|
|
|
|
inline void AssertProgressInfoForDownload(nsDownload* aDownload);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsDownloadManager* mDownloadManager;
|
|
|
|
nsCOMPtr<nsISupportsArray> mDownloads;
|
|
|
|
};
|
|
|
|
|
2003-12-10 21:59:41 +00:00
|
|
|
class nsDownloadsDataSource : public nsIRDFDataSource,
|
|
|
|
public nsIRDFRemoteDataSource
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRDFDATASOURCE
|
|
|
|
NS_DECL_NSIRDFREMOTEDATASOURCE
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsDownloadsDataSource() { };
|
|
|
|
virtual ~nsDownloadsDataSource() { };
|
|
|
|
|
|
|
|
nsresult LoadDataSource();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIRDFDataSource> mInner;
|
|
|
|
};
|
|
|
|
|
2005-01-04 13:40:51 +00:00
|
|
|
class nsDownload : public nsIDownload
|
2003-11-27 00:54:33 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIWEBPROGRESSLISTENER
|
2005-04-05 23:24:23 +00:00
|
|
|
NS_DECL_NSIWEBPROGRESSLISTENER2
|
2004-04-17 00:58:23 +00:00
|
|
|
NS_DECL_NSITRANSFER
|
2003-11-27 00:54:33 +00:00
|
|
|
NS_DECL_NSIDOWNLOAD
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsDownload();
|
|
|
|
virtual ~nsDownload();
|
|
|
|
|
2003-12-09 05:55:09 +00:00
|
|
|
public:
|
2003-12-10 21:59:41 +00:00
|
|
|
DownloadState GetDownloadState();
|
|
|
|
void SetDownloadState(DownloadState aState);
|
|
|
|
DownloadType GetDownloadType();
|
|
|
|
void SetDownloadType(DownloadType aType);
|
2003-12-09 05:55:09 +00:00
|
|
|
|
2003-11-27 00:54:33 +00:00
|
|
|
protected:
|
|
|
|
nsresult SetDownloadManager(nsDownloadManager* aDownloadManager);
|
|
|
|
nsresult SetDialogListener(nsIWebProgressListener* aInternalListener);
|
|
|
|
nsresult GetDialogListener(nsIWebProgressListener** aInternalListener);
|
|
|
|
nsresult SetDialog(nsIProgressDialog* aDialog);
|
|
|
|
nsresult GetDialog(nsIProgressDialog** aDialog);
|
2005-04-24 21:16:28 +00:00
|
|
|
nsresult SetCancelable(nsICancelable* aCancelable);
|
2004-04-17 00:58:23 +00:00
|
|
|
nsresult SetTarget(nsIURI* aTarget);
|
2005-01-04 13:40:51 +00:00
|
|
|
nsresult SetDisplayName(const PRUnichar* aDisplayName);
|
2003-11-27 00:54:33 +00:00
|
|
|
nsresult SetSource(nsIURI* aSource);
|
|
|
|
nsresult GetTransferInformation(PRInt32* aCurr, PRInt32* aMax);
|
|
|
|
nsresult SetMIMEInfo(nsIMIMEInfo* aMIMEInfo);
|
|
|
|
nsresult SetStartTime(PRInt64 aStartTime);
|
|
|
|
|
|
|
|
void Pause(PRBool aPaused);
|
|
|
|
PRBool IsPaused();
|
|
|
|
|
|
|
|
nsDownloadManager* mDownloadManager;
|
2004-04-17 00:58:23 +00:00
|
|
|
nsCOMPtr<nsIURI> mTarget;
|
2003-11-27 00:54:33 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsString mDisplayName;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> mSource;
|
|
|
|
nsCOMPtr<nsIWebProgressListener> mDialogListener;
|
2005-04-24 21:16:28 +00:00
|
|
|
nsCOMPtr<nsICancelable> mCancelable;
|
2003-11-27 00:54:33 +00:00
|
|
|
nsCOMPtr<nsIRequest> mRequest;
|
|
|
|
nsCOMPtr<nsIProgressDialog> mDialog;
|
|
|
|
nsCOMPtr<nsIMIMEInfo> mMIMEInfo;
|
|
|
|
|
|
|
|
DownloadState mDownloadState;
|
2003-12-10 21:59:41 +00:00
|
|
|
DownloadType mDownloadType;
|
2003-11-27 00:54:33 +00:00
|
|
|
|
|
|
|
PRBool mPaused;
|
|
|
|
PRInt32 mPercentComplete;
|
2004-12-18 04:06:51 +00:00
|
|
|
PRUint64 mCurrBytes;
|
|
|
|
PRUint64 mMaxBytes;
|
2003-11-27 00:54:33 +00:00
|
|
|
PRInt64 mStartTime;
|
|
|
|
PRTime mLastUpdate;
|
|
|
|
|
|
|
|
friend class nsDownloadManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|