Changeset 116789 in webkit


Ignore:
Timestamp:
May 11, 2012 11:31:41 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: extract PresentationConsoleMessageHelper from DebuggerPresentationModel.
https://bugs.webkit.org/show_bug.cgi?id=86229

Reviewed by Vsevolod Vlasov.

This change also starts tracking messages along with the live location changes.

Tested with script-formatter-console.html.

  • inspector/front-end/BreakpointManager.js:
  • inspector/front-end/DebuggerPresentationModel.js:

(WebInspector.DebuggerPresentationModel):
(WebInspector.DebuggerPresentationModel.prototype._parsedScriptSource):
(WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
(WebInspector.PresentationConsoleMessageHelper):
(WebInspector.PresentationConsoleMessageHelper.prototype._addPendingConsoleMessage):
(WebInspector.PresentationConsoleMessageHelper.prototype._parsedScriptSource):
(WebInspector.PresentationConsoleMessageHelper.prototype._debuggerReset):
(WebInspector.PresentationConsoleMessage):

  • inspector/front-end/JavaScriptSourceFrame.js:

(WebInspector.JavaScriptSourceFrame.prototype.populateLineGutterContextMenu):
(WebInspector.JavaScriptSourceFrame.prototype._consoleMessageAdded):
(WebInspector.JavaScriptSourceFrame.prototype._setBreakpoint):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/inspector/debugger/script-formatter-console-expected.txt

    r99405 r116789  
    66Running: testConsoleMessagesForFormattedScripts
    77script-formatter-console.html:10
     8Pre-format row message list:
     9["9"]
     10["9"]
    811script-formatter-console.html:13
     12Post-format row message list:
     13["12"]
     14["12"]
    915Debugger was disabled.
    1016
  • trunk/LayoutTests/inspector/debugger/script-formatter-console.html

    r116775 r116789  
    88function f1()
    99{
    10     console.log("Test message.");
     10    console.error("Test message.");
    1111}
    1212
     
    3131            {
    3232                dumpConsoleMessageURLs();
     33                InspectorTest.addResult("Pre-format row message list:");
     34                InspectorTest.addResult(JSON.stringify(Object.keys(sourceFrame._rowMessages)));
     35                InspectorTest.addResult(JSON.stringify(Object.keys(sourceFrame._messageBubbles)));
    3336                sourceFrame._uiSourceCode.setFormatted(true, didFormatLinkText);
    3437            }
     
    3740            {
    3841                dumpConsoleMessageURLs();
     42                InspectorTest.addResult("Post-format row message list:");
     43                InspectorTest.addResult(JSON.stringify(Object.keys(sourceFrame._rowMessages)));
     44                InspectorTest.addResult(JSON.stringify(Object.keys(sourceFrame._messageBubbles)));
    3945                next();
    4046            }
  • trunk/Source/WebCore/ChangeLog

    r116788 r116789  
     12012-05-11  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: extract PresentationConsoleMessageHelper from DebuggerPresentationModel.
     4        https://bugs.webkit.org/show_bug.cgi?id=86229
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        This change also starts tracking messages along with the live location changes.
     9
     10        Tested with script-formatter-console.html.
     11
     12        * inspector/front-end/BreakpointManager.js:
     13        * inspector/front-end/DebuggerPresentationModel.js:
     14        (WebInspector.DebuggerPresentationModel):
     15        (WebInspector.DebuggerPresentationModel.prototype._parsedScriptSource):
     16        (WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
     17        (WebInspector.PresentationConsoleMessageHelper):
     18        (WebInspector.PresentationConsoleMessageHelper.prototype._addPendingConsoleMessage):
     19        (WebInspector.PresentationConsoleMessageHelper.prototype._parsedScriptSource):
     20        (WebInspector.PresentationConsoleMessageHelper.prototype._debuggerReset):
     21        (WebInspector.PresentationConsoleMessage):
     22        * inspector/front-end/JavaScriptSourceFrame.js:
     23        (WebInspector.JavaScriptSourceFrame.prototype.populateLineGutterContextMenu):
     24        (WebInspector.JavaScriptSourceFrame.prototype._consoleMessageAdded):
     25        (WebInspector.JavaScriptSourceFrame.prototype._setBreakpoint):
     26
    1272012-05-11  Emil A Eklund  <eae@chromium.org>
    228
  • trunk/Source/WebCore/inspector/front-end/BreakpointManager.js

    r116775 r116789  
    499499    this.enabled = breakpoint.enabled();
    500500}
     501
     502/** @type {WebInspector.BreakpointManager} */
     503WebInspector.breakpointManager = null;
  • trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js

    r116780 r116789  
    3838    this._scriptMapping.addEventListener(WebInspector.MainScriptMapping.Events.UISourceCodeListChanged, this._handleUISourceCodeListChanged, this);
    3939
    40     this._pendingConsoleMessages = {};
    41     this._consoleMessageLiveLocations = [];
    42 
    4340    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
    44     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this._failedToParseScriptSource, this);
     41    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScriptSource, this);
    4542    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
    4643
    47     WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this);
    48     WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
    49 
    5044    new WebInspector.DebuggerPresentationModelResourceBinding(this);
     45    new WebInspector.PresentationConsoleMessageHelper();
    5146}
    5247
     
    5954WebInspector.DebuggerPresentationModel.prototype = {
    6055    /**
    61      * @param {DebuggerAgent.Location} rawLocation
    62      * @param {function(WebInspector.UILocation):(boolean|undefined)} updateDelegate
    63      * @return {WebInspector.LiveLocation}
    64      */
    65     createLiveLocation: function(rawLocation, updateDelegate)
    66     {
    67         var script = WebInspector.debuggerModel.scriptForId(rawLocation.scriptId);
    68         return script.createLiveLocation(rawLocation, updateDelegate);
    69     },
    70 
    71     /**
    7256     * @param {WebInspector.Event} event
    7357     */
     
    7660        var script = /** @type {WebInspector.Script} */ event.data;
    7761        this._scriptMapping.addScript(script);
    78         this._addPendingConsoleMessagesToScript(script);
    79     },
    80 
    81     /**
    82      * @param {WebInspector.Event} event
    83      */
    84     _failedToParseScriptSource: function(event)
    85     {
    86         this._parsedScriptSource(event);
    8762    },
    8863
     
    153128    },
    154129
     130    _debuggerReset: function()
     131    {
     132        this._scriptMapping.reset();
     133    }
     134}
     135
     136WebInspector.DebuggerPresentationModel.prototype.__proto__ = WebInspector.Object.prototype;
     137
     138/**
     139 * @constructor
     140 */
     141WebInspector.PresentationConsoleMessageHelper = function()
     142{
     143    this._pendingConsoleMessages = {};
     144    this._presentationConsoleMessages = [];
     145
     146    WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this);
     147    WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
     148
     149    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
     150    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScriptSource, this);
     151    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
     152}
     153
     154WebInspector.PresentationConsoleMessageHelper.prototype = {
    155155    /**
    156156     * @param {WebInspector.Event} event
     
    175175    _addConsoleMessageToScript: function(message, rawLocation)
    176176    {
    177         function updateLocation(uiLocation)
    178         {
    179             var presentationMessage = new WebInspector.PresentationConsoleMessage(uiLocation.uiSourceCode, uiLocation.lineNumber, message);
    180             uiLocation.uiSourceCode.consoleMessageAdded(presentationMessage);
    181         }
    182         var liveLocation = this.createLiveLocation(rawLocation, updateLocation.bind(this));
    183         this._consoleMessageLiveLocations.push(liveLocation);
     177        this._presentationConsoleMessages.push(new WebInspector.PresentationConsoleMessage(message, rawLocation));
    184178    },
    185179
     
    195189
    196190    /**
    197      * @param {WebInspector.Script} script
    198      */
    199     _addPendingConsoleMessagesToScript: function(script)
    200     {
     191     * @param {WebInspector.Event} event
     192     */
     193    _parsedScriptSource: function(event)
     194    {
     195        var script = /** @type {WebInspector.Script} */ event.data;
     196
    201197        var messages = this._pendingConsoleMessages[script.sourceURL];
    202198        if (!messages)
     
    222218    {
    223219        this._pendingConsoleMessages = {};
    224         for (var i = 0; i < this._consoleMessageLiveLocations.length; ++i)
    225             this._consoleMessageLiveLocations[i].dispose();
    226         this._consoleMessageLiveLocations = [];
    227         var uiSourceCodes = this.uiSourceCodes();
     220        for (var i = 0; i < this._presentationConsoleMessages.length; ++i)
     221            this._presentationConsoleMessages[i].dispose();
     222        this._presentationConsoleMessages = [];
     223        var uiSourceCodes = WebInspector.debuggerPresentationModel.uiSourceCodes();
    228224        for (var i = 0; i < uiSourceCodes.length; ++i)
    229225            uiSourceCodes[i].consoleMessagesCleared();
    230226    },
    231227
    232     /**
    233      * @param {WebInspector.UISourceCode} uiSourceCode
    234      * @param {number} lineNumber
    235      */
    236     continueToLine: function(uiSourceCode, lineNumber)
    237     {
    238         var rawLocation = uiSourceCode.uiLocationToRawLocation(lineNumber, 0);
    239         WebInspector.debuggerModel.continueToLocation(rawLocation);
    240     },
    241 
    242228    _debuggerReset: function()
    243229    {
    244         this._scriptMapping.reset();
    245230        this._pendingConsoleMessages = {};
    246         this._consoleMessageLiveLocations = [];
     231        this._presentationConsoleMessages = [];
    247232    }
    248233}
    249234
    250 WebInspector.DebuggerPresentationModel.prototype.__proto__ = WebInspector.Object.prototype;
    251 
    252235/**
    253236 * @constructor
    254  * @param {WebInspector.UISourceCode} uiSourceCode
    255  * @param {number} lineNumber
    256  * @param {WebInspector.ConsoleMessage} originalMessage
    257  */
    258 WebInspector.PresentationConsoleMessage = function(uiSourceCode, lineNumber, originalMessage)
     237 * @param {WebInspector.ConsoleMessage} message
     238 * @param {DebuggerAgent.Location} rawLocation
     239 */
     240WebInspector.PresentationConsoleMessage = function(message, rawLocation)
    259241{
    260     this.uiSourceCode = uiSourceCode;
    261     this.lineNumber = lineNumber;
    262     this.originalMessage = originalMessage;
     242    this.originalMessage = message;
     243    this._liveLocation = WebInspector.debuggerModel.createLiveLocation(rawLocation, this._updateLocation.bind(this));
     244}
     245
     246WebInspector.PresentationConsoleMessage.prototype = {
     247    /**
     248     * @param {WebInspector.UILocation} uiLocation
     249     */
     250    _updateLocation: function(uiLocation)
     251    {
     252        if (this._uiLocation)
     253            this._uiLocation.uiSourceCode.consoleMessageRemoved(this);
     254        this._uiLocation = uiLocation;
     255        this._uiLocation.uiSourceCode.consoleMessageAdded(this);
     256    },
     257
     258    get lineNumber()
     259    {
     260        return this._uiLocation.lineNumber;
     261    },
     262
     263    dispose: function()
     264    {
     265        this._liveLocation.dispose();
     266    }
    263267}
    264268
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSource.js

    r116780 r116789  
    4141    WebInspector.UISourceCode.call(this, id, url, contentProvider, sourceMapping);
    4242
    43     /**
    44      * @type {Array.<WebInspector.PresentationConsoleMessage>}
    45      */
    46     this._consoleMessages = [];
    4743    this._formatterMapping = new WebInspector.IdentityFormatterSourceMapping();
    4844    // FIXME: postpone breakpoints restore to after the mapping has been established.
     
    5450
    5551WebInspector.JavaScriptSource.prototype = {
    56     /**
    57      * @return {Array.<WebInspector.PresentationConsoleMessage>}
    58      */
    59     consoleMessages: function()
    60     {
    61         return this._consoleMessages;
    62     },
    63 
    64     /**
    65      * @param {WebInspector.PresentationConsoleMessage} message
    66      */
    67     consoleMessageAdded: function(message)
    68     {
    69         this._consoleMessages.push(message);
    70         this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessageAdded, message);
    71     },
    72 
    73     consoleMessagesCleared: function()
    74     {
    75         this._consoleMessages = [];
    76         this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessagesCleared);
    77     },
    78 
    7952    /**
    8053     * @param {?string} content
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSourceFrame.js

    r116780 r116789  
    6060    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ContentChanged, this._onContentChanged, this);
    6161    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessageAdded, this._consoleMessageAdded, this);
     62    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessageRemoved, this._consoleMessageRemoved, this);
    6263    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessagesCleared, this._consoleMessagesCleared, this);
    6364}
     
    143144        } else {
    144145            // This row has a breakpoint, we want to show edit and remove breakpoint, and either disable or enable.
    145             contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove breakpoint" : "Remove Breakpoint"), breakpoint.remove.bind(this));
     146            contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove breakpoint" : "Remove Breakpoint"), breakpoint.remove.bind(breakpoint));
    146147            contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Edit breakpoint…" : "Edit Breakpoint…"), this._editBreakpointCondition.bind(this, lineNumber, breakpoint));
    147148            if (breakpoint.enabled())
     
    521522    _consoleMessageAdded: function(event)
    522523    {
    523         var message = event.data;
     524        var message = /** @type {WebInspector.PresentationConsoleMessage} */ event.data;
    524525        if (this.loaded)
    525526            this.addMessageToSource(message.lineNumber, message.originalMessage);
     527    },
     528
     529    _consoleMessageRemoved: function(event)
     530    {
     531        var message = /** @type {WebInspector.PresentationConsoleMessage} */ event.data;
     532        if (this.loaded)
     533            this.removeMessageFromSource(message.lineNumber, message.originalMessage);
    526534    },
    527535
     
    564572    _continueToLine: function(lineNumber)
    565573    {
    566         this._model.continueToLine(this._uiSourceCode, lineNumber);
     574        var rawLocation = this._uiSourceCode.uiLocationToRawLocation(lineNumber, 0);
     575        WebInspector.debuggerModel.continueToLocation(rawLocation);
    567576    },
    568577
  • trunk/Source/WebCore/inspector/front-end/SourceFrame.js

    r115813 r116789  
    474474    },
    475475
     476    removeMessageFromSource: function(lineNumber, msg)
     477    {
     478        if (lineNumber >= this._textModel.linesCount)
     479            lineNumber = this._textModel.linesCount - 1;
     480        if (lineNumber < 0)
     481            lineNumber = 0;
     482
     483        var rowMessages = this._rowMessages[lineNumber];
     484        for (var i = 0; rowMessages && i < rowMessages.length; ++i) {
     485            var rowMessage = rowMessages[i];
     486            if (rowMessage.consoleMessage !== msg)
     487                continue;
     488
     489            var messageLineElement = rowMessage.element;
     490            var messageBubbleElement = messageLineElement.parentElement;
     491            messageBubbleElement.removeChild(messageLineElement);
     492            rowMessages.remove(rowMessage);
     493            if (!rowMessages.length)
     494                delete this._rowMessages[lineNumber];
     495            if (!messageBubbleElement.childElementCount) {
     496                this._textViewer.removeDecoration(lineNumber, messageBubbleElement);
     497                delete this._messageBubbles[lineNumber];
     498            }
     499            break;
     500        }
     501    },
     502
    476503    populateLineGutterContextMenu: function(contextMenu, lineNumber)
    477504    {
  • trunk/Source/WebCore/inspector/front-end/UISourceCode.js

    r116775 r116789  
    5252    this._requestContentCallbacks = [];
    5353    this._liveLocations = [];
     54    /**
     55     * @type {Array.<WebInspector.PresentationConsoleMessage>}
     56     */
     57    this._consoleMessages = [];
    5458}
    5559
     
    5761    ContentChanged: "ContentChanged",
    5862    ConsoleMessageAdded: "ConsoleMessageAdded",
     63    ConsoleMessageRemoved: "ConsoleMessageRemoved",
    5964    ConsoleMessagesCleared: "ConsoleMessagesCleared"
    6065}
     
    207212     * @return {Array.<WebInspector.PresentationConsoleMessage>}
    208213     */
    209     consoleMessages: function() {}
     214    consoleMessages: function()
     215    {
     216        return this._consoleMessages;
     217    },
     218
     219    /**
     220     * @param {WebInspector.PresentationConsoleMessage} message
     221     */
     222    consoleMessageAdded: function(message)
     223    {
     224        this._consoleMessages.push(message);
     225        this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessageAdded, message);
     226    },
     227
     228    /**
     229     * @param {WebInspector.PresentationConsoleMessage} message
     230     */
     231    consoleMessageRemoved: function(message)
     232    {
     233        this._consoleMessages.remove(message);
     234        this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessageRemoved, message);
     235    },
     236
     237    consoleMessagesCleared: function()
     238    {
     239        this._consoleMessages = [];
     240        this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessagesCleared);
     241    }
    210242}
    211243
Note: See TracChangeset for help on using the changeset viewer.