Bug 1354532 - Part 2 - To facilitate the DownloadsSubview, add a 'LimitedHistoryDownloadsData' and 'LimitedPrivateHistoryDownloadData' dataview. r?Paolo
MozReview-Commit-ID: Jkyj2SQ7F00
--- 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
+ });
+ });
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();
});