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

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

Issue 310463003: DevTools: introduce TargetBreakpoints as a presentation of breakpoint and its state within target (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 13 matching lines...) Expand all
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 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.Object} 33 * @extends {WebInspector.Object}
34 * @implements {WebInspector.TargetManager.Observer}
35 * @param {!WebInspector.Setting} breakpointStorage 34 * @param {!WebInspector.Setting} breakpointStorage
36 * @param {!WebInspector.Workspace} workspace 35 * @param {!WebInspector.Workspace} workspace
37 * @param {!WebInspector.TargetManager} targetManager 36 * @param {!WebInspector.TargetManager} targetManager
38 */ 37 */
39 WebInspector.BreakpointManager = function(breakpointStorage, workspace, targetMa nager) 38 WebInspector.BreakpointManager = function(breakpointStorage, workspace, targetMa nager)
40 { 39 {
41 this._storage = new WebInspector.BreakpointManager.Storage(this, breakpointS torage); 40 this._storage = new WebInspector.BreakpointManager.Storage(this, breakpointS torage);
42 this._workspace = workspace; 41 this._workspace = workspace;
43 this._targetManager = targetManager; 42 this._targetManager = targetManager;
44 43
45 this._breakpointForDebuggerId = {};
46 this._breakpointsForUISourceCode = new Map(); 44 this._breakpointsForUISourceCode = new Map();
47 this._breakpointsForPrimaryUISourceCode = new Map(); 45 this._breakpointsForPrimaryUISourceCode = new Map();
48 /** @type {!StringMultimap.<!WebInspector.BreakpointManager.Breakpoint>} */ 46 /** @type {!StringMultimap.<!WebInspector.BreakpointManager.Breakpoint>} */
49 this._provisionalBreakpoints = new StringMultimap(); 47 this._provisionalBreakpoints = new StringMultimap();
50 48
51 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemove d, this._projectRemoved, this); 49 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemove d, this._projectRemoved, this);
52 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this); 50 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this);
53 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this); 51 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this);
54 this._targetManager.observeTargets(this);
55 } 52 }
56 53
57 WebInspector.BreakpointManager.Events = { 54 WebInspector.BreakpointManager.Events = {
58 BreakpointAdded: "breakpoint-added", 55 BreakpointAdded: "breakpoint-added",
59 BreakpointRemoved: "breakpoint-removed" 56 BreakpointRemoved: "breakpoint-removed"
60 } 57 }
61 58
62 WebInspector.BreakpointManager._sourceFileId = function(uiSourceCode) 59 WebInspector.BreakpointManager._sourceFileId = function(uiSourceCode)
63 { 60 {
64 if (!uiSourceCode.url) 61 if (!uiSourceCode.url)
65 return ""; 62 return "";
66 return uiSourceCode.uri(); 63 return uiSourceCode.uri();
67 } 64 }
68 65
69 /** 66 /**
70 * @param {string} sourceFileId 67 * @param {string} sourceFileId
71 * @param {number} lineNumber 68 * @param {number} lineNumber
72 * @param {number} columnNumber 69 * @param {number} columnNumber
73 * @return {string} 70 * @return {string}
74 */ 71 */
75 WebInspector.BreakpointManager._breakpointStorageId = function(sourceFileId, lin eNumber, columnNumber) 72 WebInspector.BreakpointManager._breakpointStorageId = function(sourceFileId, lin eNumber, columnNumber)
76 { 73 {
77 if (!sourceFileId) 74 if (!sourceFileId)
78 return ""; 75 return "";
79 return sourceFileId + ":" + lineNumber + ":" + columnNumber; 76 return sourceFileId + ":" + lineNumber + ":" + columnNumber;
80 } 77 }
81 78
82 WebInspector.BreakpointManager.prototype = { 79 WebInspector.BreakpointManager.prototype = {
83 /**
84 * @param {!WebInspector.Target} target
85 */
86 targetAdded: function(target)
87 {
88 target.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events. BreakpointResolved, this._breakpointResolved, this);
89 },
90
91 /**
92 * @param {!WebInspector.Target} target
93 */
94 targetRemoved: function(target)
95 {
96 target.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Even ts.BreakpointResolved, this._breakpointResolved, this);
97 },
98 80
99 /** 81 /**
100 * @param {string} sourceFileId 82 * @param {string} sourceFileId
101 * @return {!StringMap.<!WebInspector.BreakpointManager.Breakpoint>} 83 * @return {!StringMap.<!WebInspector.BreakpointManager.Breakpoint>}
102 */ 84 */
103 _provisionalBreakpointsForSourceFileId: function(sourceFileId) 85 _provisionalBreakpointsForSourceFileId: function(sourceFileId)
104 { 86 {
105 var result = new StringMap(); 87 var result = new StringMap();
106 var breakpoints = this._provisionalBreakpoints.get(sourceFileId).values( ); 88 var breakpoints = this._provisionalBreakpoints.get(sourceFileId).values( );
107 for (var i = 0; i < breakpoints.length; ++i) 89 for (var i = 0; i < breakpoints.length; ++i)
108 result.put(breakpoints[i]._breakpointStorageId(), breakpoints[i]); 90 result.put(breakpoints[i]._breakpointStorageId(), breakpoints[i]);
109 return result; 91 return result;
110 }, 92 },
111 93
112 /** 94 /**
113 * @param {!WebInspector.Target} target 95 * @param {!WebInspector.Target} target
114 */ 96 */
115 removeProvisionalBreakpointsForTest: function(target) 97 removeProvisionalBreakpointsForTest: function(target)
vsevik 2014/06/04 16:28:53 This one is only used for final clean up, so you c
sergeyv 2014/06/05 12:59:51 Done.
116 { 98 {
117 var breakpoints = this._provisionalBreakpoints.values(); 99 var breakpoints = this._provisionalBreakpoints.values();
118 for (var i = 0; i < breakpoints.length; ++i) { 100 for (var i = 0; i < breakpoints.length; ++i)
119 var debuggerId = breakpoints[i]._debuggerId; 101 breakpoints[i].removeProvisionalBreakpointsForTest(target);
vsevik 2014/06/04 16:28:53 removeProvisionalForTest
sergeyv 2014/06/05 12:59:51 Done.
120 if (debuggerId)
121 target.debuggerModel.removeBreakpoint(debuggerId);
122 }
123 this._provisionalBreakpoints.clear(); 102 this._provisionalBreakpoints.clear();
124 }, 103 },
125 104
126 /** 105 /**
127 * @param {!WebInspector.UISourceCode} uiSourceCode 106 * @param {!WebInspector.UISourceCode} uiSourceCode
128 */ 107 */
129 _restoreBreakpoints: function(uiSourceCode) 108 _restoreBreakpoints: function(uiSourceCode)
130 { 109 {
131 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code); 110 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code);
132 if (!sourceFileId) 111 if (!sourceFileId)
133 return; 112 return;
134 113
135 this._storage.mute(); 114 this._storage.mute();
136 var breakpointItems = this._storage.breakpointItems(uiSourceCode); 115 var breakpointItems = this._storage.breakpointItems(uiSourceCode);
137 var provisionalBreakpoints = this._provisionalBreakpointsForSourceFileId (sourceFileId); 116 var provisionalBreakpoints = this._provisionalBreakpointsForSourceFileId (sourceFileId);
138 for (var i = 0; i < breakpointItems.length; ++i) { 117 for (var i = 0; i < breakpointItems.length; ++i) {
139 var breakpointItem = breakpointItems[i]; 118 var breakpointItem = breakpointItems[i];
140 var itemStorageId = WebInspector.BreakpointManager._breakpointStorag eId(breakpointItem.sourceFileId, breakpointItem.lineNumber, breakpointItem.colum nNumber); 119 var itemStorageId = WebInspector.BreakpointManager._breakpointStorag eId(breakpointItem.sourceFileId, breakpointItem.lineNumber, breakpointItem.colum nNumber);
141 var provisionalBreakpoint = provisionalBreakpoints.get(itemStorageId ); 120 var provisionalBreakpoint = provisionalBreakpoints.get(itemStorageId );
142 if (provisionalBreakpoint) { 121 if (provisionalBreakpoint) {
143 if (!this._breakpointsForPrimaryUISourceCode.get(uiSourceCode)) 122 if (!this._breakpointsForPrimaryUISourceCode.get(uiSourceCode))
144 this._breakpointsForPrimaryUISourceCode.put(uiSourceCode, [] ); 123 this._breakpointsForPrimaryUISourceCode.put(uiSourceCode, [] );
145 this._breakpointsForPrimaryUISourceCode.get(uiSourceCode).push(p rovisionalBreakpoint); 124 this._breakpointsForPrimaryUISourceCode.get(uiSourceCode).push(p rovisionalBreakpoint);
146 provisionalBreakpoint._updateInDebugger(); 125 provisionalBreakpoint._updateBreakpoint();
147 } else { 126 } else {
148 this._innerSetBreakpoint(uiSourceCode, breakpointItem.lineNumber , breakpointItem.columnNumber, breakpointItem.condition, breakpointItem.enabled) ; 127 this._innerSetBreakpoint(uiSourceCode, breakpointItem.lineNumber , breakpointItem.columnNumber, breakpointItem.condition, breakpointItem.enabled) ;
149 } 128 }
150 } 129 }
151 this._provisionalBreakpoints.removeAll(sourceFileId); 130 this._provisionalBreakpoints.removeAll(sourceFileId);
152 this._storage.unmute(); 131 this._storage.unmute();
153 }, 132 },
154 133
155 /** 134 /**
156 * @param {!WebInspector.Event} event 135 * @param {!WebInspector.Event} event
(...skipping 30 matching lines...) Expand all
187 }, 166 },
188 167
189 /** 168 /**
190 * @param {!WebInspector.UISourceCode} uiSourceCode 169 * @param {!WebInspector.UISourceCode} uiSourceCode
191 */ 170 */
192 _removeUISourceCode: function(uiSourceCode) 171 _removeUISourceCode: function(uiSourceCode)
193 { 172 {
194 var breakpoints = this._breakpointsForPrimaryUISourceCode.get(uiSourceCo de) || []; 173 var breakpoints = this._breakpointsForPrimaryUISourceCode.get(uiSourceCo de) || [];
195 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code); 174 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code);
196 for (var i = 0; i < breakpoints.length; ++i) { 175 for (var i = 0; i < breakpoints.length; ++i) {
197 breakpoints[i]._resetLocations();
198 if (breakpoints[i].enabled()) 176 if (breakpoints[i].enabled())
199 this._provisionalBreakpoints.put(sourceFileId, breakpoints[i]); 177 this._provisionalBreakpoints.put(sourceFileId, breakpoints[i]);
178 breakpoints[i]._resetLocations();
vsevik 2014/06/04 16:28:53 Is this change important?
sergeyv 2014/06/05 12:59:51 Done.
200 } 179 }
201 uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.Source MappingChanged, this._uiSourceCodeMappingChanged, this); 180 uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.Source MappingChanged, this._uiSourceCodeMappingChanged, this);
202 this._breakpointsForPrimaryUISourceCode.remove(uiSourceCode); 181 this._breakpointsForPrimaryUISourceCode.remove(uiSourceCode);
203 }, 182 },
204 183
205 /** 184 /**
206 * @param {!WebInspector.UISourceCode} uiSourceCode 185 * @param {!WebInspector.UISourceCode} uiSourceCode
207 * @param {number} lineNumber 186 * @param {number} lineNumber
208 * @param {number} columnNumber 187 * @param {number} columnNumber
209 * @param {string} condition 188 * @param {string} condition
(...skipping 13 matching lines...) Expand all
223 * @param {number} lineNumber 202 * @param {number} lineNumber
224 * @param {number} columnNumber 203 * @param {number} columnNumber
225 * @param {string} condition 204 * @param {string} condition
226 * @param {boolean} enabled 205 * @param {boolean} enabled
227 * @return {!WebInspector.BreakpointManager.Breakpoint} 206 * @return {!WebInspector.BreakpointManager.Breakpoint}
228 */ 207 */
229 _innerSetBreakpoint: function(uiSourceCode, lineNumber, columnNumber, condit ion, enabled) 208 _innerSetBreakpoint: function(uiSourceCode, lineNumber, columnNumber, condit ion, enabled)
230 { 209 {
231 var breakpoint = this.findBreakpoint(uiSourceCode, lineNumber, columnNum ber); 210 var breakpoint = this.findBreakpoint(uiSourceCode, lineNumber, columnNum ber);
232 if (breakpoint) { 211 if (breakpoint) {
233 breakpoint._updateBreakpoint(condition, enabled); 212 breakpoint._setNewState(condition, enabled);
234 return breakpoint; 213 return breakpoint;
235 } 214 }
236 var projectId = uiSourceCode.project().id(); 215 var projectId = uiSourceCode.project().id();
237 var path = uiSourceCode.path(); 216 var path = uiSourceCode.path();
238 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code); 217 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code);
239 breakpoint = new WebInspector.BreakpointManager.Breakpoint(this, project Id, path, sourceFileId, lineNumber, columnNumber, condition, enabled); 218 breakpoint = new WebInspector.BreakpointManager.Breakpoint(this, project Id, path, sourceFileId, lineNumber, columnNumber, condition, enabled);
240 if (!this._breakpointsForPrimaryUISourceCode.get(uiSourceCode)) 219 if (!this._breakpointsForPrimaryUISourceCode.get(uiSourceCode))
241 this._breakpointsForPrimaryUISourceCode.put(uiSourceCode, []); 220 this._breakpointsForPrimaryUISourceCode.put(uiSourceCode, []);
242 this._breakpointsForPrimaryUISourceCode.get(uiSourceCode).push(breakpoin t); 221 this._breakpointsForPrimaryUISourceCode.get(uiSourceCode).push(breakpoin t);
243 return breakpoint; 222 return breakpoint;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 }, 333 },
355 334
356 _projectRemoved: function(event) 335 _projectRemoved: function(event)
357 { 336 {
358 var project = /** @type {!WebInspector.Project} */ (event.data); 337 var project = /** @type {!WebInspector.Project} */ (event.data);
359 var uiSourceCodes = project.uiSourceCodes(); 338 var uiSourceCodes = project.uiSourceCodes();
360 for (var i = 0; i < uiSourceCodes.length; ++i) 339 for (var i = 0; i < uiSourceCodes.length; ++i)
361 this._removeUISourceCode(uiSourceCodes[i]); 340 this._removeUISourceCode(uiSourceCodes[i]);
362 }, 341 },
363 342
364 _breakpointResolved: function(event)
365 {
366 var breakpointId = /** @type {!DebuggerAgent.BreakpointId} */ (event.dat a.breakpointId);
367 var location = /** @type {!WebInspector.DebuggerModel.Location} */ (even t.data.location);
368 var breakpoint = this._breakpointForDebuggerId[breakpointId];
369 if (!breakpoint)
370 return;
371 breakpoint._addResolvedLocation(location);
372 },
373
374 /** 343 /**
375 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint 344 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint
376 * @param {boolean} removeFromStorage 345 * @param {boolean} removeFromStorage
377 */ 346 */
378 _removeBreakpoint: function(breakpoint, removeFromStorage) 347 _removeBreakpoint: function(breakpoint, removeFromStorage)
379 { 348 {
380 var uiSourceCode = breakpoint.uiSourceCode(); 349 var uiSourceCode = breakpoint.uiSourceCode();
381 var breakpoints = uiSourceCode ? this._breakpointsForPrimaryUISourceCode .get(uiSourceCode) || [] : []; 350 var breakpoints = uiSourceCode ? this._breakpointsForPrimaryUISourceCode .get(uiSourceCode) || [] : [];
382 var index = breakpoints.indexOf(breakpoint); 351 breakpoints.remove(breakpoint);
383 if (index > -1)
384 breakpoints.splice(index, 1);
385 if (removeFromStorage) 352 if (removeFromStorage)
386 this._storage._removeBreakpoint(breakpoint); 353 this._storage._removeBreakpoint(breakpoint);
387 this._provisionalBreakpoints.remove(breakpoint._sourceFileId, breakpoint ); 354 this._provisionalBreakpoints.remove(breakpoint._sourceFileId, breakpoint );
388 }, 355 },
389 356
390 /** 357 /**
391 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint 358 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint
392 * @param {!WebInspector.UILocation} uiLocation 359 * @param {!WebInspector.UILocation} uiLocation
393 */ 360 */
394 _uiLocationAdded: function(breakpoint, uiLocation) 361 _uiLocationAdded: function(breakpoint, uiLocation)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (!breakpoints.size()) 403 if (!breakpoints.size())
437 this._breakpointsForUISourceCode.remove(uiLocation.uiSourceCode); 404 this._breakpointsForUISourceCode.remove(uiLocation.uiSourceCode);
438 this.dispatchEventToListeners(WebInspector.BreakpointManager.Events.Brea kpointRemoved, {breakpoint: breakpoint, uiLocation: uiLocation}); 405 this.dispatchEventToListeners(WebInspector.BreakpointManager.Events.Brea kpointRemoved, {breakpoint: breakpoint, uiLocation: uiLocation});
439 }, 406 },
440 407
441 __proto__: WebInspector.Object.prototype 408 __proto__: WebInspector.Object.prototype
442 } 409 }
443 410
444 /** 411 /**
445 * @constructor 412 * @constructor
413 * @implements {WebInspector.TargetManager.Observer}
446 * @param {!WebInspector.BreakpointManager} breakpointManager 414 * @param {!WebInspector.BreakpointManager} breakpointManager
447 * @param {string} projectId 415 * @param {string} projectId
448 * @param {string} path 416 * @param {string} path
449 * @param {string} sourceFileId 417 * @param {string} sourceFileId
450 * @param {number} lineNumber 418 * @param {number} lineNumber
451 * @param {number} columnNumber 419 * @param {number} columnNumber
452 * @param {string} condition 420 * @param {string} condition
453 * @param {boolean} enabled 421 * @param {boolean} enabled
454 */ 422 */
455 WebInspector.BreakpointManager.Breakpoint = function(breakpointManager, projectI d, path, sourceFileId, lineNumber, columnNumber, condition, enabled) 423 WebInspector.BreakpointManager.Breakpoint = function(breakpointManager, projectI d, path, sourceFileId, lineNumber, columnNumber, condition, enabled)
456 { 424 {
457 this._breakpointManager = breakpointManager; 425 this._breakpointManager = breakpointManager;
458 this._projectId = projectId; 426 this._projectId = projectId;
459 this._path = path; 427 this._path = path;
460 this._lineNumber = lineNumber; 428 this._lineNumber = lineNumber;
461 this._columnNumber = columnNumber; 429 this._columnNumber = columnNumber;
462 this._sourceFileId = sourceFileId; 430 this._sourceFileId = sourceFileId;
463 /** @type {!Array.<!WebInspector.Script.Location>} */
464 this._liveLocations = [];
465 /** @type {!Object.<string, !WebInspector.UILocation>} */
466 this._uiLocations = {};
467 431
468 /** @type {!Object.<string, number>} */ 432 /** @type {!Object.<string, number>} */
469 this._numberOfDebuggerLocationForUILocation = new Map(); 433 this._numberOfDebuggerLocationForUILocation = {};
470 434
471 // Force breakpoint update. 435 // Force breakpoint update.
472 /** @type {string} */ this._condition; 436 /** @type {string} */ this._condition;
473 /** @type {boolean} */ this._enabled; 437 /** @type {boolean} */ this._enabled;
474 this._updateBreakpoint(condition, enabled); 438 /** @type {boolean} */ this._isRemoved;
439 /** @type {!WebInspector.UILocation|undefined} */ this._fakeBreakpointPrimar yLocation;
vsevik 2014/06/04 16:28:53 I would replace this with primayrLocation() getter
440
441 /** @type {!Map.<!WebInspector.Target, !WebInspector.BreakpointManager.Targe tBreakpoint>}*/
442 this._targetBreakpoints = new Map();
443 this._breakpointManager._targetManager.observeTargets(this);
444 this._setNewState(condition, enabled);
vsevik 2014/06/04 16:28:53 updateState
sergeyv 2014/06/05 12:59:51 Done.
475 } 445 }
476 446
477 WebInspector.BreakpointManager.Breakpoint.prototype = { 447 WebInspector.BreakpointManager.Breakpoint.prototype = {
478 /** 448 /**
449 * @param {!WebInspector.Target} target
450 */
451 targetAdded: function(target)
452 {
453 target.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events. BreakpointResolved, this._breakpointResolved, this);
vsevik 2014/06/04 16:28:53 This should be in TargetBreakpoint constructor
sergeyv 2014/06/05 12:59:51 Done.
454 this._targetBreakpoints.put(target, new WebInspector.BreakpointManager.T argetBreakpoint(target, this));
455 },
456
457 /**
458 * @param {!WebInspector.Target} target
459 */
460 targetRemoved: function(target)
461 {
462 target.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Even ts.BreakpointResolved, this._breakpointResolved, this);
vsevik 2014/06/04 16:28:53 This should be in TargetBreakpoint.dispose()
sergeyv 2014/06/05 12:59:51 Done.
463 var targetBreakpoint = this._targetBreakpoints.remove(target);
464 targetBreakpoint._resetLocations();
vsevik 2014/06/04 16:28:53 This should be in TargetBreakpoint.dispose()
sergeyv 2014/06/05 12:59:51 Done.
465 },
466
467 /**
468 * @param {!WebInspector.Target} target
469 */
470 removeProvisionalBreakpointsForTest: function(target)
471 {
472 var debuggerId = this._targetBreakpoints.get(target)._debuggerId;
473 if (debuggerId)
474 target.debuggerModel.removeBreakpoint(debuggerId);
vsevik 2014/06/04 16:28:53 I would delegate this call to TargetBreakpoint.
sergeyv 2014/06/05 12:59:51 Done. But instead of it, I just call remove method
475 },
476
477 /**
479 * @return {string} 478 * @return {string}
480 */ 479 */
481 projectId: function() 480 projectId: function()
482 { 481 {
483 return this._projectId; 482 return this._projectId;
484 }, 483 },
485 484
486 /** 485 /**
487 * @return {string} 486 * @return {string}
488 */ 487 */
(...skipping 20 matching lines...) Expand all
509 508
510 /** 509 /**
511 * @return {?WebInspector.UISourceCode} 510 * @return {?WebInspector.UISourceCode}
512 */ 511 */
513 uiSourceCode: function() 512 uiSourceCode: function()
514 { 513 {
515 return this._breakpointManager._workspace.uiSourceCode(this._projectId, this._path); 514 return this._breakpointManager._workspace.uiSourceCode(this._projectId, this._path);
516 }, 515 },
517 516
518 /** 517 /**
519 * @param {!WebInspector.DebuggerModel.Location} location 518 * @param {?WebInspector.UILocation} oldUILocation
520 * @return {boolean} 519 * @param {!WebInspector.UILocation} newUILocation
521 */ 520 */
522 _addResolvedLocation: function(location) 521 _replaceUILocation: function(oldUILocation, newUILocation)
523 { 522 {
524 var script = location.script(); 523 if (this._isRemoved)
525 var uiLocation = script.rawLocationToUILocation(location.lineNumber, loc ation.columnNumber); 524 return;
526 var breakpoint = this._breakpointManager.findBreakpoint(uiLocation.uiSou rceCode, uiLocation.lineNumber, uiLocation.columnNumber); 525
527 if (breakpoint && breakpoint != this) { 526 this._removeUILocation(oldUILocation, true);
528 // location clash 527 this._removeFakeBreakpointAtPrimaryLocation();
vsevik 2014/06/04 16:28:53 this one seems redundant.
sergeyv 2014/06/05 12:59:51 Well, it is not :) since here we add a real locati
529 this.remove(); 528
530 return false; 529 if (!this._numberOfDebuggerLocationForUILocation[newUILocation.id()])
531 } 530 this._numberOfDebuggerLocationForUILocation[newUILocation.id()] = 0;
532 this._liveLocations.push(location.createLiveLocation(this._locationUpdat ed.bind(this, location))); 531
533 return true; 532 if (++this._numberOfDebuggerLocationForUILocation[newUILocation.id()] == = 1)
533 this._breakpointManager._uiLocationAdded(this, newUILocation);
534 }, 534 },
535 535
536 /** 536 /**
537 * @param {!WebInspector.DebuggerModel.Location} location 537 * @param {?WebInspector.UILocation} uiLocation
538 * @param {!WebInspector.UILocation} uiLocation 538 * @param {boolean=} muteCreationFakeBreakpoint
539 */ 539 */
540 _locationUpdated: function(location, uiLocation) 540 _removeUILocation: function(uiLocation, muteCreationFakeBreakpoint)
541 { 541 {
542 var oldUILocation = /** @type {!WebInspector.UILocation} */ (this._uiLoc ations[location.id()]); 542 if (!uiLocation || --this._numberOfDebuggerLocationForUILocation[uiLocat ion.id()] !== 0)
543 if (oldUILocation && --this._numberOfDebuggerLocationForUILocation[oldUI Location.id()] === 0) { 543 return;
544 delete this._numberOfDebuggerLocationForUILocation[oldUILocation.id( )];
545 this._breakpointManager._uiLocationRemoved(this, oldUILocation);
546 }
547 if (this._uiLocations[""]) {
548 var defaultLocation = this._uiLocations[""];
549 delete this._uiLocations[""];
550 this._breakpointManager._uiLocationRemoved(this, defaultLocation);
551 }
552 this._uiLocations[location.id()] = uiLocation;
553 544
554 if (!this._numberOfDebuggerLocationForUILocation[uiLocation.id()]) 545 delete this._numberOfDebuggerLocationForUILocation[uiLocation.id()];
555 this._numberOfDebuggerLocationForUILocation[uiLocation.id()] = 0; 546 this._breakpointManager._uiLocationRemoved(this, uiLocation);
556 547 if (!muteCreationFakeBreakpoint)
557 if (++this._numberOfDebuggerLocationForUILocation[uiLocation.id()] === 1 ) 548 this._fakeBreakpointAtPrimaryLocation();
558 this._breakpointManager._uiLocationAdded(this, uiLocation);
559 }, 549 },
560 550
561 /** 551 /**
562 * @return {boolean} 552 * @return {boolean}
563 */ 553 */
564 enabled: function() 554 enabled: function()
565 { 555 {
566 return this._enabled; 556 return this._enabled;
567 }, 557 },
568 558
569 /** 559 /**
570 * @param {boolean} enabled 560 * @param {boolean} enabled
571 */ 561 */
572 setEnabled: function(enabled) 562 setEnabled: function(enabled)
573 { 563 {
574 this._updateBreakpoint(this._condition, enabled); 564 this._setNewState(this._condition, enabled);
575 }, 565 },
576 566
577 /** 567 /**
578 * @return {string} 568 * @return {string}
579 */ 569 */
580 condition: function() 570 condition: function()
581 { 571 {
582 return this._condition; 572 return this._condition;
583 }, 573 },
584 574
585 /** 575 /**
586 * @param {string} condition 576 * @param {string} condition
587 */ 577 */
588 setCondition: function(condition) 578 setCondition: function(condition)
589 { 579 {
590 this._updateBreakpoint(condition, this._enabled); 580 this._setNewState(condition, this._enabled);
591 }, 581 },
592 582
593 /** 583 /**
594 * @param {string} condition 584 * @param {string} condition
595 * @param {boolean} enabled 585 * @param {boolean} enabled
596 */ 586 */
597 _updateBreakpoint: function(condition, enabled) 587 _setNewState: function(condition, enabled)
598 { 588 {
599 if (this._enabled === enabled && this._condition === condition) 589 if (this._enabled === enabled && this._condition === condition)
600 return; 590 return;
601 this._enabled = enabled; 591 this._enabled = enabled;
602 this._condition = condition; 592 this._condition = condition;
603 this._breakpointManager._storage._updateBreakpoint(this); 593 this._breakpointManager._storage._updateBreakpoint(this);
594 this._updateBreakpoint();
595 },
596
597 _updateBreakpoint: function()
598 {
599 this._removeFakeBreakpointAtPrimaryLocation();
600 this._fakeBreakpointAtPrimaryLocation();
604 this._updateInDebugger(); 601 this._updateInDebugger();
605 }, 602 },
606 603
607 /** 604 /**
608 * @param {boolean=} keepInStorage 605 * @param {boolean=} keepInStorage
609 */ 606 */
610 remove: function(keepInStorage) 607 remove: function(keepInStorage)
611 { 608 {
609 this._isRemoved = true;
612 var removeFromStorage = !keepInStorage; 610 var removeFromStorage = !keepInStorage;
611 this._removeFakeBreakpointAtPrimaryLocation();
612 var targets = this._targetBreakpoints.keys();
613 for (var i = 0; i < targets.length; ++i) {
614 this._targetBreakpoints.get(targets[i])._removeFromDebugger();
vsevik 2014/06/04 16:28:53 Again ,let's put all this stuff into TargetBreakpo
sergeyv 2014/06/05 12:59:51 Done.
615 targets[i].debuggerModel.removeEventListener(WebInspector.DebuggerMo del.Events.BreakpointResolved, this._breakpointResolved, this);
616 }
617 this._breakpointManager._removeBreakpoint(this, removeFromStorage);
618 this._breakpointManager._targetManager.removeTargetObserver(this);
619 },
620
621 _updateInDebugger: function()
622 {
623 var targetBreakpoints = this._targetBreakpoints.values();
624 for (var i = 0; i < targetBreakpoints.length; ++i)
625 targetBreakpoints[i]._updateInDebugger();
626 },
627
628 /**
629 * @return {string}
630 */
631 _breakpointStorageId: function()
632 {
633 return WebInspector.BreakpointManager._breakpointStorageId(this._sourceF ileId, this._lineNumber, this._columnNumber);
634 },
635
636 _fakeBreakpointAtPrimaryLocation: function()
637 {
638 if (this._isRemoved || !Object.isEmpty(this._numberOfDebuggerLocationFor UILocation) || this._fakeBreakpointPrimaryLocation)
639 return;
640
641 var uiSourceCode = this._breakpointManager._workspace.uiSourceCode(this. _projectId, this._path);
642 if (!uiSourceCode)
643 return;
644
645 this._fakeBreakpointPrimaryLocation = uiSourceCode.uiLocation(this._line Number, this._columnNumber);
646 this._breakpointManager._uiLocationAdded(this, this._fakeBreakpointPrima ryLocation);
647 },
648
649 _removeFakeBreakpointAtPrimaryLocation: function()
650 {
651 if (this._fakeBreakpointPrimaryLocation) {
652 this._breakpointManager._uiLocationRemoved(this, this._fakeBreakpoin tPrimaryLocation);
653 delete this._fakeBreakpointPrimaryLocation;
654 }
655 },
656
657 /**
658 * @param {!WebInspector.Event} event
659 */
660 _breakpointResolved: function(event)
vsevik 2014/06/04 16:28:53 This method belongs to TargetBreakpoint
sergeyv 2014/06/05 12:59:51 Done.
661 {
662 var breakpointId = /** @type {!DebuggerAgent.BreakpointId} */ (event.dat a.breakpointId);
663 var location = /** @type {!WebInspector.DebuggerModel.Location} */ (even t.data.location);
664 this._targetBreakpoints.get(location.target())._breakpointResolved(break pointId, location);
665 },
666
667 _resetLocations: function()
668 {
669 this._removeFakeBreakpointAtPrimaryLocation();
670 var targetBreakpoints = this._targetBreakpoints.values();
671 for (var i = 0; i < targetBreakpoints.length; ++i)
672 targetBreakpoints[i]._resetLocations();
673 }
674 }
675
676 /**
677 * @constructor
678 * @extends {WebInspector.TargetAware}
679 * @param {!WebInspector.Target} target
680 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint
681 */
682 WebInspector.BreakpointManager.TargetBreakpoint = function(target, breakpoint)
683 {
684 WebInspector.TargetAware.call(this, target);
685 this._breakpoint = breakpoint;
686 /** @type {!Array.<!WebInspector.Script.Location>} */
687 this._liveLocations = [];
688
689 /** @type {!Object.<string, !WebInspector.UILocation>} */
690 this._uiLocations = {};
691 }
692
693 WebInspector.BreakpointManager.TargetBreakpoint.prototype = {
694
695 _resetLocations: function()
696 {
697 var uiLocations = Object.values(this._uiLocations);
698 for (var i = 0; i < uiLocations.length; ++i)
699 this._breakpoint._removeUILocation(uiLocations[i]);
700
701 this._uiLocations = {};
702
703 for (var i = 0; i < this._liveLocations.length; ++i)
704 this._liveLocations[i].dispose();
705 this._liveLocations = [];
706 },
707
708 /**
709 * @param {boolean=} muteCallback
710 */
711 _removeFromDebugger: function(muteCallback)
712 {
713 this._resetLocations();
714 if (!this._debuggerId)
715 return;
716 this.target().debuggerModel.removeBreakpoint(this._debuggerId, muteCallb ack ? undefined : this._didRemoveFromDebugger.bind(this));
717 },
718
719 _updateInDebugger: function()
720 {
613 this._removeFromDebugger(); 721 this._removeFromDebugger();
614 this._breakpointManager._removeBreakpoint(this, removeFromStorage); 722 var uiSourceCode = this._breakpoint.uiSourceCode();
615 }, 723 if (!uiSourceCode || !this._breakpoint._enabled)
616 724 return;
617 _updateInDebugger: function() 725 var scriptFile = uiSourceCode.scriptFileForTarget(this._target);
618 { 726 if (scriptFile && scriptFile.hasDivergedFromVM())
619 this._removeFromDebugger(); 727 return;
620 this._fakeBreakpointAtPrimaryLocation(); 728
621 var uiSourceCode = this.uiSourceCode(); 729 var lineNumber = this._breakpoint._lineNumber;
622 if (!uiSourceCode || !this._enabled) 730 var columnNumber = this._breakpoint._columnNumber;
623 return; 731 var rawLocation = uiSourceCode.uiLocationToRawLocation(this._target, lin eNumber, columnNumber);
624 732 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (rawLocation);
625 var targets = this._breakpointManager._targetManager.targets(); 733 var condition = this._breakpoint.condition();
626 for (var i = 0; i < targets.length; ++i) { 734 if (debuggerModelLocation)
627 var scriptFile = uiSourceCode.scriptFileForTarget(targets[i]); 735 this.target().debuggerModel.setBreakpointByScriptLocation(debuggerMo delLocation, condition, this._didSetBreakpointInDebugger.bind(this));
628 if (scriptFile && scriptFile.hasDivergedFromVM()) 736 else if (uiSourceCode.url)
629 return; 737 this.target().debuggerModel.setBreakpointByURL(uiSourceCode.url, lin eNumber, columnNumber, condition, this._didSetBreakpointInDebugger.bind(this));
630 } 738 },
631 739
632 for (var i = 0; i < targets.length; ++i) { 740 /**
633 var rawLocation = uiSourceCode.uiLocationToRawLocation(targets[i], t his._lineNumber, this._columnNumber); 741 * @param {?DebuggerAgent.BreakpointId} breakpointId
634 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.L ocation} */ (rawLocation); 742 * @param {!Array.<!WebInspector.DebuggerModel.Location>} locations
635 if (debuggerModelLocation) 743 */
636 targets[i].debuggerModel.setBreakpointByScriptLocation(debuggerM odelLocation, this._condition, this._didSetBreakpointInDebugger.bind(this));
637 else if (uiSourceCode.url)
638 targets[i].debuggerModel.setBreakpointByURL(uiSourceCode.url, th is._lineNumber, this._columnNumber, this._condition, this._didSetBreakpointInDeb ugger.bind(this));
639 }
640 },
641
642 /**
643 * @param {?DebuggerAgent.BreakpointId} breakpointId
644 * @param {!Array.<!WebInspector.DebuggerModel.Location>} locations
645 */
646 _didSetBreakpointInDebugger: function(breakpointId, locations) 744 _didSetBreakpointInDebugger: function(breakpointId, locations)
647 { 745 {
648 if (!breakpointId) { 746 if (!breakpointId) {
649 this.remove(true); 747 this._breakpoint.remove(true);
650 return; 748 return;
651 } 749 }
750
751 if (this._debuggerId)
752 this._removeFromDebugger(true);
652 753
653 this._debuggerId = breakpointId; 754 this._debuggerId = breakpointId;
654 this._breakpointManager._breakpointForDebuggerId[breakpointId] = this;
655
656 for (var i = 0; i < locations.length; ++i) 755 for (var i = 0; i < locations.length; ++i)
657 if (!this._addResolvedLocation(locations[i])) 756 if (!this._addResolvedLocation(locations[i]))
658 return; 757 return;
659 }, 758 },
660 759
661 _removeFromDebugger: function()
662 {
663 this._resetLocations();
664 if (!this._debuggerId)
665 return;
666 var barrier = new CallbackBarrier();
667 this._breakpointManager._targetManager.targets().forEach(function(target ){target.debuggerModel.removeBreakpoint(this._debuggerId, barrier.createCallback ())}, this);
668 barrier.callWhenDone(this._didRemoveFromDebugger.bind(this));
669 },
670
671 _didRemoveFromDebugger: function() 760 _didRemoveFromDebugger: function()
672 { 761 {
673 delete this._breakpointManager._breakpointForDebuggerId[this._debuggerId ];
674 delete this._debuggerId; 762 delete this._debuggerId;
675 }, 763 },
676 764
677 _resetLocations: function() 765 /**
678 { 766 * @param {!DebuggerAgent.BreakpointId} breakpointId
679 for (var stringifiedLocation in this._uiLocations) { 767 * @param {!WebInspector.DebuggerModel.Location} location
680 var uiLocation = this._uiLocations[stringifiedLocation]; 768 */
681 if (this._numberOfDebuggerLocationForUILocation[uiLocation.id()]) { 769 _breakpointResolved: function(breakpointId, location)
682 this._breakpointManager._uiLocationRemoved(this, uiLocation); 770 {
683 delete this._numberOfDebuggerLocationForUILocation[uiLocation.id ()]; 771 if (this._debuggerId === breakpointId)
684 } 772 this._addResolvedLocation(location);
685 } 773 },
686 if (this._uiLocations[""]) 774
687 this._breakpointManager._uiLocationRemoved(this, this._uiLocations[" "]); 775 /**
688 for (var i = 0; i < this._liveLocations.length; ++i) 776 * @param {!WebInspector.DebuggerModel.Location} location
689 this._liveLocations[i].dispose(); 777 * @param {!WebInspector.UILocation} uiLocation
690 this._liveLocations = []; 778 */
691 this._uiLocations = {}; 779 _locationUpdated: function(location, uiLocation)
692 this._numberOfDebuggerLocationForUILocation = {}; 780 {
693 }, 781 var oldUILocation = this._uiLocations[location.id()] || null;
694 782 this._uiLocations[location.id()] = uiLocation;
695 /** 783 this._breakpoint._replaceUILocation(oldUILocation, uiLocation);
696 * @return {string} 784 },
697 */ 785
698 _breakpointStorageId: function() 786 /**
699 { 787 * @param {!WebInspector.DebuggerModel.Location} location
700 return WebInspector.BreakpointManager._breakpointStorageId(this._sourceF ileId, this._lineNumber, this._columnNumber); 788 * @return {boolean}
701 }, 789 */
702 790 _addResolvedLocation: function(location)
703 _fakeBreakpointAtPrimaryLocation: function() 791 {
704 { 792 var script = location.script();
705 var uiSourceCode = this._breakpointManager._workspace.uiSourceCode(this. _projectId, this._path); 793 var uiLocation = script.rawLocationToUILocation(location.lineNumber, loc ation.columnNumber);
706 if (!uiSourceCode) 794 var breakpoint = this._breakpoint._breakpointManager.findBreakpoint(uiLo cation.uiSourceCode, uiLocation.lineNumber, uiLocation.columnNumber);
707 return; 795 if (breakpoint && breakpoint != this._breakpoint) {
708 var uiLocation = uiSourceCode.uiLocation(this._lineNumber, this._columnN umber); 796 // location clash
709 this._uiLocations[""] = uiLocation; 797 this._breakpoint.remove();
710 this._breakpointManager._uiLocationAdded(this, uiLocation); 798 return false;
711 } 799 }
800 this._liveLocations.push(location.createLiveLocation(this._locationUpdat ed.bind(this, location)));
801 return true;
802 },
803
804 __proto__: WebInspector.TargetAware.prototype
712 } 805 }
713 806
714 /** 807 /**
715 * @constructor 808 * @constructor
716 * @param {!WebInspector.BreakpointManager} breakpointManager 809 * @param {!WebInspector.BreakpointManager} breakpointManager
717 * @param {!WebInspector.Setting} setting 810 * @param {!WebInspector.Setting} setting
718 */ 811 */
719 WebInspector.BreakpointManager.Storage = function(breakpointManager, setting) 812 WebInspector.BreakpointManager.Storage = function(breakpointManager, setting)
720 { 813 {
721 this._breakpointManager = breakpointManager; 814 this._breakpointManager = breakpointManager;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 { 889 {
797 this.sourceFileId = breakpoint._sourceFileId; 890 this.sourceFileId = breakpoint._sourceFileId;
798 this.lineNumber = breakpoint.lineNumber(); 891 this.lineNumber = breakpoint.lineNumber();
799 this.columnNumber = breakpoint.columnNumber(); 892 this.columnNumber = breakpoint.columnNumber();
800 this.condition = breakpoint.condition(); 893 this.condition = breakpoint.condition();
801 this.enabled = breakpoint.enabled(); 894 this.enabled = breakpoint.enabled();
802 } 895 }
803 896
804 /** @type {!WebInspector.BreakpointManager} */ 897 /** @type {!WebInspector.BreakpointManager} */
805 WebInspector.breakpointManager; 898 WebInspector.breakpointManager;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698