From fb55ba5754e397344493ed5ab27f853acd753759 Mon Sep 17 00:00:00 2001 From: Yuan Xulei Date: Wed, 11 Sep 2013 14:15:48 +0200 Subject: [PATCH] Bug 912340 - Add the manifest's 'role' property to mozIApplication. r=fabrice --HG-- extra : rebase_source : 1b816681777578222c30d0184a865cf68e2c8efb --- dom/apps/src/AppsUtils.jsm | 9 +++++++++ dom/apps/src/Webapps.jsm | 11 ++++++++++- dom/interfaces/apps/mozIApplication.idl | 5 ++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/dom/apps/src/AppsUtils.jsm b/dom/apps/src/AppsUtils.jsm index 4ab81234fed0..4882cb8d5d24 100644 --- a/dom/apps/src/AppsUtils.jsm +++ b/dom/apps/src/AppsUtils.jsm @@ -93,6 +93,7 @@ this.AppsUtils = { installerIsBrowser: !!aApp.installerIsBrowser, storeId: aApp.storeId || "", storeVersion: aApp.storeVersion || 0, + role: aApp.role || "", redirects: aApp.redirects }; }, @@ -320,6 +321,10 @@ this.AppsUtils = { } } + // The 'role' field must be a string. + if (aManifest.role && (typeof aManifest.role !== "string")) { + return false; + } return true; }, @@ -639,5 +644,9 @@ ManifestHelper.prototype = { fullPackagePath: function() { let packagePath = this._localeProp("package_path"); return this._origin.resolve(packagePath ? packagePath : ""); + }, + + get role() { + return this._manifest.role || ""; } } diff --git a/dom/apps/src/Webapps.jsm b/dom/apps/src/Webapps.jsm index 0f5a8382f5aa..cec1ea66c205 100644 --- a/dom/apps/src/Webapps.jsm +++ b/dom/apps/src/Webapps.jsm @@ -190,6 +190,11 @@ this.DOMApplicationRegistry = { this.webapps[id].storeVersion = 0; } + // Default role to "". + if (this.webapps[id].role === undefined) { + this.webapps[id].role = ""; + } + // At startup we can't be downloading, and the $TMP directory // will be empty so we can't just apply a staged update. app.downloading = false; @@ -242,13 +247,14 @@ this.DOMApplicationRegistry = { if (supportSystemMessages()) { this._processManifestForIds(ids, aRunUpdate); } else { - // Read the CSPs. If MOZ_SYS_MSG is defined this is done on + // Read the CSPs and roles. If MOZ_SYS_MSG is defined this is done on // _processManifestForIds so as to not reading the manifests // twice this._readManifests(ids, (function readCSPs(aResults) { aResults.forEach(function registerManifest(aResult) { let app = this.webapps[aResult.id]; app.csp = aResult.manifest.csp || ""; + app.role = aResult.manifest.role || ""; if (app.appStatus >= Ci.nsIPrincipal.APP_STATUS_PRIVILEGED) { app.redirects = this.sanitizeRedirects(aResult.redirects); } @@ -734,6 +740,7 @@ this.DOMApplicationRegistry = { let manifest = aResult.manifest; app.name = manifest.name; app.csp = manifest.csp || ""; + app.role = manifest.role || ""; if (app.appStatus >= Ci.nsIPrincipal.APP_STATUS_PRIVILEGED) { app.redirects = this.sanitizeRedirects(manifest.redirects); } @@ -1477,6 +1484,7 @@ this.DOMApplicationRegistry = { app.name = manifest.name; app.csp = manifest.csp || ""; + app.role = manifest.role || ""; app.updateTime = Date.now(); } else { manifest = new ManifestHelper(aOldManifest, app.origin); @@ -2057,6 +2065,7 @@ this.DOMApplicationRegistry = { appObject.name = manifest.name; appObject.csp = manifest.csp || ""; + appObject.role = manifest.role || ""; appObject.installerAppId = aData.appId; appObject.installerIsBrowser = aData.isBrowser; diff --git a/dom/interfaces/apps/mozIApplication.idl b/dom/interfaces/apps/mozIApplication.idl index 458f59713300..8438e769b1aa 100644 --- a/dom/interfaces/apps/mozIApplication.idl +++ b/dom/interfaces/apps/mozIApplication.idl @@ -11,7 +11,7 @@ * We expose Gecko-internal helpers related to "web apps" through this * sub-interface. */ -[scriptable, uuid(05c57885-27cf-47fc-8da7-eeec9eb853a7)] +[scriptable, uuid(11322d0c-e98e-442d-97a6-8b197d5b888e)] interface mozIApplication: mozIDOMApplication { /* Return true if this app has |permission|. */ @@ -40,4 +40,7 @@ interface mozIApplication: mozIDOMApplication /* Store version if the app is installed from a store */ readonly attribute unsigned long storeVersion; + + /* role copied from the manifest */ + readonly attribute DOMString role; };