From 8fba853f1ed0f94bd5af6d5dd3fec5b37223e373 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Tue, 24 Jun 2014 00:40:56 +0200 Subject: [PATCH] Bug 922187 - Properly catch exceptions in checkInstalled and fire the error callback on the DOM request. r=myk --- dom/apps/src/Webapps.js | 9 ++++++++- dom/tests/mochitest/webapps/file_bug_779982.html | 13 +++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dom/apps/src/Webapps.js b/dom/apps/src/Webapps.js index 69f0f199d137..98aaf4219a09 100644 --- a/dom/apps/src/Webapps.js +++ b/dom/apps/src/Webapps.js @@ -181,10 +181,17 @@ WebappsRegistry.prototype = { checkInstalled: function(aManifestURL) { let manifestURL = Services.io.newURI(aManifestURL, null, this._window.document.baseURIObject); - this._window.document.nodePrincipal.checkMayLoad(manifestURL, true, false); let request = this.createRequest(); + try { + this._window.document.nodePrincipal.checkMayLoad(manifestURL, true, + false); + } catch (ex) { + Services.DOMRequest.fireErrorAsync(request, "CROSS_ORIGIN_CHECK_NOT_ALLOWED"); + return request; + } + this.addMessageListeners("Webapps:CheckInstalled:Return:OK"); cpmm.sendAsyncMessage("Webapps:CheckInstalled", { origin: this._getOrigin(this._window.location.href), manifestURL: manifestURL.spec, diff --git a/dom/tests/mochitest/webapps/file_bug_779982.html b/dom/tests/mochitest/webapps/file_bug_779982.html index 12c7a0b6dbc5..4fe6d1a7c793 100644 --- a/dom/tests/mochitest/webapps/file_bug_779982.html +++ b/dom/tests/mochitest/webapps/file_bug_779982.html @@ -34,11 +34,16 @@ break; case "checkInstalledWrong": - try { - navigator.mozApps.checkInstalled('http://something.org/manifest.webapp'); + var request = navigator.mozApps.checkInstalled('http://something.org/manifest.webapp'); + request.onsuccess = function() { finish(false); - } catch (e) { - finish(true); + } + request.onerror = function() { + if (this.error.name == "CROSS_ORIGIN_URL_NOT_ALLOWED") { + finish(true); + } else { + finish(false); + } } break;