Bug 794102 - checkInstalled should return an app object. r=felipc

This commit is contained in:
Andrea Marchesini 2012-10-02 16:38:51 -04:00
parent 5eca5b886d
commit 930c405ed4
7 changed files with 42 additions and 34 deletions

View File

@ -65,8 +65,8 @@ WebappsRegistry.prototype = {
Services.DOMRequest.fireSuccess(req, null);
}
break;
case "Webapps:IsInstalled:Return:OK":
Services.DOMRequest.fireSuccess(req, msg.installed);
case "Webapps:CheckInstalled:Return:OK":
Services.DOMRequest.fireSuccess(req, msg.app);
break;
case "Webapps:GetInstalled:Return:OK":
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
@ -159,15 +159,15 @@ WebappsRegistry.prototype = {
return request;
},
isInstalled: function(aManifestURL) {
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();
cpmm.sendAsyncMessage("Webapps:IsInstalled", { origin: this._getOrigin(this._window.location.href),
manifestURL: manifestURL.spec,
oid: this._id,
requestID: this.getRequestId(request) });
cpmm.sendAsyncMessage("Webapps:CheckInstalled", { origin: this._getOrigin(this._window.location.href),
manifestURL: manifestURL.spec,
oid: this._id,
requestID: this.getRequestId(request) });
return request;
},
@ -259,7 +259,7 @@ WebappsRegistry.prototype = {
this.initHelper(aWindow, ["Webapps:Install:Return:OK", "Webapps:Install:Return:KO",
"Webapps:GetInstalled:Return:OK",
"Webapps:GetSelf:Return:OK",
"Webapps:IsInstalled:Return:OK" ]);
"Webapps:CheckInstalled:Return:OK" ]);
let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
this._id = util.outerWindowID;

View File

@ -154,7 +154,7 @@ let DOMApplicationRegistry = {
init: function() {
this.messages = ["Webapps:Install", "Webapps:Uninstall",
"Webapps:GetSelf", "Webapps:IsInstalled",
"Webapps:GetSelf", "Webapps:CheckInstalled",
"Webapps:GetInstalled", "Webapps:GetNotInstalled",
"Webapps:Launch", "Webapps:GetAll",
"Webapps:InstallPackage", "Webapps:GetBasePath",
@ -561,8 +561,8 @@ let DOMApplicationRegistry = {
case "Webapps:Launch":
this.launchApp(msg, mm);
break;
case "Webapps:IsInstalled":
this.isInstalled(msg, mm);
case "Webapps:CheckInstalled":
this.checkInstalled(msg, mm);
break;
case "Webapps:GetInstalled":
this.getInstalled(msg, mm);
@ -1454,17 +1454,25 @@ let DOMApplicationRegistry = {
}).bind(this));
},
isInstalled: function(aData, aMm) {
aData.installed = false;
checkInstalled: function(aData, aMm) {
aData.app = null;
let tmp = [];
for (let appId in this.webapps) {
if (this.webapps[appId].manifestURL == aData.manifestURL) {
aData.installed = true;
aData.app = AppsUtils.cloneAppObject(this.webapps[appId]);
tmp.push({ id: appId });
break;
}
}
aMm.sendAsyncMessage("Webapps:IsInstalled:Return:OK", aData);
this._readManifests(tmp, (function(aResult) {
for (let i = 0; i < aResult.length; i++) {
aData.app.manifest = aResult[i].manifest;
break;
}
aMm.sendAsyncMessage("Webapps:CheckInstalled:Return:OK", aData);
}).bind(this));
},
getInstalled: function(aData, aMm) {

View File

@ -122,7 +122,7 @@ interface mozIDOMApplicationMgmt : nsISupports
void applyDownload(in mozIDOMApplication app);
};
[scriptable, uuid(7ca34d3e-d855-4d0a-a3b3-58c0acad9ec3)]
[scriptable, uuid(abfc6c15-8b92-4b9a-b892-52e6ae76f379)]
interface mozIDOMApplicationRegistry : nsISupports
{
/**
@ -144,9 +144,9 @@ interface mozIDOMApplicationRegistry : nsISupports
nsIDOMDOMRequest getSelf();
/**
* the request will return true if the app from that origin is installed
* the request will return the application if the app from that origin is installed
*/
nsIDOMDOMRequest isInstalled(in DOMString manifestUrl);
nsIDOMDOMRequest checkInstalled(in DOMString manifestUrl);
/**
* the request will return the applications installed from this origin, or null.

View File

@ -23,19 +23,19 @@
}
break;
case "isInstalled":
navigator.mozApps.isInstalled('http://example.org/manifest.webapp').onsuccess = function onIsInstalled() {
case "checkInstalled":
navigator.mozApps.checkInstalled('http://example.org/manifest.webapp').onsuccess = function onCheckInstalled() {
if (data[1] == 'true') {
finish(this.result == false);
finish(!this.result);
} else {
finish(this.result == true);
finish(!!this.result);
}
}
break;
case "isInstalledWrong":
case "checkInstalledWrong":
try {
navigator.mozApps.isInstalled('http://something.org/manifest.webapp');
navigator.mozApps.checkInstalled('http://something.org/manifest.webapp');
finish(false);
} catch (e) {
finish(true);

View File

@ -46,17 +46,17 @@ var gData = [
},
{
app: 'http://example.org/manifest.webapp',
action: 'isInstalled',
action: 'checkInstalled',
isnull: false,
src: fileTestOnCurrentOrigin,
message: 'isInstalled() for app should return true'
message: 'checkInstalled() for app should return true'
},
{
app: 'http://example.org/manifest.webapp',
action: 'isInstalledWrong',
action: 'checkInstalledWrong',
isnull: true,
src: fileTestOnCurrentOrigin,
message: 'isInstalled() for browser should return true'
message: 'checkInstalled() for browser should return true'
},
// Browser
{
@ -68,17 +68,17 @@ var gData = [
},
{
browser: true,
action: 'isInstalled',
action: 'checkInstalled',
isnull: false,
src: fileTestOnCurrentOrigin,
message: 'isInstalled() for browser should return true'
message: 'checkInstalled() for browser should return true'
},
{
browser: true,
action: 'isInstalledWrong',
action: 'checkInstalledWrong',
isnull: true,
src: fileTestOnCurrentOrigin,
message: 'isInstalled() for browser should return true'
message: 'checkInstalled() for browser should return true'
},
];

View File

@ -4,7 +4,7 @@
https://bugzilla.mozilla.org/show_bug.cgi?id=779982
-->
<head>
<title>Test for getSelf()/isInstalled() in browser and in apps</title>
<title>Test for getSelf()/checkInstalled() in browser and in apps</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>

View File

@ -20,7 +20,7 @@
var props = {
QueryInterface: "function",
isInstalled: "function",
checkInstalled: "function",
getInstalled: "function",
getSelf: "function",
install: "function",