service-container.js (2861B)
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 createContextMenu, 9 } = require("resource://devtools/client/webconsole/utils/context-menu.js"); 10 11 const { 12 createEditContextMenu, 13 } = require("resource://devtools/client/framework/toolbox-context-menu.js"); 14 const { 15 getLongStringFullText, 16 } = require("resource://devtools/client/shared/string-utils.js"); 17 18 function setupServiceContainer({ 19 webConsoleUI, 20 hud, 21 toolbox, 22 webConsoleWrapper, 23 }) { 24 const serviceContainer = { 25 openContextMenu: (event, message) => 26 createContextMenu(event, message, webConsoleWrapper), 27 28 openEditContextMenu: event => { 29 const { screenX, screenY } = event; 30 const menu = createEditContextMenu(window, "webconsole-menu"); 31 // Emit the "menu-open" event for testing. 32 menu.once("open", () => webConsoleWrapper.emitForTests("menu-open")); 33 menu.popup(screenX, screenY, hud.chromeWindow.document); 34 }, 35 36 // NOTE these methods are proxied currently because the 37 // service container is passed down the tree. These methods should eventually 38 // be moved to redux actions. 39 recordTelemetryEvent: (event, extra = {}) => hud.recordEvent(event, extra), 40 openLink: (url, e) => hud.openLink(url, e), 41 openNodeInInspector: grip => hud.openNodeInInspector(grip), 42 getInputSelection: () => hud.getInputSelection(), 43 onViewSource: location => hud.viewSource(location.url, location.line), 44 resendNetworkRequest: requestId => hud.resendNetworkRequest(requestId), 45 focusInput: () => hud.focusInput(), 46 setInputValue: value => hud.setInputValue(value), 47 getLongString: grip => getLongStringFullText(hud.commands.client, grip), 48 getJsTermTooltipAnchor: () => webConsoleUI.getJsTermTooltipAnchor(), 49 emitForTests: (event, value) => webConsoleUI.emitForTests(event, value), 50 attachRefToWebConsoleUI: (id, node) => webConsoleUI.attachRef(id, node), 51 requestData: (id, type) => 52 webConsoleUI.networkDataProvider.requestData(id, type), 53 createElement: nodename => webConsoleWrapper.createElement(nodename), 54 getToolboxStore: () => null, 55 }; 56 57 if (toolbox) { 58 const { highlight, unhighlight } = toolbox.getHighlighter(); 59 60 Object.assign(serviceContainer, { 61 getToolboxStore: () => toolbox.store, 62 sourceMapURLService: toolbox.sourceMapURLService, 63 highlightDomElement: highlight, 64 unHighlightDomElement: unhighlight, 65 onViewSourceInDebugger: location => hud.onViewSourceInDebugger(location), 66 onViewSourceInStyleEditor: location => 67 hud.onViewSourceInStyleEditor(location), 68 }); 69 } 70 71 return serviceContainer; 72 } 73 74 module.exports.setupServiceContainer = setupServiceContainer;