summaryrefslogtreecommitdiffstats
path: root/devtools/shared/flags.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /devtools/shared/flags.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/flags.js')
-rw-r--r--devtools/shared/flags.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/devtools/shared/flags.js b/devtools/shared/flags.js
new file mode 100644
index 0000000000..0239ec211e
--- /dev/null
+++ b/devtools/shared/flags.js
@@ -0,0 +1,69 @@
+/* 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/. */
+
+"use strict";
+
+/**
+ * This module controls various global flags that can be toggled on and off.
+ * These flags are generally used to change the behavior of the code during
+ * testing. They are tracked by preferences so that they are propagated
+ * between the parent and content processes. The flags are exposed via a module
+ * as a conveniene and to stop from littering preference names throughout the
+ * code ase.
+ *
+ * Each of the flags is documented where it is defined.
+ */
+
+/**
+ * We cannot make a normal property writeable on `exports` because
+ * the module system freezes it. This function observes a preference
+ * and provides the latest value through a getter.
+ */
+function makePrefTrackedFlag(exports, name, pref) {
+ let flag;
+ // We don't have access to pref in worker, so disable all logs by default
+ if (isWorker) {
+ flag = false;
+ } else {
+ flag = Services.prefs.getBoolPref(pref, false);
+ const prefObserver = () => {
+ flag = Services.prefs.getBoolPref(pref, false);
+ };
+ Services.prefs.addObserver(pref, prefObserver);
+
+ // Also listen for Loader unload to unregister the pref observer and prevent leaking
+ const unloadObserver = function(subject) {
+ if (subject.wrappedJSObject == require("@loader/unload")) {
+ Services.prefs.removeObserver(pref, prefObserver);
+ Services.obs.removeObserver(unloadObserver, "devtools:loader:destroy");
+ }
+ };
+ Services.obs.addObserver(unloadObserver, "devtools:loader:destroy");
+ }
+ Object.defineProperty(exports, name, {
+ get() {
+ return flag;
+ },
+ });
+}
+
+/**
+ * Setting the "devtools.debugger.log" preference to true will enable logging of
+ * the RDP calls to the devtools server.
+ */
+makePrefTrackedFlag(exports, "wantLogging", "devtools.debugger.log");
+
+/**
+ * Setting the "devtools.debugger.log.verbose" preference to true will enable a
+ * more verbose logging of the the RDP. The "devtools.debugger.log" preference
+ * must be set to true as well for this to have any effect.
+ */
+makePrefTrackedFlag(exports, "wantVerbose", "devtools.debugger.log.verbose");
+
+/**
+ * Setting the "devtools.testing" preference to true will toggle on certain
+ * behaviors that can differ from the production version of the code. These
+ * behaviors typically enable easier testing or enhanced debugging features.
+ */
+makePrefTrackedFlag(exports, "testing", "devtools.testing");