This repository was archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpermissions.js
48 lines (41 loc) · 1.45 KB
/
permissions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*global define: true port: true */
/*jshint asi:true globalstrict: true */
'use strict';
const { Cc, Ci } = require('chrome')
const nsIPermissionManager = Ci.nsIPermissionManager
const manager = Cc['@mozilla.org/permissionmanager;1'].
getService(nsIPermissionManager)
const ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService)
const { UNKNOWN_ACTION, ALLOW_ACTION, DENY_ACTION } = nsIPermissionManager
exports.add = function add(permission) {
let { host, type, capability, expireType, expireTime } = permission
let uri = ioService.newURI('http://' + host, null, null)
uri.host = host
capability = capability === true ? ALLOW_ACTION :
capability === false ? DENY_ACTION :
capability === null ? UNKNOWN_ACTION : capability
manager.add(uri, String(type), capability, expireType, expireTime)
}
exports.remove = function remove({ host, type }) {
manager.remove(host, type)
}
exports.permissions = function() {
function tail(enumerator) {
return !enumerator.hasMoreElements() ? null : Object.defineProperties({}, {
head: {
enumerable: true,
value: enumerator.getNext().QueryInterface(Ci.nsIPermission)
},
tail: {
enumerable: true,
get: new function(value) {
return function() {
return value || (value = tail(enumerator))
}
}
}
})
}
return tail(manager.enumerator)
}