Bug 827976 - Downloads Manager doesn't need a reference to the hidden window. r=mak
☠☠ backed out by bf3cbcc82527 ☠ ☠
authorFelipe Gomes <felipc@gmail.com>
Fri, 01 Mar 2019 21:06:58 +0000
changeset 519899 07ef335770a8c0e985b9491c21882c658d458260
parent 519898 9d3805d77b99ae1e3a6b9b60a8b34af857724974
child 519900 e253b264e7bdfdf28bfb2f15ab0f22cded77d91c
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs827976
milestone67.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 827976 - Downloads Manager doesn't need a reference to the hidden window. r=mak Differential Revision: https://phabricator.services.mozilla.com/D21079
browser/components/downloads/DownloadsCommon.jsm
browser/components/newtab/lib/DownloadsManager.jsm
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -180,29 +180,30 @@ var DownloadsCommon = {
     return PrefObserver.animateNotifications;
   },
 
   /**
    * 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
+   * @param [optional] window
    *        The browser window which owns the download button.
+   *        If not given, the privacy status will be assumed as non-private.
    * @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, privateAll = false, limited = false) {
-    let isPrivate = PrivateBrowsingUtils.isContentWindowPrivate(window);
+    let isPrivate = window && PrivateBrowsingUtils.isContentWindowPrivate(window);
     if (isPrivate && !privateAll) {
       return PrivateDownloadsData;
     }
     if (history) {
       if (isPrivate && privateAll)
         return LimitedPrivateHistoryDownloadData;
       return limited ? LimitedHistoryDownloadsData : HistoryDownloadsData;
     }
--- a/browser/components/newtab/lib/DownloadsManager.jsm
+++ b/browser/components/newtab/lib/DownloadsManager.jsm
@@ -1,15 +1,16 @@
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
 
 const {actionTypes: at} = ChromeUtils.import("resource://activity-stream/common/Actions.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
+  BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
   DownloadsCommon: "resource:///modules/DownloadsCommon.jsm",
   DownloadsViewUI: "resource:///modules/DownloadsViewUI.jsm",
   FileUtils: "resource://gre/modules/FileUtils.jsm",
 });
 
 const DOWNLOAD_CHANGED_DELAY_TIME = 1000; // time in ms to delay timer for downloads changed events
 
 this.DownloadsManager = class DownloadsManager {
@@ -36,18 +37,18 @@ this.DownloadsManager = class DownloadsM
                    DownloadsCommon.strings.sizeUnknown,
       referrer: download.source.referrer,
       date_added: download.endTime,
     };
   }
 
   init(store) {
     this._store = store;
-    this._browser = Services.appShell.hiddenDOMWindow;
-    this._downloadData = DownloadsCommon.getData(this._browser.ownerGlobal, true, false, true);
+    this._downloadData = DownloadsCommon.getData(null /* null for non-private downloads */, 
+                                                 true, false, true);
     this._downloadData.addView(this);
   }
 
   onDownloadAdded(download) {
     if (!this._downloadItems.has(download.source.url)) {
       this._downloadItems.set(download.source.url, download);
 
       // On startup, all existing downloads fire this notification, so debounce them
@@ -136,17 +137,17 @@ this.DownloadsManager = class DownloadsM
           DownloadsCommon.showDownloadedFile(
             new FileUtils.File(download.target.path));
         });
         break;
       case at.OPEN_DOWNLOAD_FILE:
         doDownloadAction(download => {
           DownloadsCommon.openDownloadedFile(
             new FileUtils.File(download.target.path), null,
-            this._browser.ownerGlobal);
+            BrowserWindowTracker.getTopWindow());
         });
         break;
       case at.UNINIT:
         this.uninit();
         break;
     }
   }
 };