Bug 1354532 - Part 2 - To facilitate the DownloadsSubview, add a 'LimitedHistoryDownloadsData' and 'LimitedPrivateHistoryDownloadData' dataview. r=Paolo
☠☠ backed out by 48fa888e2007 ☠ ☠
authorMike de Boer <mdeboer@mozilla.com>
Wed, 06 Sep 2017 16:23:06 +0200
changeset 428667 63909748b3ce21c442c37c3889ffeae0abd43ba5
parent 428666 f1d18c741b2caddeb79714a25a2a7f34914ce1b8
child 428668 545712909b9be7cf10713169c1eac44636589769
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersPaolo
bugs1354532
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1354532 - Part 2 - To facilitate the DownloadsSubview, add a 'LimitedHistoryDownloadsData' and 'LimitedPrivateHistoryDownloadData' dataview. r=Paolo MozReview-Commit-ID: Jkyj2SQ7F00
browser/components/downloads/DownloadsCommon.jsm
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -73,16 +73,18 @@ const kDownloadsStringsRequiringFormatti
 };
 
 const kDownloadsStringsRequiringPluralForm = {
   otherDownloads3: true
 };
 
 const kPartialDownloadSuffix = ".part";
 
+const kMaxHistoryResultsForLimitedView = 42;
+
 const kPrefBranch = Services.prefs.getBranch("browser.download.");
 
 var PrefObserver = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                          Ci.nsISupportsWeakReference]),
   getPref(name) {
     try {
       switch (typeof this.prefs[name]) {
@@ -188,23 +190,32 @@ this.DownloadsCommon = {
    * Get access to one of the DownloadsData, PrivateDownloadsData, or
    * HistoryDownloadsData objects, depending on the privacy status of the
    * specified window and on whether history downloads should be included.
    *
    * @param window
    *        The browser window which owns the download button.
    * @param [optional] history
    *        True to include history downloads when the window is public.
+   * @param [optional] privateAll
+   *        Whether to force the public downloads data to be returned together
+   *        with the private downloads data for a private window.
+   * @param [optional] limited
+   *        True to limit the amount of downloads returned to
+   *        `kMaxHistoryResultsForLimitedView`.
    */
-  getData(window, history = false) {
-    if (PrivateBrowsingUtils.isContentWindowPrivate(window)) {
+  getData(window, history = false, privateAll = false, limited = false) {
+    let isPrivate = PrivateBrowsingUtils.isContentWindowPrivate(window);
+    if (isPrivate && !privateAll) {
       return PrivateDownloadsData;
     }
     if (history) {
-      return HistoryDownloadsData;
+      if (isPrivate && privateAll)
+        return LimitedPrivateHistoryDownloadData;
+      return limited ? LimitedHistoryDownloadsData : HistoryDownloadsData;
     }
     return DownloadsData;
   },
 
   /**
    * Initializes the Downloads back-end and starts receiving events for both the
    * private and non-private downloads data objects.
    */
@@ -631,31 +642,40 @@ XPCOMUtils.defineLazyGetter(DownloadsCom
  *
  * Note that using this object does not automatically initialize the list of
  * downloads. This is useful to display a neutral progress indicator in
  * the main browser window until the autostart timeout elapses.
  *
  * This powers the DownloadsData, PrivateDownloadsData, and HistoryDownloadsData
  * singleton objects.
  */
-function DownloadsDataCtor({ isPrivate, isHistory } = {}) {
+function DownloadsDataCtor({ isPrivate, isHistory, maxHistoryResults } = {}) {
   this._isPrivate = !!isPrivate;
 
   // Contains all the available Download objects and their integer state.
   this.oldDownloadStates = new Map();
 
   // For the history downloads list we don't need to register this as a view,
   // but we have to ensure that the DownloadsData object is initialized before
   // we register more views. This ensures that the view methods of DownloadsData
   // are invoked before those of views registered on HistoryDownloadsData,
   // allowing the endTime property to be set correctly.
   if (isHistory) {
+    if (isPrivate) {
+      PrivateDownloadsData.initializeDataLink();
+    }
     DownloadsData.initializeDataLink();
-    this._promiseList = DownloadsData._promiseList
-                                     .then(() => DownloadHistory.getList());
+    this._promiseList = DownloadsData._promiseList.then(() => {
+      // For history downloads in Private Browsing mode, we'll fetch the combined
+      // list of public and private downloads.
+      return DownloadHistory.getList({
+        type: isPrivate ? Downloads.ALL : Downloads.PUBLIC,
+        maxHistoryResults: maxHistoryResults
+      });
+    });
     return;
   }
 
   // This defines "initializeDataLink" and "_promiseList" synchronously, then
   // continues execution only when "initializeDataLink" is called, allowing the
   // underlying data to be loaded only when actually needed.
   this._promiseList = (async () => {
     await new Promise(resolve => this.initializeDataLink = resolve);
@@ -830,16 +850,25 @@ DownloadsDataCtor.prototype = {
     browserWin.DownloadsPanel.showPanel();
   }
 };
 
 XPCOMUtils.defineLazyGetter(this, "HistoryDownloadsData", function() {
   return new DownloadsDataCtor({ isHistory: true });
 });
 
+XPCOMUtils.defineLazyGetter(this, "LimitedHistoryDownloadsData", function() {
+  return new DownloadsDataCtor({ isHistory: true, maxHistoryResults: kMaxHistoryResultsForLimitedView });
+});
+
+XPCOMUtils.defineLazyGetter(this, "LimitedPrivateHistoryDownloadData", function() {
+  return new DownloadsDataCtor({ isPrivate: true, isHistory: true,
+    maxHistoryResults: kMaxHistoryResultsForLimitedView });
+});
+
 XPCOMUtils.defineLazyGetter(this, "PrivateDownloadsData", function() {
   return new DownloadsDataCtor({ isPrivate: true });
 });
 
 XPCOMUtils.defineLazyGetter(this, "DownloadsData", function() {
   return new DownloadsDataCtor();
 });