Bug 846057 - Add testPermission and hasPermission APIs. r=jgriffin

This commit is contained in:
David Clarke 2013-03-04 20:17:24 -05:00
parent d2f9772497
commit e9952adf69
2 changed files with 42 additions and 2 deletions

View File

@ -236,6 +236,19 @@ SpecialPowersObserverAPI.prototype = {
case "remove":
Services.perms.removeFromPrincipal(principal, msg.type);
break;
case "has":
let hasPerm = Services.perms.testPermissionFromPrincipal(principal, msg.type);
if (hasPerm == Ci.nsIPermissionManager.ALLOW_ACTION)
return true;
return false;
break;
case "test":
let testPerm = Services.perms.testPermissionFromPrincipal(principal, msg.type, msg.value);
if (testPerm == msg.value) {
return true;
}
return false;
break;
default:
throw new SpecialPowersException("Invalid operation for " +
"SPPermissionManager");

View File

@ -1244,7 +1244,7 @@ SpecialPowersAPI.prototype = {
: Ci.nsIPermissionManager.DENY_ACTION;
var msg = {
'op': "add",
'op': 'add',
'type': type,
'permission': permission,
'url': url,
@ -1259,7 +1259,7 @@ SpecialPowersAPI.prototype = {
let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
var msg = {
'op': "remove",
'op': 'remove',
'type': type,
'url': url,
'appId': appId,
@ -1269,6 +1269,33 @@ SpecialPowersAPI.prototype = {
this._sendSyncMessage('SPPermissionManager', msg);
},
hasPermission: function (type, arg) {
let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
var msg = {
'op': 'has',
'type': type,
'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement
};
return this._sendSyncMessage('SPPermissionManager', msg)[0];
},
testPermission: function (type, value, arg) {
let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
var msg = {
'op': 'test',
'type': type,
'value': value,
'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement
};
return this._sendSyncMessage('SPPermissionManager', msg)[0];
},
getMozFullPath: function(file) {
return file.mozFullPath;
},