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

Side by Side Diff: Source/devtools/front_end/sdk/DebuggerWorkspaceBinding.js

Issue 299443016: DevTools: Decouple debugger model from UI entities (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merge DebuggerScriptMapping into DebuggerWorkspaceBinding Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @implements {WebInspector.TargetManager.Observer}
8 * @param {!WebInspector.TargetManager} targetManager
9 * @param {!WebInspector.Workspace} workspace
10 * @param {!WebInspector.NetworkWorkspaceBinding} networkWorkspaceBinding
7 */ 11 */
8 WebInspector.DebuggerWorkspaceBinding = function() 12 WebInspector.DebuggerWorkspaceBinding = function(targetManager, workspace, netwo rkWorkspaceBinding)
9 { 13 {
14 this._workspace = workspace;
15 this._networkWorkspaceBinding = networkWorkspaceBinding;
16
17 /** @type {!Map.<!WebInspector.Target, !WebInspector.DebuggerWorkspaceBindin g.TargetData>} */
18 this._targetToData = new Map();
19 targetManager.observeTargets(this);
20
21 targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.Debu ggerModel.Events.GlobalObjectCleared, this._globalObjectCleared, this);
22 targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.Debu ggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
10 } 23 }
11 24
12 WebInspector.DebuggerWorkspaceBinding.prototype = { 25 WebInspector.DebuggerWorkspaceBinding.prototype = {
26 /**
27 * @param {!WebInspector.Target} target
28 */
29 targetAdded: function(target)
30 {
31 this._targetToData.put(target, new WebInspector.DebuggerWorkspaceBinding .TargetData(target, this));
32 },
33
34 /**
35 * @param {!WebInspector.Target} target
36 */
37 targetRemoved: function(target)
38 {
39 this._targetToData.remove(target)._dispose();
40 },
41
42 /**
43 * @param {!WebInspector.Script} script
44 * @param {!WebInspector.SourceMapping} sourceMapping
45 */
46 pushSourceMapping: function(script, sourceMapping)
47 {
48 var info = this._ensureInfoForScript(script);
49 info._pushSourceMapping(sourceMapping);
50 },
51
52 /**
53 * @param {!WebInspector.Script} script
54 * @return {!WebInspector.SourceMapping}
55 */
56 popSourceMapping: function(script)
57 {
58 var info = this._infoForScript(script.target(), script.scriptId);
59 console.assert(info);
60 return info._popSourceMapping();
61 },
62
63 /**
64 * @param {!WebInspector.Script} script
65 */
66 updateLocations: function(script)
67 {
68 var info = this._infoForScript(script.target(), script.scriptId);
69 if (info)
70 info._updateLocations();
71 },
13 72
14 /** 73 /**
15 * @param {!WebInspector.DebuggerModel.Location} rawLocation 74 * @param {!WebInspector.DebuggerModel.Location} rawLocation
16 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel egate 75 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel egate
17 * @return {!WebInspector.Script.Location} 76 * @return {!WebInspector.DebuggerWorkspaceBinding.Location}
18 */ 77 */
19 createLiveLocation: function(rawLocation, updateDelegate) 78 createLiveLocation: function(rawLocation, updateDelegate)
20 { 79 {
21 return rawLocation.createLiveLocation(updateDelegate); 80 var info = this._infoForScript(rawLocation.target(), rawLocation.scriptI d);
81 console.assert(info);
82 var location = new WebInspector.DebuggerWorkspaceBinding.Location(info._ script, rawLocation, this, updateDelegate);
83 info._addLocation(location);
84 return location;
22 }, 85 },
23 86
24 /** 87 /**
25 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame 88 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame
26 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel egate 89 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel egate
27 * @return {!WebInspector.Script.Location} 90 * @return {!WebInspector.DebuggerWorkspaceBinding.Location}
28 */ 91 */
29 createCallFrameLiveLocation: function(callFrame, updateDelegate) 92 createCallFrameLiveLocation: function(callFrame, updateDelegate)
30 { 93 {
31 return callFrame.createLiveLocation(updateDelegate); 94 var target = callFrame.target();
95 this._ensureInfoForScript(callFrame.script)
96 var location = this.createLiveLocation(callFrame.location(), updateDeleg ate);
97 this._registerCallFrameLiveLocation(target, location);
98 return location;
32 }, 99 },
33 100
34 /** 101 /**
35 * @param {!WebInspector.DebuggerModel.Location} rawLocation 102 * @param {!WebInspector.DebuggerModel.Location} rawLocation
36 * @return {?WebInspector.UILocation} 103 * @return {!WebInspector.UILocation}
37 */ 104 */
38 rawLocationToUILocation: function(rawLocation) 105 rawLocationToUILocation: function(rawLocation)
39 { 106 {
40 return rawLocation.target().debuggerModel.rawLocationToUILocation(rawLoc ation); 107 var info = this._infoForScript(rawLocation.target(), rawLocation.scriptI d);
108 console.assert(info);
109 return info._rawLocationToUILocation(rawLocation);
41 }, 110 },
42 111
43 /** 112 /**
44 * @param {!WebInspector.Target} target 113 * @param {!WebInspector.Target} target
45 * @param {!WebInspector.UISourceCode} uiSourceCode 114 * @param {!WebInspector.UISourceCode} uiSourceCode
46 * @param {number} lineNumber 115 * @param {number} lineNumber
47 * @param {number} columnNumber 116 * @param {number} columnNumber
48 * @return {!WebInspector.DebuggerModel.Location} 117 * @return {!WebInspector.DebuggerModel.Location}
49 */ 118 */
50 uiLocationToRawLocation: function(target, uiSourceCode, lineNumber, columnNu mber) 119 uiLocationToRawLocation: function(target, uiSourceCode, lineNumber, columnNu mber)
51 { 120 {
52 return /** @type {!WebInspector.DebuggerModel.Location} */ (uiSourceCode .uiLocationToRawLocation(target, lineNumber, columnNumber)); 121 return /** @type {!WebInspector.DebuggerModel.Location} */ (uiSourceCode .uiLocationToRawLocation(target, lineNumber, columnNumber));
122 },
123
124 /**
125 * @param {!WebInspector.Target} target
126 * @return {?WebInspector.LiveEditSupport}
127 */
128 liveEditSupport: function(target)
129 {
130 var targetData = this._targetToData.get(target);
131 return targetData ? targetData._liveEditSupport : null;
132 },
133
134 /**
135 * @param {!WebInspector.Event} event
136 */
137 _globalObjectCleared: function(event)
138 {
139 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.ta rget);
140 this._reset(debuggerModel.target());
141 },
142
143 /**
144 * @param {!WebInspector.Target} target
145 */
146 _reset: function(target)
147 {
148 var targetData = this._targetToData.get(target);
149 targetData.callFrameLocations.values().forEach(function(location) { loca tion.dispose(); });
150 targetData.callFrameLocations.clear();
151 },
152
153 /**
154 * @param {!WebInspector.Script} script
155 * @return {!WebInspector.DebuggerWorkspaceBinding.ScriptInfo}
156 */
157 _ensureInfoForScript: function(script)
158 {
159 var scriptDataMap = this._targetToData.get(script.target()).scriptDataMa p;
160 var info = scriptDataMap.get(script.scriptId);
161 if (!info) {
162 info = new WebInspector.DebuggerWorkspaceBinding.ScriptInfo(script);
163 scriptDataMap.put(script.scriptId, info);
164 }
165 return info;
166 },
167
168
169 /**
170 * @param {!WebInspector.Target} target
171 * @param {string} scriptId
172 * @return {?WebInspector.DebuggerWorkspaceBinding.ScriptInfo}
173 */
174 _infoForScript: function(target, scriptId)
175 {
176 var data = this._targetToData.get(target);
177 if (!data)
178 return null;
179 return data.scriptDataMap.get(scriptId) || null;
180 },
181
182 /**
183 * @param {!WebInspector.Target} target
184 * @param {!WebInspector.DebuggerWorkspaceBinding.Location} location
185 */
186 _registerCallFrameLiveLocation: function(target, location)
187 {
188 var locations = this._targetToData.get(target).callFrameLocations;
189 locations.add(location);
190 },
191
192 /**
193 * @param {!WebInspector.DebuggerWorkspaceBinding.Location} location
194 */
195 _removeLiveLocation: function(location)
196 {
197 var info = this._infoForScript(location._script.target(), location._scri pt.scriptId);
198 if (info)
199 info._removeLocation(location);
200 },
201
202 /**
203 * @param {!WebInspector.Event} event
204 */
205 _debuggerResumed: function(event)
206 {
207 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.ta rget);
208 this._reset(debuggerModel.target());
53 } 209 }
54 } 210 }
55 211
56 /** 212 /**
213 * @constructor
214 * @param {!WebInspector.Target} target
215 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
216 */
217 WebInspector.DebuggerWorkspaceBinding.TargetData = function(target, debuggerWork spaceBinding)
218 {
219 /** @type {!StringMap.<!WebInspector.DebuggerWorkspaceBinding.ScriptInfo>} * /
220 this.scriptDataMap = new StringMap();
221
222 /** @type {!Set.<!WebInspector.DebuggerWorkspaceBinding.Location>} */
223 this.callFrameLocations = new Set();
224
225 var debuggerModel = target.debuggerModel;
226 var workspace = debuggerWorkspaceBinding._workspace;
227
228 this._liveEditSupport = new WebInspector.LiveEditSupport(target, workspace, debuggerWorkspaceBinding);
229 this._defaultMapping = new WebInspector.DefaultScriptMapping(debuggerModel, workspace, debuggerWorkspaceBinding);
230 this._resourceMapping = new WebInspector.ResourceScriptMapping(debuggerModel , workspace, debuggerWorkspaceBinding);
231 this._compilerMapping = new WebInspector.CompilerScriptMapping(debuggerModel , workspace, debuggerWorkspaceBinding._networkWorkspaceBinding, debuggerWorkspac eBinding);
232
233 /** @type {!WebInspector.LiveEditSupport} */
234 this._liveEditSupport = new WebInspector.LiveEditSupport(target, workspace, debuggerWorkspaceBinding);
235
236 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScrip tSource, this._parsedScriptSource, this);
237 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToPar seScriptSource, this._parsedScriptSource, this);
238 }
239
240 WebInspector.DebuggerWorkspaceBinding.TargetData.prototype = {
241 /**
242 * @param {!WebInspector.Event} event
243 */
244 _parsedScriptSource: function(event)
245 {
246 var script = /** @type {!WebInspector.Script} */ (event.data);
247 this._defaultMapping.addScript(script);
248
249 if (script.isSnippet()) {
250 WebInspector.scriptSnippetModel.addScript(script);
251 return;
252 }
253
254 this._resourceMapping.addScript(script);
255
256 if (WebInspector.settings.jsSourceMapsEnabled.get())
257 this._compilerMapping.addScript(script);
258 },
259
260 _dispose: function()
261 {
262 this._compilerMapping.dispose();
263 this._resourceMapping.dispose();
264 this._defaultMapping.dispose();
265 }
266 }
267
268 /**
269 * @constructor
270 * @param {!WebInspector.Script} script
271 */
272 WebInspector.DebuggerWorkspaceBinding.ScriptInfo = function(script)
273 {
274 this._script = script;
275
276 /** @type {!Array.<!WebInspector.SourceMapping>} */
277 this._sourceMappings = [];
278
279 /** @type {!Set.<!WebInspector.LiveLocation>} */
280 this._locations = new Set();
281 }
282
283 WebInspector.DebuggerWorkspaceBinding.ScriptInfo.prototype = {
284 /**
285 * @param {!WebInspector.SourceMapping} sourceMapping
286 */
287 _pushSourceMapping: function(sourceMapping)
288 {
289 this._sourceMappings.push(sourceMapping);
290 this._updateLocations();
291 },
292
293 /**
294 * @return {!WebInspector.SourceMapping}
295 */
296 _popSourceMapping: function()
297 {
298 var sourceMapping = this._sourceMappings.pop();
299 this._updateLocations();
300 return sourceMapping;
301 },
302
303 /**
304 * @param {!WebInspector.LiveLocation} location
305 */
306 _addLocation: function(location)
307 {
308 this._locations.add(location);
309 location.update();
310 },
311
312 /**
313 * @param {!WebInspector.LiveLocation} location
314 */
315 _removeLocation: function(location)
316 {
317 this._locations.remove(location);
318 },
319
320 _updateLocations: function()
321 {
322 var items = this._locations.values();
323 for (var i = 0; i < items.length; ++i)
324 items[i].update();
325 },
326
327 /**
328 * @param {!WebInspector.DebuggerModel.Location} rawLocation
329 * @return {!WebInspector.UILocation}
330 */
331 _rawLocationToUILocation: function(rawLocation)
332 {
333 var uiLocation;
334 for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i )
335 uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLoca tion);
336 console.assert(uiLocation, "Script raw location cannot be mapped to any UI location.");
337 return /** @type {!WebInspector.UILocation} */ (uiLocation);
338 }
339 }
340
341
342 /**
343 * @constructor
344 * @extends {WebInspector.LiveLocation}
345 * @param {!WebInspector.Script} script
346 * @param {!WebInspector.DebuggerModel.Location} rawLocation
347 * @param {!WebInspector.DebuggerWorkspaceBinding} binding
348 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDelegat e
349 */
350 WebInspector.DebuggerWorkspaceBinding.Location = function(script, rawLocation, b inding, updateDelegate)
351 {
352 WebInspector.LiveLocation.call(this, rawLocation, updateDelegate);
353 this._script = script;
354 this._binding = binding;
355 }
356
357 WebInspector.DebuggerWorkspaceBinding.Location.prototype = {
358 /**
359 * @return {!WebInspector.UILocation}
360 */
361 uiLocation: function()
362 {
363 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (this.rawLocation());
364 return this._binding.rawLocationToUILocation(debuggerModelLocation);
365 },
366
367 dispose: function()
368 {
369 WebInspector.LiveLocation.prototype.dispose.call(this);
370 this._binding._removeLiveLocation(this);
371 },
372
373 __proto__: WebInspector.LiveLocation.prototype
374 }
375
376 /**
57 * @type {!WebInspector.DebuggerWorkspaceBinding} 377 * @type {!WebInspector.DebuggerWorkspaceBinding}
58 */ 378 */
59 WebInspector.debuggerWorkspaceBinding; 379 WebInspector.debuggerWorkspaceBinding;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698