|
Lines 33-49
WI.QuickConsole = class QuickConsole extends WI.View
a/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js_sec1
|
| 33 |
this._toggleOrFocusKeyboardShortcut.implicitlyPreventsDefault = false; |
33 |
this._toggleOrFocusKeyboardShortcut.implicitlyPreventsDefault = false; |
| 34 |
this._keyboardShortcutDisabled = false; |
34 |
this._keyboardShortcutDisabled = false; |
| 35 |
|
35 |
|
| 36 |
this._automaticExecutionContextPathComponent = this._createExecutionContextPathComponent(null, WI.UIString("Auto")); |
36 |
this._useExecutionContextOfInspectedNode = InspectorBackend.hasDomain("DOM"); |
| 37 |
this._updateAutomaticExecutionContextPathComponentTooltip(); |
37 |
this._restoreSelectedExecutionContextForFrame = null; |
| 38 |
|
|
|
| 39 |
this._mainExecutionContextPathComponent = null; |
| 40 |
this._otherExecutionContextPathComponents = []; |
| 41 |
|
| 42 |
this._frameToPathComponent = new Map; |
| 43 |
this._targetToPathComponent = new Map; |
| 44 |
|
| 45 |
this._shouldAutomaticallySelectExecutionContext = true; |
| 46 |
this._restoreSelectedExecutionContextForFrame = false; |
| 47 |
|
38 |
|
| 48 |
this.element.classList.add("quick-console"); |
39 |
this.element.classList.add("quick-console"); |
| 49 |
this.element.addEventListener("mousedown", this._handleMouseDown.bind(this)); |
40 |
this.element.addEventListener("mousedown", this._handleMouseDown.bind(this)); |
|
Lines 60-107
WI.QuickConsole = class QuickConsole extends WI.View
a/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js_sec2
|
| 60 |
// would be for CodeMirror's event handler to pass if it doesn't do anything. |
51 |
// would be for CodeMirror's event handler to pass if it doesn't do anything. |
| 61 |
this.prompt.escapeKeyHandlerWhenEmpty = function() { WI.toggleSplitConsole(); }; |
52 |
this.prompt.escapeKeyHandlerWhenEmpty = function() { WI.toggleSplitConsole(); }; |
| 62 |
|
53 |
|
| 63 |
this._navigationBar = new WI.QuickConsoleNavigationBar; |
54 |
this._navigationBar = new WI.SizesToFitNavigationBar; |
| 64 |
this.addSubview(this._navigationBar); |
55 |
this.addSubview(this._navigationBar); |
| 65 |
|
56 |
|
| 66 |
this._executionContextSelectorItem = new WI.HierarchicalPathNavigationItem; |
57 |
this._activeExecutionContextNavigationItemDivider = new WI.DividerNavigationItem; |
| 67 |
this._executionContextSelectorItem.showSelectorArrows = true; |
58 |
this._navigationBar.addNavigationItem(this._activeExecutionContextNavigationItemDivider); |
| 68 |
this._navigationBar.addNavigationItem(this._executionContextSelectorItem); |
|
|
| 69 |
|
59 |
|
| 70 |
this._executionContextSelectorDivider = new WI.DividerNavigationItem; |
60 |
this._activeExecutionContextNavigationItem = new WI.NavigationItem("active-execution-context"); |
| 71 |
this._navigationBar.addNavigationItem(this._executionContextSelectorDivider); |
61 |
WI.addMouseDownContextMenuHandlers(this._activeExecutionContextNavigationItem.element, this._populateActiveExecutionContextNavigationItemContextMenu.bind(this)); |
|
|
62 |
this._navigationBar.addNavigationItem(this._activeExecutionContextNavigationItem); |
| 72 |
|
63 |
|
| 73 |
WI.settings.consoleSavedResultAlias.addEventListener(WI.Setting.Event.Changed, this._updateAutomaticExecutionContextPathComponentTooltip, this); |
64 |
this._updateActiveExecutionContextDisplay(); |
| 74 |
|
65 |
|
| 75 |
WI.consoleDrawer.toggleButtonShortcutTooltip(this._toggleOrFocusKeyboardShortcut); |
66 |
WI.settings.consoleSavedResultAlias.addEventListener(WI.Setting.Event.Changed, this._handleConsoleSavedResultAliasSettingChanged, this); |
| 76 |
WI.consoleDrawer.addEventListener(WI.ConsoleDrawer.Event.CollapsedStateChanged, this._updateStyles, this); |
67 |
WI.settings.engineeringShowInternalExecutionContexts.addEventListener(WI.Setting.Event.Changed, this._handleEngineeringShowInternalExecutionContextsSettingChanged, this); |
| 77 |
|
68 |
|
| 78 |
WI.Frame.addEventListener(WI.Frame.Event.PageExecutionContextChanged, this._framePageExecutionContextsChanged, this); |
69 |
WI.Frame.addEventListener(WI.Frame.Event.PageExecutionContextChanged, this._handleFramePageExecutionContextChanged, this); |
| 79 |
WI.Frame.addEventListener(WI.Frame.Event.ExecutionContextsCleared, this._frameExecutionContextsCleared, this); |
70 |
WI.Frame.addEventListener(WI.Frame.Event.ExecutionContextsCleared, this._handleFrameExecutionContextsCleared, this); |
| 80 |
|
71 |
|
| 81 |
WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ActiveCallFrameDidChange, this._debuggerActiveCallFrameDidChange, this); |
72 |
WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.ActiveCallFrameDidChange, this._handleDebuggerActiveCallFrameDidChange, this); |
| 82 |
|
73 |
|
| 83 |
WI.runtimeManager.addEventListener(WI.RuntimeManager.Event.ActiveExecutionContextChanged, this._activeExecutionContextChanged, this); |
74 |
WI.runtimeManager.addEventListener(WI.RuntimeManager.Event.ActiveExecutionContextChanged, this._handleActiveExecutionContextChanged, this); |
| 84 |
WI.notifications.addEventListener(WI.Notification.TransitionPageTarget, this._pageTargetTransitioned, this); |
|
|
| 85 |
|
75 |
|
| 86 |
WI.targetManager.addEventListener(WI.TargetManager.Event.TargetAdded, this._targetAdded, this); |
76 |
WI.notifications.addEventListener(WI.Notification.TransitionPageTarget, this._handleTransitionPageTarget, this); |
| 87 |
WI.targetManager.addEventListener(WI.TargetManager.Event.TargetRemoved, this._targetRemoved, this); |
77 |
|
|
|
78 |
WI.targetManager.addEventListener(WI.TargetManager.Event.TargetRemoved, this._handleTargetRemoved, this); |
| 88 |
|
79 |
|
| 89 |
WI.domManager.addEventListener(WI.DOMManager.Event.InspectedNodeChanged, this._handleInspectedNodeChanged, this); |
80 |
WI.domManager.addEventListener(WI.DOMManager.Event.InspectedNodeChanged, this._handleInspectedNodeChanged, this); |
| 90 |
|
81 |
|
|
|
82 |
WI.consoleDrawer.toggleButtonShortcutTooltip(this._toggleOrFocusKeyboardShortcut); |
| 83 |
WI.consoleDrawer.addEventListener(WI.ConsoleDrawer.Event.CollapsedStateChanged, this._updateStyles, this); |
| 91 |
WI.TabBrowser.addEventListener(WI.TabBrowser.Event.SelectedTabContentViewDidChange, this._updateStyles, this); |
84 |
WI.TabBrowser.addEventListener(WI.TabBrowser.Event.SelectedTabContentViewDidChange, this._updateStyles, this); |
| 92 |
|
85 |
|
| 93 |
WI.whenTargetsAvailable().then(() => { |
86 |
WI.whenTargetsAvailable().then(() => { |
| 94 |
this._initializeMainExecutionContextPathComponent(); |
87 |
this._updateActiveExecutionContextDisplay(); |
| 95 |
}); |
88 |
}); |
| 96 |
} |
89 |
} |
| 97 |
|
90 |
|
| 98 |
// Public |
91 |
// Public |
| 99 |
|
92 |
|
| 100 |
get navigationBar() |
|
|
| 101 |
{ |
| 102 |
return this._navigationBar; |
| 103 |
} |
| 104 |
|
| 105 |
set keyboardShortcutDisabled(disabled) |
93 |
set keyboardShortcutDisabled(disabled) |
| 106 |
{ |
94 |
{ |
| 107 |
this._keyboardShortcutDisabled = disabled; |
95 |
this._keyboardShortcutDisabled = disabled; |
|
Lines 120-194
WI.QuickConsole = class QuickConsole extends WI.View
a/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js_sec3
|
| 120 |
super.closed(); |
108 |
super.closed(); |
| 121 |
} |
109 |
} |
| 122 |
|
110 |
|
| 123 |
_pageTargetTransitioned() |
|
|
| 124 |
{ |
| 125 |
this._initializeMainExecutionContextPathComponent(); |
| 126 |
} |
| 127 |
|
| 128 |
_initializeMainExecutionContextPathComponent() |
| 129 |
{ |
| 130 |
if (!WI.mainTarget || WI.mainTarget instanceof WI.MultiplexingBackendTarget) |
| 131 |
return; |
| 132 |
|
| 133 |
let nextSibling = this._mainExecutionContextPathComponent ? this._mainExecutionContextPathComponent.nextSibling : null; |
| 134 |
|
| 135 |
this._mainExecutionContextPathComponent = this._createExecutionContextPathComponent(WI.mainTarget.executionContext); |
| 136 |
this._mainExecutionContextPathComponent.previousSibling = this._automaticExecutionContextPathComponent; |
| 137 |
this._mainExecutionContextPathComponent.nextSibling = nextSibling; |
| 138 |
|
| 139 |
this._automaticExecutionContextPathComponent.nextSibling = this._mainExecutionContextPathComponent; |
| 140 |
|
| 141 |
this._shouldAutomaticallySelectExecutionContext = true; |
| 142 |
this._selectExecutionContext(WI.mainTarget.executionContext); |
| 143 |
this._rebuildExecutionContextPathComponents(); |
| 144 |
} |
| 145 |
|
| 146 |
// Protected |
| 147 |
|
| 148 |
layout() |
| 149 |
{ |
| 150 |
// A hard maximum size of 33% of the window. |
| 151 |
let maximumAllowedHeight = Math.round(window.innerHeight * 0.33); |
| 152 |
this.prompt.element.style.maxHeight = maximumAllowedHeight + "px"; |
| 153 |
} |
| 154 |
|
| 155 |
// Private |
111 |
// Private |
| 156 |
|
112 |
|
| 157 |
_preferredNameForFrame(frame) |
113 |
_displayNameForExecutionContext(context, maxLength = Infinity) |
| 158 |
{ |
114 |
{ |
| 159 |
if (frame.name) |
115 |
function truncate(string, length) { |
| 160 |
return WI.UIString("%s (%s)").format(frame.name, frame.mainResource.displayName); |
116 |
if (!Number.isFinite(maxLength)) |
| 161 |
return frame.mainResource.displayName; |
117 |
return string; |
| 162 |
} |
118 |
return string.trim().truncateMiddle(length); |
|
|
119 |
} |
| 163 |
|
120 |
|
| 164 |
_selectExecutionContext(executionContext) |
121 |
if (context.type === WI.ExecutionContext.Type.Internal) |
| 165 |
{ |
122 |
return WI.unlocalizedString("[Internal] ") + context.name; |
| 166 |
let preferredName = null; |
|
|
| 167 |
|
123 |
|
| 168 |
let inspectedNode = WI.domManager.inspectedNode; |
124 |
let target = context.target; |
| 169 |
if (inspectedNode) { |
125 |
if (target.type === WI.TargetType.Worker) |
| 170 |
let frame = inspectedNode.frame; |
126 |
return truncate(target.displayName, maxLength); |
| 171 |
if (frame) { |
127 |
|
| 172 |
if (this._shouldAutomaticallySelectExecutionContext) |
128 |
let frame = context.frame; |
| 173 |
executionContext = frame.pageExecutionContext; |
129 |
if (frame) { |
| 174 |
preferredName = this._preferredNameForFrame(frame); |
130 |
if (context === frame.executionContextList.pageExecutionContext) { |
|
|
131 |
let resourceName = frame.mainResource.displayName; |
| 132 |
let frameName = frame.name; |
| 133 |
if (frameName) { |
| 134 |
// Attempt to show all of the frame name, but ensure that at least 20 characters |
| 135 |
// of the resource name are shown as well. |
| 136 |
let frameNameMaxLength = Math.max(maxLength - resourceName.length, 20); |
| 137 |
return WI.UIString("%s (%s)").format(truncate(frameName, frameNameMaxLength), truncate(resourceName, maxLength - frameNameMaxLength)); |
| 138 |
} |
| 139 |
return truncate(resourceName, maxLength); |
| 175 |
} |
140 |
} |
| 176 |
} |
141 |
} |
| 177 |
|
142 |
|
| 178 |
if (!executionContext) |
143 |
return truncate(context.name, maxLength); |
| 179 |
executionContext = WI.mainTarget.executionContext; |
|
|
| 180 |
|
| 181 |
this._automaticExecutionContextPathComponent.displayName = WI.UIString("Auto - %s").format(preferredName || executionContext.name); |
| 182 |
|
| 183 |
let changed = WI.runtimeManager.activeExecutionContext !== executionContext; |
| 184 |
if (changed) |
| 185 |
WI.runtimeManager.activeExecutionContext = executionContext; |
| 186 |
return changed; |
| 187 |
} |
144 |
} |
| 188 |
|
145 |
|
| 189 |
_updateAutomaticExecutionContextPathComponentTooltip() |
146 |
_resolveDesiredActiveExecutionContext(forceInspectedNode) |
| 190 |
{ |
147 |
{ |
| 191 |
this._automaticExecutionContextPathComponent.tooltip = WI.UIString("Execution context for %s").format(WI.RuntimeManager.preferredSavedResultPrefix() + "0"); |
148 |
let executionContext = null; |
|
|
149 |
|
| 150 |
if (this._useExecutionContextOfInspectedNode || forceInspectedNode) { |
| 151 |
let inspectedNode = WI.domManager.inspectedNode; |
| 152 |
if (inspectedNode) { |
| 153 |
let frame = inspectedNode.frame; |
| 154 |
if (frame) { |
| 155 |
let pageExecutionContext = frame.pageExecutionContext; |
| 156 |
if (pageExecutionContext) |
| 157 |
executionContext = pageExecutionContext; |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
if (!executionContext && WI.networkManager.mainFrame) |
| 163 |
executionContext = WI.networkManager.mainFrame.pageExecutionContext; |
| 164 |
|
| 165 |
return executionContext || WI.mainTarget.executionContext; |
| 166 |
} |
| 167 |
|
| 168 |
_setActiveExecutionContext(context) |
| 169 |
{ |
| 170 |
let wasActive = WI.runtimeManager.activeExecutionContext === context; |
| 171 |
|
| 172 |
WI.runtimeManager.activeExecutionContext = context; |
| 173 |
|
| 174 |
if (wasActive) |
| 175 |
this._updateActiveExecutionContextDisplay(); |
| 176 |
} |
| 177 |
|
| 178 |
_updateActiveExecutionContextDisplay() |
| 179 |
{ |
| 180 |
let toggleHidden = (hidden) => { |
| 181 |
this._activeExecutionContextNavigationItemDivider.hidden = hidden; |
| 182 |
this._activeExecutionContextNavigationItem.hidden = hidden; |
| 183 |
}; |
| 184 |
|
| 185 |
if (WI.debuggerManager.activeCallFrame) { |
| 186 |
toggleHidden(true); |
| 187 |
return; |
| 188 |
} |
| 189 |
|
| 190 |
if (!WI.runtimeManager.activeExecutionContext || !WI.networkManager.mainFrame) { |
| 191 |
toggleHidden(true); |
| 192 |
return; |
| 193 |
} |
| 194 |
|
| 195 |
if (WI.networkManager.frames.length === 1 && WI.networkManager.mainFrame.executionContextList.contexts.length === 1 && !WI.targetManager.workerTargets.length) { |
| 196 |
toggleHidden(true); |
| 197 |
return; |
| 198 |
} |
| 199 |
|
| 200 |
const maxLength = 40; |
| 201 |
|
| 202 |
if (this._useExecutionContextOfInspectedNode) { |
| 203 |
this._activeExecutionContextNavigationItem.element.classList.add("automatic"); |
| 204 |
this._activeExecutionContextNavigationItem.element.textContent = WI.UIString("Auto \u2014 %s").format(this._displayNameForExecutionContext(WI.runtimeManager.activeExecutionContext, maxLength)); |
| 205 |
this._activeExecutionContextNavigationItem.tooltip = WI.UIString("Execution context for %s").format(WI.RuntimeManager.preferredSavedResultPrefix() + "0"); |
| 206 |
} else { |
| 207 |
this._activeExecutionContextNavigationItem.element.classList.remove("automatic"); |
| 208 |
this._activeExecutionContextNavigationItem.element.textContent = this._displayNameForExecutionContext(WI.runtimeManager.activeExecutionContext, maxLength); |
| 209 |
this._activeExecutionContextNavigationItem.tooltip = this._displayNameForExecutionContext(WI.runtimeManager.activeExecutionContext); |
| 210 |
} |
| 211 |
|
| 212 |
this._activeExecutionContextNavigationItem.element.appendChild(WI.ImageUtilities.useSVGSymbol("Images/UpDownArrows.svg", "selector-arrows")); |
| 213 |
|
| 214 |
toggleHidden(false); |
| 215 |
} |
| 216 |
|
| 217 |
_populateActiveExecutionContextNavigationItemContextMenu(contextMenu) |
| 218 |
{ |
| 219 |
const maxLength = 120; |
| 220 |
|
| 221 |
let activeExecutionContext = WI.runtimeManager.activeExecutionContext; |
| 222 |
|
| 223 |
if (InspectorBackend.hasDomain("DOM")) { |
| 224 |
let executionContextForInspectedNode = this._resolveDesiredActiveExecutionContext(true); |
| 225 |
contextMenu.appendCheckboxItem(WI.UIString("Auto \u2014 %s").format(this._displayNameForExecutionContext(executionContextForInspectedNode, maxLength)), () => { |
| 226 |
this._useExecutionContextOfInspectedNode = true; |
| 227 |
this._setActiveExecutionContext(executionContextForInspectedNode); |
| 228 |
}, this._useExecutionContextOfInspectedNode); |
| 229 |
|
| 230 |
contextMenu.appendSeparator(); |
| 231 |
} |
| 232 |
|
| 233 |
let indent = 0; |
| 234 |
let addExecutionContext = (context) => { |
| 235 |
if (context.type === WI.ExecutionContext.Type.Internal && !WI.settings.engineeringShowInternalExecutionContexts.value) |
| 236 |
return; |
| 237 |
|
| 238 |
let additionalIndent = (context.frame && context !== context.frame.executionContextList.pageExecutionContext) || context.type !== WI.ExecutionContext.Type.Normal; |
| 239 |
|
| 240 |
// Mimic macOS `-[NSMenuItem setIndentationLevel]`. |
| 241 |
contextMenu.appendCheckboxItem(" ".repeat(indent + additionalIndent) + this._displayNameForExecutionContext(context, maxLength), () => { |
| 242 |
this._useExecutionContextOfInspectedNode = false; |
| 243 |
this._setActiveExecutionContext(context); |
| 244 |
}, activeExecutionContext === context); |
| 245 |
}; |
| 246 |
|
| 247 |
let addExecutionContextsForFrame = (frame) => { |
| 248 |
let pageExecutionContext = frame.executionContextList.pageExecutionContext; |
| 249 |
|
| 250 |
let contexts = frame.executionContextList.contexts.sort((a, b) => { |
| 251 |
if (a === pageExecutionContext) |
| 252 |
return -1; |
| 253 |
if (b === pageExecutionContext) |
| 254 |
return 1; |
| 255 |
|
| 256 |
const executionContextTypeRanking = [ |
| 257 |
WI.ExecutionContext.Type.Normal, |
| 258 |
WI.ExecutionContext.Type.User, |
| 259 |
WI.ExecutionContext.Type.Internal, |
| 260 |
]; |
| 261 |
return executionContextTypeRanking.indexOf(a.type) - executionContextTypeRanking.indexOf(b.type); |
| 262 |
}); |
| 263 |
for (let context of contexts) |
| 264 |
addExecutionContext(context); |
| 265 |
}; |
| 266 |
|
| 267 |
let mainFrame = WI.networkManager.mainFrame; |
| 268 |
addExecutionContextsForFrame(mainFrame); |
| 269 |
|
| 270 |
indent = 1; |
| 271 |
|
| 272 |
let otherFrames = WI.networkManager.frames.filter((frame) => frame !== mainFrame && frame.executionContextList.pageExecutionContext); |
| 273 |
if (otherFrames.length) { |
| 274 |
contextMenu.appendHeader(WI.UIString("Frames")); |
| 275 |
|
| 276 |
for (let frame of otherFrames) |
| 277 |
addExecutionContextsForFrame(frame); |
| 278 |
} |
| 279 |
|
| 280 |
let workerTargets = WI.targetManager.workerTargets; |
| 281 |
if (workerTargets.length) { |
| 282 |
contextMenu.appendHeader(WI.UIString("Workers")); |
| 283 |
|
| 284 |
for (let target of workerTargets) |
| 285 |
addExecutionContext(target.executionContext); |
| 286 |
} |
| 192 |
} |
287 |
} |
| 193 |
|
288 |
|
| 194 |
_handleMouseDown(event) |
289 |
_handleMouseDown(event) |
|
Lines 226-453
WI.QuickConsole = class QuickConsole extends WI.View
a/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js_sec4
|
| 226 |
} |
321 |
} |
| 227 |
} |
322 |
} |
| 228 |
|
323 |
|
| 229 |
_executionContextPathComponentsToDisplay() |
324 |
_handleConsoleSavedResultAliasSettingChanged() |
| 230 |
{ |
325 |
{ |
| 231 |
// If we are in the debugger the console will use the active call frame, don't show the selector. |
326 |
this._updateActiveExecutionContextDisplay(); |
| 232 |
if (WI.debuggerManager.activeCallFrame) |
|
|
| 233 |
return []; |
| 234 |
|
| 235 |
// If there is only the Main ExecutionContext, don't show the selector. |
| 236 |
if (!this._otherExecutionContextPathComponents.length) |
| 237 |
return []; |
| 238 |
|
| 239 |
if (this._shouldAutomaticallySelectExecutionContext) |
| 240 |
return [this._automaticExecutionContextPathComponent]; |
| 241 |
|
| 242 |
if (WI.runtimeManager.activeExecutionContext === WI.mainTarget.executionContext) |
| 243 |
return [this._mainExecutionContextPathComponent]; |
| 244 |
|
| 245 |
return this._otherExecutionContextPathComponents.filter((component) => component.representedObject === WI.runtimeManager.activeExecutionContext); |
| 246 |
} |
327 |
} |
| 247 |
|
328 |
|
| 248 |
_rebuildExecutionContextPathComponents() |
329 |
_handleEngineeringShowInternalExecutionContextsSettingChanged(event) |
| 249 |
{ |
330 |
{ |
| 250 |
let components = this._executionContextPathComponentsToDisplay(); |
331 |
if (WI.runtimeManager.activeExecutionContext.type !== WI.ExecutionContext.Type.Internal) |
| 251 |
let isEmpty = !components.length; |
332 |
return; |
| 252 |
|
|
|
| 253 |
this._executionContextSelectorItem.element.classList.toggle("automatic-execution-context", this._shouldAutomaticallySelectExecutionContext); |
| 254 |
this._executionContextSelectorItem.components = components; |
| 255 |
|
| 256 |
this._executionContextSelectorItem.hidden = isEmpty; |
| 257 |
this._executionContextSelectorDivider.hidden = isEmpty; |
| 258 |
|
333 |
|
|
|
334 |
this._useExecutionContextOfInspectedNode = InspectorBackend.hasDomain("DOM"); |
| 335 |
this._setActiveExecutionContext(this._resolveDesiredActiveExecutionContext()); |
| 259 |
} |
336 |
} |
| 260 |
|
337 |
|
| 261 |
_framePageExecutionContextsChanged(event) |
338 |
_handleFramePageExecutionContextChanged(event) |
| 262 |
{ |
339 |
{ |
| 263 |
let frame = event.target; |
340 |
if (this._restoreSelectedExecutionContextForFrame !== event.target) |
|
|
341 |
return; |
| 264 |
|
342 |
|
| 265 |
let newExecutionContextPathComponent = this._insertExecutionContextPathComponentForFrame(frame); |
343 |
this._restoreSelectedExecutionContextForFrame = null; |
| 266 |
|
344 |
|
| 267 |
if (this._restoreSelectedExecutionContextForFrame === frame) { |
345 |
let {context} = event.data; |
| 268 |
this._restoreSelectedExecutionContextForFrame = null; |
|
|
| 269 |
|
346 |
|
| 270 |
this._selectExecutionContext(newExecutionContextPathComponent.representedObject); |
347 |
this._useExecutionContextOfInspectedNode = false; |
| 271 |
} |
348 |
this._setActiveExecutionContext(context); |
| 272 |
} |
349 |
} |
| 273 |
|
350 |
|
| 274 |
_frameExecutionContextsCleared(event) |
351 |
_handleFrameExecutionContextsCleared(event) |
| 275 |
{ |
352 |
{ |
| 276 |
let frame = event.target; |
353 |
let {committingProvisionalLoad, contexts} = event.data; |
|
|
354 |
|
| 355 |
let hasActiveExecutionContext = contexts.some((context) => context === WI.runtimeManager.activeExecutionContext); |
| 356 |
if (!hasActiveExecutionContext) |
| 357 |
return; |
| 277 |
|
358 |
|
| 278 |
// If this frame is navigating and it is selected in the UI we want to reselect its new item after navigation. |
359 |
// If this frame is navigating and it is selected in the UI we want to reselect its new item after navigation. |
| 279 |
if (event.data.committingProvisionalLoad && !this._restoreSelectedExecutionContextForFrame) { |
360 |
if (committingProvisionalLoad && !this._restoreSelectedExecutionContextForFrame) { |
| 280 |
let executionContextPathComponent = this._frameToPathComponent.get(frame); |
361 |
this._restoreSelectedExecutionContextForFrame = event.target; |
| 281 |
if (executionContextPathComponent && executionContextPathComponent.representedObject === WI.runtimeManager.activeExecutionContext) { |
|
|
| 282 |
this._restoreSelectedExecutionContextForFrame = frame; |
| 283 |
// As a fail safe, if the frame never gets an execution context, clear the restore value. |
| 284 |
setTimeout(() => { |
| 285 |
this._restoreSelectedExecutionContextForFrame = false; |
| 286 |
}, 10); |
| 287 |
} |
| 288 |
} |
| 289 |
|
362 |
|
| 290 |
this._removeExecutionContextPathComponentForFrame(frame); |
363 |
// As a fail safe, if the frame never gets an execution context, clear the restore value. |
| 291 |
} |
364 |
setTimeout(() => { |
| 292 |
|
365 |
this._restoreSelectedExecutionContextForFrame = null; |
| 293 |
_activeExecutionContextChanged(event) |
366 |
}, 10); |
| 294 |
{ |
|
|
| 295 |
this._rebuildExecutionContextPathComponents(); |
| 296 |
} |
| 297 |
|
| 298 |
_createExecutionContextPathComponent(executionContext, preferredName) |
| 299 |
{ |
| 300 |
console.assert(!executionContext || executionContext instanceof WI.ExecutionContext); |
| 301 |
|
| 302 |
let pathComponent = new WI.HierarchicalPathComponent(preferredName || executionContext.name, "execution-context", executionContext, true, true); |
| 303 |
pathComponent.addEventListener(WI.HierarchicalPathComponent.Event.SiblingWasSelected, this._pathComponentSelected, this); |
| 304 |
pathComponent.addEventListener(WI.HierarchicalPathComponent.Event.Clicked, this._pathComponentClicked, this); |
| 305 |
pathComponent.truncatedDisplayNameLength = 50; |
| 306 |
return pathComponent; |
| 307 |
} |
| 308 |
|
| 309 |
_compareExecutionContextPathComponents(a, b) |
| 310 |
{ |
| 311 |
let aExecutionContext = a.representedObject; |
| 312 |
let bExecutionContext = b.representedObject; |
| 313 |
|
| 314 |
// "Targets" (workers) at the top. |
| 315 |
let aNonMainTarget = aExecutionContext.target !== WI.mainTarget; |
| 316 |
let bNonMainTarget = bExecutionContext.target !== WI.mainTarget; |
| 317 |
if (aNonMainTarget && !bNonMainTarget) |
| 318 |
return -1; |
| 319 |
if (bNonMainTarget && !aNonMainTarget) |
| 320 |
return 1; |
| 321 |
if (aNonMainTarget && bNonMainTarget) |
| 322 |
return a.displayName.extendedLocaleCompare(b.displayName); |
| 323 |
|
| 324 |
// "Main Frame" follows. |
| 325 |
if (aExecutionContext === WI.mainTarget.executionContext) |
| 326 |
return -1; |
| 327 |
if (bExecutionContext === WI.mainTarget.executionContext) |
| 328 |
return 1; |
| 329 |
|
| 330 |
// Only Frame contexts remain. |
| 331 |
console.assert(aExecutionContext.frame); |
| 332 |
console.assert(bExecutionContext.frame); |
| 333 |
|
| 334 |
// Frames with a name above frames without a name. |
| 335 |
if (aExecutionContext.frame.name && !bExecutionContext.frame.name) |
| 336 |
return -1; |
| 337 |
if (!aExecutionContext.frame.name && bExecutionContext.frame.name) |
| 338 |
return 1; |
| 339 |
|
| 340 |
return a.displayName.extendedLocaleCompare(b.displayName); |
| 341 |
} |
| 342 |
|
| 343 |
_insertOtherExecutionContextPathComponent(executionContextPathComponent) |
| 344 |
{ |
| 345 |
let index = insertionIndexForObjectInListSortedByFunction(executionContextPathComponent, this._otherExecutionContextPathComponents, this._compareExecutionContextPathComponents); |
| 346 |
|
| 347 |
let prev = index > 0 ? this._otherExecutionContextPathComponents[index - 1] : this._mainExecutionContextPathComponent; |
| 348 |
let next = this._otherExecutionContextPathComponents[index] || null; |
| 349 |
if (prev) { |
| 350 |
prev.nextSibling = executionContextPathComponent; |
| 351 |
executionContextPathComponent.previousSibling = prev; |
| 352 |
} |
| 353 |
if (next) { |
| 354 |
next.previousSibling = executionContextPathComponent; |
| 355 |
executionContextPathComponent.nextSibling = next; |
| 356 |
} |
| 357 |
|
| 358 |
this._otherExecutionContextPathComponents.splice(index, 0, executionContextPathComponent); |
| 359 |
|
| 360 |
this._rebuildExecutionContextPathComponents(); |
| 361 |
} |
| 362 |
|
| 363 |
_removeOtherExecutionContextPathComponent(executionContextPathComponent) |
| 364 |
{ |
| 365 |
executionContextPathComponent.removeEventListener(WI.HierarchicalPathComponent.Event.SiblingWasSelected, this._pathComponentSelected, this); |
| 366 |
executionContextPathComponent.removeEventListener(WI.HierarchicalPathComponent.Event.Clicked, this._pathComponentClicked, this); |
| 367 |
|
| 368 |
let prev = executionContextPathComponent.previousSibling; |
| 369 |
let next = executionContextPathComponent.nextSibling; |
| 370 |
if (prev) |
| 371 |
prev.nextSibling = next; |
| 372 |
if (next) |
| 373 |
next.previousSibling = prev; |
| 374 |
|
| 375 |
this._otherExecutionContextPathComponents.remove(executionContextPathComponent, true); |
| 376 |
|
| 377 |
this._rebuildExecutionContextPathComponents(); |
| 378 |
} |
| 379 |
|
| 380 |
_insertExecutionContextPathComponentForFrame(frame) |
| 381 |
{ |
| 382 |
if (frame.isMainFrame()) |
| 383 |
return this._mainExecutionContextPathComponent; |
| 384 |
|
| 385 |
let executionContextPathComponent = this._createExecutionContextPathComponent(frame.pageExecutionContext, this._preferredNameForFrame(frame)); |
| 386 |
this._insertOtherExecutionContextPathComponent(executionContextPathComponent); |
| 387 |
this._frameToPathComponent.set(frame, executionContextPathComponent); |
| 388 |
return executionContextPathComponent; |
| 389 |
} |
| 390 |
|
| 391 |
_removeExecutionContextPathComponentForFrame(frame) |
| 392 |
{ |
| 393 |
if (frame.isMainFrame()) { |
| 394 |
this._shouldAutomaticallySelectExecutionContext = true; |
| 395 |
this._initializeMainExecutionContextPathComponent(); |
| 396 |
return; |
367 |
return; |
| 397 |
} |
368 |
} |
| 398 |
|
369 |
|
| 399 |
let executionContextPathComponent = this._frameToPathComponent.take(frame); |
370 |
this._useExecutionContextOfInspectedNode = InspectorBackend.hasDomain("DOM"); |
| 400 |
this._removeOtherExecutionContextPathComponent(executionContextPathComponent); |
371 |
this._setActiveExecutionContext(this._resolveDesiredActiveExecutionContext()); |
| 401 |
} |
372 |
} |
| 402 |
|
373 |
|
| 403 |
_targetAdded(event) |
374 |
_handleDebuggerActiveCallFrameDidChange(event) |
| 404 |
{ |
375 |
{ |
| 405 |
let target = event.data.target; |
376 |
this._updateActiveExecutionContextDisplay(); |
| 406 |
if (target.type !== WI.TargetType.Worker) |
377 |
} |
|
|
378 |
|
| 379 |
_handleActiveExecutionContextChanged(event) |
| 380 |
{ |
| 381 |
this._updateActiveExecutionContextDisplay(); |
| 382 |
} |
| 383 |
|
| 384 |
_handleTransitionPageTarget() |
| 385 |
{ |
| 386 |
this._updateActiveExecutionContextDisplay(); |
| 387 |
} |
| 388 |
|
| 389 |
_handleTargetRemoved(event) |
| 390 |
{ |
| 391 |
let {target} = event.data; |
| 392 |
if (target !== WI.runtimeManager.activeExecutionContext) |
| 407 |
return; |
393 |
return; |
| 408 |
|
394 |
|
| 409 |
console.assert(target.type === WI.TargetType.Worker); |
395 |
this._useExecutionContextOfInspectedNode = InspectorBackend.hasDomain("DOM"); |
| 410 |
let preferredName = WI.UIString("Worker \u2014 %s").format(target.displayName); |
396 |
this._setActiveExecutionContext(this._resolveDesiredActiveExecutionContext()); |
| 411 |
let executionContextPathComponent = this._createExecutionContextPathComponent(target.executionContext, preferredName); |
|
|
| 412 |
|
| 413 |
this._targetToPathComponent.set(target, executionContextPathComponent); |
| 414 |
this._insertOtherExecutionContextPathComponent(executionContextPathComponent); |
| 415 |
} |
397 |
} |
| 416 |
|
398 |
|
| 417 |
_targetRemoved(event) |
399 |
_handleInspectedNodeChanged(event) |
| 418 |
{ |
400 |
{ |
| 419 |
let target = event.data.target; |
401 |
if (!this._useExecutionContextOfInspectedNode) |
| 420 |
if (target.type !== WI.TargetType.Worker) |
|
|
| 421 |
return; |
402 |
return; |
| 422 |
|
403 |
|
| 423 |
let executionContextPathComponent = this._targetToPathComponent.take(target); |
404 |
this._setActiveExecutionContext(this._resolveDesiredActiveExecutionContext()); |
| 424 |
|
|
|
| 425 |
if (WI.runtimeManager.activeExecutionContext === executionContextPathComponent.representedObject) { |
| 426 |
this._shouldAutomaticallySelectExecutionContext = true; |
| 427 |
this._selectExecutionContext(); |
| 428 |
} |
| 429 |
|
| 430 |
this._removeOtherExecutionContextPathComponent(executionContextPathComponent); |
| 431 |
} |
| 432 |
|
| 433 |
_pathComponentSelected(event) |
| 434 |
{ |
| 435 |
this._shouldAutomaticallySelectExecutionContext = event.data.pathComponent === this._automaticExecutionContextPathComponent; |
| 436 |
|
| 437 |
// Only manually rebuild the execution context path components if the newly selected |
| 438 |
// execution context matches the previously selected one. |
| 439 |
if (!this._selectExecutionContext(event.data.pathComponent.representedObject)) |
| 440 |
this._rebuildExecutionContextPathComponents(); |
| 441 |
} |
| 442 |
|
| 443 |
_pathComponentClicked(event) |
| 444 |
{ |
| 445 |
this.prompt.focus(); |
| 446 |
} |
| 447 |
|
| 448 |
_debuggerActiveCallFrameDidChange(event) |
| 449 |
{ |
| 450 |
this._rebuildExecutionContextPathComponents(); |
| 451 |
} |
405 |
} |
| 452 |
|
406 |
|
| 453 |
_toggleOrFocus(event) |
407 |
_toggleOrFocus(event) |
|
Lines 468-476
WI.QuickConsole = class QuickConsole extends WI.View
a/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js_sec5
|
| 468 |
{ |
422 |
{ |
| 469 |
this.element.classList.toggle("showing-log", WI.isShowingConsoleTab() || WI.isShowingSplitConsole()); |
423 |
this.element.classList.toggle("showing-log", WI.isShowingConsoleTab() || WI.isShowingSplitConsole()); |
| 470 |
} |
424 |
} |
| 471 |
|
|
|
| 472 |
_handleInspectedNodeChanged(event) |
| 473 |
{ |
| 474 |
this._selectExecutionContext(WI.runtimeManager.activeExecutionContext); |
| 475 |
} |
| 476 |
}; |
425 |
}; |