From e501512494a477922250d162d615f5f1264c5ca7 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Tue, 7 Aug 2012 09:48:44 -0700 Subject: [PATCH] Bug 776677 - Fire notifications when webapp installs throw errors. r=fabrice --- dom/apps/src/Webapps.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/dom/apps/src/Webapps.js b/dom/apps/src/Webapps.js index 775ef148941..c87faac2f60 100644 --- a/dom/apps/src/Webapps.js +++ b/dom/apps/src/Webapps.js @@ -58,6 +58,14 @@ WebappsRegistry.prototype = { mgmt: 'r' }, + /* Fires errors on the request object. Also fires a notification if preventDefault was + * not called on the event + */ + _fireError: function fireError(aRequest, aError, aTopic) { + if (!Services.DOMRequest.fireError(aRequest, aError)) + Services.obs.notifyObservers(this, aTopic, aError); + }, + /** from https://developer.mozilla.org/en/OpenWebApps/The_Manifest * only the name property is mandatory */ @@ -87,7 +95,7 @@ WebappsRegistry.prototype = { app.installOrigin, app.installTime)); break; case "Webapps:Install:Return:KO": - Services.DOMRequest.fireError(req, msg.error || "DENIED"); + this._fireError(req, msg.error || "DENIED", "webapps-install-error"); break; case "Webapps:GetSelf:Return:OK": if (msg.apps.length) { @@ -132,7 +140,7 @@ WebappsRegistry.prototype = { try { let manifest = JSON.parse(xhr.responseText, installOrigin); if (!this.checkManifest(manifest, installOrigin)) { - Services.DOMRequest.fireError(request, "INVALID_MANIFEST"); + this._fireError(request, "INVALID_MANIFEST", "webapps-install-error"); } else { let receipts = (aParams && aParams.receipts && Array.isArray(aParams.receipts)) ? aParams.receipts : []; let categories = (aParams && aParams.categories && Array.isArray(aParams.categories)) ? aParams.categories : []; @@ -147,16 +155,16 @@ WebappsRegistry.prototype = { requestID: requestID }); } } catch(e) { - Services.DOMRequest.fireError(request, "MANIFEST_PARSE_ERROR"); + this._fireError(request, "MANIFEST_PARSE_ERROR", "webapps-install-error"); } } else { - Services.DOMRequest.fireError(request, "MANIFEST_URL_ERROR"); + this._fireError(request, "MANIFEST_URL_ERROR", "webapps-install-error"); } }).bind(this), false); xhr.addEventListener("error", (function() { - Services.DOMRequest.fireError(request, "NETWORK_ERROR"); + this._fireError(request, "NETWORK_ERROR", "webapps-install-error"); }).bind(this), false); xhr.send(null);