Bug 1651518 - [devtools] Ensure spawning DistinctSystemPrincipalLoader.sys.mjs only once. r=devtools-reviewers,nchevobbe

This is important to spawn this ESM only once between regular and browser toolbox,
and especially between various callsites used by the browser toolbox.
Otherwise we may start loading modules in two distinct system loaders
and may have inconsistancies when using `instanceof`.

Differential Revision: https://phabricator.services.mozilla.com/D207432
This commit is contained in:
Alexandre Poirot 2024-05-27 09:53:54 +00:00
parent 7b27af09b0
commit b4a695c2c0
12 changed files with 40 additions and 18 deletions

View File

@ -12,13 +12,16 @@ const CHROME_DEBUGGER_PROFILE_NAME = "chrome_debugger_profile";
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { require } from "resource://devtools/shared/loader/Loader.sys.mjs";
import {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} from "resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs";
import { Subprocess } from "resource://gre/modules/Subprocess.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
BackgroundTasksUtils: "resource://gre/modules/BackgroundTasksUtils.sys.mjs",

View File

@ -10,7 +10,8 @@ var { loader, require } = ChromeUtils.importESModule(
var { useDistinctSystemPrincipalLoader, releaseDistinctSystemPrincipalLoader } =
ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
// Require this module to setup core modules

View File

@ -16,7 +16,8 @@ let tracker, releaseTrackerLoader;
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
const requester = {};

View File

@ -32,7 +32,8 @@ if (DEBUG_ALLOCATIONS) {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
const requester = {};
const loader = useDistinctSystemPrincipalLoader(requester);
@ -78,7 +79,8 @@ if (DEBUG_STEP) {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
const requester = {};
const loader = useDistinctSystemPrincipalLoader(requester);

View File

@ -3,6 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const lazy = {};
ChromeUtils.defineESModuleGetters(
lazy,
{
loader: "resource://devtools/shared/loader/Loader.sys.mjs",
},
{ global: "contextual" }
);
ChromeUtils.defineESModuleGetters(
lazy,
{
@ -10,9 +18,8 @@ ChromeUtils.defineESModuleGetters(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
useDistinctSystemPrincipalLoader:
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
loader: "resource://devtools/shared/loader/Loader.sys.mjs",
},
{ global: "contextual" }
{ global: "shared" }
);
// Name of the attribute into which we save data in `sharedData` object.

View File

@ -21,7 +21,8 @@ export function initContentProcessTarget(msg) {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
// Use a unique object to identify this one usage of the loader

View File

@ -28,7 +28,8 @@ try {
customLoader = false;
if (content.document.nodePrincipal.isSystemPrincipal) {
const { useDistinctSystemPrincipalLoader } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
loader = useDistinctSystemPrincipalLoader(chromeGlobal);
customLoader = true;
@ -181,7 +182,8 @@ try {
if (customLoader) {
const { releaseDistinctSystemPrincipalLoader } =
ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
releaseDistinctSystemPrincipalLoader(chromeGlobal);
}

View File

@ -89,7 +89,8 @@ function getDistinctDevToolsServer() {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
const requester = {};
const distinctLoader = useDistinctSystemPrincipalLoader(requester);

View File

@ -7,7 +7,8 @@ const {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
const { DevToolsSocketStatus } = ChromeUtils.importESModule(

View File

@ -60,7 +60,8 @@ function distinct_system_principal_loader() {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
const requester = {};

View File

@ -7,7 +7,8 @@ const {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
function run_test() {

View File

@ -1091,7 +1091,8 @@ DevToolsStartup.prototype = {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs",
{ global: "shared" }
);
try {