mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 883959: Part 2: Rework download progress. r=sfoster.
This commit is contained in:
parent
4f373a7bbe
commit
71d1d8ef0e
@ -12,6 +12,7 @@ var Downloads = {
|
||||
* downloads if it starts before other downloads have completed.
|
||||
*/
|
||||
_downloadCount: 0,
|
||||
_downloadsInProgress: 0,
|
||||
_inited: false,
|
||||
_progressAlert: null,
|
||||
_lastSec: Infinity,
|
||||
@ -99,25 +100,26 @@ var Downloads = {
|
||||
},
|
||||
|
||||
cancelDownload: function dh_cancelDownload(aDownload) {
|
||||
this._progressNotificationInfo.delete(aDownload.guid);
|
||||
this._runDownloadBooleanMap.delete(aDownload.targetFile.path);
|
||||
this._downloadCount--;
|
||||
if (this._progressNotificationInfo.size == 0) {
|
||||
this._notificationBox.removeNotification(this._progressNotification);
|
||||
this._progressNotification = null;
|
||||
}
|
||||
|
||||
let fileURI = aDownload.target;
|
||||
if (!(fileURI && fileURI.spec)) {
|
||||
Util.dumpLn("Cant remove download file for: "+aDownload.id+", fileURI is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
let file = this._getLocalFile(fileURI);
|
||||
try {
|
||||
this.manager.cancelDownload(aDownload.id);
|
||||
let file = this._getLocalFile(fileURI);
|
||||
if (file && file.exists())
|
||||
file.remove(false);
|
||||
this.manager.cancelDownload(aDownload.id);
|
||||
|
||||
// If cancelling was successful, stop tracking the download.
|
||||
this._progressNotificationInfo.delete(aDownload.guid);
|
||||
this._runDownloadBooleanMap.delete(aDownload.targetFile.path);
|
||||
this._downloadCount--;
|
||||
this._downloadsInProgress--;
|
||||
if (this._downloadsInProgress <= 0) {
|
||||
this._notificationBox.removeNotification(this._progressNotification);
|
||||
this._progressNotification = null;
|
||||
}
|
||||
} catch (ex) {
|
||||
Util.dumpLn("Failed to cancel download, with id: "+aDownload.id+", download target URI spec: " + fileURI.spec);
|
||||
Util.dumpLn("Failed download source:"+(aDownload.source && aDownload.source.spec));
|
||||
@ -367,6 +369,7 @@ var Downloads = {
|
||||
break;
|
||||
case "dl-start":
|
||||
this._downloadCount++;
|
||||
this._downloadsInProgress++;
|
||||
let download = aSubject.QueryInterface(Ci.nsIDownload);
|
||||
if (!this._progressNotificationInfo.get(download.guid)) {
|
||||
this._progressNotificationInfo.set(download.guid, {});
|
||||
@ -378,18 +381,19 @@ var Downloads = {
|
||||
this.updateInfobar(download);
|
||||
break;
|
||||
case "dl-done":
|
||||
this._downloadsInProgress--;
|
||||
download = aSubject.QueryInterface(Ci.nsIDownload);
|
||||
let runAfterDownload = this._runDownloadBooleanMap.get(download.targetFile.path);
|
||||
if (runAfterDownload) {
|
||||
this.openDownload(download);
|
||||
}
|
||||
|
||||
this._progressNotificationInfo.delete(download.guid);
|
||||
this._runDownloadBooleanMap.delete(download.targetFile.path);
|
||||
if (this._progressNotificationInfo.size == 0) {
|
||||
if (this._downloadsInProgress == 0) {
|
||||
if (this._downloadCount > 1 || !runAfterDownload) {
|
||||
this._showDownloadCompleteNotification(download);
|
||||
}
|
||||
this._progressNotificationInfo.clear();
|
||||
this._downloadCount = 0;
|
||||
this._notificationBox.removeNotification(this._progressNotification);
|
||||
this._progressNotification = null;
|
||||
@ -397,6 +401,7 @@ var Downloads = {
|
||||
break;
|
||||
case "dl-failed":
|
||||
download = aSubject.QueryInterface(Ci.nsIDownload);
|
||||
this._showDownloadFailedNotification(download);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
@ -331,4 +331,14 @@ gTests.push({
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Make sure the cancelled/aborted downloads are handled correctly.
|
||||
*/
|
||||
gTests.push({
|
||||
desc: "Cancel/Abort Downloads",
|
||||
run: function(){
|
||||
todo(false, "Ensure that a cancelled/aborted download is in the correct state \
|
||||
including correct values for state variables (e.g. _downloadCount, _downloadsInProgress) \
|
||||
and the existence of the downloaded file.");
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user