Bug 768276. Part 3 - Implement mozApps.getNotInstalled. r=jst

This commit is contained in:
Felipe Gomes 2012-06-29 13:46:21 -07:00
parent 480edeec88
commit 4be4f50178
4 changed files with 45 additions and 4 deletions

View File

@ -53,6 +53,7 @@ WebappsRegistry.prototype = {
install: 'r',
getSelf: 'r',
getInstalled: 'r',
getNotInstalled: 'r',
mgmt: 'r'
},
@ -100,8 +101,10 @@ WebappsRegistry.prototype = {
case "Webapps:GetInstalled:Return:OK":
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
break;
case "Webapps:GetNotInstalled:Return:OK":
Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
break;
case "Webapps:GetSelf:Return:KO":
case "Webapps:GetInstalled:Return:KO":
Services.DOMRequest.fireError(req, "ERROR");
break;
}
@ -172,6 +175,14 @@ WebappsRegistry.prototype = {
return request;
},
getNotInstalled: function() {
let request = this.createRequest();
cpmm.sendAsyncMessage("Webapps:GetNotInstalled", { origin: this._getOrigin(this._window.location.href),
oid: this._id,
requestID: this.getRequestId(request) });
return request;
},
get mgmt() {
if (!this._mgmt)
this._mgmt = new WebappsApplicationMgmt(this._window);
@ -185,7 +196,7 @@ WebappsRegistry.prototype = {
// nsIDOMGlobalPropertyInitializer implementation
init: function(aWindow) {
this.initHelper(aWindow, ["Webapps:Install:Return:OK", "Webapps:Install:Return:KO",
"Webapps:GetInstalled:Return:OK", "Webapps:GetInstalled:Return:KO",
"Webapps:GetInstalled:Return:OK", "Webapps:GetNotInstalled:Return:OK",
"Webapps:GetSelf:Return:OK", "Webapps:GetSelf:Return:KO"]);
let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);

View File

@ -39,7 +39,8 @@ let DOMApplicationRegistry = {
init: function() {
this.messages = ["Webapps:Install", "Webapps:Uninstall",
"Webapps:GetSelf", "Webapps:GetInstalled",
"Webapps:GetSelf",
"Webapps:GetInstalled", "Webapps:GetNotInstalled",
"Webapps:Launch", "Webapps:GetAll"];
this.messages.forEach((function(msgName) {
@ -125,6 +126,9 @@ let DOMApplicationRegistry = {
case "Webapps:GetInstalled":
this.getInstalled(msg);
break;
case "Webapps:GetNotInstalled":
this.getNotInstalled(msg);
break;
case "Webapps:GetAll":
if (msg.hasPrivileges)
this.getAll(msg);
@ -329,6 +333,25 @@ let DOMApplicationRegistry = {
}).bind(this));
},
getNotInstalled: function(aData) {
aData.apps = [];
let tmp = [];
for (let id in this.webapps) {
if (this.webapps[id].installOrigin == aData.origin &&
!this._isLaunchable(aData.origin)) {
aData.apps.push(this._cloneAppObject(this.webapps[id]));
tmp.push({ id: id });
}
}
this._readManifests(tmp, (function(aResult) {
for (let i = 0; i < aResult.length; i++)
aData.apps[i].manifest = aResult[i].manifest;
ppmm.sendAsyncMessage("Webapps:GetNotInstalled:Return:OK", aData);
}).bind(this));
},
getAll: function(aData) {
aData.apps = [];
let tmp = [];

View File

@ -83,7 +83,7 @@ interface mozIDOMApplicationMgmt : nsISupports
attribute nsIDOMEventListener onuninstall;
};
[scriptable, uuid(f6929871-288b-4613-9a37-9a150760ac50)]
[scriptable, uuid(d7b0ff50-e667-4ed2-b996-0eb937763952)]
interface mozIDOMApplicationRegistry : nsISupports
{
/**
@ -106,5 +106,11 @@ interface mozIDOMApplicationRegistry : nsISupports
*/
nsIDOMDOMRequest getInstalled();
/**
* the request will return the applications acquired from this origin but which
* are not launchable (e.g. by not being natively installed), or null.
*/
nsIDOMDOMRequest getNotInstalled();
readonly attribute mozIDOMApplicationMgmt mgmt;
};

View File

@ -25,6 +25,7 @@
var expectedMethods = ['navigator.mozApps.QueryInterface',
'navigator.mozApps.getInstalled',
'navigator.mozApps.getNotInstalled',
'navigator.mozApps.getSelf',
'navigator.mozApps.install',
'navigator.mozApps.mgmt.QueryInterface',