OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** |
| 5 * @unrestricted |
| 6 */ |
| 7 WebInspector.DebuggerPausedMessage = class { |
| 8 constructor() { |
| 9 this._element = createElementWithClass('div', 'paused-message flex-none'); |
| 10 var root = WebInspector.createShadowRootWithCoreStyles(this._element, 'sourc
es/debuggerPausedMessage.css'); |
| 11 this._contentElement = root.createChild('div', 'paused-status'); |
| 12 } |
4 | 13 |
5 /** | 14 /** |
6 * @constructor | 15 * @return {!Element} |
7 */ | 16 */ |
8 WebInspector.DebuggerPausedMessage = function() | 17 element() { |
9 { | 18 return this._element; |
10 this._element = createElementWithClass("div", "paused-message flex-none"); | 19 } |
11 var root = WebInspector.createShadowRootWithCoreStyles(this._element, "sourc
es/debuggerPausedMessage.css"); | |
12 this._contentElement = root.createChild("div", "paused-status"); | |
13 }; | |
14 | 20 |
15 WebInspector.DebuggerPausedMessage.prototype = { | 21 /** |
| 22 * @param {?WebInspector.DebuggerPausedDetails} details |
| 23 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding |
| 24 * @param {!WebInspector.BreakpointManager} breakpointManager |
| 25 */ |
| 26 render(details, debuggerWorkspaceBinding, breakpointManager) { |
| 27 var status = this._contentElement; |
| 28 status.hidden = !details; |
| 29 status.removeChildren(); |
| 30 if (!details) |
| 31 return; |
| 32 |
| 33 var messageWrapper; |
| 34 if (details.reason === WebInspector.DebuggerModel.BreakReason.DOM) { |
| 35 messageWrapper = WebInspector.DOMBreakpointsSidebarPane.createBreakpointHi
tMessage(details); |
| 36 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.EventLi
stener) { |
| 37 var eventName = details.auxData['eventName']; |
| 38 var eventNameForUI = WebInspector.EventListenerBreakpointsSidebarPane.even
tNameForUI(eventName, details.auxData); |
| 39 messageWrapper = buildWrapper(WebInspector.UIString('Paused on event liste
ner'), eventNameForUI); |
| 40 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.XHR) { |
| 41 messageWrapper = buildWrapper(WebInspector.UIString('Paused on XMLHttpRequ
est'), details.auxData['url'] || ''); |
| 42 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Excepti
on) { |
| 43 var description = details.auxData['description'] || details.auxData['value
'] || ''; |
| 44 var descriptionFirstLine = description.split('\n', 1)[0]; |
| 45 messageWrapper = buildWrapper(WebInspector.UIString('Paused on exception')
, descriptionFirstLine, description); |
| 46 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Promise
Rejection) { |
| 47 var description = details.auxData['description'] || details.auxData['value
'] || ''; |
| 48 var descriptionFirstLine = description.split('\n', 1)[0]; |
| 49 messageWrapper = |
| 50 buildWrapper(WebInspector.UIString('Paused on promise rejection'), des
criptionFirstLine, description); |
| 51 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Assert)
{ |
| 52 messageWrapper = buildWrapper(WebInspector.UIString('Paused on assertion')
); |
| 53 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.DebugCo
mmand) { |
| 54 messageWrapper = buildWrapper(WebInspector.UIString('Paused on debugged fu
nction')); |
| 55 } else if (details.callFrames.length) { |
| 56 var uiLocation = debuggerWorkspaceBinding.rawLocationToUILocation(details.
callFrames[0].location()); |
| 57 var breakpoint = |
| 58 uiLocation ? breakpointManager.findBreakpointOnLine(uiLocation.uiSourc
eCode, uiLocation.lineNumber) : null; |
| 59 var defaultText = |
| 60 breakpoint ? WebInspector.UIString('Paused on breakpoint') : WebInspec
tor.UIString('Debugger paused'); |
| 61 messageWrapper = buildWrapper(defaultText); |
| 62 } else { |
| 63 console.warn( |
| 64 'ScriptsPanel paused, but callFrames.length is zero.'); // TODO remov
e this once we understand this case better |
| 65 } |
| 66 |
| 67 var errorLike = details.reason === WebInspector.DebuggerModel.BreakReason.Ex
ception || |
| 68 details.reason === WebInspector.DebuggerModel.BreakReason.PromiseRejecti
on || |
| 69 details.reason === WebInspector.DebuggerModel.BreakReason.Assert; |
| 70 status.classList.toggle('error-reason', errorLike); |
| 71 if (messageWrapper) |
| 72 status.appendChild(messageWrapper); |
| 73 |
16 /** | 74 /** |
| 75 * @param {string} mainText |
| 76 * @param {string=} subText |
| 77 * @param {string=} title |
17 * @return {!Element} | 78 * @return {!Element} |
18 */ | 79 */ |
19 element: function() | 80 function buildWrapper(mainText, subText, title) { |
20 { | 81 var messageWrapper = createElement('span'); |
21 return this._element; | 82 var mainElement = messageWrapper.createChild('div', 'status-main'); |
22 }, | 83 mainElement.textContent = mainText; |
23 | 84 if (subText) { |
24 /** | 85 var subElement = messageWrapper.createChild('div', 'status-sub monospace
'); |
25 * @param {?WebInspector.DebuggerPausedDetails} details | 86 subElement.textContent = subText; |
26 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding | 87 } |
27 * @param {!WebInspector.BreakpointManager} breakpointManager | 88 if (title) |
28 */ | 89 messageWrapper.title = title; |
29 render: function(details, debuggerWorkspaceBinding, breakpointManager) | 90 return messageWrapper; |
30 { | |
31 var status = this._contentElement; | |
32 status.hidden = !details; | |
33 status.removeChildren(); | |
34 if (!details) | |
35 return; | |
36 | |
37 var messageWrapper; | |
38 if (details.reason === WebInspector.DebuggerModel.BreakReason.DOM) { | |
39 messageWrapper = WebInspector.DOMBreakpointsSidebarPane.createBreakp
ointHitMessage(details); | |
40 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Eve
ntListener) { | |
41 var eventName = details.auxData["eventName"]; | |
42 var eventNameForUI = WebInspector.EventListenerBreakpointsSidebarPan
e.eventNameForUI(eventName, details.auxData); | |
43 messageWrapper = buildWrapper(WebInspector.UIString("Paused on event
listener"), eventNameForUI); | |
44 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.XHR
) { | |
45 messageWrapper = buildWrapper(WebInspector.UIString("Paused on XMLHt
tpRequest"), details.auxData["url"] || ""); | |
46 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Exc
eption) { | |
47 var description = details.auxData["description"] || details.auxData[
"value"] || ""; | |
48 var descriptionFirstLine = description.split("\n", 1)[0]; | |
49 messageWrapper = buildWrapper(WebInspector.UIString("Paused on excep
tion"), descriptionFirstLine, description); | |
50 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Pro
miseRejection) { | |
51 var description = details.auxData["description"] || details.auxData[
"value"] || ""; | |
52 var descriptionFirstLine = description.split("\n", 1)[0]; | |
53 messageWrapper = buildWrapper(WebInspector.UIString("Paused on promi
se rejection"), descriptionFirstLine, description); | |
54 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Ass
ert) { | |
55 messageWrapper = buildWrapper(WebInspector.UIString("Paused on asser
tion")); | |
56 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Deb
ugCommand) { | |
57 messageWrapper = buildWrapper(WebInspector.UIString("Paused on debug
ged function")); | |
58 } else if (details.callFrames.length) { | |
59 var uiLocation = debuggerWorkspaceBinding.rawLocationToUILocation(de
tails.callFrames[0].location()); | |
60 var breakpoint = uiLocation ? breakpointManager.findBreakpointOnLine
(uiLocation.uiSourceCode, uiLocation.lineNumber) : null; | |
61 var defaultText = breakpoint ? WebInspector.UIString("Paused on brea
kpoint") : WebInspector.UIString("Debugger paused"); | |
62 messageWrapper = buildWrapper(defaultText); | |
63 } else { | |
64 console.warn("ScriptsPanel paused, but callFrames.length is zero.");
// TODO remove this once we understand this case better | |
65 } | |
66 | |
67 var errorLike = details.reason === WebInspector.DebuggerModel.BreakReaso
n.Exception || details.reason === WebInspector.DebuggerModel.BreakReason.Promise
Rejection || details.reason === WebInspector.DebuggerModel.BreakReason.Assert; | |
68 status.classList.toggle("error-reason", errorLike); | |
69 if (messageWrapper) | |
70 status.appendChild(messageWrapper); | |
71 | |
72 /** | |
73 * @param {string} mainText | |
74 * @param {string=} subText | |
75 * @param {string=} title | |
76 * @return {!Element} | |
77 */ | |
78 function buildWrapper(mainText, subText, title) | |
79 { | |
80 var messageWrapper = createElement("span"); | |
81 var mainElement = messageWrapper.createChild("div", "status-main"); | |
82 mainElement.textContent = mainText; | |
83 if (subText) { | |
84 var subElement = messageWrapper.createChild("div", "status-sub m
onospace"); | |
85 subElement.textContent = subText; | |
86 } | |
87 if (title) | |
88 messageWrapper.title = title; | |
89 return messageWrapper; | |
90 } | |
91 } | 91 } |
| 92 } |
92 }; | 93 }; |
OLD | NEW |