toolkit/modules/PermissionsUtils.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 // License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 this.EXPORTED_SYMBOLS = ["PermissionsUtils"];
michael@0 6
michael@0 7 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
michael@0 8
michael@0 9 Cu.import("resource://gre/modules/Services.jsm");
michael@0 10
michael@0 11
michael@0 12 let gImportedPrefBranches = new Set();
michael@0 13
michael@0 14 function importPrefBranch(aPrefBranch, aPermission, aAction) {
michael@0 15 let list = Services.prefs.getChildList(aPrefBranch, {});
michael@0 16
michael@0 17 for (let pref of list) {
michael@0 18 let hosts = "";
michael@0 19 try {
michael@0 20 hosts = Services.prefs.getCharPref(pref);
michael@0 21 } catch (e) {}
michael@0 22
michael@0 23 if (!hosts)
michael@0 24 continue;
michael@0 25
michael@0 26 hosts = hosts.split(",");
michael@0 27
michael@0 28 for (let host of hosts) {
michael@0 29 try {
michael@0 30 let uri = Services.io.newURI("http://" + host, null, null);
michael@0 31 Services.perms.add(uri, aPermission, aAction);
michael@0 32 } catch (e) {}
michael@0 33 }
michael@0 34
michael@0 35 Services.prefs.setCharPref(pref, "");
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39
michael@0 40 this.PermissionsUtils = {
michael@0 41 /**
michael@0 42 * Import permissions from perferences to the Permissions Manager. After being
michael@0 43 * imported, all processed permissions will be set to an empty string.
michael@0 44 * Perferences are only processed once during the application's
michael@0 45 * lifetime - it's safe to call this multiple times without worrying about
michael@0 46 * doing unnecessary work, as the preferences branch will only be processed
michael@0 47 * the first time.
michael@0 48 *
michael@0 49 * @param aPrefBranch Preferences branch to import from. The preferences
michael@0 50 * under this branch can specify whitelist (ALLOW_ACTION)
michael@0 51 * or blacklist (DENY_ACTION) additions using perference
michael@0 52 * names of the form:
michael@0 53 * * <BRANCH>.whitelist.add.<ID>
michael@0 54 * * <BRANCH>.blacklist.add.<ID>
michael@0 55 * Where <ID> can be any valid preference name.
michael@0 56 * The value is expected to be a comma separated list of
michael@0 57 * host named. eg:
michael@0 58 * * something.example.com
michael@0 59 * * foo.exmaple.com,bar.example.com
michael@0 60 *
michael@0 61 * @param aPermission Permission name to be passsed to the Permissions
michael@0 62 * Manager.
michael@0 63 */
michael@0 64 importFromPrefs: function(aPrefBranch, aPermission) {
michael@0 65 if (!aPrefBranch.endsWith("."))
michael@0 66 aPrefBranch += ".";
michael@0 67
michael@0 68 // Ensure we only import this pref branch once.
michael@0 69 if (gImportedPrefBranches.has(aPrefBranch))
michael@0 70 return;
michael@0 71
michael@0 72 importPrefBranch(aPrefBranch + "whitelist.add", aPermission,
michael@0 73 Services.perms.ALLOW_ACTION);
michael@0 74 importPrefBranch(aPrefBranch + "blacklist.add", aPermission,
michael@0 75 Services.perms.DENY_ACTION);
michael@0 76
michael@0 77 gImportedPrefBranches.add(aPrefBranch);
michael@0 78 }
michael@0 79 };

mercurial