Changeset 93595 in webkit


Ignore:
Timestamp:
Aug 23, 2011 5:43:31 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

Web Inspector: switch to using BreakpointManager.
https://bugs.webkit.org/show_bug.cgi?id=66225

Reviewed by Pavel Feldman.

  • inspector/front-end/DebuggerPresentationModel.js:

(WebInspector.DebuggerPresentationModel):
(WebInspector.DebuggerPresentationModel.prototype._addScript.didCreateSourceMapping):
(WebInspector.DebuggerPresentationModel.prototype._addScript):
(WebInspector.DebuggerPresentationModel.prototype.setFormatSourceFiles):
(WebInspector.DebuggerPresentationModel.prototype.breakpointsForSourceFileId):
(WebInspector.DebuggerPresentationModel.prototype.setBreakpoint):
(WebInspector.DebuggerPresentationModel.prototype.setBreakpointEnabled):
(WebInspector.DebuggerPresentationModel.prototype.updateBreakpoint):
(WebInspector.DebuggerPresentationModel.prototype.removeBreakpoint):
(WebInspector.DebuggerPresentationModel.prototype.findBreakpoint):
(WebInspector.DebuggerPresentationModel.prototype._breakpointAdded):
(WebInspector.DebuggerPresentationModel.prototype._breakpointRemoved):
(WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
(WebInspector.PresentationBreakpoint.prototype.loadSnippet):

  • inspector/front-end/SourceFile.js:

(WebInspector.RawSourceCode):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r93594 r93595  
     12011-08-19  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Web Inspector: switch to using BreakpointManager.
     4        https://bugs.webkit.org/show_bug.cgi?id=66225
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/front-end/DebuggerPresentationModel.js:
     9        (WebInspector.DebuggerPresentationModel):
     10        (WebInspector.DebuggerPresentationModel.prototype._addScript.didCreateSourceMapping):
     11        (WebInspector.DebuggerPresentationModel.prototype._addScript):
     12        (WebInspector.DebuggerPresentationModel.prototype.setFormatSourceFiles):
     13        (WebInspector.DebuggerPresentationModel.prototype.breakpointsForSourceFileId):
     14        (WebInspector.DebuggerPresentationModel.prototype.setBreakpoint):
     15        (WebInspector.DebuggerPresentationModel.prototype.setBreakpointEnabled):
     16        (WebInspector.DebuggerPresentationModel.prototype.updateBreakpoint):
     17        (WebInspector.DebuggerPresentationModel.prototype.removeBreakpoint):
     18        (WebInspector.DebuggerPresentationModel.prototype.findBreakpoint):
     19        (WebInspector.DebuggerPresentationModel.prototype._breakpointAdded):
     20        (WebInspector.DebuggerPresentationModel.prototype._breakpointRemoved):
     21        (WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
     22        (WebInspector.PresentationBreakpoint.prototype.loadSnippet):
     23        * inspector/front-end/SourceFile.js:
     24        (WebInspector.RawSourceCode):
     25
    1262011-08-23  Steve Block  <steveblock@google.com>
    227
  • trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js

    r92838 r93595  
    3737    // FIXME: move this to RawSourceCode when it's not re-created in pretty-print mode.
    3838    this._sourceMappingListeners = [];
    39     this._breakpointsByDebuggerId = {};
    40     this._breakpointsWithoutSourceFile = {};
    4139
    4240    this._presentationCallFrames = [];
    4341    this._selectedCallFrameIndex = 0;
    4442
    45     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerWasEnabled, this._debuggerWasEnabled, this);
     43    this._breakpointManager = new WebInspector.BreakpointManager(WebInspector.settings.breakpoints, this._breakpointAdded.bind(this), this._breakpointRemoved.bind(this), WebInspector.debuggerModel);
     44
    4645    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
    4746    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this._failedToParseScriptSource, this);
    48     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointResolved, this._breakpointResolved, this);
    4947    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
    5048    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
     
    7068
    7169WebInspector.DebuggerPresentationModel.prototype = {
    72     _debuggerWasEnabled: function()
    73     {
    74         if (this._breakpointsRestored)
    75             return;
    76         this._restoreBreakpointsFromSettings();
    77         this._breakpointsRestored = true;
    78     },
    79 
    8070    sourceFile: function(sourceFileId)
    8171    {
     
    183173        sourceFile.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeReplaced, this._uiSourceCodeReplaced, this);
    184174
    185         this._restoreBreakpoints(sourceFile);
     175        function didCreateSourceMapping()
     176        {
     177            this._breakpointManager.uiSourceCodeAdded(sourceFile);
     178            var breakpoints = this._breakpointManager.breakpointsForUISourceCode(sourceFileId);
     179            for (var lineNumber in breakpoints) {
     180                var breakpoint = breakpoints[lineNumber];
     181                this._breakpointAdded(breakpoint.uiSourceCodeId, breakpoint.lineNumber, breakpoint.condition, breakpoint.enabled);
     182            }
     183        }
     184        // FIXME: force source formatting if needed. This will go away once formatting
     185        // is fully encapsulated in RawSourceCode class.
     186        sourceFile.createSourceMappingIfNeeded(didCreateSourceMapping.bind(this));
    186187
    187188        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.SourceFileAdded, sourceFile.uiSourceCode);
     
    198199        // FIXME: restore breakpoints in new source code (currently we just recreate everything when switching to pretty-print mode).
    199200        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.SourceFileReplaced, event.data);
    200     },
    201 
    202     _restoreBreakpoints: function(sourceFile)
    203     {
    204         var pendingBreakpoints = this._breakpointsWithoutSourceFile[sourceFile.id];
    205         if (!pendingBreakpoints)
    206             return;
    207         for (var lineNumber in pendingBreakpoints) {
    208             var breakpointData = pendingBreakpoints[lineNumber];
    209             if ("debuggerId" in breakpointData) {
    210                 var breakpoint = new WebInspector.PresentationBreakpoint(sourceFile, breakpointData.lineNumber, breakpointData.condition, breakpointData.enabled);
    211                 this._bindDebuggerId(breakpoint, breakpointData.debuggerId);
    212                 this._breakpointAdded(breakpoint);
    213             } else
    214                 this.setBreakpoint(sourceFile.id, breakpointData.lineNumber, breakpointData.condition, breakpointData.enabled, true);
    215         }
    216         delete this._breakpointsWithoutSourceFile[sourceFile.id];
    217201    },
    218202
     
    291275        this._formatSourceFiles = formatSourceFiles;
    292276
    293         for (var id in this._sourceFiles) {
    294             var sourceFile = this._sourceFiles[id];
    295             for (var line in sourceFile.breakpoints)
    296                 this._removeBreakpointFromDebugger(sourceFile.breakpoints[line]);
    297         }
    298 
    299         for (var id in this._breakpointsWithoutSourceFile) {
    300             var breakpoints = this._breakpointsWithoutSourceFile[id];
    301             for (var lineNumber in breakpoints)
    302                 this._removeBreakpointFromDebugger(breakpoints[lineNumber]);
    303         }
    304 
     277        this._breakpointManager.reset();
     278        this._sourceFiles = {};
    305279        var messages = this._messages;
    306         this._reset();
     280        this._messages = [];
    307281
    308282        var scripts = WebInspector.debuggerModel.scripts;
     
    370344    breakpointsForSourceFileId: function(sourceFileId)
    371345    {
    372         var sourceFile = this.sourceFile(sourceFileId);
    373         if (!sourceFile)
    374             return [];
    375         var breakpoints = [];
    376         for (var lineNumber in sourceFile.breakpoints)
    377             breakpoints.push(sourceFile.breakpoints[lineNumber]);
    378         return breakpoints;
    379     },
    380 
    381     setBreakpoint: function(sourceFileId, lineNumber, condition, enabled, dontSaveBreakpoints)
     346        var breakpointsMap = this._breakpointManager.breakpointsForUISourceCode(sourceFileId);
     347        var breakpointsList = [];
     348        for (var lineNumber in breakpointsMap)
     349            breakpointsList.push(breakpointsMap[lineNumber]);
     350        return breakpointsList;
     351    },
     352
     353    setBreakpoint: function(sourceFileId, lineNumber, condition, enabled)
     354    {
     355        this._breakpointManager.setBreakpoint(this._sourceFiles[sourceFileId], lineNumber, condition, enabled);
     356    },
     357
     358    setBreakpointEnabled: function(sourceFileId, lineNumber, enabled)
     359    {
     360        var breakpoint = this.findBreakpoint(sourceFileId, lineNumber);
     361        if (!breakpoint)
     362            return;
     363        this._breakpointManager.removeBreakpoint(sourceFileId, lineNumber);
     364        this._breakpointManager.setBreakpoint(this._sourceFiles[sourceFileId], lineNumber, breakpoint.condition, enabled);
     365    },
     366
     367    updateBreakpoint: function(sourceFileId, lineNumber, condition, enabled)
     368    {
     369        this._breakpointManager.removeBreakpoint(sourceFileId, lineNumber);
     370        this._breakpointManager.setBreakpoint(this._sourceFiles[sourceFileId], lineNumber, condition, enabled);
     371    },
     372
     373    removeBreakpoint: function(sourceFileId, lineNumber)
     374    {
     375        this._breakpointManager.removeBreakpoint(sourceFileId, lineNumber);
     376    },
     377
     378    findBreakpoint: function(sourceFileId, lineNumber)
     379    {
     380        return this._breakpointManager.breakpointsForUISourceCode(sourceFileId)[lineNumber];
     381    },
     382
     383    _breakpointAdded: function(sourceFileId, lineNumber, condition, enabled)
    382384    {
    383385        var sourceFile = this._sourceFiles[sourceFileId];
    384386        if (!sourceFile)
    385387            return;
    386 
    387         var breakpoint = new WebInspector.PresentationBreakpoint(sourceFile, lineNumber, condition, enabled);
    388         if (!enabled) {
    389             this._breakpointAdded(breakpoint);
    390             if (!dontSaveBreakpoints)
    391                 this._saveBreakpoints();
    392             return;
    393         }
    394 
    395         function callback()
    396         {
    397             this._breakpointAdded(breakpoint);
    398             if (!dontSaveBreakpoints)
    399                 this._saveBreakpoints();
    400         }
    401         this._setBreakpointInDebugger(breakpoint, callback.bind(this));
    402     },
    403 
    404     _setBreakpointInDebugger: function(breakpoint, callback)
    405     {
    406         function didSetBreakpoint(breakpointId, locations)
    407         {
    408             if (!breakpointId)
    409                 return;
    410 
    411             this._bindDebuggerId(breakpoint, breakpointId);
    412             breakpoint.location = locations[0];
    413             callback();
    414         }
    415 
    416         function didGetScriptLocation(location)
    417         {
    418             var script = WebInspector.debuggerModel.scriptForSourceID(location.scriptId);
    419             if (script.sourceURL)
    420                 WebInspector.debuggerModel.setBreakpoint(script.sourceURL, location.lineNumber, location.columnNumber, breakpoint.condition, didSetBreakpoint.bind(this));
    421             else {
    422                 location.scriptId = script.scriptId;
    423                 WebInspector.debuggerModel.setBreakpointBySourceId(location, breakpoint.condition, didSetBreakpoint.bind(this));
    424             }
    425         }
    426         this._uiLocationToScriptLocation(breakpoint.sourceFile.id, breakpoint.lineNumber, didGetScriptLocation.bind(this));
    427     },
    428 
    429     _removeBreakpointFromDebugger: function(breakpoint, callback)
    430     {
    431         if ("debuggerId" in breakpoint) {
    432             WebInspector.debuggerModel.removeBreakpoint(breakpoint.debuggerId);
    433             this._unbindDebuggerId(breakpoint);
    434         }
    435 
    436         if (callback)
    437             callback();
    438     },
    439 
    440     _bindDebuggerId: function(breakpoint, debuggerId)
    441     {
    442         breakpoint.debuggerId = debuggerId;
    443         this._breakpointsByDebuggerId[debuggerId] = breakpoint;
    444     },
    445 
    446     _unbindDebuggerId: function(breakpoint)
    447     {
    448         delete this._breakpointsByDebuggerId[breakpoint.debuggerId];
    449         delete breakpoint.debuggerId;
    450     },
    451 
    452     setBreakpointEnabled: function(sourceFileId, lineNumber, enabled)
    453     {
    454         var breakpoint = this.findBreakpoint(sourceFileId, lineNumber);
    455         if (!breakpoint)
    456             return;
    457 
    458         this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.BreakpointRemoved, breakpoint);
    459 
    460         breakpoint.enabled = enabled;
    461 
    462         function afterUpdate()
    463         {
    464             this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.BreakpointAdded, breakpoint);
    465             this._saveBreakpoints();
    466         }
    467 
    468         if (!enabled)
    469             this._removeBreakpointFromDebugger(breakpoint, afterUpdate.call(this));
    470         else
    471             this._setBreakpointInDebugger(breakpoint, afterUpdate.bind(this));
    472     },
    473 
    474     updateBreakpoint: function(sourceFileId, lineNumber, condition, enabled)
    475     {
    476         this.removeBreakpoint(sourceFileId, lineNumber);
    477         this.setBreakpoint(sourceFileId, lineNumber, condition, enabled);
    478     },
    479 
    480     removeBreakpoint: function(sourceFileId, lineNumber)
    481     {
    482         var breakpoint = this.findBreakpoint(sourceFileId, lineNumber);
    483         if (!breakpoint)
    484             return;
    485 
    486         function callback()
    487         {
    488             this._breakpointRemoved(breakpoint);
    489             this._saveBreakpoints();
    490         }
    491         this._removeBreakpointFromDebugger(breakpoint, callback.bind(this));
    492     },
    493 
    494     findBreakpoint: function(sourceFileId, lineNumber)
    495     {
    496         var sourceFile = this.sourceFile(sourceFileId);
    497         if (sourceFile)
    498             return sourceFile.breakpoints[lineNumber];
    499     },
    500 
    501     _breakpointAdded: function(breakpoint)
    502     {
    503         var sourceFile = breakpoint.sourceFile;
    504         if (!sourceFile)
    505             return;
    506 
    507         function updateSourceFileBreakpointsAndDispatchEvent()
    508         {
    509             var existingBreakpoint = this.findBreakpoint(sourceFile.id, breakpoint.lineNumber);
    510             if (existingBreakpoint) {
    511                 // We can't show more than one breakpoint on a single source file line.
    512                 this._removeBreakpointFromDebugger(breakpoint);
    513                 return;
    514             }
    515             sourceFile.breakpoints[breakpoint.lineNumber] = breakpoint;
    516             this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.BreakpointAdded, breakpoint);
    517         }
    518 
    519         function didGetUILocation(sourceFileId, lineNumber)
    520         {
    521             breakpoint.lineNumber = lineNumber;
    522             updateSourceFileBreakpointsAndDispatchEvent.call(this);
    523         }
    524         // Refine line number based on resolved location.
    525         if (breakpoint.location)
    526             this._scriptLocationToUILocation(null, breakpoint.location.scriptId, breakpoint.location.lineNumber, breakpoint.location.columnNumber, didGetUILocation.bind(this));
    527         else
    528             updateSourceFileBreakpointsAndDispatchEvent.call(this);
    529     },
    530 
    531     _breakpointRemoved: function(breakpoint)
    532     {
    533         var sourceFile = breakpoint.sourceFile;
    534         if (sourceFile.breakpoints[breakpoint.lineNumber] === breakpoint) {
    535             // There can already be a newer breakpoint;
    536             delete sourceFile.breakpoints[breakpoint.lineNumber];
    537             this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.BreakpointRemoved, breakpoint);
    538         }
    539     },
    540 
    541     _breakpointResolved: function(event)
    542     {
    543         var debuggerId = event.data.breakpointId;
    544         if (!(debuggerId in this._breakpointsByDebuggerId))
    545             return;
    546         var breakpoint = this._breakpointsByDebuggerId[debuggerId];
    547 
    548         this._breakpointRemoved(breakpoint);
    549         breakpoint.location = event.data.location;
    550         this._breakpointAdded(breakpoint);
    551     },
    552 
    553     _restoreBreakpointsFromSettings: function()
    554     {
    555         var breakpoints = WebInspector.settings.breakpoints.get();
    556         for (var i = 0; i < breakpoints.length; ++i) {
    557             var breakpointData = breakpoints[i];
    558             var sourceFileId = breakpointData.sourceFileId;
    559             if (!sourceFileId)
    560                 continue;
    561             var sourceFile = this._sourceFiles[sourceFileId];
    562             if (sourceFile) {
    563                 this.setBreakpoint(sourceFileId, breakpointData.lineNumber, breakpointData.condition, breakpointData.enabled);
    564                 continue;
    565             }
    566 
    567             // Add breakpoint once source file becomes available.
    568             var pendingBreakpoints = this._breakpointsWithoutSourceFile[sourceFileId];
    569             if (!pendingBreakpoints) {
    570                 pendingBreakpoints = {};
    571                 this._breakpointsWithoutSourceFile[sourceFileId] = pendingBreakpoints;
    572             }
    573             pendingBreakpoints[breakpointData.lineNumber] = breakpointData;
    574         }
    575     },
    576 
    577     _saveBreakpoints: function()
    578     {
    579         var serializedBreakpoints = [];
    580 
    581         // Store added breakpoints.
    582         for (var sourceFileId in this._sourceFiles) {
    583             var sourceFile = this._sourceFiles[sourceFileId];
    584             if (!sourceFile.url)
    585                 continue;
    586 
    587             for (var lineNumber in sourceFile.breakpoints)
    588                 serializedBreakpoints.push(sourceFile.breakpoints[lineNumber].serialize());
    589         }
    590 
    591         // Store not added breakpoints.
    592         for (var sourceFileId in this._breakpointsWithoutSourceFile) {
    593             var breakpoints = this._breakpointsWithoutSourceFile[sourceFileId];
    594             for (var lineNumber in breakpoints)
    595                 serializedBreakpoints.push(breakpoints[lineNumber]);
    596         }
    597 
    598         // Sanitize debugger ids.
    599         for (var i = 0; i < serializedBreakpoints.length; ++i) {
    600             var breakpoint = serializedBreakpoints[i];
    601             var breakpointCopy = {};
    602             for (var property in breakpoint) {
    603                 if (property !== "debuggerId")
    604                     breakpointCopy[property] = breakpoint[property];
    605             }
    606             serializedBreakpoints[i] = breakpointCopy;
    607         }
    608 
    609         WebInspector.settings.breakpoints.set(serializedBreakpoints);
     388        var presentationBreakpoint = new WebInspector.PresentationBreakpoint(sourceFile, lineNumber, condition, enabled);
     389        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.BreakpointAdded, presentationBreakpoint);
     390    },
     391
     392    _breakpointRemoved: function(sourceFileId, lineNumber)
     393    {
     394        this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.BreakpointRemoved, { sourceFileId: sourceFileId, lineNumber: lineNumber });
    610395    },
    611396
     
    673458    },
    674459
    675     _reset: function()
    676     {
    677         for (var id in this._sourceFiles) {
    678             var sourceFile = this._sourceFiles[id];
    679             for (var line in sourceFile.breakpoints) {
    680                 var breakpoints = this._breakpointsWithoutSourceFile[sourceFile.id];
    681                 if (!breakpoints) {
    682                     breakpoints = {};
    683                     this._breakpointsWithoutSourceFile[sourceFile.id] = breakpoints;
    684                 }
    685                 breakpoints[line] = sourceFile.breakpoints[line].serialize();
    686             }
    687         }
    688 
     460    _debuggerReset: function()
     461    {
    689462        this._sourceFiles = {};
    690463        this._messages = [];
    691         this._breakpointsByDebuggerId = {};
    692     },
    693 
    694     _debuggerReset: function()
    695     {
    696         this._reset();
    697464        this._sourceMappingListeners = [];
    698465        this._presentationCallFrames = [];
    699466        this._selectedCallFrameIndex = 0;
     467        this._breakpointManager.debuggerReset();
    700468    }
    701469}
     
    738506        }
    739507        this.sourceFile.requestContent(didRequestContent.bind(this));
    740     },
    741 
    742     serialize: function()
    743     {
    744         var serializedBreakpoint = {};
    745         serializedBreakpoint.sourceFileId = this.sourceFile.id;
    746         serializedBreakpoint.lineNumber = this.lineNumber;
    747         serializedBreakpoint.condition = this.condition;
    748         serializedBreakpoint.enabled = this.enabled;
    749         if ("debuggerId" in this)
    750             serializedBreakpoint.debuggerId = this.debuggerId;
    751         return serializedBreakpoint;
    752508    }
    753509}
  • trunk/Source/WebCore/inspector/front-end/ScriptFormatterWorker.js

    r86443 r93595  
    9595
    9696        var scriptContent = this._content.substring(this._position, cursor);
     97        this._mapping.original.push(this._position);
     98        this._mapping.formatted.push(this._formattedContent.length);
    9799        var formattedScriptContent = formatScript(scriptContent, this._mapping, this._position, this._formattedContent.length);
    98100
  • trunk/Source/WebCore/inspector/front-end/SourceFile.js

    r93501 r93595  
    4545    this.isContentScript = script.isContentScript;
    4646    this.messages = [];
    47     this.breakpoints = {};
    4847
    4948    if (this._hasPendingResource())
Note: See TracChangeset for help on using the changeset viewer.