DistinctSystemPrincipalLoader.sys.mjs (1626B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const { DevToolsLoader } = ChromeUtils.importESModule( 6 "resource://devtools/shared/loader/Loader.sys.mjs", 7 // `global: "devtools"` will import the loader in a special priviledged 8 // global created for DevTools, which will be reused as the shared global 9 // to load additional modules for the "DistinctSystemPrincipalLoader". 10 { global: "devtools" } 11 ); 12 13 // When debugging system principal resources (JSMs, chrome documents, ...) 14 // We have to load DevTools actors in another system principal global. 15 // That's mostly because of spidermonkey's Debugger API which requires 16 // debuggee and debugger to be in distinct principals. 17 // 18 // We try to hold a single instance of this special loader via this API. 19 // 20 // @param requester object 21 // Object/instance which is using the loader. 22 // The same requester object should be passed to release method. 23 let systemLoader = null; 24 const systemLoaderRequesters = new Set(); 25 26 export function useDistinctSystemPrincipalLoader(requester) { 27 if (!systemLoader) { 28 systemLoader = new DevToolsLoader({ 29 useDevToolsLoaderGlobal: true, 30 }); 31 systemLoaderRequesters.clear(); 32 } 33 systemLoaderRequesters.add(requester); 34 return systemLoader; 35 } 36 37 export function releaseDistinctSystemPrincipalLoader(requester) { 38 systemLoaderRequesters.delete(requester); 39 if (systemLoaderRequesters.size == 0) { 40 systemLoader.destroy(); 41 systemLoader = null; 42 } 43 }