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

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

Issue 464963002: DevTools: Make UISourceCode Target-agnostic (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments 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} 7 * @implements {WebInspector.TargetManager.Observer}
8 * @param {!WebInspector.TargetManager} targetManager 8 * @param {!WebInspector.TargetManager} targetManager
9 * @param {!WebInspector.Workspace} workspace 9 * @param {!WebInspector.Workspace} workspace
10 * @param {!WebInspector.NetworkWorkspaceBinding} networkWorkspaceBinding 10 * @param {!WebInspector.NetworkWorkspaceBinding} networkWorkspaceBinding
11 */ 11 */
12 WebInspector.DebuggerWorkspaceBinding = function(targetManager, workspace, netwo rkWorkspaceBinding) 12 WebInspector.DebuggerWorkspaceBinding = function(targetManager, workspace, netwo rkWorkspaceBinding)
13 { 13 {
14 this._workspace = workspace; 14 this._workspace = workspace;
15 this._networkWorkspaceBinding = networkWorkspaceBinding; 15 this._networkWorkspaceBinding = networkWorkspaceBinding;
16 16
17 /** @type {!Map.<!WebInspector.Target, !WebInspector.DebuggerWorkspaceBindin g.TargetData>} */ 17 /** @type {!Map.<!WebInspector.Target, !WebInspector.DebuggerWorkspaceBindin g.TargetData>} */
18 this._targetToData = new Map(); 18 this._targetToData = new Map();
19 targetManager.observeTargets(this); 19 targetManager.observeTargets(this);
20 20
21 targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.Debu ggerModel.Events.GlobalObjectCleared, this._globalObjectCleared, this); 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); 22 targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.Debu ggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
23 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved , this._uiSourceCodeRemoved, this);
23 } 24 }
24 25
25 WebInspector.DebuggerWorkspaceBinding.prototype = { 26 WebInspector.DebuggerWorkspaceBinding.prototype = {
26 /** 27 /**
27 * @param {!WebInspector.Target} target 28 * @param {!WebInspector.Target} target
28 */ 29 */
29 targetAdded: function(target) 30 targetAdded: function(target)
30 { 31 {
31 this._targetToData.put(target, new WebInspector.DebuggerWorkspaceBinding .TargetData(target, this)); 32 this._targetToData.put(target, new WebInspector.DebuggerWorkspaceBinding .TargetData(target, this));
32 }, 33 },
33 34
34 /** 35 /**
35 * @param {!WebInspector.Target} target 36 * @param {!WebInspector.Target} target
36 */ 37 */
37 targetRemoved: function(target) 38 targetRemoved: function(target)
38 { 39 {
39 this._targetToData.remove(target)._dispose(); 40 this._targetToData.remove(target)._dispose();
40 }, 41 },
41 42
42 /** 43 /**
44 * @param {!WebInspector.Event} event
45 */
46 _uiSourceCodeRemoved: function(event)
47 {
48 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
49 var targetDatas = this._targetToData.values();
50 for (var i = 0; i < targetDatas.length; ++i)
51 targetDatas[i]._uiSourceCodeRemoved(uiSourceCode);
52 },
53
54 /**
43 * @param {!WebInspector.Script} script 55 * @param {!WebInspector.Script} script
44 * @param {!WebInspector.SourceMapping} sourceMapping 56 * @param {!WebInspector.SourceMapping} sourceMapping
45 */ 57 */
46 pushSourceMapping: function(script, sourceMapping) 58 pushSourceMapping: function(script, sourceMapping)
47 { 59 {
48 var info = this._ensureInfoForScript(script); 60 var info = this._ensureInfoForScript(script);
49 info._pushSourceMapping(sourceMapping); 61 info._pushSourceMapping(sourceMapping);
50 }, 62 },
51 63
52 /** 64 /**
53 * @param {!WebInspector.Script} script 65 * @param {!WebInspector.Script} script
54 * @return {!WebInspector.SourceMapping} 66 * @return {!WebInspector.SourceMapping}
55 */ 67 */
56 popSourceMapping: function(script) 68 popSourceMapping: function(script)
57 { 69 {
58 var info = this._infoForScript(script.target(), script.scriptId); 70 var info = this._infoForScript(script.target(), script.scriptId);
59 console.assert(info); 71 console.assert(info);
60 return info._popSourceMapping(); 72 return info._popSourceMapping();
61 }, 73 },
62 74
63 /** 75 /**
76 * @param {!WebInspector.Target} target
77 * @param {!WebInspector.UISourceCode} uiSourceCode
78 * @param {?WebInspector.SourceMapping} sourceMapping
79 */
80 setSourceMapping: function(target, uiSourceCode, sourceMapping)
81 {
82 var data = this._targetToData.get(target);
83 if (data)
84 data._setSourceMapping(uiSourceCode, sourceMapping);
85 },
86
87 /**
64 * @param {!WebInspector.Script} script 88 * @param {!WebInspector.Script} script
65 */ 89 */
66 updateLocations: function(script) 90 updateLocations: function(script)
67 { 91 {
68 var info = this._infoForScript(script.target(), script.scriptId); 92 var info = this._infoForScript(script.target(), script.scriptId);
69 if (info) 93 if (info)
70 info._updateLocations(); 94 info._updateLocations();
71 }, 95 },
72 96
73 /** 97 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 var info = this._infoForScript(rawLocation.target(), rawLocation.scriptI d); 131 var info = this._infoForScript(rawLocation.target(), rawLocation.scriptI d);
108 console.assert(info); 132 console.assert(info);
109 return info._rawLocationToUILocation(rawLocation); 133 return info._rawLocationToUILocation(rawLocation);
110 }, 134 },
111 135
112 /** 136 /**
113 * @param {!WebInspector.Target} target 137 * @param {!WebInspector.Target} target
114 * @param {!WebInspector.UISourceCode} uiSourceCode 138 * @param {!WebInspector.UISourceCode} uiSourceCode
115 * @param {number} lineNumber 139 * @param {number} lineNumber
116 * @param {number} columnNumber 140 * @param {number} columnNumber
117 * @return {!WebInspector.DebuggerModel.Location} 141 * @return {?WebInspector.DebuggerModel.Location}
118 */ 142 */
119 uiLocationToRawLocation: function(target, uiSourceCode, lineNumber, columnNu mber) 143 uiLocationToRawLocation: function(target, uiSourceCode, lineNumber, columnNu mber)
120 { 144 {
121 return /** @type {!WebInspector.DebuggerModel.Location} */ (uiSourceCode .uiLocationToRawLocation(target, lineNumber, columnNumber)); 145 var targetData = this._targetToData.get(target);
146 return targetData ? /** @type {?WebInspector.DebuggerModel.Location} */ (targetData._uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber)) : null;
122 }, 147 },
123 148
124 /** 149 /**
150 * @param {!WebInspector.UISourceCode} uiSourceCode
151 * @param {number} lineNumber
152 * @param {number} columnNumber
153 * @return {!Array.<!WebInspector.RawLocation>}
154 */
155 uiLocationToRawLocations: function(uiSourceCode, lineNumber, columnNumber)
156 {
157 var result = [];
158 var targetDatas = this._targetToData.values();
159 for (var i = 0; i < targetDatas.length; ++i) {
160 var rawLocation = targetDatas[i]._uiLocationToRawLocation(uiSourceCo de, lineNumber, columnNumber);
161 if (rawLocation)
162 result.push(rawLocation);
163 }
164 return result;
165 },
166
167 /**
168 * @param {!WebInspector.UISourceCode} uiSourceCode
169 * @param {number} lineNumber
170 * @return {boolean}
171 */
172 uiLineHasMapping: function(uiSourceCode, lineNumber)
173 {
174 var targetDatas = this._targetToData.values();
175 for (var i = 0; i < targetDatas.length; ++i) {
176 if (!targetDatas[i]._uiLineHasMapping(uiSourceCode, lineNumber))
177 return false;
178 }
179 return true;
180 },
181
182 /**
125 * @param {!WebInspector.Target} target 183 * @param {!WebInspector.Target} target
126 * @return {?WebInspector.LiveEditSupport} 184 * @return {?WebInspector.LiveEditSupport}
127 */ 185 */
128 liveEditSupport: function(target) 186 liveEditSupport: function(target)
129 { 187 {
130 var targetData = this._targetToData.get(target); 188 var targetData = this._targetToData.get(target);
131 return targetData ? targetData._liveEditSupport : null; 189 return targetData ? targetData._liveEditSupport : null;
132 }, 190 },
133 191
134 /** 192 /**
193 * @param {!WebInspector.UISourceCode} uiSourceCode
194 * @param {!WebInspector.Target} target
195 * @return {?WebInspector.ResourceScriptFile}
196 */
197 scriptFile: function(uiSourceCode, target)
198 {
199 var targetData = this._targetToData.get(target);
200 return targetData ? targetData._resourceMapping.scriptFile(uiSourceCode) : null;
201 },
202
203 /**
135 * @param {!WebInspector.Event} event 204 * @param {!WebInspector.Event} event
136 */ 205 */
137 _globalObjectCleared: function(event) 206 _globalObjectCleared: function(event)
138 { 207 {
139 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.ta rget); 208 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.ta rget);
140 this._reset(debuggerModel.target()); 209 this._reset(debuggerModel.target());
141 }, 210 },
142 211
143 /** 212 /**
144 * @param {!WebInspector.Target} target 213 * @param {!WebInspector.Target} target
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 278 }
210 } 279 }
211 280
212 /** 281 /**
213 * @constructor 282 * @constructor
214 * @param {!WebInspector.Target} target 283 * @param {!WebInspector.Target} target
215 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding 284 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
216 */ 285 */
217 WebInspector.DebuggerWorkspaceBinding.TargetData = function(target, debuggerWork spaceBinding) 286 WebInspector.DebuggerWorkspaceBinding.TargetData = function(target, debuggerWork spaceBinding)
218 { 287 {
288 this._target = target;
289
219 /** @type {!StringMap.<!WebInspector.DebuggerWorkspaceBinding.ScriptInfo>} * / 290 /** @type {!StringMap.<!WebInspector.DebuggerWorkspaceBinding.ScriptInfo>} * /
220 this.scriptDataMap = new StringMap(); 291 this.scriptDataMap = new StringMap();
221 292
222 /** @type {!Set.<!WebInspector.DebuggerWorkspaceBinding.Location>} */ 293 /** @type {!Set.<!WebInspector.DebuggerWorkspaceBinding.Location>} */
223 this.callFrameLocations = new Set(); 294 this.callFrameLocations = new Set();
224 295
225 var debuggerModel = target.debuggerModel; 296 var debuggerModel = target.debuggerModel;
226 var workspace = debuggerWorkspaceBinding._workspace; 297 var workspace = debuggerWorkspaceBinding._workspace;
227 298
228 this._liveEditSupport = new WebInspector.LiveEditSupport(target, workspace, debuggerWorkspaceBinding); 299 this._liveEditSupport = new WebInspector.LiveEditSupport(target, workspace, debuggerWorkspaceBinding);
229 this._defaultMapping = new WebInspector.DefaultScriptMapping(debuggerModel, workspace, debuggerWorkspaceBinding); 300 this._defaultMapping = new WebInspector.DefaultScriptMapping(debuggerModel, workspace, debuggerWorkspaceBinding);
230 this._resourceMapping = new WebInspector.ResourceScriptMapping(debuggerModel , workspace, debuggerWorkspaceBinding); 301 this._resourceMapping = new WebInspector.ResourceScriptMapping(debuggerModel , workspace, debuggerWorkspaceBinding);
231 this._compilerMapping = new WebInspector.CompilerScriptMapping(debuggerModel , workspace, debuggerWorkspaceBinding._networkWorkspaceBinding, debuggerWorkspac eBinding); 302 this._compilerMapping = new WebInspector.CompilerScriptMapping(debuggerModel , workspace, debuggerWorkspaceBinding._networkWorkspaceBinding, debuggerWorkspac eBinding);
232 303
233 /** @type {!WebInspector.LiveEditSupport} */ 304 /** @type {!WebInspector.LiveEditSupport} */
234 this._liveEditSupport = new WebInspector.LiveEditSupport(target, workspace, debuggerWorkspaceBinding); 305 this._liveEditSupport = new WebInspector.LiveEditSupport(target, workspace, debuggerWorkspaceBinding);
235 306
307 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.SourceMapping>} * /
308 this._uiSourceCodeToSourceMapping = new Map();
309
236 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScrip tSource, this._parsedScriptSource, this); 310 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScrip tSource, this._parsedScriptSource, this);
237 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToPar seScriptSource, this._parsedScriptSource, this); 311 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToPar seScriptSource, this._parsedScriptSource, this);
238 } 312 }
239 313
240 WebInspector.DebuggerWorkspaceBinding.TargetData.prototype = { 314 WebInspector.DebuggerWorkspaceBinding.TargetData.prototype = {
241 /** 315 /**
242 * @param {!WebInspector.Event} event 316 * @param {!WebInspector.Event} event
243 */ 317 */
244 _parsedScriptSource: function(event) 318 _parsedScriptSource: function(event)
245 { 319 {
246 var script = /** @type {!WebInspector.Script} */ (event.data); 320 var script = /** @type {!WebInspector.Script} */ (event.data);
247 this._defaultMapping.addScript(script); 321 this._defaultMapping.addScript(script);
248 322
249 if (script.isSnippet()) { 323 if (script.isSnippet()) {
250 WebInspector.scriptSnippetModel.addScript(script); 324 WebInspector.scriptSnippetModel.addScript(script);
251 return; 325 return;
252 } 326 }
253 327
254 this._resourceMapping.addScript(script); 328 this._resourceMapping.addScript(script);
255 329
256 if (WebInspector.settings.jsSourceMapsEnabled.get()) 330 if (WebInspector.settings.jsSourceMapsEnabled.get())
257 this._compilerMapping.addScript(script); 331 this._compilerMapping.addScript(script);
258 }, 332 },
259 333
334 /**
335 * @param {!WebInspector.UISourceCode} uiSourceCode
336 * @param {?WebInspector.SourceMapping} sourceMapping
337 */
338 _setSourceMapping: function(uiSourceCode, sourceMapping)
339 {
340 if (this._uiSourceCodeToSourceMapping.get(uiSourceCode) === sourceMappin g)
341 return;
342
343 if (sourceMapping)
344 this._uiSourceCodeToSourceMapping.put(uiSourceCode, sourceMapping);
345 else
346 this._uiSourceCodeToSourceMapping.remove(uiSourceCode);
347
348 uiSourceCode.dispatchEventToListeners(WebInspector.UISourceCode.Events.S ourceMappingChanged, {target: this._target, isIdentity: sourceMapping ? sourceMa pping.isIdentity() : false});
349 },
350
351 /**
352 * @param {!WebInspector.UISourceCode} uiSourceCode
353 * @param {number} lineNumber
354 * @param {number} columnNumber
355 * @return {?WebInspector.RawLocation}
356 */
357 _uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
358 {
359 var sourceMapping = this._uiSourceCodeToSourceMapping.get(uiSourceCode);
360 return sourceMapping ? sourceMapping.uiLocationToRawLocation(uiSourceCod e, lineNumber, columnNumber) : null;
361 },
362
363 /**
364 * @param {!WebInspector.UISourceCode} uiSourceCode
365 * @param {number} lineNumber
366 * @return {boolean}
367 */
368 _uiLineHasMapping: function(uiSourceCode, lineNumber)
369 {
370 var sourceMapping = this._uiSourceCodeToSourceMapping.get(uiSourceCode);
371 return sourceMapping ? sourceMapping.uiLineHasMapping(uiSourceCode, line Number) : true;
372 },
373
374 /**
375 * @param {!WebInspector.UISourceCode} uiSourceCode
376 */
377 _uiSourceCodeRemoved: function(uiSourceCode)
378 {
379 this._uiSourceCodeToSourceMapping.remove(uiSourceCode);
380 },
381
260 _dispose: function() 382 _dispose: function()
261 { 383 {
262 this._compilerMapping.dispose(); 384 this._compilerMapping.dispose();
263 this._resourceMapping.dispose(); 385 this._resourceMapping.dispose();
264 this._defaultMapping.dispose(); 386 this._defaultMapping.dispose();
387 this._uiSourceCodeToSourceMapping.clear();
265 } 388 }
266 } 389 }
267 390
268 /** 391 /**
269 * @constructor 392 * @constructor
270 * @param {!WebInspector.Script} script 393 * @param {!WebInspector.Script} script
271 */ 394 */
272 WebInspector.DebuggerWorkspaceBinding.ScriptInfo = function(script) 395 WebInspector.DebuggerWorkspaceBinding.ScriptInfo = function(script)
273 { 396 {
274 this._script = script; 397 this._script = script;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 this._binding._removeLiveLocation(this); 493 this._binding._removeLiveLocation(this);
371 }, 494 },
372 495
373 __proto__: WebInspector.LiveLocation.prototype 496 __proto__: WebInspector.LiveLocation.prototype
374 } 497 }
375 498
376 /** 499 /**
377 * @type {!WebInspector.DebuggerWorkspaceBinding} 500 * @type {!WebInspector.DebuggerWorkspaceBinding}
378 */ 501 */
379 WebInspector.debuggerWorkspaceBinding; 502 WebInspector.debuggerWorkspaceBinding;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/CompilerScriptMapping.js ('k') | Source/devtools/front_end/sdk/DefaultScriptMapping.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698