From aee7bed9534044387da7cb01f688706de8ef50ec Mon Sep 17 00:00:00 2001 From: Marco Perez Date: Sun, 31 May 2009 04:42:02 +0200 Subject: [PATCH] Bug 495583 - [SeaMonkey] Remove SUITE_USING_XPFE_DM remnants; r=neil --- toolkit/components/Makefile.in | 2 - toolkit/components/build/Makefile.in | 2 - .../components/build/nsToolkitCompsModule.cpp | 6 - toolkit/mozapps/downloads/Makefile.in | 2 - toolkit/toolkit-makefiles.sh | 4 - xpfe/components/Makefile.in | 4 - xpfe/components/build/Makefile.in | 13 - xpfe/components/build/nsModule.cpp | 17 - xpfe/components/download-manager/Makefile.in | 49 - .../download-manager/public/Makefile.in | 54 - .../download-manager/public/nsIDownload.idl | 136 -- .../public/nsIDownloadManager.idl | 211 --- .../public/nsIDownloadProgressListener.idl | 95 -- .../public/nsIProgressDialog.idl | 100 -- .../download-manager/resources/Makefile.in | 50 - .../resources/downloadmanager.js | 462 ------ .../resources/downloadmanager.xul | 267 --- .../download-manager/resources/jar.mn | 7 - .../locale/en-US/downloadmanager.dtd | 31 - .../locale/en-US/downloadmanager.properties | 13 - .../resources/mac/Makefile.in | 45 - .../resources/mac/dlmanagermenuoverlay.xul | 86 - .../download-manager/resources/mac/jar.mn | 2 - .../download-manager/src/Makefile.in | 90 - .../src/nsDownloadManager.cpp | 1475 ----------------- .../download-manager/src/nsDownloadManager.h | 188 --- .../src/nsDownloadProgressListener.js | 314 ---- .../download-manager/src/nsDownloadProxy.h | 99 -- 28 files changed, 3824 deletions(-) delete mode 100644 xpfe/components/download-manager/Makefile.in delete mode 100644 xpfe/components/download-manager/public/Makefile.in delete mode 100644 xpfe/components/download-manager/public/nsIDownload.idl delete mode 100644 xpfe/components/download-manager/public/nsIDownloadManager.idl delete mode 100644 xpfe/components/download-manager/public/nsIDownloadProgressListener.idl delete mode 100644 xpfe/components/download-manager/public/nsIProgressDialog.idl delete mode 100644 xpfe/components/download-manager/resources/Makefile.in delete mode 100644 xpfe/components/download-manager/resources/downloadmanager.js delete mode 100644 xpfe/components/download-manager/resources/downloadmanager.xul delete mode 100644 xpfe/components/download-manager/resources/jar.mn delete mode 100644 xpfe/components/download-manager/resources/locale/en-US/downloadmanager.dtd delete mode 100644 xpfe/components/download-manager/resources/locale/en-US/downloadmanager.properties delete mode 100644 xpfe/components/download-manager/resources/mac/Makefile.in delete mode 100644 xpfe/components/download-manager/resources/mac/dlmanagermenuoverlay.xul delete mode 100644 xpfe/components/download-manager/resources/mac/jar.mn delete mode 100644 xpfe/components/download-manager/src/Makefile.in delete mode 100644 xpfe/components/download-manager/src/nsDownloadManager.cpp delete mode 100644 xpfe/components/download-manager/src/nsDownloadManager.h delete mode 100644 xpfe/components/download-manager/src/nsDownloadProgressListener.js delete mode 100644 xpfe/components/download-manager/src/nsDownloadProxy.h diff --git a/toolkit/components/Makefile.in b/toolkit/components/Makefile.in index 7a75119e8b77..3217ca47bcc1 100644 --- a/toolkit/components/Makefile.in +++ b/toolkit/components/Makefile.in @@ -108,11 +108,9 @@ endif # MOZ_XUL endif # MOZ_THUNDERBIRD -ifndef SUITE_USING_XPFE_DM ifdef MOZ_RDF DIRS += downloads endif -endif # SUITE_USING_XPFE_DM ifdef MOZ_URL_CLASSIFIER DIRS += url-classifier diff --git a/toolkit/components/build/Makefile.in b/toolkit/components/build/Makefile.in index 2a605d4f2a9a..3c8cc800c1f3 100644 --- a/toolkit/components/build/Makefile.in +++ b/toolkit/components/build/Makefile.in @@ -123,11 +123,9 @@ REQUIRES += parentalcontrols endif endif -ifndef SUITE_USING_XPFE_DM ifdef MOZ_RDF SHARED_LIBRARY_LIBS += ../downloads/src/$(LIB_PREFIX)download_s.$(LIB_SUFFIX) endif -endif ifdef ALERTS_SERVICE SHARED_LIBRARY_LIBS += ../alerts/src/$(LIB_PREFIX)alerts_s.$(LIB_SUFFIX) diff --git a/toolkit/components/build/nsToolkitCompsModule.cpp b/toolkit/components/build/nsToolkitCompsModule.cpp index 81c98037d6c2..707ce33a2303 100644 --- a/toolkit/components/build/nsToolkitCompsModule.cpp +++ b/toolkit/components/build/nsToolkitCompsModule.cpp @@ -49,12 +49,10 @@ #include "nsAlertsService.h" #endif -#ifndef SUITE_USING_XPFE_DM #ifdef MOZ_RDF #include "nsDownloadManager.h" #include "nsDownloadProxy.h" #endif -#endif #include "nsTypeAheadFind.h" @@ -83,13 +81,11 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsParentalControlsServiceWin) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAlertsService) #endif -#ifndef SUITE_USING_XPFE_DM #ifdef MOZ_RDF NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsDownloadManager, nsDownloadManager::GetSingleton) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadProxy) #endif -#endif NS_GENERIC_FACTORY_CONSTRUCTOR(nsTypeAheadFind) @@ -147,7 +143,6 @@ static const nsModuleComponentInfo components[] = NS_PARENTALCONTROLSSERVICE_CONTRACTID, nsParentalControlsServiceWinConstructor }, #endif -#ifndef SUITE_USING_XPFE_DM #ifdef MOZ_RDF { "Download Manager", NS_DOWNLOADMANAGER_CID, @@ -157,7 +152,6 @@ static const nsModuleComponentInfo components[] = NS_DOWNLOAD_CID, NS_TRANSFER_CONTRACTID, nsDownloadProxyConstructor }, -#endif #endif { "TypeAheadFind Component", NS_TYPEAHEADFIND_CID, diff --git a/toolkit/mozapps/downloads/Makefile.in b/toolkit/mozapps/downloads/Makefile.in index 83fcfb78a09e..97e17e8708da 100644 --- a/toolkit/mozapps/downloads/Makefile.in +++ b/toolkit/mozapps/downloads/Makefile.in @@ -42,12 +42,10 @@ VPATH = @srcdir@ include $(topsrcdir)/config/config.mk -ifndef SUITE_USING_XPFE_DM DIRS = src ifdef ENABLE_TESTS DIRS += tests endif -endif include $(topsrcdir)/config/rules.mk diff --git a/toolkit/toolkit-makefiles.sh b/toolkit/toolkit-makefiles.sh index 1a038a3e6a03..20b7992a01f3 100644 --- a/toolkit/toolkit-makefiles.sh +++ b/toolkit/toolkit-makefiles.sh @@ -559,10 +559,6 @@ MAKEFILES_xpfe=" xpfe/browser/src/Makefile xpfe/components/Makefile xpfe/components/directory/Makefile - xpfe/components/download-manager/Makefile - xpfe/components/download-manager/src/Makefile - xpfe/components/download-manager/public/Makefile - xpfe/components/download-manager/resources/Makefile xpfe/components/find/Makefile xpfe/components/find/public/Makefile xpfe/components/find/src/Makefile diff --git a/xpfe/components/Makefile.in b/xpfe/components/Makefile.in index 63dcde87c05b..35a67b663080 100644 --- a/xpfe/components/Makefile.in +++ b/xpfe/components/Makefile.in @@ -74,10 +74,6 @@ ifneq (,$(MOZ_THUNDERBIRD)$(MOZ_SUITE)$(MOZ_SUNBIRD)) DIRS += autocomplete endif -ifdef SUITE_USING_XPFE_DM -DIRS += download-manager -endif - ifdef MOZ_HAVE_BROWSER DIRS += \ directory \ diff --git a/xpfe/components/build/Makefile.in b/xpfe/components/build/Makefile.in index f38bcf81c80f..bdd0c3e39c7c 100644 --- a/xpfe/components/build/Makefile.in +++ b/xpfe/components/build/Makefile.in @@ -77,19 +77,6 @@ SHARED_LIBRARY_LIBS += ../../browser/src/$(LIB_PREFIX)mozbrwsr_s.$(LIB_SUFFIX) LOCAL_INCLUDES += -I$(srcdir)/../../browser/src endif -# Suite xpfe download manager includes -ifdef SUITE_USING_XPFE_DM -REQUIRES += \ - downloadmanager \ - intl \ - widget \ - mimetype \ - $(NULL) - -SHARED_LIBRARY_LIBS += ../download-manager/src/$(LIB_PREFIX)downloadmanager_s.$(LIB_SUFFIX) -LOCAL_INCLUDES += -I$(srcdir)/../download-manager/src -endif - ifeq ($(OS_ARCH),WINNT) OS_LIBS += $(call EXPAND_LIBNAME,ole32 shell32) endif diff --git a/xpfe/components/build/nsModule.cpp b/xpfe/components/build/nsModule.cpp index de06907c1045..ea7dbc9e38a6 100644 --- a/xpfe/components/build/nsModule.cpp +++ b/xpfe/components/build/nsModule.cpp @@ -45,11 +45,6 @@ #include "nsRDFCID.h" #endif -#ifdef SUITE_USING_XPFE_DM -#include "nsDownloadManager.h" -#include "nsDownloadProxy.h" -#endif - #if !defined(MOZ_MACBROWSER) #include "nsBrowserStatusFilter.h" #include "nsBrowserInstance.h" @@ -68,11 +63,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserStatusFilter) NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserInstance) #endif -#ifdef SUITE_USING_XPFE_DM -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDownloadManager, Init) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadProxy) -#endif - static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, @@ -117,13 +107,6 @@ static const nsModuleComponentInfo components[] = { nsHTTPIndexConstructor }, #endif -#ifdef SUITE_USING_XPFE_DM - { "Download Manager", NS_DOWNLOADMANAGER_CID, NS_DOWNLOADMANAGER_CONTRACTID, - nsDownloadManagerConstructor }, - { "Download", NS_DOWNLOAD_CID, NS_TRANSFER_CONTRACTID, - nsDownloadProxyConstructor }, -#endif - #if !defined(MOZ_MACBROWSER) { NS_BROWSERSTATUSFILTER_CLASSNAME, NS_BROWSERSTATUSFILTER_CID, diff --git a/xpfe/components/download-manager/Makefile.in b/xpfe/components/download-manager/Makefile.in deleted file mode 100644 index 12689e5bf183..000000000000 --- a/xpfe/components/download-manager/Makefile.in +++ /dev/null @@ -1,49 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# 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/ -# -# 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): -# -# Alternatively, the contents of this file may be used under the terms of -# either of 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 MPL, 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 MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = downloadmanager -DIRS = public src resources - -include $(topsrcdir)/config/rules.mk - diff --git a/xpfe/components/download-manager/public/Makefile.in b/xpfe/components/download-manager/public/Makefile.in deleted file mode 100644 index 7640a059e2ee..000000000000 --- a/xpfe/components/download-manager/public/Makefile.in +++ /dev/null @@ -1,54 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# 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/ -# -# 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): -# -# Alternatively, the contents of this file may be used under the terms of -# either of 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 MPL, 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 MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = downloadmanager - -XPIDLSRCS = nsIDownloadManager.idl \ - nsIDownloadProgressListener.idl \ - nsIDownload.idl \ - nsIProgressDialog.idl \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - diff --git a/xpfe/components/download-manager/public/nsIDownload.idl b/xpfe/components/download-manager/public/nsIDownload.idl deleted file mode 100644 index 8141fa85fab7..000000000000 --- a/xpfe/components/download-manager/public/nsIDownload.idl +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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 - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsITransfer.idl" - -interface nsIURI; -interface nsILocalFile; -interface nsIObserver; -interface nsICancelable; -interface nsIWebProgressListener; -interface nsIMIMEInfo; - -/** - * Represents a download object. - * - * @note This object is no longer updated once it enters a completed state. - * Completed states are the following: - * nsIDownloadManager::DOWNLOAD_FINISHED - * nsIDownloadManager::DOWNLOAD_FAILED - * nsIDownloadManager::DOWNLOAD_CANCELED - */ -[scriptable, uuid(974db2c6-fbd2-4de1-8d24-f54ce4f3e8bc)] -interface nsIDownload : nsITransfer { - - /** - * The target of a download is always a file on the local file system. - */ - readonly attribute nsILocalFile targetFile; - - /** - * The percentage of transfer completed. - * If the file size is unknown it'll be -1 here. - */ - readonly attribute PRInt32 percentComplete; - - /** - * The amount of bytes downloaded so far. - */ - readonly attribute PRUint64 amountTransferred; - - /** - * The size of file in bytes. - * Unknown size is represented by LL_MAXUINT. - */ - readonly attribute PRUint64 size; - - /** - * The source of the transfer. - */ - readonly attribute nsIURI source; - - /** - * The target of the transfer. - */ - readonly attribute nsIURI target; - - /** - * Object that can be used to cancel the download. - * Will be null after the download is finished. - */ - readonly attribute nsICancelable cancelable; - - /** - * The user-readable description of the transfer. - */ - readonly attribute AString displayName; - - /** - * The time a transfer was started. - */ - readonly attribute long long startTime; - - /** - * The speed of the transfer in bytes/sec. - */ - readonly attribute double speed; - - /** - * Optional. If set, it will contain the target's relevant MIME information. - * This includes its MIME Type, helper app, and whether that helper should be - * executed. - */ - readonly attribute nsIMIMEInfo MIMEInfo; - - /** - * The id of the download that is stored in the database. - */ - readonly attribute unsigned long id; - - /** - * The state of the download. - * @see nsIDownloadManager and nsIXPInstallManagerUI - */ - readonly attribute short state; -}; - -%{C++ -// {E3FA9D0A-1DD1-11B2-BDEF-8C720B597445} -#define NS_DOWNLOAD_CID \ - { 0xe3fa9d0a, 0x1dd1, 0x11b2, { 0xbd, 0xef, 0x8c, 0x72, 0x0b, 0x59, 0x74, 0x45 } } -%} diff --git a/xpfe/components/download-manager/public/nsIDownloadManager.idl b/xpfe/components/download-manager/public/nsIDownloadManager.idl deleted file mode 100644 index 1330d1e21567..000000000000 --- a/xpfe/components/download-manager/public/nsIDownloadManager.idl +++ /dev/null @@ -1,211 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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 - * Ben Goodger - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Keeps track of ongoing downloads, in the form of nsIDownload's. - -#include "nsISupports.idl" - -interface nsIDOMWindow; -interface nsIURI; -interface nsILocalFile; -interface nsIDownload; -interface nsICancelable; -interface nsIMIMEInfo; - -[scriptable, uuid(9cdfcea3-fbe4-4ba1-a0fd-fe273097ddfa)] -interface nsIDownloadManager : nsISupports { - - // Methods called by clients to carry out various managing functions - - /** - * Creates an nsIDownload and adds it to be managed by the download manager. - * - * @param aSource The source URI of the transfer. Must not be null. - * - * @param aTarget The target URI of the transfer. Must not be null. - * - * @param aDisplayName The user-readable description of the transfer. - * Can be empty. - * - * @param aMIMEInfo The MIME info associated with the target, - * including MIME type and helper app when appropriate. - * This parameter is optional. - * - * @param startTime Time when the download started (ie, when the first - * response from the server was received) - * @param aTempFile The location of a temporary file; i.e. a file in which - * the received data will be stored, but which is not - * equal to the target file. (will be moved to the real - * target by the caller, when the download is finished) - * May be null. - * - * @param aCancelable An object that can be used to abort the download. - * Must not be null. - - * @return The newly created download item with the passed-in properties. - */ - nsIDownload addDownload(in nsIURI aSource, - in nsIURI aTarget, - in AString aDisplayName, - in nsIMIMEInfo aMIMEInfo, - in PRTime startTime, - in nsILocalFile aTempFile, - in nsICancelable aCancelable); - - /** - * Retrieves an in-progress download managed by the download manager. - * - * @param aTargetPath A UTF8-encoded path to the target file. - * - * @return The download with the specified path. - */ - nsIDownload getDownload(in AUTF8String aTargetPath); - - /** - * Cancels the download with the specified target path if it's - * currently in progress. If a "persist" was specified for the download, - * nsIWebBrowserPersist::CancelSave will be called. If an observer was set - * on the nsIDownload, it will be notified with the "oncancel" topic. Clients - * that don't provide a "persist" must listen for this topic and cancel the - * download. - * - * @param aTargetPath The target path of the download to - * be cancelled. - */ - void cancelDownload(in AUTF8String aTargetPath); - - /** - * Pause a download to allow later resumal. This may or may not close - * the network connection. In either case, new data won't be received. - * - * @param aDownload Download to pause, as returned by getDownload or - * addDownload. - * - * Trying to pause a download that is already paused will throw - * NS_ERROR_NOT_AVAILABLE. - * NS_ERROR_UNEXPECTED may be thrown to indicate an internal error. - * Any exception defined by nsIRequest::Suspend may be thrown. - * No other exceptions will be thrown. - */ - void pauseDownload(in nsIDownload aDownload); - - /** - * Resume a previously paused download. - * @param aTargetPath Target path of the download to be resumed. - * - * @throws NS_ERROR_NOT_RESUMABLE If resuming is not supported for this - * entity, or if the entity has changed since - * the download was paused - * @throws NS_ERROR_NOT_AVAILABLE If no such download exists, or if the - * download was not paused, or if the - * download is finished already. - * In addition, this may throw NS_ERROR_OUT_OF_MEMORY, or any error defined by - * nsIResumableChannel::setEntityID, nsIResumableChannel::asyncOpenAt, - * nsIRequest::Resume, or nsIIOService::newChannel. - * Also, NS_ERROR_UNEXPECTED may be thrown to indicate an internal error. - */ - void resumeDownload(in AUTF8String aTargetPath); - - /** - * Removes the download with the specified target path if it's not - * currently in progress. Whereas cancelDownload simply cancels the transfer - * but retains information about it, removeDownload removes all knowledge of it. - * - * @param aTargetPath The target path of the download to - * be removed. - */ - void removeDownload(in AUTF8String aTargetPath); - - // UI-related methods - - /** - * Opens the Download Manager front end. - * - * @param aParent The parent, or opener, of the front end (optional). - * @param aDownload A download to pass to the manager window. Useful - * if, for example, you want the window to select a - * certain download (optional). - */ - void open(in nsIDOMWindow aParent, in nsIDownload aDownload); - - /** - * Opens an individual progress dialog displaying progress for the download. - * - * @param aDownload The download object to display progress for, as returned - * by getDownload or addDownload. - * - * @param aParent The parent, or opener, of the front end (optional). - * - * @param aCancelDownloadOnClose Whether closing the dialog - * should cancel the download. - */ - - void openProgressDialogFor(in nsIDownload aDownload, - in nsIDOMWindow aParent, - in boolean aCancelDownloadOnClose); - - /** - * Called when the download manager front end is closed. Useful for - * third party managers to let us know when they've closed. - */ - - void onClose(); - - /** - * Indicate that a batch update (e.g. mass removal) is about to start. - */ - - void startBatchUpdate(); - - /** - * Indicate that a batch update is ending. - */ - - void endBatchUpdate(); -}; - - -%{C++ -#define NS_DOWNLOADMANAGER_CONTRACTID "@mozilla.org/download-manager;1" -#define NS_DOWNLOADMANAGER_CLASSNAME "Mozilla Download Manager" -// {EDB0490E-1DD1-11B2-83B8-DBF8D85906A6} -#define NS_DOWNLOADMANAGER_CID \ - { 0xedb0490e, 0x1dd1, 0x11b2, { 0x83, 0xb8, 0xdb, 0xf8, 0xd8, 0x59, 0x06, 0xa6 } } -%} diff --git a/xpfe/components/download-manager/public/nsIDownloadProgressListener.idl b/xpfe/components/download-manager/public/nsIDownloadProgressListener.idl deleted file mode 100644 index 170effe14ad4..000000000000 --- a/xpfe/components/download-manager/public/nsIDownloadProgressListener.idl +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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 - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* A minimally extended progress listener used by download manager - * to update its default UI. This is implemented in nsDownloadProgressListener.js. - * See nsIWebProgressListener for documentation, and use its constants. This isn't - * too pretty, but the alternative is having this extend nsIWebProgressListener and - * adding an |item| attribute, which would mean a separate nsIDownloadProgressListener - * for every nsIDownloadItem, which is a waste... - */ - -#include "nsISupports.idl" - -interface nsIWebProgress; -interface nsIRequest; -interface nsIURI; -interface nsIDownload; -interface nsIDOMDocument; - -[scriptable, uuid(c7e22278-53a7-49d9-999f-0e7861738b50)] -interface nsIDownloadProgressListener : nsISupports { - - /** - * document - * The document of the download manager frontend. - */ - - attribute nsIDOMDocument document; - - void onStateChange(in nsIWebProgress aWebProgress, - in nsIRequest aRequest, - in unsigned long aStateFlags, - in nsresult aStatus, - in nsIDownload aDownload); - - void onProgressChange(in nsIWebProgress aWebProgress, - in nsIRequest aRequest, - in long long aCurSelfProgress, - in long long aMaxSelfProgress, - in long long aCurTotalProgress, - in long long aMaxTotalProgress, - in nsIDownload aDownload); - - void onStatusChange(in nsIWebProgress aWebProgress, - in nsIRequest aRequest, - in nsresult aStatus, - in wstring aMessage, - in nsIDownload aDownload); - - void onLocationChange(in nsIWebProgress aWebProgress, - in nsIRequest aRequest, - in nsIURI aLocation, - in nsIDownload aDownload); - - void onSecurityChange(in nsIWebProgress aWebProgress, - in nsIRequest aRequest, - in unsigned long aState, - in nsIDownload aDownload); - -}; diff --git a/xpfe/components/download-manager/public/nsIProgressDialog.idl b/xpfe/components/download-manager/public/nsIProgressDialog.idl deleted file mode 100644 index 406e9e5692b9..000000000000 --- a/xpfe/components/download-manager/public/nsIProgressDialog.idl +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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): - * Bill Law law@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 - * 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIDownload.idl" - -interface nsIDOMWindow; -interface nsIObserver; - -/* nsIProgressDialog - * - * These objects are used to display progress notifications to the user. - * They are displayed while files are being saved to disk, for example. - * - * Typical usage is to: - * 1. Create an instance, via the component manager CreateInstance() - * method. - * 2. Set appropriate attributes that control the display and behavior - * of the dialog. - * 3. Open the dialog. - * 4. Send progress notifications to the dialog, via its - * nsIDownloadProgressListener methods. - * 5. Close the dialog when the operation completes, or when the user - * closes it manually. - * 6. Release the instance. The instance will be referenced by - * the dialog itself, so it won't get freed until the dialog closes. - * The dialog will keep the instance alive, so typically one does - * not need to hold a reference to it. - */ - -[scriptable, uuid(20e790a2-76c6-462d-851a-22ab6cbbe48b)] -interface nsIProgressDialog : nsIDownload { - /** - * Open the dialog - * - * @param aParent Parent window; optional (if null, then - * a top-level window is created) - */ - void open( in nsIDOMWindow aParent ); - - /** - * Whether the download should be cancelled when the progress - * dialog is closed using the standard OS close box. This is - * useful for showing the progress dialog as an information - * window, which is what download manager does. - */ - attribute PRBool cancelDownloadOnClose; - - /** - * Observer for this dialog. If set, receives the following topics: - * oncancel - observer should cancel the transfer - * onpause - observer should suspend the transfer - * onresume - observer should resume the suspended transfer - * For each of those, the subject will be the nsIProgressDialog. - */ - attribute nsIObserver observer; - - /** - * The dialog object itself. This might be null if the dialog isn't - * open yet, or has been closed. - */ - attribute nsIDOMWindow dialog; -}; - - diff --git a/xpfe/components/download-manager/resources/Makefile.in b/xpfe/components/download-manager/resources/Makefile.in deleted file mode 100644 index d02196ad9b7f..000000000000 --- a/xpfe/components/download-manager/resources/Makefile.in +++ /dev/null @@ -1,50 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# 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/ -# -# 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): -# -# Alternatively, the contents of this file may be used under the terms of -# either of 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 MPL, 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 MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) -DIRS = mac -endif - -include $(topsrcdir)/config/rules.mk - diff --git a/xpfe/components/download-manager/resources/downloadmanager.js b/xpfe/components/download-manager/resources/downloadmanager.js deleted file mode 100644 index bb60ab943406..000000000000 --- a/xpfe/components/download-manager/resources/downloadmanager.js +++ /dev/null @@ -1,462 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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): - * Ben Goodger (Original Author) - * Blake Ross - * Jan Varga - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -const NC_NS = "http://home.netscape.com/NC-rdf#"; - -var gDownloadView = null; -var gDownloadManager = null; -var gRDFService = null; -var gNC_File = null; -var gFileHandler = null; -var gStatusBar = null; -var gCannotLaunch = ((navigator.platform.indexOf("Win") == -1) && - (navigator.platform.indexOf("OS/2") == -1) && - (navigator.platform.indexOf("Mac") == -1) && - (navigator.platform.indexOf("BeOS") == -1)); - -const dlObserver = { - observe: function(subject, topic, state) { - if (topic != "download-starting") return; - selectDownload(subject.QueryInterface(Components.interfaces.nsIDownload)); - } -}; - -function selectDownload(aDownload) -{ - var dlElt = document.getElementById(aDownload.targetFile.path); - var dlIndex = gDownloadView.contentView.getIndexOfItem(dlElt); - gDownloadView.view.selection.select(dlIndex); - gDownloadView.treeBoxObject.ensureRowIsVisible(dlIndex); -} - -function DLManagerStartup() -{ - if (!window.arguments.length) - return; - - try { - var observerService = Components.classes[kObserverServiceProgID] - .getService(Components.interfaces.nsIObserverService); - observerService.addObserver(dlObserver, "download-starting", false); - } - catch (ex) { - } - - const rdfSvcContractID = "@mozilla.org/rdf/rdf-service;1"; - const rdfSvcIID = Components.interfaces.nsIRDFService; - gRDFService = Components.classes[rdfSvcContractID].getService(rdfSvcIID); - - gNC_File = gRDFService.GetResource(NC_NS + "File"); - - gDownloadView = document.getElementById("downloadView"); - setSortVariables(gDownloadView); - - const dlmgrContractID = "@mozilla.org/download-manager;1"; - const dlmgrIID = Components.interfaces.nsIDownloadManager; - gDownloadManager = Components.classes[dlmgrContractID].getService(dlmgrIID); - - const ioSvcContractID = "@mozilla.org/network/io-service;1"; - const ioSvcIID = Components.interfaces.nsIIOService; - var ioService = Components.classes[ioSvcContractID].getService(ioSvcIID); - - const fileHandlerIID = Components.interfaces.nsIFileProtocolHandler; - gFileHandler = ioService.getProtocolHandler("file") - .QueryInterface(fileHandlerIID); - - var ds = window.arguments[0]; - gDownloadView.database.AddDataSource(ds); - gDownloadView.builder.rebuild(); - window.setTimeout(onRebuild, 0); - - // correct keybinding command attributes which don't do our business yet - var key = document.getElementById("key_delete"); - if (key.getAttribute("command")) - key.setAttribute("command", "cmd_remove"); - key = document.getElementById("key_delete2"); - if (key.getAttribute("command")) - key.setAttribute("command", "cmd_remove"); - - document.getElementById("btn_openfile").hidden = gCannotLaunch; - document.getElementById("downloadPaneContext-openfile").hidden = gCannotLaunch; -} - -function onRebuild() { - gDownloadView.controllers.appendController(downloadViewController); - gDownloadView.focus(); - - // If the window was opened automatically because - // a download started, select the new download - if (window.arguments.length > 1 && window.arguments[1]) { - var dl = window.arguments[1]; - selectDownload(dl.QueryInterface(Components.interfaces.nsIDownload)); - } - else if (gDownloadView.view && gDownloadView.view.rowCount > 0) { - // Select the first item in the view, if any. - gDownloadView.view.selection.select(0); - } -} - -function onSelect(aEvent) { - if (!gStatusBar) - gStatusBar = document.getElementById("statusbar-text"); - - var selectionCount = gDownloadView.view.selection.count; - if (selectionCount == 1) - gStatusBar.label = createLocalFile(getSelectedItem().id).path; - else - gStatusBar.label = ""; - - window.updateCommands("tree-select"); -} - -function onTrigger() { - if (downloadViewController.isCommandEnabled('cmd_properties')) - goDoCommand('cmd_properties'); - else if (downloadViewController.isCommandEnabled('cmd_openfile')) - goDoCommand('cmd_openfile'); - else if (downloadViewController.isCommandEnabled('cmd_showinshell')) - goDoCommand('cmd_showinshell'); -} - -var downloadViewController = { - supportsCommand: function dVC_supportsCommand (aCommand) - { - switch (aCommand) { - case "cmd_properties": - case "cmd_pause": - case "cmd_cancel": - case "cmd_remove": - case "cmd_copyurl": - case "cmd_openfile": - case "cmd_showinshell": - case "cmd_selectAll": - return true; - } - return false; - }, - - isCommandEnabled: function dVC_isCommandEnabled (aCommand) - { - if (!gDownloadView.view || !gDownloadView.view.selection) return false; - var selectionCount = gDownloadView.view.selection.count; - if (!selectionCount) return false; - - var selectedItem = getSelectedItem(); - var isDownloading = selectedItem && gDownloadManager.getDownload(selectedItem.id); - - switch (aCommand) { - case "cmd_openfile": - if (gCannotLaunch) - return false; - case "cmd_showinshell": - // we can't reveal until the download is complete, because we have not given - // the file its final name until them. - return selectionCount == 1 && !isDownloading && selectedItem && - createLocalFile(selectedItem.id).exists(); - case "cmd_properties": - return selectionCount == 1 && isDownloading; - case "cmd_pause": - return false; - case "cmd_cancel": - // XXX check if selection is still in progress - // how to handle multiple selection? - return isDownloading; - case "cmd_remove": - // XXX ensure selection isn't still in progress - // and how to handle multiple selection? - return selectionCount > 0 && !isDownloading; - case "cmd_copyurl": - return selectionCount > 0; - case "cmd_selectAll": - return gDownloadView.view.rowCount != selectionCount; - default: - return false; - } - }, - - doCommand: function dVC_doCommand (aCommand) - { - var selectedItem, selectedItems; - var file, i; - - switch (aCommand) { - case "cmd_properties": - selectedItem = getSelectedItem(); - var dl; - if (selectedItem) - dl = gDownloadManager.getDownload(selectedItem.id); - if (dl) - gDownloadManager.openProgressDialogFor(dl, window, false); - break; - case "cmd_openfile": - selectedItem = getSelectedItem(); - if (selectedItem) { - file = createLocalFile(selectedItem.id); - const kDontAskAgainPref = "browser.download.progressDnlgDialog.dontAskForLaunch"; - try { - var pref = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefBranch); - var dontAskAgain = pref.getBoolPref(kDontAskAgainPref); - } catch (e) { - // dontAskAgain not set - then we need to ask user - dontAskAgain = false; - } - if (!dontAskAgain && file.isExecutable()) { - try { - var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - } catch (ex) { - break; - } - var strBundle = document.getElementById("dlProgressDlgBundle"); - var title = strBundle.getFormattedString("openingAlertTitle", [file.leafName]); - var msg = strBundle.getFormattedString("securityAlertMsg", [file.leafName]); - var dontaskmsg = strBundle.getString("dontAskAgain"); - var checkbox = {value:0}; - var okToProceed = promptService.confirmCheck(window, title, msg, dontaskmsg, checkbox); - try { - if (checkbox.value != dontAskAgain) - pref.setBoolPref(kDontAskAgainPref, checkbox.value); - } catch (ex) {} - if (!okToProceed) - return; - } - file.launch(); - } - break; - case "cmd_showinshell": - selectedItem = getSelectedItem(); - if (selectedItem) { - file = createLocalFile(selectedItem.id); - - // on unix, open a browser window rooted at the parent - if ((navigator.platform.indexOf("Win") == -1) && - (navigator.platform.indexOf("Mac") == -1) && - (navigator.platform.indexOf("OS/2") == -1) && - (navigator.platform.indexOf("BeOS") == -1)) { - var parent = file.parent; - if (parent) { - const browserURL = "chrome://navigator/content/navigator.xul"; - window.openDialog(browserURL, "_blank", "chrome,all,dialog=no", parent.path); - } - } - else { - file.reveal(); - } - } - break; - case "cmd_pause": - break; - case "cmd_cancel": - // XXX we should probably prompt the user - selectedItems = getSelectedItems(); - for (i = 0; i < selectedItems.length; i++) - gDownloadManager.cancelDownload(selectedItems[i].id); - window.updateCommands("tree-select"); - break; - case "cmd_remove": - selectedItems = getSelectedItems(); - // Figure out where to place the selection after deletion - var newSelectionPos = gDownloadView.contentView.getIndexOfItem(selectedItems[0]); - gDownloadManager.startBatchUpdate(); - - // Notify the datasource that we're about to begin a batch operation - var ds = window.arguments[0] - .QueryInterface(Components.interfaces.nsIRDFDataSource); - ds.beginUpdateBatch(); - for (i = 0; i <= selectedItems.length - 1; ++i) { - gDownloadManager.removeDownload(selectedItems[i].id); - } - ds.endUpdateBatch(); - - gDownloadManager.endBatchUpdate(); - // If there's nothing on the panel now, skip setting the selection - if (gDownloadView.treeBoxObject.view && gDownloadView.treeBoxObject.view.rowCount > 0) { - // Select the item that replaced the first deleted one - if (newSelectionPos >= gDownloadView.treeBoxObject.view.rowCount) - newSelectionPos = gDownloadView.treeBoxObject.view.rowCount - 1; - gDownloadView.view.selection.select(newSelectionPos); - gDownloadView.treeBoxObject.ensureRowIsVisible(newSelectionPos); - gStatusBar.label = createLocalFile(getSelectedItem().id).path; - } - else { - // Nothing on the panel, so clear the Status Bar - gStatusBar.label = ""; - } - window.updateCommands("tree-select"); - break; - case "cmd_selectAll": - gDownloadView.view.selection.selectAll(); - break; - case "cmd_copyurl": - selectedItems = getSelectedItems(); - if (selectedItems.length > 0) { - gStatusBar.label = copyToClipboard(selectedItems); - } - break; - default: - } - }, - - onEvent: function dVC_onEvent (aEvent) - { - switch (aEvent) { - case "tree-select": - this.onCommandUpdate(); - } - }, - - onCommandUpdate: function dVC_onCommandUpdate () - { - var cmds = ["cmd_properties", "cmd_pause", "cmd_cancel", "cmd_remove", - "cmd_copyurl", "cmd_openfile", "cmd_showinshell"]; - for (var command in cmds) - goUpdateCommand(cmds[command]); - } -}; - -function getSelectedItem() -{ - if (gDownloadView.currentIndex != -1) - return gDownloadView.contentView.getItemAtIndex(gDownloadView.currentIndex); - return null; -} - -function getSelectedItems() -{ - var items = []; - var k = 0; - - var selection = gDownloadView.view.selection; - var rangeCount = selection.getRangeCount(); - for (var i = 0; i < rangeCount; i++) { - var startIndex = {}; - var endIndex = {}; - selection.getRangeAt(i, startIndex, endIndex); - for (var j = startIndex.value; j <= endIndex.value; j++) - items[k++] = gDownloadView.contentView.getItemAtIndex(j); - } - - return items; -} - -function createLocalFile(aFilePath) -{ - const lfIID = Components.interfaces.nsILocalFile; - // XXXvarga We should fix the download manager to be consistent, that is, - // use urls instead of local paths when adding new items to the list. - // Once it's fixed, the code below can be removed. - // See bug 208113 for more details. - - var file; - if (aFilePath.substring(0,5) == 'file:') { - file = gFileHandler.getFileFromURLSpec(aFilePath) - .QueryInterface(lfIID); - } - else { - const lfContractID = "@mozilla.org/file/local;1"; - file = Components.classes[lfContractID].createInstance(lfIID); - file.initWithPath(aFilePath); - } - - return file; -} - -function DLManagerShutdown() -{ - try { - var observerService = Components.classes[kObserverServiceProgID] - .getService(Components.interfaces.nsIObserverService); - observerService.removeObserver(dlObserver, "download-starting"); - } - catch (ex) { - } -} - -function setSortVariables(tree) -{ - var node; - for (node = document.getElementById("Name"); node; node = node.nextSibling) { - if (node.getAttribute("sortActive") == "true") - break; - } - if (!node) { - node = document.getElementById("Progress"); - node.setAttribute("sortActive", "true"); - node.setAttribute("sortDirection", "descending"); - } - - tree.setAttribute("sortActive", "true"); - tree.setAttribute("sortDirection", node.getAttribute("sortDirection")); - tree.setAttribute("sortResource", node.getAttribute("resource")); -} - -function doSort(node) -{ - if (node.localName != "treecol") - return; - - var sortResource = node.getAttribute("resource"); - - var sortDirection = node.getAttribute("sortDirection"); - sortDirection = sortDirection == "ascending" ? "descending" : "ascending"; - - try { - var sortService = Components.classes["@mozilla.org/xul/xul-sort-service;1"] - .getService(Components.interfaces.nsIXULSortService); - sortService.sort(node, sortResource, sortDirection); - } - catch(ex) { - } -} - -function copyToClipboard(selectedItems) -{ - var urlArray = new Array(selectedItems.length); - for (var i = 0; i < selectedItems.length; ++i) { - urlArray[i] = selectedItems[i].firstChild.lastChild.getAttribute("label"); - } - - var clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"] - .getService(Components.interfaces.nsIClipboardHelper); - clipboardHelper.copyString(urlArray.join("\n")); - - return urlArray.join(" "); // for status text -} diff --git a/xpfe/components/download-manager/resources/downloadmanager.xul b/xpfe/components/download-manager/resources/downloadmanager.xul deleted file mode 100644 index 679036ea671e..000000000000 --- a/xpfe/components/download-manager/resources/downloadmanager.xul +++ /dev/null @@ -1,267 +0,0 @@ - - - - - - - -%downloadManagerDTD; - -%downloadProgressDTD; -]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/xpfe/components/download-manager/resources/mac/jar.mn b/xpfe/components/download-manager/resources/mac/jar.mn deleted file mode 100644 index d3f521c5c6b7..000000000000 --- a/xpfe/components/download-manager/resources/mac/jar.mn +++ /dev/null @@ -1,2 +0,0 @@ -comm.jar: - content/communicator/downloadmanager/dlmanagermenuoverlay.xul (dlmanagermenuoverlay.xul) diff --git a/xpfe/components/download-manager/src/Makefile.in b/xpfe/components/download-manager/src/Makefile.in deleted file mode 100644 index a177e48063d6..000000000000 --- a/xpfe/components/download-manager/src/Makefile.in +++ /dev/null @@ -1,90 +0,0 @@ -#! gmake -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# 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/ -# -# 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) 2000 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Stuart Parmenter -# -# Alternatively, the contents of this file may be used under the terms of -# either of 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 MPL, 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 MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = downloadmanager -LIBRARY_NAME = downloadmanager_s -MOZILLA_INTERNAL_API = 1 - -REQUIRES = xpcom \ - string \ - rdf \ - uriloader \ - mimetype \ - necko \ - intl \ - windowwatcher \ - webbrowserpersist \ - appshell \ - dom \ - profile \ - widget \ - pref \ - embed_base \ - alerts \ - toolkitcomps \ - $(NULL) - -CPPSRCS = \ - nsDownloadManager.cpp \ - $(NULL) - -# Toolkit exports this from its download manager, so we need to as we're not -# currently building the toolkit version, but other things need it. -EXTRA_JS_MODULES = \ - ../../../../toolkit/mozapps/downloads/src/DownloadUtils.jsm \ - ../../../../toolkit/mozapps/downloads/src/DownloadLastDir.jsm \ - $(NULL) - -EXTRA_COMPONENTS = nsDownloadProgressListener.js - -# we don't want the shared lib, but we want to force the creation of a -# static lib. -FORCE_STATIC_LIB = 1 - -include $(topsrcdir)/config/rules.mk - -EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) - diff --git a/xpfe/components/download-manager/src/nsDownloadManager.cpp b/xpfe/components/download-manager/src/nsDownloadManager.cpp deleted file mode 100644 index f7d91bca0401..000000000000 --- a/xpfe/components/download-manager/src/nsDownloadManager.cpp +++ /dev/null @@ -1,1475 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cin: */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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 (Original Author) - * Ben Goodger (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsDownloadManager.h" -#include "nsIWebProgress.h" -#include "nsIRDFLiteral.h" -#include "rdf.h" -#include "nsNetUtil.h" -#include "nsIDOMWindow.h" -#include "nsIDOMWindowInternal.h" -#include "nsIDOMEvent.h" -#include "nsIDOMEventTarget.h" -#include "nsRDFCID.h" -#include "nsAppDirectoryServiceDefs.h" -#include "nsIObserver.h" -#include "nsIProgressDialog.h" -#include "nsIWebBrowserPersist.h" -#include "nsIWindowWatcher.h" -#include "nsIStringBundle.h" -#include "nsCRT.h" -#include "nsIWindowMediator.h" -#include "nsIPromptService.h" -#include "nsIObserverService.h" -#include "nsIProfileChangeStatus.h" -#include "nsIPrefService.h" -#include "nsIFileURL.h" -#include "nsIAlertsService.h" -#include "nsEmbedCID.h" -#include "nsInt64.h" -#include "nsToolkitCompsCID.h" - -/* Outstanding issues/todo: - * 1. Implement pause/resume. - */ - -#define DOWNLOAD_MANAGER_FE_URL "chrome://communicator/content/downloadmanager/downloadmanager.xul" -#define DOWNLOAD_MANAGER_BUNDLE "chrome://communicator/locale/downloadmanager/downloadmanager.properties" - -static const nsInt64 gInterval((PRUint32)(400 * PR_USEC_PER_MSEC)); - -static nsIRDFResource* gNC_DownloadsRoot = nsnull; -static nsIRDFResource* gNC_File = nsnull; -static nsIRDFResource* gNC_URL = nsnull; -static nsIRDFResource* gNC_Name = nsnull; -static nsIRDFResource* gNC_ProgressMode = nsnull; -static nsIRDFResource* gNC_ProgressPercent = nsnull; -static nsIRDFResource* gNC_Transferred = nsnull; -static nsIRDFResource* gNC_DownloadState = nsnull; -static nsIRDFResource* gNC_StatusText = nsnull; - -static nsIRDFService* gRDFService = nsnull; - -static PRInt32 gRefCnt = 0; - -/** - * This function extracts the local file path corresponding to the given URI. - */ -static nsresult -GetFilePathUTF8(nsIURI *aURI, nsACString &aResult) -{ - nsresult rv; - - nsCOMPtr fileURL = do_QueryInterface(aURI, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr file; - rv = fileURL->GetFile(getter_AddRefs(file)); - if (NS_FAILED(rv)) return rv; - - nsAutoString path; - rv = file->GetPath(path); - if (NS_SUCCEEDED(rv)) - CopyUTF16toUTF8(path, aResult); - return rv; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsDownloadManager - -NS_IMPL_ISUPPORTS3(nsDownloadManager, nsIDownloadManager, nsIDOMEventListener, nsIObserver) - -nsDownloadManager::nsDownloadManager() : mBatches(0) -{ -} - -nsDownloadManager::~nsDownloadManager() -{ - if (--gRefCnt != 0 || !gRDFService) - // Either somebody tried to use |CreateInstance| instead of - // |GetService| or |Init| failed very early, so there's nothing to - // do here. - return; - - gRDFService->UnregisterDataSource(mDataSource); - - NS_IF_RELEASE(gNC_DownloadsRoot); - NS_IF_RELEASE(gNC_File); - NS_IF_RELEASE(gNC_URL); - NS_IF_RELEASE(gNC_Name); - NS_IF_RELEASE(gNC_ProgressMode); - NS_IF_RELEASE(gNC_ProgressPercent); - NS_IF_RELEASE(gNC_Transferred); - NS_IF_RELEASE(gNC_DownloadState); - NS_IF_RELEASE(gNC_StatusText); - - NS_RELEASE(gRDFService); -} - -nsresult -nsDownloadManager::Init() -{ - if (gRefCnt++ != 0) { - NS_NOTREACHED("download manager should be used as a service"); - return NS_ERROR_UNEXPECTED; // This will make the |CreateInstance| fail. - } - - if (!mCurrDownloads.Init()) - return NS_ERROR_FAILURE; - - nsresult rv; - mRDFContainerUtils = do_GetService("@mozilla.org/rdf/container-utils;1", &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr obsService = do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_FAILED(rv)) return rv; - - - rv = CallGetService("@mozilla.org/rdf/rdf-service;1", &gRDFService); - if (NS_FAILED(rv)) return rv; - - gRDFService->GetResource(NS_LITERAL_CSTRING("NC:DownloadsRoot"), &gNC_DownloadsRoot); - gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "File"), &gNC_File); - gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"), &gNC_URL); - gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"), &gNC_Name); - gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ProgressMode"), &gNC_ProgressMode); - gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ProgressPercent"), &gNC_ProgressPercent); - gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Transferred"), &gNC_Transferred); - gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "DownloadState"), &gNC_DownloadState); - gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "StatusText"), &gNC_StatusText); - - nsCAutoString downloadsDB; - rv = GetProfileDownloadsFileURL(downloadsDB); - if (NS_FAILED(rv)) return rv; - - rv = gRDFService->GetDataSourceBlocking(downloadsDB.get(), getter_AddRefs(mDataSource)); - if (NS_FAILED(rv)) return rv; - - mListener = do_CreateInstance("@mozilla.org/download-manager/listener;1", &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = bundleService->CreateBundle(DOWNLOAD_MANAGER_BUNDLE, getter_AddRefs(mBundle)); - if (NS_FAILED(rv)) - return rv; - - // The following two AddObserver calls must be the last lines in this function, - // because otherwise, this function may fail (and thus, this object would be not - // completely initialized), but the observerservice would still keep a reference - // to us and notify us about shutdown, which may cause crashes. - // failure to add an observer is not critical - obsService->AddObserver(this, "profile-before-change", PR_FALSE); - obsService->AddObserver(this, "profile-approve-change", PR_FALSE); - - return NS_OK; -} - -nsresult -nsDownloadManager::DownloadStarted(const nsACString& aTargetPath) -{ - if (mCurrDownloads.GetWeak(aTargetPath)) - AssertProgressInfoFor(aTargetPath); - - return NS_OK; -} - -nsresult -nsDownloadManager::DownloadEnded(const nsACString& aTargetPath, const PRUnichar* aMessage) -{ - nsDownload* dl = mCurrDownloads.GetWeak(aTargetPath); - if (dl) { - AssertProgressInfoFor(aTargetPath); - mCurrDownloads.Remove(aTargetPath); - } - - return NS_OK; -} - -nsresult -nsDownloadManager::GetProfileDownloadsFileURL(nsCString& aDownloadsFileURL) -{ - nsCOMPtr downloadsFile; - nsresult rv = NS_GetSpecialDirectory(NS_APP_DOWNLOADS_50_FILE, getter_AddRefs(downloadsFile)); - if (NS_FAILED(rv)) - return rv; - - return NS_GetURLSpecFromFile(downloadsFile, aDownloadsFileURL); -} - -nsresult -nsDownloadManager::GetDownloadsContainer(nsIRDFContainer** aResult) -{ - if (mDownloadsContainer) { - *aResult = mDownloadsContainer; - NS_ADDREF(*aResult); - return NS_OK; - } - - PRBool isContainer; - nsresult rv = mRDFContainerUtils->IsContainer(mDataSource, gNC_DownloadsRoot, &isContainer); - if (NS_FAILED(rv)) return rv; - - if (!isContainer) { - rv = mRDFContainerUtils->MakeSeq(mDataSource, gNC_DownloadsRoot, getter_AddRefs(mDownloadsContainer)); - if (NS_FAILED(rv)) return rv; - } - else { - mDownloadsContainer = do_CreateInstance(NS_RDF_CONTRACTID "/container;1", &rv); - if (NS_FAILED(rv)) return rv; - rv = mDownloadsContainer->Init(mDataSource, gNC_DownloadsRoot); - if (NS_FAILED(rv)) return rv; - } - - *aResult = mDownloadsContainer; - NS_IF_ADDREF(*aResult); - - return rv; -} - -nsresult -nsDownloadManager::GetInternalListener(nsIDownloadProgressListener** aInternalListener) -{ - *aInternalListener = mListener; - NS_IF_ADDREF(*aInternalListener); - return NS_OK; -} - -nsresult -nsDownloadManager::GetDataSource(nsIRDFDataSource** aDataSource) -{ - *aDataSource = mDataSource; - NS_ADDREF(*aDataSource); - return NS_OK; -} - -nsresult -nsDownloadManager::AssertProgressInfo() -{ - nsCOMPtr supports; - nsCOMPtr res; - nsCOMPtr intLiteral; - - gRDFService->GetIntLiteral(DOWNLOADING, getter_AddRefs(intLiteral)); - nsCOMPtr downloads; - nsresult rv = mDataSource->GetSources(gNC_DownloadState, intLiteral, PR_TRUE, getter_AddRefs(downloads)); - if (NS_FAILED(rv)) return rv; - - PRBool hasMoreElements; - downloads->HasMoreElements(&hasMoreElements); - - while (hasMoreElements) { - const char* uri; - downloads->GetNext(getter_AddRefs(supports)); - res = do_QueryInterface(supports); - res->GetValueConst(&uri); - AssertProgressInfoFor(nsDependentCString(uri)); - downloads->HasMoreElements(&hasMoreElements); - } - return rv; -} - -nsresult -nsDownloadManager::AssertProgressInfoFor(const nsACString& aTargetPath) -{ - nsDownload* internalDownload = mCurrDownloads.GetWeak(aTargetPath); - if (!internalDownload) - return NS_ERROR_FAILURE; - - nsresult rv; - PRInt32 percentComplete; - nsCOMPtr oldTarget; - nsCOMPtr intLiteral; - nsCOMPtr res; - nsCOMPtr literal; - - gRDFService->GetResource(aTargetPath, getter_AddRefs(res)); - - DownloadState state = internalDownload->GetDownloadState(); - - // update progress mode - nsAutoString progressMode; - if (state == DOWNLOADING) - progressMode.AssignLiteral("normal"); - else - progressMode.AssignLiteral("none"); - - gRDFService->GetLiteral(progressMode.get(), getter_AddRefs(literal)); - - rv = mDataSource->GetTarget(res, gNC_ProgressMode, PR_TRUE, getter_AddRefs(oldTarget)); - - if (oldTarget) - rv = mDataSource->Change(res, gNC_ProgressMode, oldTarget, literal); - else - rv = mDataSource->Assert(res, gNC_ProgressMode, literal, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - // update download state (not started, downloading, queued, finished, etc...) - gRDFService->GetIntLiteral(state, getter_AddRefs(intLiteral)); - - mDataSource->GetTarget(res, gNC_DownloadState, PR_TRUE, getter_AddRefs(oldTarget)); - - if (oldTarget) { - rv = mDataSource->Change(res, gNC_DownloadState, oldTarget, intLiteral); - if (NS_FAILED(rv)) return rv; - } - - nsAutoString strKey; - if (state == NOTSTARTED) - strKey.AssignLiteral("notStarted"); - else if (state == DOWNLOADING) - strKey.AssignLiteral("downloading"); - else if (state == FINISHED) - strKey.AssignLiteral("finished"); - else if (state == FAILED) - strKey.AssignLiteral("failed"); - else if (state == CANCELED) - strKey.AssignLiteral("canceled"); - - nsXPIDLString value; - rv = mBundle->GetStringFromName(strKey.get(), getter_Copies(value)); - if (NS_FAILED(rv)) return rv; - - gRDFService->GetLiteral(value, getter_AddRefs(literal)); - - rv = mDataSource->GetTarget(res, gNC_StatusText, PR_TRUE, getter_AddRefs(oldTarget)); - - if (oldTarget) { - rv = mDataSource->Change(res, gNC_StatusText, oldTarget, literal); - if (NS_FAILED(rv)) return rv; - } - else { - rv = mDataSource->Assert(res, gNC_StatusText, literal, PR_TRUE); - if (NS_FAILED(rv)) return rv; - } - - // update percentage - internalDownload->GetPercentComplete(&percentComplete); - - mDataSource->GetTarget(res, gNC_ProgressPercent, PR_TRUE, getter_AddRefs(oldTarget)); - gRDFService->GetIntLiteral(percentComplete, getter_AddRefs(intLiteral)); - - if (oldTarget) - rv = mDataSource->Change(res, gNC_ProgressPercent, oldTarget, intLiteral); - else - rv = mDataSource->Assert(res, gNC_ProgressPercent, intLiteral, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - // update transferred - nsDownload::TransferInformation transferInfo = - internalDownload->GetTransferInformation(); - - // convert from bytes to kbytes for progress display - PRInt64 current = (transferInfo.mCurrBytes + 512) / 1024; - PRInt64 max = (transferInfo.mMaxBytes + 512) / 1024; - - nsAutoString currBytes; currBytes.AppendInt(current); - nsAutoString maxBytes; maxBytes.AppendInt(max); - const PRUnichar *strings[] = { - currBytes.get(), - maxBytes.get() - }; - - rv = mBundle->FormatStringFromName(NS_LITERAL_STRING("transferred").get(), - strings, 2, getter_Copies(value)); - if (NS_FAILED(rv)) return rv; - - gRDFService->GetLiteral(value, getter_AddRefs(literal)); - - mDataSource->GetTarget(res, gNC_Transferred, PR_TRUE, getter_AddRefs(oldTarget)); - - if (oldTarget) - rv = mDataSource->Change(res, gNC_Transferred, oldTarget, literal); - else - rv = mDataSource->Assert(res, gNC_Transferred, literal, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr remote = do_QueryInterface(mDataSource); - remote->Flush(); - - // XXX should also store and update time elapsed - return rv; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsIDownloadManager - -NS_IMETHODIMP -nsDownloadManager::AddDownload(nsIURI* aSource, - nsIURI* aTarget, - const nsAString& aDisplayName, - nsIMIMEInfo *aMIMEInfo, - PRTime aStartTime, - nsILocalFile* aTempFile, - nsICancelable* aCancelable, - nsIDownload** aDownload) -{ - NS_ENSURE_ARG_POINTER(aSource); - NS_ENSURE_ARG_POINTER(aTarget); - NS_ENSURE_ARG_POINTER(aDownload); - - nsCOMPtr downloads; - nsresult rv = GetDownloadsContainer(getter_AddRefs(downloads)); - if (NS_FAILED(rv)) return rv; - - // this will create a cycle that will be broken in nsDownload::OnStateChange - nsDownload* internalDownload = new nsDownload(this, aTarget, aSource, aCancelable); - if (!internalDownload) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(*aDownload = internalDownload); - - // the path of the target is the unique identifier we use - nsCOMPtr targetFile; - rv = internalDownload->GetTargetFile(getter_AddRefs(targetFile)); - if (NS_FAILED(rv)) return rv; - - nsAutoString path; - rv = targetFile->GetPath(path); - if (NS_FAILED(rv)) return rv; - - NS_ConvertUTF16toUTF8 utf8Path(path); - - nsCOMPtr downloadRes; - gRDFService->GetResource(utf8Path, getter_AddRefs(downloadRes)); - - nsCOMPtr node; - - // Assert source url information - nsCAutoString spec; - aSource->GetSpec(spec); - - nsCOMPtr urlResource; - gRDFService->GetResource(spec, getter_AddRefs(urlResource)); - mDataSource->GetTarget(downloadRes, gNC_URL, PR_TRUE, getter_AddRefs(node)); - if (node) - rv = mDataSource->Change(downloadRes, gNC_URL, node, urlResource); - else - rv = mDataSource->Assert(downloadRes, gNC_URL, urlResource, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - // Set and assert the "pretty" (display) name of the download - nsAutoString displayName; displayName.Assign(aDisplayName); - if (displayName.IsEmpty()) { - targetFile->GetLeafName(displayName); - } - internalDownload->SetDisplayName(displayName.get()); - internalDownload->SetTempFile(aTempFile); - - nsCOMPtr nameLiteral; - gRDFService->GetLiteral(displayName.get(), getter_AddRefs(nameLiteral)); - mDataSource->GetTarget(downloadRes, gNC_Name, PR_TRUE, getter_AddRefs(node)); - if (node) - rv = mDataSource->Change(downloadRes, gNC_Name, node, nameLiteral); - else - rv = mDataSource->Assert(downloadRes, gNC_Name, nameLiteral, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - internalDownload->SetMIMEInfo(aMIMEInfo); - internalDownload->SetStartTime(aStartTime); - - // Assert file information - nsCOMPtr fileResource; - gRDFService->GetResource(utf8Path, getter_AddRefs(fileResource)); - rv = mDataSource->Assert(downloadRes, gNC_File, fileResource, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - // Assert download state information (NOTSTARTED, since it's just now being added) - nsCOMPtr intLiteral; - gRDFService->GetIntLiteral(NOTSTARTED, getter_AddRefs(intLiteral)); - mDataSource->GetTarget(downloadRes, gNC_DownloadState, PR_TRUE, getter_AddRefs(node)); - if (node) - rv = mDataSource->Change(downloadRes, gNC_DownloadState, node, intLiteral); - else - rv = mDataSource->Assert(downloadRes, gNC_DownloadState, intLiteral, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - PRInt32 itemIndex; - downloads->IndexOf(downloadRes, &itemIndex); - if (itemIndex == -1) { - rv = downloads->AppendElement(downloadRes); - if (NS_FAILED(rv)) return rv; - } - - // Now flush all this to disk - nsCOMPtr remote(do_QueryInterface(mDataSource)); - rv = remote->Flush(); - if (NS_FAILED(rv)) return rv; - - mCurrDownloads.Put(utf8Path, internalDownload); - - return rv; -} - -NS_IMETHODIMP -nsDownloadManager::GetDownload(const nsACString & aTargetPath, nsIDownload** aDownloadItem) -{ - NS_ENSURE_ARG_POINTER(aDownloadItem); - - // if it's currently downloading we can get it from the table - // XXX otherwise we should look for it in the datasource and - // create a new nsIDownload with the resource's properties - NS_IF_ADDREF(*aDownloadItem = mCurrDownloads.GetWeak(aTargetPath)); - return NS_OK; -} - -NS_IMETHODIMP -nsDownloadManager::CancelDownload(const nsACString & aTargetPath) -{ - nsRefPtr internalDownload = mCurrDownloads.GetWeak(aTargetPath); - if (!internalDownload) - return NS_ERROR_FAILURE; - - return internalDownload->Cancel(); -} - -NS_IMETHODIMP -nsDownloadManager::PauseDownload(nsIDownload* aDownload) -{ - NS_ENSURE_ARG_POINTER(aDownload); - return static_cast(aDownload)->Suspend(); -} - -NS_IMETHODIMP -nsDownloadManager::ResumeDownload(const nsACString & aTargetPath) -{ - nsDownload* dl = mCurrDownloads.GetWeak(aTargetPath); - if (!dl) - return NS_ERROR_NOT_AVAILABLE; - return dl->Resume(); -} - -NS_IMETHODIMP -nsDownloadManager::RemoveDownload(const nsACString & aTargetPath) -{ - // RemoveDownload is for downloads not currently in progress. Having it - // cancel in-progress downloads would make things complicated, so just return. - nsDownload* inProgress = mCurrDownloads.GetWeak(aTargetPath); - NS_ASSERTION(!inProgress, "Can't call RemoveDownload on a download in progress!"); - if (inProgress) - return NS_ERROR_FAILURE; - - nsCOMPtr downloads; - nsresult rv = GetDownloadsContainer(getter_AddRefs(downloads)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr res; - gRDFService->GetResource(aTargetPath, getter_AddRefs(res)); - - // remove all the arcs for this resource, and then remove it from the Seq - nsCOMPtr arcs; - rv = mDataSource->ArcLabelsOut(res, getter_AddRefs(arcs)); - if (NS_FAILED(rv)) return rv; - - PRBool moreArcs; - rv = arcs->HasMoreElements(&moreArcs); - if (NS_FAILED(rv)) return rv; - - while (moreArcs) { - nsCOMPtr supports; - rv = arcs->GetNext(getter_AddRefs(supports)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr arc(do_QueryInterface(supports, &rv)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr targets; - rv = mDataSource->GetTargets(res, arc, PR_TRUE, getter_AddRefs(targets)); - if (NS_FAILED(rv)) return rv; - - PRBool moreTargets; - rv = targets->HasMoreElements(&moreTargets); - if (NS_FAILED(rv)) return rv; - - while (moreTargets) { - rv = targets->GetNext(getter_AddRefs(supports)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr target(do_QueryInterface(supports, &rv)); - if (NS_FAILED(rv)) return rv; - - // and now drop this assertion from the graph - rv = mDataSource->Unassert(res, arc, target); - if (NS_FAILED(rv)) return rv; - - rv = targets->HasMoreElements(&moreTargets); - if (NS_FAILED(rv)) return rv; - } - rv = arcs->HasMoreElements(&moreArcs); - if (NS_FAILED(rv)) return rv; - } - - PRInt32 itemIndex; - downloads->IndexOf(res, &itemIndex); - if (itemIndex <= 0) - return NS_ERROR_FAILURE; - - nsCOMPtr node; - rv = downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node)); - if (NS_FAILED(rv)) return rv; - - // if a mass removal is being done, we don't want to flush every time - if (mBatches) return rv; - - nsCOMPtr remote = do_QueryInterface(mDataSource); - return remote->Flush(); -} - -NS_IMETHODIMP -nsDownloadManager::StartBatchUpdate() -{ - ++mBatches; - return NS_OK; -} - -NS_IMETHODIMP -nsDownloadManager::EndBatchUpdate() -{ - nsresult rv = NS_OK; - if (--mBatches == 0) { - nsCOMPtr remote = do_QueryInterface(mDataSource); - rv = remote->Flush(); - } - return rv; -} - -NS_IMETHODIMP -nsDownloadManager::Open(nsIDOMWindow* aParent, nsIDownload* aDownload) -{ - - // first assert new progress info so the ui is correctly updated - // if this fails, it fails -- continue. - AssertProgressInfo(); - - // check for an existing manager window and focus it - nsresult rv; - nsCOMPtr wm = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr dlSupports(do_QueryInterface(aDownload)); - - // if the window's already open, do nothing (focusing it would be annoying) - nsCOMPtr recentWindow; - wm->GetMostRecentWindow(NS_LITERAL_STRING("Download:Manager").get(), getter_AddRefs(recentWindow)); - if (recentWindow) { - nsCOMPtr obsService = do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_FAILED(rv)) return rv; - return obsService->NotifyObservers(dlSupports, "download-starting", nsnull); - } - - // if we ever have the capability to display the UI of third party dl managers, - // we'll open their UI here instead. - nsCOMPtr ww = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - // pass the datasource to the window - nsCOMPtr params(do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID)); - nsCOMPtr dsSupports(do_QueryInterface(mDataSource)); - params->AppendElement(dsSupports); - params->AppendElement(dlSupports); - - nsCOMPtr newWindow; - rv = ww->OpenWindow(aParent, - DOWNLOAD_MANAGER_FE_URL, - "_blank", - "chrome,all,dialog=no,resizable", - params, - getter_AddRefs(newWindow)); - - if (NS_FAILED(rv)) return rv; - - nsCOMPtr target = do_QueryInterface(newWindow); - if (!target) return NS_ERROR_FAILURE; - - 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::OpenProgressDialogFor(nsIDownload* aDownload, nsIDOMWindow* aParent, PRBool aCancelDownloadOnClose) -{ - NS_ENSURE_ARG_POINTER(aDownload); - nsresult rv; - nsDownload* internalDownload = static_cast(aDownload); - nsIProgressDialog* oldDialog = internalDownload->GetDialog(); - - if (oldDialog) { - nsCOMPtr window; - oldDialog->GetDialog(getter_AddRefs(window)); - if (window) { - nsCOMPtr internalWin = do_QueryInterface(window); - internalWin->Focus(); - return NS_OK; - } - } - - nsCOMPtr dialog(do_CreateInstance("@mozilla.org/progressdialog;1", &rv)); - if (NS_FAILED(rv)) return rv; - - dialog->SetCancelDownloadOnClose(aCancelDownloadOnClose); - - // now give the dialog the necessary context - - // start time... - PRInt64 startTime = 0; - aDownload->GetStartTime(&startTime); - - // source... - nsCOMPtr source; - aDownload->GetSource(getter_AddRefs(source)); - - // target... - nsCOMPtr target; - aDownload->GetTarget(getter_AddRefs(target)); - - // helper app... - nsCOMPtr mimeInfo; - aDownload->GetMIMEInfo(getter_AddRefs(mimeInfo)); - - dialog->Init(source, target, EmptyString(), mimeInfo, startTime, nsnull, - nsnull); - dialog->SetObserver(internalDownload); - - // now set the listener so we forward notifications to the dialog - nsCOMPtr listener = do_QueryInterface(dialog); - internalDownload->SetDialogListener(listener); - - internalDownload->SetDialog(dialog); - - return dialog->Open(aParent); -} - -NS_IMETHODIMP -nsDownloadManager::OnClose() -{ - mDocument = nsnull; - mListener->SetDocument(nsnull); - return NS_OK; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsIDOMEventListener - -NS_IMETHODIMP -nsDownloadManager::HandleEvent(nsIDOMEvent* aEvent) -{ - // the event is either load or unload - nsAutoString eventType; - aEvent->GetType(eventType); - if (eventType.EqualsLiteral("unload")) - return OnClose(); - - nsCOMPtr target; - nsresult rv = aEvent->GetTarget(getter_AddRefs(target)); - if (NS_FAILED(rv)) return rv; - - mDocument = do_QueryInterface(target); - mListener->SetDocument(mDocument); - return NS_OK; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsIObserver - -NS_IMETHODIMP -nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData) -{ - nsresult rv; - if (nsCRT::strcmp(aTopic, "profile-approve-change") == 0) { - // Only run this on profile switch - if (!NS_LITERAL_STRING("switch").Equals(aData)) - return NS_OK; - - // If count == 0, nothing to do - if (mCurrDownloads.Count() == 0) - return NS_OK; - - nsCOMPtr changeStatus(do_QueryInterface(aSubject)); - if (!changeStatus) - return NS_ERROR_UNEXPECTED; - - nsXPIDLString title, text, proceed, cancel; - nsresult rv = mBundle->GetStringFromName(NS_LITERAL_STRING("profileSwitchTitle").get(), - getter_Copies(title)); - NS_ENSURE_SUCCESS(rv, rv); - rv = mBundle->GetStringFromName(NS_LITERAL_STRING("profileSwitchText").get(), - getter_Copies(text)); - NS_ENSURE_SUCCESS(rv, rv); - rv = mBundle->GetStringFromName(NS_LITERAL_STRING("profileSwitchContinue").get(), - getter_Copies(proceed)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr promptService(do_GetService(NS_PROMPTSERVICE_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - - PRInt32 button; - rv = promptService->ConfirmEx(nsnull, title.get(), text.get(), - nsIPromptService::BUTTON_TITLE_CANCEL * nsIPromptService::BUTTON_POS_0 | - nsIPromptService::BUTTON_TITLE_IS_STRING * nsIPromptService::BUTTON_POS_1, - nsnull, - proceed.get(), - nsnull, - nsnull, - nsnull, - &button); - if (NS_FAILED(rv)) - return rv; - - if (button == 0) - changeStatus->VetoChange(); - } - else if (nsCRT::strcmp(aTopic, "profile-before-change") == 0) { - nsCOMPtr supports; - nsCOMPtr res; - nsCOMPtr intLiteral; - - gRDFService->GetIntLiteral(DOWNLOADING, getter_AddRefs(intLiteral)); - nsCOMPtr downloads; - rv = mDataSource->GetSources(gNC_DownloadState, intLiteral, PR_TRUE, getter_AddRefs(downloads)); - if (NS_FAILED(rv)) return rv; - - PRBool hasMoreElements; - downloads->HasMoreElements(&hasMoreElements); - - while (hasMoreElements) { - const char* uri; - - downloads->GetNext(getter_AddRefs(supports)); - res = do_QueryInterface(supports); - res->GetValueConst(&uri); - CancelDownload(nsDependentCString(uri)); - downloads->HasMoreElements(&hasMoreElements); - } - } - return NS_OK; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsDownload - -NS_IMPL_ISUPPORTS5(nsDownload, nsIDownload, nsITransfer, nsIWebProgressListener, - nsIWebProgressListener2, nsIObserver) - -nsDownload::nsDownload(nsDownloadManager* aManager, - nsIURI* aTarget, - nsIURI* aSource, - nsICancelable* aCancelable) : - mDownloadManager(aManager), - mTarget(aTarget), - mSource(aSource), - mCancelable(aCancelable), - mDownloadState(NOTSTARTED), - mPercentComplete(0), - mCurrBytes(LL_ZERO), - mMaxBytes(LL_ZERO), - mStartTime(LL_ZERO), - mLastUpdate(PR_Now() - (PRUint32)gInterval), - mSpeed(0) -{ -} - -nsDownload::~nsDownload() -{ - nsCAutoString path; - nsresult rv = GetFilePathUTF8(mTarget, path); - if (NS_FAILED(rv)) return; - - mDownloadManager->AssertProgressInfoFor(path); -} - -nsresult -nsDownload::Suspend() -{ - if (!mRequest) - return NS_ERROR_UNEXPECTED; - return mRequest->Suspend(); -} - -nsresult -nsDownload::Cancel() -{ - // Don't cancel if download is already finished or canceled - if (GetDownloadState() == FINISHED || GetDownloadState() == CANCELED) - return NS_OK; - - nsresult rv = mCancelable->Cancel(NS_BINDING_ABORTED); - if (NS_FAILED(rv)) - return rv; - - SetDownloadState(CANCELED); - - nsCAutoString path; - rv = GetFilePathUTF8(mTarget, path); - if (NS_FAILED(rv)) - return rv; - mDownloadManager->DownloadEnded(path, nsnull); - - // Dump the temp file. This should really be done when the transfer - // is cancelled, but there are other cancellation causes that shouldn't - // remove this. We need to improve those bits. - if (mTempFile) { - PRBool exists; - mTempFile->Exists(&exists); - if (exists) - mTempFile->Remove(PR_FALSE); - } - - // if there's a progress dialog open for the item, - // we have to notify it that we're cancelling - nsCOMPtr observer = do_QueryInterface(GetDialog()); - if (observer) { - rv = observer->Observe(static_cast(this), "oncancel", nsnull); - } - - return rv; -} - -nsresult -nsDownload::SetDisplayName(const PRUnichar* aDisplayName) -{ - mDisplayName = aDisplayName; - - nsCOMPtr ds; - mDownloadManager->GetDataSource(getter_AddRefs(ds)); - - nsCOMPtr nameLiteral; - nsCOMPtr res; - nsCAutoString path; - nsresult rv = GetFilePathUTF8(mTarget, path); - if (NS_FAILED(rv)) return rv; - - gRDFService->GetResource(path, getter_AddRefs(res)); - - gRDFService->GetLiteral(aDisplayName, getter_AddRefs(nameLiteral)); - ds->Assert(res, gNC_Name, nameLiteral, PR_TRUE); - - return NS_OK; -} - -nsresult -nsDownload::Resume() -{ - if (!mRequest) - return NS_ERROR_UNEXPECTED; - return mRequest->Resume(); -} - -/////////////////////////////////////////////////////////////////////////////// -// nsIObserver -NS_IMETHODIMP -nsDownload::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData) -{ - if (strcmp(aTopic, "onpause") == 0) { - return Suspend(); - } - if (strcmp(aTopic, "onresume") == 0) { - return Resume(); - } - if (strcmp(aTopic, "oncancel") == 0) { - SetDialog(nsnull); - - Cancel(); - // Ignoring return value; this function will get called twice, - // and bad things happen if we return a failure code the second time. - return NS_OK; - } - - if (strcmp(aTopic, "alertclickcallback") == 0) { - // show the download manager - mDownloadManager->Open(nsnull, this); - return NS_OK; - } - - return NS_OK; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsIWebProgressListener2 - -NS_IMETHODIMP -nsDownload::OnProgressChange64(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt64 aCurSelfProgress, - PRInt64 aMaxSelfProgress, - PRInt64 aCurTotalProgress, - PRInt64 aMaxTotalProgress) -{ - if (!mRequest) - mRequest = aRequest; // used for pause/resume - - // Filter notifications since they come in so frequently, but we want to - // process the last notification. - PRTime now = PR_Now(); - nsInt64 delta = now - mLastUpdate; - if (delta < gInterval && aCurTotalProgress != aMaxTotalProgress) - return NS_OK; - - mLastUpdate = now; - - if (mDownloadState == NOTSTARTED) { - nsCAutoString path; - nsresult rv = GetFilePathUTF8(mTarget, path); - if (NS_FAILED(rv)) return rv; - - mDownloadState = DOWNLOADING; - mDownloadManager->DownloadStarted(path); - } - - // Calculate the speed using the elapsed delta time and bytes downloaded - // during that time for more accuracy. - double elapsedSecs = double(delta) / PR_USEC_PER_SEC; - if (elapsedSecs > 0) { - nsUint64 curTotalProgress = (PRUint64)aCurTotalProgress; - nsUint64 diffBytes = curTotalProgress - nsUint64(mCurrBytes); - double speed = double(diffBytes) / elapsedSecs; - if (LL_IS_ZERO(mCurrBytes)) - mSpeed = speed; - else { - // Calculate 'smoothed average' of 10 readings. - mSpeed = mSpeed * 0.9 + speed * 0.1; - } - } - - if (aMaxTotalProgress > 0) - mPercentComplete = aCurTotalProgress * 100 / aMaxTotalProgress; - else - mPercentComplete = -1; - - mCurrBytes = aCurTotalProgress; - mMaxBytes = aMaxTotalProgress; - - if (mDownloadManager->MustUpdateUI()) { - nsCOMPtr internalListener; - mDownloadManager->GetInternalListener(getter_AddRefs(internalListener)); - if (internalListener) { - internalListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, - aCurTotalProgress, aMaxTotalProgress, this); - } - } - - if (mDialogListener) { - mDialogListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, - aCurTotalProgress, aMaxTotalProgress, this); - } - - return NS_OK; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsIWebProgressListener - -NS_IMETHODIMP -nsDownload::OnProgressChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) -{ - return OnProgressChange64(aWebProgress, aRequest, - aCurSelfProgress, aMaxSelfProgress, - aCurTotalProgress, aMaxTotalProgress); -} - -NS_IMETHODIMP -nsDownload::OnRefreshAttempted(nsIWebProgress *aWebProgress, - nsIURI *aUri, - PRInt32 aDelay, - PRBool aSameUri, - PRBool *allowRefresh) -{ - *allowRefresh = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::OnLocationChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, nsIURI *aLocation) -{ - if (mDownloadManager->MustUpdateUI()) { - nsCOMPtr internalListener; - mDownloadManager->GetInternalListener(getter_AddRefs(internalListener)); - if (internalListener) - internalListener->OnLocationChange(aWebProgress, aRequest, aLocation, this); - } - - if (mDialogListener) - mDialogListener->OnLocationChange(aWebProgress, aRequest, aLocation, this); - - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::OnStatusChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, nsresult aStatus, - const PRUnichar *aMessage) -{ - if (NS_FAILED(aStatus)) { - mDownloadState = FAILED; - nsCAutoString path; - nsresult rv = GetFilePathUTF8(mTarget, path); - if (NS_SUCCEEDED(rv)) - mDownloadManager->DownloadEnded(path, aMessage); - } - - if (mDownloadManager->MustUpdateUI()) { - nsCOMPtr internalListener; - mDownloadManager->GetInternalListener(getter_AddRefs(internalListener)); - if (internalListener) - internalListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage, this); - } - - if (mDialogListener) - mDialogListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage, this); - else { - // Need to display error alert ourselves, if an error occurred. - if (NS_FAILED(aStatus)) { - // Get title for alert. - nsXPIDLString title; - nsresult rv; - nsCOMPtr bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); - nsCOMPtr bundle; - if (bundleService) - rv = bundleService->CreateBundle(DOWNLOAD_MANAGER_BUNDLE, getter_AddRefs(bundle)); - if (bundle) - bundle->GetStringFromName(NS_LITERAL_STRING("alertTitle").get(), getter_Copies(title)); - - // Get Download Manager window, to be parent of alert. - nsCOMPtr wm = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv); - nsCOMPtr dmWindow; - if (wm) - wm->GetMostRecentWindow(NS_LITERAL_STRING("Download:Manager").get(), getter_AddRefs(dmWindow)); - - // Show alert. - nsCOMPtr prompter(do_GetService(NS_PROMPTSERVICE_CONTRACTID)); - if (prompter) - prompter->Alert(dmWindow, title, aMessage); - } - } - - return NS_OK; -} - -void nsDownload::DisplayDownloadFinishedAlert() -{ - nsresult rv; - nsCOMPtr alertsService(do_GetService(NS_ALERTSERVICE_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return; - - nsCOMPtr bundle; - nsCOMPtr bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return; - - rv = bundleService->CreateBundle(DOWNLOAD_MANAGER_BUNDLE, getter_AddRefs(bundle)); - if (NS_FAILED(rv)) - return; - - nsXPIDLString finishedTitle, finishedText; - rv = bundle->GetStringFromName(NS_LITERAL_STRING("finishedTitle").get(), - getter_Copies(finishedTitle)); - if (NS_FAILED(rv)) - return; - - const PRUnichar *strings[] = { mDisplayName.get() }; - rv = bundle->FormatStringFromName(NS_LITERAL_STRING("finishedText").get(), - strings, 1, getter_Copies(finishedText)); - if (NS_FAILED(rv)) - return; - - nsCAutoString url; - mTarget->GetSpec(url); - alertsService->ShowAlertNotification(NS_LITERAL_STRING("moz-icon://") + NS_ConvertUTF8toUTF16(url), - finishedTitle, finishedText, PR_TRUE, - NS_LITERAL_STRING("download"), this, - EmptyString()); -} - -NS_IMETHODIMP -nsDownload::OnStateChange(nsIWebProgress* aWebProgress, - nsIRequest* aRequest, PRUint32 aStateFlags, - nsresult aStatus) -{ - // Record the start time only if it hasn't been set. - if (LL_IS_ZERO(mStartTime) && (aStateFlags & STATE_START)) - SetStartTime(PR_Now()); - - // When we break the ref cycle with mPersist, we don't want to lose - // access to out member vars! - nsRefPtr kungFuDeathGrip(this); - - // We need to update mDownloadState before updating the dialog, because - // that will close and call CancelDownload if it was the last open window. - nsresult rv = NS_OK; - if (aStateFlags & STATE_STOP) { - if (mDownloadState == DOWNLOADING || mDownloadState == NOTSTARTED) { - mDownloadState = FINISHED; - - // Set file size at the end of a transfer (for unknown transfer amounts) - if (mMaxBytes == -1) - mMaxBytes = mCurrBytes; - - // Files less than 1Kb shouldn't show up as 0Kb. - if (mMaxBytes < 1024) { - mCurrBytes = 1024; - mMaxBytes = 1024; - } - - mPercentComplete = 100; - - // Play a sound or show an alert when the download finishes - PRBool playSound = PR_FALSE; - PRBool showAlert = PR_FALSE; - nsXPIDLCString soundStr; - - nsCOMPtr prefs = do_GetService("@mozilla.org/preferences-service;1"); - - if (prefs) { - nsCOMPtr prefBranch; - prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); - if (prefBranch) { - rv = prefBranch->GetBoolPref("browser.download.finished_download_sound", &playSound); - if (NS_SUCCEEDED(rv) && playSound) - prefBranch->GetCharPref("browser.download.finished_sound_url", getter_Copies(soundStr)); - rv = prefBranch->GetBoolPref("browser.download.finished_download_alert", &showAlert); - if (NS_FAILED(rv)) - showAlert = PR_FALSE; - } - } - - if (!soundStr.IsEmpty()) { - if (!mDownloadManager->mSoundInterface) { - mDownloadManager->mSoundInterface = do_CreateInstance("@mozilla.org/sound;1"); - } - if (mDownloadManager->mSoundInterface) { - nsCOMPtr soundURI; - - NS_NewURI(getter_AddRefs(soundURI), soundStr); - nsCOMPtr soundURL(do_QueryInterface(soundURI)); - if (soundURL) - mDownloadManager->mSoundInterface->Play(soundURL); - else - mDownloadManager->mSoundInterface->Beep(); - } - } - if (showAlert) - DisplayDownloadFinishedAlert(); - - nsCAutoString path; - rv = GetFilePathUTF8(mTarget, path); - // can't do an early return; have to break reference cycle below - if (NS_SUCCEEDED(rv)) { - mDownloadManager->DownloadEnded(path, nsnull); - } - } - - // break the cycle we created in AddDownload - mCancelable = nsnull; - // and the one with the progress dialog - if (mDialog) { - mDialog->SetObserver(nsnull); - mDialog = nsnull; - } - } - - if (mDownloadManager->MustUpdateUI()) { - nsCOMPtr internalListener; - mDownloadManager->GetInternalListener(getter_AddRefs(internalListener)); - if (internalListener) - internalListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus, this); - } - - if (mDialogListener) { - mDialogListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus, this); - if (aStateFlags & STATE_STOP) { - // Break this cycle, too - mDialogListener = nsnull; - } - } - - return rv; -} - -NS_IMETHODIMP -nsDownload::OnSecurityChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, PRUint32 aState) -{ - if (mDownloadManager->MustUpdateUI()) { - nsCOMPtr internalListener; - mDownloadManager->GetInternalListener(getter_AddRefs(internalListener)); - if (internalListener) - internalListener->OnSecurityChange(aWebProgress, aRequest, aState, this); - } - - if (mDialogListener) - mDialogListener->OnSecurityChange(aWebProgress, aRequest, aState, this); - - return NS_OK; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsIDownload - -NS_IMETHODIMP -nsDownload::Init(nsIURI* aSource, - nsIURI* aTarget, - const nsAString& aDisplayName, - nsIMIMEInfo *aMIMEInfo, - PRTime aStartTime, - nsILocalFile* aTempFile, - nsICancelable* aCancelable) -{ - NS_NOTREACHED("Huh...how did we get here?!"); - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetDisplayName(nsAString &aDisplayName) -{ - aDisplayName = mDisplayName; - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetCancelable(nsICancelable** aCancelable) -{ - *aCancelable = mCancelable; - NS_IF_ADDREF(*aCancelable); - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetTarget(nsIURI** aTarget) -{ - *aTarget = mTarget; - NS_IF_ADDREF(*aTarget); - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetSource(nsIURI** aSource) -{ - *aSource = mSource; - NS_IF_ADDREF(*aSource); - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetStartTime(PRInt64* aStartTime) -{ - *aStartTime = mStartTime; - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetPercentComplete(PRInt32* aPercentComplete) -{ - *aPercentComplete = mPercentComplete; - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetAmountTransferred(PRUint64* aAmountTransferred) -{ - *aAmountTransferred = mCurrBytes; - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetSize(PRUint64* aSize) -{ - *aSize = mMaxBytes; - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetMIMEInfo(nsIMIMEInfo** aMIMEInfo) -{ - *aMIMEInfo = mMIMEInfo; - NS_IF_ADDREF(*aMIMEInfo); - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetTargetFile(nsILocalFile** aTargetFile) -{ - nsresult rv; - - nsCOMPtr fileURL = do_QueryInterface(mTarget, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr file; - rv = fileURL->GetFile(getter_AddRefs(file)); - if (NS_SUCCEEDED(rv)) - rv = CallQueryInterface(file, aTargetFile); - return rv; -} - -NS_IMETHODIMP -nsDownload::GetSpeed(double* aSpeed) -{ - *aSpeed = mSpeed; - return NS_OK; -} - -NS_IMETHODIMP -nsDownload::GetId(PRUint32 *aId) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDownload::GetState(PRInt16 *aState) -{ - *aState = mDownloadState; - return NS_OK; -} - -nsresult -nsDownload::SetTempFile(nsILocalFile* aTempFile) -{ - mTempFile = aTempFile; - return NS_OK; -} diff --git a/xpfe/components/download-manager/src/nsDownloadManager.h b/xpfe/components/download-manager/src/nsDownloadManager.h deleted file mode 100644 index 5987c5c8b975..000000000000 --- a/xpfe/components/download-manager/src/nsDownloadManager.h +++ /dev/null @@ -1,188 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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 - * Ben Goodger - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef downloadmanager___h___ -#define downloadmanager___h___ - -#include "nsIDownloadManager.h" -#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 "nsIURI.h" -#include "nsILocalFile.h" -#include "nsRefPtrHashtable.h" -#include "nsIRequest.h" -#include "nsIObserver.h" -#include "nsIStringBundle.h" -#include "nsIProgressDialog.h" -#include "nsIMIMEInfo.h" -#include "nsISound.h" -#include "nsAutoPtr.h" - -enum DownloadState { NOTSTARTED = -1, DOWNLOADING, FINISHED, FAILED, CANCELED }; - -class nsDownload; - -class nsDownloadManager : public nsIDownloadManager, - public nsIDOMEventListener, - public nsIObserver -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIDOWNLOADMANAGER - NS_DECL_NSIDOMEVENTLISTENER - NS_DECL_NSIOBSERVER - - nsresult Init(); - - nsDownloadManager(); - ~nsDownloadManager(); - -protected: - nsresult GetDownloadsContainer(nsIRDFContainer** aResult); - nsresult GetProfileDownloadsFileURL(nsCString& aDownloadsFileURL); - nsresult GetInternalListener(nsIDownloadProgressListener** aInternalListener); - nsresult GetDataSource(nsIRDFDataSource** aDataSource); - nsresult AssertProgressInfo(); - nsresult AssertProgressInfoFor(const nsACString& aTargetPath); - nsresult DownloadStarted(const nsACString& aTargetPath); - nsresult DownloadEnded(const nsACString& aTargetPath, const PRUnichar* aMessage); - PRBool MustUpdateUI() { if (mDocument) return PR_TRUE; return PR_FALSE; } - - nsCOMPtr mSoundInterface; - -private: - nsCOMPtr mDataSource; - nsCOMPtr mDocument; - nsCOMPtr mDownloadsContainer; - nsCOMPtr mListener; - nsCOMPtr mRDFContainerUtils; - nsCOMPtr mBundle; - PRInt32 mBatches; - nsRefPtrHashtable mCurrDownloads; - - friend class nsDownload; -}; - -class nsDownload : public nsIDownload, - public nsIObserver -{ -public: - NS_DECL_NSIWEBPROGRESSLISTENER - NS_DECL_NSIWEBPROGRESSLISTENER2 - NS_DECL_NSITRANSFER - NS_DECL_NSIDOWNLOAD - NS_DECL_NSIOBSERVER - NS_DECL_ISUPPORTS - - nsDownload(nsDownloadManager* aManager, nsIURI* aTarget, nsIURI* aSource, - nsICancelable* aCancelable); - ~nsDownload(); - - nsresult Cancel(); - nsresult Suspend(); - nsresult SetDisplayName(const PRUnichar* aDisplayName); - nsresult SetTempFile(nsILocalFile* aTempFile); - nsresult Resume(); - void DisplayDownloadFinishedAlert(); - - void SetDialogListener(nsIDownloadProgressListener* aInternalListener) { - mDialogListener = aInternalListener; - } - void SetDialog(nsIProgressDialog* aDialog) { - mDialog = aDialog; - } - // May return null - nsIProgressDialog* GetDialog() { - return mDialog; - } - - struct TransferInformation { - PRInt64 mCurrBytes, mMaxBytes; - TransferInformation(PRInt64 aCurr, PRInt64 aMax) : - mCurrBytes(aCurr), - mMaxBytes(aMax) - {} - }; - - TransferInformation GetTransferInformation() { - return TransferInformation(mCurrBytes, mMaxBytes); - } - DownloadState GetDownloadState() { - return mDownloadState; - } - void SetDownloadState(DownloadState aState) { - mDownloadState = aState; - } - void SetMIMEInfo(nsIMIMEInfo* aMIMEInfo) { - mMIMEInfo = aMIMEInfo; - } - void SetStartTime(PRInt64 aStartTime) { - mStartTime = aStartTime; - mLastUpdate = aStartTime; - } -private: - nsRefPtr mDownloadManager; - - nsString mDisplayName; - - nsCOMPtr mTarget; - nsCOMPtr mSource; - nsCOMPtr mDialogListener; - nsCOMPtr mCancelable; - nsCOMPtr mRequest; - nsCOMPtr mDialog; - nsCOMPtr mMIMEInfo; - nsCOMPtr mTempFile; - DownloadState mDownloadState; - - PRInt32 mPercentComplete; - PRUint64 mCurrBytes; - PRUint64 mMaxBytes; - PRTime mStartTime; - PRTime mLastUpdate; - double mSpeed; -}; - -#endif diff --git a/xpfe/components/download-manager/src/nsDownloadProgressListener.js b/xpfe/components/download-manager/src/nsDownloadProgressListener.js deleted file mode 100644 index 775a46d801da..000000000000 --- a/xpfe/components/download-manager/src/nsDownloadProgressListener.js +++ /dev/null @@ -1,314 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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 (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var gStrings = new Array; -const interval = 500; // Update every 500 milliseconds. - -function nsDownloadProgressListener() { -} - -nsDownloadProgressListener.prototype = { - rateChanges: 0, - rateChangeLimit: 0, - priorRate: "", - lastUpdate: -500, - doc: null, - get document() { - return this.doc; - }, - set document(newval) { - return this.doc = newval; - }, - onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus, aDownload) - { - if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) - { - var aDownloadID = aDownload.targetFile.path; - var elt = this.doc.getElementById(aDownloadID).firstChild.firstChild; - - var timeRemainingCol = elt.nextSibling.nextSibling.nextSibling; - timeRemainingCol.setAttribute("label", ""); - - var speedCol = timeRemainingCol.nextSibling.nextSibling; - speedCol.setAttribute("label", ""); - - var elapsedCol = speedCol.nextSibling; - elapsedCol.setAttribute("label", ""); - - // Fire an onselect event for the downloadView element - // to update menu status - var event = this.doc.createEvent('Events'); - event.initEvent('select', false, true); - this.doc.getElementById("downloadView").dispatchEvent(event); - } - }, - - onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, - aCurTotalProgress, aMaxTotalProgress, aDownload) - { - var overallProgress = aCurTotalProgress; - // Get current time. - var now = ( new Date() ).getTime(); - // If interval hasn't elapsed, ignore it. - if ( now - this.lastUpdate < interval && aMaxTotalProgress != "-1" && parseInt(aCurTotalProgress) < parseInt(aMaxTotalProgress) ) { - return; - } - - // Update this time. - this.lastUpdate = now; - - var aDownloadID = aDownload.targetFile.path - var elt = this.doc.getElementById(aDownloadID).firstChild.firstChild; - if (this.doc.getElementById("TimeElapsed").getAttribute("hidden") != "true") { - elapsedCol = elt.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling; - // Update elapsed time display. - elapsedCol.setAttribute("label", formatSeconds( now / 1000 - aDownload.startTime / 1000000, this.doc )); - } - // Calculate percentage. - var percent; - var progressCol = elt.nextSibling; - if ( aMaxTotalProgress > 0) - { - percent = Math.floor((overallProgress*100.0)/aMaxTotalProgress); - if ( percent > 100 ) - percent = 100; - - // Advance progress meter. - progressCol.setAttribute( "value", percent ); - - progressCol.setAttribute("mode", "normal"); - } - else - { - percent = -1; - - // Progress meter should be barber-pole in this case. - progressCol.setAttribute( "mode", "undetermined" ); - } - - // now that we've set the progress and the time, update # bytes downloaded... - // Update status (nnK of mmK bytes at xx.xK aCurTotalProgress/sec) - var status = getString( "progressMsgNoRate", this.doc ); - - // Insert 1 is the number of kilobytes downloaded so far. - status = replaceInsert( status, 1, parseInt( overallProgress/1024 + .5 ) ); - - // Insert 2 is the total number of kilobytes to be downloaded (if known). - if ( aMaxTotalProgress != "-1" ) - status = replaceInsert( status, 2, parseInt( aMaxTotalProgress/1024 + .5 ) ); - else - status = replaceInsert( status, 2, "??" ); - - var rateMsg = getString( "rateMsg", this.doc ); - var rate = aDownload.speed; - if ( rate ) - { - // rate is bytes/sec - var kRate = (rate / 1024).toFixed(1); // kilobytes/sec - - // Don't update too often! - if ( kRate != this.priorRate ) - { - if ( this.rateChanges++ == this.rateChangeLimit ) - { - // Time to update download rate. - this.priorRate = kRate; - this.rateChanges = 0; - } - else - { - // Stick with old rate for a bit longer. - kRate = this.priorRate; - } - } - else - this.rateChanges = 0; - - // Insert 3 is the download rate (in kilobytes/sec). - rateMsg = replaceInsert( rateMsg, 1, kRate ); - } - else - rateMsg = replaceInsert( rateMsg, 1, "??.?" ); - - var timeRemainingCol = elt.nextSibling.nextSibling.nextSibling; - - // Update status msg. - var statusCol = timeRemainingCol.nextSibling; - statusCol.setAttribute("label", status); - - var speedCol = statusCol.nextSibling; - speedCol.setAttribute("label", rateMsg); - // Update percentage label on progress meter. - if (this.doc.getElementById("ProgressPercent").getAttribute("hidden") != "true") { - var progressText = elt.nextSibling.nextSibling; - if (percent < 0) - progressText.setAttribute("label", ""); - else { - var percentMsg = getString( "percentMsg", this.doc ); - percentMsg = replaceInsert( percentMsg, 1, percent ); - progressText.setAttribute("label", percentMsg); - } - } - // Update time remaining. - if ( rate && (aMaxTotalProgress > 0) ) - { - var rem = ( aMaxTotalProgress - aCurTotalProgress ) / rate; - rem = parseInt( rem + .5 ); - timeRemainingCol.setAttribute("label", formatSeconds( rem, this.doc )); - } - else - timeRemainingCol.setAttribute("label", getString( "unknownTime", this.doc )); - }, - onLocationChange: function(aWebProgress, aRequest, aLocation, aDownload) - { - }, - onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage, aDownload) - { - }, - onSecurityChange: function(aWebProgress, aRequest, state, aDownload) - { - }, - QueryInterface : function(iid) - { - if (iid.equals(Components.interfaces.nsIDownloadProgressListener) || - iid.equals(Components.interfaces.nsISupports)) - return this; - - throw Components.results.NS_NOINTERFACE; - } -}; - -var nsDownloadProgressListenerFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - return (new nsDownloadProgressListener()).QueryInterface(iid); - } -}; - -var nsDownloadProgressListenerModule = { - - registerSelf: function (compMgr, fileSpec, location, type) - { - var compReg = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compReg.registerFactoryLocation(Components.ID("{09cddbea-1dd2-11b2-aa15-c41ffea19d79}"), - "Download Progress Listener", - "@mozilla.org/download-manager/listener;1", - fileSpec, location, type); - }, - canUnload: function(compMgr) - { - return true; - }, - - getClassObject: function (compMgr, cid, iid) { - if (!cid.equals(Components.ID("{09cddbea-1dd2-11b2-aa15-c41ffea19d79}"))) - throw Components.results.NS_ERROR_NO_INTERFACE; - - if (!iid.equals(Components.interfaces.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - return nsDownloadProgressListenerFactory; - } -}; - -function NSGetModule(compMgr, fileSpec) { - return nsDownloadProgressListenerModule; -} - -function replaceInsert( text, index, value ) { - var result = text; - var regExp = new RegExp( "#"+index ); - result = result.replace( regExp, value ); - return result; -} - -function getString( stringId, doc ) { - // Check if we've fetched this string already. - if ( !gStrings[ stringId ] ) { - // Try to get it. - var elem = doc.getElementById( "strings."+stringId ); - try { - if ( elem - && - elem.childNodes - && - elem.childNodes[0] - && - elem.childNodes[0].nodeValue ) { - gStrings[ stringId ] = elem.childNodes[0].nodeValue; - } else { - // If unable to fetch string, use an empty string. - gStrings[ stringId ] = ""; - } - } catch (e) { gStrings[ stringId ] = ""; } - } - return gStrings[ stringId ]; -} - -function formatSeconds( secs, doc ) -{ - // Round the number of seconds to remove fractions. - secs = parseInt( secs + .5 ); - var hours = parseInt( secs/3600 ); - secs -= hours*3600; - var mins = parseInt( secs/60 ); - secs -= mins*60; - var result; - if ( hours ) - result = getString( "longTimeFormat", doc ); - else - result = getString( "shortTimeFormat", doc ); - - if ( hours < 10 ) - hours = "0" + hours; - if ( mins < 10 ) - mins = "0" + mins; - if ( secs < 10 ) - secs = "0" + secs; - - // Insert hours, minutes, and seconds into result string. - result = replaceInsert( result, 1, hours ); - result = replaceInsert( result, 2, mins ); - result = replaceInsert( result, 3, secs ); - - return result; -} - - diff --git a/xpfe/components/download-manager/src/nsDownloadProxy.h b/xpfe/components/download-manager/src/nsDownloadProxy.h deleted file mode 100644 index ddf59eadd43e..000000000000 --- a/xpfe/components/download-manager/src/nsDownloadProxy.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * 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/ - * - * 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 (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 MPL, 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 MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef downloadproxy___h___ -#define downloadproxy___h___ - -#include "nsCOMPtr.h" -#include "nsIDownload.h" -#include "nsIDownloadManager.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "nsIMIMEInfo.h" - -#define DOWNLOAD_MANAGER_BEHAVIOR_PREF "browser.downloadmanager.behavior" - -class nsDownloadProxy : public nsITransfer -{ -public: - - nsDownloadProxy() { } - virtual ~nsDownloadProxy() { } - - NS_DECL_ISUPPORTS - NS_FORWARD_SAFE_NSIWEBPROGRESSLISTENER(mInner) - NS_FORWARD_SAFE_NSIWEBPROGRESSLISTENER2(mInner) - - NS_IMETHODIMP Init(nsIURI* aSource, - nsIURI* aTarget, - const nsAString& aDisplayName, - nsIMIMEInfo *aMIMEInfo, - PRTime aStartTime, - nsILocalFile* aTempFile, - nsICancelable* aCancelable) { - nsresult rv; - nsCOMPtr dm = do_GetService("@mozilla.org/download-manager;1", &rv); - if (NS_FAILED(rv)) - return rv; - - rv = dm->AddDownload(aSource, aTarget, aDisplayName, aMIMEInfo, aStartTime, - aTempFile, aCancelable, getter_AddRefs(mInner)); - if (NS_FAILED(rv)) - return rv; - - PRInt32 behavior; - nsCOMPtr branch = do_GetService("@mozilla.org/preferences-service;1", &rv); - if (NS_SUCCEEDED(rv)) - rv = branch->GetIntPref(DOWNLOAD_MANAGER_BEHAVIOR_PREF, &behavior); - if (NS_FAILED(rv)) - behavior = 0; - - if (behavior == 0) - rv = dm->Open(nsnull, mInner); - else if (behavior == 1) - rv = dm->OpenProgressDialogFor(mInner, nsnull, PR_TRUE); - return rv; - } -private: - nsCOMPtr mInner; -}; - -NS_IMPL_ISUPPORTS3(nsDownloadProxy, nsITransfer, - nsIWebProgressListener, nsIWebProgressListener2) - -#endif