mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-21 22:57:31 +09:00
[PALEMOON] Bug 1115983 - Keep only minimal state information in the DataItem
This commit is contained in:
parent
419dd13315
commit
23f4f8a235
3 changed files with 118 additions and 209 deletions
|
|
@ -57,6 +57,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "DownloadUIHelper",
|
||||||
"resource://gre/modules/DownloadUIHelper.jsm");
|
"resource://gre/modules/DownloadUIHelper.jsm");
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils",
|
XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils",
|
||||||
"resource://gre/modules/DownloadUtils.jsm");
|
"resource://gre/modules/DownloadUtils.jsm");
|
||||||
|
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
|
||||||
|
"resource://gre/modules/FileUtils.jsm");
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "OS",
|
XPCOMUtils.defineLazyModuleGetter(this, "OS",
|
||||||
"resource://gre/modules/osfile.jsm")
|
"resource://gre/modules/osfile.jsm")
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
||||||
|
|
@ -94,11 +96,6 @@ const kDownloadsStringsRequiringPluralForm = {
|
||||||
otherDownloads2: true
|
otherDownloads2: true
|
||||||
};
|
};
|
||||||
|
|
||||||
XPCOMUtils.defineLazyGetter(this, "DownloadsLocalFileCtor", function () {
|
|
||||||
return Components.Constructor("@mozilla.org/file/local;1",
|
|
||||||
"nsILocalFile", "initWithPath");
|
|
||||||
});
|
|
||||||
|
|
||||||
const kPartialDownloadSuffix = ".part";
|
const kPartialDownloadSuffix = ".part";
|
||||||
|
|
||||||
const kPrefBranch = Services.prefs.getBranch("browser.download.");
|
const kPrefBranch = Services.prefs.getBranch("browser.download.");
|
||||||
|
|
@ -431,12 +428,12 @@ this.DownloadsCommon = {
|
||||||
break;
|
break;
|
||||||
case nsIDM.DOWNLOAD_DOWNLOADING:
|
case nsIDM.DOWNLOAD_DOWNLOADING:
|
||||||
summary.numDownloading++;
|
summary.numDownloading++;
|
||||||
if (dataItem.maxBytes > 0 && dataItem.speed > 0) {
|
if (dataItem.maxBytes > 0 && dataItem.download.speed > 0) {
|
||||||
let sizeLeft = dataItem.maxBytes - dataItem.currBytes;
|
let sizeLeft = dataItem.maxBytes - dataItem.download.currentBytes;
|
||||||
summary.rawTimeLeft = Math.max(summary.rawTimeLeft,
|
summary.rawTimeLeft = Math.max(summary.rawTimeLeft,
|
||||||
sizeLeft / dataItem.speed);
|
sizeLeft / dataItem.download.speed);
|
||||||
summary.slowestSpeed = Math.min(summary.slowestSpeed,
|
summary.slowestSpeed = Math.min(summary.slowestSpeed,
|
||||||
dataItem.speed);
|
dataItem.download.speed);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -445,7 +442,7 @@ this.DownloadsCommon = {
|
||||||
dataItem.state != nsIDM.DOWNLOAD_CANCELED &&
|
dataItem.state != nsIDM.DOWNLOAD_CANCELED &&
|
||||||
dataItem.state != nsIDM.DOWNLOAD_FAILED) {
|
dataItem.state != nsIDM.DOWNLOAD_FAILED) {
|
||||||
summary.totalSize += dataItem.maxBytes;
|
summary.totalSize += dataItem.maxBytes;
|
||||||
summary.totalTransferred += dataItem.currBytes;
|
summary.totalTransferred += dataItem.download.currentBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -574,7 +571,6 @@ this.DownloadsCommon = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a downloaded file in the system file manager.
|
* Show a downloaded file in the system file manager.
|
||||||
* If you have a dataItem, use dataItem.showLocalFile.
|
|
||||||
*
|
*
|
||||||
* @param aFile
|
* @param aFile
|
||||||
* a downloaded file.
|
* a downloaded file.
|
||||||
|
|
@ -793,7 +789,8 @@ DownloadsDataCtor.prototype = {
|
||||||
|
|
||||||
// RRR: Annotation service throws here. commented out for now.
|
// RRR: Annotation service throws here. commented out for now.
|
||||||
/*PlacesUtils.annotations.setPageAnnotation(
|
/*PlacesUtils.annotations.setPageAnnotation(
|
||||||
NetUtil.newURI(aDataItem.uri), "downloads/metaData",
|
NetUtil.newURI(aDataItem.download.source.url),
|
||||||
|
"downloads/metaData",
|
||||||
JSON.stringify(downloadMetaData), 0,
|
JSON.stringify(downloadMetaData), 0,
|
||||||
PlacesUtils.annotations.EXPIRE_WITH_HISTORY);*/
|
PlacesUtils.annotations.EXPIRE_WITH_HISTORY);*/
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
|
@ -873,7 +870,7 @@ DownloadsDataCtor.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedItemsArray.sort(function(a, b) b.startTime - a.startTime);
|
loadedItemsArray.sort(function(a, b) b.download.startTime - a.download.startTime);
|
||||||
loadedItemsArray.forEach(
|
loadedItemsArray.forEach(
|
||||||
function (dataItem) aView.onDataItemAdded(dataItem, false)
|
function (dataItem) aView.onDataItemAdded(dataItem, false)
|
||||||
);
|
);
|
||||||
|
|
@ -1364,12 +1361,9 @@ DownloadsDataItem.prototype = {
|
||||||
*/
|
*/
|
||||||
_initFromJSDownload: function (aDownload)
|
_initFromJSDownload: function (aDownload)
|
||||||
{
|
{
|
||||||
this._download = aDownload;
|
this.download = aDownload;
|
||||||
|
|
||||||
this.downloadGuid = "id:" + this._autoIncrementId;
|
this.downloadGuid = "id:" + this._autoIncrementId;
|
||||||
this.file = aDownload.target.path;
|
|
||||||
this.target = OS.Path.basename(aDownload.target.path);
|
|
||||||
this.uri = aDownload.source.url;
|
|
||||||
this.endTime = Date.now();
|
this.endTime = Date.now();
|
||||||
|
|
||||||
this.updateFromJSDownload();
|
this.updateFromJSDownload();
|
||||||
|
|
@ -1381,41 +1375,35 @@ DownloadsDataItem.prototype = {
|
||||||
updateFromJSDownload: function ()
|
updateFromJSDownload: function ()
|
||||||
{
|
{
|
||||||
// Collapse state using the correct priority.
|
// Collapse state using the correct priority.
|
||||||
if (this._download.succeeded) {
|
if (this.download.succeeded) {
|
||||||
this.state = nsIDM.DOWNLOAD_FINISHED;
|
this.state = nsIDM.DOWNLOAD_FINISHED;
|
||||||
} else if (this._download.error &&
|
} else if (this.download.error &&
|
||||||
this._download.error.becauseBlockedByParentalControls) {
|
this.download.error.becauseBlockedByParentalControls) {
|
||||||
this.state = nsIDM.DOWNLOAD_BLOCKED_PARENTAL;
|
this.state = nsIDM.DOWNLOAD_BLOCKED_PARENTAL;
|
||||||
} else if (this._download.error) {
|
} else if (this.download.error) {
|
||||||
this.state = nsIDM.DOWNLOAD_FAILED;
|
this.state = nsIDM.DOWNLOAD_FAILED;
|
||||||
} else if (this._download.canceled && this._download.hasPartialData) {
|
} else if (this.download.canceled && this.download.hasPartialData) {
|
||||||
this.state = nsIDM.DOWNLOAD_PAUSED;
|
this.state = nsIDM.DOWNLOAD_PAUSED;
|
||||||
} else if (this._download.canceled) {
|
} else if (this.download.canceled) {
|
||||||
this.state = nsIDM.DOWNLOAD_CANCELED;
|
this.state = nsIDM.DOWNLOAD_CANCELED;
|
||||||
} else if (this._download.stopped) {
|
} else if (this.download.stopped) {
|
||||||
this.state = nsIDM.DOWNLOAD_NOTSTARTED;
|
this.state = nsIDM.DOWNLOAD_NOTSTARTED;
|
||||||
} else {
|
} else {
|
||||||
this.state = nsIDM.DOWNLOAD_DOWNLOADING;
|
this.state = nsIDM.DOWNLOAD_DOWNLOADING;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.referrer = this._download.source.referrer;
|
if (this.download.succeeded) {
|
||||||
this.startTime = this._download.startTime;
|
|
||||||
this.currBytes = this._download.currentBytes;
|
|
||||||
this.resumable = this._download.hasPartialData;
|
|
||||||
this.speed = this._download.speed;
|
|
||||||
|
|
||||||
if (this._download.succeeded) {
|
|
||||||
// If the download succeeded, show the final size if available, otherwise
|
// If the download succeeded, show the final size if available, otherwise
|
||||||
// use the last known number of bytes transferred. The final size on disk
|
// use the last known number of bytes transferred. The final size on disk
|
||||||
// will be available when bug 941063 is resolved.
|
// will be available when bug 941063 is resolved.
|
||||||
this.maxBytes = this._download.hasProgress ?
|
this.maxBytes = this.download.hasProgress ?
|
||||||
this._download.totalBytes :
|
this.download.totalBytes :
|
||||||
this._download.currentBytes;
|
this.download.currentBytes;
|
||||||
this.percentComplete = 100;
|
this.percentComplete = 100;
|
||||||
} else if (this._download.hasProgress) {
|
} else if (this.download.hasProgress) {
|
||||||
// If the final size and progress are known, use them.
|
// If the final size and progress are known, use them.
|
||||||
this.maxBytes = this._download.totalBytes;
|
this.maxBytes = this.download.totalBytes;
|
||||||
this.percentComplete = this._download.progress;
|
this.percentComplete = this.download.progress;
|
||||||
} else {
|
} else {
|
||||||
// The download final size and progress percentage is unknown.
|
// The download final size and progress percentage is unknown.
|
||||||
this.maxBytes = -1;
|
this.maxBytes = -1;
|
||||||
|
|
@ -1580,14 +1568,6 @@ DownloadsDataItem.prototype = {
|
||||||
].indexOf(this.state) != -1;
|
].indexOf(this.state) != -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether the download is finished and can be opened.
|
|
||||||
*/
|
|
||||||
get openable()
|
|
||||||
{
|
|
||||||
return this.state == nsIDM.DOWNLOAD_FINISHED;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether the download stopped because of an error, and can be
|
* Indicates whether the download stopped because of an error, and can be
|
||||||
* resumed manually.
|
* resumed manually.
|
||||||
|
|
@ -1604,10 +1584,13 @@ DownloadsDataItem.prototype = {
|
||||||
* @throws if the native path is not valid. This can happen if the same
|
* @throws if the native path is not valid. This can happen if the same
|
||||||
* profile is used on different platforms, for example if a native
|
* profile is used on different platforms, for example if a native
|
||||||
* Windows path is stored and then the item is accessed on a Mac.
|
* Windows path is stored and then the item is accessed on a Mac.
|
||||||
|
*
|
||||||
|
* @deprecated Callers should use OS.File and "download.target.path".
|
||||||
*/
|
*/
|
||||||
get localFile()
|
get localFile()
|
||||||
{
|
{
|
||||||
return this._getFile(this.file);
|
// We should remove should use this.download.target.partFilePath and check asyncrhonously.
|
||||||
|
return new FileUtils.File(this.download.target.path);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1616,80 +1599,12 @@ DownloadsDataItem.prototype = {
|
||||||
* @throws if the native path is not valid. This can happen if the same
|
* @throws if the native path is not valid. This can happen if the same
|
||||||
* profile is used on different platforms, for example if a native
|
* profile is used on different platforms, for example if a native
|
||||||
* Windows path is stored and then the item is accessed on a Mac.
|
* Windows path is stored and then the item is accessed on a Mac.
|
||||||
|
*
|
||||||
|
* @deprecated Callers should use OS.File and "download.target.partFilePath".
|
||||||
*/
|
*/
|
||||||
get partFile()
|
get partFile()
|
||||||
{
|
{
|
||||||
return this._getFile(this.file + kPartialDownloadSuffix);
|
return new FileUtils.File(this.download.target.path + kPartialDownloadSuffix);
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an nsILocalFile for aFilename. aFilename might be a file URL or
|
|
||||||
* a native path.
|
|
||||||
*
|
|
||||||
* @param aFilename the filename of the file to retrieve.
|
|
||||||
* @return an nsILocalFile for the file.
|
|
||||||
* @throws if the native path is not valid. This can happen if the same
|
|
||||||
* profile is used on different platforms, for example if a native
|
|
||||||
* Windows path is stored and then the item is accessed on a Mac.
|
|
||||||
* @note This function makes no guarantees about the file's existence -
|
|
||||||
* callers should check that the returned file exists.
|
|
||||||
*/
|
|
||||||
_getFile: function DDI__getFile(aFilename)
|
|
||||||
{
|
|
||||||
// The download database may contain targets stored as file URLs or native
|
|
||||||
// paths. This can still be true for previously stored items, even if new
|
|
||||||
// items are stored using their file URL. See also bug 239948 comment 12.
|
|
||||||
if (aFilename.startsWith("file:")) {
|
|
||||||
// Assume the file URL we obtained from the downloads database or from the
|
|
||||||
// "spec" property of the target has the UTF-8 charset.
|
|
||||||
let fileUrl = NetUtil.newURI(aFilename).QueryInterface(Ci.nsIFileURL);
|
|
||||||
return fileUrl.file.clone().QueryInterface(Ci.nsILocalFile);
|
|
||||||
} else {
|
|
||||||
// The downloads database contains a native path. Try to create a local
|
|
||||||
// file, though this may throw an exception if the path is invalid.
|
|
||||||
return new DownloadsLocalFileCtor(aFilename);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open the target file for this download.
|
|
||||||
*
|
|
||||||
* @param aOwnerWindow
|
|
||||||
* The window with which the required action is associated.
|
|
||||||
* @throws if the file cannot be opened.
|
|
||||||
*/
|
|
||||||
openLocalFile: function DDI_openLocalFile(aOwnerWindow) {
|
|
||||||
this._download.launch().then(null, Cu.reportError);
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the downloaded file in the system file manager.
|
|
||||||
*/
|
|
||||||
showLocalFile: function DDI_showLocalFile() {
|
|
||||||
DownloadsCommon.showDownloadedFile(this.localFile);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resumes the download if paused, pauses it if active.
|
|
||||||
* @throws if the download is not resumable or if has already done.
|
|
||||||
*/
|
|
||||||
togglePauseResume: function DDI_togglePauseResume() {
|
|
||||||
if (this._download.stopped) {
|
|
||||||
this._download.start();
|
|
||||||
} else {
|
|
||||||
this._download.cancel();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to retry the download.
|
|
||||||
* @throws if we cannot.
|
|
||||||
*/
|
|
||||||
retry: function DDI_retry() {
|
|
||||||
this._download.start();
|
|
||||||
return;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1705,29 +1620,6 @@ DownloadsDataItem.prototype = {
|
||||||
localFile.remove(false);
|
localFile.remove(false);
|
||||||
}
|
}
|
||||||
} catch (ex) { }
|
} catch (ex) { }
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancels the download.
|
|
||||||
* @throws if the download is already done.
|
|
||||||
*/
|
|
||||||
cancel: function() {
|
|
||||||
this._download.cancel();
|
|
||||||
this._download.removePartialData().then(null, Cu.reportError);
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the download.
|
|
||||||
*/
|
|
||||||
remove: function DDI_remove() {
|
|
||||||
let promiseList = this._download.source.isPrivate
|
|
||||||
? Downloads.getList(Downloads.PUBLIC)
|
|
||||||
: Downloads.getList(Downloads.PRIVATE);
|
|
||||||
promiseList.then(list => list.remove(this._download))
|
|
||||||
.then(() => this._download.finalize(true))
|
|
||||||
.then(null, Cu.reportError);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ DownloadElementShell.prototype = {
|
||||||
// The download uri (as a string)
|
// The download uri (as a string)
|
||||||
get downloadURI() {
|
get downloadURI() {
|
||||||
if (this._dataItem)
|
if (this._dataItem)
|
||||||
return this._dataItem.uri;
|
return this._dataItem.download.source.url;
|
||||||
if (this._placesNode)
|
if (this._placesNode)
|
||||||
return this._placesNode.uri;
|
return this._placesNode.uri;
|
||||||
throw new Error("Unexpected download element state");
|
throw new Error("Unexpected download element state");
|
||||||
|
|
@ -246,21 +246,22 @@ DownloadElementShell.prototype = {
|
||||||
getDownloadMetaData: function DES_getDownloadMetaData() {
|
getDownloadMetaData: function DES_getDownloadMetaData() {
|
||||||
if (!this._metaData) {
|
if (!this._metaData) {
|
||||||
if (this._dataItem) {
|
if (this._dataItem) {
|
||||||
|
let leafName = OS.Path.basename(this._dataItem.download.target.path);
|
||||||
let s = DownloadsCommon.strings;
|
let s = DownloadsCommon.strings;
|
||||||
let referrer = this._dataItem.referrer || this._dataItem.uri;
|
let referrer = this.dataItem.download.source.referrer ||
|
||||||
|
this.dataItem.download.source.url;
|
||||||
let [displayHost, fullHost] = DownloadUtils.getURIHost(referrer);
|
let [displayHost, fullHost] = DownloadUtils.getURIHost(referrer);
|
||||||
this._metaData = {
|
this._metaData = {
|
||||||
state: this._dataItem.state,
|
state: this._dataItem.state,
|
||||||
endTime: this._dataItem.endTime,
|
endTime: this._dataItem.endTime,
|
||||||
fileName: this._dataItem.target,
|
fileName: leafName,
|
||||||
displayName: this._dataItem.target,
|
displayName: leafName,
|
||||||
extendedDisplayName: s.statusSeparator(this._dataItem.target, displayHost),
|
extendedDisplayName: s.statusSeparator(leafName, displayHost),
|
||||||
extendedDisplayNameTip: s.statusSeparator(this._dataItem.target, fullHost)
|
extendedDisplayNameTip: s.statusSeparator(leafName, fullHost)
|
||||||
};
|
};
|
||||||
if (this._dataItem.done)
|
if (this._dataItem.done)
|
||||||
this._metaData.fileSize = this._dataItem.maxBytes;
|
this._metaData.fileSize = this._dataItem.maxBytes;
|
||||||
if (this._dataItem.localFile)
|
this._metaData.filePath = this._dataItem.download.target.path;
|
||||||
this._metaData.filePath = this._dataItem.localFile.path;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
|
|
@ -304,7 +305,7 @@ DownloadElementShell.prototype = {
|
||||||
if (this._dataItem && this._dataItem.inProgress) {
|
if (this._dataItem && this._dataItem.inProgress) {
|
||||||
if (this._dataItem.paused) {
|
if (this._dataItem.paused) {
|
||||||
let transfer =
|
let transfer =
|
||||||
DownloadUtils.getTransferTotal(this._dataItem.currBytes,
|
DownloadUtils.getTransferTotal(this._dataItem.download.currentBytes,
|
||||||
this._dataItem.maxBytes);
|
this._dataItem.maxBytes);
|
||||||
|
|
||||||
// We use the same XUL label to display both the state and the amount
|
// We use the same XUL label to display both the state and the amount
|
||||||
|
|
@ -313,9 +314,9 @@ DownloadElementShell.prototype = {
|
||||||
}
|
}
|
||||||
if (this._dataItem.state == nsIDM.DOWNLOAD_DOWNLOADING) {
|
if (this._dataItem.state == nsIDM.DOWNLOAD_DOWNLOADING) {
|
||||||
let [status, newEstimatedSecondsLeft] =
|
let [status, newEstimatedSecondsLeft] =
|
||||||
DownloadUtils.getDownloadStatus(this.dataItem.currBytes,
|
DownloadUtils.getDownloadStatus(this.dataItem.download.currentBytes,
|
||||||
this.dataItem.maxBytes,
|
this.dataItem.maxBytes,
|
||||||
this.dataItem.speed,
|
this.dataItem.download.speed,
|
||||||
this._lastEstimatedSecondsLeft || Infinity);
|
this._lastEstimatedSecondsLeft || Infinity);
|
||||||
this._lastEstimatedSecondsLeft = newEstimatedSecondsLeft;
|
this._lastEstimatedSecondsLeft = newEstimatedSecondsLeft;
|
||||||
return status;
|
return status;
|
||||||
|
|
@ -365,7 +366,7 @@ DownloadElementShell.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO (bug 829201): history downloads should get the referrer from Places.
|
// TODO (bug 829201): history downloads should get the referrer from Places.
|
||||||
let referrer = this._dataItem && this._dataItem.referrer ||
|
let referrer = this._dataItem && this._dataItem.download.source.referrer ||
|
||||||
this.downloadURI;
|
this.downloadURI;
|
||||||
let [displayHost, fullHost] = DownloadUtils.getURIHost(referrer);
|
let [displayHost, fullHost] = DownloadUtils.getURIHost(referrer);
|
||||||
|
|
||||||
|
|
@ -488,10 +489,10 @@ DownloadElementShell.prototype = {
|
||||||
return false;
|
return false;
|
||||||
switch (aCommand) {
|
switch (aCommand) {
|
||||||
case "downloadsCmd_open": {
|
case "downloadsCmd_open": {
|
||||||
// We cannot open a session download file unless it's done ("openable").
|
// We cannot open a session download file unless it's succeeded.
|
||||||
// If it's finished, we need to make sure the file was not removed,
|
// If it's succeeded, we need to make sure the file was not removed,
|
||||||
// as we do for past downloads.
|
// as we do for past downloads.
|
||||||
if (this._dataItem && !this._dataItem.openable)
|
if (this._dataItem && !this._dataItem.download.succeeded) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (this._targetFileInfoFetched)
|
if (this._targetFileInfoFetched)
|
||||||
|
|
@ -515,12 +516,13 @@ DownloadElementShell.prototype = {
|
||||||
return this.getDownloadMetaData().state == nsIDM.DOWNLOAD_FINISHED;
|
return this.getDownloadMetaData().state == nsIDM.DOWNLOAD_FINISHED;
|
||||||
}
|
}
|
||||||
case "downloadsCmd_pauseResume":
|
case "downloadsCmd_pauseResume":
|
||||||
return this._dataItem && this._dataItem.inProgress && this._dataItem.resumable;
|
return this._dataItem && this._dataItem.inProgress &&
|
||||||
|
this._dataItem.download.hasPartialData;
|
||||||
case "downloadsCmd_retry":
|
case "downloadsCmd_retry":
|
||||||
// An history download can always be retried.
|
// An history download can always be retried.
|
||||||
return !this._dataItem || this._dataItem.canRetry;
|
return !this._dataItem || this._dataItem.canRetry;
|
||||||
case "downloadsCmd_openReferrer":
|
case "downloadsCmd_openReferrer":
|
||||||
return this._dataItem && !!this._dataItem.referrer;
|
return this._dataItem && !!this._dataItem.download.source.referrer;
|
||||||
case "cmd_delete":
|
case "cmd_delete":
|
||||||
// The behavior in this case is somewhat unexpected, so we disallow that.
|
// The behavior in this case is somewhat unexpected, so we disallow that.
|
||||||
if (this._placesNode && this._dataItem && this._dataItem.inProgress)
|
if (this._placesNode && this._dataItem && this._dataItem.inProgress)
|
||||||
|
|
@ -546,36 +548,35 @@ DownloadElementShell.prototype = {
|
||||||
doCommand: function DES_doCommand(aCommand) {
|
doCommand: function DES_doCommand(aCommand) {
|
||||||
switch (aCommand) {
|
switch (aCommand) {
|
||||||
case "downloadsCmd_open": {
|
case "downloadsCmd_open": {
|
||||||
let file = this._dataItem ?
|
let file = new FileUtils.File(this._dataItem
|
||||||
this.dataItem.localFile :
|
? this._dataItem.download.target.path
|
||||||
new FileUtils.File(this.getDownloadMetaData().filePath);
|
: this.getDownloadMetaData().filePath);
|
||||||
|
|
||||||
DownloadsCommon.openDownloadedFile(file, null, window);
|
DownloadsCommon.openDownloadedFile(file, null, window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "downloadsCmd_show": {
|
case "downloadsCmd_show": {
|
||||||
if (this._dataItem) {
|
let file = new FileUtils.File(this._dataItem
|
||||||
this._dataItem.showLocalFile();
|
? this._dataItem.download.target.path
|
||||||
}
|
: this.getDownloadMetaData().filePath);
|
||||||
else {
|
|
||||||
let file = new FileUtils.File(this.getDownloadMetaData().filePath);
|
DownloadsCommon.showDownloadedFile(file);
|
||||||
DownloadsCommon.showDownloadedFile(file);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "downloadsCmd_openReferrer": {
|
case "downloadsCmd_openReferrer": {
|
||||||
openURL(this._dataItem.referrer);
|
openURL(this._dataItem.download.source.referrer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "downloadsCmd_cancel": {
|
case "downloadsCmd_cancel": {
|
||||||
this._dataItem.cancel();
|
this._dataItem.download.cancel().catch(() => {});
|
||||||
|
this._dataItem.download.removePartialData().catch(Cu.reportError);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "cmd_delete": {
|
case "cmd_delete": {
|
||||||
if (this._dataItem)
|
if (this._dataItem)
|
||||||
Downloads.getList(Downloads.ALL)
|
Downloads.getList(Downloads.ALL)
|
||||||
.then(list => list.remove(this._dataItem._download))
|
.then(list => list.remove(this._dataItem.download))
|
||||||
.then(() => this._dataItem._download.finalize(true))
|
.then(() => this._dataItem.download.finalize(true))
|
||||||
.catch(Cu.reportError);
|
.catch(Cu.reportError);
|
||||||
if (this._placesNode)
|
if (this._placesNode)
|
||||||
PlacesUtils.bhistory.removePage(this._downloadURIObj);
|
PlacesUtils.bhistory.removePage(this._downloadURIObj);
|
||||||
|
|
@ -583,13 +584,17 @@ DownloadElementShell.prototype = {
|
||||||
}
|
}
|
||||||
case "downloadsCmd_retry": {
|
case "downloadsCmd_retry": {
|
||||||
if (this._dataItem)
|
if (this._dataItem)
|
||||||
this._dataItem.retry();
|
this._dataItem.download.start().catch(() => {});
|
||||||
else
|
else
|
||||||
this._retryAsHistoryDownload();
|
this._retryAsHistoryDownload();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "downloadsCmd_pauseResume": {
|
case "downloadsCmd_pauseResume": {
|
||||||
this._dataItem.togglePauseResume();
|
if (this._dataItem.download.stopped) {
|
||||||
|
this._dataItem.download.start();
|
||||||
|
} else {
|
||||||
|
this._dataItem.download.cancel();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -836,7 +841,8 @@ DownloadsPlacesView.prototype = {
|
||||||
_addDownloadData:
|
_addDownloadData:
|
||||||
function DPV_addDownloadData(aDataItem, aPlacesNode, aNewest = false,
|
function DPV_addDownloadData(aDataItem, aPlacesNode, aNewest = false,
|
||||||
aDocumentFragment = null) {
|
aDocumentFragment = null) {
|
||||||
let downloadURI = aPlacesNode ? aPlacesNode.uri : aDataItem.uri;
|
let downloadURI = aPlacesNode ? aPlacesNode.uri
|
||||||
|
: aDataItem.download.source.url;
|
||||||
let shellsForURI = this._downloadElementsShellsForURI.get(downloadURI);
|
let shellsForURI = this._downloadElementsShellsForURI.get(downloadURI);
|
||||||
if (!shellsForURI) {
|
if (!shellsForURI) {
|
||||||
shellsForURI = new Set();
|
shellsForURI = new Set();
|
||||||
|
|
@ -989,7 +995,8 @@ DownloadsPlacesView.prototype = {
|
||||||
|
|
||||||
_removeSessionDownloadFromView:
|
_removeSessionDownloadFromView:
|
||||||
function DPV__removeSessionDownloadFromView(aDataItem) {
|
function DPV__removeSessionDownloadFromView(aDataItem) {
|
||||||
let shells = this._downloadElementsShellsForURI.get(aDataItem.uri);
|
let shells = this._downloadElementsShellsForURI
|
||||||
|
.get(aDataItem.download.source.url);
|
||||||
if (shells.size == 0)
|
if (shells.size == 0)
|
||||||
throw new Error("Should have had at leaat one shell for this uri");
|
throw new Error("Should have had at leaat one shell for this uri");
|
||||||
|
|
||||||
|
|
@ -1005,7 +1012,7 @@ DownloadsPlacesView.prototype = {
|
||||||
this._removeElement(shell.element);
|
this._removeElement(shell.element);
|
||||||
shells.delete(shell);
|
shells.delete(shell);
|
||||||
if (shells.size == 0)
|
if (shells.size == 0)
|
||||||
this._downloadElementsShellsForURI.delete(aDataItem.uri);
|
this._downloadElementsShellsForURI.delete(aDataItem.download.source.url);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We have one download element shell containing both a session download
|
// We have one download element shell containing both a session download
|
||||||
|
|
|
||||||
|
|
@ -1071,12 +1071,14 @@ function DownloadsViewItem(aDataItem, aElement)
|
||||||
// as bug 239948 comment 12 is handled, the "file" property will be always a
|
// 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 "//"
|
// 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).
|
// (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 s = DownloadsCommon.strings;
|
||||||
let [displayHost, fullHost] =
|
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 = {
|
let attributes = {
|
||||||
"type": "download",
|
"type": "download",
|
||||||
"class": "download-state",
|
"class": "download-state",
|
||||||
|
|
@ -1084,9 +1086,9 @@ function DownloadsViewItem(aDataItem, aElement)
|
||||||
"downloadGuid": 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": this.dataItem.target,
|
"displayName": target,
|
||||||
"extendedDisplayName": s.statusSeparator(this.dataItem.target, displayHost),
|
"extendedDisplayName": s.statusSeparator(target, displayHost),
|
||||||
"extendedDisplayNameTip": s.statusSeparator(this.dataItem.target, fullHost),
|
"extendedDisplayNameTip": s.statusSeparator(target, fullHost),
|
||||||
"image": this.image
|
"image": this.image
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1203,7 +1205,7 @@ DownloadsViewItem.prototype = {
|
||||||
let statusTip = "";
|
let statusTip = "";
|
||||||
|
|
||||||
if (this.dataItem.paused) {
|
if (this.dataItem.paused) {
|
||||||
let transfer = DownloadUtils.getTransferTotal(this.dataItem.currBytes,
|
let transfer = DownloadUtils.getTransferTotal(this.dataItem.download.currentBytes,
|
||||||
this.dataItem.maxBytes);
|
this.dataItem.maxBytes);
|
||||||
|
|
||||||
// We use the same XUL label to display both the state and the amount
|
// 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
|
// The remaining time per download is likely enough information for the
|
||||||
// panel.
|
// panel.
|
||||||
[status] =
|
[status] =
|
||||||
DownloadUtils.getDownloadStatusNoRate(this.dataItem.currBytes,
|
DownloadUtils.getDownloadStatusNoRate(this.dataItem.download.currentBytes,
|
||||||
this.dataItem.maxBytes,
|
this.dataItem.maxBytes,
|
||||||
this.dataItem.speed,
|
this.dataItem.download.speed,
|
||||||
this.lastEstimatedSecondsLeft);
|
this.lastEstimatedSecondsLeft);
|
||||||
|
|
||||||
// We are, however, OK with displaying the rate in the tooltip.
|
// We are, however, OK with displaying the rate in the tooltip.
|
||||||
let newEstimatedSecondsLeft;
|
let newEstimatedSecondsLeft;
|
||||||
[statusTip, newEstimatedSecondsLeft] =
|
[statusTip, newEstimatedSecondsLeft] =
|
||||||
DownloadUtils.getDownloadStatus(this.dataItem.currBytes,
|
DownloadUtils.getDownloadStatus(this.dataItem.download.currentBytes,
|
||||||
this.dataItem.maxBytes,
|
this.dataItem.maxBytes,
|
||||||
this.dataItem.speed,
|
this.dataItem.download.speed,
|
||||||
this.lastEstimatedSecondsLeft);
|
this.lastEstimatedSecondsLeft);
|
||||||
this.lastEstimatedSecondsLeft = newEstimatedSecondsLeft;
|
this.lastEstimatedSecondsLeft = newEstimatedSecondsLeft;
|
||||||
} else if (this.dataItem.starting) {
|
} else if (this.dataItem.starting) {
|
||||||
|
|
@ -1248,7 +1250,8 @@ DownloadsViewItem.prototype = {
|
||||||
}.apply(this);
|
}.apply(this);
|
||||||
|
|
||||||
let [displayHost, fullHost] =
|
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 end = new Date(this.dataItem.endTime);
|
||||||
let [displayDate, fullDate] = DownloadUtils.getReadableDates(end);
|
let [displayDate, fullDate] = DownloadUtils.getReadableDates(end);
|
||||||
|
|
@ -1294,18 +1297,17 @@ DownloadsViewItem.prototype = {
|
||||||
*/
|
*/
|
||||||
verifyTargetExists: function DVI_verifyTargetExists() {
|
verifyTargetExists: function DVI_verifyTargetExists() {
|
||||||
// We don't need to check if the download is not finished successfully.
|
// We don't need to check if the download is not finished successfully.
|
||||||
if (!this.dataItem.openable) {
|
if (!this.dataItem.download.succeeded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OS.File.exists(this.dataItem.localFile.path).then(
|
OS.File.exists(this.dataItem.download.target.path).then(aExists => {
|
||||||
function DVI_RTE_onSuccess(aExists) {
|
if (aExists) {
|
||||||
if (aExists) {
|
this._element.setAttribute("exists", "true");
|
||||||
this._element.setAttribute("exists", "true");
|
} else {
|
||||||
} else {
|
this._element.removeAttribute("exists");
|
||||||
this._element.removeAttribute("exists");
|
}
|
||||||
}
|
}).catch(Cu.reportError);
|
||||||
}.bind(this), Cu.reportError);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1434,18 +1436,20 @@ DownloadsViewItemController.prototype = {
|
||||||
{
|
{
|
||||||
switch (aCommand) {
|
switch (aCommand) {
|
||||||
case "downloadsCmd_open": {
|
case "downloadsCmd_open": {
|
||||||
return this.dataItem.openable && this.dataItem.localFile.exists();
|
return this.dataItem.download.succeeded &&
|
||||||
|
this.dataItem.localFile.exists();
|
||||||
}
|
}
|
||||||
case "downloadsCmd_show": {
|
case "downloadsCmd_show": {
|
||||||
return this.dataItem.localFile.exists() ||
|
return this.dataItem.localFile.exists() ||
|
||||||
this.dataItem.partFile.exists();
|
this.dataItem.partFile.exists();
|
||||||
}
|
}
|
||||||
case "downloadsCmd_pauseResume":
|
case "downloadsCmd_pauseResume":
|
||||||
return this.dataItem.inProgress && this.dataItem.resumable;
|
return this.dataItem.inProgress &&
|
||||||
|
this.dataItem.download.hasPartialData;
|
||||||
case "downloadsCmd_retry":
|
case "downloadsCmd_retry":
|
||||||
return this.dataItem.canRetry;
|
return this.dataItem.canRetry;
|
||||||
case "downloadsCmd_openReferrer":
|
case "downloadsCmd_openReferrer":
|
||||||
return !!this.dataItem.referrer;
|
return !!this.dataItem.download.source.referrer;
|
||||||
case "cmd_delete":
|
case "cmd_delete":
|
||||||
case "downloadsCmd_cancel":
|
case "downloadsCmd_cancel":
|
||||||
case "downloadsCmd_copyLocation":
|
case "downloadsCmd_copyLocation":
|
||||||
|
|
@ -1474,20 +1478,22 @@ DownloadsViewItemController.prototype = {
|
||||||
cmd_delete: function DVIC_cmd_delete()
|
cmd_delete: function DVIC_cmd_delete()
|
||||||
{
|
{
|
||||||
Downloads.getList(Downloads.ALL)
|
Downloads.getList(Downloads.ALL)
|
||||||
.then(list => list.remove(this.dataItem._download))
|
.then(list => list.remove(this.dataItem.download))
|
||||||
.then(() => this.dataItem._download.finalize(true))
|
.then(() => this.dataItem.download.finalize(true))
|
||||||
.catch(Cu.reportError);
|
.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()
|
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()
|
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
|
// We explicitly close the panel here to give the user the feedback that
|
||||||
// their click has been received, and we're handling the action.
|
// their click has been received, and we're handling the action.
|
||||||
// Otherwise, we'd have to wait for the file-type handler to execute
|
// 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()
|
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
|
// We explicitly close the panel here to give the user the feedback that
|
||||||
// their click has been received, and we're handling the action.
|
// their click has been received, and we're handling the action.
|
||||||
|
|
@ -1510,24 +1516,28 @@ DownloadsViewItemController.prototype = {
|
||||||
|
|
||||||
downloadsCmd_pauseResume: function DVIC_downloadsCmd_pauseResume()
|
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()
|
downloadsCmd_retry: function DVIC_downloadsCmd_retry()
|
||||||
{
|
{
|
||||||
this.dataItem.retry();
|
this.dataItem.download.start().catch(() => {});
|
||||||
},
|
},
|
||||||
|
|
||||||
downloadsCmd_openReferrer: function DVIC_downloadsCmd_openReferrer()
|
downloadsCmd_openReferrer: function DVIC_downloadsCmd_openReferrer()
|
||||||
{
|
{
|
||||||
openURL(this.dataItem.referrer);
|
openURL(this.dataItem.download.source.referrer);
|
||||||
},
|
},
|
||||||
|
|
||||||
downloadsCmd_copyLocation: function DVIC_downloadsCmd_copyLocation()
|
downloadsCmd_copyLocation: function DVIC_downloadsCmd_copyLocation()
|
||||||
{
|
{
|
||||||
let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"]
|
let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"]
|
||||||
.getService(Ci.nsIClipboardHelper);
|
.getService(Ci.nsIClipboardHelper);
|
||||||
clipboard.copyString(this.dataItem.uri, document);
|
clipboard.copyString(this.dataItem.download.source.url, document);
|
||||||
},
|
},
|
||||||
|
|
||||||
downloadsCmd_doDefault: function DVIC_downloadsCmd_doDefault()
|
downloadsCmd_doDefault: function DVIC_downloadsCmd_doDefault()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue