1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 ChromeUtils.defineESModuleGetters(lazy, {
8 error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
9 MarionettePrefs: "chrome://remote/content/marionette/prefs.sys.mjs",
13 export const permissions = {};
15 function mapToInternalPermissionParameters(browsingContext, permissionType) {
16 const currentURI = browsingContext.currentWindowGlobal.documentURI;
18 // storage-access is quite special...
19 if (permissionType === "storage-access") {
20 const thirdPartyPrincipalSite = Services.eTLD.getSite(currentURI);
22 const topLevelURI = browsingContext.top.currentWindowGlobal.documentURI;
23 const topLevelPrincipal =
24 Services.scriptSecurityManager.createContentPrincipal(topLevelURI, {});
27 name: "3rdPartyFrameStorage^" + thirdPartyPrincipalSite,
28 principal: topLevelPrincipal,
32 const currentPrincipal =
33 Services.scriptSecurityManager.createContentPrincipal(currentURI, {});
37 principal: currentPrincipal,
42 * Set a permission's state.
43 * Note: Currently just a shim to support testdriver's set_permission.
45 * @param {object} permissionType
46 * The Gecko internal permission type
47 * @param {string} state
48 * State of the permission. It can be `granted`, `denied` or `prompt`.
49 * @param {boolean} oneRealm
51 * @param {browsingContext=} browsingContext
52 * Current browsing context object
53 * @throws {UnsupportedOperationError}
54 * If `marionette.setpermission.enabled` is not set or
55 * an unsupported permission is used.
57 permissions.set = function (permissionType, state, oneRealm, browsingContext) {
58 if (!lazy.MarionettePrefs.setPermissionEnabled) {
59 throw new lazy.error.UnsupportedOperationError(
60 "'Set Permission' is not available"
64 const { name, principal } = mapToInternalPermissionParameters(
71 Services.perms.addFromPrincipal(
74 Services.perms.ALLOW_ACTION
79 Services.perms.addFromPrincipal(
82 Services.perms.DENY_ACTION
87 Services.perms.removeFromPrincipal(principal, name);
91 throw new lazy.error.UnsupportedOperationError(
92 "Unrecognized permission keyword for 'Set Permission' operation"