2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.NativeBreakpointsSidebarPane}
35 WebInspector.DOMBreakpointsSidebarPane = function()
37 WebInspector.NativeBreakpointsSidebarPane.call(this, WebInspector.UIString("DOM Breakpoints"));
39 this._breakpointElements = {};
41 this._breakpointTypes = {
42 SubtreeModified: "subtree-modified",
43 AttributeModified: "attribute-modified",
44 NodeRemoved: "node-removed"
46 this._breakpointTypeLabels = {};
47 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspector.UIString("Subtree Modified");
48 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebInspector.UIString("Attribute Modified");
49 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UIString("Node Removed");
51 this._contextMenuLabels = {};
52 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Subtree modifications" : "Subtree Modifications");
53 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Attributes modifications" : "Attributes Modifications");
54 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Node removal" : "Node Removal");
56 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, this._inspectedURLChanged, this);
57 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspector.DOMModel.Events.NodeRemoved, this._nodeRemoved, this);
60 WebInspector.DOMBreakpointsSidebarPane.prototype = {
61 _inspectedURLChanged: function(event)
63 this._breakpointElements = {};
65 var url = /** @type {string} */ (event.data);
66 this._inspectedURL = url.removeURLFragment();
70 * @param {!WebInspector.DOMNode} node
71 * @param {!WebInspector.ContextMenu} contextMenu
73 populateNodeContextMenu: function(node, contextMenu)
75 if (node.pseudoType())
78 var nodeBreakpoints = {};
79 for (var id in this._breakpointElements) {
80 var element = this._breakpointElements[id];
81 if (element._node === node)
82 nodeBreakpoints[element._type] = true;
86 * @param {string} type
87 * @this {WebInspector.DOMBreakpointsSidebarPane}
89 function toggleBreakpoint(type)
91 if (!nodeBreakpoints[type])
92 this._setBreakpoint(node, type, true);
94 this._removeBreakpoint(node, type);
95 this._saveBreakpoints();
98 var breakPointSubMenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Break on..."));
99 for (var key in this._breakpointTypes) {
100 var type = this._breakpointTypes[key];
101 var label = this._contextMenuLabels[type];
102 breakPointSubMenu.appendCheckboxItem(label, toggleBreakpoint.bind(this, type), nodeBreakpoints[type]);
107 * @param {!WebInspector.DebuggerPausedDetails} details
108 * @param {function(!Element)} callback
110 createBreakpointHitStatusMessage: function(details, callback)
112 var auxData = /** @type {!Object} */ (details.auxData);
113 var domModel = details.target().domModel;
114 if (auxData.type === this._breakpointTypes.SubtreeModified) {
115 var targetNodeObject = details.target().runtimeModel.createRemoteObject(auxData["targetNode"]);
116 targetNodeObject.pushNodeToFrontend(didPushNodeToFrontend.bind(this));
118 this._doCreateBreakpointHitStatusMessage(auxData, domModel.nodeForId(auxData.nodeId), null, callback);
122 * @param {?WebInspector.DOMNode} targetNode
123 * @this {WebInspector.DOMBreakpointsSidebarPane}
125 function didPushNodeToFrontend(targetNode)
128 targetNodeObject.release();
129 this._doCreateBreakpointHitStatusMessage(auxData, domModel.nodeForId(auxData.nodeId), targetNode, callback);
134 * @param {!Object} auxData
135 * @param {?WebInspector.DOMNode} node
136 * @param {?WebInspector.DOMNode} targetNode
137 * @param {function(!Element)} callback
139 _doCreateBreakpointHitStatusMessage: function(auxData, node, targetNode, callback)
142 var typeLabel = this._breakpointTypeLabels[auxData.type];
143 var linkifiedNode = WebInspector.DOMPresentationUtils.linkifyNodeReference(node);
144 var substitutions = [typeLabel, linkifiedNode];
145 var targetNodeLink = "";
147 targetNodeLink = WebInspector.DOMPresentationUtils.linkifyNodeReference(targetNode);
149 if (auxData.type === this._breakpointTypes.SubtreeModified) {
150 if (auxData.insertion) {
151 if (targetNode !== node) {
152 message = "Paused on a \"%s\" breakpoint set on %s, because a new child was added to its descendant %s.";
153 substitutions.push(targetNodeLink);
155 message = "Paused on a \"%s\" breakpoint set on %s, because a new child was added to that node.";
157 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed.";
158 substitutions.push(targetNodeLink);
161 message = "Paused on a \"%s\" breakpoint set on %s.";
163 var element = document.createElement("span");
165 s: function(substitution)
170 function append(a, b)
172 if (typeof b === "string")
173 b = document.createTextNode(b);
174 element.appendChild(b);
176 WebInspector.formatLocalized(message, substitutions, formatters, "", append);
181 _nodeRemoved: function(event)
183 var node = event.data.node;
184 this._removeBreakpointsForNode(event.data.node);
185 var children = node.children();
188 for (var i = 0; i < children.length; ++i)
189 this._removeBreakpointsForNode(children[i]);
190 this._saveBreakpoints();
193 _removeBreakpointsForNode: function(node)
195 for (var id in this._breakpointElements) {
196 var element = this._breakpointElements[id];
197 if (element._node === node)
198 this._removeBreakpoint(element._node, element._type);
202 _setBreakpoint: function(node, type, enabled)
204 var breakpointId = this._createBreakpointId(node.id, type);
205 if (breakpointId in this._breakpointElements)
208 var element = document.createElement("li");
209 element._node = node;
210 element._type = type;
211 element.addEventListener("contextmenu", this._contextMenu.bind(this, node, type), true);
213 var checkboxElement = document.createElement("input");
214 checkboxElement.className = "checkbox-elem";
215 checkboxElement.type = "checkbox";
216 checkboxElement.checked = enabled;
217 checkboxElement.addEventListener("click", this._checkboxClicked.bind(this, node, type), false);
218 element._checkboxElement = checkboxElement;
219 element.appendChild(checkboxElement);
221 var labelElement = document.createElement("span");
222 element.appendChild(labelElement);
224 var linkifiedNode = WebInspector.DOMPresentationUtils.linkifyNodeReference(node);
225 linkifiedNode.classList.add("monospace");
226 labelElement.appendChild(linkifiedNode);
228 var description = document.createElement("div");
229 description.className = "source-text";
230 description.textContent = this._breakpointTypeLabels[type];
231 labelElement.appendChild(description);
233 var currentElement = this.listElement.firstChild;
234 while (currentElement) {
235 if (currentElement._type && currentElement._type < element._type)
237 currentElement = currentElement.nextSibling;
239 this.addListElement(element, currentElement);
240 this._breakpointElements[breakpointId] = element;
242 DOMDebuggerAgent.setDOMBreakpoint(node.id, type);
245 _removeAllBreakpoints: function()
247 for (var id in this._breakpointElements) {
248 var element = this._breakpointElements[id];
249 this._removeBreakpoint(element._node, element._type);
251 this._saveBreakpoints();
254 _removeBreakpoint: function(node, type)
256 var breakpointId = this._createBreakpointId(node.id, type);
257 var element = this._breakpointElements[breakpointId];
261 this.removeListElement(element);
262 delete this._breakpointElements[breakpointId];
263 if (element._checkboxElement.checked)
264 DOMDebuggerAgent.removeDOMBreakpoint(node.id, type);
267 _contextMenu: function(node, type, event)
269 var contextMenu = new WebInspector.ContextMenu(event);
272 * @this {WebInspector.DOMBreakpointsSidebarPane}
274 function removeBreakpoint()
276 this._removeBreakpoint(node, type);
277 this._saveBreakpoints();
279 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove breakpoint" : "Remove Breakpoint"), removeBreakpoint.bind(this));
280 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove all DOM breakpoints" : "Remove All DOM Breakpoints"), this._removeAllBreakpoints.bind(this));
284 _checkboxClicked: function(node, type, event)
286 if (event.target.checked)
287 DOMDebuggerAgent.setDOMBreakpoint(node.id, type);
289 DOMDebuggerAgent.removeDOMBreakpoint(node.id, type);
290 this._saveBreakpoints();
293 highlightBreakpoint: function(auxData)
295 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type);
296 var element = this._breakpointElements[breakpointId];
300 element.classList.add("breakpoint-hit");
301 this._highlightedElement = element;
304 clearBreakpointHighlight: function()
306 if (this._highlightedElement) {
307 this._highlightedElement.classList.remove("breakpoint-hit");
308 delete this._highlightedElement;
312 _createBreakpointId: function(nodeId, type)
314 return nodeId + ":" + type;
317 _saveBreakpoints: function()
319 var breakpoints = [];
320 var storedBreakpoints = WebInspector.settings.domBreakpoints.get();
321 for (var i = 0; i < storedBreakpoints.length; ++i) {
322 var breakpoint = storedBreakpoints[i];
323 if (breakpoint.url !== this._inspectedURL)
324 breakpoints.push(breakpoint);
326 for (var id in this._breakpointElements) {
327 var element = this._breakpointElements[id];
328 breakpoints.push({ url: this._inspectedURL, path: element._node.path(), type: element._type, enabled: element._checkboxElement.checked });
330 WebInspector.settings.domBreakpoints.set(breakpoints);
334 * @param {!WebInspector.Target} target
336 restoreBreakpoints: function(target)
338 var pathToBreakpoints = {};
341 * @param {string} path
342 * @param {?DOMAgent.NodeId} nodeId
343 * @this {WebInspector.DOMBreakpointsSidebarPane}
345 function didPushNodeByPathToFrontend(path, nodeId)
347 var node = nodeId ? target.domModel.nodeForId(nodeId) : null;
351 var breakpoints = pathToBreakpoints[path];
352 for (var i = 0; i < breakpoints.length; ++i)
353 this._setBreakpoint(node, breakpoints[i].type, breakpoints[i].enabled);
356 var breakpoints = WebInspector.settings.domBreakpoints.get();
357 for (var i = 0; i < breakpoints.length; ++i) {
358 var breakpoint = breakpoints[i];
359 if (breakpoint.url !== this._inspectedURL)
361 var path = breakpoint.path;
362 if (!pathToBreakpoints[path]) {
363 pathToBreakpoints[path] = [];
364 target.domModel.pushNodeByPathToFrontend(path, didPushNodeByPathToFrontend.bind(this, path));
366 pathToBreakpoints[path].push(breakpoint);
371 * @param {!WebInspector.Panel} panel
372 * @return {!WebInspector.DOMBreakpointsSidebarPane.Proxy}
374 createProxy: function(panel)
376 var proxy = new WebInspector.DOMBreakpointsSidebarPane.Proxy(this, panel);
379 this._proxies.push(proxy);
383 onContentReady: function()
385 for (var i = 0; i != this._proxies.length; i++)
386 this._proxies[i].onContentReady();
389 __proto__: WebInspector.NativeBreakpointsSidebarPane.prototype
394 * @extends {WebInspector.SidebarPane}
395 * @param {!WebInspector.DOMBreakpointsSidebarPane} pane
396 * @param {!WebInspector.Panel} panel
398 WebInspector.DOMBreakpointsSidebarPane.Proxy = function(pane, panel)
400 WebInspector.View.__assert(!pane.titleElement.firstChild, "Cannot create proxy for a sidebar pane with a toolbar");
402 WebInspector.SidebarPane.call(this, pane.title());
403 this.registerRequiredCSS("breakpointsList.css");
405 this._wrappedPane = pane;
408 this.bodyElement.remove();
409 this.bodyElement = this._wrappedPane.bodyElement;
412 WebInspector.DOMBreakpointsSidebarPane.Proxy.prototype = {
415 this._wrappedPane.expand();
418 onContentReady: function()
420 if (this._panel.isShowing())
421 this._reattachBody();
423 WebInspector.SidebarPane.prototype.onContentReady.call(this);
428 WebInspector.SidebarPane.prototype.wasShown.call(this);
429 this._reattachBody();
432 _reattachBody: function()
434 if (this.bodyElement.parentNode !== this.element)
435 this.element.appendChild(this.bodyElement);
438 __proto__: WebInspector.SidebarPane.prototype
442 * @type {!WebInspector.DOMBreakpointsSidebarPane}
444 WebInspector.domBreakpointsSidebarPane;