From a970e88a1753101d2d55139bd7ae44d005c33f44 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 07:23:54 +0200 Subject: [PALEMOON] Bug 1115369 - Use notifications instead of getViewItem for DownloadsView --- .../components/downloads/content/downloads.js | 56 +++++++++------------- 1 file changed, 22 insertions(+), 34 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index 833d7d72f..44457e711 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -570,7 +570,7 @@ const DownloadsPanel = { // still exist, and update the allowed items interactions accordingly. We // do these checks on a background thread, and don't prevent the panel to // be displayed while these checks are being performed. - for each (let viewItem in DownloadsView._viewItems) { + for (let viewItem of DownloadsView._visibleViewItems.values()) { viewItem.verifyTargetExists(); } @@ -711,11 +711,11 @@ const DownloadsView = { _dataItems: [], /** - * Object containing the available DownloadsViewItem objects, indexed by their - * numeric download identifier. There is a limited number of view items in - * the panel at any given time. + * Associates the visible DownloadsDataItem objects with their corresponding + * DownloadsViewItem object. There is a limited number of view items in the + * panel at any given time. */ - _viewItems: {}, + _visibleViewItems: new Map(), /** * Called when the number of items in the list changes. @@ -879,31 +879,21 @@ const DownloadsView = { this._itemCountChanged(); }, - /** - * Returns the view item associated with the provided data item for this view. - * - * @param aDataItem - * DownloadsDataItem object for which the view item is requested. - * - * @return Object that can be used to notify item status events. - */ - getViewItem: function DV_getViewItem(aDataItem) - { - // If the item is visible, just return it, otherwise return a mock object - // that doesn't react to notifications. - if (aDataItem.downloadGuid in this._viewItems) { - return this._viewItems[aDataItem.downloadGuid]; + // DownloadsView + onDataItemStateChanged(aDataItem, aOldState) { + let viewItem = this._visibleViewItems.get(aDataItem); + if (viewItem) { + viewItem.onStateChanged(aOldState); } - return this._invisibleViewItem; }, - /** - * Mock DownloadsDataItem object that doesn't react to notifications. - */ - _invisibleViewItem: Object.freeze({ - onStateChange: function () { }, - onProgressChange: function () { } - }), + // DownloadsView + onDataItemChanged(aDataItem) { + let viewItem = this._visibleViewItems.get(aDataItem); + if (viewItem) { + viewItem.onChanged(); + } + }, /** * Creates a new view item associated with the specified data item, and adds @@ -916,7 +906,7 @@ const DownloadsView = { let element = document.createElement("richlistitem"); let viewItem = new DownloadsViewItem(aDataItem, element); - this._viewItems[aDataItem.downloadGuid] = viewItem; + this._visibleViewItems.set(aDataItem, viewItem); if (aNewest) { this.richListBox.insertBefore(element, this.richListBox.firstChild); } else { @@ -930,14 +920,14 @@ const DownloadsView = { _removeViewItem: function DV_removeViewItem(aDataItem) { DownloadsCommon.log("Removing a DownloadsViewItem from the downloads list."); - let element = this.getViewItem(aDataItem)._element; + let element = this._visibleViewItems.get(aDataItem)._element; let previousSelectedIndex = this.richListBox.selectedIndex; this.richListBox.removeChild(element); if (previousSelectedIndex != -1) { this.richListBox.selectedIndex = Math.min(previousSelectedIndex, this.richListBox.itemCount - 1); } - delete this._viewItems[aDataItem.downloadGuid]; + this._visibleViewItems.delete(aDataItem); }, ////////////////////////////////////////////////////////////////////////////// @@ -1134,7 +1124,7 @@ DownloadsViewItem.prototype = { * the download might be the same as before, if the data layer received * multiple events for the same download. */ - onStateChange: function DVI_onStateChange(aOldState) + onStateChanged(aOldState) { { // If a download just finished successfully, it means that the target file // now exists and we can extract its specific icon. To ensure that the icon @@ -1155,14 +1145,12 @@ DownloadsViewItem.prototype = { // Update the user interface after switching states. this._element.setAttribute("state", this.dataItem.state); - this._updateProgress(); - this._updateStatusLine(); }, /** * Called when the download progress has changed. */ - onProgressChange: function DVI_onProgressChange() { + onChanged() { this._updateProgress(); this._updateStatusLine(); }, -- cgit v1.2.3 From e666c9a8e06c7de97fe0462a9219b19835980384 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 08:40:06 +0200 Subject: [PALEMOON] Bug 1115983 - Keep only minimal state information in the DataItem --- .../components/downloads/content/downloads.js | 76 ++++++++++++---------- 1 file changed, 43 insertions(+), 33 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index 44457e711..fb63f4b17 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -1071,12 +1071,14 @@ function DownloadsViewItem(aDataItem, aElement) // as bug 239948 comment 12 is handled, the "file" property will be always a // file URL rather than a file name. At that point we should remove the "//" // (double slash) from the icon URI specification (see test_moz_icon_uri.js). - this.image = "moz-icon://" + this.dataItem.file + "?size=32"; + this.image = "moz-icon://" + this.dataItem.download.target.path + "?size=32"; let s = DownloadsCommon.strings; let [displayHost, fullHost] = - DownloadUtils.getURIHost(this.dataItem.referrer || this.dataItem.uri); + DownloadUtils.getURIHost(this.dataItem.download.source.referrer || + this.dataItem.download.source.url); + let target = OS.Path.basename(this.dataItem.download.target.path); let attributes = { "type": "download", "class": "download-state", @@ -1084,9 +1086,9 @@ function DownloadsViewItem(aDataItem, aElement) "downloadGuid": this.dataItem.downloadGuid, "state": this.dataItem.state, "progress": this.dataItem.inProgress ? this.dataItem.percentComplete : 100, - "displayName": this.dataItem.target, - "extendedDisplayName": s.statusSeparator(this.dataItem.target, displayHost), - "extendedDisplayNameTip": s.statusSeparator(this.dataItem.target, fullHost), + "displayName": target, + "extendedDisplayName": s.statusSeparator(target, displayHost), + "extendedDisplayNameTip": s.statusSeparator(target, fullHost), "image": this.image }; @@ -1203,7 +1205,7 @@ DownloadsViewItem.prototype = { let statusTip = ""; if (this.dataItem.paused) { - let transfer = DownloadUtils.getTransferTotal(this.dataItem.currBytes, + let transfer = DownloadUtils.getTransferTotal(this.dataItem.download.currentBytes, this.dataItem.maxBytes); // We use the same XUL label to display both the state and the amount @@ -1216,17 +1218,17 @@ DownloadsViewItem.prototype = { // The remaining time per download is likely enough information for the // panel. [status] = - DownloadUtils.getDownloadStatusNoRate(this.dataItem.currBytes, + DownloadUtils.getDownloadStatusNoRate(this.dataItem.download.currentBytes, this.dataItem.maxBytes, - this.dataItem.speed, + this.dataItem.download.speed, this.lastEstimatedSecondsLeft); // We are, however, OK with displaying the rate in the tooltip. let newEstimatedSecondsLeft; [statusTip, newEstimatedSecondsLeft] = - DownloadUtils.getDownloadStatus(this.dataItem.currBytes, + DownloadUtils.getDownloadStatus(this.dataItem.download.currentBytes, this.dataItem.maxBytes, - this.dataItem.speed, + this.dataItem.download.speed, this.lastEstimatedSecondsLeft); this.lastEstimatedSecondsLeft = newEstimatedSecondsLeft; } else if (this.dataItem.starting) { @@ -1248,7 +1250,8 @@ DownloadsViewItem.prototype = { }.apply(this); let [displayHost, fullHost] = - DownloadUtils.getURIHost(this.dataItem.referrer || this.dataItem.uri); + DownloadUtils.getURIHost(this.dataItem.download.source.referrer || + this.dataItem.download.source.url); let end = new Date(this.dataItem.endTime); let [displayDate, fullDate] = DownloadUtils.getReadableDates(end); @@ -1294,18 +1297,17 @@ DownloadsViewItem.prototype = { */ verifyTargetExists: function DVI_verifyTargetExists() { // We don't need to check if the download is not finished successfully. - if (!this.dataItem.openable) { + if (!this.dataItem.download.succeeded) { return; } - OS.File.exists(this.dataItem.localFile.path).then( - function DVI_RTE_onSuccess(aExists) { - if (aExists) { - this._element.setAttribute("exists", "true"); - } else { - this._element.removeAttribute("exists"); - } - }.bind(this), Cu.reportError); + OS.File.exists(this.dataItem.download.target.path).then(aExists => { + if (aExists) { + this._element.setAttribute("exists", "true"); + } else { + this._element.removeAttribute("exists"); + } + }).catch(Cu.reportError); }, }; @@ -1434,18 +1436,20 @@ DownloadsViewItemController.prototype = { { switch (aCommand) { case "downloadsCmd_open": { - return this.dataItem.openable && this.dataItem.localFile.exists(); + return this.dataItem.download.succeeded && + this.dataItem.localFile.exists(); } case "downloadsCmd_show": { return this.dataItem.localFile.exists() || this.dataItem.partFile.exists(); } case "downloadsCmd_pauseResume": - return this.dataItem.inProgress && this.dataItem.resumable; + return this.dataItem.inProgress && + this.dataItem.download.hasPartialData; case "downloadsCmd_retry": return this.dataItem.canRetry; case "downloadsCmd_openReferrer": - return !!this.dataItem.referrer; + return !!this.dataItem.download.source.referrer; case "cmd_delete": case "downloadsCmd_cancel": case "downloadsCmd_copyLocation": @@ -1474,20 +1478,22 @@ DownloadsViewItemController.prototype = { cmd_delete: function DVIC_cmd_delete() { Downloads.getList(Downloads.ALL) - .then(list => list.remove(this.dataItem._download)) - .then(() => this.dataItem._download.finalize(true)) + .then(list => list.remove(this.dataItem.download)) + .then(() => this.dataItem.download.finalize(true)) .catch(Cu.reportError); - PlacesUtils.bhistory.removePage(NetUtil.newURI(this.dataItem.uri)); + PlacesUtils.bhistory.removePage( + NetUtil.newURI(this.dataItem.download.source.url)); }, downloadsCmd_cancel: function DVIC_downloadsCmd_cancel() { - this.dataItem.cancel(); + this.dataItem.download.cancel().catch(() => {}); + this.dataItem.download.removePartialData().catch(Cu.reportError); }, downloadsCmd_open: function DVIC_downloadsCmd_open() { - this.dataItem.openLocalFile(window); + this.dataItem.download.launch().catch(Cu.reportError); // We explicitly close the panel here to give the user the feedback that // their click has been received, and we're handling the action. // Otherwise, we'd have to wait for the file-type handler to execute @@ -1498,7 +1504,7 @@ DownloadsViewItemController.prototype = { downloadsCmd_show: function DVIC_downloadsCmd_show() { - this.dataItem.showLocalFile(); + DownloadsCommon.showDownloadedFile(this.dataItem.localFile); // We explicitly close the panel here to give the user the feedback that // their click has been received, and we're handling the action. @@ -1510,24 +1516,28 @@ DownloadsViewItemController.prototype = { downloadsCmd_pauseResume: function DVIC_downloadsCmd_pauseResume() { - this.dataItem.togglePauseResume(); + if (this.dataItem.download.stopped) { + this.dataItem.download.start(); + } else { + this.dataItem.download.cancel(); + } }, downloadsCmd_retry: function DVIC_downloadsCmd_retry() { - this.dataItem.retry(); + this.dataItem.download.start().catch(() => {}); }, downloadsCmd_openReferrer: function DVIC_downloadsCmd_openReferrer() { - openURL(this.dataItem.referrer); + openURL(this.dataItem.download.source.referrer); }, downloadsCmd_copyLocation: function DVIC_downloadsCmd_copyLocation() { let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"] .getService(Ci.nsIClipboardHelper); - clipboard.copyString(this.dataItem.uri, document); + clipboard.copyString(this.dataItem.download.source.url, document); }, downloadsCmd_doDefault: function DVIC_downloadsCmd_doDefault() -- cgit v1.2.3 From ac3159f02f3b60a8f20a22ff6a66c51d075e11a7 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 09:32:40 +0200 Subject: [PALEMOON] Bug 1116176 - Create DownloadsHistoryDataItem and HistoryDownload objects --- application/palemoon/components/downloads/content/downloads.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index fb63f4b17..af0c85535 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -880,10 +880,10 @@ const DownloadsView = { }, // DownloadsView - onDataItemStateChanged(aDataItem, aOldState) { + onDataItemStateChanged(aDataItem) { let viewItem = this._visibleViewItems.get(aDataItem); if (viewItem) { - viewItem.onStateChanged(aOldState); + viewItem.onStateChanged(); } }, @@ -1126,16 +1126,14 @@ DownloadsViewItem.prototype = { * the download might be the same as before, if the data layer received * multiple events for the same download. */ - onStateChanged(aOldState) { - { + onStateChanged() { // If a download just finished successfully, it means that the target file // now exists and we can extract its specific icon. To ensure that the icon // is reloaded, we must change the URI used by the XUL image element, for // example by adding a query parameter. Since this URI has a "moz-icon" // scheme, this only works if we add one of the parameters explicitly // supported by the nsIMozIconURI interface. - if (aOldState != Ci.nsIDownloadManager.DOWNLOAD_FINISHED && - aOldState != this.dataItem.state) { + if (this.dataItem.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) { this._element.setAttribute("image", this.image + "&state=normal"); // We assume the existence of the target of a download that just completed -- cgit v1.2.3 From 927853bde5ac254ce255a46b15266fbcf6046b09 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 09:59:35 +0200 Subject: [PALEMOON] Bug 1115379 - Streamline DownloadsViewItemController construction and remove now unneeded identifiers --- .../components/downloads/content/downloads.js | 32 ++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index af0c85535..a6c716b8c 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -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 * it to the top or the bottom of the list. @@ -907,6 +917,8 @@ const DownloadsView = { let element = document.createElement("richlistitem"); let viewItem = new DownloadsViewItem(aDataItem, element); this._visibleViewItems.set(aDataItem, viewItem); + let viewItemController = new DownloadsViewItemController(aDataItem); + this._controllersForElements.set(element, viewItemController); if (aNewest) { this.richListBox.insertBefore(element, this.richListBox.firstChild); } else { @@ -928,6 +940,7 @@ const DownloadsView = { this.richListBox.itemCount - 1); } this._visibleViewItems.delete(aDataItem); + this._controllersForElements.delete(element); }, ////////////////////////////////////////////////////////////////////////////// @@ -949,7 +962,7 @@ const DownloadsView = { while (target.nodeName != "richlistitem") { target = target.parentNode; } - new DownloadsViewItemController(target).doCommand(aCommand); + DownloadsView.controllerForElement(target).doCommand(aCommand); }, onDownloadClick: function DV_onDownloadClick(aEvent) @@ -1028,8 +1041,8 @@ const DownloadsView = { return; } - let controller = new DownloadsViewItemController(element); - let localFile = controller.dataItem.localFile; + let localFile = DownloadsView.controllerForElement(element) + .dataItem.localFile; if (!localFile.exists()) { return; } @@ -1082,8 +1095,6 @@ function DownloadsViewItem(aDataItem, aElement) let attributes = { "type": "download", "class": "download-state", - "id": "downloadsItem_" + this.dataItem.downloadGuid, - "downloadGuid": this.dataItem.downloadGuid, "state": this.dataItem.state, "progress": this.dataItem.inProgress ? this.dataItem.percentComplete : 100, "displayName": target, @@ -1360,8 +1371,8 @@ const DownloadsViewController = { // Other commands are selection-specific. let element = DownloadsView.richListBox.selectedItem; - return element && - new DownloadsViewItemController(element).isCommandEnabled(aCommand); + return element && DownloadsView.controllerForElement(element) + .isCommandEnabled(aCommand); }, doCommand: function DVC_doCommand(aCommand) @@ -1376,7 +1387,7 @@ const DownloadsViewController = { let element = DownloadsView.richListBox.selectedItem; if (element) { // 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", * related to a single item in the downloads list widgets. */ -function DownloadsViewItemController(aElement) { - let downloadGuid = aElement.getAttribute("downloadGuid"); - this.dataItem = DownloadsCommon.getData(window).dataItems[downloadGuid]; +function DownloadsViewItemController(aDataItem) { + this.dataItem = aDataItem; } DownloadsViewItemController.prototype = { -- cgit v1.2.3 From f2f7005141bbc366aee8fce0c88592d5c544d30d Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 10:27:51 +0200 Subject: [PALEMOON] Bug 1117139 - Move code controlling the "download.xml" binding to a common place --- .../components/downloads/content/downloads.js | 220 ++------------------- 1 file changed, 16 insertions(+), 204 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index a6c716b8c..edc9fc2ec 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -64,22 +64,6 @@ "use strict"; -//////////////////////////////////////////////////////////////////////////////// -//// Globals - -XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils", - "resource://gre/modules/DownloadUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon", - "resource:///modules/DownloadsCommon.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "OS", - "resource://gre/modules/osfile.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", - "resource://gre/modules/PrivateBrowsingUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", - "resource://gre/modules/PlacesUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "NetUtil", - "resource://gre/modules/NetUtil.jsm"); - //////////////////////////////////////////////////////////////////////////////// //// DownloadsPanel @@ -932,7 +916,7 @@ const DownloadsView = { _removeViewItem: function DV_removeViewItem(aDataItem) { DownloadsCommon.log("Removing a DownloadsViewItem from the downloads list."); - let element = this._visibleViewItems.get(aDataItem)._element; + let element = this._visibleViewItems.get(aDataItem).element; let previousSelectedIndex = this.richListBox.selectedIndex; this.richListBox.removeChild(element); if (previousSelectedIndex != -1) { @@ -1075,45 +1059,21 @@ XPCOMUtils.defineConstant(this, "DownloadsView", DownloadsView); */ function DownloadsViewItem(aDataItem, aElement) { - this._element = aElement; this.dataItem = aDataItem; - this.lastEstimatedSecondsLeft = Infinity; - - // Set the URI that represents the correct icon for the target file. As soon - // as bug 239948 comment 12 is handled, the "file" property will be always a - // file URL rather than a file name. At that point we should remove the "//" - // (double slash) from the icon URI specification (see test_moz_icon_uri.js). - this.image = "moz-icon://" + this.dataItem.download.target.path + "?size=32"; - - let s = DownloadsCommon.strings; - let [displayHost, fullHost] = - DownloadUtils.getURIHost(this.dataItem.download.source.referrer || - this.dataItem.download.source.url); - - let target = OS.Path.basename(this.dataItem.download.target.path); - let attributes = { - "type": "download", - "class": "download-state", - "state": this.dataItem.state, - "progress": this.dataItem.inProgress ? this.dataItem.percentComplete : 100, - "displayName": target, - "extendedDisplayName": s.statusSeparator(target, displayHost), - "extendedDisplayNameTip": s.statusSeparator(target, fullHost), - "image": this.image - }; - - for (let attributeName in attributes) { - this._element.setAttribute(attributeName, attributes[attributeName]); - } + this.element = aElement; + this.element._shell = this; - // Initialize more complex attributes. - this._updateProgress(); - this._updateStatusLine(); + this.element.setAttribute("type", "download"); + this.element.classList.add("download-state"); + + this._updateState(); this.verifyTargetExists(); } DownloadsViewItem.prototype = { + __proto__: DownloadElementShell.prototype, + /** * The DownloadDataItem associated with this view item. */ @@ -1124,19 +1084,6 @@ DownloadsViewItem.prototype = { */ _element: null, - /** - * The inner XUL element for the progress bar, or null if not available. - */ - _progressElement: null, - - ////////////////////////////////////////////////////////////////////////////// - //// Callback functions from DownloadsData - - /** - * Called when the download state might have changed. Sometimes the state of - * the download might be the same as before, if the data layer received - * multiple events for the same download. - */ onStateChanged() { // If a download just finished successfully, it means that the target file // now exists and we can extract its specific icon. To ensure that the icon @@ -1145,158 +1092,23 @@ DownloadsViewItem.prototype = { // scheme, this only works if we add one of the parameters explicitly // supported by the nsIMozIconURI interface. if (this.dataItem.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) { - this._element.setAttribute("image", this.image + "&state=normal"); + this.element.setAttribute("image", this.image + "&state=normal"); // We assume the existence of the target of a download that just completed // successfully, without checking the condition in the background. If the // panel is already open, this will take effect immediately. If the panel // is opened later, a new background existence check will be performed. - this._element.setAttribute("exists", "true"); + this.element.setAttribute("exists", "true"); } // Update the user interface after switching states. - this._element.setAttribute("state", this.dataItem.state); + this.element.setAttribute("state", this.dataItem.state); }, - /** - * Called when the download progress has changed. - */ onChanged() { this._updateProgress(); - this._updateStatusLine(); }, - ////////////////////////////////////////////////////////////////////////////// - //// Functions for updating the user interface - - /** - * Updates the progress bar. - */ - _updateProgress: function DVI_updateProgress() { - if (this.dataItem.starting) { - // Before the download starts, the progress meter has its initial value. - this._element.setAttribute("progressmode", "normal"); - this._element.setAttribute("progress", "0"); - } else if (this.dataItem.state == Ci.nsIDownloadManager.DOWNLOAD_SCANNING || - this.dataItem.percentComplete == -1) { - // We might not know the progress of a running download, and we don't know - // the remaining time during the malware scanning phase. - this._element.setAttribute("progressmode", "undetermined"); - } else { - // This is a running download of which we know the progress. - this._element.setAttribute("progressmode", "normal"); - this._element.setAttribute("progress", this.dataItem.percentComplete); - } - - // Find the progress element as soon as the download binding is accessible. - if (!this._progressElement) { - this._progressElement = - document.getAnonymousElementByAttribute(this._element, "anonid", - "progressmeter"); - } - - // Dispatch the ValueChange event for accessibility, if possible. - if (this._progressElement) { - let event = document.createEvent("Events"); - event.initEvent("ValueChange", true, true); - this._progressElement.dispatchEvent(event); - } - }, - - /** - * Updates the main status line, including bytes transferred, bytes total, - * download rate, and time remaining. - */ - _updateStatusLine: function DVI_updateStatusLine() { - const nsIDM = Ci.nsIDownloadManager; - - let status = ""; - let statusTip = ""; - - if (this.dataItem.paused) { - let transfer = DownloadUtils.getTransferTotal(this.dataItem.download.currentBytes, - this.dataItem.maxBytes); - - // We use the same XUL label to display both the state and the amount - // transferred, for example "Paused - 1.1 MB". - status = DownloadsCommon.strings.statusSeparatorBeforeNumber( - DownloadsCommon.strings.statePaused, - transfer); - } else if (this.dataItem.state == nsIDM.DOWNLOAD_DOWNLOADING) { - // We don't show the rate for each download in order to reduce clutter. - // The remaining time per download is likely enough information for the - // panel. - [status] = - DownloadUtils.getDownloadStatusNoRate(this.dataItem.download.currentBytes, - this.dataItem.maxBytes, - this.dataItem.download.speed, - this.lastEstimatedSecondsLeft); - - // We are, however, OK with displaying the rate in the tooltip. - let newEstimatedSecondsLeft; - [statusTip, newEstimatedSecondsLeft] = - DownloadUtils.getDownloadStatus(this.dataItem.download.currentBytes, - this.dataItem.maxBytes, - this.dataItem.download.speed, - this.lastEstimatedSecondsLeft); - this.lastEstimatedSecondsLeft = newEstimatedSecondsLeft; - } else if (this.dataItem.starting) { - status = DownloadsCommon.strings.stateStarting; - } else if (this.dataItem.state == nsIDM.DOWNLOAD_SCANNING) { - status = DownloadsCommon.strings.stateScanning; - } else if (!this.dataItem.inProgress) { - let stateLabel = function () { - let s = DownloadsCommon.strings; - switch (this.dataItem.state) { - case nsIDM.DOWNLOAD_FAILED: return s.stateFailed; - case nsIDM.DOWNLOAD_CANCELED: return s.stateCanceled; - case nsIDM.DOWNLOAD_BLOCKED_PARENTAL: return s.stateBlockedParentalControls; - case nsIDM.DOWNLOAD_BLOCKED_POLICY: return s.stateBlockedPolicy; - case nsIDM.DOWNLOAD_DIRTY: return s.stateDirty; - case nsIDM.DOWNLOAD_FINISHED: return this._fileSizeText; - } - return null; - }.apply(this); - - let [displayHost, fullHost] = - DownloadUtils.getURIHost(this.dataItem.download.source.referrer || - this.dataItem.download.source.url); - - let end = new Date(this.dataItem.endTime); - let [displayDate, fullDate] = DownloadUtils.getReadableDates(end); - - // We use the same XUL label to display the state, the host name, and the - // end time, for example "Canceled - 222.net - 11:15" or "1.1 MB - - // website2.com - Yesterday". We show the full host and the complete date - // in the tooltip. - let firstPart = DownloadsCommon.strings.statusSeparator(stateLabel, - displayHost); - status = DownloadsCommon.strings.statusSeparator(firstPart, displayDate); - statusTip = DownloadsCommon.strings.statusSeparator(fullHost, fullDate); - } - - this._element.setAttribute("status", status); - this._element.setAttribute("statusTip", statusTip || status); - }, - - /** - * Localized string representing the total size of completed downloads, for - * example "1.5 MB" or "Unknown size". - */ - get _fileSizeText() - { - // Display the file size, but show "Unknown" for negative sizes. - let fileSize = this.dataItem.maxBytes; - if (fileSize < 0) { - return DownloadsCommon.strings.sizeUnknown; - } - let [size, unit] = DownloadUtils.convertByteUnits(fileSize); - return DownloadsCommon.strings.sizeWithUnits(size, unit); - }, - - ////////////////////////////////////////////////////////////////////////////// - //// Functions called by the panel - /** * Starts checking whether the target file of a finished download is still * available on disk, and sets an attribute that controls how the item is @@ -1306,15 +1118,15 @@ DownloadsViewItem.prototype = { */ verifyTargetExists: function DVI_verifyTargetExists() { // We don't need to check if the download is not finished successfully. - if (!this.dataItem.download.succeeded) { + if (!this.download.succeeded) { return; } - OS.File.exists(this.dataItem.download.target.path).then(aExists => { + OS.File.exists(this.download.target.path).then(aExists => { if (aExists) { - this._element.setAttribute("exists", "true"); + this.element.setAttribute("exists", "true"); } else { - this._element.removeAttribute("exists"); + this.element.removeAttribute("exists"); } }).catch(Cu.reportError); }, -- cgit v1.2.3 From 462332eee018e24d88255c708fa8acb67a717673 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 11:13:36 +0200 Subject: [PALEMOON] Bug 1117141 - Part 1 of 2 - Bypass all the DownloadsDataItem properties --- .../components/downloads/content/downloads.js | 82 ++++++++++++---------- 1 file changed, 46 insertions(+), 36 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index edc9fc2ec..05233e76d 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -1025,9 +1025,10 @@ const DownloadsView = { return; } - let localFile = DownloadsView.controllerForElement(element) - .dataItem.localFile; - if (!localFile.exists()) { + // We must check for existence synchronously because this is a DOM event. + let file = new FileUtils.File(DownloadsView.controllerForElement(element) + .download.target.path); + if (!file.exists()) { return; } @@ -1085,24 +1086,17 @@ DownloadsViewItem.prototype = { _element: null, onStateChanged() { - // If a download just finished successfully, it means that the target file - // now exists and we can extract its specific icon. To ensure that the icon - // is reloaded, we must change the URI used by the XUL image element, for - // example by adding a query parameter. Since this URI has a "moz-icon" - // scheme, this only works if we add one of the parameters explicitly - // supported by the nsIMozIconURI interface. - if (this.dataItem.state == Ci.nsIDownloadManager.DOWNLOAD_FINISHED) { - this.element.setAttribute("image", this.image + "&state=normal"); + this.element.setAttribute("image", this.image); + this.element.setAttribute("state", + DownloadsCommon.stateOfDownload(this.download)); + if (this.download.succeeded) { // We assume the existence of the target of a download that just completed // successfully, without checking the condition in the background. If the // panel is already open, this will take effect immediately. If the panel // is opened later, a new background existence check will be performed. this.element.setAttribute("exists", "true"); } - - // Update the user interface after switching states. - this.element.setAttribute("state", this.dataItem.state); }, onChanged() { @@ -1252,24 +1246,38 @@ DownloadsViewItemController.prototype = { */ dataItem: null, + get download() this.dataItem.download, + isCommandEnabled: function DVIC_isCommandEnabled(aCommand) { switch (aCommand) { case "downloadsCmd_open": { - return this.dataItem.download.succeeded && - this.dataItem.localFile.exists(); + if (!this.download.succeeded) { + return false; + } + + let file = new FileUtils.File(this.download.target.path); + return file.exists(); } case "downloadsCmd_show": { - return this.dataItem.localFile.exists() || - this.dataItem.partFile.exists(); + let file = new FileUtils.File(this.download.target.path); + if (file.exists()) { + return true; + } + + if (!this.download.target.partFilePath) { + return false; + } + + let partFile = new FileUtils.File(this.download.target.partFilePath); + return partFile.exists(); } case "downloadsCmd_pauseResume": - return this.dataItem.inProgress && - this.dataItem.download.hasPartialData; + return this.download.hasPartialData && !this.download.error; case "downloadsCmd_retry": - return this.dataItem.canRetry; + return this.download.canceled || this.download.error; case "downloadsCmd_openReferrer": - return !!this.dataItem.download.source.referrer; + return !!this.download.source.referrer; case "cmd_delete": case "downloadsCmd_cancel": case "downloadsCmd_copyLocation": @@ -1298,22 +1306,23 @@ DownloadsViewItemController.prototype = { cmd_delete: function DVIC_cmd_delete() { Downloads.getList(Downloads.ALL) - .then(list => list.remove(this.dataItem.download)) - .then(() => this.dataItem.download.finalize(true)) + .then(list => list.remove(this.download)) + .then(() => this.download.finalize(true)) .catch(Cu.reportError); PlacesUtils.bhistory.removePage( - NetUtil.newURI(this.dataItem.download.source.url)); + NetUtil.newURI(this.download.source.url)); }, downloadsCmd_cancel: function DVIC_downloadsCmd_cancel() { - this.dataItem.download.cancel().catch(() => {}); - this.dataItem.download.removePartialData().catch(Cu.reportError); + this.download.cancel().catch(() => {}); + this.download.removePartialData().catch(Cu.reportError); }, downloadsCmd_open: function DVIC_downloadsCmd_open() { - this.dataItem.download.launch().catch(Cu.reportError); + this.download.launch().catch(Cu.reportError); + // We explicitly close the panel here to give the user the feedback that // their click has been received, and we're handling the action. // Otherwise, we'd have to wait for the file-type handler to execute @@ -1324,7 +1333,8 @@ DownloadsViewItemController.prototype = { downloadsCmd_show: function DVIC_downloadsCmd_show() { - DownloadsCommon.showDownloadedFile(this.dataItem.localFile); + let file = new FileUtils.File(this.download.target.path); + DownloadsCommon.showDownloadedFile(file); // We explicitly close the panel here to give the user the feedback that // their click has been received, and we're handling the action. @@ -1336,28 +1346,28 @@ DownloadsViewItemController.prototype = { downloadsCmd_pauseResume: function DVIC_downloadsCmd_pauseResume() { - if (this.dataItem.download.stopped) { - this.dataItem.download.start(); + if (this.download.stopped) { + this.download.start(); } else { - this.dataItem.download.cancel(); + this.download.cancel(); } }, downloadsCmd_retry: function DVIC_downloadsCmd_retry() { - this.dataItem.download.start().catch(() => {}); + this.download.start().catch(() => {}); }, downloadsCmd_openReferrer: function DVIC_downloadsCmd_openReferrer() { - openURL(this.dataItem.download.source.referrer); + openURL(this.download.source.referrer); }, downloadsCmd_copyLocation: function DVIC_downloadsCmd_copyLocation() { let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"] .getService(Ci.nsIClipboardHelper); - clipboard.copyString(this.dataItem.download.source.url, document); + clipboard.copyString(this.download.source.url, document); }, downloadsCmd_doDefault: function DVIC_downloadsCmd_doDefault() @@ -1366,7 +1376,7 @@ DownloadsViewItemController.prototype = { // Determine the default command for the current item. let defaultCommand = function () { - switch (this.dataItem.state) { + switch (DownloadsCommon.stateOfDownload(this.download)) { case nsIDM.DOWNLOAD_NOTSTARTED: return "downloadsCmd_cancel"; case nsIDM.DOWNLOAD_FINISHED: return "downloadsCmd_open"; case nsIDM.DOWNLOAD_FAILED: return "downloadsCmd_retry"; -- cgit v1.2.3 From d6c976bf65e309d298c250d7466b2cb0e523d088 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 11:41:22 +0200 Subject: [PALEMOON] Bug 1117141 - Part 2 of 2 - Refactor notifications and remove the DownloadsDataItem object --- .../components/downloads/content/downloads.js | 121 +++++++++------------ 1 file changed, 51 insertions(+), 70 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index 05233e76d..9a6aa97e9 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -687,15 +687,15 @@ const DownloadsView = { loading: false, /** - * Ordered array of all DownloadsDataItem objects. We need to keep this array - * because only a limited number of items are shown at once, and if an item - * that is currently visible is removed from the list, we might need to take - * another item from the array and make it appear at the bottom. + * Ordered array of all Download objects. We need to keep this array because + * only a limited number of items are shown at once, and if an item that is + * currently visible is removed from the list, we might need to take another + * item from the array and make it appear at the bottom. */ - _dataItems: [], + _downloads: [], /** - * Associates the visible DownloadsDataItem objects with their corresponding + * Associates the visible Download objects with their corresponding * DownloadsViewItem object. There is a limited number of view items in the * panel at any given time. */ @@ -707,8 +707,8 @@ const DownloadsView = { _itemCountChanged: function DV_itemCountChanged() { DownloadsCommon.log("The downloads item count has changed - we are tracking", - this._dataItems.length, "downloads in total."); - let count = this._dataItems.length; + this._downloads.length, "downloads in total."); + let count = this._downloads.length; let hiddenCount = count - this.kItemCountLimit; if (count > 0) { @@ -797,8 +797,8 @@ const DownloadsView = { * Called when a new download data item is available, either during the * asynchronous data load or when a new download is started. * - * @param aDataItem - * DownloadsDataItem object that was just added. + * @param aDownload + * Download object that was just added. * @param aNewest * When true, indicates that this item is the most recent and should be * added in the topmost position. This happens when a new download is @@ -806,28 +806,28 @@ const DownloadsView = { * and should be appended. The latter generally happens during the * asynchronous data load. */ - onDataItemAdded: function DV_onDataItemAdded(aDataItem, aNewest) + onDownloadAdded(download, aNewest) { { DownloadsCommon.log("A new download data item was added - aNewest =", aNewest); if (aNewest) { - this._dataItems.unshift(aDataItem); + this._downloads.unshift(download); } else { - this._dataItems.push(aDataItem); + this._downloads.push(download); } - let itemsNowOverflow = this._dataItems.length > this.kItemCountLimit; + let itemsNowOverflow = this._downloads.length > this.kItemCountLimit; if (aNewest || !itemsNowOverflow) { // The newly added item is visible in the panel and we must add the // corresponding element. This is either because it is the first item, or // because it was added at the bottom but the list still doesn't overflow. - this._addViewItem(aDataItem, aNewest); + this._addViewItem(download, aNewest); } if (aNewest && itemsNowOverflow) { // If the list overflows, remove the last item from the panel to make room // for the new one that we just added at the top. - this._removeViewItem(this._dataItems[this.kItemCountLimit]); + this._removeViewItem(this._downloads[this.kItemCountLimit]); } // For better performance during batch loads, don't update the count for @@ -837,48 +837,45 @@ const DownloadsView = { } }, + onDownloadStateChanged(download) { + let viewItem = this._visibleViewItems.get(download); + if (viewItem) { + viewItem.onStateChanged(); + } + }, + + onDownloadChanged(download) { + let viewItem = this._visibleViewItems.get(download); + if (viewItem) { + viewItem.onChanged(); + } + }, + /** * Called when a data item is removed. Ensures that the widget associated * with the view item is removed from the user interface. * - * @param aDataItem - * DownloadsDataItem object that is being removed. + * @param download + * Download object that is being removed. */ - onDataItemRemoved: function DV_onDataItemRemoved(aDataItem) - { + onDownloadRemoved(download) { DownloadsCommon.log("A download data item was removed."); - let itemIndex = this._dataItems.indexOf(aDataItem); - this._dataItems.splice(itemIndex, 1); + let itemIndex = this._downloads.indexOf(download); + this._downloads.splice(itemIndex, 1); if (itemIndex < this.kItemCountLimit) { // The item to remove is visible in the panel. - this._removeViewItem(aDataItem); - if (this._dataItems.length >= this.kItemCountLimit) { + this._removeViewItem(download); + if (this._downloads.length >= this.kItemCountLimit) { // Reinsert the next item into the panel. - this._addViewItem(this._dataItems[this.kItemCountLimit - 1], false); + this._addViewItem(this._downloads[this.kItemCountLimit - 1], false); } } this._itemCountChanged(); }, - // DownloadsView - onDataItemStateChanged(aDataItem) { - let viewItem = this._visibleViewItems.get(aDataItem); - if (viewItem) { - viewItem.onStateChanged(); - } - }, - - // DownloadsView - onDataItemChanged(aDataItem) { - let viewItem = this._visibleViewItems.get(aDataItem); - if (viewItem) { - viewItem.onChanged(); - } - }, - /** * Associates each richlistitem for a download with its corresponding * DownloadsViewItemController object. @@ -893,15 +890,15 @@ const DownloadsView = { * Creates a new view item associated with the specified data item, and adds * it to the top or the bottom of the list. */ - _addViewItem: function DV_addViewItem(aDataItem, aNewest) + _addViewItem(download, aNewest) { DownloadsCommon.log("Adding a new DownloadsViewItem to the downloads list.", "aNewest =", aNewest); let element = document.createElement("richlistitem"); - let viewItem = new DownloadsViewItem(aDataItem, element); - this._visibleViewItems.set(aDataItem, viewItem); - let viewItemController = new DownloadsViewItemController(aDataItem); + let viewItem = new DownloadsViewItem(download, element); + this._visibleViewItems.set(download, viewItem); + let viewItemController = new DownloadsViewItemController(download); this._controllersForElements.set(element, viewItemController); if (aNewest) { this.richListBox.insertBefore(element, this.richListBox.firstChild); @@ -913,17 +910,17 @@ const DownloadsView = { /** * Removes the view item associated with the specified data item. */ - _removeViewItem: function DV_removeViewItem(aDataItem) + _removeViewItem(download) { { DownloadsCommon.log("Removing a DownloadsViewItem from the downloads list."); - let element = this._visibleViewItems.get(aDataItem).element; + let element = this._visibleViewItems.get(download).element; let previousSelectedIndex = this.richListBox.selectedIndex; this.richListBox.removeChild(element); if (previousSelectedIndex != -1) { this.richListBox.selectedIndex = Math.min(previousSelectedIndex, this.richListBox.itemCount - 1); } - this._visibleViewItems.delete(aDataItem); + this._visibleViewItems.delete(download); this._controllersForElements.delete(element); }, @@ -1053,14 +1050,13 @@ XPCOMUtils.defineConstant(this, "DownloadsView", DownloadsView); * Builds and updates a single item in the downloads list widget, responding to * changes in the download state and real-time data. * - * @param aDataItem - * DownloadsDataItem to be associated with the view item. + * @param download + * Download object to be associated with the view item. * @param aElement * XUL element corresponding to the single download item in the view. */ -function DownloadsViewItem(aDataItem, aElement) -{ - this.dataItem = aDataItem; +function DownloadsViewItem(download, aElement) { + this.download = download; this.element = aElement; this.element._shell = this; @@ -1075,11 +1071,6 @@ function DownloadsViewItem(aDataItem, aElement) DownloadsViewItem.prototype = { __proto__: DownloadElementShell.prototype, - /** - * The DownloadDataItem associated with this view item. - */ - dataItem: null, - /** * The XUL element corresponding to the associated richlistbox item. */ @@ -1233,21 +1224,11 @@ XPCOMUtils.defineConstant(this, "DownloadsViewController", DownloadsViewControll * Handles all the user interaction events, in particular the "commands", * related to a single item in the downloads list widgets. */ -function DownloadsViewItemController(aDataItem) { - this.dataItem = aDataItem; +function DownloadsViewItemController(download) { + this.download = download; } DownloadsViewItemController.prototype = { - ////////////////////////////////////////////////////////////////////////////// - //// Command dispatching - - /** - * The DownloadDataItem controlled by this object. - */ - dataItem: null, - - get download() this.dataItem.download, - isCommandEnabled: function DVIC_isCommandEnabled(aCommand) { switch (aCommand) { -- cgit v1.2.3 From 761b6eb255109a07d7cbcaaef6891cb14c961dbc Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 12:29:40 +0200 Subject: Fix typos --- application/palemoon/components/downloads/content/downloads.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index 9a6aa97e9..01682d325 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -807,7 +807,6 @@ const DownloadsView = { * asynchronous data load. */ onDownloadAdded(download, aNewest) { - { DownloadsCommon.log("A new download data item was added - aNewest =", aNewest); @@ -911,7 +910,6 @@ const DownloadsView = { * Removes the view item associated with the specified data item. */ _removeViewItem(download) { - { DownloadsCommon.log("Removing a DownloadsViewItem from the downloads list."); let element = this._visibleViewItems.get(download).element; let previousSelectedIndex = this.richListBox.selectedIndex; -- cgit v1.2.3 From beeede618586155d0f3fcb8e9313e076eef3e6e5 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 12:41:33 +0200 Subject: [PALEMOON] Bug 1127867 - Use the new back-end property to get the size of downloads asynchronously --- .../components/downloads/content/downloads.js | 33 +--------------------- 1 file changed, 1 insertion(+), 32 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index 01682d325..199324b6b 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -555,7 +555,7 @@ const DownloadsPanel = { // do these checks on a background thread, and don't prevent the panel to // be displayed while these checks are being performed. for (let viewItem of DownloadsView._visibleViewItems.values()) { - viewItem.verifyTargetExists(); + viewItem.download.refresh().catch(Cu.reportError); } if (aAnchor) { @@ -1063,7 +1063,6 @@ function DownloadsViewItem(download, aElement) { this.element.classList.add("download-state"); this._updateState(); - this.verifyTargetExists(); } DownloadsViewItem.prototype = { @@ -1078,41 +1077,11 @@ DownloadsViewItem.prototype = { this.element.setAttribute("image", this.image); this.element.setAttribute("state", DownloadsCommon.stateOfDownload(this.download)); - - if (this.download.succeeded) { - // We assume the existence of the target of a download that just completed - // successfully, without checking the condition in the background. If the - // panel is already open, this will take effect immediately. If the panel - // is opened later, a new background existence check will be performed. - this.element.setAttribute("exists", "true"); - } }, onChanged() { this._updateProgress(); }, - - /** - * Starts checking whether the target file of a finished download is still - * available on disk, and sets an attribute that controls how the item is - * presented visually. - * - * The existence check is executed on a background thread. - */ - verifyTargetExists: function DVI_verifyTargetExists() { - // We don't need to check if the download is not finished successfully. - if (!this.download.succeeded) { - return; - } - - OS.File.exists(this.download.target.path).then(aExists => { - if (aExists) { - this.element.setAttribute("exists", "true"); - } else { - this.element.removeAttribute("exists"); - } - }).catch(Cu.reportError); - }, }; //////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 551c6ff0463b555d32c51d22163318b7204c5388 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 13:12:21 +0200 Subject: [PALEMOON] Bug 1129896 - Part 2 of 2 - Convert the shared front-end code to a JavaScript code module --- .../components/downloads/content/downloads.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index 199324b6b..b36b9d0fe 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -4,6 +4,21 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; + +XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon", + "resource:///modules/DownloadsCommon.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "DownloadsViewUI", + "resource:///modules/DownloadsViewUI.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", + "resource://gre/modules/FileUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "NetUtil", + "resource://gre/modules/NetUtil.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", + "resource://gre/modules/PlacesUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "Services", + "resource://gre/modules/Services.jsm"); + /** * Handles the Downloads panel user interface for each browser window. * @@ -1066,7 +1081,7 @@ function DownloadsViewItem(download, aElement) { } DownloadsViewItem.prototype = { - __proto__: DownloadElementShell.prototype, + __proto__: DownloadsViewUI.DownloadElementShell.prototype, /** * The XUL element corresponding to the associated richlistbox item. @@ -1253,10 +1268,7 @@ DownloadsViewItemController.prototype = { commands: { cmd_delete: function DVIC_cmd_delete() { - Downloads.getList(Downloads.ALL) - .then(list => list.remove(this.download)) - .then(() => this.download.finalize(true)) - .catch(Cu.reportError); + DownloadsCommon.removeAndFinalizeDownload(this.download); PlacesUtils.bhistory.removePage( NetUtil.newURI(this.download.source.url)); }, -- cgit v1.2.3 From 909c3ee13f633b0fd8c4b1b7501d3896ae630f6d Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 29 Jul 2018 13:20:49 +0200 Subject: [PALEMOON] Bug 1135348 - Fix about:downloads by adding missing XPCOMUtils imports --- application/palemoon/components/downloads/content/downloads.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index b36b9d0fe..ee728406c 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -6,6 +6,8 @@ var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon", "resource:///modules/DownloadsCommon.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "DownloadsViewUI", -- cgit v1.2.3 From 322d0be583c1dbc9d1dc1fe4212aed9c82bbbf7a Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Fri, 25 Jan 2019 12:13:24 +0100 Subject: Fix incorrect file reference in `onDownloadDragStart` Follow-up to Janek's port in 462332eee018e24d88255c708fa8acb67a717673 where this variable was changed creating a mismatch with surrounding code. This fixes #943. --- application/palemoon/components/downloads/content/downloads.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'application/palemoon/components/downloads/content/downloads.js') diff --git a/application/palemoon/components/downloads/content/downloads.js b/application/palemoon/components/downloads/content/downloads.js index ee728406c..ee1c6902e 100644 --- a/application/palemoon/components/downloads/content/downloads.js +++ b/application/palemoon/components/downloads/content/downloads.js @@ -1038,9 +1038,9 @@ const DownloadsView = { } // We must check for existence synchronously because this is a DOM event. - let file = new FileUtils.File(DownloadsView.controllerForElement(element) - .download.target.path); - if (!file.exists()) { + let localFile = new FileUtils.File(DownloadsView.controllerForElement(element) + .download.target.path); + if (!localFile.exists()) { return; } -- cgit v1.2.3