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

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: 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 this._sourceFilesWithRestoredBreakpoints = {}; 46 this._sourceFilesWithRestoredBreakpoints = {};
49 47
48 /** @type {!Array.<!WebInspector.BreakpointManager.Breakpoint>}*/
49 this._breakpoints = [];
vsevik 2014/06/02 13:38:00 Let's only keep provisional breakpoints there.
50
50 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillRe set, this._projectWillReset, this); 51 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillRe set, this._projectWillReset, this);
51 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this); 52 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAdded, this);
52 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this); 53 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this);
53 this._targetManager.observeTargets(this);
54 } 54 }
55 55
56 WebInspector.BreakpointManager.Events = { 56 WebInspector.BreakpointManager.Events = {
57 BreakpointAdded: "breakpoint-added", 57 BreakpointAdded: "breakpoint-added",
58 BreakpointRemoved: "breakpoint-removed" 58 BreakpointRemoved: "breakpoint-removed"
59 } 59 }
60 60
61 WebInspector.BreakpointManager._sourceFileId = function(uiSourceCode) 61 WebInspector.BreakpointManager._sourceFileId = function(uiSourceCode)
62 { 62 {
63 if (!uiSourceCode.url) 63 if (!uiSourceCode.url)
64 return ""; 64 return "";
65 return uiSourceCode.uri(); 65 return uiSourceCode.uri();
66 } 66 }
67 67
68 /** 68 /**
69 * @param {string} sourceFileId 69 * @param {string} sourceFileId
70 * @param {number} lineNumber 70 * @param {number} lineNumber
71 * @param {number} columnNumber 71 * @param {number} columnNumber
72 * @return {string} 72 * @return {string}
73 */ 73 */
74 WebInspector.BreakpointManager._breakpointStorageId = function(sourceFileId, lin eNumber, columnNumber) 74 WebInspector.BreakpointManager._breakpointStorageId = function(sourceFileId, lin eNumber, columnNumber)
75 { 75 {
76 if (!sourceFileId) 76 if (!sourceFileId)
77 return ""; 77 return "";
78 return sourceFileId + ":" + lineNumber + ":" + columnNumber; 78 return sourceFileId + ":" + lineNumber + ":" + columnNumber;
79 } 79 }
80 80
81 WebInspector.BreakpointManager.prototype = { 81 WebInspector.BreakpointManager.prototype = {
82 /**
83 * @param {!WebInspector.Target} target
84 */
85 targetAdded: function(target)
86 {
87 target.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events. BreakpointResolved, this._breakpointResolved, this);
88 },
89
90 /**
91 * @param {!WebInspector.Target} target
92 */
93 targetRemoved: function(target)
94 {
95 target.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Even ts.BreakpointResolved, this._breakpointResolved, this);
96 },
97 82
98 /** 83 /**
99 * @param {string} sourceFileId 84 * @param {string} sourceFileId
100 */ 85 */
101 _provisionalBreakpointsForSourceFileId: function(sourceFileId) 86 _provisionalBreakpointsForSourceFileId: function(sourceFileId)
102 { 87 {
103 var result = new StringMap(); 88 var result = new StringMap();
104 for (var debuggerId in this._breakpointForDebuggerId) { 89 for (var j = 0; j < this._breakpoints.length; ++j) {
105 var breakpoint = this._breakpointForDebuggerId[debuggerId]; 90 var breakpoint = this._breakpoints[j];
106 if (breakpoint._sourceFileId === sourceFileId) 91 if (breakpoint._sourceFileId === sourceFileId)
107 result.put(breakpoint._breakpointStorageId(), breakpoint); 92 result.put(breakpoint._breakpointStorageId(), breakpoint);
108 } 93 }
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 for (var debuggerId in this._breakpointForDebuggerId) 102 for (var j = 0; j < this._breakpoints.length; ++j)
118 target.debuggerModel.removeBreakpoint(debuggerId); 103 this._breakpoints[j].removeProvisionalBreakpointsForTest(target);
119 }, 104 },
120 105
121 /** 106 /**
122 * @param {!WebInspector.UISourceCode} uiSourceCode 107 * @param {!WebInspector.UISourceCode} uiSourceCode
123 */ 108 */
124 _restoreBreakpoints: function(uiSourceCode) 109 _restoreBreakpoints: function(uiSourceCode)
125 { 110 {
126 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code); 111 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code);
127 if (!sourceFileId || this._sourceFilesWithRestoredBreakpoints[sourceFile Id]) 112 if (!sourceFileId || this._sourceFilesWithRestoredBreakpoints[sourceFile Id])
128 return; 113 return;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 { 208 {
224 var breakpoint = this.findBreakpoint(uiSourceCode, lineNumber, columnNum ber); 209 var breakpoint = this.findBreakpoint(uiSourceCode, lineNumber, columnNum ber);
225 if (breakpoint) { 210 if (breakpoint) {
226 breakpoint._updateBreakpoint(condition, enabled); 211 breakpoint._updateBreakpoint(condition, enabled);
227 return breakpoint; 212 return breakpoint;
228 } 213 }
229 var projectId = uiSourceCode.project().id(); 214 var projectId = uiSourceCode.project().id();
230 var path = uiSourceCode.path(); 215 var path = uiSourceCode.path();
231 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code); 216 var sourceFileId = WebInspector.BreakpointManager._sourceFileId(uiSource Code);
232 breakpoint = new WebInspector.BreakpointManager.Breakpoint(this, project Id, path, sourceFileId, lineNumber, columnNumber, condition, enabled); 217 breakpoint = new WebInspector.BreakpointManager.Breakpoint(this, project Id, path, sourceFileId, lineNumber, columnNumber, condition, enabled);
218 this._breakpoints.push(breakpoint);
233 if (!this._breakpointsForPrimaryUISourceCode.get(uiSourceCode)) 219 if (!this._breakpointsForPrimaryUISourceCode.get(uiSourceCode))
234 this._breakpointsForPrimaryUISourceCode.put(uiSourceCode, []); 220 this._breakpointsForPrimaryUISourceCode.put(uiSourceCode, []);
235 this._breakpointsForPrimaryUISourceCode.get(uiSourceCode).push(breakpoin t); 221 this._breakpointsForPrimaryUISourceCode.get(uiSourceCode).push(breakpoin t);
236 return breakpoint; 222 return breakpoint;
237 }, 223 },
238 224
239 /** 225 /**
240 * @param {!WebInspector.UISourceCode} uiSourceCode 226 * @param {!WebInspector.UISourceCode} uiSourceCode
241 * @param {number} lineNumber 227 * @param {number} lineNumber
242 * @param {number} columnNumber 228 * @param {number} columnNumber
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 }, 333 },
348 334
349 _projectWillReset: function(event) 335 _projectWillReset: function(event)
350 { 336 {
351 var project = /** @type {!WebInspector.Project} */ (event.data); 337 var project = /** @type {!WebInspector.Project} */ (event.data);
352 var uiSourceCodes = project.uiSourceCodes(); 338 var uiSourceCodes = project.uiSourceCodes();
353 for (var i = 0; i < uiSourceCodes.length; ++i) 339 for (var i = 0; i < uiSourceCodes.length; ++i)
354 this._removeUISourceCode(uiSourceCodes[i]); 340 this._removeUISourceCode(uiSourceCodes[i]);
355 }, 341 },
356 342
357 _breakpointResolved: function(event)
358 {
359 var breakpointId = /** @type {!DebuggerAgent.BreakpointId} */ (event.dat a.breakpointId);
360 var location = /** @type {!WebInspector.DebuggerModel.Location} */ (even t.data.location);
361 var breakpoint = this._breakpointForDebuggerId[breakpointId];
362 if (!breakpoint)
363 return;
364 breakpoint._addResolvedLocation(location);
365 },
366
367 /** 343 /**
368 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint 344 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint
369 * @param {boolean} removeFromStorage 345 * @param {boolean} removeFromStorage
370 */ 346 */
371 _removeBreakpoint: function(breakpoint, removeFromStorage) 347 _removeBreakpoint: function(breakpoint, removeFromStorage)
372 { 348 {
373 var uiSourceCode = breakpoint.uiSourceCode(); 349 var uiSourceCode = breakpoint.uiSourceCode();
374 var breakpoints = uiSourceCode ? this._breakpointsForPrimaryUISourceCode .get(uiSourceCode) || [] : []; 350 var breakpoints = uiSourceCode ? this._breakpointsForPrimaryUISourceCode .get(uiSourceCode) || [] : [];
375 var index = breakpoints.indexOf(breakpoint); 351 breakpoints.remove(breakpoint);
376 if (index > -1) 352 this._breakpoints.remove(breakpoint);
377 breakpoints.splice(index, 1);
378 if (removeFromStorage) 353 if (removeFromStorage)
379 this._storage._removeBreakpoint(breakpoint); 354 this._storage._removeBreakpoint(breakpoint);
380 }, 355 },
381 356
382 /** 357 /**
383 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint 358 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint
384 * @param {!WebInspector.UILocation} uiLocation 359 * @param {!WebInspector.UILocation} uiLocation
385 */ 360 */
386 _uiLocationAdded: function(breakpoint, uiLocation) 361 _uiLocationAdded: function(breakpoint, uiLocation)
387 { 362 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 if (!breakpoints.size()) 403 if (!breakpoints.size())
429 this._breakpointsForUISourceCode.remove(uiLocation.uiSourceCode); 404 this._breakpointsForUISourceCode.remove(uiLocation.uiSourceCode);
430 this.dispatchEventToListeners(WebInspector.BreakpointManager.Events.Brea kpointRemoved, {breakpoint: breakpoint, uiLocation: uiLocation}); 405 this.dispatchEventToListeners(WebInspector.BreakpointManager.Events.Brea kpointRemoved, {breakpoint: breakpoint, uiLocation: uiLocation});
431 }, 406 },
432 407
433 __proto__: WebInspector.Object.prototype 408 __proto__: WebInspector.Object.prototype
434 } 409 }
435 410
436 /** 411 /**
437 * @constructor 412 * @constructor
413 * @implements {WebInspector.TargetManager.Observer}
438 * @param {!WebInspector.BreakpointManager} breakpointManager 414 * @param {!WebInspector.BreakpointManager} breakpointManager
439 * @param {string} projectId 415 * @param {string} projectId
440 * @param {string} path 416 * @param {string} path
441 * @param {string} sourceFileId 417 * @param {string} sourceFileId
442 * @param {number} lineNumber 418 * @param {number} lineNumber
443 * @param {number} columnNumber 419 * @param {number} columnNumber
444 * @param {string} condition 420 * @param {string} condition
445 * @param {boolean} enabled 421 * @param {boolean} enabled
446 */ 422 */
447 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)
448 { 424 {
449 this._breakpointManager = breakpointManager; 425 this._breakpointManager = breakpointManager;
450 this._projectId = projectId; 426 this._projectId = projectId;
451 this._path = path; 427 this._path = path;
452 this._lineNumber = lineNumber; 428 this._lineNumber = lineNumber;
453 this._columnNumber = columnNumber; 429 this._columnNumber = columnNumber;
454 this._sourceFileId = sourceFileId; 430 this._sourceFileId = sourceFileId;
455 /** @type {!Array.<!WebInspector.Script.Location>} */
456 this._liveLocations = [];
457 /** @type {!Object.<string, !WebInspector.UILocation>} */
458 this._uiLocations = {};
459 431
460 /** @type {!Object.<string, number>} */ 432 /** @type {!Object.<string, number>} */
461 this._numberOfDebuggerLocationForUILocation = new Map(); 433 this._numberOfDebuggerLocationForUILocation = {};
462 434
463 // Force breakpoint update. 435 // Force breakpoint update.
464 /** @type {string} */ this._condition; 436 /** @type {string} */ this._condition;
465 /** @type {boolean} */ this._enabled; 437 /** @type {boolean} */ this._enabled;
438 /** @type {boolean} */ this._isRemoved;
439 /** @type {!WebInspector.UILocation|undefined} */ this._fakeBreakpointPrimar yLocation;
440
441 /** @type {!Map.<!WebInspector.Target, !WebInspector.BreakpointManager.Targe tBreakpoint>}*/
442 this._targetBreakpoints = new Map();
443 this._breakpointManager._targetManager.observeTargets(this);
466 this._updateBreakpoint(condition, enabled); 444 this._updateBreakpoint(condition, enabled);
467 } 445 }
468 446
469 WebInspector.BreakpointManager.Breakpoint.prototype = { 447 WebInspector.BreakpointManager.Breakpoint.prototype = {
470 /** 448 /**
449 * @param {!WebInspector.Target} target
450 */
451 targetAdded: function(target)
452 {
453 target.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events. BreakpointResolved, this._breakpointResolved, this);
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);
463 var targetBreakpoint = this._targetBreakpoints.remove(target);
464 targetBreakpoint._resetLocations();
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);
475 },
476
477 /**
471 * @return {string} 478 * @return {string}
472 */ 479 */
473 projectId: function() 480 projectId: function()
474 { 481 {
475 return this._projectId; 482 return this._projectId;
476 }, 483 },
477 484
478 /** 485 /**
479 * @return {string} 486 * @return {string}
480 */ 487 */
(...skipping 20 matching lines...) Expand all
501 508
502 /** 509 /**
503 * @return {?WebInspector.UISourceCode} 510 * @return {?WebInspector.UISourceCode}
504 */ 511 */
505 uiSourceCode: function() 512 uiSourceCode: function()
506 { 513 {
507 return this._breakpointManager._workspace.uiSourceCode(this._projectId, this._path); 514 return this._breakpointManager._workspace.uiSourceCode(this._projectId, this._path);
508 }, 515 },
509 516
510 /** 517 /**
511 * @param {!WebInspector.DebuggerModel.Location} location 518 * @param {?WebInspector.UILocation} oldUILocation
512 * @return {boolean} 519 * @param {!WebInspector.UILocation} newUILocation
513 */ 520 */
514 _addResolvedLocation: function(location) 521 _replaceUILocation: function(oldUILocation, newUILocation)
515 { 522 {
516 var script = location.script(); 523 if (this._isRemoved)
517 var uiLocation = script.rawLocationToUILocation(location.lineNumber, loc ation.columnNumber); 524 return;
518 var breakpoint = this._breakpointManager.findBreakpoint(uiLocation.uiSou rceCode, uiLocation.lineNumber, uiLocation.columnNumber); 525
519 if (breakpoint && breakpoint != this) { 526 this._removeUILocation(oldUILocation);
520 // location clash 527 this._removeFakeBreakpointAtPrimaryLocation();
521 this.remove(); 528
522 return false; 529 if (!this._numberOfDebuggerLocationForUILocation[newUILocation.id()])
523 } 530 this._numberOfDebuggerLocationForUILocation[newUILocation.id()] = 0;
524 this._liveLocations.push(location.createLiveLocation(this._locationUpdat ed.bind(this, location))); 531
525 return true; 532 if (++this._numberOfDebuggerLocationForUILocation[newUILocation.id()] == = 1)
533 this._breakpointManager._uiLocationAdded(this, newUILocation);
526 }, 534 },
527 535
528 /** 536 /**
529 * @param {!WebInspector.DebuggerModel.Location} location 537 *
530 * @param {!WebInspector.UILocation} uiLocation 538 * @param {?WebInspector.UILocation} uiLocation
531 */ 539 */
532 _locationUpdated: function(location, uiLocation) 540 _removeUILocation: function(uiLocation)
533 { 541 {
534 var oldUILocation = /** @type {!WebInspector.UILocation} */ (this._uiLoc ations[location.id()]); 542 if (uiLocation && --this._numberOfDebuggerLocationForUILocation[uiLocati on.id()] === 0) {
535 if (oldUILocation && --this._numberOfDebuggerLocationForUILocation[oldUI Location.id()] === 0) { 543 delete this._numberOfDebuggerLocationForUILocation[uiLocation.id()];
536 delete this._numberOfDebuggerLocationForUILocation[oldUILocation.id( )]; 544 this._breakpointManager._uiLocationRemoved(this, uiLocation);
537 this._breakpointManager._uiLocationRemoved(this, oldUILocation);
538 } 545 }
539 if (this._uiLocations[""]) {
540 var defaultLocation = this._uiLocations[""];
541 delete this._uiLocations[""];
542 this._breakpointManager._uiLocationRemoved(this, defaultLocation);
543 }
544 this._uiLocations[location.id()] = uiLocation;
545
546 if (!this._numberOfDebuggerLocationForUILocation[uiLocation.id()])
547 this._numberOfDebuggerLocationForUILocation[uiLocation.id()] = 0;
548
549 if (++this._numberOfDebuggerLocationForUILocation[uiLocation.id()] === 1 )
550 this._breakpointManager._uiLocationAdded(this, uiLocation);
551 }, 546 },
552 547
553 /** 548 /**
554 * @return {boolean} 549 * @return {boolean}
555 */ 550 */
556 enabled: function() 551 enabled: function()
557 { 552 {
558 return this._enabled; 553 return this._enabled;
559 }, 554 },
560 555
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 this._condition = condition; 589 this._condition = condition;
595 this._breakpointManager._storage._updateBreakpoint(this); 590 this._breakpointManager._storage._updateBreakpoint(this);
596 this._updateInDebugger(); 591 this._updateInDebugger();
597 }, 592 },
598 593
599 /** 594 /**
600 * @param {boolean=} keepInStorage 595 * @param {boolean=} keepInStorage
601 */ 596 */
602 remove: function(keepInStorage) 597 remove: function(keepInStorage)
603 { 598 {
599 this._isRemoved = true;
604 var removeFromStorage = !keepInStorage; 600 var removeFromStorage = !keepInStorage;
601 this._removeFakeBreakpointAtPrimaryLocation();
602 var targets = this._targetBreakpoints.keys();
603 for (var i = 0; i < targets.length; ++i) {
604 this._targetBreakpoints.get(targets[i])._removeFromDebugger();
605 targets[i].debuggerModel.removeEventListener(WebInspector.DebuggerMo del.Events.BreakpointResolved, this._breakpointResolved, this);
606 }
607 this._breakpointManager._removeBreakpoint(this, removeFromStorage);
608 this._breakpointManager._targetManager.removeTargetObserver(this);
609 },
610
611 _updateInDebugger: function()
612 {
613 this._removeFakeBreakpointAtPrimaryLocation();
614 var targetBreakpoints = this._targetBreakpoints.values();
615 for (var i = 0; i < targetBreakpoints.length; ++i)
616 targetBreakpoints[i]._updateInDebugger();
617 },
618
619 /**
620 * @return {string}
621 */
622 _breakpointStorageId: function()
623 {
624 return WebInspector.BreakpointManager._breakpointStorageId(this._sourceF ileId, this._lineNumber, this._columnNumber);
625 },
626
627 _fakeBreakpointAtPrimaryLocation: function()
628 {
629 if (this._isRemoved || !Object.isEmpty(this._numberOfDebuggerLocationFor UILocation) || this._fakeBreakpointPrimaryLocation)
630 return;
631
632 var uiSourceCode = this._breakpointManager._workspace.uiSourceCode(this. _projectId, this._path);
633 if (!uiSourceCode)
634 return;
635
636 this._fakeBreakpointPrimaryLocation = uiSourceCode.uiLocation(this._line Number, this._columnNumber);
637 this._breakpointManager._uiLocationAdded(this, this._fakeBreakpointPrima ryLocation);
638 },
639
640 _removeFakeBreakpointAtPrimaryLocation: function()
641 {
642 if (this._fakeBreakpointPrimaryLocation) {
643 this._breakpointManager._uiLocationRemoved(this, this._fakeBreakpoin tPrimaryLocation);
644 delete this._fakeBreakpointPrimaryLocation;
645 }
646 },
647
648 /**
649 * @param {!WebInspector.Event} event
650 */
651 _breakpointResolved: function(event)
652 {
653 var breakpointId = /** @type {!DebuggerAgent.BreakpointId} */ (event.dat a.breakpointId);
654 var location = /** @type {!WebInspector.DebuggerModel.Location} */ (even t.data.location);
655 this._targetBreakpoints.get(location.target())._breakpointResolved(break pointId, location);
656 },
657
658 _resetLocations: function()
659 {
660 this._removeFakeBreakpointAtPrimaryLocation();
661 var targetBreakpoints = this._targetBreakpoints.values();
662 for (var i = 0; i < targetBreakpoints.length; ++i)
663 targetBreakpoints[i]._resetLocations();
664 }
665 }
666
667 /**
668 * @constructor
669 * @extends {WebInspector.TargetAware}
670 * @param {!WebInspector.Target} target
671 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint
672 */
673 WebInspector.BreakpointManager.TargetBreakpoint = function(target, breakpoint)
674 {
675 WebInspector.TargetAware.call(this, target);
676 this._breakpoint = breakpoint;
677 /** @type {!Array.<!WebInspector.Script.Location>} */
678 this._liveLocations = [];
679
680 /** @type {!Object.<string, !WebInspector.UILocation>} */
681 this._uiLocations = {};
682 }
683
684 WebInspector.BreakpointManager.TargetBreakpoint.prototype = {
685
686 _resetLocations: function()
687 {
688 var uiLocations = Object.values(this._uiLocations);
689 for (var i = 0; i < uiLocations.length; ++i)
690 this._breakpoint._removeUILocation(uiLocations[i]);
691
692 this._uiLocations = {};
693
694 for (var i = 0; i < this._liveLocations.length; ++i)
695 this._liveLocations[i].dispose();
696 this._liveLocations = [];
697 },
698
699 /**
700 * @param {boolean=} muteCallback
701 */
702 _removeFromDebugger: function(muteCallback)
703 {
704 this._resetLocations();
705 if (!this._debuggerId)
706 return;
707 this.target().debuggerModel.removeBreakpoint(this._debuggerId, muteCallb ack ? undefined : this._didRemoveFromDebugger.bind(this));
708 },
709
710 _updateInDebugger: function()
711 {
605 this._removeFromDebugger(); 712 this._removeFromDebugger();
606 this._breakpointManager._removeBreakpoint(this, removeFromStorage); 713 this._breakpoint._fakeBreakpointAtPrimaryLocation();
vsevik 2014/06/02 13:38:00 TargetBreakpoint should know nothing about faking
607 }, 714 var uiSourceCode = this._breakpoint.uiSourceCode();
608 715 if (!uiSourceCode || !this._breakpoint._enabled)
609 _updateInDebugger: function() 716 return;
610 { 717 var scriptFile = uiSourceCode.scriptFileForTarget(this._target);
611 this._removeFromDebugger(); 718 if (scriptFile && scriptFile.hasDivergedFromVM())
612 this._fakeBreakpointAtPrimaryLocation(); 719 return;
613 var uiSourceCode = this.uiSourceCode(); 720
614 if (!uiSourceCode || !this._enabled) 721 var lineNumber = this._breakpoint._lineNumber;
615 return; 722 var columnNumber = this._breakpoint._columnNumber;
616 723 var rawLocation = uiSourceCode.uiLocationToRawLocation(this._target, lin eNumber, columnNumber);
617 var targets = this._breakpointManager._targetManager.targets(); 724 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (rawLocation);
618 for (var i = 0; i < targets.length; ++i) { 725 var condition = this._breakpoint.condition();
619 var scriptFile = uiSourceCode.scriptFileForTarget(targets[i]); 726 if (debuggerModelLocation)
620 if (scriptFile && scriptFile.hasDivergedFromVM()) 727 this.target().debuggerModel.setBreakpointByScriptLocation(debuggerMo delLocation, condition, this._didSetBreakpointInDebugger.bind(this));
621 return; 728 else if (uiSourceCode.url)
622 } 729 this.target().debuggerModel.setBreakpointByURL(uiSourceCode.url, lin eNumber, columnNumber, condition, this._didSetBreakpointInDebugger.bind(this));
623 730 },
624 for (var i = 0; i < targets.length; ++i) { 731
625 var rawLocation = uiSourceCode.uiLocationToRawLocation(targets[i], t his._lineNumber, this._columnNumber); 732 /**
626 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.L ocation} */ (rawLocation); 733 * @param {?DebuggerAgent.BreakpointId} breakpointId
627 if (debuggerModelLocation) 734 * @param {!Array.<!WebInspector.DebuggerModel.Location>} locations
628 targets[i].debuggerModel.setBreakpointByScriptLocation(debuggerM odelLocation, this._condition, this._didSetBreakpointInDebugger.bind(this)); 735 */
629 else if (uiSourceCode.url)
630 targets[i].debuggerModel.setBreakpointByURL(uiSourceCode.url, th is._lineNumber, this._columnNumber, this._condition, this._didSetBreakpointInDeb ugger.bind(this));
631 }
632 },
633
634 /**
635 * @param {?DebuggerAgent.BreakpointId} breakpointId
636 * @param {!Array.<!WebInspector.DebuggerModel.Location>} locations
637 */
638 _didSetBreakpointInDebugger: function(breakpointId, locations) 736 _didSetBreakpointInDebugger: function(breakpointId, locations)
639 { 737 {
640 if (!breakpointId) { 738 if (!breakpointId) {
641 this.remove(true); 739 this._breakpoint.remove(true);
642 return; 740 return;
643 } 741 }
742
743 if (this._debuggerId)
744 this._removeFromDebugger(true);
644 745
645 this._debuggerId = breakpointId; 746 this._debuggerId = breakpointId;
646 this._breakpointManager._breakpointForDebuggerId[breakpointId] = this;
647
648 for (var i = 0; i < locations.length; ++i) 747 for (var i = 0; i < locations.length; ++i)
649 if (!this._addResolvedLocation(locations[i])) 748 if (!this._addResolvedLocation(locations[i]))
650 return; 749 return;
651 }, 750 },
652 751
653 _removeFromDebugger: function()
654 {
655 this._resetLocations();
656 if (!this._debuggerId)
657 return;
658 var barrier = new CallbackBarrier();
659 this._breakpointManager._targetManager.targets().forEach(function(target ){target.debuggerModel.removeBreakpoint(this._debuggerId, barrier.createCallback ())}, this);
660 barrier.callWhenDone(this._didRemoveFromDebugger.bind(this));
661 },
662
663 _didRemoveFromDebugger: function() 752 _didRemoveFromDebugger: function()
664 { 753 {
665 delete this._breakpointManager._breakpointForDebuggerId[this._debuggerId ];
666 delete this._debuggerId; 754 delete this._debuggerId;
667 }, 755 },
668 756
669 _resetLocations: function() 757 /**
670 { 758 * @param {!DebuggerAgent.BreakpointId} breakpointId
671 for (var stringifiedLocation in this._uiLocations) { 759 * @param {!WebInspector.DebuggerModel.Location} location
672 var uiLocation = this._uiLocations[stringifiedLocation]; 760 */
673 if (this._numberOfDebuggerLocationForUILocation[uiLocation.id()]) { 761 _breakpointResolved: function(breakpointId, location)
674 this._breakpointManager._uiLocationRemoved(this, uiLocation); 762 {
675 delete this._numberOfDebuggerLocationForUILocation[uiLocation.id ()]; 763 if (this._debuggerId === breakpointId)
676 } 764 this._addResolvedLocation(location);
677 } 765 },
678 if (this._uiLocations[""]) 766
679 this._breakpointManager._uiLocationRemoved(this, this._uiLocations[" "]); 767 /**
680 for (var i = 0; i < this._liveLocations.length; ++i) 768 * @param {!WebInspector.DebuggerModel.Location} location
681 this._liveLocations[i].dispose(); 769 * @param {!WebInspector.UILocation} uiLocation
682 this._liveLocations = []; 770 */
683 this._uiLocations = {}; 771 _locationUpdated: function(location, uiLocation)
684 this._numberOfDebuggerLocationForUILocation = {}; 772 {
685 }, 773 var oldUILocation = this._uiLocations[location.id()] || null;
686 774 this._uiLocations[location.id()] = uiLocation;
687 /** 775 this._breakpoint._replaceUILocation(oldUILocation, uiLocation);
688 * @return {string} 776 },
689 */ 777
690 _breakpointStorageId: function() 778 /**
691 { 779 * @param {!WebInspector.DebuggerModel.Location} location
692 return WebInspector.BreakpointManager._breakpointStorageId(this._sourceF ileId, this._lineNumber, this._columnNumber); 780 * @return {boolean}
693 }, 781 */
694 782 _addResolvedLocation: function(location)
695 _fakeBreakpointAtPrimaryLocation: function() 783 {
696 { 784 var script = location.script();
697 var uiSourceCode = this._breakpointManager._workspace.uiSourceCode(this. _projectId, this._path); 785 var uiLocation = script.rawLocationToUILocation(location.lineNumber, loc ation.columnNumber);
698 if (!uiSourceCode) 786 var breakpoint = this._breakpoint._breakpointManager.findBreakpoint(uiLo cation.uiSourceCode, uiLocation.lineNumber, uiLocation.columnNumber);
699 return; 787 if (breakpoint && breakpoint != this._breakpoint) {
700 var uiLocation = uiSourceCode.uiLocation(this._lineNumber, this._columnN umber); 788 // location clash
701 this._uiLocations[""] = uiLocation; 789 this._breakpoint.remove();
702 this._breakpointManager._uiLocationAdded(this, uiLocation); 790 return false;
703 } 791 }
792 this._liveLocations.push(location.createLiveLocation(this._locationUpdat ed.bind(this, location)));
793 return true;
794 },
795
796 __proto__: WebInspector.TargetAware.prototype
704 } 797 }
705 798
706 /** 799 /**
707 * @constructor 800 * @constructor
708 * @param {!WebInspector.BreakpointManager} breakpointManager 801 * @param {!WebInspector.BreakpointManager} breakpointManager
709 * @param {!WebInspector.Setting} setting 802 * @param {!WebInspector.Setting} setting
710 */ 803 */
711 WebInspector.BreakpointManager.Storage = function(breakpointManager, setting) 804 WebInspector.BreakpointManager.Storage = function(breakpointManager, setting)
712 { 805 {
713 this._breakpointManager = breakpointManager; 806 this._breakpointManager = breakpointManager;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 { 881 {
789 this.sourceFileId = breakpoint._sourceFileId; 882 this.sourceFileId = breakpoint._sourceFileId;
790 this.lineNumber = breakpoint.lineNumber(); 883 this.lineNumber = breakpoint.lineNumber();
791 this.columnNumber = breakpoint.columnNumber(); 884 this.columnNumber = breakpoint.columnNumber();
792 this.condition = breakpoint.condition(); 885 this.condition = breakpoint.condition();
793 this.enabled = breakpoint.enabled(); 886 this.enabled = breakpoint.enabled();
794 } 887 }
795 888
796 /** @type {!WebInspector.BreakpointManager} */ 889 /** @type {!WebInspector.BreakpointManager} */
797 WebInspector.breakpointManager; 890 WebInspector.breakpointManager;
OLDNEW
« no previous file with comments | « LayoutTests/inspector/sources/debugger/set-breakpoint.html ('k') | Source/devtools/front_end/sdk/Target.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698