Bug 1095506 - Serialize the error object when saving to the store. r=paolo

We now serialize the Download.error property when saving to the store so
that data about error conditions will survive a restart. This is
important for supporting blocked downloads with partial data that could
be unblocked.

--HG--
extra : rebase_source : 40821e59e2b258803cde5da456cd9d0d20caa9e0
This commit is contained in:
Steven MacLeod 2014-11-07 10:00:24 -05:00
Родитель 2ad98eea62
Коммит 157484861d
1 изменённых файлов: 72 добавлений и 4 удалений

Просмотреть файл

@ -477,6 +477,16 @@ this.Download.prototype = {
// Update the download error, unless a new attempt already started. The
// change in the status property is notified in the finally block.
if (this._currentAttempt == currentAttempt || !this._currentAttempt) {
if (!(ex instanceof DownloadError)) {
let properties = {innerException: ex};
if (ex.message) {
properties.message = ex.message;
}
ex = new DownloadError(properties);
}
this.error = ex;
}
throw ex;
@ -910,8 +920,8 @@ this.Download.prototype = {
serializable.saver = saver;
}
if (this.error && ("message" in this.error)) {
serializable.error = { message: this.error.message };
if (this.error) {
serializable.errorObj = this.error.toSerializable();
}
if (this.startTime) {
@ -920,7 +930,7 @@ this.Download.prototype = {
// These are serialized unless they are false, null, or empty strings.
for (let property of kSerializableDownloadProperties) {
if (property != "error" && property != "startTime" && this[property]) {
if (property != "startTime" && this[property]) {
serializable[property] = this[property];
}
}
@ -956,7 +966,6 @@ this.Download.prototype = {
const kSerializableDownloadProperties = [
"succeeded",
"canceled",
"error",
"totalBytes",
"hasPartialData",
"tryToKeepPartialData",
@ -1011,6 +1020,10 @@ Download.fromSerializable = function (aSerializable) {
download.startTime = new Date(time);
}
if ("errorObj" in aSerializable) {
download.error = DownloadError.fromSerializable(aSerializable.errorObj);
}
for (let property of kSerializableDownloadProperties) {
if (property in aSerializable) {
download[property] = aSerializable[property];
@ -1022,6 +1035,7 @@ Download.fromSerializable = function (aSerializable) {
property != "startTime" &&
property != "source" &&
property != "target" &&
property != "error" &&
property != "saver");
return download;
@ -1263,6 +1277,10 @@ this.DownloadError = function (aProperties)
this.becauseBlocked = true;
}
if (aProperties.innerException) {
this.innerException = aProperties.innerException;
}
this.stack = new Error().stack;
}
@ -1301,6 +1319,56 @@ this.DownloadError.prototype = {
* and may be malware.
*/
becauseBlockedByReputationCheck: false,
/**
* If this DownloadError was caused by an exception this property will
* contain the original exception. This will not be serialized when saving
* to the store.
*/
innerException: null,
/**
* Returns a static representation of the current object state.
*
* @return A JavaScript object that can be serialized to JSON.
*/
toSerializable: function ()
{
let serializable = {
result: this.result,
message: this.message,
becauseSourceFailed: this.becauseSourceFailed,
becauseTargetFailed: this.becauseTargetFailed,
becauseBlocked: this.becauseBlocked,
becauseBlockedByParentalControls: this.becauseBlockedByParentalControls,
becauseBlockedByReputationCheck: this.becauseBlockedByReputationCheck,
};
serializeUnknownProperties(this, serializable);
return serializable;
},
};
/**
* Creates a new DownloadError object from its serializable representation.
*
* @param aSerializable
* Serializable representation of a DownloadError object.
*
* @return The newly created DownloadError object.
*/
this.DownloadError.fromSerializable = function (aSerializable) {
let e = new DownloadError(aSerializable);
deserializeUnknownProperties(e, aSerializable, property =>
property != "result" &&
property != "message" &&
property != "becauseSourceFailed" &&
property != "becauseTargetFailed" &&
property != "becauseBlocked" &&
property != "becauseBlockedByParentalControls" &&
property != "becauseBlockedByReputationCheck");
return e;
};
////////////////////////////////////////////////////////////////////////////////