зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1796582 - [devtools] Load DistinctSystemPrincipalLoader in the dedicated DevToolsLoader global r=ochameau
Depends on D160215 Differential Revision: https://phabricator.services.mozilla.com/D160216
This commit is contained in:
Родитель
ec442d678c
Коммит
f18b983cde
|
@ -14,14 +14,9 @@ const {
|
|||
|
||||
const lazy = {};
|
||||
|
||||
loader.lazyGetter(lazy, "NetworkObserver", () => {
|
||||
const {
|
||||
NetworkObserver,
|
||||
} = ChromeUtils.importESModule(
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
NetworkObserver:
|
||||
"resource://devtools/server/actors/network-monitor/NetworkObserver.sys.mjs",
|
||||
{ loadInDevToolsLoader: loader.invisibleToDebugger }
|
||||
);
|
||||
return NetworkObserver;
|
||||
});
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
|
|
|
@ -9,30 +9,22 @@ const { isWindowGlobalPartOfContext } = ChromeUtils.importESModule(
|
|||
"resource://devtools/server/actors/watcher/browsing-context-helpers.sys.mjs"
|
||||
);
|
||||
const { WatcherRegistry } = ChromeUtils.importESModule(
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs"
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs",
|
||||
{
|
||||
// WatcherRegistry needs to be a true singleton and loads ActorManagerParent
|
||||
// which also has to be a true singleton.
|
||||
loadInDevToolsLoader: false,
|
||||
}
|
||||
);
|
||||
const Targets = require("resource://devtools/server/actors/targets/index.js");
|
||||
|
||||
const lazy = {};
|
||||
|
||||
loader.lazyGetter(lazy, "NetworkObserver", () => {
|
||||
const {
|
||||
NetworkObserver,
|
||||
} = ChromeUtils.importESModule(
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
NetworkObserver:
|
||||
"resource://devtools/server/actors/network-monitor/NetworkObserver.sys.mjs",
|
||||
{ loadInDevToolsLoader: loader.invisibleToDebugger }
|
||||
);
|
||||
return NetworkObserver;
|
||||
});
|
||||
|
||||
loader.lazyGetter(lazy, "NetworkUtils", () => {
|
||||
const {
|
||||
NetworkUtils,
|
||||
} = ChromeUtils.importESModule(
|
||||
NetworkUtils:
|
||||
"resource://devtools/server/actors/network-monitor/utils/NetworkUtils.sys.mjs",
|
||||
{ loadInDevToolsLoader: loader.invisibleToDebugger }
|
||||
);
|
||||
return NetworkUtils;
|
||||
});
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
|
|
|
@ -11,7 +11,12 @@ const { TargetActorRegistry } = ChromeUtils.importESModule(
|
|||
"resource://devtools/server/actors/targets/target-actor-registry.sys.mjs"
|
||||
);
|
||||
const { WatcherRegistry } = ChromeUtils.importESModule(
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs"
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs",
|
||||
{
|
||||
// WatcherRegistry needs to be a true singleton and loads ActorManagerParent
|
||||
// which also has to be a true singleton.
|
||||
loadInDevToolsLoader: false,
|
||||
}
|
||||
);
|
||||
const Targets = require("resource://devtools/server/actors/targets/index.js");
|
||||
const { getAllBrowsingContextsForContext } = ChromeUtils.importESModule(
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
"use strict";
|
||||
|
||||
const { WatcherRegistry } = ChromeUtils.importESModule(
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs"
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs",
|
||||
{
|
||||
// WatcherRegistry needs to be a true singleton and loads ActorManagerParent
|
||||
// which also has to be a true singleton.
|
||||
loadInDevToolsLoader: false,
|
||||
}
|
||||
);
|
||||
const { WindowGlobalLogger } = ChromeUtils.importESModule(
|
||||
"resource://devtools/server/connectors/js-window-actor/WindowGlobalLogger.sys.mjs"
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
"use strict";
|
||||
|
||||
const { WatcherRegistry } = ChromeUtils.importESModule(
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs"
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs",
|
||||
{
|
||||
// WatcherRegistry needs to be a true singleton and loads ActorManagerParent
|
||||
// which also has to be a true singleton.
|
||||
loadInDevToolsLoader: false,
|
||||
}
|
||||
);
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
|
|
|
@ -4,7 +4,15 @@
|
|||
|
||||
import { loader } from "resource://devtools/shared/loader/Loader.sys.mjs";
|
||||
import { EventEmitter } from "resource://gre/modules/EventEmitter.sys.mjs";
|
||||
import { WatcherRegistry } from "resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs";
|
||||
|
||||
const { WatcherRegistry } = ChromeUtils.importESModule(
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs",
|
||||
{
|
||||
// WatcherRegistry needs to be a true singleton and loads ActorManagerParent
|
||||
// which also has to be a true singleton.
|
||||
loadInDevToolsLoader: false,
|
||||
}
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
|
|
|
@ -4,7 +4,15 @@
|
|||
|
||||
import { loader } from "resource://devtools/shared/loader/Loader.sys.mjs";
|
||||
import { EventEmitter } from "resource://gre/modules/EventEmitter.sys.mjs";
|
||||
import { WatcherRegistry } from "resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs";
|
||||
|
||||
const { WatcherRegistry } = ChromeUtils.importESModule(
|
||||
"resource://devtools/server/actors/watcher/WatcherRegistry.sys.mjs",
|
||||
{
|
||||
// WatcherRegistry needs to be a true singleton and loads ActorManagerParent
|
||||
// which also has to be a true singleton.
|
||||
loadInDevToolsLoader: false,
|
||||
}
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const { DevToolsLoader } = ChromeUtils.importESModule(
|
||||
"resource://devtools/shared/loader/Loader.sys.mjs"
|
||||
"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, ...)
|
||||
|
@ -22,7 +28,7 @@ const systemLoaderRequesters = new Set();
|
|||
export function useDistinctSystemPrincipalLoader(requester) {
|
||||
if (!systemLoader) {
|
||||
systemLoader = new DevToolsLoader({
|
||||
invisibleToDebugger: true,
|
||||
useDevToolsLoaderGlobal: true,
|
||||
});
|
||||
systemLoaderRequesters.clear();
|
||||
}
|
||||
|
|
|
@ -31,11 +31,23 @@ var gNextLoaderID = 0;
|
|||
* We use this in order to debug modules loaded in this shared system
|
||||
* compartment. The debugger actor has to be running in a distinct
|
||||
* compartment than the context it is debugging.
|
||||
* @param useDevToolsLoaderGlobal boolean
|
||||
* If true, the loader will reuse the current global to load other
|
||||
* modules instead of creating a sandbox with custom options. Cannot be
|
||||
* used with invisibleToDebugger and/or freshCompartment.
|
||||
* TODO: This should ultimately replace invisibleToDebugger.
|
||||
*/
|
||||
export function DevToolsLoader({
|
||||
invisibleToDebugger = false,
|
||||
freshCompartment = false,
|
||||
useDevToolsLoaderGlobal = false,
|
||||
} = {}) {
|
||||
if (useDevToolsLoaderGlobal && (invisibleToDebugger || freshCompartment)) {
|
||||
throw new Error(
|
||||
"Loader cannot use invisibleToDebugger or freshCompartment if useDevToolsLoaderGlobal is true"
|
||||
);
|
||||
}
|
||||
|
||||
const paths = {
|
||||
// This resource:// URI is only registered when running DAMP tests.
|
||||
// This is done by: testing/talos/talos/tests/devtools/addon/api.js
|
||||
|
@ -55,8 +67,12 @@ export function DevToolsLoader({
|
|||
"toolkit/locales": "chrome://global/locale",
|
||||
};
|
||||
|
||||
const sharedGlobal = useDevToolsLoaderGlobal
|
||||
? Cu.getGlobalForObject({})
|
||||
: undefined;
|
||||
this.loader = new Loader({
|
||||
paths,
|
||||
sharedGlobal,
|
||||
invisibleToDebugger,
|
||||
freshCompartment,
|
||||
sandboxName: "DevTools (Module loader)",
|
||||
|
@ -130,7 +146,7 @@ export function DevToolsLoader({
|
|||
|
||||
// Register custom globals to the current loader instance
|
||||
Object.defineProperties(
|
||||
this.loader.globals,
|
||||
this.loader.sharedGlobal,
|
||||
Object.getOwnPropertyDescriptors(globals)
|
||||
);
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ function join(base, ...paths) {
|
|||
// @see https://searchfox.org/mozilla-central/rev/0948667bc62415d48abff27e1405fb4ab4d65d75/js/xpconnect/idl/xpccomponents.idl#127-245
|
||||
function Sandbox(options) {
|
||||
// Normalize options and rename to match `Cu.Sandbox` expectations.
|
||||
options = {
|
||||
const sandboxOptions = {
|
||||
// This will allow exposing Components as well as Cu, Ci and Cr.
|
||||
wantComponents: true,
|
||||
|
||||
|
@ -149,7 +149,7 @@ function Sandbox(options) {
|
|||
freshCompartment: options.freshCompartment || false,
|
||||
};
|
||||
|
||||
return Cu.Sandbox(systemPrincipal, options);
|
||||
return Cu.Sandbox(systemPrincipal, sandboxOptions);
|
||||
}
|
||||
|
||||
// This allows defining some modules in AMD format while retaining CommonJS
|
||||
|
@ -180,14 +180,14 @@ function load(loader, module) {
|
|||
properties.define = define;
|
||||
}
|
||||
|
||||
// Create a new object in this sandbox, that will be used as
|
||||
// the scope object for this particular module
|
||||
const sandbox = new loader.sharedGlobalSandbox.Object();
|
||||
Object.assign(sandbox, properties);
|
||||
// Create a new object in the shared global of the loader, that will be used
|
||||
// as the scope object for this particular module.
|
||||
const scopeFromSharedGlobal = new loader.sharedGlobal.Object();
|
||||
Object.assign(scopeFromSharedGlobal, properties);
|
||||
|
||||
const originalExports = module.exports;
|
||||
try {
|
||||
Services.scriptloader.loadSubScript(module.uri, sandbox);
|
||||
Services.scriptloader.loadSubScript(module.uri, scopeFromSharedGlobal);
|
||||
} catch (error) {
|
||||
// loadSubScript sometime throws string errors, which includes no stack.
|
||||
// At least provide the current stack by re-throwing a real Error object.
|
||||
|
@ -538,24 +538,30 @@ function Loader(options) {
|
|||
modules[uri] = module;
|
||||
}
|
||||
|
||||
// Create the unique sandbox we will be using for all modules,
|
||||
// so that we prevent creating a new compartment per module.
|
||||
// The side effect is that all modules will share the same
|
||||
// global objects.
|
||||
const sharedGlobalSandbox = Sandbox({
|
||||
name: options.sandboxName || "DevTools",
|
||||
invisibleToDebugger: options.invisibleToDebugger || false,
|
||||
prototype: options.sandboxPrototype || globals,
|
||||
freshCompartment: options.freshCompartment,
|
||||
});
|
||||
let sharedGlobal;
|
||||
if (options.sharedGlobal) {
|
||||
sharedGlobal = options.sharedGlobal;
|
||||
} else {
|
||||
// Create the unique sandbox we will be using for all modules,
|
||||
// so that we prevent creating a new compartment per module.
|
||||
// The side effect is that all modules will share the same
|
||||
// global objects.
|
||||
sharedGlobal = Sandbox({
|
||||
name: options.sandboxName || "DevTools",
|
||||
invisibleToDebugger: options.invisibleToDebugger || false,
|
||||
prototype: options.sandboxPrototype || globals,
|
||||
freshCompartment: options.freshCompartment,
|
||||
});
|
||||
}
|
||||
|
||||
if (options.sandboxPrototype) {
|
||||
// If we were given a sandboxPrototype, we have to define the globals on
|
||||
// the sandbox directly. Note that this will not work for callers who
|
||||
// depend on being able to add globals after the loader was created.
|
||||
if (options.sharedGlobal || options.sandboxPrototype) {
|
||||
// If we were given a sharedGlobal or a sandboxPrototype, we have to define
|
||||
// the globals on the shared global directly. Note that this will not work
|
||||
// for callers who depend on being able to add globals after the loader was
|
||||
// created.
|
||||
for (const name of getOwnIdentifiers(globals)) {
|
||||
Object.defineProperty(
|
||||
sharedGlobalSandbox,
|
||||
sharedGlobal,
|
||||
name,
|
||||
Object.getOwnPropertyDescriptor(globals, name)
|
||||
);
|
||||
|
@ -572,7 +578,7 @@ function Loader(options) {
|
|||
mappingCache: { enumerable: false, value: new Map() },
|
||||
// Map of module objects indexed by module URIs.
|
||||
modules: { enumerable: false, value: modules },
|
||||
sharedGlobalSandbox: { enumerable: false, value: sharedGlobalSandbox },
|
||||
sharedGlobal: { enumerable: false, value: sharedGlobal },
|
||||
supportAMDModules: {
|
||||
enumerable: false,
|
||||
value: options.supportAMDModules || false,
|
||||
|
|
Загрузка…
Ссылка в новой задаче