From 6638204722832d546deee9f7efd72e5a388f9022 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 11 Sep 2013 18:13:46 -0500 Subject: [PATCH] Bug 915067 - Part 2: Filter certified apps from webapps actor. r=ochameau --- toolkit/devtools/server/actors/webapps.js | 121 ++++++++++++++++------ 1 file changed, 92 insertions(+), 29 deletions(-) diff --git a/toolkit/devtools/server/actors/webapps.js b/toolkit/devtools/server/actors/webapps.js index b00821b51a11..1e19f6cac131 100644 --- a/toolkit/devtools/server/actors/webapps.js +++ b/toolkit/devtools/server/actors/webapps.js @@ -500,13 +500,36 @@ WebappsActor.prototype = { let defer = promise.defer(); let reg = DOMApplicationRegistry; - reg.getAll(function onsuccess(apps) { - defer.resolve({ apps: apps }); + reg.getAll(apps => { + defer.resolve({ apps: this._filterAllowedApps(apps) }); }); return defer.promise; }, + _areCertifiedAppsAllowed: function wa__areCertifiedAppsAllowed() { + let pref = "devtools.debugger.forbid-certified-apps"; + return !Services.prefs.getBoolPref(pref); + }, + + _isAppAllowedForManifest: function wa__isAppAllowedForManifest(aManifest) { + if (this._areCertifiedAppsAllowed()) { + return true; + } + let type = this._getAppType(aManifest.type); + return type !== Ci.nsIPrincipal.APP_STATUS_CERTIFIED; + }, + + _filterAllowedApps: function wa__filterAllowedApps(aApps) { + return aApps.filter(app => this._isAppAllowedForManifest(app.manifest)); + }, + + _isAppAllowedForURL: function wa__isAppAllowedForURL(aManifestURL) { + return this._findManifestByURL(aManifestURL).then(manifest => { + return this._isAppAllowedForManifest(manifest); + }); + }, + uninstall: function wa_actorUninstall(aRequest) { debug("uninstall"); @@ -531,6 +554,19 @@ WebappsActor.prototype = { return defer.promise; }, + _findManifestByURL: function wa__findManifestByURL(aManifestURL) { + let deferred = promise.defer(); + + let reg = DOMApplicationRegistry; + let id = reg._appIdForManifestURL(aManifestURL); + + reg._readManifests([{ id: id }], function (aResults) { + deferred.resolve(aResults[0].manifest); + }); + + return deferred.promise; + }, + getIconAsDataURL: function (aRequest) { debug("getIconAsDataURL"); @@ -549,9 +585,7 @@ WebappsActor.prototype = { let deferred = promise.defer(); - let id = reg._appIdForManifestURL(manifestURL); - reg._readManifests([{ id: id }], function (aResults) { - let jsonManifest = aResults[0].manifest; + this._findManifestByURL(manifestURL).then(jsonManifest => { let manifest = new ManifestHelper(jsonManifest, app.origin); let iconURL = manifest.iconURLForSize(aRequest.size || 128); if (!iconURL) { @@ -665,14 +699,22 @@ WebappsActor.prototype = { listRunningApps: function (aRequest) { debug("listRunningApps\n"); + let appPromises = []; let apps = []; for each (let frame in this._appFrames()) { let manifestURL = frame.getAttribute("mozapp"); - apps.push(manifestURL); + + appPromises.push(this._isAppAllowedForURL(manifestURL).then(allowed => { + if (allowed) { + apps.push(manifestURL); + } + })); } - return { apps: apps }; + return promise.all(appPromises).then(() => { + return { apps: apps }; + }); }, _connectToApp: function (aFrame) { @@ -745,24 +787,34 @@ WebappsActor.prototype = { } } + let notFoundError = { + error: "appNotFound", + message: "Unable to find any opened app whose manifest " + + "is '" + manifestURL + "'" + }; + if (!appFrame) { - return { error: "appNotFound", - message: "Unable to find any opened app whose manifest " + - "is '" + manifestURL + "'" }; + return notFoundError; } - // Only create a new actor, if we haven't already - // instanciated one for this connection. - let mm = appFrame.QueryInterface(Ci.nsIFrameLoaderOwner) - .frameLoader - .messageManager; - let actor = this._appActorsMap.get(mm); - if (!actor) { - return this._connectToApp(appFrame) - .then(function (actor) ({ actor: actor })); - } + return this._isAppAllowedForURL(manifestURL).then(allowed => { + if (!allowed) { + return notFoundError; + } - return { actor: actor }; + // Only create a new actor, if we haven't already + // instanciated one for this connection. + let mm = appFrame.QueryInterface(Ci.nsIFrameLoaderOwner) + .frameLoader + .messageManager; + let actor = this._appActorsMap.get(mm); + if (!actor) { + return this._connectToApp(appFrame) + .then(function (actor) ({ actor: actor })); + } + + return { actor: actor }; + }); }, watchApps: function () { @@ -800,19 +852,30 @@ WebappsActor.prototype = { } this._openedApps.add(manifestURL); - this.conn.send({ from: this.actorID, - type: "appOpen", - manifestURL: manifestURL - }); + this._isAppAllowedForURL(manifestURL).then(allowed => { + if (allowed) { + this.conn.send({ from: this.actorID, + type: "appOpen", + manifestURL: manifestURL + }); + } + }); + break; case "appterminated": manifestURL = event.detail.manifestURL; this._openedApps.delete(manifestURL); - this.conn.send({ from: this.actorID, - type: "appClose", - manifestURL: manifestURL - }); + + this._isAppAllowedForURL(manifestURL).then(allowed => { + if (allowed) { + this.conn.send({ from: this.actorID, + type: "appClose", + manifestURL: manifestURL + }); + } + }); + break; } }