Bug 828247 - Library downloads view does not show the end time for completed downloads.
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 11 Jan 2013 00:32:16 +0100
changeset 127069 ccb73a00491f35f3cbf3af2e07e9d3df35acc21e
parent 127068 f8bbe9e656211656a7d0b711d77aabb3342449b7
child 127070 f188e913bd771b386c67a40ad09fae9ce0414f9d
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs828247
milestone20.0a2
Bug 828247 - Library downloads view does not show the end time for completed downloads. r=Mano a=gavin
browser/components/downloads/content/allDownloadsViewOverlay.js
--- a/browser/components/downloads/content/allDownloadsViewOverlay.js
+++ b/browser/components/downloads/content/allDownloadsViewOverlay.js
@@ -351,47 +351,65 @@ DownloadElementShell.prototype = {
       }
       if (this._dataItem.starting) {
         return s.stateStarting;
       }
       if (this._dataItem.state == nsIDM.DOWNLOAD_SCANNING) {
         return s.stateScanning;
       }
 
-      let [displayHost, fullHost] =
-        DownloadUtils.getURIHost(this._dataItem.referrer ||
-                                 this._dataItem.uri);
-
-      let end = new Date(this.dataItem.endTime);
-      let [displayDate, fullDate] = DownloadUtils.getReadableDates(end);
-      return s.statusSeparator(fullHost, fullDate);
+      throw new Error("_getStatusText called with a bogus download state");
     }
 
+    // This is a not-in-progress or history download.
+    let stateLabel = "";
     switch (this.getDownloadState()) {
       case nsIDM.DOWNLOAD_FAILED:
-        return s.stateFailed;
+        stateLabel = s.stateFailed;
+        break;
       case nsIDM.DOWNLOAD_CANCELED:
-        return s.stateCanceled;
+        stateLabel = s.stateCanceled;
+        break;
       case nsIDM.DOWNLOAD_BLOCKED_PARENTAL:
-        return s.stateBlockedParentalControls;
+        stateLabel = s.stateBlockedParentalControls;
+        break;
       case nsIDM.DOWNLOAD_BLOCKED_POLICY:
-        return s.stateBlockedPolicy;
+        stateLabel = s.stateBlockedPolicy;
+        break;
       case nsIDM.DOWNLOAD_DIRTY:
-        return s.stateDirty;
+        stateLabel = s.stateDirty;
+        break;
       case nsIDM.DOWNLOAD_FINISHED:{
         // For completed downloads, show the file size (e.g. "1.5 MB")
         if (this._targetFileInfoFetched && this._targetFileExists) {
           let [size, unit] = DownloadUtils.convertByteUnits(this._targetFileSize);
-          return s.sizeWithUnits(size, unit);
+          stateLabel = s.sizeWithUnits(size, unit);
+          break;
         }
+        // Fallback to default unknown state.
+      }
+      default:
+        stateLabel = s.sizeUnknown;
         break;
-      }
     }
 
-    return s.sizeUnknown;
+    // TODO (bug 829201): history downloads should get the referrer from Places.
+    let referrer = this._dataItem && this._dataItem.referrer ||
+                   this.downloadURI;
+    let [displayHost, fullHost] = DownloadUtils.getURIHost(referrer);
+
+    // TODO (bug 826991): history downloads should get endTime from annotations.
+    let date = this._dataItem && this._dataItem.endTime ||
+               (this._placesNode.time / 1000);
+    let [displayDate, fullDate] = DownloadUtils.getReadableDates(new Date(date));
+
+    // We use the same XUL label to display the state, the host name, and the
+    // end time.
+    let firstPart = s.statusSeparator(stateLabel, displayHost);
+    return s.statusSeparator(firstPart, displayDate);
   },
 
   // The progressmeter element for the download
   get _progressElement() {
     if (!("__progressElement" in this)) {
       this.__progressElement =
         document.getAnonymousElementByAttribute(this._element, "anonid",
                                                 "progressmeter");