Files
lbmk/config/firefox/default/patches/0050-webgl-permission.patch.patch
T
Leah Rowe 2b34aeea5d WIP: convert to lwmk
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-09-08 06:44:40 +01:00

615 lines
25 KiB
Diff

From 9c9f33a51b1676b1bcc3f85e10347115b40e2ff4 Mon Sep 17 00:00:00 2001
From: LibreWolf Developers <noreply@librewolf.net>
Date: Sun, 6 Sep 2026 10:12:55 +0100
Subject: [PATCH 50/52] webgl-permission.patch
---
.../content/popup-notifications.inc.xhtml | 7 +
browser/modules/ObserverForwarder.sys.mjs | 5 +
.../WebGLPermissionPromptHelper.sys.mjs | 132 +++++++++++++++++
browser/themes/shared/icons/webgl-blocked.svg | 18 +++
browser/themes/shared/icons/webgl.svg | 17 +++
browser/themes/shared/jar.inc.mn | 3 +
browser/themes/shared/notification-icons.css | 9 ++
.../notification-icons/webgl-blocked.svg | 18 +++
.../shared/notification-icons/webgl.svg | 17 +++
dom/canvas/ClientWebGLContext.cpp | 140 ++++++++++++++++++
dom/ipc/BrowserParent.cpp | 23 +++
dom/ipc/BrowserParent.h | 2 +
dom/ipc/PBrowser.ipdl | 8 +
modules/libpref/init/StaticPrefList.yaml | 14 ++
modules/libpref/moz.build | 1 +
15 files changed, 414 insertions(+)
create mode 100644 browser/modules/WebGLPermissionPromptHelper.sys.mjs
create mode 100644 browser/themes/shared/icons/webgl-blocked.svg
create mode 100644 browser/themes/shared/icons/webgl.svg
create mode 100644 browser/themes/shared/notification-icons/webgl-blocked.svg
create mode 100644 browser/themes/shared/notification-icons/webgl.svg
diff --git a/browser/base/content/popup-notifications.inc.xhtml b/browser/base/content/popup-notifications.inc.xhtml
index 4e2f449c8199..256e4c94719a 100644
--- a/browser/base/content/popup-notifications.inc.xhtml
+++ b/browser/base/content/popup-notifications.inc.xhtml
@@ -175,6 +175,13 @@
</popupnotificationcontent>
</popupnotification>
+ <popupnotification id="webgl-permissions-prompt-notification" hidden="true">
+ <popupnotificationcontent orient="vertical">
+ <description class="popup-notification-description"/>
+ <label id="webgl-permissions-prompt-warning"/>
+ </popupnotificationcontent>
+ </popupnotification>
+
<popupnotification id="contextual-feature-recommendation-notification"
buttonhighlight="true"
hidden="true">
diff --git a/browser/modules/ObserverForwarder.sys.mjs b/browser/modules/ObserverForwarder.sys.mjs
index b62b572cdb11..222765c2754e 100644
--- a/browser/modules/ObserverForwarder.sys.mjs
+++ b/browser/modules/ObserverForwarder.sys.mjs
@@ -14,6 +14,8 @@ let lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
CanvasPermissionPromptHelper:
"moz-src:///browser/modules/CanvasPermissionPromptHelper.sys.mjs",
+ WebGLPermissionPromptHelper:
+ "moz-src:///browser/modules/WebGLPermissionPromptHelper.sys.mjs",
FilePickerCrashed: "resource:///modules/FilePickerCrashed.sys.mjs",
PluginManager: "resource:///actors/PluginParent.sys.mjs",
SerialDeviceSharingHelper:
@@ -29,6 +31,9 @@ let gObservers = {
"canvas-permissions-prompt": ["CanvasPermissionPromptHelper"],
"canvas-permissions-prompt-hide-doorhanger": ["CanvasPermissionPromptHelper"],
+ "webgl-permissions-prompt": ["WebGLPermissionPromptHelper"],
+ "webgl-permissions-prompt-hide-doorhanger": ["WebGLPermissionPromptHelper"],
+
"file-picker-crashed": ["FilePickerCrashed"],
"gmp-plugin-crash": ["PluginManager"],
"plugin-crashed": ["PluginManager"],
diff --git a/browser/modules/WebGLPermissionPromptHelper.sys.mjs b/browser/modules/WebGLPermissionPromptHelper.sys.mjs
new file mode 100644
index 000000000000..7c647a147894
--- /dev/null
+++ b/browser/modules/WebGLPermissionPromptHelper.sys.mjs
@@ -0,0 +1,132 @@
+/* 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 https://mozilla.org/MPL/2.0/. */
+
+import { PrivateBrowsingUtils } from "resource://gre/modules/PrivateBrowsingUtils.sys.mjs";
+
+export let WebGLPermissionPromptHelper = {
+ _permissionsPrompt: "webgl-permissions-prompt",
+ _permissionsPromptHideDoorHanger: "webgl-permissions-prompt-hide-doorhanger",
+ _notificationIcon: "webgl-notification-icon",
+
+ // aSubject is an nsIBrowser (e10s) or an nsIDOMWindow (non-e10s).
+ // aData is an Origin string.
+ observe(aSubject, aTopic, aData) {
+ if (
+ aTopic != this._permissionsPrompt &&
+ aTopic != this._permissionsPromptHideDoorHanger
+ ) {
+ return;
+ }
+
+ let browser;
+ if (aSubject instanceof Ci.nsIDOMWindow) {
+ browser = aSubject.docShell.chromeEventHandler;
+ } else {
+ browser = aSubject;
+ }
+
+ let window = browser?.documentGlobal;
+ if (!window) {
+ // Without knowing where this came from, we can't show the prompt.
+ return;
+ }
+
+ let principal =
+ Services.scriptSecurityManager.createContentPrincipalFromOrigin(aData);
+ let permission = Services.perms.testPermissionFromPrincipal(principal, "webgl");
+ if (permission === Ci.nsIPermissionManager.DENY_ACTION ||
+ permission === Ci.nsIPermissionManager.ALLOW_ACTION) {
+ return;
+ }
+
+ if (window.PopupNotifications.getNotification(
+ this._permissionsPrompt,
+ browser
+ )) {
+ return;
+ }
+
+ let { gNavigatorBundle, gBrowserBundle } = window;
+ let message = gNavigatorBundle.getFormattedString(
+ "webgl.siteprompt2",
+ ["<>"],
+ 1
+ );
+
+ function setWebGLPermission(aPerm, aPersistent) {
+ Services.perms.addFromPrincipal(
+ principal,
+ "webgl",
+ aPerm,
+ aPersistent
+ ? Ci.nsIPermissionManager.EXPIRE_NEVER
+ : Ci.nsIPermissionManager.EXPIRE_SESSION
+ );
+ }
+
+ let mainAction = {
+ label: gNavigatorBundle.getString("webgl.allow2"),
+ accessKey: gNavigatorBundle.getString("webgl.allow2.accesskey"),
+ callback(state) {
+ setWebGLPermission(
+ Ci.nsIPermissionManager.ALLOW_ACTION,
+ state && state.checkboxChecked
+ );
+ let tab = window?.gBrowser?.getTabForBrowser(browser);
+ if (tab) {
+ window.gBrowser.reloadTab(tab);
+ }
+ },
+ };
+
+ let secondaryActions = [
+ {
+ label: gNavigatorBundle.getString("webgl.block"),
+ accessKey: gNavigatorBundle.getString("webgl.block.accesskey"),
+ callback(state) {
+ setWebGLPermission(
+ Ci.nsIPermissionManager.DENY_ACTION,
+ state && state.checkboxChecked
+ );
+ },
+ },
+ ];
+
+ let checkbox = {
+ // In PB mode, we don't want the "always remember" checkbox
+ show: !PrivateBrowsingUtils.isWindowPrivate(window),
+ };
+ if (checkbox.show) {
+ checkbox.checked = true;
+ checkbox.label = gBrowserBundle.GetStringFromName("webgl.remember2");
+ }
+
+ let options = {
+ checkbox,
+ name: principal.host,
+ learnMoreURL:
+ Services.urlFormatter.formatURLPref("app.support.baseURL") +
+ "webgl-prompt",
+ dismissed: aTopic == this._permissionsPromptHideDoorHanger,
+ eventCallback(e) {
+ if (e == "showing" && this?.browser?.ownerDocument) {
+ this.browser.ownerDocument.getElementById(
+ "webgl-permissions-prompt-warning"
+ ).textContent = gBrowserBundle.GetStringFromName(
+ "webgl.siteprompt2.warning"
+ );
+ }
+ },
+ };
+ window.PopupNotifications.show(
+ browser,
+ this._permissionsPrompt,
+ message,
+ this._notificationIcon,
+ mainAction,
+ secondaryActions,
+ options
+ );
+ },
+};
diff --git a/browser/themes/shared/icons/webgl-blocked.svg b/browser/themes/shared/icons/webgl-blocked.svg
new file mode 100644
index 000000000000..6e18b7cf5401
--- /dev/null
+++ b/browser/themes/shared/icons/webgl-blocked.svg
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ version="1.1"
+ id="svg1"
+ xml:space="preserve"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ fill="context-fill"
+ fill-opacity="context-fill-opacity"><defs
+ id="defs1" /><g
+ id="g30"
+ transform="translate(-95.002999,-238.87424)"><path
+ id="path30"
+ style="stroke-linecap:round;paint-order:stroke fill markers"
+ d="m 95.604562,238.87619 c -0.463094,0.0319 -0.839908,0.6221 -0.419922,1.06446 l 1,1 1.820312,1.82031 v 10.48437 a 0.625,0.625 0 0 0 0.625,0.625 0.625,0.625 0 0 0 0.625,-0.625 v -1.35547 h 7.878908 l 2.80078,2.80079 c 0.24466,0.24372 0.6401,0.24372 0.88477,0 0.24415,-0.24409 0.24415,-0.64068 0,-0.88477 l -2.0625,-2.06445 -1.10157,-1.10157 h -0.002 l -3.72656,-3.72656 v -0.002 l -0.96289,-0.96289 h -0.002 l -1.82031,-1.82031 -1.249999,-1.25 -0.636719,-0.63672 -2.367187,-2.36719 -0.462891,-0.46289 -0.355469,-0.35547 c -0.147451,-0.13999 -0.31048,-0.19033 -0.464843,-0.17969 z m 6.056638,4.00196 1.25,1.25 h 5.07422 c 0.42057,0 0.74894,0.32747 0.75,0.74804 l 0.0117,5.01953 c 5e-5,0.0215 -0.004,0.0416 -0.006,0.0625 l 0.96289,0.96289 c 0.18374,-0.30216 0.29391,-0.65288 0.29297,-1.02929 l -0.0117,-5.01953 c -0.003,-1.09501 -0.90499,-1.99414 -2,-1.99414 z m -2.406248,1.25 h 0.117188 l 2.13867,2.14062 a 1.4999924,1.4999924 0 0 0 -0.50976,1.10547 1.4999924,1.4999924 0 0 0 1.5,1.5 1.4999924,1.4999924 0 0 0 1.11718,-0.5 l 2.26563,2.26562 h -6.628908 z" /></g></svg>
diff --git a/browser/themes/shared/icons/webgl.svg b/browser/themes/shared/icons/webgl.svg
new file mode 100644
index 000000000000..ffbf97c74dc7
--- /dev/null
+++ b/browser/themes/shared/icons/webgl.svg
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ version="1.1"
+ id="svg1"
+ xml:space="preserve"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ fill="context-fill"
+ fill-opacity="context-fill-opacity"><defs
+ id="defs1" /><g
+ id="g27"
+ transform="translate(-95.002767,-238.87424)"><path
+ id="path26"
+ d="m 96.625679,239.87424 a 0.625,0.625 0 0 0 -0.625,0.625 0.625,0.625 0 0 0 0.625,0.625 h 0.626953 c 0.422091,-7e-5 0.751953,0.32791 0.751953,0.75 v 11.37109 a 0.625,0.625 0 0 0 0.625,0.625 0.625,0.625 0 0 0 0.624997,-0.625 v -1.35547 h 8.749998 c 1.095,0 1.99494,-0.90304 1.99219,-1.99804 l -0.0117,-5.01953 c -0.003,-1.09501 -0.90499,-1.99414 -2,-1.99414 h -8.730468 v -1.00391 c 0,-1.09772 -0.904231,-2.00019 -2.00195,-2 z m 2.628903,4.25391 h 8.730468 c 0.42057,0 0.74894,0.32747 0.75,0.74804 l 0.0117,5.01953 c 10e-4,0.41835 -0.32385,0.74415 -0.74219,0.74414 h -8.749998 z m 3.246088,1.74609 a 1.4999924,1.4999924 0 0 0 -1.5,1.5 1.4999924,1.4999924 0 0 0 1.5,1.5 1.4999924,1.4999924 0 0 0 1.5,-1.5 1.4999924,1.4999924 0 0 0 -1.5,-1.5 z" /></g></svg>
diff --git a/browser/themes/shared/jar.inc.mn b/browser/themes/shared/jar.inc.mn
index 450bff017b14..731979c9d588 100644
--- a/browser/themes/shared/jar.inc.mn
+++ b/browser/themes/shared/jar.inc.mn
@@ -212,6 +212,9 @@
skin/classic/browser/calendar-24.svg (../shared/icons/calendar-24.svg)
skin/classic/browser/canvas.svg (../shared/icons/canvas.svg)
skin/classic/browser/canvas-blocked.svg (../shared/icons/canvas-blocked.svg)
+ skin/classic/browser/webgl.svg (../shared/icons/webgl.svg)
+ skin/classic/browser/webgl-blocked.svg (../shared/icons/webgl-blocked.svg)
+ skin/classic/browser/notification-icons/webgl.svg (../shared/notification-icons/webgl.svg)
skin/classic/browser/characterEncoding.svg (../shared/icons/characterEncoding.svg)
skin/classic/browser/chevron-animation.svg (../shared/icons/chevron-animation.svg)
skin/classic/browser/circle-check-dotted.svg (../shared/icons/circle-check-dotted.svg)
diff --git a/browser/themes/shared/notification-icons.css b/browser/themes/shared/notification-icons.css
index 7d3f1207266e..fbc37db2709e 100644
--- a/browser/themes/shared/notification-icons.css
+++ b/browser/themes/shared/notification-icons.css
@@ -211,6 +211,15 @@
list-style-image: url(chrome://browser/skin/canvas-blocked.svg);
}
+#webgl-notification-icon,
+.webgl-icon {
+ list-style-image: url(chrome://browser/skin/webgl.svg);
+}
+
+.webgl-icon.blocked-permission-icon {
+ list-style-image: url(chrome://browser/skin/webgl-blocked.svg);
+}
+
#webauthn-notification-icon,
.popup-notification-icon[popupid^="webauthn-prompt-"] {
list-style-image: url(chrome://browser/skin/fingerprint.svg);
diff --git a/browser/themes/shared/notification-icons/webgl-blocked.svg b/browser/themes/shared/notification-icons/webgl-blocked.svg
new file mode 100644
index 000000000000..6e18b7cf5401
--- /dev/null
+++ b/browser/themes/shared/notification-icons/webgl-blocked.svg
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ version="1.1"
+ id="svg1"
+ xml:space="preserve"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ fill="context-fill"
+ fill-opacity="context-fill-opacity"><defs
+ id="defs1" /><g
+ id="g30"
+ transform="translate(-95.002999,-238.87424)"><path
+ id="path30"
+ style="stroke-linecap:round;paint-order:stroke fill markers"
+ d="m 95.604562,238.87619 c -0.463094,0.0319 -0.839908,0.6221 -0.419922,1.06446 l 1,1 1.820312,1.82031 v 10.48437 a 0.625,0.625 0 0 0 0.625,0.625 0.625,0.625 0 0 0 0.625,-0.625 v -1.35547 h 7.878908 l 2.80078,2.80079 c 0.24466,0.24372 0.6401,0.24372 0.88477,0 0.24415,-0.24409 0.24415,-0.64068 0,-0.88477 l -2.0625,-2.06445 -1.10157,-1.10157 h -0.002 l -3.72656,-3.72656 v -0.002 l -0.96289,-0.96289 h -0.002 l -1.82031,-1.82031 -1.249999,-1.25 -0.636719,-0.63672 -2.367187,-2.36719 -0.462891,-0.46289 -0.355469,-0.35547 c -0.147451,-0.13999 -0.31048,-0.19033 -0.464843,-0.17969 z m 6.056638,4.00196 1.25,1.25 h 5.07422 c 0.42057,0 0.74894,0.32747 0.75,0.74804 l 0.0117,5.01953 c 5e-5,0.0215 -0.004,0.0416 -0.006,0.0625 l 0.96289,0.96289 c 0.18374,-0.30216 0.29391,-0.65288 0.29297,-1.02929 l -0.0117,-5.01953 c -0.003,-1.09501 -0.90499,-1.99414 -2,-1.99414 z m -2.406248,1.25 h 0.117188 l 2.13867,2.14062 a 1.4999924,1.4999924 0 0 0 -0.50976,1.10547 1.4999924,1.4999924 0 0 0 1.5,1.5 1.4999924,1.4999924 0 0 0 1.11718,-0.5 l 2.26563,2.26562 h -6.628908 z" /></g></svg>
diff --git a/browser/themes/shared/notification-icons/webgl.svg b/browser/themes/shared/notification-icons/webgl.svg
new file mode 100644
index 000000000000..ffbf97c74dc7
--- /dev/null
+++ b/browser/themes/shared/notification-icons/webgl.svg
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ version="1.1"
+ id="svg1"
+ xml:space="preserve"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ fill="context-fill"
+ fill-opacity="context-fill-opacity"><defs
+ id="defs1" /><g
+ id="g27"
+ transform="translate(-95.002767,-238.87424)"><path
+ id="path26"
+ d="m 96.625679,239.87424 a 0.625,0.625 0 0 0 -0.625,0.625 0.625,0.625 0 0 0 0.625,0.625 h 0.626953 c 0.422091,-7e-5 0.751953,0.32791 0.751953,0.75 v 11.37109 a 0.625,0.625 0 0 0 0.625,0.625 0.625,0.625 0 0 0 0.624997,-0.625 v -1.35547 h 8.749998 c 1.095,0 1.99494,-0.90304 1.99219,-1.99804 l -0.0117,-5.01953 c -0.003,-1.09501 -0.90499,-1.99414 -2,-1.99414 h -8.730468 v -1.00391 c 0,-1.09772 -0.904231,-2.00019 -2.00195,-2 z m 2.628903,4.25391 h 8.730468 c 0.42057,0 0.74894,0.32747 0.75,0.74804 l 0.0117,5.01953 c 10e-4,0.41835 -0.32385,0.74415 -0.74219,0.74414 h -8.749998 z m 3.246088,1.74609 a 1.4999924,1.4999924 0 0 0 -1.5,1.5 1.4999924,1.4999924 0 0 0 1.5,1.5 1.4999924,1.4999924 0 0 0 1.5,-1.5 1.4999924,1.4999924 0 0 0 -1.5,-1.5 z" /></g></svg>
diff --git a/dom/canvas/ClientWebGLContext.cpp b/dom/canvas/ClientWebGLContext.cpp
index afed0c39f23a..e9af0b03ffb8 100644
--- a/dom/canvas/ClientWebGLContext.cpp
+++ b/dom/canvas/ClientWebGLContext.cpp
@@ -24,7 +24,9 @@
#include "mozilla/RandomNum.h"
#include "mozilla/ResultVariant.h"
#include "mozilla/ScopeExit.h"
+#include "mozilla/StaticPrefs_librewolf.h"
#include "mozilla/StaticPrefs_webgl.h"
+#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/BufferSourceBinding.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/GeneratePlaceholderCanvasData.h"
@@ -45,6 +47,8 @@
#include "mozilla/layers/WebRenderUserData.h"
#include "nsContentUtils.h"
#include "nsDisplayList.h"
+#include "nsIPrincipal.h"
+#include "nsIPermissionManager.h"
namespace mozilla {
@@ -862,6 +866,131 @@ void ClientWebGLContext::ResetBitmap() {
Run<RPROC(Resize)>(size); // No-change resize still clears/resets everything.
}
+static uint32_t GetWebGLPermission(nsIPrincipal* aPrincipal) {
+ if (!aPrincipal) {
+ return nsIPermissionManager::UNKNOWN_ACTION;
+ }
+
+ if (IsUnrestrictedPrincipal(aPrincipal)) {
+ return true;
+ }
+
+ nsresult rv;
+ nsCOMPtr<nsIPermissionManager> permissionManager =
+ do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
+ NS_ENSURE_SUCCESS(rv, nsIPermissionManager::UNKNOWN_ACTION);
+
+ uint32_t permission;
+ rv = permissionManager->TestPermissionFromPrincipal(
+ aPrincipal, "webgl"_ns, &permission);
+ NS_ENSURE_SUCCESS(rv, nsIPermissionManager::UNKNOWN_ACTION);
+
+ return permission;
+}
+
+static bool IsWebGLAllowed_impl(
+ bool webGLDisabled, JSContext* aCx,
+ nsIPrincipal* aPrincipal,
+ const std::function<void(const nsAutoString&)>& aReportToConsole,
+ const std::function<void(bool)>& aTryPrompt) {
+
+ if(!webGLDisabled) {
+ return true;
+ }
+
+ if (!aCx) {
+ return false;
+ }
+
+ if (IsUnrestrictedPrincipal(aPrincipal)) {
+ return true;
+ }
+
+ Maybe<nsAutoCString> origin = Nothing();
+ auto getOrigin = [&]() {
+ if (origin.isSome()) {
+ return origin->IsEmpty();
+ }
+
+ nsAutoCString originResult;
+ nsresult rv = NS_ERROR_FAILURE;
+ if (aPrincipal) {
+ rv = aPrincipal->GetOrigin(originResult);
+ }
+ origin = NS_SUCCEEDED(rv) ? Some(originResult) : Some(""_ns);
+
+ return NS_SUCCEEDED(rv);
+ };
+
+ uint64_t permission = GetWebGLPermission(aPrincipal);
+ switch (permission) {
+ case nsIPermissionManager::ALLOW_ACTION:
+ return true;
+ case nsIPermissionManager::DENY_ACTION:
+ return false;
+ default:
+ break;
+ }
+
+ bool hidePermissionDoorhanger = StaticPrefs::librewolf_webgl_prompt_hide();
+
+ nsAutoString message;
+ message.AppendPrintf("Blocked %s from creating WebGL context but prompting the user.",
+ getOrigin() ? origin->get() : "unknown");
+ aReportToConsole(message);
+
+ aTryPrompt(hidePermissionDoorhanger);
+
+ return false;
+}
+
+static bool IsWebGLAllowed(dom::Document* aDocument, JSContext* aCx,
+ nsIPrincipal* aPrincipal) {
+ if(NS_WARN_IF(!aDocument)) {
+ return false;
+ }
+
+ bool webGLDisabled = StaticPrefs::librewolf_webgl_prompt();
+
+ if (!webGLDisabled) {
+ return true;
+ }
+
+ auto reportToConsole = [&](const nsAutoString& message) {
+ nsContentUtils::ReportToConsoleNonLocalized(
+ message, nsIScriptError::warningFlag, "Security"_ns, aDocument);
+ };
+
+ auto prompt = [&](bool hidePermissionDoorhanger) {
+ if (!aPrincipal) {
+ return;
+ }
+
+ nsAutoCString origin;
+ nsresult rv = aPrincipal->GetOrigin(origin);
+ if (NS_FAILED(rv)) {
+ return;
+ }
+
+ if (!XRE_IsContentProcess()) {
+ MOZ_ASSERT_UNREACHABLE(
+ "Who's calling this from the parent process without a chrome window "
+ "(it would have been exempt from the RFP targets)?");
+ return;
+ }
+
+ nsPIDOMWindowOuter* win = aDocument->GetWindow();
+ if (RefPtr<dom::BrowserChild> browserChild =
+ dom::BrowserChild::GetFrom(win)) {
+ browserChild->SendShowWebGLPermissionPrompt(origin, hidePermissionDoorhanger);
+ }
+ };
+
+ return IsWebGLAllowed_impl(
+ webGLDisabled, aCx, aPrincipal,
+ reportToConsole, prompt);
+}
+
bool ClientWebGLContext::CreateHostContext(const uvec2& requestedSize) {
const auto pNotLost = MakeRefPtr<webgl::NotLostData>(*this);
auto& notLost = *pNotLost;
@@ -900,6 +1029,17 @@ bool ClientWebGLContext::CreateHostContext(const uvec2& requestedSize) {
.options = options,
};
+ if (mCanvasElement && !StaticPrefs::webgl_disabled()) {
+ if(!IsWebGLAllowed(mCanvasElement->OwnerDoc(),
+ nsContentUtils::GetCurrentJSContext(),
+ mCanvasElement->NodePrincipal())) {
+
+ return Err("WebGL is currently disabled.");
+ }
+ }
+
+
+
// -
ScopedGfxFeatureReporter reporter("IpcWebGL");
diff --git a/dom/ipc/BrowserParent.cpp b/dom/ipc/BrowserParent.cpp
index 4fbe13919101..2473600d45c4 100644
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -4229,6 +4229,29 @@ mozilla::ipc::IPCResult BrowserParent::RecvShowCanvasPermissionPrompt(
return IPC_OK();
}
+mozilla::ipc::IPCResult BrowserParent::RecvShowWebGLPermissionPrompt(const nsCString& aOrigin, const bool& aHideDoorHanger) {
+ nsCOMPtr<nsIBrowser> browser =
+ mFrameElement ? mFrameElement->AsBrowser() : nullptr;
+ if (!browser) {
+ // If the tab is being closed, the browser may not be available.
+ // In this case we can ignore the request.
+ return IPC_OK();
+ }
+ nsCOMPtr<nsIObserverService> os = services::GetObserverService();
+ if (!os) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ nsresult rv = os->NotifyObservers(
+ browser,
+ aHideDoorHanger ? "webgl-permissions-prompt-hide-doorhanger"
+ : "webgl-permissions-prompt",
+ NS_ConvertUTF8toUTF16(aOrigin).get());
+ if (NS_FAILED(rv)) {
+ return IPC_FAIL_NO_REASON(this);
+ }
+ return IPC_OK();
+}
+
mozilla::ipc::IPCResult BrowserParent::RecvVisitURI(
nsIURI* aURI, nsIURI* aLastVisitedURI, const uint32_t& aFlags,
const uint64_t& aBrowserId) {
diff --git a/dom/ipc/BrowserParent.h b/dom/ipc/BrowserParent.h
index f2537eccb928..c74a4e4c1251 100644
--- a/dom/ipc/BrowserParent.h
+++ b/dom/ipc/BrowserParent.h
@@ -757,6 +757,8 @@ class BrowserParent final : public PBrowserParent,
mozilla::ipc::IPCResult RecvShowCanvasPermissionPrompt(
const nsCString& aOrigin, const bool& aHideDoorHanger);
+ mozilla::ipc::IPCResult RecvShowWebGLPermissionPrompt(const nsCString& aOrigin, const bool& aHideDoorHanger);
+
mozilla::ipc::IPCResult RecvSetSystemFont(const nsCString& aFontName);
mozilla::ipc::IPCResult RecvGetSystemFont(nsCString* aFontName);
diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl
index 2be0054f75be..ee483b2fa6ce 100644
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -650,6 +650,14 @@ parent:
*/
async ShowCanvasPermissionPrompt(nsCString aOrigin,
bool aHideDoorHanger);
+ /**
+ * This function is used to notify the parent that it should display a
+ * WebGL permission prompt.
+ *
+ * @param aOrigin origin string of the document that is requesting access.
+ */
+ async ShowWebGLPermissionPrompt(nsCString aOrigin,
+ bool aHideDoorHanger);
sync SetSystemFont(nsCString aFontName);
sync GetSystemFont() returns (nsCString retval);
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
index d073433aa9b5..27fc0906de46 100644
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -11976,6 +11976,20 @@
value: true
mirror: always
+#---------------------------------------------------------------------------
+# Prefs starting with "librewolf."
+#---------------------------------------------------------------------------
+
+- name: librewolf.webgl.prompt
+ type: RelaxedAtomicBool
+ value: true
+ mirror: always
+
+- name: librewolf.webgl.prompt.hide
+ type: RelaxedAtomicBool
+ value: true
+ mirror: always
+
#---------------------------------------------------------------------------
# Prefs starting with "logging."
#---------------------------------------------------------------------------
diff --git a/modules/libpref/moz.build b/modules/libpref/moz.build
index 2c8b218c618f..16805711b4e2 100644
--- a/modules/libpref/moz.build
+++ b/modules/libpref/moz.build
@@ -56,6 +56,7 @@ pref_groups = [
"javascript",
"layers",
"layout",
+ "librewolf",
"logging",
"mathml",
"media",
--
2.47.3