| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 /** | 30 /** |
| 31 * @unrestricted | 31 * @unrestricted |
| 32 * @implements {SDK.SDKModelObserver<!SDK.DebuggerModel>} | 32 * @implements {SDK.SDKModelObserver<!SDK.DebuggerModel>} |
| 33 * @implements {Bindings.DebuggerSourceMapping} |
| 33 */ | 34 */ |
| 34 Snippets.ScriptSnippetModel = class extends Common.Object { | 35 Snippets.ScriptSnippetModel = class extends Common.Object { |
| 35 /** | 36 /** |
| 36 * @param {!Workspace.Workspace} workspace | 37 * @param {!Workspace.Workspace} workspace |
| 37 */ | 38 */ |
| 38 constructor(workspace) { | 39 constructor(workspace) { |
| 39 super(); | 40 super(); |
| 40 this._workspace = workspace; | 41 this._workspace = workspace; |
| 41 /** @type {!Object.<string, !Workspace.UISourceCode>} */ | 42 /** @type {!Object.<string, !Workspace.UISourceCode>} */ |
| 42 this._uiSourceCodeForSnippetId = {}; | 43 this._uiSourceCodeForSnippetId = {}; |
| 43 /** @type {!Map.<!Workspace.UISourceCode, string>} */ | 44 /** @type {!Map.<!Workspace.UISourceCode, string>} */ |
| 44 this._snippetIdForUISourceCode = new Map(); | 45 this._snippetIdForUISourceCode = new Map(); |
| 45 | 46 |
| 46 /** @type {!Map.<!SDK.DebuggerModel, !Snippets.SnippetScriptMapping>} */ | 47 /** @type {!Map.<!SDK.DebuggerModel, !Snippets.SnippetScriptMapping>} */ |
| 47 this._mappingForDebuggerModel = new Map(); | 48 this._mappingForDebuggerModel = new Map(); |
| 48 this._snippetStorage = new Snippets.SnippetStorage('script', 'Script snippet
#'); | 49 this._snippetStorage = new Snippets.SnippetStorage('script', 'Script snippet
#'); |
| 49 this._lastSnippetEvaluationIndexSetting = Common.settings.createSetting('las
tSnippetEvaluationIndex', 0); | 50 this._lastSnippetEvaluationIndexSetting = Common.settings.createSetting('las
tSnippetEvaluationIndex', 0); |
| 50 this._project = new Snippets.SnippetsProject(workspace, this); | 51 this._project = new Snippets.SnippetsProject(workspace, this); |
| 51 this._loadSnippets(); | 52 this._loadSnippets(); |
| 52 SDK.targetManager.observeModels(SDK.DebuggerModel, this); | 53 SDK.targetManager.observeModels(SDK.DebuggerModel, this); |
| 54 Bindings.debuggerWorkspaceBinding.addSourceMapping(this); |
| 53 } | 55 } |
| 54 | 56 |
| 55 /** | 57 /** |
| 56 * @override | 58 * @override |
| 57 * @param {!SDK.DebuggerModel} debuggerModel | 59 * @param {!SDK.DebuggerModel} debuggerModel |
| 58 */ | 60 */ |
| 59 modelAdded(debuggerModel) { | 61 modelAdded(debuggerModel) { |
| 60 this._mappingForDebuggerModel.set(debuggerModel, new Snippets.SnippetScriptM
apping(debuggerModel, this)); | 62 this._mappingForDebuggerModel.set(debuggerModel, new Snippets.SnippetScriptM
apping(debuggerModel, this)); |
| 61 } | 63 } |
| 62 | 64 |
| 63 /** | 65 /** |
| 64 * @override | 66 * @override |
| 65 * @param {!SDK.DebuggerModel} debuggerModel | 67 * @param {!SDK.DebuggerModel} debuggerModel |
| 66 */ | 68 */ |
| 67 modelRemoved(debuggerModel) { | 69 modelRemoved(debuggerModel) { |
| 68 this._mappingForDebuggerModel.remove(debuggerModel); | 70 this._mappingForDebuggerModel.remove(debuggerModel); |
| 69 } | 71 } |
| 70 | 72 |
| 71 /** | 73 /** |
| 74 * @override |
| 75 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 76 * @return {?Workspace.UILocation} |
| 77 */ |
| 78 rawLocationToUILocation(rawLocation) { |
| 79 var mapping = this._mappingForDebuggerModel.get(rawLocation.debuggerModel); |
| 80 if (!mapping) |
| 81 return null; |
| 82 return mapping.rawLocationToUILocation(rawLocation); |
| 83 } |
| 84 |
| 85 /** |
| 86 * @override |
| 87 * @param {!Workspace.UISourceCode} uiSourceCode |
| 88 * @param {number} lineNumber |
| 89 * @param {number} columnNumber |
| 90 * @return {?SDK.DebuggerModel.Location} |
| 91 */ |
| 92 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
| 93 for (var mapping of this._mappingForDebuggerModel.values()) { |
| 94 var rawLocation = mapping.uiLocationToRawLocation(uiSourceCode, lineNumber
, columnNumber); |
| 95 if (rawLocation) |
| 96 return rawLocation; |
| 97 } |
| 98 return null; |
| 99 } |
| 100 |
| 101 /** |
| 72 * @param {!SDK.DebuggerModel} debuggerModel | 102 * @param {!SDK.DebuggerModel} debuggerModel |
| 73 * @return {!Snippets.SnippetScriptMapping|undefined} | 103 * @return {!Snippets.SnippetScriptMapping|undefined} |
| 74 */ | 104 */ |
| 75 snippetScriptMapping(debuggerModel) { | 105 snippetScriptMapping(debuggerModel) { |
| 76 return this._mappingForDebuggerModel.get(debuggerModel); | 106 return this._mappingForDebuggerModel.get(debuggerModel); |
| 77 } | 107 } |
| 78 | 108 |
| 79 /** | 109 /** |
| 80 * @return {!Workspace.Project} | 110 * @return {!Workspace.Project} |
| 81 */ | 111 */ |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 return null; | 360 return null; |
| 331 var splitURL = sourceURL.substring(snippetPrefix.length).split('_'); | 361 var splitURL = sourceURL.substring(snippetPrefix.length).split('_'); |
| 332 var snippetId = splitURL[0]; | 362 var snippetId = splitURL[0]; |
| 333 return snippetId; | 363 return snippetId; |
| 334 } | 364 } |
| 335 }; | 365 }; |
| 336 | 366 |
| 337 Snippets.ScriptSnippetModel.snippetSourceURLPrefix = 'snippets:///'; | 367 Snippets.ScriptSnippetModel.snippetSourceURLPrefix = 'snippets:///'; |
| 338 | 368 |
| 339 /** | 369 /** |
| 340 * @implements {Bindings.DebuggerSourceMapping} | |
| 341 * @unrestricted | 370 * @unrestricted |
| 342 */ | 371 */ |
| 343 Snippets.SnippetScriptMapping = class { | 372 Snippets.SnippetScriptMapping = class { |
| 344 /** | 373 /** |
| 345 * @param {!SDK.DebuggerModel} debuggerModel | 374 * @param {!SDK.DebuggerModel} debuggerModel |
| 346 * @param {!Snippets.ScriptSnippetModel} scriptSnippetModel | 375 * @param {!Snippets.ScriptSnippetModel} scriptSnippetModel |
| 347 */ | 376 */ |
| 348 constructor(debuggerModel, scriptSnippetModel) { | 377 constructor(debuggerModel, scriptSnippetModel) { |
| 349 this._debuggerModel = debuggerModel; | 378 this._debuggerModel = debuggerModel; |
| 350 this._scriptSnippetModel = scriptSnippetModel; | 379 this._scriptSnippetModel = scriptSnippetModel; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 return Snippets.ScriptSnippetModel.snippetSourceURLPrefix + snippetId + eval
uationSuffix; | 425 return Snippets.ScriptSnippetModel.snippetSourceURLPrefix + snippetId + eval
uationSuffix; |
| 397 } | 426 } |
| 398 | 427 |
| 399 _reset() { | 428 _reset() { |
| 400 this._uiSourceCodeForScriptId = {}; | 429 this._uiSourceCodeForScriptId = {}; |
| 401 this._scriptForUISourceCode.clear(); | 430 this._scriptForUISourceCode.clear(); |
| 402 this._evaluationIndexForUISourceCode.clear(); | 431 this._evaluationIndexForUISourceCode.clear(); |
| 403 } | 432 } |
| 404 | 433 |
| 405 /** | 434 /** |
| 406 * @override | |
| 407 * @param {!SDK.DebuggerModel.Location} rawLocation | 435 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 408 * @return {?Workspace.UILocation} | 436 * @return {?Workspace.UILocation} |
| 409 */ | 437 */ |
| 410 rawLocationToUILocation(rawLocation) { | 438 rawLocationToUILocation(rawLocation) { |
| 411 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL
ocation); | 439 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL
ocation); |
| 412 var uiSourceCode = this._uiSourceCodeForScriptId[debuggerModelLocation.scrip
tId]; | 440 var uiSourceCode = this._uiSourceCodeForScriptId[debuggerModelLocation.scrip
tId]; |
| 413 if (!uiSourceCode) | 441 if (!uiSourceCode) |
| 414 return null; | 442 return null; |
| 415 | 443 |
| 416 return uiSourceCode.uiLocation(debuggerModelLocation.lineNumber, debuggerMod
elLocation.columnNumber || 0); | 444 return uiSourceCode.uiLocation(debuggerModelLocation.lineNumber, debuggerMod
elLocation.columnNumber || 0); |
| 417 } | 445 } |
| 418 | 446 |
| 419 /** | 447 /** |
| 420 * @override | |
| 421 * @param {!Workspace.UISourceCode} uiSourceCode | 448 * @param {!Workspace.UISourceCode} uiSourceCode |
| 422 * @param {number} lineNumber | 449 * @param {number} lineNumber |
| 423 * @param {number} columnNumber | 450 * @param {number} columnNumber |
| 424 * @return {?SDK.DebuggerModel.Location} | 451 * @return {?SDK.DebuggerModel.Location} |
| 425 */ | 452 */ |
| 426 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { | 453 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
| 427 var script = this._scriptForUISourceCode.get(uiSourceCode); | 454 var script = this._scriptForUISourceCode.get(uiSourceCode); |
| 428 if (!script) | 455 if (!script) |
| 429 return null; | 456 return null; |
| 430 | 457 |
| 431 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe
r); | 458 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe
r); |
| 432 } | 459 } |
| 433 | 460 |
| 434 /** | 461 /** |
| 435 * @param {!SDK.Script} script | 462 * @param {!SDK.Script} script |
| 436 * @param {!Workspace.UISourceCode} uiSourceCode | 463 * @param {!Workspace.UISourceCode} uiSourceCode |
| 437 */ | 464 */ |
| 438 _addScript(script, uiSourceCode) { | 465 _addScript(script, uiSourceCode) { |
| 439 console.assert(!this._scriptForUISourceCode.get(uiSourceCode)); | 466 console.assert(!this._scriptForUISourceCode.get(uiSourceCode)); |
| 440 Bindings.debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSo
urceCode, this); | |
| 441 this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode; | 467 this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode; |
| 442 this._scriptForUISourceCode.set(uiSourceCode, script); | 468 this._scriptForUISourceCode.set(uiSourceCode, script); |
| 443 Bindings.debuggerWorkspaceBinding.pushSourceMapping(script, this); | 469 Bindings.debuggerWorkspaceBinding.updateLocations(script); |
| 444 } | 470 } |
| 445 | 471 |
| 446 /** | 472 /** |
| 447 * @param {!Workspace.UISourceCode} uiSourceCode | 473 * @param {!Workspace.UISourceCode} uiSourceCode |
| 448 * @param {!Array.<!{breakpoint: !Bindings.BreakpointManager.Breakpoint, uiLoc
ation: !Workspace.UILocation}>} breakpointLocations | 474 * @param {!Array.<!{breakpoint: !Bindings.BreakpointManager.Breakpoint, uiLoc
ation: !Workspace.UILocation}>} breakpointLocations |
| 449 */ | 475 */ |
| 450 _restoreBreakpoints(uiSourceCode, breakpointLocations) { | 476 _restoreBreakpoints(uiSourceCode, breakpointLocations) { |
| 451 var script = this._scriptForUISourceCode.get(uiSourceCode); | 477 var script = this._scriptForUISourceCode.get(uiSourceCode); |
| 452 if (!script) | 478 if (!script) |
| 453 return; | 479 return; |
| 454 var rawLocation = | 480 var rawLocation = |
| 455 /** @type {!SDK.DebuggerModel.Location} */ (this._debuggerModel.createRa
wLocation(script, 0, 0)); | 481 /** @type {!SDK.DebuggerModel.Location} */ (this._debuggerModel.createRa
wLocation(script, 0, 0)); |
| 456 var scriptUISourceCode = Bindings.debuggerWorkspaceBinding.rawLocationToUILo
cation(rawLocation).uiSourceCode; | 482 var scriptUISourceCode = Bindings.debuggerWorkspaceBinding.rawLocationToUILo
cation(rawLocation).uiSourceCode; |
| 457 if (scriptUISourceCode) | 483 if (scriptUISourceCode) |
| 458 this._scriptSnippetModel._restoreBreakpoints(scriptUISourceCode, breakpoin
tLocations); | 484 this._scriptSnippetModel._restoreBreakpoints(scriptUISourceCode, breakpoin
tLocations); |
| 459 } | 485 } |
| 460 | |
| 461 /** | |
| 462 * @override | |
| 463 * @return {boolean} | |
| 464 */ | |
| 465 isIdentity() { | |
| 466 return false; | |
| 467 } | |
| 468 | |
| 469 /** | |
| 470 * @override | |
| 471 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 472 * @param {number} lineNumber | |
| 473 * @return {boolean} | |
| 474 */ | |
| 475 uiLineHasMapping(uiSourceCode, lineNumber) { | |
| 476 return true; | |
| 477 } | |
| 478 }; | 486 }; |
| 479 | 487 |
| 480 /** | 488 /** |
| 481 * @implements {Common.ContentProvider} | 489 * @implements {Common.ContentProvider} |
| 482 * @unrestricted | 490 * @unrestricted |
| 483 */ | 491 */ |
| 484 Snippets.SnippetContentProvider = class { | 492 Snippets.SnippetContentProvider = class { |
| 485 /** | 493 /** |
| 486 * @param {!Snippets.Snippet} snippet | 494 * @param {!Snippets.Snippet} snippet |
| 487 */ | 495 */ |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 */ | 617 */ |
| 610 deleteFile(uiSourceCode) { | 618 deleteFile(uiSourceCode) { |
| 611 this._model.deleteScriptSnippet(uiSourceCode); | 619 this._model.deleteScriptSnippet(uiSourceCode); |
| 612 } | 620 } |
| 613 }; | 621 }; |
| 614 | 622 |
| 615 /** | 623 /** |
| 616 * @type {!Snippets.ScriptSnippetModel} | 624 * @type {!Snippets.ScriptSnippetModel} |
| 617 */ | 625 */ |
| 618 Snippets.scriptSnippetModel = new Snippets.ScriptSnippetModel(Workspace.workspac
e); | 626 Snippets.scriptSnippetModel = new Snippets.ScriptSnippetModel(Workspace.workspac
e); |
| OLD | NEW |