Bug 1448143 - Factor out a size getter from DownloadsViewUI.jsm so other consumers can access it
MozReview-Commit-ID: EgyfXz1ntys
--- a/browser/components/downloads/DownloadsViewUI.jsm
+++ b/browser/components/downloads/DownloadsViewUI.jsm
@@ -104,16 +104,38 @@ this.DownloadsViewUI.DownloadElementShel
*/
get displayName() {
if (!this.download.target.path) {
return this.download.source.url;
}
return OS.Path.basename(this.download.target.path);
},
+ /**
+ * The user-facing label for the size (if any) of the download. The return value
+ * is an object 'sizeStrings' with 2 strings:
+ * 1. stateLabel - The size with the units (e.g. "1.5 MB").
+ * 2. status - The status of the download (e.g. "Completed");
+ */
+ get sizeStrings() {
+ let s = DownloadsCommon.strings;
+ let sizeStrings = {};
+
+ if (this.download.target.size !== undefined) {
+ let [size, unit] = DownloadUtils.convertByteUnits(this.download.target.size);
+ sizeStrings.stateLabel = s.sizeWithUnits(size, unit);
+ sizeStrings.status = s.statusSeparator(s.stateCompleted, sizeStrings.stateLabel);
+ } else {
+ // History downloads may not have a size defined.
+ sizeStrings.stateLabel = s.sizeUnknown;
+ sizeStrings.status = s.stateCompleted;
+ }
+ return sizeStrings;
+ },
+
get browserWindow() {
return RecentWindow.getMostRecentBrowserWindow();
},
/**
* The progress element for the download, or undefined in case the XBL binding
* has not been applied yet.
*/
@@ -240,27 +262,20 @@ this.DownloadsViewUI.DownloadElementShel
hoverStatus = status;
} else {
let stateLabel;
if (this.download.succeeded && !this.download.target.exists) {
stateLabel = s.fileMovedOrMissing;
hoverStatus = stateLabel;
} else if (this.download.succeeded) {
- // For completed downloads, show the file size (e.g. "1.5 MB").
- if (this.download.target.size !== undefined) {
- let [size, unit] =
- DownloadUtils.convertByteUnits(this.download.target.size);
- stateLabel = s.sizeWithUnits(size, unit);
- status = s.statusSeparator(s.stateCompleted, stateLabel);
- } else {
- // History downloads may not have a size defined.
- stateLabel = s.sizeUnknown;
- status = s.stateCompleted;
- }
+ // For completed downloads, show the file size
+ let sizeStrings = this.sizeStrings;
+ stateLabel = sizeStrings.stateLabel;
+ status = sizeStrings.status;
hoverStatus = status;
} else if (this.download.canceled) {
stateLabel = s.stateCanceled;
} else if (this.download.error.becauseBlockedByParentalControls) {
stateLabel = s.stateBlockedParentalControls;
} else if (this.download.error.becauseBlockedByReputationCheck) {
stateLabel = this.rawBlockedTitleAndDetails[0];
} else {