frame.js (3004B)
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 import { showMenu } from "../../context-menu/menu"; 6 import { copyToTheClipboard } from "../../utils/clipboard"; 7 import { 8 getShouldSelectOriginalLocation, 9 getCurrentThreadFrames, 10 getFrameworkGroupingState, 11 } from "../../selectors/index"; 12 import { toggleFrameworkGrouping } from "../../actions/ui"; 13 import { restart, toggleBlackBox } from "../../actions/pause/index"; 14 import { formatCopyName } from "../../utils/pause/frames/index"; 15 16 function formatMenuElement(labelString, click, disabled = false) { 17 const label = L10N.getStr(labelString); 18 const accesskey = L10N.getStr(`${labelString}.accesskey`); 19 const id = `node-menu-${labelString}`; 20 return { 21 id, 22 label, 23 accesskey, 24 disabled, 25 click, 26 }; 27 } 28 29 function isValidRestartFrame(frame) { 30 // Any frame state than 'on-stack' is either dismissed by the server 31 // or can potentially cause unexpected errors. 32 // Global frame has frame.callee equal to null and can't be restarted. 33 return frame.type === "call" && frame.state === "on-stack"; 34 } 35 36 function copyStackTrace() { 37 return async ({ getState }) => { 38 const frames = getCurrentThreadFrames(getState()); 39 const shouldDisplayOriginalLocation = 40 getShouldSelectOriginalLocation(getState()); 41 42 const framesToCopy = frames 43 .map(frame => formatCopyName(frame, L10N, shouldDisplayOriginalLocation)) 44 .join("\n"); 45 copyToTheClipboard(framesToCopy); 46 }; 47 } 48 49 export function showFrameContextMenu(event, frame, hideRestart = false) { 50 return async ({ dispatch, getState }) => { 51 const items = []; 52 53 // Hides 'Restart Frame' item for call stack groups context menu, 54 // otherwise can be misleading for the user which frame gets restarted. 55 if (!hideRestart && isValidRestartFrame(frame)) { 56 items.push( 57 formatMenuElement("restartFrame", () => dispatch(restart(frame))) 58 ); 59 } 60 61 const toggleFrameWorkL10nLabel = getFrameworkGroupingState(getState()) 62 ? "framework.disableGrouping" 63 : "framework.enableGrouping"; 64 items.push( 65 formatMenuElement(toggleFrameWorkL10nLabel, () => 66 dispatch( 67 toggleFrameworkGrouping(!getFrameworkGroupingState(getState())) 68 ) 69 ) 70 ); 71 72 const { source } = frame; 73 if (frame.source) { 74 items.push( 75 formatMenuElement("copySourceUri2", () => 76 copyToTheClipboard(source.url) 77 ) 78 ); 79 80 const toggleBlackBoxL10nLabel = source.isBlackBoxed 81 ? "ignoreContextItem.unignore" 82 : "ignoreContextItem.ignore"; 83 items.push( 84 formatMenuElement(toggleBlackBoxL10nLabel, () => 85 dispatch(toggleBlackBox(source)) 86 ) 87 ); 88 } 89 90 items.push( 91 formatMenuElement("copyStackTrace", () => dispatch(copyStackTrace())) 92 ); 93 94 showMenu(event, items); 95 }; 96 }