зеркало из https://github.com/mozilla/gecko-dev.git
Download manager. Not part of build.
This commit is contained in:
Родитель
a95b15203d
Коммит
6c30133fea
|
@ -20,7 +20,7 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Blake Ross <blakeross@telocity.com>
|
||||
* Blake Ross <blaker@netscape.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
|
||||
|
@ -36,15 +36,28 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/*
|
||||
* nsIDownloadItem acts as a "master listener" for the ongoing transfer. It implements nsIWebProgressListener,
|
||||
* If clients provide a persist object, the item will automatically be set as the persist's listener. Otherwise,
|
||||
* clients should set this themselves on whatever download mechanism they're using.
|
||||
* nsIDownloadItem's listener impl will forward progress notifications onto three possible
|
||||
* listeners: the internal listener (an nsIDownloadProgressListener, used to update
|
||||
* the main download manager UI), the properties listener (used to update the download manager
|
||||
* properties dialog), and an optional listener set by the client via nsIDownloadItem's |listener|
|
||||
* attribute (used to update client UI).
|
||||
*/
|
||||
|
||||
#include "nsIWebProgressListener.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsILocalFile;
|
||||
interface nsIWebProgressListener;
|
||||
interface nsIDownloadProgressListener;
|
||||
interface nsIObserver;
|
||||
interface nsIWebBrowserPersist;
|
||||
|
||||
[scriptable, uuid(06cb92f2-1dd2-11b2-95f2-96dfdfb804a1)]
|
||||
interface nsIDownloadItem : nsISupports {
|
||||
interface nsIDownloadItem : nsIWebProgressListener {
|
||||
|
||||
/**
|
||||
* prettyName
|
||||
|
@ -66,7 +79,7 @@ interface nsIDownloadItem : nsISupports {
|
|||
|
||||
/**
|
||||
* percentComplete
|
||||
* The percent complete of an item at any given moment
|
||||
* The percentage complete of an item
|
||||
*/
|
||||
readonly attribute PRInt32 percentComplete;
|
||||
|
||||
|
@ -79,17 +92,29 @@ interface nsIDownloadItem : nsISupports {
|
|||
|
||||
/**
|
||||
* listener
|
||||
* Optionally set by the client; downloading information is
|
||||
* Optional; 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
|
||||
* persist
|
||||
* Optional. If set, it will be used for cancellation, and the download item
|
||||
* will be set as its listener. If not, observer should be set to listen and
|
||||
* respond accordingly to topics like oncancel, and the client promises to set
|
||||
* the download item (which implements nsIWebProgressListener) as the listener for
|
||||
* whatever transfer component being used.
|
||||
*/
|
||||
attribute nsIWebProgressListener propertiesListener;
|
||||
|
||||
attribute nsIWebBrowserPersist persist;
|
||||
|
||||
/**
|
||||
* observer
|
||||
* If set, receives notifications of events like cancel ("oncancel").
|
||||
* Must be set if no persist object is specified (see above).
|
||||
*/
|
||||
|
||||
attribute nsIObserver observer;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Blake Ross <blakeross@telocity.com>
|
||||
* Blake Ross <blaker@netscape.com>
|
||||
* Ben Goodger <ben@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
|
@ -37,21 +37,6 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* So here's the deal:
|
||||
*
|
||||
* As it stands, nsIDownloadManager does not handle the actual downloading of files.
|
||||
* Rather, it manages them. When clients use some transfer component to download a
|
||||
* file, they also create an nsIDownloadItem, define its properties (uri, target, etc.),
|
||||
* get the download manager service, and call addItem. nsIDownloadItem acts as a
|
||||
* "master listener" for the ongoing transfer. It implements nsIWebProgressListener,
|
||||
* and clients should set it to be the listener for whatever xfer component they're using.
|
||||
* nsIDownloadItem's listener impl will forward progress notifications onto three possible
|
||||
* listeners: the internal listener (an nsIDownloadProgressListener, used to update
|
||||
* the main download manager UI), the properties listener (used to update the download manager
|
||||
* properties dialog), and an optional listener set by the client via nsIDownloadItem's |listener|
|
||||
* attribute (used to update client UI).
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIWebProgressListener.idl"
|
||||
|
||||
|
@ -62,32 +47,51 @@ interface nsIDownloadItem;
|
|||
interface nsIDownloadManager : nsISupports {
|
||||
|
||||
/**
|
||||
* addItem
|
||||
* Adds an item to be managed by the download manager.
|
||||
* addDownload
|
||||
* Adds a download to be managed by the download manager.
|
||||
*/
|
||||
|
||||
void addItem(in nsIDownloadItem item);
|
||||
void addDownload(in nsIDownloadItem item);
|
||||
|
||||
/**
|
||||
* getItem
|
||||
* getDownload
|
||||
* Used to retrieve a download managed by the download manager.
|
||||
*/
|
||||
|
||||
nsIDownloadItem getItem(in string id);
|
||||
nsIDownloadItem getDownload(in string key);
|
||||
|
||||
/**
|
||||
* cancelDownload
|
||||
* If a persist is set on the download item, download manager will call
|
||||
* nsIWebBrowserPersist::CancelSave. Else, if an observer is set on the item
|
||||
* (it should be), it will be notified with the "oncancel" topic. Callers
|
||||
* that don't provide a persist object promise to listen for this topic and cancel
|
||||
* the download; the download will be removed from the manager.
|
||||
*/
|
||||
|
||||
void cancelDownload(in string key);
|
||||
|
||||
/**
|
||||
* open
|
||||
* Opens the Download Manager front end.
|
||||
*/
|
||||
void open(in nsIDOMWindowInternal aOwnerDocument);
|
||||
|
||||
void open(in nsIDOMWindowInternal aOwnerWindow);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* openProgressDialogFor
|
||||
* Opens an individual progress dialog displaying progress for the download.
|
||||
*/
|
||||
void uninitializeUI();
|
||||
|
||||
void openProgressDialogFor(in string key, in nsIDOMWindowInternal aOwnerWindow);
|
||||
|
||||
/**
|
||||
* onClose
|
||||
* Called when the download manager UI is closed. Useful for
|
||||
* third party managers to let us know when they've closed.
|
||||
*/
|
||||
void onClose();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,10 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* A minimally extended progress listener used by download manager
|
||||
* to update its default UI.
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIWebProgressListener.idl"
|
||||
|
||||
|
|
|
@ -41,13 +41,12 @@ const NC_NS = "http://home.netscape.com/NC-rdf#";
|
|||
|
||||
var gDownloadView = null;
|
||||
var gDownloadViewChildren = null;
|
||||
var gDownloadManager = null;
|
||||
var gRDFService = null;
|
||||
var gNC_File = null;
|
||||
// random global variables...
|
||||
var keepProgressWindowUpBox;
|
||||
|
||||
var webBrowserPersist;
|
||||
|
||||
function NODE_ID(aElement)
|
||||
{
|
||||
return aElement.getAttribute("ref") || aElement.id;
|
||||
|
@ -77,20 +76,12 @@ function Startup()
|
|||
gDownloadView.controllers.appendController(downloadViewController);
|
||||
const dlmgrContractID = "@mozilla.org/download-manager;1";
|
||||
const dlmgrIID = Components.interfaces.nsIDownloadManager;
|
||||
const dlmgr = Components.classes[dlmgrContractID].getService(dlmgrIID);
|
||||
const ds = dlmgr.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
gDownloadManager = Components.classes[dlmgrContractID].getService(dlmgrIID);
|
||||
const ds = gDownloadManager.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
gDownloadView.database.AddDataSource(ds);
|
||||
gDownloadView.builder.rebuild();
|
||||
}
|
||||
|
||||
function Shutdown()
|
||||
{
|
||||
const dlmgrContractID = "@mozilla.org/download-manager;1";
|
||||
const dlmgrIID = Components.interfaces.nsIDownloadManager;
|
||||
const dlmgr = Components.classes[dlmgrContractID].getService(dlmgrIID);
|
||||
dlmgr.uninitializeUI();
|
||||
}
|
||||
|
||||
var downloadView = {
|
||||
onClick: function downloadView_click(aEvent)
|
||||
{
|
||||
|
@ -169,6 +160,9 @@ var downloadViewController = {
|
|||
// a) Prompt user to confirm end of transfers in progress
|
||||
// b) End transfers
|
||||
// c) Delete entries from datasource
|
||||
|
||||
for (var i = 0; i < selection.length; ++i)
|
||||
gDownloadManager.cancelDownload(selection.id);
|
||||
deleteItem(selection);
|
||||
break;
|
||||
case "cmd_selectAll":
|
||||
|
|
|
@ -217,10 +217,10 @@ nsDownloadProgressListener.prototype = {
|
|||
},
|
||||
onLocationChange: function(aWebProgress, aRequest, aLocation)
|
||||
{
|
||||
// we can ignore this notification
|
||||
},
|
||||
onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
|
||||
{
|
||||
// XXX error handling
|
||||
},
|
||||
onSecurityChange: function(aWebProgress, aRequest, state)
|
||||
{
|
||||
|
|
|
@ -48,11 +48,12 @@
|
|||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIProgressDialog.h"
|
||||
|
||||
/* Outstanding issues/todo:
|
||||
* 1. Client should be able to set cancel callback so users can cancel downloads from manager FE.
|
||||
* 2. Error handling? Holding off on this until law is done with his changes.
|
||||
* 1. Using the target path as an identifier is not sufficient because it's not unique on mac.
|
||||
*/
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
@ -69,9 +70,13 @@ nsIRDFResource* gNC_ProgressPercent;
|
|||
|
||||
nsIRDFService* gRDFService;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsDownloadManager
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsDownloadManager, nsIDownloadManager, nsIRDFDataSource, nsIRDFRemoteDataSource)
|
||||
|
||||
nsDownloadManager::nsDownloadManager() : mCurrDownloadItems(nsnull)
|
||||
nsDownloadManager::nsDownloadManager() : mCurrDownloadItems(nsnull),
|
||||
mMustUpdateUI(PR_FALSE)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -131,21 +136,69 @@ nsDownloadManager::Init()
|
|||
return gRDFService->RegisterDataSource(this, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::GetURI(char** aURI)
|
||||
nsresult
|
||||
nsDownloadManager::NotifyDownloadEnded(const char* aKey)
|
||||
{
|
||||
if (!aURI)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aURI = nsCRT::strdup("rdf:downloads");
|
||||
if (!(*aURI))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCStringKey key(aKey);
|
||||
if (mCurrDownloadItems->Exists(&key))
|
||||
mCurrDownloadItems->Remove(&key);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDownloadManager::GetProfileDownloadsFileURL(char** aDownloadsFileURL)
|
||||
{
|
||||
nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1"));
|
||||
nsCOMPtr<nsIFile> profileDir;
|
||||
|
||||
// get the profile directory
|
||||
nsresult rv = fileLocator->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(profileDir));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// add downloads.rdf to the path
|
||||
rv = profileDir->Append(PROFILE_DOWNLOAD_FILE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_GetURLSpecFromFile(profileDir, aDownloadsFileURL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDownloadManager::GetDownloadsContainer(nsIRDFContainer** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIRDFContainerUtils> rdfC(do_GetService(NS_RDF_CONTRACTID "/container-utils;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool isContainer;
|
||||
rv = mRDFContainerUtils->IsContainer(mInner, gNC_DownloadsRoot, &isContainer);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFContainer> ctr;
|
||||
|
||||
if (!isContainer) {
|
||||
rv = mRDFContainerUtils->MakeSeq(mInner, gNC_DownloadsRoot, getter_AddRefs(ctr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
ctr = do_CreateInstance(NS_RDF_CONTRACTID "/container;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = ctr->Init(mInner, gNC_DownloadsRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
*aResult = ctr;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIDownloadManager
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::AddItem(nsIDownloadItem* aDownloadItem)
|
||||
nsDownloadManager::AddDownload(nsIDownloadItem* aDownloadItem)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDownloadItem);
|
||||
|
||||
|
@ -231,17 +284,23 @@ nsDownloadManager::AddItem(nsIDownloadItem* aDownloadItem)
|
|||
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(mInner));
|
||||
rv = remote->Flush();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
nsCOMPtr<nsIWebBrowserPersist> persist;
|
||||
aDownloadItem->GetPersist(getter_AddRefs(persist));
|
||||
if (persist) {
|
||||
nsCOMPtr<nsIWebProgressListener> progressListener = do_QueryInterface(aDownloadItem);
|
||||
persist->SetProgressListener(progressListener);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::GetItem(const char* aID, nsIDownloadItem** aDownloadItem)
|
||||
nsDownloadManager::GetDownload(const char* aKey, nsIDownloadItem** aDownloadItem)
|
||||
{
|
||||
// if it's currently downloading we can get it from the table
|
||||
// XXX otherwise we need to look for it in the datasource and
|
||||
// XXX otherwise we should look for it in the datasource and
|
||||
// create a new nsIDownloadItem with the resource's properties
|
||||
nsCStringKey key(aID);
|
||||
nsCStringKey key(aKey);
|
||||
if (mCurrDownloadItems->Exists(&key)) {
|
||||
*aDownloadItem = NS_STATIC_CAST(nsIDownloadItem*, mCurrDownloadItems->Get(&key));
|
||||
NS_ADDREF(*aDownloadItem);
|
||||
|
@ -251,87 +310,82 @@ nsDownloadManager::GetItem(const char* aID, nsIDownloadItem** aDownloadItem)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::Open(nsIDOMWindowInternal* aOwnerDocument)
|
||||
nsDownloadManager::CancelDownload(const char* aKey)
|
||||
{
|
||||
// if we ever have third party download managers hooked up, we'll
|
||||
// open their UI here instead.
|
||||
nsCStringKey key(aKey);
|
||||
if (mCurrDownloadItems->Exists(&key)) {
|
||||
nsIDownloadItem* item = NS_STATIC_CAST(nsIDownloadItem*, mCurrDownloadItems->Get(&key));
|
||||
mCurrDownloadItems->Remove(&key);
|
||||
|
||||
// if a persist was provided, we can do the cancel ourselves.
|
||||
nsCOMPtr<nsIWebBrowserPersist> persist;
|
||||
item->GetPersist(getter_AddRefs(persist));
|
||||
if (persist)
|
||||
persist->CancelSave();
|
||||
|
||||
// if an observer was provided, notify that the download was cancelled.
|
||||
// if no persist was provided, this is necessary so that whatever transfer
|
||||
// component being used can cancel the download itself.
|
||||
nsCOMPtr<nsIObserver> observer;
|
||||
item->GetObserver(getter_AddRefs(observer));
|
||||
if (observer)
|
||||
return observer->Observe(item, "oncancel", nsnull);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::Open(nsIDOMWindowInternal* aOwnerWindow)
|
||||
{
|
||||
// if we ever have the capability to display the UI of third party dl managers,
|
||||
// we'll open their UI here instead.
|
||||
nsCOMPtr<nsIDOMWindow> newWindow;
|
||||
nsresult rv = aOwnerDocument->OpenDialog(NS_LITERAL_STRING(DOWNLOAD_MANAGER_URL),
|
||||
nsresult rv = aOwnerWindow->OpenDialog(NS_LITERAL_STRING(DOWNLOAD_MANAGER_URL),
|
||||
NS_LITERAL_STRING("_blank"),
|
||||
NS_LITERAL_STRING("chrome,titlebar,dependent,centerscreen"),
|
||||
nsnull, getter_AddRefs(newWindow));
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// whether or not mDocument is null is not a sufficient flag,
|
||||
// because we may be using a third party download manager that
|
||||
// doesn't use our architecture
|
||||
mMustUpdateUI = PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(newWindow);
|
||||
if (!target) return NS_ERROR_FAILURE;
|
||||
|
||||
return target->AddEventListener(NS_LITERAL_STRING("load"), this, PR_FALSE);
|
||||
rv = target->AddEventListener(NS_LITERAL_STRING("load"), this, PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return target->AddEventListener(NS_LITERAL_STRING("unload"), this, PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::UninitializeUI()
|
||||
{
|
||||
mDocument = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDownloadManager::NotifyDownloadEnded(const char* aTargetPath)
|
||||
{
|
||||
nsCStringKey key(aTargetPath);
|
||||
if (mCurrDownloadItems->Exists(&key))
|
||||
mCurrDownloadItems->Remove(&key);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDownloadManager::GetProfileDownloadsFileURL(char** aDownloadsFileURL)
|
||||
{
|
||||
nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1"));
|
||||
nsCOMPtr<nsIFile> profileDir;
|
||||
|
||||
// get the profile directory
|
||||
nsresult rv = fileLocator->Get(NS_APP_USER_PROFILE_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(profileDir));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// add downloads.rdf to the path
|
||||
rv = profileDir->Append(PROFILE_DOWNLOAD_FILE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_GetURLSpecFromFile(profileDir, aDownloadsFileURL);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDownloadManager::GetDownloadsContainer(nsIRDFContainer** aResult)
|
||||
nsDownloadManager::OpenProgressDialogFor(const char* aKey, nsIDOMWindowInternal* aOwnerWindow)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCStringKey key(aKey);
|
||||
if (!mCurrDownloadItems->Exists(&key))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
DownloadItem* item = NS_STATIC_CAST(DownloadItem*, mCurrDownloadItems->Get(&key));
|
||||
|
||||
nsCOMPtr<nsIRDFContainerUtils> rdfC(do_GetService(NS_RDF_CONTRACTID "/container-utils;1", &rv));
|
||||
nsCOMPtr<nsIProgressDialog> dialog(do_CreateInstance("@mozilla.org/progressdialog;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIWebProgressListener> listener = do_QueryInterface(dialog);
|
||||
item->SetDialogListener(listener);
|
||||
|
||||
return dialog->Open(aOwnerWindow, nsnull);
|
||||
}
|
||||
|
||||
PRBool isContainer;
|
||||
rv = mRDFContainerUtils->IsContainer(mInner, gNC_DownloadsRoot, &isContainer);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFContainer> ctr;
|
||||
|
||||
if (!isContainer) {
|
||||
rv = mRDFContainerUtils->MakeSeq(mInner, gNC_DownloadsRoot, getter_AddRefs(ctr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
ctr = do_CreateInstance(NS_RDF_CONTRACTID "/container;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = ctr->Init(mInner, gNC_DownloadsRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
*aResult = ctr;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
|
||||
return rv;
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::OnClose()
|
||||
{
|
||||
mDocument = nsnull;
|
||||
mMustUpdateUI = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -340,6 +394,13 @@ nsDownloadManager::GetDownloadsContainer(nsIRDFContainer** aResult)
|
|||
NS_IMETHODIMP
|
||||
nsDownloadManager::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEvent);
|
||||
|
||||
nsAutoString eventType;
|
||||
aEvent->GetType(eventType);
|
||||
if (eventType.Equals(NS_LITERAL_STRING("unload")))
|
||||
return OnClose();
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsresult rv = aEvent->GetTarget(getter_AddRefs(target));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -416,6 +477,19 @@ nsDownloadManager::HandleEvent(nsIDOMEvent* aEvent)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFDataSource
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::GetURI(char** aURI)
|
||||
{
|
||||
if (!aURI)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aURI = nsCRT::strdup("rdf:downloads");
|
||||
if (!(*aURI))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::GetSource(nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
|
@ -647,6 +721,29 @@ DownloadItem::UpdateProgressInfo()
|
|||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DownloadItem::SetDownloadManager(nsDownloadManager* aDownloadManager)
|
||||
{
|
||||
mDownloadManager = aDownloadManager;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DownloadItem::SetDialogListener(nsIWebProgressListener* aDialogListener)
|
||||
{
|
||||
mDialogListener = aDialogListener;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DownloadItem::GetDialogListener(nsIWebProgressListener** aDialogListener)
|
||||
{
|
||||
*aDialogListener = mDialogListener;
|
||||
NS_ADDREF(*aDialogListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(DownloadItem, nsIWebProgressListener, nsIDownloadItem)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -672,8 +769,8 @@ DownloadItem::OnProgressChange(nsIWebProgress *aWebProgress,
|
|||
aCurTotalProgress, aMaxTotalProgress);
|
||||
}
|
||||
|
||||
if (mPropertiesListener) {
|
||||
mPropertiesListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress,
|
||||
if (mDialogListener) {
|
||||
mDialogListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress,
|
||||
aCurTotalProgress, aMaxTotalProgress);
|
||||
}
|
||||
|
||||
|
@ -690,8 +787,8 @@ DownloadItem::OnLocationChange(nsIWebProgress *aWebProgress,
|
|||
if (mDownloadManager->MustUpdateUI() && mInternalListener)
|
||||
mInternalListener->OnLocationChange(aWebProgress, aRequest, aLocation);
|
||||
|
||||
if (mPropertiesListener)
|
||||
mPropertiesListener->OnLocationChange(aWebProgress, aRequest, aLocation);
|
||||
if (mDialogListener)
|
||||
mDialogListener->OnLocationChange(aWebProgress, aRequest, aLocation);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -707,8 +804,8 @@ DownloadItem::OnStatusChange(nsIWebProgress *aWebProgress,
|
|||
if (mDownloadManager->MustUpdateUI() && mInternalListener)
|
||||
mInternalListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
||||
|
||||
if (mPropertiesListener)
|
||||
mPropertiesListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
||||
if (mDialogListener)
|
||||
mDialogListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -718,23 +815,24 @@ DownloadItem::OnStateChange(nsIWebProgress* aWebProgress,
|
|||
nsIRequest* aRequest, PRInt32 aStateFlags,
|
||||
PRUint32 aStatus)
|
||||
{
|
||||
if (aStateFlags & STATE_START)
|
||||
if (aStateFlags & STATE_START) {
|
||||
mTimeStarted = PR_Now();
|
||||
mRequest = aRequest;
|
||||
}
|
||||
else if (aStateFlags & STATE_STOP) {
|
||||
char* path;
|
||||
mTarget->GetPath(&path);
|
||||
mDownloadManager->NotifyDownloadEnded(path);
|
||||
}
|
||||
|
||||
|
||||
if (mListener)
|
||||
mListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
|
||||
|
||||
if (mDownloadManager->MustUpdateUI() && mInternalListener)
|
||||
mInternalListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
|
||||
|
||||
if (mPropertiesListener)
|
||||
mPropertiesListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
|
||||
if (mDialogListener)
|
||||
mDialogListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -749,8 +847,8 @@ DownloadItem::OnSecurityChange(nsIWebProgress *aWebProgress,
|
|||
if (mDownloadManager->MustUpdateUI() && mInternalListener)
|
||||
mInternalListener->OnSecurityChange(aWebProgress, aRequest, aState);
|
||||
|
||||
if (mPropertiesListener)
|
||||
mPropertiesListener->OnSecurityChange(aWebProgress, aRequest, aState);
|
||||
if (mDialogListener)
|
||||
mDialogListener->OnSecurityChange(aWebProgress, aRequest, aState);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -847,23 +945,31 @@ DownloadItem::GetInternalListener(nsIDownloadProgressListener** aInternalListene
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DownloadItem::SetPropertiesListener(nsIWebProgressListener* aPropertiesListener)
|
||||
DownloadItem::SetPersist(nsIWebBrowserPersist* aPersist)
|
||||
{
|
||||
mPropertiesListener = aPropertiesListener;
|
||||
mPersist = aPersist;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DownloadItem::GetPropertiesListener(nsIWebProgressListener** aPropertiesListener)
|
||||
DownloadItem::GetPersist(nsIWebBrowserPersist** aPersist)
|
||||
{
|
||||
*aPropertiesListener = mPropertiesListener;
|
||||
NS_ADDREF(*aPropertiesListener);
|
||||
*aPersist = mPersist;
|
||||
NS_ADDREF(*aPersist);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DownloadItem::SetDownloadManager(nsDownloadManager* aDownloadManager)
|
||||
NS_IMETHODIMP
|
||||
DownloadItem::SetObserver(nsIObserver* aObserver)
|
||||
{
|
||||
mDownloadManager = aDownloadManager;
|
||||
mObserver = aObserver;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DownloadItem::GetObserver(nsIObserver** aObserver)
|
||||
{
|
||||
*aObserver = mObserver;
|
||||
NS_ADDREF(*aObserver);
|
||||
return NS_OK;
|
||||
}
|
|
@ -54,6 +54,9 @@
|
|||
#include "nsIURI.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
class nsDownloadManager : public nsIDownloadManager,
|
||||
public nsIRDFDataSource,
|
||||
|
@ -76,7 +79,7 @@ protected:
|
|||
nsresult GetDownloadsContainer(nsIRDFContainer** aResult);
|
||||
nsresult GetProfileDownloadsFileURL(char** aDownloadsFileURL);
|
||||
nsresult NotifyDownloadEnded(const char* aTargetPath);
|
||||
PRBool MustUpdateUI() { if (mDocument) return PR_TRUE; return PR_FALSE; }
|
||||
PRBool MustUpdateUI() { return mMustUpdateUI; }
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIRDFDataSource> mInner;
|
||||
|
@ -85,11 +88,12 @@ private:
|
|||
nsCOMPtr<nsIRDFContainerUtils> mRDFContainerUtils;
|
||||
nsHashtable* mCurrDownloadItems;
|
||||
|
||||
PRBool mMustUpdateUI;
|
||||
|
||||
friend class DownloadItem;
|
||||
};
|
||||
|
||||
class DownloadItem : public nsIWebProgressListener,
|
||||
public nsIDownloadItem
|
||||
class DownloadItem : public nsIDownloadItem
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
|
@ -105,6 +109,8 @@ protected:
|
|||
nsresult SetDownloadManager(nsDownloadManager* aDownloadManager);
|
||||
nsresult SetInternalListener(nsIDownloadProgressListener* aInternalListener);
|
||||
nsresult GetInternalListener(nsIDownloadProgressListener** aInternalListener);
|
||||
nsresult SetDialogListener(nsIWebProgressListener* aInternalListener);
|
||||
nsresult GetDialogListener(nsIWebProgressListener** aInternalListener);
|
||||
private:
|
||||
nsIRDFResource* mDownloadItem;
|
||||
nsIRDFDataSource* mDataSource;
|
||||
|
@ -115,7 +121,10 @@ private:
|
|||
nsCOMPtr<nsIURI> mSource;
|
||||
nsCOMPtr<nsIWebProgressListener> mListener;
|
||||
nsCOMPtr<nsIDownloadProgressListener> mInternalListener;
|
||||
nsCOMPtr<nsIWebProgressListener> mPropertiesListener;
|
||||
nsCOMPtr<nsIWebProgressListener> mDialogListener;
|
||||
nsCOMPtr<nsIWebBrowserPersist> mPersist;
|
||||
nsCOMPtr<nsIRequest> mRequest;
|
||||
nsCOMPtr<nsIObserver> mObserver;
|
||||
|
||||
PRInt32 mCurTotalProgress;
|
||||
PRInt32 mMaxTotalProgress;
|
||||
|
@ -124,5 +133,4 @@ private:
|
|||
|
||||
friend class nsDownloadManager;
|
||||
};
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче