[PALEMOON] Bug 1117141 - Part 1 of 2 - Bypass all the DownloadsDataItem properties

This commit is contained in:
janekptacijarabaci 2018-07-29 11:13:36 +02:00 • committed by Roy Tam
commit 5705b9b36a
4 changed files with 321 additions and 306 deletions

View file

@ -72,12 +72,19 @@ DownloadElementShell.prototype = {
* URI string for the file type icon displayed in the download element.
*/
get image() {
if (this.download.target.path) {
return "moz-icon://" + this.download.target.path + "?size=32";
if (!this.download.target.path) {
// Old history downloads may not have a target path.
return "moz-icon://.unknown?size=32";
}
// Old history downloads may not have a target path.
return "moz-icon://.unknown?size=32";
// When a download that was previously in progress finishes successfully, it
// means that the target file now exists and we can extract its specific
// icon, for example from a Windows executable. To ensure that the icon is
// reloaded, however, we must change the URI used by the XUL image element,
// for example by adding a query parameter. This only works if we add one of
// the parameters explicitly supported by the nsIMozIconURI interface.
return "moz-icon://" + this.download.target.path + "?size=32" +
(this.download.succeeded ? "&state=normal" : "");
},
/**
@ -127,11 +134,12 @@ DownloadElementShell.prototype = {
* update in order to improve performance.
*/
_updateState() {
this.element.setAttribute("state", this.dataItem.state);
this.element.setAttribute("displayName", this.displayName);
this.element.setAttribute("extendedDisplayName", this.extendedDisplayName);
this.element.setAttribute("extendedDisplayNameTip", this.extendedDisplayNameTip);
this.element.setAttribute("image", this.image);
this.element.setAttribute("state",
DownloadsCommon.stateOfDownload(this.download));
// Since state changed, reset the time left estimation.
this.lastEstimatedSecondsLeft = Infinity;
@ -144,19 +152,12 @@ DownloadElementShell.prototype = {
* namely the progress bar and the status line.
*/
_updateProgress() {
if (this.dataItem.starting) {
// Before the download starts, the progress meter has its initial value.
// The progress bar is only displayed for in-progress downloads.
if (this.download.hasProgress) {
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");
this.element.setAttribute("progress", this.download.progress);
} else {
// This is a running download of which we know the progress.
this.element.setAttribute("progressmode", "normal");
this.element.setAttribute("progress", this.dataItem.percentComplete);
this.element.setAttribute("progressmode", "undetermined");
}
// Dispatch the ValueChange event for accessibility, if possible.
@ -190,71 +191,60 @@ DownloadElementShell.prototype = {
let text = "";
let tip = "";
if (this.dataItem.paused) {
let transfer = DownloadUtils.getTransferTotal(this.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".
text = s.statusSeparatorBeforeNumber(s.statePaused, transfer);
} else if (this.dataItem.state == nsIDM.DOWNLOAD_DOWNLOADING) {
if (!this.download.stopped) {
let maxBytes = DownloadsCommon.maxBytesOfDownload(this.download);
// By default, extended status information including the individual
// download rate is displayed in the tooltip. The history view overrides
// the getter and displays the detials in the main area instead.
[text] = DownloadUtils.getDownloadStatusNoRate(
this.download.currentBytes,
this.dataItem.maxBytes,
maxBytes,
this.download.speed,
this.lastEstimatedSecondsLeft);
let newEstimatedSecondsLeft;
[tip, newEstimatedSecondsLeft] = DownloadUtils.getDownloadStatus(
this.download.currentBytes,
this.dataItem.maxBytes,
maxBytes,
this.download.speed,
this.lastEstimatedSecondsLeft);
this.lastEstimatedSecondsLeft = newEstimatedSecondsLeft;
} else if (this.dataItem.starting) {
} else if (this.download.canceled && this.download.hasPartialData) {
let maxBytes = DownloadsCommon.maxBytesOfDownload(this.download);
let transfer = DownloadUtils.getTransferTotal(this.download.currentBytes,
maxBytes);
// We use the same XUL label to display both the state and the amount
// transferred, for example "Paused - 1.1 MB".
text = s.statusSeparatorBeforeNumber(s.statePaused, transfer);
} else if (!this.download.succeeded && !this.download.canceled &&
!this.download.error) {
text = s.stateStarting;
} else if (this.dataItem.state == nsIDM.DOWNLOAD_SCANNING) {
text = s.stateScanning;
} else {
let stateLabel;
switch (this.dataItem.state) {
case nsIDM.DOWNLOAD_FAILED:
stateLabel = s.stateFailed;
break;
case nsIDM.DOWNLOAD_CANCELED:
stateLabel = s.stateCanceled;
break;
case nsIDM.DOWNLOAD_BLOCKED_PARENTAL:
stateLabel = s.stateBlockedParentalControls;
break;
case nsIDM.DOWNLOAD_BLOCKED_POLICY:
stateLabel = s.stateBlockedPolicy;
break;
case nsIDM.DOWNLOAD_DIRTY:
stateLabel = s.stateDirty;
break;
case nsIDM.DOWNLOAD_FINISHED:
// For completed downloads, show the file size (e.g. "1.5 MB")
if (this.dataItem.maxBytes !== undefined &&
this.dataItem.maxBytes >= 0) {
let [size, unit] =
DownloadUtils.convertByteUnits(this.dataItem.maxBytes);
stateLabel = s.sizeWithUnits(size, unit);
break;
}
// Fallback to default unknown state.
default:
if (this.download.succeeded) {
// For completed downloads, show the file size (e.g. "1.5 MB")
let maxBytes = DownloadsCommon.maxBytesOfDownload(this.download);
if (maxBytes >= 0) {
let [size, unit] = DownloadUtils.convertByteUnits(maxBytes);
stateLabel = s.sizeWithUnits(size, unit);
} else {
stateLabel = s.sizeUnknown;
break;
}
} else if (this.download.canceled) {
stateLabel = s.stateCanceled;
} else if (this.download.error.becauseBlockedByParentalControls) {
stateLabel = s.stateBlockedParentalControls;
} else if (this.download.error.becauseBlockedByReputationCheck) {
stateLabel = s.stateDirty;
} else {
stateLabel = s.stateFailed;
}
let referrer = this.download.source.referrer ||
this.download.source.url;
let referrer = this.download.source.referrer || this.download.source.url;
let [displayHost, fullHost] = DownloadUtils.getURIHost(referrer);
let date = new Date(this.dataItem.endTime);
let date = new Date(this.download.endTime);
let [displayDate, fullDate] = DownloadUtils.getReadableDates(date);
let firstPart = s.statusSeparator(stateLabel, displayHost);