Bug 791943. r=fabrice

This commit is contained in:
Myk Melez 2012-09-24 22:41:21 -04:00
parent 597c61b068
commit 159114ff49
2 changed files with 36 additions and 0 deletions

View File

@ -80,9 +80,21 @@ WebappsRegistry.prototype = {
return uri.prePath;
},
_validateScheme: function(aURL) {
let scheme = Services.io.newURI(aURL, null, null).scheme;
if (scheme != "http" && scheme != "https") {
throw new Components.Exception(
"INVALID_URL_SCHEME: '" + scheme + "'; must be 'http' or 'https'",
Cr.NS_ERROR_FAILURE
);
}
},
// mozIDOMApplicationRegistry implementation
install: function(aURL, aParams) {
this._validateScheme(aURL);
let installURL = this._window.location.href;
let installOrigin = this._getOrigin(installURL);
let request = this.createRequest();
@ -162,6 +174,8 @@ WebappsRegistry.prototype = {
// mozIDOMApplicationRegistry2 implementation
installPackage: function(aPackageURL, aParams) {
this._validateScheme(aPackageURL);
let request = this.createRequest();
let requestID = this.getRequestId(request);

View File

@ -28,6 +28,7 @@ var steps = [
invalidLaunchPath,
invalidEntryPoint,
invalidLocaleEntryPoint,
fileURL,
];
runAll(steps);
@ -136,5 +137,26 @@ function installPackageNotImplemented(next) {
next();
}
function fileURL(next) {
try {
navigator.mozApps.install("file:///nonexistent");
ok(false,
"attempt to install nonexistent file: URL doesn't throw exception");
} catch(ex) {
is(ex.message, "INVALID_URL_SCHEME: 'file'; must be 'http' or 'https'",
"attempt to install nonexistent file: URL throws exception");
}
try {
navigator.mozApps.install("file:///");
ok(false, "attempt to install existent file: URL doesn't throw exception");
} catch(ex) {
is(ex.message, "INVALID_URL_SCHEME: 'file'; must be 'http' or 'https'",
"attempt to install existent file: URL throws exception");
}
next();
}
</script>
</window>