mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
bug 273971 patch by Son Le <son.le0@gmail.com> r=biesi sr=neil
- make nsIDownload::currBytes and maxBytes use bytes rather than kilobytes - make transfers of unknown size use the right size - send mProgress rather than mContentLength as the current progress in OnStateChange
This commit is contained in:
parent
c6d79334bd
commit
c6e491a9d3
@ -459,9 +459,12 @@ nsDownloadManager::AssertProgressInfoFor(const PRUnichar* aPath)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// update transferred
|
||||
PRInt32 current = 0;
|
||||
PRInt32 max = 0;
|
||||
internalDownload->GetTransferInformation(¤t, &max);
|
||||
nsDownload::TransferInformation transferInfo =
|
||||
internalDownload->GetTransferInformation();
|
||||
|
||||
// convert from bytes to kbytes for progress display
|
||||
PRInt64 current = (PRFloat64)transferInfo.mCurrBytes / 1024 + .5;
|
||||
PRInt64 max = (PRFloat64)transferInfo.mMaxBytes / 1024 + .5;
|
||||
|
||||
nsAutoString currBytes; currBytes.AppendInt(current);
|
||||
nsAutoString maxBytes; maxBytes.AppendInt(max);
|
||||
@ -1934,12 +1937,10 @@ nsDownload::SetDisplayName(const PRUnichar* aDisplayName)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDownload::GetTransferInformation(PRInt32* aCurr, PRInt32* aMax)
|
||||
nsDownload::TransferInformation
|
||||
nsDownload::GetTransferInformation()
|
||||
{
|
||||
*aCurr = mCurrBytes;
|
||||
*aMax = mMaxBytes;
|
||||
return NS_OK;
|
||||
return TransferInformation(mCurrBytes, mMaxBytes);
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -1993,8 +1994,8 @@ nsDownload::OnProgressChange64(nsIWebProgress *aWebProgress,
|
||||
else
|
||||
mPercentComplete = -1;
|
||||
|
||||
mCurrBytes = (PRInt32)((PRFloat64)aCurTotalProgress / 1024.0 + .5);
|
||||
mMaxBytes = (PRInt32)((PRFloat64)aMaxTotalProgress / 1024 + .5);
|
||||
mCurrBytes = aCurTotalProgress;
|
||||
mMaxBytes = aMaxTotalProgress;
|
||||
|
||||
if (mDownloadManager->NeedsUIUpdate()) {
|
||||
nsCOMPtr<nsIDownloadProgressListener> dpl;
|
||||
@ -2095,10 +2096,16 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
|
||||
else
|
||||
mDownloadState = nsIXPInstallManagerUI::INSTALL_FINISHED;
|
||||
|
||||
// Set file size at the end of a tranfer (for unknown transfer amounts)
|
||||
if (mMaxBytes == -1)
|
||||
mMaxBytes = mCurrBytes;
|
||||
|
||||
// Files less than 1Kb shouldn't show up as 0Kb.
|
||||
if (mMaxBytes==0)
|
||||
mMaxBytes = 1;
|
||||
mCurrBytes = mMaxBytes;
|
||||
if (mMaxBytes < 1024) {
|
||||
mCurrBytes = 1024;
|
||||
mMaxBytes = 1024;
|
||||
}
|
||||
|
||||
mPercentComplete = 100;
|
||||
|
||||
nsAutoString path;
|
||||
|
@ -223,13 +223,21 @@ protected:
|
||||
nsresult SetTarget(nsIURI* aTarget);
|
||||
nsresult SetDisplayName(const PRUnichar* aDisplayName);
|
||||
nsresult SetSource(nsIURI* aSource);
|
||||
nsresult GetTransferInformation(PRInt32* aCurr, PRInt32* aMax);
|
||||
nsresult SetMIMEInfo(nsIMIMEInfo* aMIMEInfo);
|
||||
nsresult SetStartTime(PRInt64 aStartTime);
|
||||
|
||||
void Pause(PRBool aPaused);
|
||||
PRBool IsPaused();
|
||||
|
||||
struct TransferInformation {
|
||||
PRInt64 mCurrBytes, mMaxBytes;
|
||||
TransferInformation(PRInt64 aCurr, PRInt64 aMax) :
|
||||
mCurrBytes(aCurr),
|
||||
mMaxBytes(aMax)
|
||||
{}
|
||||
};
|
||||
TransferInformation GetTransferInformation();
|
||||
|
||||
nsDownloadManager* mDownloadManager;
|
||||
nsCOMPtr<nsIURI> mTarget;
|
||||
|
||||
|
@ -45,7 +45,7 @@ interface nsICancelable;
|
||||
interface nsIWebProgressListener;
|
||||
interface nsIMIMEInfo;
|
||||
|
||||
[scriptable, uuid(9e1fd9f2-9727-4926-85cd-f16c375bba6d)]
|
||||
[scriptable, uuid(a60c9199-2e21-434f-a43b-ab954ea2f6b7)]
|
||||
interface nsIDownload : nsITransfer {
|
||||
|
||||
/**
|
||||
@ -60,12 +60,12 @@ interface nsIDownload : nsITransfer {
|
||||
readonly attribute PRInt32 percentComplete;
|
||||
|
||||
/**
|
||||
* The amount of kbytes downloaded so far.
|
||||
* The amount of bytes downloaded so far.
|
||||
*/
|
||||
readonly attribute PRUint64 amountTransferred;
|
||||
|
||||
/**
|
||||
* The size of file in kbytes.
|
||||
* The size of file in bytes.
|
||||
* Unknown size is represented by 0.
|
||||
*/
|
||||
readonly attribute PRUint64 size;
|
||||
|
@ -2064,7 +2064,7 @@ nsresult nsExternalAppHandler::ExecuteDesiredAction()
|
||||
{
|
||||
if (!mCanceled)
|
||||
{
|
||||
mWebProgressListener->OnProgressChange64(nsnull, nsnull, mContentLength, mContentLength, mContentLength, mContentLength);
|
||||
mWebProgressListener->OnProgressChange64(nsnull, nsnull, mProgress, mContentLength, mProgress, mContentLength);
|
||||
}
|
||||
mWebProgressListener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, NS_OK);
|
||||
}
|
||||
|
@ -396,9 +396,13 @@ nsDownloadManager::AssertProgressInfoFor(const nsACString& aTargetPath)
|
||||
// update transferred
|
||||
nsDownload::TransferInformation transferInfo =
|
||||
internalDownload->GetTransferInformation();
|
||||
|
||||
nsAutoString currBytes; currBytes.AppendInt(transferInfo.mCurrBytes);
|
||||
nsAutoString maxBytes; maxBytes.AppendInt(transferInfo.mMaxBytes);
|
||||
|
||||
// convert from bytes to kbytes for progress display
|
||||
PRInt64 current = (PRFloat64)transferInfo.mCurrBytes / 1024 + .5;
|
||||
PRInt64 max = (PRFloat64)transferInfo.mMaxBytes / 1024 + .5;
|
||||
|
||||
nsAutoString currBytes; currBytes.AppendInt(current);
|
||||
nsAutoString maxBytes; maxBytes.AppendInt(max);
|
||||
const PRUnichar *strings[] = {
|
||||
currBytes.get(),
|
||||
maxBytes.get()
|
||||
@ -1045,8 +1049,8 @@ nsDownload::OnProgressChange64(nsIWebProgress *aWebProgress,
|
||||
else
|
||||
mPercentComplete = -1;
|
||||
|
||||
mCurrBytes = ((PRFloat64)aCurTotalProgress / 1024.0 + .5);
|
||||
mMaxBytes = ((PRFloat64)aMaxTotalProgress / 1024 + .5);
|
||||
mCurrBytes = aCurTotalProgress;
|
||||
mMaxBytes = aMaxTotalProgress;
|
||||
|
||||
if (mDownloadManager->MustUpdateUI()) {
|
||||
nsCOMPtr<nsIDownloadProgressListener> internalListener;
|
||||
@ -1205,10 +1209,17 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
|
||||
if (aStateFlags & STATE_STOP) {
|
||||
if (mDownloadState == DOWNLOADING || mDownloadState == NOTSTARTED) {
|
||||
mDownloadState = FINISHED;
|
||||
|
||||
// Set file size at the end of a tranfer (for unknown transfer amounts)
|
||||
if (mMaxBytes == -1)
|
||||
mMaxBytes = mCurrBytes;
|
||||
|
||||
// Files less than 1Kb shouldn't show up as 0Kb.
|
||||
if (mMaxBytes==0)
|
||||
mMaxBytes = 1;
|
||||
mCurrBytes = mMaxBytes;
|
||||
if (mMaxBytes < 1024) {
|
||||
mCurrBytes = 1024;
|
||||
mMaxBytes = 1024;
|
||||
}
|
||||
|
||||
mPercentComplete = 100;
|
||||
|
||||
// Play a sound or show an alert when the download finishes
|
||||
|
@ -138,8 +138,8 @@ public:
|
||||
}
|
||||
|
||||
struct TransferInformation {
|
||||
PRInt32 mCurrBytes, mMaxBytes;
|
||||
TransferInformation(PRInt32 aCurr, PRInt32 aMax) :
|
||||
PRInt64 mCurrBytes, mMaxBytes;
|
||||
TransferInformation(PRInt64 aCurr, PRInt64 aMax) :
|
||||
mCurrBytes(aCurr),
|
||||
mMaxBytes(aMax)
|
||||
{}
|
||||
|
Loading…
Reference in New Issue
Block a user