Bug 941726 - Prevent DownloadLegacy from keeping a reference to the network request after the download is stopped. r=enn

This commit is contained in:
Paolo Amadini 2013-12-03 10:15:22 +01:00
parent e340eb192b
commit de3ac81906
2 changed files with 17 additions and 9 deletions

View File

@ -2043,10 +2043,16 @@ this.DownloadLegacySaver.prototype = {
Cu.reportError(e2);
}
}
// In case the operation failed, ensure we stop downloading data. Since
// we never re-enter this function, deferCanceled is always available.
this.deferCanceled.resolve();
throw ex;
} finally {
// We don't need the reference to the request anymore.
// We don't need the reference to the request anymore. We must also set
// deferCanceled to null in order to free any indirect references it
// may hold to the request.
this.request = null;
this.deferCanceled = null;
// Allow the download to restart through a DownloadCopySaver.
this.firstExecutionFinished = true;
}
@ -2063,8 +2069,12 @@ this.DownloadLegacySaver.prototype = {
return this.copySaver.cancel.apply(this.copySaver, arguments);
}
// Cancel the operation as soon as the object is connected.
this.deferCanceled.resolve();
// If the download hasn't stopped already, resolve deferCanceled so that the
// operation is canceled as soon as a cancellation handler is registered.
// Note that the handler might not have been registered yet.
if (this.deferCanceled) {
this.deferCanceled.resolve();
}
},
/**

View File

@ -115,7 +115,8 @@ DownloadLegacyTransfer.prototype = {
// To handle asynchronous cancellation properly, we should hook up the
// handler only after we have been notified that the main request
// started. We will wait until the main request stopped before
// notifying that the download has been canceled.
// notifying that the download has been canceled. Since the request has
// not completed yet, deferCanceled is guaranteed to be set.
return download.saver.deferCanceled.promise.then(() => {
// Only cancel if the object executing the download is still running.
if (this._cancelable && !this._componentFailed) {
@ -239,11 +240,8 @@ DownloadLegacyTransfer.prototype = {
aDownload.tryToKeepPartialData = true;
}
// Start the download before allowing it to be controlled.
aDownload.start().then(null, function () {
// In case the operation failed, ensure we stop downloading data.
aDownload.saver.deferCanceled.resolve();
});
// Start the download before allowing it to be controlled. Ignore errors.
aDownload.start().then(null, () => {});
// Start processing all the other events received through nsITransfer.
this._deferDownload.resolve(aDownload);