Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @extends {WebInspector.SDKModel} | |
| 8 * @param {!WebInspector.Target} target | |
| 9 */ | |
| 10 WebInspector.DOMDebuggerModel = function(target) | |
|
lushnikov
2016/08/08 19:53:07
the class has many similar API methods. Let's redu
chenwilliam
2016/08/10 19:48:36
Done.
| |
| 11 { | |
| 12 WebInspector.SDKModel.call(this, WebInspector.DOMDebuggerModel, target); | |
| 13 this._agent = target.domdebuggerAgent(); | |
| 14 this._domBreakpointsSetting = WebInspector.settings.createLocalSetting("domB reakpoints", []); | |
| 15 this._breakpoints = {}; | |
|
lushnikov
2016/08/08 19:53:07
/** @type {!Map<.., ...>} */
this._breakpoints = n
chenwilliam
2016/08/10 19:48:35
Done.
| |
| 16 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.NodeRemoved, this._nodeRemoved, this); | |
| 17 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.InspectedURLChanged, this._inspectedURLChanged, this); | |
| 18 } | |
| 19 | |
| 20 WebInspector.DOMDebuggerModel.Marker = "breakpoint-marker"; | |
| 21 | |
| 22 WebInspector.DOMDebuggerModel.Events = { | |
| 23 BreakpointsChanged: "BreakpointsChanged" | |
| 24 }; | |
| 25 | |
| 26 WebInspector.DOMDebuggerModel.prototype = { | |
| 27 /** | |
| 28 * @return {!Object} | |
|
lushnikov
2016/08/08 19:53:07
please annotate with proper type
chenwilliam
2016/08/10 19:48:36
Done.
| |
| 29 */ | |
| 30 domBreakpoints: function() | |
| 31 { | |
| 32 return this._breakpoints; | |
| 33 }, | |
| 34 | |
| 35 /** | |
| 36 * @param {!WebInspector.DOMNode} node | |
| 37 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 38 * @param {boolean} enabled | |
| 39 */ | |
| 40 setBreakpoint: function(node, type, enabled) | |
| 41 { | |
| 42 this._setBreakpointWithoutSave(node, type, enabled); | |
| 43 this._saveBreakpoints(); | |
| 44 }, | |
| 45 | |
| 46 /** | |
| 47 * @param {!WebInspector.DOMNode} node | |
| 48 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 49 * @param {boolean} enabled | |
| 50 */ | |
| 51 _setBreakpointWithoutSave: function(node, type, enabled) | |
|
lushnikov
2016/08/08 19:53:07
_innerSetBreakpoint
chenwilliam
2016/08/10 19:48:36
Done.
| |
| 52 { | |
| 53 var breakpointId = this.createBreakpointId(node.id, type); | |
| 54 this._breakpoints[breakpointId] = { | |
| 55 node: node, | |
|
lushnikov
2016/08/08 19:53:07
let's create a type for this
chenwilliam
2016/08/10 19:48:36
Done.
| |
| 56 type: type, | |
| 57 url: this._inspectedURL, | |
| 58 path: node.path(), | |
| 59 enabled: enabled | |
| 60 }; | |
| 61 if (enabled) | |
| 62 this._setDOMBreakpoint(node, type); | |
| 63 else | |
| 64 this._removeDOMBreakpoint(node, type); | |
| 65 }, | |
| 66 | |
| 67 /** | |
| 68 * @param {!WebInspector.DOMNode} node | |
| 69 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 70 */ | |
| 71 removeBreakpoint: function(node, type) | |
| 72 { | |
| 73 this._removeBreakpointWithoutSave(node, type); | |
| 74 this._saveBreakpoints(); | |
| 75 }, | |
| 76 | |
| 77 /** | |
| 78 * @param {!WebInspector.DOMNode} node | |
| 79 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 80 */ | |
| 81 _removeBreakpointWithoutSave: function(node, type) | |
| 82 { | |
| 83 var breakpointId = this.createBreakpointId(node.id, type); | |
| 84 if (this._breakpoints[breakpointId].enabled) | |
| 85 this._removeDOMBreakpoint(node, type); | |
| 86 delete this._breakpoints[breakpointId]; | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * @param {!WebInspector.DOMNode} node | |
| 91 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 92 * @param {!Event} event | |
| 93 */ | |
| 94 checkboxClicked: function(node, type, event) | |
|
lushnikov
2016/08/08 19:53:07
the model should not talk in UI terms; this method
chenwilliam
2016/08/10 19:48:36
Done.
| |
| 95 { | |
| 96 this.setBreakpoint(node, type, event.target["checkboxElement"].checked); | |
| 97 }, | |
| 98 | |
| 99 /** | |
| 100 * @param {!WebInspector.DOMNode} node | |
| 101 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 102 */ | |
| 103 toggleBreakpoint: function(node, type) | |
| 104 { | |
| 105 var nodeBreakpoints = this.nodeBreakpoints(node); | |
| 106 if (!nodeBreakpoints[type]) | |
| 107 this.setBreakpoint(node, type, true); | |
| 108 else | |
| 109 this.removeBreakpoint(node, type); | |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * @param {!WebInspector.DOMNode} node | |
| 114 */ | |
| 115 removeBreakpointsForNode: function(node) | |
| 116 { | |
| 117 for (var id in this._breakpoints) { | |
| 118 var breakpoint = this._breakpoints[id]; | |
| 119 if (breakpoint.node === node) | |
| 120 this._removeBreakpointWithoutSave(breakpoint.node, breakpoint.ty pe); | |
| 121 } | |
| 122 this._saveBreakpoints(); | |
| 123 }, | |
| 124 | |
| 125 removeAllBreakpoints: function() | |
| 126 { | |
| 127 for (var id in this._breakpoints) { | |
| 128 var breakpoint = this._breakpoints[id]; | |
| 129 this._removeBreakpointWithoutSave(breakpoint.node, breakpoint.type); | |
| 130 } | |
| 131 this._saveBreakpoints(); | |
| 132 }, | |
| 133 | |
| 134 /** | |
| 135 * @param {!WebInspector.DOMNode} node | |
| 136 * @return {!Object<string, boolean>} | |
| 137 */ | |
| 138 nodeBreakpoints: function(node) | |
| 139 { | |
| 140 var nodeBreakpoints = {}; | |
| 141 for (var id in this._breakpoints) { | |
| 142 var breakpoint = this._breakpoints[id]; | |
| 143 if (breakpoint.node === node && breakpoint.enabled) | |
| 144 nodeBreakpoints[breakpoint.type] = true; | |
| 145 } | |
| 146 return nodeBreakpoints; | |
| 147 }, | |
| 148 | |
| 149 /** | |
| 150 * @param {!WebInspector.DOMModel} domModel | |
| 151 */ | |
| 152 restoreBreakpoints: function(domModel) | |
| 153 { | |
| 154 var pathToBreakpoints = {}; | |
| 155 | |
| 156 /** | |
| 157 * @param {string} path | |
| 158 * @param {?DOMAgent.NodeId} nodeId | |
| 159 * @this {WebInspector.DOMDebuggerModel} | |
| 160 */ | |
| 161 function didPushNodeByPathToFrontend(path, nodeId) | |
| 162 { | |
| 163 var node = nodeId ? domModel.nodeForId(nodeId) : null; | |
| 164 if (!node) | |
| 165 return; | |
| 166 | |
| 167 for (var breakpoint of pathToBreakpoints[path]) | |
| 168 this._setBreakpointWithoutSave(node, breakpoint.type, breakpoint .enabled); | |
| 169 this.dispatchEventToListeners(WebInspector.DOMDebuggerModel.Events.B reakpointsChanged); | |
| 170 } | |
| 171 | |
| 172 var breakpoints = this._domBreakpointsSetting.get(); | |
| 173 for (var breakpoint of breakpoints) { | |
| 174 if (breakpoint.url !== this._inspectedURL) | |
| 175 continue; | |
| 176 var path = breakpoint.path; | |
| 177 if (!pathToBreakpoints[path]) { | |
| 178 pathToBreakpoints[path] = []; | |
| 179 domModel.pushNodeByPathToFrontend(path, didPushNodeByPathToFront end.bind(this, path)); | |
| 180 } | |
| 181 pathToBreakpoints[path].push(breakpoint); | |
| 182 } | |
| 183 }, | |
| 184 | |
| 185 _saveBreakpoints: function() | |
| 186 { | |
| 187 var breakpoints = []; | |
| 188 var storedBreakpoints = this._domBreakpointsSetting.get(); | |
| 189 for (var breakpoint of storedBreakpoints) { | |
| 190 if (breakpoint.url !== this._inspectedURL) | |
| 191 breakpoints.push(breakpoint); | |
| 192 } | |
| 193 for (var id in this._breakpoints) { | |
| 194 var breakpoint = this._breakpoints[id]; | |
| 195 breakpoints.push({ | |
| 196 url: this._inspectedURL, | |
| 197 path: breakpoint.node.path(), | |
| 198 type: breakpoint.type, | |
| 199 enabled: breakpoint.enabled | |
| 200 }); | |
| 201 } | |
| 202 this._domBreakpointsSetting.set(breakpoints); | |
| 203 this.dispatchEventToListeners(WebInspector.DOMDebuggerModel.Events.Break pointsChanged); | |
| 204 }, | |
| 205 | |
| 206 /** | |
| 207 * @param {!WebInspector.DOMNode} node | |
| 208 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 209 */ | |
| 210 _setDOMBreakpoint: function(node, type) | |
|
lushnikov
2016/08/08 19:53:07
let's inline
chenwilliam
2016/08/10 19:48:36
Done.
| |
| 211 { | |
| 212 this._agent.setDOMBreakpoint(node.id, type); | |
| 213 node.setMarker(WebInspector.DOMDebuggerModel.Marker, true); | |
| 214 }, | |
| 215 | |
| 216 /** | |
| 217 * @param {!WebInspector.DOMNode} node | |
| 218 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 219 */ | |
| 220 _removeDOMBreakpoint: function(node, type) | |
|
lushnikov
2016/08/08 19:53:07
let's inline
chenwilliam
2016/08/10 19:48:35
Done.
| |
| 221 { | |
| 222 this._agent.removeDOMBreakpoint(node.id, type); | |
| 223 node.setMarker(WebInspector.DOMDebuggerModel.Marker, this._hasOtherBreak points(node, type) ? true : null); | |
| 224 }, | |
| 225 | |
| 226 /** | |
| 227 * @param {!WebInspector.DOMNode} node | |
| 228 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 229 * @return {boolean} | |
| 230 */ | |
| 231 _hasOtherBreakpoints: function(node, type) | |
| 232 { | |
| 233 for (var id in this._breakpoints) { | |
| 234 var breakpoint = this._breakpoints[id]; | |
| 235 if (breakpoint.node === node && breakpoint.type !== type && breakpoi nt.enabled) | |
| 236 return true; | |
| 237 } | |
| 238 return false; | |
| 239 }, | |
| 240 | |
| 241 /** | |
| 242 * @param {!WebInspector.Event} event | |
| 243 */ | |
| 244 _nodeRemoved: function(event) | |
|
lushnikov
2016/08/08 19:53:07
this method is not used?
chenwilliam
2016/08/10 19:48:35
It's used as a model listener.
WebInspector.targe
| |
| 245 { | |
| 246 var node = event.data.node; | |
| 247 this.removeBreakpointsForNode(node); | |
| 248 var children = node.children(); | |
| 249 if (!children) | |
| 250 return; | |
| 251 for (var child of children) | |
| 252 this.removeBreakpointsForNode(child); | |
| 253 this._saveBreakpoints(); | |
| 254 }, | |
| 255 | |
| 256 /** | |
| 257 * @param {!WebInspector.Event} event | |
| 258 */ | |
| 259 _inspectedURLChanged: function(event) | |
| 260 { | |
| 261 var target = /** @type {!WebInspector.Target} */ (event.data); | |
| 262 if (target !== WebInspector.targetManager.mainTarget()) | |
| 263 return; | |
| 264 this._inspectedURL = target.inspectedURL().removeURLFragment(); | |
| 265 this._breakpoints = {}; | |
| 266 this.dispatchEventToListeners(WebInspector.DOMDebuggerModel.Events.Break pointsChanged); | |
| 267 }, | |
| 268 | |
| 269 /** | |
| 270 * @param {number} nodeId | |
| 271 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 272 * @return {string} | |
| 273 */ | |
| 274 createBreakpointId: function(nodeId, type) | |
|
lushnikov
2016/08/08 19:53:07
this is used only by the DOMBreakpointsSidebarPane
chenwilliam
2016/08/10 19:48:35
OK, I have moved this method to DOMBreakpointsSide
| |
| 275 { | |
| 276 return `${nodeId}:${type}`; | |
| 277 }, | |
| 278 | |
| 279 __proto__: WebInspector.SDKModel.prototype | |
| 280 }; | |
| OLD | NEW |