OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 18 matching lines...) Expand all Loading... | |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 * @extends {WebInspector.BreakpointsSidebarPaneBase} | 33 * @extends {WebInspector.BreakpointsSidebarPaneBase} |
34 * @implements {WebInspector.ContextFlavorListener} | 34 * @implements {WebInspector.ContextFlavorListener} |
35 */ | 35 */ |
36 WebInspector.DOMBreakpointsSidebarPane = function() | 36 WebInspector.DOMBreakpointsSidebarPane = function() |
37 { | 37 { |
38 WebInspector.BreakpointsSidebarPaneBase.call(this); | 38 WebInspector.BreakpointsSidebarPaneBase.call(this); |
39 this._domBreakpointsSetting = WebInspector.settings.createLocalSetting("domB reakpoints", []); | |
40 this.listElement.classList.add("dom-breakpoints-list"); | 39 this.listElement.classList.add("dom-breakpoints-list"); |
41 | 40 |
42 this._breakpointElements = {}; | 41 this._breakpointElements = new Map(); |
43 | 42 |
44 this._breakpointTypes = { | 43 this._breakpointTypes = { |
45 SubtreeModified: "subtree-modified", | 44 SubtreeModified: "subtree-modified", |
46 AttributeModified: "attribute-modified", | 45 AttributeModified: "attribute-modified", |
47 NodeRemoved: "node-removed" | 46 NodeRemoved: "node-removed" |
48 }; | 47 }; |
49 this._breakpointTypeLabels = {}; | 48 this._breakpointTypeLabels = {}; |
50 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspe ctor.UIString("Subtree Modified"); | 49 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspe ctor.UIString("Subtree Modified"); |
51 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebIns pector.UIString("Attribute Modified"); | 50 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebIns pector.UIString("Attribute Modified"); |
52 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector .UIString("Node Removed"); | 51 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector .UIString("Node Removed"); |
53 | 52 |
54 this._contextMenuLabels = {}; | 53 this._contextMenuLabels = {}; |
55 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspecto r.UIString.capitalize("Subtree ^modifications"); | 54 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspecto r.UIString.capitalize("Subtree ^modifications"); |
56 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspec tor.UIString.capitalize("Attributes ^modifications"); | 55 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspec tor.UIString.capitalize("Attributes ^modifications"); |
57 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UI String.capitalize("Node ^removal"); | 56 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UI String.capitalize("Node ^removal"); |
58 | 57 |
59 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.NodeRemoved, this._nodeRemoved, this); | 58 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.NodeRemoved, this._nodeRemoved, this); |
60 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.InspectedURLChanged, this._inspectedURLChanged, this); | 59 WebInspector.domBreakpointManager.addEventListener(WebInspector.DOMBreakpoin tManager.Events.BreakpointsChanged, this._reloadBreakpointElements, this); |
61 this._inspectedURL = WebInspector.targetManager.inspectedURL(); | |
lushnikov
2016/08/22 18:44:25
so now instead of relying on inspectedURL to save
chenwilliam
2016/08/22 22:01:46
Done.
| |
62 this._update(); | 60 this._update(); |
63 } | 61 } |
64 | 62 |
65 WebInspector.DOMBreakpointsSidebarPane.Marker = "breakpoint-marker"; | |
66 | |
67 WebInspector.DOMBreakpointsSidebarPane.prototype = { | 63 WebInspector.DOMBreakpointsSidebarPane.prototype = { |
68 _inspectedURLChanged: function() | 64 _reloadBreakpointElements: function() |
69 { | 65 { |
70 this._breakpointElements = {}; | 66 this._breakpointElements.clear(); |
71 this.reset(); | 67 this.reset(); |
72 this._inspectedURL = WebInspector.targetManager.inspectedURL(); | 68 var breakpoints = WebInspector.domBreakpointManager.domBreakpoints(); |
69 for (var breakpoint of breakpoints) { | |
70 var id = this._createBreakpointId(breakpoint.node.id, breakpoint.typ e); | |
71 this._breakpointElements.set(id, this._createBreakpointElement(break point.node, breakpoint.type, breakpoint.enabled)); | |
72 } | |
73 }, | 73 }, |
74 | 74 |
75 /** | 75 /** |
76 * @param {!WebInspector.DOMNode} node | 76 * @param {!WebInspector.DOMNode} node |
77 * @param {!WebInspector.ContextMenu} contextMenu | 77 * @param {!WebInspector.ContextMenu} contextMenu |
78 * @param {boolean} createSubMenu | 78 * @param {boolean} createSubMenu |
79 */ | 79 */ |
80 populateNodeContextMenu: function(node, contextMenu, createSubMenu) | 80 populateNodeContextMenu: function(node, contextMenu, createSubMenu) |
81 { | 81 { |
82 if (node.pseudoType()) | 82 if (node.pseudoType()) |
83 return; | 83 return; |
84 | 84 |
85 var nodeBreakpoints = this._nodeBreakpoints(node); | 85 var nodeBreakpoints = this._nodeBreakpoints(node); |
86 | 86 |
87 /** | 87 /** |
88 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 88 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
89 * @this {WebInspector.DOMBreakpointsSidebarPane} | |
90 */ | 89 */ |
91 function toggleBreakpoint(type) | 90 function toggleBreakpoint(type) |
92 { | 91 { |
93 if (!nodeBreakpoints[type]) | 92 if (!nodeBreakpoints.get(type)) |
94 this._setBreakpoint(node, type, true); | 93 WebInspector.domBreakpointManager.setBreakpoint(node, type, true ); |
95 else | 94 else |
96 this._removeBreakpoint(node, type); | 95 WebInspector.domBreakpointManager.removeBreakpoint(node, type); |
97 this._saveBreakpoints(); | |
98 } | 96 } |
99 | 97 |
100 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI nspector.UIString("Break on...")) : contextMenu; | 98 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI nspector.UIString("Break on...")) : contextMenu; |
101 for (var key in this._breakpointTypes) { | 99 for (var key in this._breakpointTypes) { |
102 var type = this._breakpointTypes[key]; | 100 var type = this._breakpointTypes[key]; |
103 var label = this._contextMenuLabels[type]; | 101 var label = this._contextMenuLabels[type]; |
104 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(this , type), nodeBreakpoints[type]); | 102 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(null , type), nodeBreakpoints.get(type)); |
105 } | 103 } |
106 }, | 104 }, |
107 | 105 |
108 /** | 106 /** |
109 * @param {!WebInspector.DOMNode} node | 107 * @param {!WebInspector.DOMNode} node |
110 * @return {!Object<string, boolean>} | 108 * @return {!Map<string, boolean>} |
111 */ | 109 */ |
112 _nodeBreakpoints: function(node) | 110 _nodeBreakpoints: function(node) |
113 { | 111 { |
114 var nodeBreakpoints = {}; | 112 var nodeBreakpoints = new Map(); |
115 for (var id in this._breakpointElements) { | 113 var breakpoints = WebInspector.domBreakpointManager.domBreakpoints(); |
116 var element = this._breakpointElements[id]; | 114 for (var breakpoint of breakpoints) { |
117 if (element._node === node && element._checkboxElement.checked) | 115 if (breakpoint.node === node && breakpoint.enabled) |
118 nodeBreakpoints[element._type] = true; | 116 nodeBreakpoints.set(breakpoint.type, true); |
119 } | 117 } |
120 return nodeBreakpoints; | 118 return nodeBreakpoints; |
121 }, | 119 }, |
122 | 120 |
123 /** | 121 /** |
124 * @param {!WebInspector.DOMNode} node | |
125 * @return {boolean} | |
126 */ | |
127 hasBreakpoints: function(node) | |
128 { | |
129 for (var id in this._breakpointElements) { | |
130 var element = this._breakpointElements[id]; | |
131 if (element._node === node && element._checkboxElement.checked) | |
132 return true; | |
133 } | |
134 return false; | |
135 }, | |
136 | |
137 /** | |
138 * @param {!WebInspector.DebuggerPausedDetails} details | 122 * @param {!WebInspector.DebuggerPausedDetails} details |
139 * @return {!Element} | 123 * @return {!Element} |
140 */ | 124 */ |
141 createBreakpointHitStatusMessage: function(details) | 125 createBreakpointHitStatusMessage: function(details) |
142 { | 126 { |
143 var auxData = /** @type {!Object} */ (details.auxData); | 127 var auxData = /** @type {!Object} */ (details.auxData); |
144 var message = "Paused on a \"%s\" breakpoint."; | 128 var message = "Paused on a \"%s\" breakpoint."; |
145 var substitutions = []; | 129 var substitutions = []; |
146 substitutions.push(this._breakpointTypeLabels[auxData["type"]]); | 130 substitutions.push(this._breakpointTypeLabels[auxData["type"]]); |
147 | 131 |
(...skipping 19 matching lines...) Expand all Loading... | |
167 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed."; | 151 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed."; |
168 substitutions.push(targetNodeLink); | 152 substitutions.push(targetNodeLink); |
169 } | 153 } |
170 } else { | 154 } else { |
171 message = "Paused on a \"%s\" breakpoint set on %s."; | 155 message = "Paused on a \"%s\" breakpoint set on %s."; |
172 } | 156 } |
173 | 157 |
174 return WebInspector.formatLocalized(message, substitutions); | 158 return WebInspector.formatLocalized(message, substitutions); |
175 }, | 159 }, |
176 | 160 |
161 /** | |
162 * @param {!WebInspector.Event} event | |
163 */ | |
177 _nodeRemoved: function(event) | 164 _nodeRemoved: function(event) |
178 { | 165 { |
179 var node = event.data.node; | 166 var node = event.data.node; |
180 this._removeBreakpointsForNode(event.data.node); | 167 this._removeBreakpointsForNode(node); |
181 var children = node.children(); | 168 var children = node.children(); |
182 if (!children) | 169 if (!children) |
183 return; | 170 return; |
184 for (var i = 0; i < children.length; ++i) | 171 for (var child of children) |
185 this._removeBreakpointsForNode(children[i]); | 172 this._removeBreakpointsForNode(child); |
186 this._saveBreakpoints(); | |
187 }, | 173 }, |
188 | 174 |
189 /** | 175 /** |
190 * @param {!WebInspector.DOMNode} node | 176 * @param {!WebInspector.DOMNode} node |
191 */ | 177 */ |
192 _removeBreakpointsForNode: function(node) | 178 _removeBreakpointsForNode: function(node) |
193 { | 179 { |
194 for (var id in this._breakpointElements) { | 180 var breakpoints = WebInspector.domBreakpointManager.domBreakpoints(); |
195 var element = this._breakpointElements[id]; | 181 for (var breakpoint of breakpoints) { |
196 if (element._node === node) | 182 if (breakpoint.node === node) |
197 this._removeBreakpoint(element._node, element._type); | 183 WebInspector.domBreakpointManager.removeBreakpoint(breakpoint.no de, breakpoint.type); |
198 } | 184 } |
199 }, | 185 }, |
200 | 186 |
201 /** | 187 /** |
202 * @param {!WebInspector.DOMNode} node | 188 * @param {!WebInspector.DOMNode} node |
203 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 189 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
204 * @param {boolean} enabled | 190 * @param {boolean} enabled |
205 */ | 191 */ |
206 _setBreakpoint: function(node, type, enabled) | |
207 { | |
208 var breakpointId = this._createBreakpointId(node.id, type); | |
209 var breakpointElement = this._breakpointElements[breakpointId]; | |
210 if (!breakpointElement) { | |
211 breakpointElement = this._createBreakpointElement(node, type, enable d); | |
212 this._breakpointElements[breakpointId] = breakpointElement; | |
213 } else { | |
214 breakpointElement._checkboxElement.checked = enabled; | |
215 } | |
216 if (enabled) | |
217 node.target().domdebuggerAgent().setDOMBreakpoint(node.id, type); | |
218 node.setMarker(WebInspector.DOMBreakpointsSidebarPane.Marker, true); | |
219 }, | |
220 | |
221 /** | |
222 * @param {!WebInspector.DOMNode} node | |
223 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
224 * @param {boolean} enabled | |
225 */ | |
226 _createBreakpointElement: function(node, type, enabled) | 192 _createBreakpointElement: function(node, type, enabled) |
227 { | 193 { |
228 var element = createElement("li"); | 194 var element = createElement("li"); |
229 element._node = node; | 195 element._node = node; |
230 element._type = type; | 196 element._type = type; |
231 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod e, type), true); | 197 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod e, type), true); |
232 | 198 |
233 var checkboxLabel = createCheckboxLabel("", enabled); | 199 var checkboxLabel = createCheckboxLabel("", enabled); |
234 checkboxLabel.addEventListener("click", this._checkboxClicked.bind(this, node, type), false); | 200 checkboxLabel.addEventListener("click", this._checkboxClicked.bind(this, node, type), false); |
235 element._checkboxElement = checkboxLabel.checkboxElement; | 201 element._checkboxElement = checkboxLabel.checkboxElement; |
(...skipping 14 matching lines...) Expand all Loading... | |
250 var currentElement = this.listElement.firstChild; | 216 var currentElement = this.listElement.firstChild; |
251 while (currentElement) { | 217 while (currentElement) { |
252 if (currentElement._type && currentElement._type < element._type) | 218 if (currentElement._type && currentElement._type < element._type) |
253 break; | 219 break; |
254 currentElement = currentElement.nextSibling; | 220 currentElement = currentElement.nextSibling; |
255 } | 221 } |
256 this.addListElement(element, currentElement); | 222 this.addListElement(element, currentElement); |
257 return element; | 223 return element; |
258 }, | 224 }, |
259 | 225 |
260 _removeAllBreakpoints: function() | |
261 { | |
262 for (var id in this._breakpointElements) { | |
263 var element = this._breakpointElements[id]; | |
264 this._removeBreakpoint(element._node, element._type); | |
265 } | |
266 this._saveBreakpoints(); | |
267 }, | |
268 | |
269 /** | 226 /** |
270 * @param {!WebInspector.DOMNode} node | 227 * @param {!WebInspector.DOMNode} node |
271 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 228 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
272 */ | |
273 _removeBreakpoint: function(node, type) | |
274 { | |
275 var breakpointId = this._createBreakpointId(node.id, type); | |
276 var element = this._breakpointElements[breakpointId]; | |
277 if (!element) | |
278 return; | |
279 | |
280 this.removeListElement(element); | |
281 delete this._breakpointElements[breakpointId]; | |
282 if (element._checkboxElement.checked) | |
283 node.target().domdebuggerAgent().removeDOMBreakpoint(node.id, type); | |
284 node.setMarker(WebInspector.DOMBreakpointsSidebarPane.Marker, this.hasBr eakpoints(node) ? true : null); | |
285 }, | |
286 | |
287 /** | |
288 * @param {!WebInspector.DOMNode} node | |
289 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
290 * @param {!Event} event | 229 * @param {!Event} event |
291 */ | 230 */ |
292 _contextMenu: function(node, type, event) | 231 _contextMenu: function(node, type, event) |
293 { | 232 { |
294 var contextMenu = new WebInspector.ContextMenu(event); | 233 var contextMenu = new WebInspector.ContextMenu(event); |
295 | 234 var removeBreakpoint = () => WebInspector.domBreakpointManager.removeBre akpoint(node, type); |
296 /** | 235 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo int"), removeBreakpoint); |
297 * @this {WebInspector.DOMBreakpointsSidebarPane} | 236 var removeAllBreakpoints = () => WebInspector.domBreakpointManager.remov eAllBreakpoints(); |
298 */ | 237 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^all DOM breakpoints"), removeAllBreakpoints); |
299 function removeBreakpoint() | |
300 { | |
301 this._removeBreakpoint(node, type); | |
302 this._saveBreakpoints(); | |
303 } | |
304 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo int"), removeBreakpoint.bind(this)); | |
305 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^all DOM breakpoints"), this._removeAllBreakpoints.bind(this)); | |
306 contextMenu.show(); | 238 contextMenu.show(); |
307 }, | 239 }, |
308 | 240 |
309 /** | 241 /** |
310 * @param {!WebInspector.DOMNode} node | 242 * @param {!WebInspector.DOMNode} node |
311 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 243 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
312 * @param {!Event} event | 244 * @param {!Event} event |
313 */ | 245 */ |
314 _checkboxClicked: function(node, type, event) | 246 _checkboxClicked: function(node, type, event) |
315 { | 247 { |
316 if (event.target.checked) | 248 WebInspector.domBreakpointManager.setBreakpoint(node, type, event.target ["checkboxElement"].checked); |
317 node.target().domdebuggerAgent().setDOMBreakpoint(node.id, type); | |
318 else | |
319 node.target().domdebuggerAgent().removeDOMBreakpoint(node.id, type); | |
320 this._saveBreakpoints(); | |
321 }, | 249 }, |
322 | 250 |
323 /** | 251 /** |
324 * @override | 252 * @override |
325 * @param {?Object} object | 253 * @param {?Object} object |
326 */ | 254 */ |
327 flavorChanged: function(object) | 255 flavorChanged: function(object) |
328 { | 256 { |
329 this._update(); | 257 this._update(); |
330 }, | 258 }, |
331 | 259 |
332 _update: function() | 260 _update: function() |
333 { | 261 { |
334 var details = WebInspector.context.flavor(WebInspector.DebuggerPausedDet ails); | 262 var details = WebInspector.context.flavor(WebInspector.DebuggerPausedDet ails); |
335 if (!details || details.reason !== WebInspector.DebuggerModel.BreakReaso n.DOM) { | 263 if (!details || details.reason !== WebInspector.DebuggerModel.BreakReaso n.DOM) { |
336 if (this._highlightedElement) { | 264 if (this._highlightedElement) { |
337 this._highlightedElement.classList.remove("breakpoint-hit"); | 265 this._highlightedElement.classList.remove("breakpoint-hit"); |
338 delete this._highlightedElement; | 266 delete this._highlightedElement; |
339 } | 267 } |
340 return; | 268 return; |
341 } | 269 } |
342 var auxData = details.auxData; | 270 var auxData = details.auxData; |
343 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type ); | 271 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type ); |
344 var element = this._breakpointElements[breakpointId]; | 272 var element = this._breakpointElements.get(breakpointId); |
345 if (!element) | 273 if (!element) |
346 return; | 274 return; |
347 WebInspector.viewManager.showView("sources.domBreakpoints"); | 275 WebInspector.viewManager.showView("sources.domBreakpoints"); |
348 element.classList.add("breakpoint-hit"); | 276 element.classList.add("breakpoint-hit"); |
349 this._highlightedElement = element; | 277 this._highlightedElement = element; |
350 }, | 278 }, |
351 | 279 |
352 /** | 280 /** |
353 * @param {number} nodeId | 281 * @param {number} nodeId |
354 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 282 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
283 * @return {string} | |
355 */ | 284 */ |
356 _createBreakpointId: function(nodeId, type) | 285 _createBreakpointId: function(nodeId, type) |
357 { | 286 { |
358 return nodeId + ":" + type; | 287 return nodeId + ":" + type; |
359 }, | 288 }, |
360 | 289 |
361 _saveBreakpoints: function() | 290 __proto__: WebInspector.BreakpointsSidebarPaneBase.prototype |
291 } | |
292 | |
293 /** | |
294 * @type {!WebInspector.DOMBreakpointsSidebarPane} | |
295 */ | |
296 WebInspector.domBreakpointsSidebarPane; | |
297 | |
298 /** | |
299 * @constructor | |
300 * @extends {WebInspector.Object} | |
301 * @implements {WebInspector.TargetManager.Observer} | |
302 */ | |
303 WebInspector.DOMBreakpointManager = function() | |
304 { | |
305 /** @type {!Map<!WebInspector.Target, !Protocol.DOMDebuggerAgent>} */ | |
306 this._agents = new Map(); | |
307 this._domBreakpointsSetting = WebInspector.settings.createLocalSetting("domB reakpoints", []); | |
308 /** @type {!Map<string, !WebInspector.DOMBreakpointManager.Breakpoint>} */ | |
309 this._breakpoints = new Map(); | |
310 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.DocumentUpdated, this._restoreBreakpoints, this); | |
311 WebInspector.targetManager.observeTargets(this); | |
312 } | |
313 | |
314 WebInspector.DOMBreakpointManager.Marker = "breakpoint-marker"; | |
315 | |
316 WebInspector.DOMBreakpointManager.Events = { | |
317 BreakpointsChanged: "BreakpointsChanged" | |
318 } | |
319 | |
320 WebInspector.DOMBreakpointManager.prototype = { | |
321 /** | |
322 * @override | |
323 * @param {!WebInspector.Target} target | |
324 */ | |
325 targetAdded: function(target) | |
362 { | 326 { |
363 var breakpoints = []; | 327 if (target.hasDOMCapability()) |
364 var storedBreakpoints = this._domBreakpointsSetting.get(); | 328 this._agents.set(target, target.domdebuggerAgent()); |
365 for (var i = 0; i < storedBreakpoints.length; ++i) { | |
366 var breakpoint = storedBreakpoints[i]; | |
367 if (breakpoint.url !== this._inspectedURL) | |
368 breakpoints.push(breakpoint); | |
369 } | |
370 for (var id in this._breakpointElements) { | |
371 var element = this._breakpointElements[id]; | |
372 breakpoints.push({ url: this._inspectedURL, path: element._node.path (), type: element._type, enabled: element._checkboxElement.checked }); | |
373 } | |
374 this._domBreakpointsSetting.set(breakpoints); | |
375 }, | 329 }, |
376 | 330 |
377 /** | 331 /** |
378 * @param {!WebInspector.DOMModel} domModel | 332 * @override |
333 * @param {!WebInspector.Target} target | |
379 */ | 334 */ |
380 restoreBreakpoints: function(domModel) | 335 targetRemoved: function(target) |
381 { | 336 { |
337 if (target.hasDOMCapability()) | |
338 this._agents.delete(target); | |
339 }, | |
340 | |
341 /** | |
342 * @return {!Array<!WebInspector.DOMBreakpointManager.Breakpoint>} | |
343 */ | |
344 domBreakpoints: function() | |
345 { | |
346 var breakpoints = []; | |
347 for (var breakpoint of this._breakpoints.values()) | |
348 breakpoints.push(breakpoint); | |
349 return breakpoints; | |
350 }, | |
351 | |
352 /** | |
353 * @param {!WebInspector.DOMNode} node | |
354 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
355 * @param {boolean} enabled | |
356 */ | |
357 setBreakpoint: function(node, type, enabled) | |
358 { | |
359 this._innerSetBreakpoint(node, type, enabled); | |
lushnikov
2016/08/22 18:44:25
consider the following scenario:
1. You have a pag
chenwilliam
2016/08/22 22:01:46
I reproduced this scenario and it treats the diffe
| |
360 this._saveBreakpoints(); | |
361 }, | |
362 | |
363 /** | |
364 * @param {!WebInspector.DOMNode} node | |
365 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
366 * @param {boolean} enabled | |
367 */ | |
368 _innerSetBreakpoint: function(node, type, enabled) | |
369 { | |
370 var url = node.ownerDocument.documentURL.removeURLFragment(); | |
371 var breakpoint = new WebInspector.DOMBreakpointManager.Breakpoint(node, type, url, enabled); | |
372 this._breakpoints.set(this._createBreakpointId(node, type), breakpoint); | |
373 var agent = this._agents.get(node.target()); | |
374 if (enabled) { | |
375 agent.setDOMBreakpoint(node.id, type); | |
376 node.setMarker(WebInspector.DOMBreakpointManager.Marker, true); | |
377 } else { | |
378 agent.removeDOMBreakpoint(node.id, type); | |
379 node.setMarker(WebInspector.DOMBreakpointManager.Marker, this._hasOt herBreakpoints(node, type) ? true : null); | |
380 } | |
381 }, | |
382 | |
383 /** | |
384 * @param {!WebInspector.DOMNode} node | |
385 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
386 */ | |
387 removeBreakpoint: function(node, type) | |
388 { | |
389 this._innerRemoveBreakpoint(node, type); | |
390 this._saveBreakpoints(); | |
391 }, | |
392 | |
393 /** | |
394 * @param {!WebInspector.DOMNode} node | |
395 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
396 */ | |
397 _innerRemoveBreakpoint: function(node, type) | |
398 { | |
399 var breakpointId = this._createBreakpointId(node, type); | |
400 var breakpoint = this._breakpoints.get(breakpointId); | |
401 if (breakpoint.enabled) { | |
402 var agent = this._agents.get(node.target()); | |
403 agent.removeDOMBreakpoint(node.id, type); | |
404 node.setMarker(WebInspector.DOMBreakpointManager.Marker, this._hasOt herBreakpoints(node, type) ? true : null); | |
405 } | |
406 this._breakpoints.remove(breakpointId); | |
407 }, | |
408 | |
409 removeAllBreakpoints: function() | |
410 { | |
411 for (var breakpoint of this._breakpoints.values()) | |
412 this._innerRemoveBreakpoint(breakpoint.node, breakpoint.type); | |
413 this._saveBreakpoints(); | |
414 }, | |
415 | |
416 /** | |
417 * @param {!WebInspector.Event} event | |
418 */ | |
419 _restoreBreakpoints: function(event) | |
420 { | |
421 var inspectedRootDocument = /** @type {!WebInspector.DOMDocument} */ (ev ent.data); | |
422 if (!inspectedRootDocument) | |
423 return; | |
424 var domModel = /** @type {!WebInspector.DOMModel} */ (event.target); | |
382 var pathToBreakpoints = {}; | 425 var pathToBreakpoints = {}; |
426 this._breakpoints.clear(); | |
427 this.dispatchEventToListeners(WebInspector.DOMBreakpointManager.Events.B reakpointsChanged); | |
lushnikov
2016/08/22 18:44:25
let's not send this event twice
chenwilliam
2016/08/22 22:01:46
I included this because if there's no DOM breakpoi
| |
383 | 428 |
384 /** | 429 /** |
385 * @param {string} path | 430 * @param {string} path |
386 * @param {?DOMAgent.NodeId} nodeId | 431 * @param {?DOMAgent.NodeId} nodeId |
387 * @this {WebInspector.DOMBreakpointsSidebarPane} | 432 * @this {WebInspector.DOMBreakpointManager} |
388 */ | 433 */ |
389 function didPushNodeByPathToFrontend(path, nodeId) | 434 function didPushNodeByPathToFrontend(path, nodeId) |
390 { | 435 { |
391 var node = nodeId ? domModel.nodeForId(nodeId) : null; | 436 var node = nodeId ? domModel.nodeForId(nodeId) : null; |
392 if (!node) | 437 if (!node) |
393 return; | 438 return; |
394 | 439 |
395 var breakpoints = pathToBreakpoints[path]; | 440 for (var breakpoint of pathToBreakpoints[path]) |
396 for (var i = 0; i < breakpoints.length; ++i) | 441 this._innerSetBreakpoint(node, breakpoint.type, breakpoint.enabl ed); |
397 this._setBreakpoint(node, breakpoints[i].type, breakpoints[i].en abled); | 442 this.dispatchEventToListeners(WebInspector.DOMBreakpointManager.Even ts.BreakpointsChanged); |
398 } | 443 } |
399 | 444 |
400 var breakpoints = this._domBreakpointsSetting.get(); | 445 var breakpoints = this._domBreakpointsSetting.get(); |
401 for (var i = 0; i < breakpoints.length; ++i) { | 446 for (var breakpoint of breakpoints) { |
402 var breakpoint = breakpoints[i]; | 447 if (breakpoint.url !== WebInspector.targetManager.inspectedURL()) |
lushnikov
2016/08/22 18:44:25
who gives you guarantee that inspectedURL is alrea
chenwilliam
2016/08/22 22:01:46
Done.
| |
403 if (breakpoint.url !== this._inspectedURL) | |
404 continue; | 448 continue; |
405 var path = breakpoint.path; | 449 var path = breakpoint.path; |
406 if (!pathToBreakpoints[path]) { | 450 if (!pathToBreakpoints[path]) { |
407 pathToBreakpoints[path] = []; | 451 pathToBreakpoints[path] = []; |
408 domModel.pushNodeByPathToFrontend(path, didPushNodeByPathToFront end.bind(this, path)); | 452 domModel.pushNodeByPathToFrontend(path, didPushNodeByPathToFront end.bind(this, path)); |
409 } | 453 } |
410 pathToBreakpoints[path].push(breakpoint); | 454 pathToBreakpoints[path].push(breakpoint); |
411 } | 455 } |
412 }, | 456 }, |
413 | 457 |
414 __proto__: WebInspector.BreakpointsSidebarPaneBase.prototype | 458 _saveBreakpoints: function() |
459 { | |
460 var breakpoints = []; | |
461 var storedBreakpoints = this._domBreakpointsSetting.get(); | |
462 for (var breakpoint of storedBreakpoints) { | |
463 if (breakpoint.url !== WebInspector.targetManager.inspectedURL()) | |
464 breakpoints.push(breakpoint); | |
465 } | |
466 for (var breakpoint of this._breakpoints.values()) { | |
467 breakpoints.push({ | |
468 url: breakpoint.url, | |
469 path: breakpoint.node.path(), | |
470 type: breakpoint.type, | |
471 enabled: breakpoint.enabled | |
472 }); | |
473 } | |
474 this._domBreakpointsSetting.set(breakpoints); | |
475 this.dispatchEventToListeners(WebInspector.DOMBreakpointManager.Events.B reakpointsChanged); | |
476 }, | |
477 | |
478 /** | |
479 * @param {!WebInspector.DOMNode} node | |
480 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
481 * @return {boolean} | |
482 */ | |
483 _hasOtherBreakpoints: function(node, type) | |
484 { | |
485 for (var breakpoint of this._breakpoints.values()) { | |
486 if (breakpoint.node === node && breakpoint.type !== type && breakpoi nt.enabled) | |
487 return true; | |
488 } | |
489 return false; | |
490 }, | |
491 | |
492 /** | |
493 * @param {!WebInspector.DOMNode} node | |
494 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
495 * @return {string} | |
496 */ | |
497 _createBreakpointId: function(node, type) | |
498 { | |
499 return node.id + ":" + type; | |
500 }, | |
501 | |
502 __proto__: WebInspector.Object.prototype | |
503 }; | |
504 | |
505 /** | |
506 * @constructor | |
507 * @param {!WebInspector.DOMNode} node | |
508 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
509 * @param {string} url | |
510 * @param {boolean} enabled | |
511 */ | |
512 WebInspector.DOMBreakpointManager.Breakpoint = function(node, type, url, enabled ) | |
513 { | |
514 this.node = node; | |
515 this.path = node.path(); | |
516 this.type = type; | |
517 this.url = url; | |
518 this.enabled = enabled; | |
415 } | 519 } |
416 | 520 |
417 /** | 521 /** |
522 * @type {!WebInspector.DOMBreakpointManager} | |
523 */ | |
524 WebInspector.domBreakpointManager; | |
525 | |
526 /** | |
418 * @constructor | 527 * @constructor |
419 * @extends {WebInspector.VBox} | 528 * @extends {WebInspector.VBox} |
420 */ | 529 */ |
421 WebInspector.DOMBreakpointsSidebarPane.Proxy = function() | 530 WebInspector.DOMBreakpointsSidebarPane.Proxy = function() |
422 { | 531 { |
423 WebInspector.VBox.call(this); | 532 WebInspector.VBox.call(this); |
424 this.registerRequiredCSS("components/breakpointsList.css"); | 533 this.registerRequiredCSS("components/breakpointsList.css"); |
425 } | 534 } |
426 | 535 |
427 WebInspector.DOMBreakpointsSidebarPane.Proxy.prototype = { | 536 WebInspector.DOMBreakpointsSidebarPane.Proxy.prototype = { |
428 wasShown: function() | 537 wasShown: function() |
429 { | 538 { |
430 WebInspector.SimpleView.prototype.wasShown.call(this); | 539 WebInspector.SimpleView.prototype.wasShown.call(this); |
431 var pane = WebInspector.domBreakpointsSidebarPane; | 540 var pane = WebInspector.domBreakpointsSidebarPane; |
432 if (pane.element.parentNode !== this.element) | 541 if (pane.element.parentNode !== this.element) |
433 pane.show(this.element); | 542 pane.show(this.element); |
434 }, | 543 }, |
435 | 544 |
436 __proto__: WebInspector.VBox.prototype | 545 __proto__: WebInspector.VBox.prototype |
437 } | 546 } |
438 | |
439 /** | |
440 * @type {!WebInspector.DOMBreakpointsSidebarPane} | |
441 */ | |
442 WebInspector.domBreakpointsSidebarPane; | |
OLD | NEW |