Download manager. Not part of build.

This commit is contained in:
blakeross%telocity.com 2002-02-20 00:15:14 +00:00
parent ee537b0a21
commit f27287ac0e
5 changed files with 213 additions and 32 deletions

View File

@ -0,0 +1,106 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Blake Ross <blakeross@telocity.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface nsIURI;
interface nsILocalFile;
interface nsIWebProgressListener;
interface nsIDownloadProgressListener;
[scriptable, uuid(06cb92f2-1dd2-11b2-95f2-96dfdfb804a1)]
interface nsIDownloadItem : nsISupports {
/**
* prettyName
* The user-readable description of a download
*/
attribute wstring prettyName;
/**
* source
* The source of a download
*/
attribute nsIURI source;
/**
* target
* The local file where the download is being saved
*/
attribute nsILocalFile target;
/**
* percentComplete
* The percent complete of an item at any given moment
*/
readonly attribute PRInt32 percentComplete;
/**
* timeStarted
* The time a download was started; necessary for more accurate
* measurements
*/
readonly attribute long long timeStarted;
/**
* listener
* Optionally set by the client; downloading information is
* passed to this listener and used to update client UI
*/
attribute nsIWebProgressListener listener;
/**
* listener
* Optionally set by the client; downloading information is
* passed to this listener and used to update client UI
*/
attribute nsIWebProgressListener propertiesListener;
/**
* internalListener
* Set by the download manager; used to update download manager UI
*/
attribute nsIDownloadProgressListener internalListener;
};
%{C++
#define NS_DOWNLOADITEM_CONTRACTID "@mozilla.org/download-manager/item;1"
// {E3FA9D0A-1DD1-11B2-BDEF-8C720B597445}
#define NS_DOWNLOADITEM_CID \
{ 0xe3fa9d0a, 0x1dd1, 0x11b2, { 0xbd, 0xef, 0x8c, 0x72, 0x0b, 0x59, 0x74, 0x45 } }
%}

View File

@ -38,19 +38,44 @@
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIWebProgressListener.idl"
interface nsIWebProgress;
interface nsILocalFile;
interface nsIURI;
interface nsIDOMXULDocument;
interface nsIDownloadItem;
[scriptable, uuid(9be66cc0-1dd1-11b2-8617-e3a3ed26e3b0)]
interface nsIDownloadManager : nsISupports {
void addItem(in wstring aDisplayName,
in nsIURI aSourceURI,
in nsILocalFile aDestFile,
in string aParentID,
in nsIWebProgress aProgress);
/**
* addItem
* Adds an item to be managed by the download manager.
*/
void addItem(in nsIDownloadItem item);
/**
* getItem
* Used to retrieve a download managed by the download manager.
*/
nsIDownloadItem getItem(in string id);
void notifyDownloadEnded(in string id);
/**
* initializeUI
* Called by the download manager FE to signify that the manager
* should begin forwarding progress notifications to the ui listener.
*/
void initializeUI(in nsIDOMXULDocument document);
/**
* uninitializeUI
* Called by the download manager FE to signify that that the manager
* should stop forwarding progress notifications to the ui listener because
* the FE is no longer being displayed.
*/
void uninitializeUI();
};
@ -60,5 +85,4 @@ interface nsIDownloadManager : nsISupports {
// {EDB0490E-1DD1-11B2-83B8-DBF8D85906A6}
#define NS_DOWNLOADMANAGER_CID \
{ 0xedb0490e, 0x1dd1, 0x11b2, { 0x83, 0xb8, 0xdb, 0xf8, 0xd8, 0x59, 0x06, 0xa6 } }
%}

View File

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Blake Ross <blakeross@telocity.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* 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
* use your version of this file under the terms of the NPL, indicate your
* 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
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIWebProgressListener.idl"
interface nsIDownloadItem;
interface nsIDOMXULDocument;
[scriptable, uuid(09cddbea-1dd2-11b2-aa15-c41ffea19d79)]
interface nsIDownloadProgressListener : nsIWebProgressListener {
attribute nsIDownloadItem downloadItem;
attribute nsIDOMXULDocument document;
};

View File

@ -64,7 +64,7 @@
* 2. InitializeUI/UnitializeUI is lame...would like to keep manager separate from FE as
much as possible. The document arg is also lame but the listener needs it to update the UI.
* 3. Error handling? Holding off on this until law is done with his changes.
* 4. NotifyDownloadEnded should not be on nsIDownloadManager
* 4. NotifyDownloadEnded and internalListener should not be on nsIDownloadManager
*/
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);

View File

@ -39,16 +39,17 @@
#ifndef downloadmanager___h___
#define downloadmanager___h___
#include "nsIDownloadManager.h"
#include "nsIDownloadProgressListener.h"
#include "nsIDownloadItem.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFContainer.h"
#include "nsIRDFService.h"
#include "nsIDOMXULDocument.h"
#include "nsIRDFContainerUtils.h"
#include "nsIObserver.h"
#include "nsIWebProgressListener.h"
#include "nsIWebBrowserPersist.h"
#include "nsIRequestObserver.h"
#include "nsIURI.h"
#include "nsILocalFile.h"
#include "nsHashtable.h"
@ -59,7 +60,7 @@ class nsDownloadManager : public nsIDownloadManager,
{
public:
NS_DECL_NSIRDFDATASOURCE
NS_DECL_NSIRDFREMOTEDATASOURCE
NS_DECL_NSIRDFREMOTEDATASOURCE
NS_DECL_ISUPPORTS
NS_DECL_NSIDOWNLOADMANAGER
@ -71,41 +72,42 @@ public:
protected:
nsresult GetDownloadsContainer(nsIRDFContainer** aResult);
nsresult GetProfileDownloadsFileURL(char** aDownloadsFileURL);
protected:
nsCOMPtr<nsIRDFDataSource> mInner;
nsCOMPtr<nsISupportsArray> mObservers;
nsCOMPtr<nsIRDFService> mRDFService;
nsCOMPtr<nsIDOMXULDocument> mDocument;
nsCOMPtr<nsIDownloadProgressListener> mListener;
nsCOMPtr<nsIRDFContainerUtils> mRDFContainerUtils;
nsHashtable* mDownloadItems;
nsHashtable* mCurrDownloadItems;
};
class DownloadItem : public nsIWebProgressListener
class DownloadItem : public nsIWebProgressListener,
public nsIDownloadItem
{
public:
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIDOWNLOADITEM
NS_DECL_ISUPPORTS
DownloadItem();
virtual ~DownloadItem();
nsresult Init(nsIRDFResource* aDownloadItem,
nsIRDFDataSource* aDataSource,
nsIURI* aURI, nsIInputStream* aPostData, nsILocalFile* aFile);
DownloadItem();
DownloadItem(const PRUnichar* aPrettyName, nsILocalFile* aTarget, nsIURI* aSource);
virtual ~DownloadItem();
protected:
nsresult UpdateProgressInfo();
protected:
nsCOMPtr<nsIWebBrowserPersist> mWebBrowserPersist;
nsCOMPtr<nsIRequestObserver> mRequestObserver;
nsIRDFResource* mDownloadItem;
nsIRDFDataSource* mDataSource;
nsString mPrettyName;
nsCOMPtr<nsILocalFile> mTarget;
nsCOMPtr<nsIURI> mSource;
nsCOMPtr<nsIWebProgressListener> mListener;
nsCOMPtr<nsIDownloadProgressListener> mInternalListener;
nsCOMPtr<nsIWebProgressListener> mPropertiesListener;
PRInt32 mCurTotalProgress;
PRInt32 mMaxTotalProgress;
PRInt32 mPercentComplete;
PRInt64 mTimeStarted;
};
#endif