зеркало из https://github.com/mozilla/pjs.git
Download manager. Not part of build. a=asa
This commit is contained in:
Родитель
a6afb9026d
Коммит
4321bd5b2b
|
@ -0,0 +1,113 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Blake Ross <blaker@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIWebProgressListener.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsILocalFile;
|
||||
interface nsIObserver;
|
||||
interface nsIWebBrowserPersist;
|
||||
|
||||
[scriptable, uuid(06cb92f2-1dd2-11b2-95f2-96dfdfb804a1)]
|
||||
interface nsIDownload : nsIWebProgressListener {
|
||||
|
||||
void init(in nsIURI aSource,
|
||||
in nsILocalFile aTarget,
|
||||
in wstring aDisplayName,
|
||||
in nsIWebBrowserPersist aPersist);
|
||||
/**
|
||||
* The source of the download.
|
||||
*/
|
||||
readonly attribute nsIURI source;
|
||||
|
||||
/**
|
||||
* The local file to which the download is being saved.
|
||||
*/
|
||||
readonly attribute nsILocalFile target;
|
||||
|
||||
/**
|
||||
* Optional. If set, it will be used for cancellation, and the download
|
||||
* will be set as its listener. If not, |observer| should be set to listen
|
||||
* and respond accordingly to topics like oncancel, and the client promises
|
||||
* to set the download item as the listener for whatever transfer component
|
||||
* being used.
|
||||
*/
|
||||
|
||||
readonly attribute nsIWebBrowserPersist persist;
|
||||
|
||||
/**
|
||||
* The percentage of completion of the download.
|
||||
*/
|
||||
readonly attribute PRInt32 percentComplete;
|
||||
|
||||
/**
|
||||
* The user-readable description of the download.
|
||||
*/
|
||||
attribute wstring displayName;
|
||||
|
||||
/**
|
||||
* The time a download was started.
|
||||
*/
|
||||
attribute long long startTime;
|
||||
|
||||
/**
|
||||
* Set this attribute to indicate that the download will be
|
||||
* opened with a helper application upon completion.
|
||||
*/
|
||||
attribute wstring openingWith;
|
||||
|
||||
/**
|
||||
* Optional; downloading information is passed to this listener and used to
|
||||
* update client UI.
|
||||
*/
|
||||
attribute nsIWebProgressListener listener;
|
||||
|
||||
/**
|
||||
* If set, receives notifications of events like cancel ("oncancel").
|
||||
* Must be set if no persist object is specified (see above).
|
||||
*/
|
||||
attribute nsIObserver observer;
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_DOWNLOAD_CONTRACTID "@mozilla.org/download;1"
|
||||
// {E3FA9D0A-1DD1-11B2-BDEF-8C720B597445}
|
||||
#define NS_DOWNLOAD_CID \
|
||||
{ 0xe3fa9d0a, 0x1dd1, 0x11b2, { 0xbd, 0xef, 0x8c, 0x72, 0x0b, 0x59, 0x74, 0x45 } }
|
||||
%}
|
|
@ -51,6 +51,7 @@
|
|||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIProgressDialog.h"
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsIWindowWatcher.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
|
@ -662,25 +663,26 @@ nsDownloadManager::OpenProgressDialogFor(const char* aPersistentDescriptor, nsID
|
|||
nsCOMPtr<nsIProgressDialog> dialog(do_CreateInstance("@mozilla.org/progressdialog;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDownload> dl = do_QueryInterface(dialog);
|
||||
|
||||
// now give the dialog the necessary context
|
||||
|
||||
// start time...
|
||||
PRInt64 startTime = 0;
|
||||
download->GetStartTime(&startTime);
|
||||
if (startTime) // possible not to have a start time yet if the dialog was requested immediately
|
||||
dialog->SetStartTime(startTime);
|
||||
dl->SetStartTime(startTime);
|
||||
|
||||
// source...
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
download->GetSource(getter_AddRefs(uri));
|
||||
dialog->SetSource(uri);
|
||||
nsCOMPtr<nsIURI> source;
|
||||
download->GetSource(getter_AddRefs(source));
|
||||
|
||||
// target...
|
||||
nsCOMPtr<nsILocalFile> target;
|
||||
download->GetTarget(getter_AddRefs(target));
|
||||
dialog->SetTarget(target);
|
||||
|
||||
dialog->SetObserver(this);
|
||||
dl->Init(source, target, nsnull, nsnull);
|
||||
dl->SetObserver(this);
|
||||
|
||||
// now set the listener so we forward notifications to the dialog
|
||||
nsCOMPtr<nsIWebProgressListener> listener = do_QueryInterface(dialog);
|
||||
|
@ -688,7 +690,7 @@ nsDownloadManager::OpenProgressDialogFor(const char* aPersistentDescriptor, nsID
|
|||
|
||||
internalDownload->SetDialog(dialog);
|
||||
|
||||
return dialog->Open(aParent, nsnull);
|
||||
return dialog->Open(aParent);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1019,6 +1021,16 @@ nsDownload::OnSecurityChange(nsIWebProgress *aWebProgress,
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIDownload
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::Init(nsIURI* aSource,
|
||||
nsILocalFile* aTarget,
|
||||
const PRUnichar* aDisplayName,
|
||||
nsIWebBrowserPersist* aPersist)
|
||||
{
|
||||
NS_WARNING("Huh...how did we get here?!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::SetDisplayName(const PRUnichar* aDisplayName)
|
||||
{
|
||||
|
@ -1071,16 +1083,16 @@ nsDownload::GetPersist(nsIWebBrowserPersist** aPersist)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::GetStartTime(PRInt64* aStartTime)
|
||||
nsDownload::SetStartTime(PRInt64 aStartTime)
|
||||
{
|
||||
*aStartTime = mStartTime;
|
||||
mStartTime = aStartTime;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::SetStartTime(PRInt64 aStartTime)
|
||||
nsDownload::GetStartTime(PRInt64* aStartTime)
|
||||
{
|
||||
mStartTime = aStartTime;
|
||||
*aStartTime = mStartTime;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1119,4 +1131,18 @@ nsDownload::GetObserver(nsIObserver** aObserver)
|
|||
*aObserver = mObserver;
|
||||
NS_IF_ADDREF(*aObserver);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::SetOpeningWith(const PRUnichar* aOpeningWith)
|
||||
{
|
||||
mOpeningWith = aOpeningWith;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::GetOpeningWith(PRUnichar** aOpeningWith)
|
||||
{
|
||||
*aOpeningWith = ToNewUnicode(mOpeningWith);
|
||||
return NS_OK;
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Blake Ross <blakeross@telocity.com>
|
||||
* Blake Ross <blaker@netscape.com>
|
||||
* Ben Goodger <ben@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
|
@ -51,9 +51,9 @@
|
|||
#include "nsIRDFContainerUtils.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
@ -124,6 +124,8 @@ private:
|
|||
nsDownloadManager* mDownloadManager;
|
||||
|
||||
nsString mDisplayName;
|
||||
nsString mOpeningWith;
|
||||
|
||||
nsCOMPtr<nsILocalFile> mTarget;
|
||||
nsCOMPtr<nsIURI> mSource;
|
||||
nsCOMPtr<nsIWebProgressListener> mListener;
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Blake Ross <blaker@netscape.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef downloadproxy___h___
|
||||
#define downloadproxy___h___
|
||||
|
||||
#include "nsIDownload.h"
|
||||
#include "nsIDownloadManager.h"
|
||||
|
||||
class nsDownloadProxy : nsIDownload
|
||||
{
|
||||
public:
|
||||
|
||||
nsDownloadProxy() { NS_INIT_ISUPPORTS(); }
|
||||
virtual ~nsDownloadProxy() { };
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_NSIWEBPROGRESSLISTENER(mInner->)
|
||||
|
||||
NS_IMETHODIMP Init(nsIURI* aSource,
|
||||
nsILocalFile* aTarget,
|
||||
const PRUnichar* aDisplayName,
|
||||
nsIWebBrowserPersist* aPersist) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDownloadManager> dm = do_GetService("@mozilla.org/download-manager;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = dm->AddDownload(aSource, aTarget, aDisplayName, aPersist, getter_AddRefs(mInner));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char* persistentDescriptor;
|
||||
aTarget->GetPersistentDescriptor(&persistentDescriptor);
|
||||
return dm->OpenProgressDialogFor(persistentDescriptor, nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetDisplayName(PRUnichar** aDisplayName)
|
||||
{
|
||||
return mInner->GetDisplayName(aDisplayName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SetDisplayName(const PRUnichar* aDisplayName)
|
||||
{
|
||||
return mInner->SetDisplayName(aDisplayName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetOpeningWith(PRUnichar** aOpeningWith)
|
||||
{
|
||||
return mInner->GetOpeningWith(aOpeningWith);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SetOpeningWith(const PRUnichar* aOpeningWith)
|
||||
{
|
||||
return mInner->SetOpeningWith(aOpeningWith);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetSource(nsIURI** aSource)
|
||||
{
|
||||
return mInner->GetSource(aSource);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetTarget(nsILocalFile** aTarget)
|
||||
{
|
||||
return mInner->GetTarget(aTarget);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetStartTime(PRInt64* aStartTime)
|
||||
{
|
||||
return mInner->GetStartTime(aStartTime);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SetStartTime(PRInt64 aStartTime)
|
||||
{
|
||||
return mInner->SetStartTime(aStartTime);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetPercentComplete(PRInt32* aPercentComplete)
|
||||
{
|
||||
return mInner->GetPercentComplete(aPercentComplete);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetListener(nsIWebProgressListener** aListener)
|
||||
{
|
||||
return mInner->GetListener(aListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SetListener(nsIWebProgressListener* aListener)
|
||||
{
|
||||
return mInner->SetListener(aListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetObserver(nsIObserver** aObserver)
|
||||
{
|
||||
return mInner->GetObserver(aObserver);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SetObserver(nsIObserver* aObserver)
|
||||
{
|
||||
return mInner->SetObserver(aObserver);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetPersist(nsIWebBrowserPersist** aPersist)
|
||||
{
|
||||
return mInner->GetPersist(aPersist);
|
||||
}
|
||||
private:
|
||||
nsCOMPtr<nsIDownload> mInner;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsDownloadProxy, nsIDownload, nsIWebProgressListener)
|
||||
|
||||
#endif
|
||||
|
Загрузка…
Ссылка в новой задаче