summaryrefslogtreecommitdiffstats
path: root/remote/marionette/permissions.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /remote/marionette/permissions.sys.mjs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/marionette/permissions.sys.mjs')
-rw-r--r--remote/marionette/permissions.sys.mjs95
1 files changed, 95 insertions, 0 deletions
diff --git a/remote/marionette/permissions.sys.mjs b/remote/marionette/permissions.sys.mjs
new file mode 100644
index 0000000000..5238bf8347
--- /dev/null
+++ b/remote/marionette/permissions.sys.mjs
@@ -0,0 +1,95 @@
+/* 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/. */
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
+ MarionettePrefs: "chrome://remote/content/marionette/prefs.sys.mjs",
+});
+
+/** @namespace */
+export const permissions = {};
+
+function mapToInternalPermissionParameters(browsingContext, permissionType) {
+ const currentURI = browsingContext.currentWindowGlobal.documentURI;
+
+ // storage-access is quite special...
+ if (permissionType === "storage-access") {
+ const thirdPartyPrincipalSite = Services.eTLD.getSite(currentURI);
+
+ const topLevelURI = browsingContext.top.currentWindowGlobal.documentURI;
+ const topLevelPrincipal =
+ Services.scriptSecurityManager.createContentPrincipal(topLevelURI, {});
+
+ return {
+ name: "3rdPartyFrameStorage^" + thirdPartyPrincipalSite,
+ principal: topLevelPrincipal,
+ };
+ }
+
+ const currentPrincipal =
+ Services.scriptSecurityManager.createContentPrincipal(currentURI, {});
+
+ return {
+ name: permissionType,
+ principal: currentPrincipal,
+ };
+}
+
+/**
+ * Set a permission's state.
+ * Note: Currently just a shim to support testdriver's set_permission.
+ *
+ * @param {object} permissionType
+ * The Gecko internal permission type
+ * @param {string} state
+ * State of the permission. It can be `granted`, `denied` or `prompt`.
+ * @param {boolean} oneRealm
+ * Currently ignored
+ * @param {browsingContext=} browsingContext
+ * Current browsing context object
+ * @throws {UnsupportedOperationError}
+ * If `marionette.setpermission.enabled` is not set or
+ * an unsupported permission is used.
+ */
+permissions.set = function (permissionType, state, oneRealm, browsingContext) {
+ if (!lazy.MarionettePrefs.setPermissionEnabled) {
+ throw new lazy.error.UnsupportedOperationError(
+ "'Set Permission' is not available"
+ );
+ }
+
+ const { name, principal } = mapToInternalPermissionParameters(
+ browsingContext,
+ permissionType
+ );
+
+ switch (state) {
+ case "granted": {
+ Services.perms.addFromPrincipal(
+ principal,
+ name,
+ Services.perms.ALLOW_ACTION
+ );
+ return;
+ }
+ case "denied": {
+ Services.perms.addFromPrincipal(
+ principal,
+ name,
+ Services.perms.DENY_ACTION
+ );
+ return;
+ }
+ case "prompt": {
+ Services.perms.removeFromPrincipal(principal, name);
+ return;
+ }
+ default:
+ throw new lazy.error.UnsupportedOperationError(
+ "Unrecognized permission keyword for 'Set Permission' operation"
+ );
+ }
+};