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:
cbiesinger%web.de 2005-12-19 15:25:22 +00:00
parent c6d79334bd
commit c6e491a9d3
6 changed files with 54 additions and 28 deletions

View File

@ -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(&current, &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;

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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

View File

@ -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)
{}