Bug 1354532 - Part 2 - To facilitate the DownloadsSubview, add a 'LimitedHistoryDownloadsData' and 'LimitedPrivateHistoryDownloadData' dataview. r=Paolo

MozReview-Commit-ID: Jkyj2SQ7F00

--HG--
extra : rebase_source : 6342507ccd83187fc1e6690f8ba1a59c26d4c589
This commit is contained in:
Mike de Boer 2017-09-06 16:23:06 +02:00
Родитель bfdabc36cf
Коммит 330e35542c
1 изменённых файлов: 35 добавлений и 6 удалений

Просмотреть файл

@ -78,6 +78,8 @@ const kDownloadsStringsRequiringPluralForm = {
const kPartialDownloadSuffix = ".part";
const kMaxHistoryResultsForLimitedView = 42;
const kPrefBranch = Services.prefs.getBranch("browser.download.");
var PrefObserver = {
@ -193,13 +195,22 @@ this.DownloadsCommon = {
* 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;
},
@ -636,7 +647,7 @@ XPCOMUtils.defineLazyGetter(DownloadsCommon, "isWinVistaOrHigher", function() {
* 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.
@ -648,9 +659,18 @@ function DownloadsDataCtor({ isPrivate, isHistory } = {}) {
// 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;
}
@ -835,6 +855,15 @@ 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 });
});