summaryrefslogtreecommitdiffstats
path: root/devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs')
-rw-r--r--devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs45
1 files changed, 45 insertions, 0 deletions
diff --git a/devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs b/devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs
new file mode 100644
index 0000000000..06c33b8891
--- /dev/null
+++ b/devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs
@@ -0,0 +1,45 @@
+/* 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 { DevToolsLoader } = ChromeUtils.importESModule(
+ "resource://devtools/shared/loader/Loader.sys.mjs",
+ {
+ // `loadInDevToolsLoader` will import the loader in a special priviledged
+ // global created for DevTools, which will be reused as the shared global
+ // to load additional modules for the "DistinctSystemPrincipalLoader".
+ loadInDevToolsLoader: true,
+ }
+);
+
+// When debugging system principal resources (JSMs, chrome documents, ...)
+// We have to load DevTools actors in another system principal global.
+// That's mostly because of spidermonkey's Debugger API which requires
+// debuggee and debugger to be in distinct principals.
+//
+// We try to hold a single instance of this special loader via this API.
+//
+// @param requester object
+// Object/instance which is using the loader.
+// The same requester object should be passed to release method.
+let systemLoader = null;
+const systemLoaderRequesters = new Set();
+
+export function useDistinctSystemPrincipalLoader(requester) {
+ if (!systemLoader) {
+ systemLoader = new DevToolsLoader({
+ useDevToolsLoaderGlobal: true,
+ });
+ systemLoaderRequesters.clear();
+ }
+ systemLoaderRequesters.add(requester);
+ return systemLoader;
+}
+
+export function releaseDistinctSystemPrincipalLoader(requester) {
+ systemLoaderRequesters.delete(requester);
+ if (systemLoaderRequesters.size == 0) {
+ systemLoader.destroy();
+ systemLoader = null;
+ }
+}