| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @implements {WebInspector.TargetManager.Observer} | |
| 8 * @param {!WebInspector.TargetManager} targetManager | |
| 9 * @param {!WebInspector.Workspace} workspace | |
| 10 * @param {!WebInspector.NetworkWorkspaceBinding} networkWorkspaceBinding | |
| 11 */ | |
| 12 WebInspector.DebuggerWorkspaceBinding = function(targetManager, workspace, netwo
rkWorkspaceBinding) | |
| 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); | |
| 23 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved
, this._uiSourceCodeRemoved, this); | |
| 24 } | |
| 25 | |
| 26 WebInspector.DebuggerWorkspaceBinding.prototype = { | |
| 27 /** | |
| 28 * @param {!WebInspector.Target} target | |
| 29 */ | |
| 30 targetAdded: function(target) | |
| 31 { | |
| 32 this._targetToData.put(target, new WebInspector.DebuggerWorkspaceBinding
.TargetData(target, this)); | |
| 33 }, | |
| 34 | |
| 35 /** | |
| 36 * @param {!WebInspector.Target} target | |
| 37 */ | |
| 38 targetRemoved: function(target) | |
| 39 { | |
| 40 this._targetToData.remove(target)._dispose(); | |
| 41 }, | |
| 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 /** | |
| 55 * @param {!WebInspector.Script} script | |
| 56 * @param {!WebInspector.SourceMapping} sourceMapping | |
| 57 */ | |
| 58 pushSourceMapping: function(script, sourceMapping) | |
| 59 { | |
| 60 var info = this._ensureInfoForScript(script); | |
| 61 info._pushSourceMapping(sourceMapping); | |
| 62 }, | |
| 63 | |
| 64 /** | |
| 65 * @param {!WebInspector.Script} script | |
| 66 * @return {!WebInspector.SourceMapping} | |
| 67 */ | |
| 68 popSourceMapping: function(script) | |
| 69 { | |
| 70 var info = this._infoForScript(script.target(), script.scriptId); | |
| 71 console.assert(info); | |
| 72 return info._popSourceMapping(); | |
| 73 }, | |
| 74 | |
| 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 /** | |
| 88 * @param {!WebInspector.Script} script | |
| 89 */ | |
| 90 updateLocations: function(script) | |
| 91 { | |
| 92 var info = this._infoForScript(script.target(), script.scriptId); | |
| 93 if (info) | |
| 94 info._updateLocations(); | |
| 95 }, | |
| 96 | |
| 97 /** | |
| 98 * @param {!WebInspector.DebuggerModel.Location} rawLocation | |
| 99 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel
egate | |
| 100 * @return {!WebInspector.DebuggerWorkspaceBinding.Location} | |
| 101 */ | |
| 102 createLiveLocation: function(rawLocation, updateDelegate) | |
| 103 { | |
| 104 var info = this._infoForScript(rawLocation.target(), rawLocation.scriptI
d); | |
| 105 console.assert(info); | |
| 106 var location = new WebInspector.DebuggerWorkspaceBinding.Location(info._
script, rawLocation, this, updateDelegate); | |
| 107 info._addLocation(location); | |
| 108 return location; | |
| 109 }, | |
| 110 | |
| 111 /** | |
| 112 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame | |
| 113 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel
egate | |
| 114 * @return {!WebInspector.DebuggerWorkspaceBinding.Location} | |
| 115 */ | |
| 116 createCallFrameLiveLocation: function(callFrame, updateDelegate) | |
| 117 { | |
| 118 var target = callFrame.target(); | |
| 119 this._ensureInfoForScript(callFrame.script) | |
| 120 var location = this.createLiveLocation(callFrame.location(), updateDeleg
ate); | |
| 121 this._registerCallFrameLiveLocation(target, location); | |
| 122 return location; | |
| 123 }, | |
| 124 | |
| 125 /** | |
| 126 * @param {!WebInspector.DebuggerModel.Location} rawLocation | |
| 127 * @return {!WebInspector.UILocation} | |
| 128 */ | |
| 129 rawLocationToUILocation: function(rawLocation) | |
| 130 { | |
| 131 var info = this._infoForScript(rawLocation.target(), rawLocation.scriptI
d); | |
| 132 console.assert(info); | |
| 133 return info._rawLocationToUILocation(rawLocation); | |
| 134 }, | |
| 135 | |
| 136 /** | |
| 137 * @param {!WebInspector.Target} target | |
| 138 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 139 * @param {number} lineNumber | |
| 140 * @param {number} columnNumber | |
| 141 * @return {?WebInspector.DebuggerModel.Location} | |
| 142 */ | |
| 143 uiLocationToRawLocation: function(target, uiSourceCode, lineNumber, columnNu
mber) | |
| 144 { | |
| 145 var targetData = this._targetToData.get(target); | |
| 146 return targetData ? /** @type {?WebInspector.DebuggerModel.Location} */
(targetData._uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber)) :
null; | |
| 147 }, | |
| 148 | |
| 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 /** | |
| 183 * @param {!WebInspector.Target} target | |
| 184 * @return {?WebInspector.LiveEditSupport} | |
| 185 */ | |
| 186 liveEditSupport: function(target) | |
| 187 { | |
| 188 var targetData = this._targetToData.get(target); | |
| 189 return targetData ? targetData._liveEditSupport : null; | |
| 190 }, | |
| 191 | |
| 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 /** | |
| 204 * @param {!WebInspector.Event} event | |
| 205 */ | |
| 206 _globalObjectCleared: function(event) | |
| 207 { | |
| 208 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.ta
rget); | |
| 209 this._reset(debuggerModel.target()); | |
| 210 }, | |
| 211 | |
| 212 /** | |
| 213 * @param {!WebInspector.Target} target | |
| 214 */ | |
| 215 _reset: function(target) | |
| 216 { | |
| 217 var targetData = this._targetToData.get(target); | |
| 218 targetData.callFrameLocations.values().forEach(function(location) { loca
tion.dispose(); }); | |
| 219 targetData.callFrameLocations.clear(); | |
| 220 }, | |
| 221 | |
| 222 /** | |
| 223 * @param {!WebInspector.Script} script | |
| 224 * @return {!WebInspector.DebuggerWorkspaceBinding.ScriptInfo} | |
| 225 */ | |
| 226 _ensureInfoForScript: function(script) | |
| 227 { | |
| 228 var scriptDataMap = this._targetToData.get(script.target()).scriptDataMa
p; | |
| 229 var info = scriptDataMap.get(script.scriptId); | |
| 230 if (!info) { | |
| 231 info = new WebInspector.DebuggerWorkspaceBinding.ScriptInfo(script); | |
| 232 scriptDataMap.put(script.scriptId, info); | |
| 233 } | |
| 234 return info; | |
| 235 }, | |
| 236 | |
| 237 | |
| 238 /** | |
| 239 * @param {!WebInspector.Target} target | |
| 240 * @param {string} scriptId | |
| 241 * @return {?WebInspector.DebuggerWorkspaceBinding.ScriptInfo} | |
| 242 */ | |
| 243 _infoForScript: function(target, scriptId) | |
| 244 { | |
| 245 var data = this._targetToData.get(target); | |
| 246 if (!data) | |
| 247 return null; | |
| 248 return data.scriptDataMap.get(scriptId) || null; | |
| 249 }, | |
| 250 | |
| 251 /** | |
| 252 * @param {!WebInspector.Target} target | |
| 253 * @param {!WebInspector.DebuggerWorkspaceBinding.Location} location | |
| 254 */ | |
| 255 _registerCallFrameLiveLocation: function(target, location) | |
| 256 { | |
| 257 var locations = this._targetToData.get(target).callFrameLocations; | |
| 258 locations.add(location); | |
| 259 }, | |
| 260 | |
| 261 /** | |
| 262 * @param {!WebInspector.DebuggerWorkspaceBinding.Location} location | |
| 263 */ | |
| 264 _removeLiveLocation: function(location) | |
| 265 { | |
| 266 var info = this._infoForScript(location._script.target(), location._scri
pt.scriptId); | |
| 267 if (info) | |
| 268 info._removeLocation(location); | |
| 269 }, | |
| 270 | |
| 271 /** | |
| 272 * @param {!WebInspector.Event} event | |
| 273 */ | |
| 274 _debuggerResumed: function(event) | |
| 275 { | |
| 276 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.ta
rget); | |
| 277 this._reset(debuggerModel.target()); | |
| 278 } | |
| 279 } | |
| 280 | |
| 281 /** | |
| 282 * @constructor | |
| 283 * @param {!WebInspector.Target} target | |
| 284 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding | |
| 285 */ | |
| 286 WebInspector.DebuggerWorkspaceBinding.TargetData = function(target, debuggerWork
spaceBinding) | |
| 287 { | |
| 288 this._target = target; | |
| 289 | |
| 290 /** @type {!StringMap.<!WebInspector.DebuggerWorkspaceBinding.ScriptInfo>} *
/ | |
| 291 this.scriptDataMap = new StringMap(); | |
| 292 | |
| 293 /** @type {!Set.<!WebInspector.DebuggerWorkspaceBinding.Location>} */ | |
| 294 this.callFrameLocations = new Set(); | |
| 295 | |
| 296 var debuggerModel = target.debuggerModel; | |
| 297 var workspace = debuggerWorkspaceBinding._workspace; | |
| 298 | |
| 299 this._liveEditSupport = new WebInspector.LiveEditSupport(target, workspace,
debuggerWorkspaceBinding); | |
| 300 this._defaultMapping = new WebInspector.DefaultScriptMapping(debuggerModel,
workspace, debuggerWorkspaceBinding); | |
| 301 this._resourceMapping = new WebInspector.ResourceScriptMapping(debuggerModel
, workspace, debuggerWorkspaceBinding); | |
| 302 this._compilerMapping = new WebInspector.CompilerScriptMapping(debuggerModel
, workspace, debuggerWorkspaceBinding._networkWorkspaceBinding, debuggerWorkspac
eBinding); | |
| 303 | |
| 304 /** @type {!WebInspector.LiveEditSupport} */ | |
| 305 this._liveEditSupport = new WebInspector.LiveEditSupport(target, workspace,
debuggerWorkspaceBinding); | |
| 306 | |
| 307 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.SourceMapping>} *
/ | |
| 308 this._uiSourceCodeToSourceMapping = new Map(); | |
| 309 | |
| 310 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScrip
tSource, this._parsedScriptSource, this); | |
| 311 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToPar
seScriptSource, this._parsedScriptSource, this); | |
| 312 } | |
| 313 | |
| 314 WebInspector.DebuggerWorkspaceBinding.TargetData.prototype = { | |
| 315 /** | |
| 316 * @param {!WebInspector.Event} event | |
| 317 */ | |
| 318 _parsedScriptSource: function(event) | |
| 319 { | |
| 320 var script = /** @type {!WebInspector.Script} */ (event.data); | |
| 321 this._defaultMapping.addScript(script); | |
| 322 | |
| 323 if (script.isSnippet()) { | |
| 324 WebInspector.scriptSnippetModel.addScript(script); | |
| 325 return; | |
| 326 } | |
| 327 | |
| 328 this._resourceMapping.addScript(script); | |
| 329 | |
| 330 if (WebInspector.settings.jsSourceMapsEnabled.get()) | |
| 331 this._compilerMapping.addScript(script); | |
| 332 }, | |
| 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 | |
| 382 _dispose: function() | |
| 383 { | |
| 384 this._compilerMapping.dispose(); | |
| 385 this._resourceMapping.dispose(); | |
| 386 this._defaultMapping.dispose(); | |
| 387 this._uiSourceCodeToSourceMapping.clear(); | |
| 388 } | |
| 389 } | |
| 390 | |
| 391 /** | |
| 392 * @constructor | |
| 393 * @param {!WebInspector.Script} script | |
| 394 */ | |
| 395 WebInspector.DebuggerWorkspaceBinding.ScriptInfo = function(script) | |
| 396 { | |
| 397 this._script = script; | |
| 398 | |
| 399 /** @type {!Array.<!WebInspector.SourceMapping>} */ | |
| 400 this._sourceMappings = []; | |
| 401 | |
| 402 /** @type {!Set.<!WebInspector.LiveLocation>} */ | |
| 403 this._locations = new Set(); | |
| 404 } | |
| 405 | |
| 406 WebInspector.DebuggerWorkspaceBinding.ScriptInfo.prototype = { | |
| 407 /** | |
| 408 * @param {!WebInspector.SourceMapping} sourceMapping | |
| 409 */ | |
| 410 _pushSourceMapping: function(sourceMapping) | |
| 411 { | |
| 412 this._sourceMappings.push(sourceMapping); | |
| 413 this._updateLocations(); | |
| 414 }, | |
| 415 | |
| 416 /** | |
| 417 * @return {!WebInspector.SourceMapping} | |
| 418 */ | |
| 419 _popSourceMapping: function() | |
| 420 { | |
| 421 var sourceMapping = this._sourceMappings.pop(); | |
| 422 this._updateLocations(); | |
| 423 return sourceMapping; | |
| 424 }, | |
| 425 | |
| 426 /** | |
| 427 * @param {!WebInspector.LiveLocation} location | |
| 428 */ | |
| 429 _addLocation: function(location) | |
| 430 { | |
| 431 this._locations.add(location); | |
| 432 location.update(); | |
| 433 }, | |
| 434 | |
| 435 /** | |
| 436 * @param {!WebInspector.LiveLocation} location | |
| 437 */ | |
| 438 _removeLocation: function(location) | |
| 439 { | |
| 440 this._locations.remove(location); | |
| 441 }, | |
| 442 | |
| 443 _updateLocations: function() | |
| 444 { | |
| 445 var items = this._locations.values(); | |
| 446 for (var i = 0; i < items.length; ++i) | |
| 447 items[i].update(); | |
| 448 }, | |
| 449 | |
| 450 /** | |
| 451 * @param {!WebInspector.DebuggerModel.Location} rawLocation | |
| 452 * @return {!WebInspector.UILocation} | |
| 453 */ | |
| 454 _rawLocationToUILocation: function(rawLocation) | |
| 455 { | |
| 456 var uiLocation; | |
| 457 for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i
) | |
| 458 uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLoca
tion); | |
| 459 console.assert(uiLocation, "Script raw location cannot be mapped to any
UI location."); | |
| 460 return /** @type {!WebInspector.UILocation} */ (uiLocation); | |
| 461 } | |
| 462 } | |
| 463 | |
| 464 | |
| 465 /** | |
| 466 * @constructor | |
| 467 * @extends {WebInspector.LiveLocation} | |
| 468 * @param {!WebInspector.Script} script | |
| 469 * @param {!WebInspector.DebuggerModel.Location} rawLocation | |
| 470 * @param {!WebInspector.DebuggerWorkspaceBinding} binding | |
| 471 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDelegat
e | |
| 472 */ | |
| 473 WebInspector.DebuggerWorkspaceBinding.Location = function(script, rawLocation, b
inding, updateDelegate) | |
| 474 { | |
| 475 WebInspector.LiveLocation.call(this, rawLocation, updateDelegate); | |
| 476 this._script = script; | |
| 477 this._binding = binding; | |
| 478 } | |
| 479 | |
| 480 WebInspector.DebuggerWorkspaceBinding.Location.prototype = { | |
| 481 /** | |
| 482 * @return {!WebInspector.UILocation} | |
| 483 */ | |
| 484 uiLocation: function() | |
| 485 { | |
| 486 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat
ion} */ (this.rawLocation()); | |
| 487 return this._binding.rawLocationToUILocation(debuggerModelLocation); | |
| 488 }, | |
| 489 | |
| 490 dispose: function() | |
| 491 { | |
| 492 WebInspector.LiveLocation.prototype.dispose.call(this); | |
| 493 this._binding._removeLiveLocation(this); | |
| 494 }, | |
| 495 | |
| 496 __proto__: WebInspector.LiveLocation.prototype | |
| 497 } | |
| 498 | |
| 499 /** | |
| 500 * @type {!WebInspector.DebuggerWorkspaceBinding} | |
| 501 */ | |
| 502 WebInspector.debuggerWorkspaceBinding; | |
| OLD | NEW |