Bug 1354532 - Part 6 - Make sure we're using the public session downloads data in the Library panel subview. r?paolo draft
authorMike de Boer <mdeboer@mozilla.com>
Tue, 11 Jul 2017 12:24:34 +0200
changeset 606724 18a78caf7e568291c3f524f48d45935643d552ec
parent 606723 aa893d1ce09cc3b8127ef7df3060ed43a4797942
child 636849 310add73e03ca3d1d0b8ae19a115fce305b2f1b5
push id67791
push usermdeboer@mozilla.com
push dateTue, 11 Jul 2017 10:33:03 +0000
reviewerspaolo
bugs1354532
milestone56.0a1
Bug 1354532 - Part 6 - Make sure we're using the public session downloads data in the Library panel subview. r?paolo MozReview-Commit-ID: 5JflNp8Y6A
browser/components/downloads/DownloadsCommon.jsm
browser/components/downloads/DownloadsPanelSubView.jsm
browser/components/downloads/DownloadsViewUI.jsm
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -277,19 +277,22 @@ this.DownloadsCommon = {
   },
 
   /**
    * Get access to one of the DownloadsData or PrivateDownloadsData objects,
    * depending on the privacy status of the window in question.
    *
    * @param aWindow
    *        The browser window which owns the download button.
+   * @param [optional] forcePublic
+   *        Whether to force the public downloads data to be returned, even if
+   *        we're in private browsing window mode.
    */
-  getData(aWindow) {
-    if (PrivateBrowsingUtils.isContentWindowPrivate(aWindow)) {
+  getData(aWindow, forcePublic = false) {
+    if (!forcePublic && PrivateBrowsingUtils.isContentWindowPrivate(aWindow)) {
       return PrivateDownloadsData;
     }
     return DownloadsData;
   },
 
   /**
    * Initializes the Downloads back-end and starts receiving events for both the
    * private and non-private downloads data objects.
--- a/browser/components/downloads/DownloadsPanelSubView.jsm
+++ b/browser/components/downloads/DownloadsPanelSubView.jsm
@@ -24,17 +24,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/FileUtils.jsm");
 
 let gPanelViewInstances = new WeakMap();
 
 class DownloadsPanelSubView extends DownloadsViewUI.BaseDownloadsPlacesView {
   constructor(event) {
     let document = event.target.ownerDocument
     let window = document.defaultView;
-    super(window);
+    // Pass in `true` to make sure we subscribe to the public session downloads data.
+    super(window, true);
 
     this.context = "panelDownloadsContextMenu";
     this.controller = new DownloadsViewUI.DownloadsPlacesViewController(this);
     this.showLabel = DownloadsCommon.strings[AppConstants.platform == "macosx" ?
       "showMacLabel" : "showLabel"];
     this.openLabel = DownloadsCommon.strings.openFileLabel;
 
     let query = "place:transition=" + Ci.nsINavHistoryService.TRANSITION_DOWNLOAD +
--- a/browser/components/downloads/DownloadsViewUI.jsm
+++ b/browser/components/downloads/DownloadsViewUI.jsm
@@ -41,21 +41,21 @@ this.DownloadsViewUI = {
    * handled by the Downloads user interface, including standard commands.
    */
   isCommandName(name) {
     return name.startsWith("cmd_") || name.startsWith("downloadsCmd_");
   },
 };
 
 this.DownloadsViewUI.BaseDownloadsPlacesView = class {
-  constructor(window) {
-    this.init(window);
+  constructor(window, forcePublicData) {
+    this.init(window, true, forcePublicData);
   }
 
-  init(window, active = true) {
+  init(window, active = true, forcePublicData = false) {
     this.window = window;
 
     // Map download URLs to download element shells regardless of their type
     this._downloadElementsShellsForURI = new Map();
 
     // Map download data items to their element shells.
     this._viewItemsForDownloads = new WeakMap();
 
@@ -64,17 +64,17 @@ this.DownloadsViewUI.BaseDownloadsPlaces
     this._lastSessionDownloadElement = null;
 
     this._searchTerm = "";
 
     this._active = active;
 
     // Register as a downloads view. The places data will be initialized by
     // the places setter.
-    this._downloadsData = DownloadsCommon.getData(window.opener || window);
+    this._downloadsData = DownloadsCommon.getData(window.opener || window, forcePublicData);
     this._downloadsData.addView(this);
 
     // Get the Download button out of the attention state since we're about to
     // view all downloads.
     DownloadsCommon.getIndicatorData(window).attention = DownloadsCommon.ATTENTION_NONE;
   }
 
   destructor() {