From 321f2d70e2263a111964346cfdf8e0d92762f66c Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Fri, 18 Jan 2013 19:10:47 -0800 Subject: [PATCH] Back out fdeb0c833138 (bug 814226) for Linux bc failures in browser_webapps_permissions.js CLOSED TREE --- dom/apps/src/Webapps.js | 38 +++++++++++++++++++++----------------- dom/apps/src/Webapps.jsm | 5 ++++- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/dom/apps/src/Webapps.js b/dom/apps/src/Webapps.js index 32fb045d44ef..aef8887d4d07 100644 --- a/dom/apps/src/Webapps.js +++ b/dom/apps/src/Webapps.js @@ -184,10 +184,6 @@ WebappsRegistry.prototype = { }, get mgmt() { - if (!this.hasMgmtPrivilege) { - return null; - } - if (!this._mgmt) this._mgmt = new WebappsApplicationMgmt(this._window); return this._mgmt; @@ -245,19 +241,10 @@ WebappsRegistry.prototype = { "Webapps:GetSelf:Return:OK", "Webapps:CheckInstalled:Return:OK" ]); - let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindowUtils); + let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils); this._id = util.outerWindowID; cpmm.sendAsyncMessage("Webapps:RegisterForMessages", ["Webapps:Install:Return:OK"]); - - let principal = aWindow.document.nodePrincipal; - let perm = Services.perms - .testExactPermissionFromPrincipal(principal, "webapps-manage"); - - // Only pages with the webapps-manage permission set can get access to - // the mgmt object. - this.hasMgmtPrivilege = perm == Ci.nsIPermissionManager.ALLOW_ACTION; }, classID: Components.ID("{fff440b3-fae2-45c1-bf03-3b5a2e432270}"), @@ -603,6 +590,16 @@ WebappsApplication.prototype = { * mozIDOMApplicationMgmt object */ function WebappsApplicationMgmt(aWindow) { + let principal = aWindow.document.nodePrincipal; + let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager); + + let perm = principal == secMan.getSystemPrincipal() + ? Ci.nsIPermissionManager.ALLOW_ACTION + : Services.perms.testExactPermissionFromPrincipal(principal, "webapps-manage"); + + //only pages with perm set can use some functions + this.hasPrivileges = perm == Ci.nsIPermissionManager.ALLOW_ACTION; + this.initHelper(aWindow, ["Webapps:GetAll:Return:OK", "Webapps:GetAll:Return:KO", "Webapps:Uninstall:Return:OK", @@ -659,7 +656,8 @@ WebappsApplicationMgmt.prototype = { getAll: function() { let request = this.createRequest(); cpmm.sendAsyncMessage("Webapps:GetAll", { oid: this._id, - requestID: this.getRequestId(request) }); + requestID: this.getRequestId(request), + hasPrivileges: this.hasPrivileges }); return request; }, @@ -679,11 +677,17 @@ WebappsApplicationMgmt.prototype = { }, set oninstall(aCallback) { - this._oninstall = aCallback; + if (this.hasPrivileges) + this._oninstall = aCallback; + else + throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE); }, set onuninstall(aCallback) { - this._onuninstall = aCallback; + if (this.hasPrivileges) + this._onuninstall = aCallback; + else + throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE); }, receiveMessage: function(aMessage) { diff --git a/dom/apps/src/Webapps.jsm b/dom/apps/src/Webapps.jsm index 2a188dea0d6f..6b7ac6a271af 100644 --- a/dom/apps/src/Webapps.jsm +++ b/dom/apps/src/Webapps.jsm @@ -787,7 +787,10 @@ this.DOMApplicationRegistry = { this.getNotInstalled(msg, mm); break; case "Webapps:GetAll": - this.getAll(msg, mm); + if (msg.hasPrivileges) + this.getAll(msg, mm); + else + mm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg); break; case "Webapps:InstallPackage": this.doInstallPackage(msg, mm);