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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/snippets/ScriptSnippetModel.js

Issue 2931773002: DevTools: kill DebuggerWorkspaceBinding.{push,pop,set}SourceMapping (Closed)
Patch Set: address comments Created 3 years, 6 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
OLDNEW
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
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
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} 370 * @implements {Bindings.DebuggerSourceMapping}
dgozman 2017/06/08 22:25:16 Remove
lushnikov 2017/06/08 22:34:25 Done.
341 * @unrestricted 371 * @unrestricted
342 */ 372 */
343 Snippets.SnippetScriptMapping = class { 373 Snippets.SnippetScriptMapping = class {
344 /** 374 /**
345 * @param {!SDK.DebuggerModel} debuggerModel 375 * @param {!SDK.DebuggerModel} debuggerModel
346 * @param {!Snippets.ScriptSnippetModel} scriptSnippetModel 376 * @param {!Snippets.ScriptSnippetModel} scriptSnippetModel
347 */ 377 */
348 constructor(debuggerModel, scriptSnippetModel) { 378 constructor(debuggerModel, scriptSnippetModel) {
349 this._debuggerModel = debuggerModel; 379 this._debuggerModel = debuggerModel;
350 this._scriptSnippetModel = scriptSnippetModel; 380 this._scriptSnippetModel = scriptSnippetModel;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 460
431 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe r); 461 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe r);
432 } 462 }
433 463
434 /** 464 /**
435 * @param {!SDK.Script} script 465 * @param {!SDK.Script} script
436 * @param {!Workspace.UISourceCode} uiSourceCode 466 * @param {!Workspace.UISourceCode} uiSourceCode
437 */ 467 */
438 _addScript(script, uiSourceCode) { 468 _addScript(script, uiSourceCode) {
439 console.assert(!this._scriptForUISourceCode.get(uiSourceCode)); 469 console.assert(!this._scriptForUISourceCode.get(uiSourceCode));
440 Bindings.debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSo urceCode, this);
441 this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode; 470 this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode;
442 this._scriptForUISourceCode.set(uiSourceCode, script); 471 this._scriptForUISourceCode.set(uiSourceCode, script);
443 Bindings.debuggerWorkspaceBinding.pushSourceMapping(script, this); 472 Bindings.debuggerWorkspaceBinding.updateLocations(script);
444 } 473 }
445 474
446 /** 475 /**
447 * @param {!Workspace.UISourceCode} uiSourceCode 476 * @param {!Workspace.UISourceCode} uiSourceCode
448 * @param {!Array.<!{breakpoint: !Bindings.BreakpointManager.Breakpoint, uiLoc ation: !Workspace.UILocation}>} breakpointLocations 477 * @param {!Array.<!{breakpoint: !Bindings.BreakpointManager.Breakpoint, uiLoc ation: !Workspace.UILocation}>} breakpointLocations
449 */ 478 */
450 _restoreBreakpoints(uiSourceCode, breakpointLocations) { 479 _restoreBreakpoints(uiSourceCode, breakpointLocations) {
451 var script = this._scriptForUISourceCode.get(uiSourceCode); 480 var script = this._scriptForUISourceCode.get(uiSourceCode);
452 if (!script) 481 if (!script)
453 return; 482 return;
454 var rawLocation = 483 var rawLocation =
455 /** @type {!SDK.DebuggerModel.Location} */ (this._debuggerModel.createRa wLocation(script, 0, 0)); 484 /** @type {!SDK.DebuggerModel.Location} */ (this._debuggerModel.createRa wLocation(script, 0, 0));
456 var scriptUISourceCode = Bindings.debuggerWorkspaceBinding.rawLocationToUILo cation(rawLocation).uiSourceCode; 485 var scriptUISourceCode = Bindings.debuggerWorkspaceBinding.rawLocationToUILo cation(rawLocation).uiSourceCode;
457 if (scriptUISourceCode) 486 if (scriptUISourceCode)
458 this._scriptSnippetModel._restoreBreakpoints(scriptUISourceCode, breakpoin tLocations); 487 this._scriptSnippetModel._restoreBreakpoints(scriptUISourceCode, breakpoin tLocations);
459 } 488 }
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 }; 489 };
479 490
480 /** 491 /**
481 * @implements {Common.ContentProvider} 492 * @implements {Common.ContentProvider}
482 * @unrestricted 493 * @unrestricted
483 */ 494 */
484 Snippets.SnippetContentProvider = class { 495 Snippets.SnippetContentProvider = class {
485 /** 496 /**
486 * @param {!Snippets.Snippet} snippet 497 * @param {!Snippets.Snippet} snippet
487 */ 498 */
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 */ 620 */
610 deleteFile(uiSourceCode) { 621 deleteFile(uiSourceCode) {
611 this._model.deleteScriptSnippet(uiSourceCode); 622 this._model.deleteScriptSnippet(uiSourceCode);
612 } 623 }
613 }; 624 };
614 625
615 /** 626 /**
616 * @type {!Snippets.ScriptSnippetModel} 627 * @type {!Snippets.ScriptSnippetModel}
617 */ 628 */
618 Snippets.scriptSnippetModel = new Snippets.ScriptSnippetModel(Workspace.workspac e); 629 Snippets.scriptSnippetModel = new Snippets.ScriptSnippetModel(Workspace.workspac e);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698