Back out fdeb0c833138 (bug 814226) for Linux bc failures in browser_webapps_permissions.js

CLOSED TREE
This commit is contained in:
Phil Ringnalda 2013-01-18 19:10:47 -08:00
Родитель f62c0089ed
Коммит 321f2d70e2
2 изменённых файлов: 25 добавлений и 18 удалений

Просмотреть файл

@ -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) {
if (this.hasPrivileges)
this._oninstall = aCallback;
else
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
},
set onuninstall(aCallback) {
if (this.hasPrivileges)
this._onuninstall = aCallback;
else
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
},
receiveMessage: function(aMessage) {

Просмотреть файл

@ -787,7 +787,10 @@ this.DOMApplicationRegistry = {
this.getNotInstalled(msg, mm);
break;
case "Webapps:GetAll":
if (msg.hasPrivileges)
this.getAll(msg, mm);
else
mm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
break;
case "Webapps:InstallPackage":
this.doInstallPackage(msg, mm);