mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-24 05:44:10 +00:00
Bug 927699 - navigator.mozApps.install(url) lets NS_ERROR_FAILURE onto the web. r=fabrice
This commit is contained in:
parent
7bcf047f5b
commit
da35ee5548
@ -79,27 +79,28 @@ WebappsRegistry.prototype = {
|
||||
return uri.prePath;
|
||||
},
|
||||
|
||||
_validateURL: function(aURL) {
|
||||
// Checks that the URL scheme is appropriate (http or https) and
|
||||
// asynchronously fire an error on the DOM Request if it isn't.
|
||||
_validateURL: function(aURL, aRequest) {
|
||||
let uri;
|
||||
let res;
|
||||
|
||||
try {
|
||||
uri = Services.io.newURI(aURL, null, null);
|
||||
if (uri.schemeIs("http") || uri.schemeIs("https")) {
|
||||
res = uri.spec;
|
||||
}
|
||||
} catch(e) {
|
||||
throw new Components.Exception(
|
||||
"INVALID_URL: '" + aURL + "'", Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
Services.DOMRequest.fireErrorAsync(aRequest, "INVALID_URL");
|
||||
return false;
|
||||
}
|
||||
|
||||
// The scheme is incorrect, throw an exception.
|
||||
// The scheme is incorrect, fire DOMRequest error.
|
||||
if (!res) {
|
||||
throw new Components.Exception(
|
||||
"INVALID_URL_SCHEME: '" + uri.scheme + "'; must be 'http' or 'https'",
|
||||
Cr.NS_ERROR_FAILURE
|
||||
);
|
||||
Services.DOMRequest.fireErrorAsync(aRequest, "INVALID_URL");
|
||||
return false;
|
||||
}
|
||||
|
||||
return uri.spec;
|
||||
},
|
||||
|
||||
@ -113,13 +114,7 @@ WebappsRegistry.prototype = {
|
||||
return true;
|
||||
}
|
||||
|
||||
let runnable = {
|
||||
run: function run() {
|
||||
Services.DOMRequest.fireError(aRequest, "BACKGROUND_APP");
|
||||
}
|
||||
}
|
||||
Services.tm.currentThread.dispatch(runnable,
|
||||
Ci.nsIThread.DISPATCH_NORMAL);
|
||||
Services.DOMRequest.fireErrorAsync(aRequest, "BACKGROUND_APP");
|
||||
return false;
|
||||
},
|
||||
|
||||
@ -155,11 +150,11 @@ WebappsRegistry.prototype = {
|
||||
// mozIDOMApplicationRegistry implementation
|
||||
|
||||
install: function(aURL, aParams) {
|
||||
let uri = this._validateURL(aURL);
|
||||
|
||||
let request = this.createRequest();
|
||||
|
||||
if (this._ensureForeground(request)) {
|
||||
let uri = this._validateURL(aURL, request);
|
||||
|
||||
if (uri && this._ensureForeground(request)) {
|
||||
this.addMessageListeners("Webapps:Install:Return:KO");
|
||||
cpmm.sendAsyncMessage("Webapps:Install",
|
||||
this._prepareInstall(uri, request, aParams, false));
|
||||
@ -218,11 +213,11 @@ WebappsRegistry.prototype = {
|
||||
},
|
||||
|
||||
installPackage: function(aURL, aParams) {
|
||||
let uri = this._validateURL(aURL);
|
||||
|
||||
let request = this.createRequest();
|
||||
|
||||
if (this._ensureForeground(request)) {
|
||||
let uri = this._validateURL(aURL, request);
|
||||
|
||||
if (uri && this._ensureForeground(request)) {
|
||||
this.addMessageListeners("Webapps:Install:Return:KO");
|
||||
cpmm.sendAsyncMessage("Webapps:InstallPackage",
|
||||
this._prepareInstall(uri, request, aParams, true));
|
||||
@ -471,13 +466,7 @@ WebappsApplication.prototype = {
|
||||
requestID: this.getRequestId(request) }
|
||||
);
|
||||
} else {
|
||||
let runnable = {
|
||||
run: function run() {
|
||||
Services.DOMRequest.fireError(request, "NO_CLEARABLE_BROWSER");
|
||||
}
|
||||
}
|
||||
Services.tm.currentThread.dispatch(runnable,
|
||||
Ci.nsIThread.DISPATCH_NORMAL);
|
||||
Services.DOMRequest.fireErrorAsync(request, "NO_CLEARABLE_BROWSER");
|
||||
}
|
||||
return request;
|
||||
},
|
||||
@ -751,7 +740,7 @@ WebappsApplicationMgmt.prototype = {
|
||||
var msg = aMessage.json;
|
||||
let req = this.getRequest(msg.requestID);
|
||||
// We want Webapps:Install:Return:OK and Webapps:Uninstall:Broadcast:Return:OK
|
||||
// to be boradcasted to all instances of mozApps.mgmt.
|
||||
// to be broadcasted to all instances of mozApps.mgmt.
|
||||
if (!((msg.oid == this._id && req) ||
|
||||
aMessage.name == "Webapps:Install:Return:OK" ||
|
||||
aMessage.name == "Webapps:Uninstall:Broadcast:Return:OK")) {
|
||||
|
@ -56,6 +56,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=826058
|
||||
launchableValue = SpecialPowers.setAllAppsLaunchable(true);
|
||||
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
|
||||
|
||||
// Test Bug 927699 - navigator.mozApps.install(url) lets NS_ERROR_FAILURE
|
||||
// onto the web
|
||||
var request = navigator.mozApps.install("");
|
||||
request.onerror = function() {
|
||||
ok(request.error.name == "INVALID_URL", "Got expected INVALID_URL");
|
||||
continueTest();
|
||||
};
|
||||
request.onsuccess = mozAppsError;
|
||||
yield undefined;
|
||||
|
||||
setAppVersion(1, continueTest);
|
||||
yield undefined;
|
||||
SpecialPowers.autoConfirmAppInstall(continueTest);
|
||||
@ -69,7 +79,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=826058
|
||||
setAppVersion(2, continueTest);
|
||||
yield undefined;
|
||||
|
||||
var request = navigator.mozApps.install(gHostedManifestURL);
|
||||
request = navigator.mozApps.install(gHostedManifestURL);
|
||||
request.onerror = mozAppsError;
|
||||
request.onsuccess = continueTest;
|
||||
yield undefined;
|
||||
|
@ -94,6 +94,12 @@ var steps = [
|
||||
function() {
|
||||
PackagedTestHelper.setAppVersion(0, PackagedTestHelper.next);
|
||||
},
|
||||
function() {
|
||||
// Bug 927699 - navigator.mozApps.install(url) lets NS_ERROR_FAILURE onto
|
||||
// the web.
|
||||
ok(true, "== TEST == INVALID_URL");
|
||||
checkAppInstallError("", "INVALID_URL");
|
||||
},
|
||||
function() {
|
||||
// Test network error.
|
||||
ok(true, "== TEST == Network error");
|
||||
|
@ -168,20 +168,27 @@ function invalidMessage(next) {
|
||||
|
||||
function fileURL(next) {
|
||||
try {
|
||||
navigator.mozApps.install("file:///nonexistent");
|
||||
ok(false,
|
||||
"attempt to install nonexistent file: URL doesn't throw exception");
|
||||
var req = navigator.mozApps.install("file:///nonexistent");
|
||||
req.onsuccess = function() {
|
||||
ok(false, "Unexpected success installing non existent file");
|
||||
};
|
||||
req.onerror = function() {
|
||||
is(this.error.name, "INVALID_URL", "Expected INVALID_URL");
|
||||
};
|
||||
} catch(ex) {
|
||||
is(ex.message, "INVALID_URL_SCHEME: 'file'; must be 'http' or 'https'",
|
||||
"attempt to install nonexistent file: URL throws exception");
|
||||
ok(false, "Unexpected exception " + ex.message);
|
||||
}
|
||||
|
||||
try {
|
||||
navigator.mozApps.install("file:///");
|
||||
ok(false, "attempt to install existent file: URL doesn't throw exception");
|
||||
req = navigator.mozApps.install("file:///");
|
||||
req.onsuccess = function() {
|
||||
ok(false, "Unexpected success installing file: URL");
|
||||
};
|
||||
req.onerror = function() {
|
||||
is(this.error.name, "INVALID_URL", "Expected INVALID_URL");
|
||||
};
|
||||
} catch(ex) {
|
||||
is(ex.message, "INVALID_URL_SCHEME: 'file'; must be 'http' or 'https'",
|
||||
"attempt to install existent file: URL throws exception");
|
||||
ok(false, "Unexpected exception " + ex.message);
|
||||
}
|
||||
|
||||
next();
|
||||
|
Loading…
x
Reference in New Issue
Block a user