Bug 779935 - nsIAppsService.idl need to get mozIDOMApplication from manifest id [r=mounir]

This commit is contained in:
Fabrice Desré 2012-08-08 09:41:47 -07:00
parent a7aac6193b
commit f8f53af964
3 changed files with 61 additions and 2 deletions

View File

@ -53,6 +53,26 @@ AppsService.prototype = {
} }
}, },
getAppByLocalId: function getAppByLocalId(aLocalId) {
debug("getAppByLocalId( " + aLocalId + " )");
if (this.inParent) {
return DOMApplicationRegistry.getAppByLocalId(aLocalId);
} else {
return this.cpmm.sendSyncMessage("WebApps:GetAppByLocalId",
{ id: aLocalId })[0];
}
},
getManifestURLByLocalId: function getManifestURLByLocalId(aLocalId) {
debug("getManifestURLByLocalId( " + aLocalId + " )");
if (this.inParent) {
return DOMApplicationRegistry.getManifestURLByLocalId(aLocalId);
} else {
return this.cpmm.sendSyncMessage("WebApps:GetManifestURLByLocalId",
{ id: aLocalId })[0];
}
},
classID : APPS_SERVICE_CID, classID : APPS_SERVICE_CID,
QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService]) QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService])
} }

View File

@ -57,7 +57,8 @@ let DOMApplicationRegistry = {
"Webapps:GetInstalled", "Webapps:GetNotInstalled", "Webapps:GetInstalled", "Webapps:GetNotInstalled",
"Webapps:Launch", "Webapps:GetAll", "Webapps:Launch", "Webapps:GetAll",
"Webapps:InstallPackage", "Webapps:GetBasePath", "Webapps:InstallPackage", "Webapps:GetBasePath",
"WebApps:GetAppByManifestURL", "WebApps:GetAppLocalIdByManifestURL"]; "WebApps:GetAppByManifestURL", "WebApps:GetAppLocalIdByManifestURL",
"WebApps:GetAppByLocalId", "Webapps:GetManifestURLByLocalId"];
this.messages.forEach((function(msgName) { this.messages.forEach((function(msgName) {
ppmm.addMessageListener(msgName, this); ppmm.addMessageListener(msgName, this);
@ -249,6 +250,12 @@ let DOMApplicationRegistry = {
case "WebApps:GetAppLocalIdByManifestURL": case "WebApps:GetAppLocalIdByManifestURL":
return { id: this.getAppLocalIdByManifestURL(msg.url) }; return { id: this.getAppLocalIdByManifestURL(msg.url) };
break; break;
case "WebApps:GetAppByLocalId":
return this.getAppByLocalId(msg.id);
break;
case "WebApps:GetManifestURLByLocalId":
return this.getManifestURLByLocalId(msg.id);
break;
} }
}, },
@ -698,6 +705,28 @@ let DOMApplicationRegistry = {
return null; return null;
}, },
getAppByLocalId: function(aLocalId) {
for (let id in this.webapps) {
let app = this.webapps[id];
if (app.localId == aLocalId) {
return this._cloneAppObject(app);
}
}
return null;
},
getManifestURLByLocalId: function(aLocalId) {
for (let id in this.webapps) {
let app = this.webapps[id];
if (app.localId == aLocalId) {
return app.manifestURL;
}
}
return null;
},
getAppLocalIdByManifestURL: function(aManifestURL) { getAppLocalIdByManifestURL: function(aManifestURL) {
for (let id in this.webapps) { for (let id in this.webapps) {
if (this.webapps[id].manifestURL == aManifestURL) { if (this.webapps[id].manifestURL == aManifestURL) {

View File

@ -15,7 +15,7 @@ interface mozIDOMApplication;
* This service allows accessing some DOMApplicationRegistry methods from * This service allows accessing some DOMApplicationRegistry methods from
* non-javascript code. * non-javascript code.
*/ */
[scriptable, uuid(1210a0f3-add3-4381-b892-9c102e3afc42)] [scriptable, uuid(04e4ef3c-1a30-45bc-ab08-291820f13872)]
interface nsIAppsService : nsISupports interface nsIAppsService : nsISupports
{ {
mozIDOMApplication getAppByManifestURL(in DOMString manifestURL); mozIDOMApplication getAppByManifestURL(in DOMString manifestURL);
@ -27,4 +27,14 @@ interface nsIAppsService : nsISupports
* installed manifest URL. * installed manifest URL.
*/ */
unsigned long getAppLocalIdByManifestURL(in DOMString manifestURL); unsigned long getAppLocalIdByManifestURL(in DOMString manifestURL);
/**
* Returns the application associated to this localId.
*/
mozIDOMApplication getAppByLocalId(in unsigned long localId);
/**
* Returns the manifest URL associated to this localId.
*/
DOMString getManifestURLByLocalId(in unsigned long localId);
}; };