Bug 298842 make the temp file part of nsITransfer
r=mconnor sr=darin a=shaver git-svn-id: svn://10.0.0.236/trunk@175720 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -71,7 +71,8 @@ NS_IMPL_ISUPPORTS_INHERITED4(nsDownloadListener, CHDownloader, nsIDownload,
|
||||
/* void init (in nsIURI aSource, in nsIURI aTarget, in AString aDisplayName, in wstring openingWith, in long long startTime, in nsICancelable aCancelable); */
|
||||
NS_IMETHODIMP
|
||||
nsDownloadListener::Init(nsIURI *aSource, nsIURI *aTarget, const nsAString &aDisplayName,
|
||||
nsIMIMEInfo* aMIMEInfo, PRInt64 startTime, nsICancelable* aCancelable)
|
||||
nsIMIMEInfo* aMIMEInfo, PRInt64 startTime, nsILocalFile* aTempFile,
|
||||
nsICancelable* aCancelable)
|
||||
{
|
||||
// get the local file corresponding to the given target URI
|
||||
nsCOMPtr<nsILocalFile> targetFile;
|
||||
|
||||
@@ -64,10 +64,11 @@ NS_IMPL_ISUPPORTS_INHERITED4(nsDownloadListener, CHDownloader, nsIDownload,
|
||||
|
||||
#pragma mark -
|
||||
|
||||
/* void init (in nsIURI aSource, in nsILocalFile aTarget, in AString aDisplayName, in wstring openingWith, in long long startTime, in nsICancelable aCancelable); */
|
||||
/* void init (in nsIURI aSource, in nsILocalFile aTarget, in AString aDisplayName, in wstring openingWith, in long long startTime, in nsILocalFile aTempFile, in nsICancelable aCancelable); */
|
||||
NS_IMETHODIMP
|
||||
nsDownloadListener::Init(nsIURI *aSource, nsILocalFile *aTarget, const nsAString &aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsICancelable* aCancelable)
|
||||
nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsILocalFile* aTempFile,
|
||||
nsICancelable* aCancelable)
|
||||
{
|
||||
CreateDownloadDisplay(); // call the base class to make the download UI
|
||||
|
||||
|
||||
@@ -75,8 +75,10 @@ NS_IMPL_ISUPPORTS4(CDownload, nsIDownload, nsITransfer,
|
||||
#pragma mark -
|
||||
#pragma mark [CDownload::nsIDownload]
|
||||
|
||||
/* void init (in nsIURI aSource, in nsILocalFile aTarget, in wstring aDisplayName, in nsIMIMEInfo aMIMEInfo, in long long startTime, in nsICancelable aCancelable); */
|
||||
NS_IMETHODIMP CDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName, nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsICancelable* aCancelable)
|
||||
/* void init (in nsIURI aSource, in nsILocalFile aTarget, in wstring aDisplayName, in nsIMIMEInfo aMIMEInfo, in long long startTime, in nsILocalFile aTempFile, in nsICancelable aCancelable); */
|
||||
NS_IMETHODIMP CDownload::Init(nsIURI *aSource, nsILocalFile *aTarget,
|
||||
const PRUnichar *aDisplayName, nsIMIMEInfo *aMIMEInfo, PRInt64 startTime,
|
||||
nsILocalFile* aTempFile, nsICancelable* aCancelable)
|
||||
{
|
||||
try {
|
||||
mSource = aSource;
|
||||
|
||||
@@ -169,7 +169,8 @@ nsProgressDialog.prototype = {
|
||||
this );
|
||||
},
|
||||
|
||||
init: function( aSource, aTarget, aDisplayName, aMIMEInfo, aStartTime, aOperation ) {
|
||||
init: function( aSource, aTarget, aDisplayName, aMIMEInfo, aStartTime,
|
||||
aTempFile, aOperation ) {
|
||||
this.source = aSource;
|
||||
this.target = aTarget;
|
||||
this.displayName = aDisplayName;
|
||||
|
||||
@@ -1916,7 +1916,8 @@ nsresult nsSaveMsgListener::InitializeDownload(nsIRequest * aRequest, PRInt32 aB
|
||||
|
||||
nsCOMPtr<nsIURI> url;
|
||||
channel->GetURI(getter_AddRefs(url));
|
||||
rv = tr->Init(url, outputURI, EmptyString(), mimeinfo, timeDownloadStarted, this);
|
||||
rv = tr->Init(url, outputURI, EmptyString(), mimeinfo,
|
||||
timeDownloadStarted, nsnull, this);
|
||||
|
||||
// now store the web progresslistener
|
||||
mTransfer = tr;
|
||||
|
||||
@@ -51,7 +51,7 @@ interface nsIRDFDataSource;
|
||||
interface nsIDownloadProgressListener;
|
||||
interface nsISupportsArray;
|
||||
|
||||
[scriptable, uuid(31e8cfdc-52c7-4a36-b1c2-8038a12c271d)]
|
||||
[scriptable, uuid(1f280341-30f4-4009-bb0d-a78f2936d1fb)]
|
||||
interface nsIDownloadManager : nsISupports {
|
||||
// Download States
|
||||
const short DOWNLOAD_NOTSTARTED = -1;
|
||||
@@ -81,6 +81,12 @@ interface nsIDownloadManager : nsISupports {
|
||||
*
|
||||
* @param startTime Time when the download started
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
@@ -93,6 +99,7 @@ interface nsIDownloadManager : nsISupports {
|
||||
in AString aIconURL,
|
||||
in nsIMIMEInfo aMIMEInfo,
|
||||
in PRTime aStartTime,
|
||||
in nsILocalFile aTempFile,
|
||||
in nsICancelable aCancelable);
|
||||
|
||||
/**
|
||||
|
||||
@@ -500,6 +500,7 @@ nsDownloadManager::AddDownload(DownloadType aDownloadType,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsICancelable* aCancelable,
|
||||
nsILocalFile* aTempFile,
|
||||
nsIDownload** aDownload)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aSource);
|
||||
@@ -2177,6 +2178,7 @@ nsDownload::Init(nsIURI* aSource,
|
||||
const nsAString& aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsILocalFile* aTempFile,
|
||||
nsICancelable* aCancelable)
|
||||
{
|
||||
NS_WARNING("Huh...how did we get here?!");
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
const nsAString& aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsILocalFile* aTempFile,
|
||||
nsICancelable* aCancelable) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDownloadManager> dm = do_GetService("@mozilla.org/download-manager;1", &rv);
|
||||
@@ -71,7 +72,8 @@ public:
|
||||
|
||||
rv = dm->AddDownload(nsIDownloadManager::DOWNLOAD_TYPE_DOWNLOAD, aSource,
|
||||
aTarget, aDisplayName, EmptyString(), aMIMEInfo,
|
||||
aStartTime, aCancelable, getter_AddRefs(mInner));
|
||||
aStartTime, aCancelable, aTempFile,
|
||||
getter_AddRefs(mInner));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
|
||||
|
||||
@@ -418,13 +418,13 @@ function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
|
||||
|
||||
const kWrapColumn = 80;
|
||||
tr.init((aChosenData ? aChosenData.uri : fileInfo.uri),
|
||||
persistArgs.target, "", null, null, persist);
|
||||
persistArgs.target, "", null, null, null, persist);
|
||||
persist.progressListener = tr;
|
||||
persist.saveDocument(persistArgs.source, persistArgs.target, filesFolder,
|
||||
persistArgs.contentType, encodingFlags, kWrapColumn);
|
||||
} else {
|
||||
tr.init((aChosenData ? aChosenData.uri : source),
|
||||
persistArgs.target, "", null, null, persist);
|
||||
persistArgs.target, "", null, null, null, persist);
|
||||
persist.progressListener = tr;
|
||||
persist.saveURI((aChosenData ? aChosenData.uri : source),
|
||||
null, aReferrer, persistArgs.postData, null,
|
||||
|
||||
@@ -45,7 +45,7 @@ interface nsICancelable;
|
||||
interface nsIWebProgressListener;
|
||||
interface nsIMIMEInfo;
|
||||
|
||||
[scriptable, uuid(1cb42fb4-f092-4a0e-8930-6c06a524da07)]
|
||||
[scriptable, uuid(9e1fd9f2-9727-4926-85cd-f16c375bba6d)]
|
||||
interface nsIDownload : nsITransfer {
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,8 +41,9 @@
|
||||
interface nsIURI;
|
||||
interface nsICancelable;
|
||||
interface nsIMIMEInfo;
|
||||
interface nsILocalFile;
|
||||
|
||||
[scriptable, uuid(0721AAF2-28AC-46cd-BCFA-5F8CA2A8B99B)]
|
||||
[scriptable, uuid(23c51569-e9a1-4a92-adeb-3723db82ef7c)]
|
||||
interface nsITransfer : nsIWebProgressListener2 {
|
||||
|
||||
/**
|
||||
@@ -64,6 +65,12 @@ interface nsITransfer : nsIWebProgressListener2 {
|
||||
* response from the server was received)
|
||||
* XXX presumably wbp and exthandler do this differently
|
||||
*
|
||||
* @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.
|
||||
* Implementations are expected to hold a strong
|
||||
@@ -76,6 +83,7 @@ interface nsITransfer : nsIWebProgressListener2 {
|
||||
in AString aDisplayName,
|
||||
in nsIMIMEInfo aMIMEInfo,
|
||||
in PRTime startTime,
|
||||
in nsILocalFile aTempFile,
|
||||
in nsICancelable aCancelable);
|
||||
};
|
||||
|
||||
@@ -87,19 +95,11 @@ interface nsITransfer : nsIWebProgressListener2 {
|
||||
* Notifications of the download progress will happen via
|
||||
* nsIWebProgressListener/nsIWebProgressListener2.
|
||||
*
|
||||
* If nsIObserver is implemented, the component may get a notification with
|
||||
* topic "temp-file" and an nsILocalFile instance as subject, which indicates
|
||||
* 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.
|
||||
*
|
||||
* INTERFACES THAT MUST BE IMPLEMENTED:
|
||||
* nsITransfer
|
||||
* nsIWebProgressListener
|
||||
* nsIWebProgressListener2
|
||||
*
|
||||
* INTERFACES THAT MAY BE IMPLEMENTED:
|
||||
* nsIObserver
|
||||
*
|
||||
* XXX move this to nsEmbedCID.h once the interfaces (and the contract ID) are
|
||||
* frozen.
|
||||
*/
|
||||
|
||||
@@ -2085,15 +2085,11 @@ nsresult nsExternalAppHandler::InitializeDownload(nsITransfer* aTransfer)
|
||||
rv = NS_NewFileURI(getter_AddRefs(target), mFinalFileDestination);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> lf(do_QueryInterface(mTempFile));
|
||||
rv = aTransfer->Init(mSourceUrl, target, EmptyString(),
|
||||
mMimeInfo, mTimeDownloadStarted, this);
|
||||
mMimeInfo, mTimeDownloadStarted, lf, this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Tell the listener about the location of the target file
|
||||
nsCOMPtr<nsIObserver> obs(do_QueryInterface(aTransfer));
|
||||
if (obs)
|
||||
obs->Observe(mTempFile, "temp-file", nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -394,13 +394,13 @@ function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
|
||||
|
||||
const kWrapColumn = 80;
|
||||
tr.init((aChosenData ? aChosenData.uri : fileInfo.uri),
|
||||
persistArgs.target, "", null, null, persist);
|
||||
persistArgs.target, "", null, null, null, persist);
|
||||
persist.progressListener = tr;
|
||||
persist.saveDocument(persistArgs.source, persistArgs.target, filesFolder,
|
||||
persistArgs.contentType, encodingFlags, kWrapColumn);
|
||||
} else {
|
||||
tr.init((aChosenData ? aChosenData.uri : source),
|
||||
persistArgs.target, "", null, null, persist);
|
||||
persistArgs.target, "", null, null, null, persist);
|
||||
persist.progressListener = tr;
|
||||
persist.saveURI((aChosenData ? aChosenData.uri : source),
|
||||
null, aReferrer, persistArgs.postData, null,
|
||||
|
||||
@@ -49,7 +49,7 @@ interface nsIDownload;
|
||||
interface nsICancelable;
|
||||
interface nsIMIMEInfo;
|
||||
|
||||
[scriptable, uuid(db2eb695-ebb3-4296-9f52-41ddcfce4ca3)]
|
||||
[scriptable, uuid(9cdfcea3-fbe4-4ba1-a0fd-fe273097ddfa)]
|
||||
interface nsIDownloadManager : nsISupports {
|
||||
|
||||
// Methods called by clients to carry out various managing functions
|
||||
@@ -70,6 +70,11 @@ interface nsIDownloadManager : nsISupports {
|
||||
*
|
||||
* @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.
|
||||
@@ -81,6 +86,7 @@ interface nsIDownloadManager : nsISupports {
|
||||
in AString aDisplayName,
|
||||
in nsIMIMEInfo aMIMEInfo,
|
||||
in PRTime startTime,
|
||||
in nsILocalFile aTempFile,
|
||||
in nsICancelable aCancelable);
|
||||
|
||||
/**
|
||||
|
||||
@@ -435,6 +435,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
|
||||
const nsAString& aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsILocalFile* aTempFile,
|
||||
nsICancelable* aCancelable,
|
||||
nsIDownload** aDownload)
|
||||
{
|
||||
@@ -761,7 +762,8 @@ nsDownloadManager::OpenProgressDialogFor(nsIDownload* aDownload, nsIDOMWindow* a
|
||||
nsCOMPtr<nsIMIMEInfo> mimeInfo;
|
||||
aDownload->GetMIMEInfo(getter_AddRefs(mimeInfo));
|
||||
|
||||
dialog->Init(source, target, EmptyString(), mimeInfo, startTime, nsnull);
|
||||
dialog->Init(source, target, EmptyString(), mimeInfo, startTime, nsnull,
|
||||
nsnull);
|
||||
dialog->SetObserver(internalDownload);
|
||||
|
||||
// now set the listener so we forward notifications to the dialog
|
||||
@@ -1307,6 +1309,7 @@ nsDownload::Init(nsIURI* aSource,
|
||||
const nsAString& aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsILocalFile* aTempFile,
|
||||
nsICancelable* aCancelable)
|
||||
{
|
||||
NS_NOTREACHED("Huh...how did we get here?!");
|
||||
|
||||
@@ -64,13 +64,15 @@ public:
|
||||
const nsAString& aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsILocalFile* aTempFile,
|
||||
nsICancelable* aCancelable) {
|
||||
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, aMIMEInfo, aStartTime, aCancelable, getter_AddRefs(mInner));
|
||||
rv = dm->AddDownload(aSource, aTarget, aDisplayName, aMIMEInfo, aStartTime,
|
||||
aTempFile, aCancelable, getter_AddRefs(mInner));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user