debug-target-support.js (3499B)
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 "use strict"; 6 7 const { 8 DEBUG_TARGET_PANE, 9 PREFERENCES, 10 RUNTIMES, 11 } = require("resource://devtools/client/aboutdebugging/src/constants.js"); 12 13 // Process target debugging is disabled by default. 14 function isProcessDebuggingSupported() { 15 return Services.prefs.getBoolPref( 16 PREFERENCES.PROCESS_DEBUGGING_ENABLED, 17 false 18 ); 19 } 20 21 // Local tab debugging is disabled by default. 22 function isLocalTabDebuggingSupported() { 23 return Services.prefs.getBoolPref( 24 PREFERENCES.LOCAL_TAB_DEBUGGING_ENABLED, 25 false 26 ); 27 } 28 29 // Local process debugging is disabled by default. 30 // This preference has no default value in 31 // devtools/client/preferences/devtools-client.js 32 // because it is only intended for tests. 33 function isLocalProcessDebuggingSupported() { 34 return Services.prefs.getBoolPref( 35 "devtools.aboutdebugging.test-local-process-debugging", 36 false 37 ); 38 } 39 40 // Installing extensions can be disabled in enterprise policy. 41 // Note: Temporary Extensions are only supported when debugging This Firefox, so checking 42 // the local preference is acceptable here. If we enable Temporary extensions for remote 43 // runtimes, we should retrieve the preference from the target runtime instead. 44 function isTemporaryExtensionSupported() { 45 return Services.prefs.getBoolPref(PREFERENCES.XPINSTALL_ENABLED, true); 46 } 47 48 const ALL_DEBUG_TARGET_PANES = [ 49 DEBUG_TARGET_PANE.INSTALLED_EXTENSION, 50 ...(isProcessDebuggingSupported() ? [DEBUG_TARGET_PANE.PROCESSES] : []), 51 DEBUG_TARGET_PANE.OTHER_WORKER, 52 DEBUG_TARGET_PANE.SERVICE_WORKER, 53 DEBUG_TARGET_PANE.SHARED_WORKER, 54 DEBUG_TARGET_PANE.TAB, 55 ...(isTemporaryExtensionSupported() 56 ? [DEBUG_TARGET_PANE.TEMPORARY_EXTENSION] 57 : []), 58 ]; 59 60 // All debug target panes (to filter out if any of the panels should be excluded). 61 const REMOTE_DEBUG_TARGET_PANES = [...ALL_DEBUG_TARGET_PANES]; 62 63 const THIS_FIREFOX_DEBUG_TARGET_PANES = ALL_DEBUG_TARGET_PANES 64 // Main process debugging is not available for This Firefox. 65 // At the moment only the main process is listed under processes, so remove the category 66 // for this runtime. 67 .filter( 68 p => p !== DEBUG_TARGET_PANE.PROCESSES || isLocalProcessDebuggingSupported() 69 ) 70 // Showing tab targets for This Firefox is behind a preference. 71 .filter(p => p !== DEBUG_TARGET_PANE.TAB || isLocalTabDebuggingSupported()); 72 73 const SUPPORTED_TARGET_PANE_BY_RUNTIME = { 74 [RUNTIMES.THIS_FIREFOX]: THIS_FIREFOX_DEBUG_TARGET_PANES, 75 [RUNTIMES.USB]: REMOTE_DEBUG_TARGET_PANES, 76 [RUNTIMES.NETWORK]: REMOTE_DEBUG_TARGET_PANES, 77 }; 78 79 /** 80 * A debug target pane is more specialized than a debug target. For instance EXTENSION is 81 * a DEBUG_TARGET but INSTALLED_EXTENSION and TEMPORARY_EXTENSION are DEBUG_TARGET_PANES. 82 */ 83 function isSupportedDebugTargetPane(runtimeType, debugTargetPaneKey) { 84 return SUPPORTED_TARGET_PANE_BY_RUNTIME[runtimeType].includes( 85 debugTargetPaneKey 86 ); 87 } 88 exports.isSupportedDebugTargetPane = isSupportedDebugTargetPane; 89 90 /** 91 * Check if the given runtimeType supports temporary extension installation 92 * from about:debugging (currently disallowed on non-local runtimes). 93 */ 94 function supportsTemporaryExtensionInstaller(runtimeType) { 95 return runtimeType === RUNTIMES.THIS_FIREFOX; 96 } 97 exports.supportsTemporaryExtensionInstaller = 98 supportsTemporaryExtensionInstaller;