mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-22 23:27:30 +09:00
[PALEMOON] Bug 1115379 - Streamline DownloadsViewItemController construction and remove now unneeded identifiers
This commit is contained in:
parent
67f36036d3
commit
a8622a0a10
2 changed files with 29 additions and 39 deletions
|
|
@ -647,12 +647,8 @@ XPCOMUtils.defineLazyGetter(DownloadsCommon, "useJSTransfer", function () {
|
||||||
function DownloadsDataCtor(aPrivate) {
|
function DownloadsDataCtor(aPrivate) {
|
||||||
this._isPrivate = aPrivate;
|
this._isPrivate = aPrivate;
|
||||||
|
|
||||||
// This Object contains all the available DownloadsDataItem objects, indexed by
|
// Contains all the available DownloadsDataItem objects.
|
||||||
// their globally unique identifier. The identifiers of downloads that have
|
this.dataItems = new Set();
|
||||||
// been removed from the Download Manager data are still present, however the
|
|
||||||
// associated objects are replaced with the value "null". This is required to
|
|
||||||
// prevent race conditions when populating the list asynchronously.
|
|
||||||
this.dataItems = {};
|
|
||||||
|
|
||||||
// Array of view objects that should be notified when the available download
|
// Array of view objects that should be notified when the available download
|
||||||
// data changes.
|
// data changes.
|
||||||
|
|
@ -690,8 +686,8 @@ DownloadsDataCtor.prototype = {
|
||||||
*/
|
*/
|
||||||
get canRemoveFinished()
|
get canRemoveFinished()
|
||||||
{
|
{
|
||||||
for (let [, dataItem] of Iterator(this.dataItems)) {
|
for (let dataItem of this.dataItems) {
|
||||||
if (dataItem && !dataItem.inProgress) {
|
if (!dataItem.inProgress) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -716,7 +712,7 @@ DownloadsDataCtor.prototype = {
|
||||||
{
|
{
|
||||||
let dataItem = new DownloadsDataItem(aDownload);
|
let dataItem = new DownloadsDataItem(aDownload);
|
||||||
this._downloadToDataItemMap.set(aDownload, dataItem);
|
this._downloadToDataItemMap.set(aDownload, dataItem);
|
||||||
this.dataItems[dataItem.downloadGuid] = dataItem;
|
this.dataItems.add(dataItem);
|
||||||
|
|
||||||
for (let view of this._views) {
|
for (let view of this._views) {
|
||||||
view.onDataItemAdded(dataItem, true);
|
view.onDataItemAdded(dataItem, true);
|
||||||
|
|
@ -745,7 +741,7 @@ DownloadsDataCtor.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._downloadToDataItemMap.delete(aDownload);
|
this._downloadToDataItemMap.delete(aDownload);
|
||||||
this.dataItems[dataItem.downloadGuid] = null;
|
this.dataItems.delete(dataItem);
|
||||||
for (let view of this._views) {
|
for (let view of this._views) {
|
||||||
view.onDataItemRemoved(dataItem);
|
view.onDataItemRemoved(dataItem);
|
||||||
}
|
}
|
||||||
|
|
@ -861,14 +857,7 @@ DownloadsDataCtor.prototype = {
|
||||||
//let loadedItemsArray = [dataItem
|
//let loadedItemsArray = [dataItem
|
||||||
// for each (dataItem in this.dataItems)
|
// for each (dataItem in this.dataItems)
|
||||||
// if (dataItem)];
|
// if (dataItem)];
|
||||||
|
let loadedItemsArray = [...this.dataItems];
|
||||||
let loadedItemsArray = [];
|
|
||||||
|
|
||||||
for each (let dataItem in this.dataItems) {
|
|
||||||
if (dataItem) {
|
|
||||||
loadedItemsArray.push(dataItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadedItemsArray.sort(function(a, b) b.download.startTime - a.download.startTime);
|
loadedItemsArray.sort(function(a, b) b.download.startTime - a.download.startTime);
|
||||||
loadedItemsArray.forEach(
|
loadedItemsArray.forEach(
|
||||||
|
|
@ -1344,13 +1333,6 @@ function DownloadsDataItem(aSource)
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadsDataItem.prototype = {
|
DownloadsDataItem.prototype = {
|
||||||
/**
|
|
||||||
* The JavaScript API does not need identifiers for Download objects, so they
|
|
||||||
* are generated sequentially for the corresponding DownloadDataItem.
|
|
||||||
*/
|
|
||||||
get _autoIncrementId() ++DownloadsDataItem.prototype.__lastId,
|
|
||||||
__lastId: 0,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this object from the JavaScript API for downloads.
|
* Initializes this object from the JavaScript API for downloads.
|
||||||
*
|
*
|
||||||
|
|
@ -1362,8 +1344,6 @@ DownloadsDataItem.prototype = {
|
||||||
_initFromJSDownload: function (aDownload)
|
_initFromJSDownload: function (aDownload)
|
||||||
{
|
{
|
||||||
this.download = aDownload;
|
this.download = aDownload;
|
||||||
|
|
||||||
this.downloadGuid = "id:" + this._autoIncrementId;
|
|
||||||
this.endTime = Date.now();
|
this.endTime = Date.now();
|
||||||
|
|
||||||
this.updateFromJSDownload();
|
this.updateFromJSDownload();
|
||||||
|
|
@ -2029,7 +2009,7 @@ DownloadsIndicatorDataCtor.prototype = {
|
||||||
{
|
{
|
||||||
let dataItems = this._isPrivate ? PrivateDownloadsData.dataItems
|
let dataItems = this._isPrivate ? PrivateDownloadsData.dataItems
|
||||||
: DownloadsData.dataItems;
|
: DownloadsData.dataItems;
|
||||||
for each (let dataItem in dataItems) {
|
for (let dataItem of dataItems) {
|
||||||
if (dataItem && dataItem.inProgress) {
|
if (dataItem && dataItem.inProgress) {
|
||||||
yield dataItem;
|
yield dataItem;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -895,6 +895,16 @@ const DownloadsView = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associates each richlistitem for a download with its corresponding
|
||||||
|
* DownloadsViewItemController object.
|
||||||
|
*/
|
||||||
|
_controllersForElements: new Map(),
|
||||||
|
|
||||||
|
controllerForElement(element) {
|
||||||
|
return this._controllersForElements.get(element);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new view item associated with the specified data item, and adds
|
* Creates a new view item associated with the specified data item, and adds
|
||||||
* it to the top or the bottom of the list.
|
* it to the top or the bottom of the list.
|
||||||
|
|
@ -907,6 +917,8 @@ const DownloadsView = {
|
||||||
let element = document.createElement("richlistitem");
|
let element = document.createElement("richlistitem");
|
||||||
let viewItem = new DownloadsViewItem(aDataItem, element);
|
let viewItem = new DownloadsViewItem(aDataItem, element);
|
||||||
this._visibleViewItems.set(aDataItem, viewItem);
|
this._visibleViewItems.set(aDataItem, viewItem);
|
||||||
|
let viewItemController = new DownloadsViewItemController(aDataItem);
|
||||||
|
this._controllersForElements.set(element, viewItemController);
|
||||||
if (aNewest) {
|
if (aNewest) {
|
||||||
this.richListBox.insertBefore(element, this.richListBox.firstChild);
|
this.richListBox.insertBefore(element, this.richListBox.firstChild);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -928,6 +940,7 @@ const DownloadsView = {
|
||||||
this.richListBox.itemCount - 1);
|
this.richListBox.itemCount - 1);
|
||||||
}
|
}
|
||||||
this._visibleViewItems.delete(aDataItem);
|
this._visibleViewItems.delete(aDataItem);
|
||||||
|
this._controllersForElements.delete(element);
|
||||||
},
|
},
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -949,7 +962,7 @@ const DownloadsView = {
|
||||||
while (target.nodeName != "richlistitem") {
|
while (target.nodeName != "richlistitem") {
|
||||||
target = target.parentNode;
|
target = target.parentNode;
|
||||||
}
|
}
|
||||||
new DownloadsViewItemController(target).doCommand(aCommand);
|
DownloadsView.controllerForElement(target).doCommand(aCommand);
|
||||||
},
|
},
|
||||||
|
|
||||||
onDownloadClick: function DV_onDownloadClick(aEvent)
|
onDownloadClick: function DV_onDownloadClick(aEvent)
|
||||||
|
|
@ -1028,8 +1041,8 @@ const DownloadsView = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let controller = new DownloadsViewItemController(element);
|
let localFile = DownloadsView.controllerForElement(element)
|
||||||
let localFile = controller.dataItem.localFile;
|
.dataItem.localFile;
|
||||||
if (!localFile.exists()) {
|
if (!localFile.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1082,8 +1095,6 @@ function DownloadsViewItem(aDataItem, aElement)
|
||||||
let attributes = {
|
let attributes = {
|
||||||
"type": "download",
|
"type": "download",
|
||||||
"class": "download-state",
|
"class": "download-state",
|
||||||
"id": "downloadsItem_" + this.dataItem.downloadGuid,
|
|
||||||
"downloadGuid": this.dataItem.downloadGuid,
|
|
||||||
"state": this.dataItem.state,
|
"state": this.dataItem.state,
|
||||||
"progress": this.dataItem.inProgress ? this.dataItem.percentComplete : 100,
|
"progress": this.dataItem.inProgress ? this.dataItem.percentComplete : 100,
|
||||||
"displayName": target,
|
"displayName": target,
|
||||||
|
|
@ -1360,8 +1371,8 @@ const DownloadsViewController = {
|
||||||
|
|
||||||
// Other commands are selection-specific.
|
// Other commands are selection-specific.
|
||||||
let element = DownloadsView.richListBox.selectedItem;
|
let element = DownloadsView.richListBox.selectedItem;
|
||||||
return element &&
|
return element && DownloadsView.controllerForElement(element)
|
||||||
new DownloadsViewItemController(element).isCommandEnabled(aCommand);
|
.isCommandEnabled(aCommand);
|
||||||
},
|
},
|
||||||
|
|
||||||
doCommand: function DVC_doCommand(aCommand)
|
doCommand: function DVC_doCommand(aCommand)
|
||||||
|
|
@ -1376,7 +1387,7 @@ const DownloadsViewController = {
|
||||||
let element = DownloadsView.richListBox.selectedItem;
|
let element = DownloadsView.richListBox.selectedItem;
|
||||||
if (element) {
|
if (element) {
|
||||||
// The doCommand function also checks if the command is enabled.
|
// The doCommand function also checks if the command is enabled.
|
||||||
new DownloadsViewItemController(element).doCommand(aCommand);
|
DownloadsView.controllerForElement(element).doCommand(aCommand);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -1416,9 +1427,8 @@ XPCOMUtils.defineConstant(this, "DownloadsViewController", DownloadsViewControll
|
||||||
* Handles all the user interaction events, in particular the "commands",
|
* Handles all the user interaction events, in particular the "commands",
|
||||||
* related to a single item in the downloads list widgets.
|
* related to a single item in the downloads list widgets.
|
||||||
*/
|
*/
|
||||||
function DownloadsViewItemController(aElement) {
|
function DownloadsViewItemController(aDataItem) {
|
||||||
let downloadGuid = aElement.getAttribute("downloadGuid");
|
this.dataItem = aDataItem;
|
||||||
this.dataItem = DownloadsCommon.getData(window).dataItems[downloadGuid];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadsViewItemController.prototype = {
|
DownloadsViewItemController.prototype = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue