2016-02-04 04:04:56 +03:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["PermissionsUtils"];
|
2016-02-04 04:04:56 +03:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2016-02-04 04:04:56 +03:00
|
|
|
|
|
|
|
var gImportedPrefBranches = new Set();
|
|
|
|
|
|
|
|
function importPrefBranch(aPrefBranch, aPermission, aAction) {
|
2019-05-21 09:20:40 +03:00
|
|
|
let list = Services.prefs.getChildList(aPrefBranch);
|
2016-02-04 04:04:56 +03:00
|
|
|
|
|
|
|
for (let pref of list) {
|
2017-03-07 17:29:48 +03:00
|
|
|
let origins = Services.prefs.getCharPref(pref, "");
|
2016-02-04 04:04:56 +03:00
|
|
|
|
|
|
|
if (!origins) {
|
|
|
|
continue;
|
2019-07-05 12:15:43 +03:00
|
|
|
}
|
2016-02-04 04:04:56 +03:00
|
|
|
|
|
|
|
origins = origins.split(",");
|
|
|
|
|
|
|
|
for (let origin of origins) {
|
|
|
|
let principals = [];
|
|
|
|
try {
|
|
|
|
principals = [
|
2019-07-08 19:37:45 +03:00
|
|
|
Services.scriptSecurityManager.createContentPrincipalFromOrigin(
|
2016-02-04 04:04:56 +03:00
|
|
|
origin
|
2019-07-05 12:15:43 +03:00
|
|
|
),
|
2016-02-04 04:04:56 +03:00
|
|
|
];
|
|
|
|
} catch (e) {
|
|
|
|
// This preference used to contain a list of hosts. For back-compat
|
|
|
|
// reasons, we convert these hosts into http:// and https:// permissions
|
|
|
|
// on default ports.
|
|
|
|
try {
|
2017-01-09 22:27:25 +03:00
|
|
|
let httpURI = Services.io.newURI("http://" + origin);
|
|
|
|
let httpsURI = Services.io.newURI("https://" + origin);
|
2016-02-04 04:04:56 +03:00
|
|
|
|
|
|
|
principals = [
|
2019-07-08 19:37:45 +03:00
|
|
|
Services.scriptSecurityManager.createContentPrincipal(httpURI, {}),
|
|
|
|
Services.scriptSecurityManager.createContentPrincipal(httpsURI, {}),
|
2016-02-04 04:04:56 +03:00
|
|
|
];
|
|
|
|
} catch (e2) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let principal of principals) {
|
|
|
|
try {
|
|
|
|
Services.perms.addFromPrincipal(principal, aPermission, aAction);
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.prefs.setCharPref(pref, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var PermissionsUtils = {
|
2016-02-04 04:04:56 +03:00
|
|
|
/**
|
|
|
|
* Import permissions from perferences to the Permissions Manager. After being
|
|
|
|
* imported, all processed permissions will be set to an empty string.
|
|
|
|
* Perferences are only processed once during the application's
|
|
|
|
* lifetime - it's safe to call this multiple times without worrying about
|
|
|
|
* doing unnecessary work, as the preferences branch will only be processed
|
|
|
|
* the first time.
|
|
|
|
*
|
|
|
|
* @param aPrefBranch Preferences branch to import from. The preferences
|
|
|
|
* under this branch can specify whitelist (ALLOW_ACTION)
|
|
|
|
* or blacklist (DENY_ACTION) additions using perference
|
|
|
|
* names of the form:
|
|
|
|
* * <BRANCH>.whitelist.add.<ID>
|
|
|
|
* * <BRANCH>.blacklist.add.<ID>
|
|
|
|
* Where <ID> can be any valid preference name.
|
|
|
|
* The value is expected to be a comma separated list of
|
|
|
|
* host named. eg:
|
|
|
|
* * something.example.com
|
|
|
|
* * foo.exmaple.com,bar.example.com
|
|
|
|
*
|
|
|
|
* @param aPermission Permission name to be passsed to the Permissions
|
|
|
|
* Manager.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
importFromPrefs(aPrefBranch, aPermission) {
|
2016-02-04 04:04:56 +03:00
|
|
|
if (!aPrefBranch.endsWith(".")) {
|
|
|
|
aPrefBranch += ".";
|
2019-07-05 12:15:43 +03:00
|
|
|
}
|
2016-02-04 04:04:56 +03:00
|
|
|
|
|
|
|
// Ensure we only import this pref branch once.
|
|
|
|
if (gImportedPrefBranches.has(aPrefBranch)) {
|
|
|
|
return;
|
2019-07-05 12:15:43 +03:00
|
|
|
}
|
2016-02-04 04:04:56 +03:00
|
|
|
|
|
|
|
importPrefBranch(
|
|
|
|
aPrefBranch + "whitelist.add",
|
|
|
|
aPermission,
|
|
|
|
Services.perms.ALLOW_ACTION
|
|
|
|
);
|
|
|
|
importPrefBranch(
|
|
|
|
aPrefBranch + "blacklist.add",
|
|
|
|
aPermission,
|
|
|
|
Services.perms.DENY_ACTION
|
|
|
|
);
|
|
|
|
|
|
|
|
gImportedPrefBranches.add(aPrefBranch);
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2016-02-04 04:04:56 +03:00
|
|
|
};
|