Bug 775815 - Use new Permission Manager API in SpecialPowers. r=sicking

This commit is contained in:
Mounir Lamouri 2012-08-23 11:23:48 -07:00
Родитель af2040dbb7
Коммит 8e092dc2e5
2 изменённых файлов: 42 добавлений и 21 удалений

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

@ -175,14 +175,17 @@ SpecialPowersObserverAPI.prototype = {
let perms = let perms =
Components.classes["@mozilla.org/permissionmanager;1"] Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager); .getService(Components.interfaces.nsIPermissionManager);
let uri = this._getURI(aMessage.json.url); let msg = aMessage.json;
switch (aMessage.json.op) { let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
let principal = secMan.getAppCodebasePrincipal(this._getURI(msg.url), msg.appId, msg.isInBrowserElement);
switch (msg.op) {
case "add": case "add":
perms.add(uri, aMessage.json.type, aMessage.json.permission); perms.addFromPrincipal(principal, msg.type, msg.permission);
break; break;
case "remove": case "remove":
perms.remove(uri.host, aMessage.json.type); perms.removeFromPrincipal(principal, msg.type);
break; break;
default: default:
throw new SpecialPowersException("Invalid operation for " + throw new SpecialPowersException("Invalid operation for " +

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

@ -1131,40 +1131,58 @@ SpecialPowersAPI.prototype = {
pm.removeFromPrincipal(document.nodePrincipal, "fullscreen"); pm.removeFromPrincipal(document.nodePrincipal, "fullscreen");
}, },
_getURI: function(urlOrDocument) { _getInfoFromPermissionArg: function(arg) {
if (typeof(urlOrDocument) == "string") { let url = "";
return Cc["@mozilla.org/network/io-service;1"]. let appId = Ci.nsIScriptSecurityManager.NO_APP_ID;
getService(Ci.nsIIOService). let isInBrowserElement = false;
newURI(urlOrDocument, null, null);
if (typeof(arg) == "string") {
// It's an URL.
url = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService)
.newURI(arg, null, null)
.spec;
} else if (arg.nodePrincipal) {
// It's a document.
url = arg.nodePrincipal.URI.spec;
appId = arg.nodePrincipal.appId;
isInBrowserElement = arg.nodePrincipal.isInBrowserElement;
} else {
url = arg.url;
appId = arg.appId;
isInBrowserElement = arg.isInBrowserElement;
} }
// Assume document.
return this.getDocumentURIObject(urlOrDocument); return [ url, appId, isInBrowserElement ];
}, },
addPermission: function(type, allow, urlOrDocument) { addPermission: function(type, allow, arg) {
let uri = this._getURI(urlOrDocument); let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
let permission = allow ? let permission = allow ? Ci.nsIPermissionManager.ALLOW_ACTION
Ci.nsIPermissionManager.ALLOW_ACTION : : Ci.nsIPermissionManager.DENY_ACTION;
Ci.nsIPermissionManager.DENY_ACTION;
var msg = { var msg = {
'op': "add", 'op': "add",
'type': type, 'type': type,
'url': uri.spec, 'permission': permission,
'permission': permission 'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement
}; };
this._sendSyncMessage('SPPermissionManager', msg); this._sendSyncMessage('SPPermissionManager', msg);
}, },
removePermission: function(type, urlOrDocument) { removePermission: function(type, arg) {
let uri = this._getURI(urlOrDocument); let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
var msg = { var msg = {
'op': "remove", 'op': "remove",
'type': type, 'type': type,
'url': uri.spec 'url': url,
'appId': appId,
'isInBrowserElement': isInBrowserElement
}; };
this._sendSyncMessage('SPPermissionManager', msg); this._sendSyncMessage('SPPermissionManager', msg);