зеркало из https://github.com/mozilla/gecko-dev.git
Bug 775815 - Use new Permission Manager API in SpecialPowers. r=sicking
This commit is contained in:
Родитель
af2040dbb7
Коммит
8e092dc2e5
|
@ -175,14 +175,17 @@ SpecialPowersObserverAPI.prototype = {
|
|||
let perms =
|
||||
Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.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":
|
||||
perms.add(uri, aMessage.json.type, aMessage.json.permission);
|
||||
perms.addFromPrincipal(principal, msg.type, msg.permission);
|
||||
break;
|
||||
case "remove":
|
||||
perms.remove(uri.host, aMessage.json.type);
|
||||
perms.removeFromPrincipal(principal, msg.type);
|
||||
break;
|
||||
default:
|
||||
throw new SpecialPowersException("Invalid operation for " +
|
||||
|
|
|
@ -1131,40 +1131,58 @@ SpecialPowersAPI.prototype = {
|
|||
pm.removeFromPrincipal(document.nodePrincipal, "fullscreen");
|
||||
},
|
||||
|
||||
_getURI: function(urlOrDocument) {
|
||||
if (typeof(urlOrDocument) == "string") {
|
||||
return Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService).
|
||||
newURI(urlOrDocument, null, null);
|
||||
_getInfoFromPermissionArg: function(arg) {
|
||||
let url = "";
|
||||
let appId = Ci.nsIScriptSecurityManager.NO_APP_ID;
|
||||
let isInBrowserElement = false;
|
||||
|
||||
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) {
|
||||
let uri = this._getURI(urlOrDocument);
|
||||
addPermission: function(type, allow, arg) {
|
||||
let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
|
||||
|
||||
let permission = allow ?
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION :
|
||||
Ci.nsIPermissionManager.DENY_ACTION;
|
||||
let permission = allow ? Ci.nsIPermissionManager.ALLOW_ACTION
|
||||
: Ci.nsIPermissionManager.DENY_ACTION;
|
||||
|
||||
var msg = {
|
||||
'op': "add",
|
||||
'type': type,
|
||||
'url': uri.spec,
|
||||
'permission': permission
|
||||
'permission': permission,
|
||||
'url': url,
|
||||
'appId': appId,
|
||||
'isInBrowserElement': isInBrowserElement
|
||||
};
|
||||
|
||||
this._sendSyncMessage('SPPermissionManager', msg);
|
||||
},
|
||||
|
||||
removePermission: function(type, urlOrDocument) {
|
||||
let uri = this._getURI(urlOrDocument);
|
||||
removePermission: function(type, arg) {
|
||||
let [url, appId, isInBrowserElement] = this._getInfoFromPermissionArg(arg);
|
||||
|
||||
var msg = {
|
||||
'op': "remove",
|
||||
'type': type,
|
||||
'url': uri.spec
|
||||
'url': url,
|
||||
'appId': appId,
|
||||
'isInBrowserElement': isInBrowserElement
|
||||
};
|
||||
|
||||
this._sendSyncMessage('SPPermissionManager', msg);
|
||||
|
|
Загрузка…
Ссылка в новой задаче