Bug 931477 - Fix size and percentage display for downloads of unknown size. r=mak, a=lsblakk
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Fri, 22 Nov 2013 20:19:48 +0100
changeset 166595 26e50190587d437a0fdbaaeac35864c4f9127ccf
parent 166594 9f605581dc87a398996278bb3add1e1f904a2f11
child 166596 fd75c8f6cc7d7cd884000e85a6a744e753ed28b4
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, lsblakk
bugs931477
milestone27.0a2
Bug 931477 - Fix size and percentage display for downloads of unknown size. r=mak, a=lsblakk
browser/components/downloads/src/DownloadsCommon.jsm
--- a/browser/components/downloads/src/DownloadsCommon.jsm
+++ b/browser/components/downloads/src/DownloadsCommon.jsm
@@ -1382,20 +1382,36 @@ DownloadsDataItem.prototype = {
       this.state = nsIDM.DOWNLOAD_NOTSTARTED;
     } else {
       this.state = nsIDM.DOWNLOAD_DOWNLOADING;
     }
 
     this.referrer = this._download.source.referrer;
     this.startTime = this._download.startTime;
     this.currBytes = this._download.currentBytes;
-    this.maxBytes = this._download.totalBytes;
     this.resumable = this._download.hasPartialData;
     this.speed = this._download.speed;
-    this.percentComplete = this._download.progress;
+
+    if (this._download.succeeded) {
+      // If the download succeeded, show the final size if available, otherwise
+      // use the last known number of bytes transferred.  The final size on disk
+      // will be available when bug 941063 is resolved.
+      this.maxBytes = this._download.hasProgress ?
+                             this._download.totalBytes :
+                             this._download.currentBytes;
+      this.percentComplete = 100;
+    } else if (this._download.hasProgress) {
+      // If the final size and progress are known, use them.
+      this.maxBytes = this._download.totalBytes;
+      this.percentComplete = this._download.progress;
+    } else {
+      // The download final size and progress percentage is unknown.
+      this.maxBytes = -1;
+      this.percentComplete = -1;
+    }
   },
 
   /**
    * Initializes this object from a download object of the Download Manager.
    *
    * The endTime property is initialized to the current date and time.
    *
    * @param aDownload