diff --git a/dom/apps/src/Webapps.js b/dom/apps/src/Webapps.js index e4bf357018ef..72c354012a26 100644 --- a/dom/apps/src/Webapps.js +++ b/dom/apps/src/Webapps.js @@ -72,14 +72,23 @@ WebappsRegistry.prototype = { return uri.prePath; }, - _validateScheme: function(aURL) { - let scheme = Services.io.newURI(aURL, null, null).scheme; - if (scheme != "http" && scheme != "https") { + _validateURL: function(aURL) { + let uri; + try { + uri = Services.io.newURI(aURL, null, null); + let scheme = uri.scheme; + if (!uri.schemeIs("http") && !uri.schemeIs("https")) { + throw new Components.Exception( + "INVALID_URL_SCHEME: '" + scheme + "'; must be 'http' or 'https'", + Cr.NS_ERROR_FAILURE + ); + } + } catch(e) { throw new Components.Exception( - "INVALID_URL_SCHEME: '" + scheme + "'; must be 'http' or 'https'", - Cr.NS_ERROR_FAILURE + "INVALID_URL: '" + aURL, Cr.NS_ERROR_FAILURE ); } + return uri.spec; }, // Checks that we run as a foreground page, and fire an error on the @@ -105,14 +114,14 @@ WebappsRegistry.prototype = { // mozIDOMApplicationRegistry implementation install: function(aURL, aParams) { + let uri = this._validateURL(aURL); + let request = this.createRequest(); if (!this._ensureForeground(request)) { return request; } - this._validateScheme(aURL); - let installURL = this._window.location.href; let requestID = this.getRequestId(request); let receipts = (aParams && aParams.receipts && @@ -126,8 +135,8 @@ WebappsRegistry.prototype = { cpmm.sendAsyncMessage("Webapps:Install", { app: { installOrigin: this._getOrigin(installURL), - origin: this._getOrigin(aURL), - manifestURL: aURL, + origin: this._getOrigin(uri), + manifestURL: uri, receipts: receipts, categories: categories }, @@ -184,14 +193,14 @@ WebappsRegistry.prototype = { // mozIDOMApplicationRegistry2 implementation installPackage: function(aURL, aParams) { + let uri = this._validateURL(aURL); + let request = this.createRequest(); if (!this._ensureForeground(request)) { return request; } - this._validateScheme(aURL); - let installURL = this._window.location.href; let requestID = this.getRequestId(request); let receipts = (aParams && aParams.receipts && @@ -205,8 +214,8 @@ WebappsRegistry.prototype = { cpmm.sendAsyncMessage("Webapps:InstallPackage", { app: { installOrigin: this._getOrigin(installURL), - origin: this._getOrigin(aURL), - manifestURL: aURL, + origin: this._getOrigin(uri), + manifestURL: uri, receipts: receipts, categories: categories },