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

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

Powered by Google App Engine
This is Rietveld 408576698