extension-component-data.js (2111B)
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_TARGETS, 9 REQUEST_EXTENSIONS_SUCCESS, 10 } = require("resource://devtools/client/aboutdebugging/src/constants.js"); 11 12 const { 13 getExtensionUuid, 14 parseFileUri, 15 } = require("resource://devtools/client/aboutdebugging/src/modules/extensions-helper.js"); 16 17 /** 18 * This middleware converts extensions object that get from DevToolsClient.listAddons() 19 * to data which is used in DebugTargetItem. 20 */ 21 const extensionComponentDataMiddleware = () => next => action => { 22 switch (action.type) { 23 case REQUEST_EXTENSIONS_SUCCESS: { 24 action.installedExtensions = toComponentData(action.installedExtensions); 25 action.temporaryExtensions = toComponentData(action.temporaryExtensions); 26 break; 27 } 28 } 29 30 return next(action); 31 }; 32 33 function getFilePath(extension) { 34 // Only show file system paths, and only for temporarily installed add-ons. 35 if ( 36 !extension.temporarilyInstalled || 37 !extension.url || 38 !extension.url.startsWith("file://") 39 ) { 40 return null; 41 } 42 43 return parseFileUri(extension.url); 44 } 45 46 function toComponentData(extensions) { 47 return extensions.map(extension => { 48 const type = DEBUG_TARGETS.EXTENSION; 49 const { 50 actor, 51 backgroundScriptStatus, 52 iconDataURL, 53 iconURL, 54 id, 55 manifestURL, 56 name, 57 persistentBackgroundScript, 58 warnings, 59 } = extension; 60 const icon = 61 iconDataURL || 62 iconURL || 63 "chrome://mozapps/skin/extensions/extensionGeneric.svg"; 64 const location = getFilePath(extension); 65 const uuid = getExtensionUuid(extension); 66 return { 67 name, 68 icon, 69 id, 70 type, 71 details: { 72 actor, 73 backgroundScriptStatus, 74 location, 75 manifestURL, 76 persistentBackgroundScript, 77 uuid, 78 warnings: warnings || [], 79 }, 80 }; 81 }); 82 } 83 84 module.exports = extensionComponentDataMiddleware;