author | Chris Peterson <cpeterson@mozilla.com> |
Mon, 05 Jan 2015 23:43:45 -0800 | |
changeset 224377 | d40cc2407fa398205e225bebc705404295d1f027 |
parent 224376 | ccbb7771093dd2d2507f082ccfe244e7a628de27 |
child 224378 | 2c04677df85eed3ff0ba21f3591d52631ab7e332 |
push id | 54198 |
push user | cpeterson@mozilla.com |
push date | Sat, 17 Jan 2015 04:43:33 +0000 |
treeherder | mozilla-inbound@d40cc2407fa3 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mak |
bugs | 1116769 |
milestone | 38.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
|
--- a/webapprt/content/downloads/downloads.js +++ b/webapprt/content/downloads/downloads.js @@ -573,17 +573,17 @@ DownloadItem.prototype = { clipboard.copyString(this.uri, document); break; } }, }; let gDownloadList = { downloadItemsMap: new Map(), - downloadItems: {}, + idToDownloadItemMap: new Map(), _autoIncrementID: 0, downloadView: null, searchBox: null, searchTerms: [], searchAttributes: [ "target", "status", "dateTime", ], contextMenus: [ // DOWNLOAD_DOWNLOADING [ @@ -722,17 +722,17 @@ let gDownloadList = { return; } // Clear the list before adding items by replacing with a shallow copy. let empty = this.downloadView.cloneNode(false); this.downloadView.parentNode.replaceChild(empty, this.downloadView); this.downloadView = empty; - for each (let downloadItem in this.downloadItems) { + for (let downloadItem of this.idToDownloadItemMap.values()) { if (downloadItem.inProgress || downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) { this.downloadView.appendChild(downloadItem.element); // Because of the joys of XBL, we can't update the buttons until the // download object is in the document. downloadItem.updateView(); } @@ -768,17 +768,17 @@ let gDownloadList = { /** * Update the disabled state of the clear list button based on whether or not * there are items in the list that can potentially be removed. */ updateClearListButton: function() { let button = document.getElementById("clearListButton"); // The button is enabled if we have items in the list that we can clean up. - for each (let downloadItem in this.downloadItems) { + for (let downloadItem of this.idToDownloadItemMap.values()) { if (!downloadItem.inProgress && downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) { button.disabled = false; return; } } button.disabled = true; @@ -803,18 +803,17 @@ let gDownloadList = { } let popup = document.getElementById("downloadContextMenu"); while (popup.hasChildNodes()) { popup.removeChild(popup.firstChild); } if (this.downloadView.selectedItem) { - let dl = this.downloadView.selectedItem; - let downloadItem = this.downloadItems[dl.getAttribute("id")]; + let downloadItem = this._getSelectedDownloadItem(); let idx = downloadItem.state; if (idx < 0) { idx = 0; } let menus = this.contextMenus[idx]; for (let i = 0; i < menus.length; ++i) { @@ -833,23 +832,21 @@ let gDownloadList = { return false; }, /** * Perform the default action for the currently selected download item. */ doDefaultForSelected: function() { // Make sure we have something selected. - let item = this.downloadView.selectedItem; - if (!item) { + let download = this._getSelectedDownloadItem(); + if (!download) { return; } - let download = this.downloadItems[item.getAttribute("id")]; - // Get the default action (first item in the menu). let menuitem = document.getElementById(this.contextMenus[download.state][0]); // Try to do the action if the command is enabled. download.doCommand(menuitem.getAttribute("cmd")); }, onDownloadDblClick: function(aEvent) { @@ -886,27 +883,27 @@ let gDownloadList = { let elm = aItem; while (elm.nodeName != "richlistitem" || elm.getAttribute("type") != "download") { elm = elm.parentNode; } - let downloadItem = this.downloadItems[elm.getAttribute("id")]; + let downloadItem = this._getDownloadItemForElement(elm); downloadItem.doCommand(aCmd); }, onDragStart: function(aEvent) { - if (!this.downloadView.selectedItem) { + let downloadItem = this._getSelectedDownloadItem(); + if (!downloadItem) { return; } let dl = this.downloadView.selectedItem; - let downloadItem = this.downloadItems[dl.getAttribute("id")]; let f = downloadItem.localFile; if (!f.exists()) { return; } let dt = aEvent.dataTransfer; dt.mozSetDataAt("application/x-moz-file", f, 0); let url = Services.io.newFileURI(f).spec; @@ -978,17 +975,17 @@ let gDownloadList = { this.downloadView.selectAll(); }, onUpdateProgress: function() { let numActive = 0; let totalSize = 0; let totalTransferred = 0; - for each (let downloadItem in this.downloadItems) { + for (let downloadItem of this.idToDownloadItemMap.values()) { if (!downloadItem.inProgress) { continue; } numActive++; // Only add to total values if we actually know the download size. if (downloadItem.maxBytes > 0 && @@ -1025,17 +1022,17 @@ let gDownloadList = { document.title = title; }, onDownloadAdded: function(aDownload) { let newID = this._autoIncrementID++; let downloadItem = new DownloadItem(newID, aDownload); this.downloadItemsMap.set(aDownload, downloadItem); - this.downloadItems[newID] = downloadItem; + this.idToDownloadItemMap.set(newID, downloadItem); if (downloadItem.inProgress || downloadItem.matchesSearch(this.searchTerms, this.searchAttributes)) { this.downloadView.appendChild(downloadItem.element); // Because of the joys of XBL, we can't update the buttons until the // download object is in the document. downloadItem.updateView(); @@ -1083,17 +1080,17 @@ let gDownloadList = { onDownloadRemoved: function(aDownload) { let downloadItem = this.downloadItemsMap.get(aDownload); if (!downloadItem) { Cu.reportError("Download doesn't exist."); return; } this.downloadItemsMap.delete(aDownload); - delete this.downloadItems[downloadItem.id]; + this.idToDownloadItemMap.delete(downloadItem.id); this.removeFromView(downloadItem); }, removeFromView: function(aDownloadItem) { // Make sure we have an item to remove. if (!aDownloadItem.element) { return; @@ -1101,16 +1098,23 @@ let gDownloadList = { let index = this.downloadView.selectedIndex; this.downloadView.removeChild(aDownloadItem.element); this.downloadView.selectedIndex = Math.min(index, this.downloadView.itemCount - 1); // We might have removed the last item, so update the clear list button. this.updateClearListButton(); }, + _getDownloadItemForElement(element) { + return this.idToDownloadItemMap.get(element.getAttribute("id")); + }, + _getSelectedDownloadItem() { + let dl = this.downloadView.selectedItem; + return dl ? this._getDownloadItemForElement(dl) : null; + }, }; function Startup() { // Convert strings to those in the string bundle. let sb = document.getElementById("downloadStrings"); let strings = ["paused", "cannotPause", "doneStatus", "doneSize", "doneSizeUnknown", "stateFailed", "stateCanceled", "stateBlocked", "stateBlockedPolicy", "stateDirty",