From 1c0be6f54475e335f9ad69a818f0277b0dd27ebd Mon Sep 17 00:00:00 2001 From: "blakeross%telocity.com" Date: Sat, 23 Feb 2002 03:06:57 +0000 Subject: [PATCH] Download manager. Not part of build. git-svn-id: svn://10.0.0.236/trunk@115262 18797224-902f-48f8-a5cc-f745e15eee43 --- .../public/nsIDownloadManager.idl | 9 ++++++ .../src/nsDownloadManager.cpp | 29 ++++++++++++++++--- .../download-manager/src/nsDownloadManager.h | 1 - 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/mozilla/xpfe/components/download-manager/public/nsIDownloadManager.idl b/mozilla/xpfe/components/download-manager/public/nsIDownloadManager.idl index c1ae9f17d09..7da687449e6 100644 --- a/mozilla/xpfe/components/download-manager/public/nsIDownloadManager.idl +++ b/mozilla/xpfe/components/download-manager/public/nsIDownloadManager.idl @@ -48,6 +48,15 @@ interface nsIDownloadItem; [scriptable, uuid(9be66cc0-1dd1-11b2-8617-e3a3ed26e3b0)] interface nsIDownloadManager : nsISupports { + /** + * createDownload + * Creates a download item that can be managed. Set the proper attributes + * on the nsIDownloadItem returned by this method, and then call addDownload to + * add it to the manager. + */ + + nsIDownloadItem createDownload(); + /** * addDownload * Adds a download to be managed by the download manager. diff --git a/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp b/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp index 5a70e1ae4bf..f19758626bb 100644 --- a/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp +++ b/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp @@ -286,6 +286,23 @@ nsDownloadManager::AssertProgressInfo() /////////////////////////////////////////////////////////////////////////////// // nsIDownloadManager +NS_IMETHODIMP +nsDownloadManager::CreateDownload(nsIDownloadItem** aDownloadItem) +{ + NS_ENSURE_ARG_POINTER(aDownloadItem); + + // only one class (DownloadItem) is really going to implement nsIDownloadItem, + // which allows us to make many assumptions about how nsIDownloadItem will work + // we want to ensure that clients don't get hold of a bogus impl, hence this method + DownloadItem* item = new DownloadItem(); + if (!item) return NS_ERROR_OUT_OF_MEMORY; + + *aDownloadItem = NS_STATIC_CAST(nsIDownloadItem*, item); + NS_ADDREF(*aDownloadItem); + + return NS_OK; +} + NS_IMETHODIMP nsDownloadManager::AddDownload(nsIDownloadItem* aDownloadItem) { @@ -296,7 +313,6 @@ nsDownloadManager::AddDownload(nsIDownloadItem* aDownloadItem) if (NS_FAILED(rv)) return rv; DownloadItem* item = NS_STATIC_CAST(DownloadItem*, aDownloadItem); - item->SetDownloadManager(this); nsXPIDLCString filePath; @@ -777,8 +793,13 @@ DownloadItem::UpdateProgressInfo() nsresult rv = gRDFService->GetDataSource("rdf:downloads", getter_AddRefs(ds)); if (NS_FAILED(rv)) return rv; + nsCOMPtr res; + char* path; + mTarget->GetPath(&path); + gRDFService->GetResource(path, getter_AddRefs(res)); + nsCOMPtr oldTarget; - rv = ds->GetTarget(mDownloadItem, gNC_ProgressPercent, PR_TRUE, getter_AddRefs(oldTarget)); + rv = ds->GetTarget(res, gNC_ProgressPercent, PR_TRUE, getter_AddRefs(oldTarget)); if (NS_FAILED(rv)) return rv; nsCOMPtr percent; @@ -787,9 +808,9 @@ DownloadItem::UpdateProgressInfo() if (NS_FAILED(rv)) return rv; if (oldTarget) - rv = ds->Change(mDownloadItem, gNC_ProgressPercent, oldTarget, percent); + rv = ds->Change(res, gNC_ProgressPercent, oldTarget, percent); else - rv = ds->Assert(mDownloadItem, gNC_ProgressPercent, percent, PR_TRUE); + rv = ds->Assert(res, gNC_ProgressPercent, percent, PR_TRUE); // XXX Store elapsed time here eventually diff --git a/mozilla/xpfe/components/download-manager/src/nsDownloadManager.h b/mozilla/xpfe/components/download-manager/src/nsDownloadManager.h index 835143a14da..3c7ec9559df 100644 --- a/mozilla/xpfe/components/download-manager/src/nsDownloadManager.h +++ b/mozilla/xpfe/components/download-manager/src/nsDownloadManager.h @@ -109,7 +109,6 @@ protected: nsresult GetDialogListener(nsIWebProgressListener** aInternalListener); private: - nsIRDFResource* mDownloadItem; nsIRDFDataSource* mDataSource; nsDownloadManager* mDownloadManager;