Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/DOMBreakpointsSidebarPane.js

Issue 2191183003: DevTools: extract model from DOMBreakpointsSidebarPane (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.BreakpointsSidebarPaneBase} 33 * @extends {WebInspector.BreakpointsSidebarPaneBase}
34 */ 34 */
35 WebInspector.DOMBreakpointsSidebarPane = function() 35 WebInspector.DOMBreakpointsSidebarPane = function()
36 { 36 {
37 WebInspector.BreakpointsSidebarPaneBase.call(this, WebInspector.UIString("DO M Breakpoints")); 37 WebInspector.BreakpointsSidebarPaneBase.call(this, WebInspector.UIString("DO M Breakpoints"));
38 this._domBreakpointsSetting = WebInspector.settings.createLocalSetting("domB reakpoints", []);
39 this.listElement.classList.add("dom-breakpoints-list"); 38 this.listElement.classList.add("dom-breakpoints-list");
40 39
41 this._breakpointElements = {}; 40 this._breakpointElements = {};
42 41
43 this._breakpointTypes = { 42 this._breakpointTypes = {
44 SubtreeModified: "subtree-modified", 43 SubtreeModified: "subtree-modified",
45 AttributeModified: "attribute-modified", 44 AttributeModified: "attribute-modified",
46 NodeRemoved: "node-removed" 45 NodeRemoved: "node-removed"
47 }; 46 };
48 this._breakpointTypeLabels = {}; 47 this._breakpointTypeLabels = {};
49 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspe ctor.UIString("Subtree Modified"); 48 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspe ctor.UIString("Subtree Modified");
50 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebIns pector.UIString("Attribute Modified"); 49 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebIns pector.UIString("Attribute Modified");
51 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector .UIString("Node Removed"); 50 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector .UIString("Node Removed");
52 51
53 this._contextMenuLabels = {}; 52 this._contextMenuLabels = {};
54 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspecto r.UIString.capitalize("Subtree ^modifications"); 53 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspecto r.UIString.capitalize("Subtree ^modifications");
55 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspec tor.UIString.capitalize("Attributes ^modifications"); 54 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspec tor.UIString.capitalize("Attributes ^modifications");
56 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UI String.capitalize("Node ^removal"); 55 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UI String.capitalize("Node ^removal");
57 56 WebInspector.targetManager.addModelListener(WebInspector.DOMDebuggerModel, W ebInspector.DOMDebuggerModel.Events.BreakpointsChanged, this._reloadBreakpointEl ements, this);
58 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.InspectedURLChanged, this._inspectedURLChanged, this);
59 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.NodeRemoved, this._nodeRemoved, this);
60 } 57 }
61 58
62 WebInspector.DOMBreakpointsSidebarPane.Marker = "breakpoint-marker";
63
64 WebInspector.DOMBreakpointsSidebarPane.prototype = { 59 WebInspector.DOMBreakpointsSidebarPane.prototype = {
65 _inspectedURLChanged: function(event) 60 /**
61 * @return {!WebInspector.DOMDebuggerModel}
62 */
63 domDebuggerModel: function()
lushnikov 2016/08/08 19:53:07 there should be no method domDebuggerModel(): DOMB
chenwilliam 2016/08/10 19:48:35 Done.
66 { 64 {
67 var target = /** @type {!WebInspector.Target} */ (event.data); 65 var targets = WebInspector.targetManager.targets(WebInspector.Target.Cap ability.DOM);
68 if (target !== WebInspector.targetManager.mainTarget()) 66 var domDebuggerModels = targets.map(target => target.model(WebInspector. DOMDebuggerModel));
69 return; 67 return domDebuggerModels[0];
chenwilliam 2016/08/06 00:28:22 This feels a bit hacky, so perhaps there's a bette
lushnikov 2016/08/08 19:53:06 In future, they'll be in separate targets.
chenwilliam 2016/08/10 19:48:35 Done.
70 this._breakpointElements = {};
71 this.reset();
72 this._inspectedURL = target.inspectedURL().removeURLFragment();
73 }, 68 },
74 69
75 /** 70 /**
76 * @param {!WebInspector.DOMNode} node 71 * @param {!WebInspector.DOMNode} node
77 * @param {!WebInspector.ContextMenu} contextMenu 72 * @param {!WebInspector.ContextMenu} contextMenu
78 * @param {boolean} createSubMenu 73 * @param {boolean} createSubMenu
79 */ 74 */
80 populateNodeContextMenu: function(node, contextMenu, createSubMenu) 75 populateNodeContextMenu: function(node, contextMenu, createSubMenu)
81 { 76 {
82 if (node.pseudoType()) 77 if (node.pseudoType())
83 return; 78 return;
84 79
85 var nodeBreakpoints = this._nodeBreakpoints(node); 80 var nodeBreakpoints = this.domDebuggerModel().nodeBreakpoints(node);
86 81
87 /** 82 /**
88 * @param {!DOMDebuggerAgent.DOMBreakpointType} type 83 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
89 * @this {WebInspector.DOMBreakpointsSidebarPane} 84 * @this {WebInspector.DOMBreakpointsSidebarPane}
90 */ 85 */
91 function toggleBreakpoint(type) 86 function toggleBreakpoint(type)
92 { 87 {
93 if (!nodeBreakpoints[type]) 88 this.domDebuggerModel().toggleBreakpoint(node, type);
94 this._setBreakpoint(node, type, true);
95 else
96 this._removeBreakpoint(node, type);
97 this._saveBreakpoints();
98 } 89 }
99 90
100 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI nspector.UIString("Break on...")) : contextMenu; 91 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI nspector.UIString("Break on...")) : contextMenu;
101 for (var key in this._breakpointTypes) { 92 for (var key in this._breakpointTypes) {
102 var type = this._breakpointTypes[key]; 93 var type = this._breakpointTypes[key];
103 var label = this._contextMenuLabels[type]; 94 var label = this._contextMenuLabels[type];
104 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(this , type), nodeBreakpoints[type]); 95 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(this , type), nodeBreakpoints[type]);
105 } 96 }
106 }, 97 },
107 98
108 /** 99 /**
109 * @param {!WebInspector.DOMNode} node
110 * @return {!Object<string, boolean>}
111 */
112 _nodeBreakpoints: function(node)
113 {
114 var nodeBreakpoints = {};
115 for (var id in this._breakpointElements) {
116 var element = this._breakpointElements[id];
117 if (element._node === node && element._checkboxElement.checked)
118 nodeBreakpoints[element._type] = true;
119 }
120 return nodeBreakpoints;
121 },
122
123 /**
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 100 * @param {!WebInspector.DebuggerPausedDetails} details
139 * @return {!Element} 101 * @return {!Element}
140 */ 102 */
141 createBreakpointHitStatusMessage: function(details) 103 createBreakpointHitStatusMessage: function(details)
142 { 104 {
143 var auxData = /** @type {!Object} */ (details.auxData); 105 var auxData = /** @type {!Object} */ (details.auxData);
144 var message = "Paused on a \"%s\" breakpoint."; 106 var message = "Paused on a \"%s\" breakpoint.";
145 var substitutions = []; 107 var substitutions = [];
146 substitutions.push(this._breakpointTypeLabels[auxData["type"]]); 108 substitutions.push(this._breakpointTypeLabels[auxData["type"]]);
147 109
(...skipping 19 matching lines...) Expand all
167 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed."; 129 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed.";
168 substitutions.push(targetNodeLink); 130 substitutions.push(targetNodeLink);
169 } 131 }
170 } else { 132 } else {
171 message = "Paused on a \"%s\" breakpoint set on %s."; 133 message = "Paused on a \"%s\" breakpoint set on %s.";
172 } 134 }
173 135
174 return WebInspector.formatLocalized(message, substitutions); 136 return WebInspector.formatLocalized(message, substitutions);
175 }, 137 },
176 138
177 _nodeRemoved: function(event) 139 _reloadBreakpointElements: function()
178 { 140 {
179 var node = event.data.node; 141 this._breakpointElements = {};
180 this._removeBreakpointsForNode(event.data.node); 142 this.reset();
chenwilliam 2016/08/06 00:28:22 This could be optimized but I did a quick check of
181 var children = node.children(); 143 var breakpoints = this.domDebuggerModel().domBreakpoints();
182 if (!children) 144 for (var id in breakpoints) {
183 return; 145 var breakpoint = breakpoints[id];
184 for (var i = 0; i < children.length; ++i) 146 this._breakpointElements[id] = this._createBreakpointElement(breakpo int.node, breakpoint.type, breakpoint.enabled);
185 this._removeBreakpointsForNode(children[i]);
186 this._saveBreakpoints();
187 },
188
189 /**
190 * @param {!WebInspector.DOMNode} node
191 */
192 _removeBreakpointsForNode: function(node)
193 {
194 for (var id in this._breakpointElements) {
195 var element = this._breakpointElements[id];
196 if (element._node === node)
197 this._removeBreakpoint(element._node, element._type);
198 } 147 }
199 }, 148 },
200 149
201 /** 150 /**
202 * @param {!WebInspector.DOMNode} node
203 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
204 * @param {boolean} enabled
205 */
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 151 * @param {!WebInspector.DOMNode} node
223 * @param {!DOMDebuggerAgent.DOMBreakpointType} type 152 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
224 * @param {boolean} enabled 153 * @param {boolean} enabled
225 */ 154 */
226 _createBreakpointElement: function(node, type, enabled) 155 _createBreakpointElement: function(node, type, enabled)
227 { 156 {
228 var element = createElement("li"); 157 var element = createElement("li");
229 element._node = node; 158 element._node = node;
230 element._type = type; 159 element._type = type;
231 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod e, type), true); 160 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod e, type), true);
232 161
233 var checkboxLabel = createCheckboxLabel("", enabled); 162 var checkboxLabel = createCheckboxLabel("", enabled);
234 checkboxLabel.addEventListener("click", this._checkboxClicked.bind(this, node, type), false); 163 var checkboxClicked = this.domDebuggerModel().checkboxClicked.bind(this. domDebuggerModel(), node, type);
164 checkboxLabel.addEventListener("click", checkboxClicked, false);
235 element._checkboxElement = checkboxLabel.checkboxElement; 165 element._checkboxElement = checkboxLabel.checkboxElement;
236 element.appendChild(checkboxLabel); 166 element.appendChild(checkboxLabel);
237 167
238 var labelElement = createElementWithClass("div", "dom-breakpoint"); 168 var labelElement = createElementWithClass("div", "dom-breakpoint");
239 element.appendChild(labelElement); 169 element.appendChild(labelElement);
240 170
241 var linkifiedNode = WebInspector.DOMPresentationUtils.linkifyNodeReferen ce(node); 171 var linkifiedNode = WebInspector.DOMPresentationUtils.linkifyNodeReferen ce(node);
242 linkifiedNode.classList.add("monospace"); 172 linkifiedNode.classList.add("monospace");
243 linkifiedNode.style.display = "block"; 173 linkifiedNode.style.display = "block";
244 labelElement.appendChild(linkifiedNode); 174 labelElement.appendChild(linkifiedNode);
245 175
246 var description = createElement("div"); 176 var description = createElement("div");
247 description.textContent = this._breakpointTypeLabels[type]; 177 description.textContent = this._breakpointTypeLabels[type];
248 labelElement.appendChild(description); 178 labelElement.appendChild(description);
249 179
250 var currentElement = this.listElement.firstChild; 180 var currentElement = this.listElement.firstChild;
251 while (currentElement) { 181 while (currentElement) {
252 if (currentElement._type && currentElement._type < element._type) 182 if (currentElement._type && currentElement._type < element._type)
253 break; 183 break;
254 currentElement = currentElement.nextSibling; 184 currentElement = currentElement.nextSibling;
255 } 185 }
256 this.addListElement(element, currentElement); 186 this.addListElement(element, currentElement);
257 return element; 187 return element;
258 }, 188 },
259 189
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 /** 190 /**
270 * @param {!WebInspector.DOMNode} node 191 * @param {!WebInspector.DOMNode} node
271 * @param {!DOMDebuggerAgent.DOMBreakpointType} type 192 * @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 193 * @param {!Event} event
291 */ 194 */
292 _contextMenu: function(node, type, event) 195 _contextMenu: function(node, type, event)
293 { 196 {
294 var contextMenu = new WebInspector.ContextMenu(event); 197 var contextMenu = new WebInspector.ContextMenu(event);
295 198
296 /** 199 /**
297 * @this {WebInspector.DOMBreakpointsSidebarPane} 200 * @this {WebInspector.DOMBreakpointsSidebarPane}
298 */ 201 */
299 function removeBreakpoint() 202 var removeBreakpoint = () => this.domDebuggerModel().removeBreakpoint(no de, type);
300 { 203 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo int"), removeBreakpoint);
301 this._removeBreakpoint(node, type); 204
302 this._saveBreakpoints(); 205 /**
303 } 206 * @this {WebInspector.DOMBreakpointsSidebarPane}
304 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo int"), removeBreakpoint.bind(this)); 207 */
305 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^all DOM breakpoints"), this._removeAllBreakpoints.bind(this)); 208 var removeAllBreakpoints = () => this.domDebuggerModel().removeAllBreakp oints();
209 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^all DOM breakpoints"), removeAllBreakpoints);
306 contextMenu.show(); 210 contextMenu.show();
307 }, 211 },
308 212
309 /**
310 * @param {!WebInspector.DOMNode} node
311 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
312 * @param {!Event} event
313 */
314 _checkboxClicked: function(node, type, event)
315 {
316 if (event.target.checked)
317 node.target().domdebuggerAgent().setDOMBreakpoint(node.id, type);
318 else
319 node.target().domdebuggerAgent().removeDOMBreakpoint(node.id, type);
320 this._saveBreakpoints();
321 },
322
323 highlightBreakpoint: function(auxData) 213 highlightBreakpoint: function(auxData)
324 { 214 {
325 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type ); 215 var breakpointId = this.domDebuggerModel().createBreakpointId(auxData.no deId, auxData.type);
326 var element = this._breakpointElements[breakpointId]; 216 var element = this._breakpointElements[breakpointId];
327 if (!element) 217 if (!element)
328 return; 218 return;
329 this.revealWidget(); 219 this.revealWidget();
330 element.classList.add("breakpoint-hit"); 220 element.classList.add("breakpoint-hit");
331 this._highlightedElement = element; 221 this._highlightedElement = element;
332 }, 222 },
333 223
334 clearBreakpointHighlight: function() 224 clearBreakpointHighlight: function()
335 { 225 {
336 if (this._highlightedElement) { 226 if (this._highlightedElement) {
337 this._highlightedElement.classList.remove("breakpoint-hit"); 227 this._highlightedElement.classList.remove("breakpoint-hit");
338 delete this._highlightedElement; 228 delete this._highlightedElement;
339 } 229 }
340 }, 230 },
341 231
342 /** 232 /**
343 * @param {number} nodeId
344 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
345 */
346 _createBreakpointId: function(nodeId, type)
347 {
348 return nodeId + ":" + type;
349 },
350
351 _saveBreakpoints: function()
352 {
353 var breakpoints = [];
354 var storedBreakpoints = this._domBreakpointsSetting.get();
355 for (var i = 0; i < storedBreakpoints.length; ++i) {
356 var breakpoint = storedBreakpoints[i];
357 if (breakpoint.url !== this._inspectedURL)
358 breakpoints.push(breakpoint);
359 }
360 for (var id in this._breakpointElements) {
361 var element = this._breakpointElements[id];
362 breakpoints.push({ url: this._inspectedURL, path: element._node.path (), type: element._type, enabled: element._checkboxElement.checked });
363 }
364 this._domBreakpointsSetting.set(breakpoints);
365 },
366
367 /**
368 * @param {!WebInspector.DOMModel} domModel 233 * @param {!WebInspector.DOMModel} domModel
369 */ 234 */
370 restoreBreakpoints: function(domModel) 235 restoreBreakpoints: function(domModel)
371 { 236 {
372 var pathToBreakpoints = {}; 237 this.domDebuggerModel().restoreBreakpoints(domModel);
373
374 /**
375 * @param {string} path
376 * @param {?DOMAgent.NodeId} nodeId
377 * @this {WebInspector.DOMBreakpointsSidebarPane}
378 */
379 function didPushNodeByPathToFrontend(path, nodeId)
380 {
381 var node = nodeId ? domModel.nodeForId(nodeId) : null;
382 if (!node)
383 return;
384
385 var breakpoints = pathToBreakpoints[path];
386 for (var i = 0; i < breakpoints.length; ++i)
387 this._setBreakpoint(node, breakpoints[i].type, breakpoints[i].en abled);
388 }
389
390 var breakpoints = this._domBreakpointsSetting.get();
391 for (var i = 0; i < breakpoints.length; ++i) {
392 var breakpoint = breakpoints[i];
393 if (breakpoint.url !== this._inspectedURL)
394 continue;
395 var path = breakpoint.path;
396 if (!pathToBreakpoints[path]) {
397 pathToBreakpoints[path] = [];
398 domModel.pushNodeByPathToFrontend(path, didPushNodeByPathToFront end.bind(this, path));
399 }
400 pathToBreakpoints[path].push(breakpoint);
401 }
402 }, 238 },
403 239
404 /** 240 /**
405 * @param {!WebInspector.Panel} panel 241 * @param {!WebInspector.Panel} panel
406 * @return {!WebInspector.DOMBreakpointsSidebarPane.Proxy} 242 * @return {!WebInspector.DOMBreakpointsSidebarPane.Proxy}
407 */ 243 */
408 createProxy: function(panel) 244 createProxy: function(panel)
409 { 245 {
410 var proxy = new WebInspector.DOMBreakpointsSidebarPane.Proxy(this, panel ); 246 var proxy = new WebInspector.DOMBreakpointsSidebarPane.Proxy(this, panel );
411 if (!this._proxies) 247 if (!this._proxies)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 this._wrappedPane.show(this.element); 281 this._wrappedPane.show(this.element);
446 }, 282 },
447 283
448 __proto__: WebInspector.View.prototype 284 __proto__: WebInspector.View.prototype
449 } 285 }
450 286
451 /** 287 /**
452 * @type {!WebInspector.DOMBreakpointsSidebarPane} 288 * @type {!WebInspector.DOMBreakpointsSidebarPane}
453 */ 289 */
454 WebInspector.domBreakpointsSidebarPane; 290 WebInspector.domBreakpointsSidebarPane;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698