Bug 941027 - Store metadata about completed downloads in the download history. r=mak, a=lsblakk
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Fri, 22 Nov 2013 20:19:48 +0100
changeset 166594 9f605581dc87a398996278bb3add1e1f904a2f11
parent 166593 85c967274d60d3a760e926b21f371bca3561a353
child 166595 26e50190587d437a0fdbaaeac35864c4f9127ccf
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
bugs941027
milestone27.0a2
Bug 941027 - Store metadata about completed downloads in the download history. r=mak, a=lsblakk
browser/components/downloads/src/DownloadsCommon.jsm
--- a/browser/components/downloads/src/DownloadsCommon.jsm
+++ b/browser/components/downloads/src/DownloadsCommon.jsm
@@ -54,16 +54,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
                                   "resource://gre/modules/Downloads.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "DownloadUIHelper",
                                   "resource://gre/modules/DownloadUIHelper.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils",
                                   "resource://gre/modules/DownloadUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS",
                                   "resource://gre/modules/osfile.jsm")
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+                                  "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
                                   "resource://gre/modules/PrivateBrowsingUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
                                   "resource:///modules/RecentWindow.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
                                   "resource://gre/modules/Promise.jsm");
@@ -762,16 +764,37 @@ DownloadsDataCtor.prototype = {
     if (oldState != aDataItem.state) {
       for (let view of this._views) {
         try {
           view.getViewItem(aDataItem).onStateChange(oldState);
         } catch (ex) {
           Cu.reportError(ex);
         }
       }
+
+      // This state transition code should actually be located in a Downloads
+      // API module (bug 941009).  Moreover, the fact that state is stored as
+      // annotations should be ideally hidden behind methods of
+      // nsIDownloadHistory (bug 830415).
+      if (!this._isPrivate && !aDataItem.inProgress) {
+        try {
+          let downloadMetaData = { state: aDataItem.state,
+                                   endTime: aDataItem.endTime };
+          if (aDataItem.done) {
+            downloadMetaData.fileSize = aDataItem.maxBytes;
+          }
+
+          PlacesUtils.annotations.setPageAnnotation(
+                        NetUtil.newURI(aDataItem.uri), "downloads/metaData",
+                        JSON.stringify(downloadMetaData), 0,
+                        PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
+        } catch (ex) {
+          Cu.reportError(ex);
+        }
+      }
     }
 
     if (!aDataItem.newDownloadNotified) {
       aDataItem.newDownloadNotified = true;
       this._notifyDownloadEvent("start");
     }
 
     if (!wasDone && aDataItem.done) {