Changeset 92598 in webkit


Ignore:
Timestamp:
Aug 8, 2011 8:50:36 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

Web Inspector: refactor links creation.
https://bugs.webkit.org/show_bug.cgi?id=65612

Reviewed by Pavel Feldman.

No new tests - it is refactoring, modified code covered by script-formatter.html test.

  • inspector/front-end/ConsoleView.js:

(WebInspector.ConsoleMessage.prototype._formatMessage):
(WebInspector.ConsoleMessage.prototype._linkifyLocation):
(WebInspector.ConsoleMessage.prototype._linkifyCallFrame):
(WebInspector.ConsoleMessage.prototype._populateStackTraceTreeElement):

  • inspector/front-end/DebuggerPresentationModel.js:

(WebInspector.DebuggerPresentationModel):
(WebInspector.DebuggerPresentationModel.prototype.addSourceMappingListener):
(WebInspector.DebuggerPresentationModel.prototype.removeSourceMappingListener):
(WebInspector.DebuggerPresentationModel.prototype.linkifyLocation.updateAnchor.didGetLocation):
(WebInspector.DebuggerPresentationModel.prototype.linkifyLocation.updateAnchor):
(WebInspector.DebuggerPresentationModel.prototype.linkifyLocation):
(WebInspector.DebuggerPresentationModel.prototype.setFormatSourceFiles):
(WebInspector.DebuggerPresentationModel.prototype._sourceFileForScript):
(WebInspector.DebuggerPresentationModel.prototype._debuggerReset):

  • inspector/front-end/EventListenersSidebarPane.js:
  • inspector/front-end/NetworkPanel.js:

(WebInspector.NetworkDataGridNode.prototype._refreshInitiatorCell):

  • inspector/front-end/Panel.js:
  • inspector/front-end/ProfileDataGridTree.js:

(WebInspector.ProfileDataGridNode.prototype.createCell):

  • inspector/front-end/ScriptsPanel.js:

(WebInspector.ScriptsPanel.prototype._folderAndDisplayNameForScriptURL):

  • inspector/front-end/StylesSidebarPane.js:

(WebInspector.StylePropertiesSection.linkifyUncopyable):
(WebInspector.StylePropertiesSection):

  • inspector/front-end/TimelinePanel.js:

(WebInspector.TimelinePanel.FormattedRecord.prototype._getRecordDetails):
(WebInspector.TimelinePanel.FormattedRecord.prototype._linkifyLocation):
(WebInspector.TimelinePanel.FormattedRecord.prototype._linkifyCallFrame):
(WebInspector.TimelinePanel.PopupContentHelper.prototype._appendLinkRow):
(WebInspector.TimelinePanel.PopupContentHelper.prototype._appendStackTrace):

  • inspector/front-end/inspector.js:

(WebInspector._showSettingsScreen):
(WebInspector.formatLinkText):
(WebInspector.linkifyResourceAsNode):

Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r92596 r92598  
     12011-08-08  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Web Inspector: refactor links creation.
     4        https://bugs.webkit.org/show_bug.cgi?id=65612
     5
     6        Reviewed by Pavel Feldman.
     7
     8        No new tests - it is refactoring, modified code covered by script-formatter.html test.
     9
     10        * inspector/front-end/ConsoleView.js:
     11        (WebInspector.ConsoleMessage.prototype._formatMessage):
     12        (WebInspector.ConsoleMessage.prototype._linkifyLocation):
     13        (WebInspector.ConsoleMessage.prototype._linkifyCallFrame):
     14        (WebInspector.ConsoleMessage.prototype._populateStackTraceTreeElement):
     15        * inspector/front-end/DebuggerPresentationModel.js:
     16        (WebInspector.DebuggerPresentationModel):
     17        (WebInspector.DebuggerPresentationModel.prototype.addSourceMappingListener):
     18        (WebInspector.DebuggerPresentationModel.prototype.removeSourceMappingListener):
     19        (WebInspector.DebuggerPresentationModel.prototype.linkifyLocation.updateAnchor.didGetLocation):
     20        (WebInspector.DebuggerPresentationModel.prototype.linkifyLocation.updateAnchor):
     21        (WebInspector.DebuggerPresentationModel.prototype.linkifyLocation):
     22        (WebInspector.DebuggerPresentationModel.prototype.setFormatSourceFiles):
     23        (WebInspector.DebuggerPresentationModel.prototype._sourceFileForScript):
     24        (WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
     25        * inspector/front-end/EventListenersSidebarPane.js:
     26        * inspector/front-end/NetworkPanel.js:
     27        (WebInspector.NetworkDataGridNode.prototype._refreshInitiatorCell):
     28        * inspector/front-end/Panel.js:
     29        * inspector/front-end/ProfileDataGridTree.js:
     30        (WebInspector.ProfileDataGridNode.prototype.createCell):
     31        * inspector/front-end/ScriptsPanel.js:
     32        (WebInspector.ScriptsPanel.prototype._folderAndDisplayNameForScriptURL):
     33        * inspector/front-end/StylesSidebarPane.js:
     34        (WebInspector.StylePropertiesSection.linkifyUncopyable):
     35        (WebInspector.StylePropertiesSection):
     36        * inspector/front-end/TimelinePanel.js:
     37        (WebInspector.TimelinePanel.FormattedRecord.prototype._getRecordDetails):
     38        (WebInspector.TimelinePanel.FormattedRecord.prototype._linkifyLocation):
     39        (WebInspector.TimelinePanel.FormattedRecord.prototype._linkifyCallFrame):
     40        (WebInspector.TimelinePanel.PopupContentHelper.prototype._appendLinkRow):
     41        (WebInspector.TimelinePanel.PopupContentHelper.prototype._appendStackTrace):
     42        * inspector/front-end/inspector.js:
     43        (WebInspector._showSettingsScreen):
     44        (WebInspector.formatLinkText):
     45        (WebInspector.linkifyResourceAsNode):
     46
    1472011-08-08  Andrew Wason  <rectalogic@rectalogic.com>
    248
  • trunk/Source/WebCore/inspector/front-end/ConsoleView.js

    r92278 r92598  
    741741        return this._format(output, output.subtype && output.subtype === "array");
    742742    },
    743    
     743
    744744    get scrollLeft()
    745745    {
     
    845845
    846846        if (this._stackTrace && this._stackTrace.length && this._stackTrace[0].url) {
    847             var urlElement = WebInspector.linkifyCallFrameAsNode(this._stackTrace[0], "console-message-url");
     847            var urlElement = this._linkifyCallFrame(this._stackTrace[0]);
    848848            this._formattedMessage.appendChild(urlElement);
    849849        } else if (this.url && this.url !== "undefined") {
    850             var urlElement = WebInspector.linkifyResourceAsNode(this.url, "scripts", this.line, "console-message-url");
     850            var urlElement = this._linkifyLocation(this.url, this.line, 0);
    851851            this._formattedMessage.appendChild(urlElement);
    852852        }
     
    881881    },
    882882
     883    _linkifyLocation: function(url, lineNumber, columnNumber)
     884    {
     885        // FIXME(62725): stack trace line/column numbers are one-based.
     886        lineNumber = lineNumber ? lineNumber - 1 : undefined;
     887        columnNumber = columnNumber ? columnNumber - 1 : 0;
     888        return WebInspector.debuggerPresentationModel.linkifyLocation(url, lineNumber, columnNumber, "console-message-url");
     889    },
     890
     891    _linkifyCallFrame: function(callFrame)
     892    {
     893        return this._linkifyLocation(callFrame.url, callFrame.lineNumber, callFrame.columnNumber);
     894    },
     895
    883896    isErrorOrWarning: function()
    884897    {
     
    10451058
    10461059            if (frame.url) {
    1047                 var urlElement = WebInspector.linkifyCallFrameAsNode(frame, "console-message-url");
     1060                var urlElement = this._linkifyCallFrame(frame);
    10481061                content.appendChild(urlElement);
    10491062            }
  • trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js

    r92369 r92598  
    3535    this._sourceFiles = {};
    3636    this._messages = [];
    37     this._anchors = [];
     37    // FIXME: move this to RawSourceCode when it's not re-created in pretty-print mode.
     38    this._sourceMappingListeners = [];
    3839    this._breakpointsByDebuggerId = {};
    3940    this._breakpointsWithoutSourceFile = {};
     
    120121    },
    121122
    122     registerAnchor: function(sourceURL, scriptId, lineNumber, columnNumber, updateHandler)
    123     {
    124         var anchor = { sourceURL: sourceURL, scriptId: scriptId, lineNumber: lineNumber, columnNumber: columnNumber, updateHandler: updateHandler };
    125         this._anchors.push(anchor);
    126         this._updateAnchor(anchor);
    127     },
    128 
    129     _updateAnchor: function(anchor)
    130     {
    131         var sourceFile = this._sourceFileForScript(anchor.sourceURL, anchor.scriptId);
    132         if (!sourceFile)
    133             return;
    134 
    135         this._scriptLocationToUILocation(anchor.sourceURL, anchor.scriptId, anchor.lineNumber, anchor.columnNumber, anchor.updateHandler);
     123    addSourceMappingListener: function(sourceURL, sourceId, listener)
     124    {
     125        this._sourceMappingListeners.push(listener);
     126    },
     127
     128    removeSourceMappingListener: function(sourceURL, sourceId, listener)
     129    {
     130        // FIXME: implement this.
     131    },
     132
     133    linkifyLocation: function(sourceURL, lineNumber, columnNumber, classes)
     134    {
     135        var linkText = WebInspector.formatLinkText(sourceURL, lineNumber);
     136        var anchor = WebInspector.linkifyURLAsNode(sourceURL, linkText, classes, false);
     137
     138        var sourceFile = this._sourceFileForScript(sourceURL);
     139        if (!sourceFile) {
     140            anchor.setAttribute("preferred_panel", "resources");
     141            anchor.setAttribute("line_number", lineNumber);
     142            return anchor;
     143        }
     144
     145        function updateAnchor()
     146        {
     147            function didGetLocation(sourceFileId, lineNumber)
     148            {
     149                anchor.textContent = WebInspector.formatLinkText(sourceFile.url, lineNumber);
     150                anchor.setAttribute("preferred_panel", "scripts");
     151                anchor.setAttribute("source_file_id", sourceFileId);
     152                anchor.setAttribute("line_number", lineNumber);
     153            }
     154            this._scriptLocationToUILocation(sourceURL, null, lineNumber, columnNumber, didGetLocation.bind(this));
     155        }
     156        updateAnchor.call(this);
     157        this.addSourceMappingListener(sourceURL, null, updateAnchor.bind(this));
     158        return anchor;
    136159    },
    137160
     
    282305            this._addConsoleMessage(messages[i]);
    283306
    284         for (var i = 0; i < this._anchors.length; ++i)
    285             this._updateAnchor(this._anchors[i]);
     307        // FIXME: move this to RawSourceCode.
     308        for (var i = 0; i < this._sourceMappingListeners.length; ++i)
     309            this._sourceMappingListeners[i]();
    286310
    287311        if (WebInspector.debuggerModel.callFrames)
     
    617641    _sourceFileForScript: function(sourceURL, scriptId)
    618642    {
    619         if (!sourceURL)
    620             sourceURL = WebInspector.debuggerModel.scriptForSourceID(scriptId).sourceURL;
     643        if (!sourceURL) {
     644            var script = WebInspector.debuggerModel.scriptForSourceID(scriptId);
     645            if (!script)
     646                return;
     647            sourceURL = script.sourceURL;
     648        }
    621649        return this._sourceFiles[this._createSourceFileId(sourceURL, scriptId)];
    622650    },
     
    659687    {
    660688        this._reset();
    661         this._anchors = [];
     689        this._sourceMappingListeners = [];
    662690        this._presentationCallFrames = [];
    663691        this._selectedCallFrameIndex = 0;
  • trunk/Source/WebCore/inspector/front-end/EventListenersSidebarPane.js

    r92369 r92598  
    237237        if (this.eventListener.location) {
    238238            this.subtitleElement.removeChildren();
    239             this.subtitleElement.appendChild(WebInspector.linkifyResourceAsNode(this.eventListener.location.scriptId, "scripts", this.eventListener.location.lineNumber));
     239            // FIXME(62725): eventListener.location should be a debugger Location.
     240            var url = this.eventListener.location.scriptId;
     241            var lineNumber = this.eventListener.location.lineNumber - 1;
     242            var columnNumber = 0;
     243            var urlElement = WebInspector.debuggerPresentationModel.linkifyLocation(url, lineNumber, columnNumber);
     244            this.subtitleElement.appendChild(urlElement);
    240245        } else {
    241246            var match = this.eventListener.handlerBody.match(/function ([^\(]+?)\(/);
  • trunk/Source/WebCore/inspector/front-end/NetworkPanel.js

    r92213 r92598  
    19781978                }
    19791979                this._initiatorCell.title = topFrame.url + ":" + topFrame.lineNumber;
    1980                 this._initiatorCell.appendChild(WebInspector.linkifyResourceAsNode(topFrame.url, "scripts", topFrame.lineNumber));
     1980                var urlElement = WebInspector.debuggerPresentationModel.linkifyLocation(topFrame.url, topFrame.lineNumber - 1, 0);
     1981                this._initiatorCell.appendChild(urlElement);
    19811982                this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Script"));
    19821983            } else { // initiator.type === "parser"
    19831984                this._initiatorCell.title = initiator.url + ":" + initiator.lineNumber;
    1984                 this._initiatorCell.appendChild(WebInspector.linkifyResourceAsNode(initiator.url, "resources", initiator.lineNumber));
     1985                this._initiatorCell.appendChild(WebInspector.linkifyResourceAsNode(initiator.url, initiator.lineNumber - 1));
    19851986                this._appendSubtitle(this._initiatorCell, WebInspector.UIString("Parser"));
    19861987            }
  • trunk/Source/WebCore/inspector/front-end/Panel.js

    r91902 r92598  
    396396    },
    397397
    398     createAnchor: function(url, lineNumber, columnNumber, classes, tooltipText)
    399     {
    400         var linkText = this.formatAnchorText(url, lineNumber);
    401         var anchor = WebInspector.linkifyURLAsNode(url, linkText, classes, false, tooltipText);
    402         anchor.setAttribute("preferred_panel", "resources");
    403         if (lineNumber !== undefined)
    404             anchor.setAttribute("line_number", lineNumber);
    405         return anchor;
    406     },
    407 
    408     formatAnchorText: function(url, lineNumber)
    409     {
    410         var text = WebInspector.displayNameForURL(url);
    411         if (lineNumber !== undefined)
    412             text += ":" + (lineNumber + 1);
    413         return text;
    414     },
    415 
    416398    canShowAnchorLocation: function(anchor)
    417399    {
  • trunk/Source/WebCore/inspector/front-end/ProfileDataGridTree.js

    r75714 r92598  
    9797
    9898        if (this.profileNode.url) {
    99             var lineNumber;
    100             if (this.profileNode.lineNumber > 0)
    101                 lineNumber = this.profileNode.lineNumber;
    102             var urlElement = WebInspector.linkifyResourceAsNode(this.profileNode.url, "scripts", lineNumber, "profile-node-file");
     99            // FIXME(62725): profileNode should reference a debugger location.
     100            var lineNumber = this.profileNode.lineNumber ? this.profileNode.lineNumber - 1 : 0;
     101            var urlElement = WebInspector.debuggerPresentationModel.linkifyLocation(this.profileNode.url, lineNumber, 0, "profile-node-file");
    103102            cell.insertBefore(urlElement, cell.firstChild);
    104103        }
  • trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js

    r92300 r92598  
    2929    WebInspector.Panel.call(this, "scripts");
    3030
    31     this._presentationModel = new WebInspector.DebuggerPresentationModel();
     31    this._presentationModel = WebInspector.debuggerPresentationModel;
    3232
    3333    this.registerShortcuts();
     
    325325        if (folderName.length > 80)
    326326            folderName = "\u2026" + folderName.substring(folderName.length - 80);
    327  
     327
    328328        return { folderName: folderName, displayName: displayName};
    329329    },
     
    546546    },
    547547
    548     createAnchor: function(url, lineNumber, columnNumber, classes, tooltipText)
    549     {
    550         var anchor = WebInspector.Panel.prototype.createAnchor.call(this, url, lineNumber, columnNumber, classes, tooltipText);
    551         if (lineNumber !== undefined)
    552             this._presentationModel.registerAnchor(url, null, lineNumber, columnNumber, this._updateAnchor.bind(this, anchor));
    553         return anchor;
    554     },
    555 
    556548    canShowAnchorLocation: function(anchor)
    557549    {
     
    562554    {
    563555        this._showSourceLine(anchor.getAttribute("source_file_id"), parseInt(anchor.getAttribute("line_number")));
    564     },
    565 
    566     _updateAnchor: function(anchor, sourceFileId, lineNumber)
    567     {
    568         var sourceFile = this._presentationModel.sourceFile(sourceFileId);
    569         var url = sourceFile.url || WebInspector.UIString("(program)");
    570         anchor.textContent = this.formatAnchorText(url, lineNumber)
    571         // Used for showing anchor location.
    572         anchor.setAttribute("preferred_panel", "scripts");
    573         anchor.setAttribute("source_file_id", sourceFileId);
    574         anchor.setAttribute("line_number", lineNumber);
    575556    },
    576557
  • trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js

    r92192 r92598  
    837837    function linkifyUncopyable(url, line)
    838838    {
    839         var link = WebInspector.linkifyResourceAsNode(url, "resources", line + 1);
     839        var link = WebInspector.linkifyResourceAsNode(url, line);
    840840        return link;
    841841    }
  • trunk/Source/WebCore/inspector/front-end/TimelinePanel.js

    r92284 r92598  
    357357        this._scheduleRefresh(true);
    358358    },
    359    
     359
    360360    _garbageCollectButtonClicked: function()
    361361    {
     
    11161116                return WebInspector.UIString("%s collected", Number.bytesToString(this.data.usedHeapSizeDelta));
    11171117            case WebInspector.TimelineAgent.RecordType.TimerFire:
    1118                 return this.scriptName ? WebInspector.linkifyResourceAsNode(this.scriptName, "scripts", this.scriptLine, "", "") : this.data.timerId;
     1118                return this.scriptName ? this._linkifyLocation(this.scriptName, this.scriptLine, 0) : this.data.timerId;
    11191119            case WebInspector.TimelineAgent.RecordType.FunctionCall:
    1120                 return this.scriptName ? WebInspector.linkifyResourceAsNode(this.scriptName, "scripts", this.scriptLine, "", "") : null;
     1120                return this.scriptName ? this._linkifyLocation(this.scriptName, this.scriptLine, 0) : null;
    11211121            case WebInspector.TimelineAgent.RecordType.EventDispatch:
    11221122                return this.data ? this.data.type : null;
     
    11251125            case WebInspector.TimelineAgent.RecordType.TimerInstall:
    11261126            case WebInspector.TimelineAgent.RecordType.TimerRemove:
    1127                 return this.stackTrace ? WebInspector.linkifyCallFrameAsNode(this.stackTrace[0], "") : this.data.timerId;
     1127                return this.stackTrace ? this._linkifyCallFrame(this.stackTrace[0]) : this.data.timerId;
    11281128            case WebInspector.TimelineAgent.RecordType.ParseHTML:
    11291129            case WebInspector.TimelineAgent.RecordType.RecalculateStyles:
    1130                 return this.stackTrace ? WebInspector.linkifyCallFrameAsNode(this.stackTrace[0], "") : null;
     1130                return this.stackTrace ? this._linkifyCallFrame(this.stackTrace[0]) : null;
    11311131            case WebInspector.TimelineAgent.RecordType.EvaluateScript:
    1132                 return this.url ? WebInspector.linkifyResourceAsNode(this.url, "scripts", this.data.lineNumber, "", "") : null;
     1132                return this.url ? this._linkifyLocation(this.url, this.data.lineNumber, 0) : null;
    11331133            case WebInspector.TimelineAgent.RecordType.XHRReadyStateChange:
    11341134            case WebInspector.TimelineAgent.RecordType.XHRLoad:
     
    11461146    },
    11471147
     1148    _linkifyLocation: function(url, lineNumber, columnNumber)
     1149    {
     1150        // FIXME(62725): stack trace line/column numbers are one-based.
     1151        lineNumber = lineNumber ? lineNumber - 1 : lineNumber;
     1152        columnNumber = columnNumber ? columnNumber - 1 : 0;
     1153        return WebInspector.debuggerPresentationModel.linkifyLocation(url, lineNumber, columnNumber, "timeline-details");
     1154    },
     1155
     1156    _linkifyCallFrame: function(callFrame)
     1157    {
     1158        return this._linkifyLocation(callFrame.url, callFrame.lineNumber, callFrame.columnNumber);
     1159    },
     1160
    11481161    _calculateAggregatedStats: function(categories)
    11491162    {
     
    12131226    _appendLinkRow: function(title, scriptName, scriptLine)
    12141227    {
    1215         var link = WebInspector.linkifyResourceAsNode(scriptName, "scripts", scriptLine, "timeline-details");
     1228        var link = WebInspector.TimelinePanel.FormattedRecord.prototype._linkifyLocation(scriptName, scriptLine, 0, "timeline-details");
    12161229        this._appendElementRow(title, link);
    12171230    },
     
    12281241            row.appendChild(this._createCell(" @ "));
    12291242            var linkCell = document.createElement("td");
    1230             linkCell.appendChild(WebInspector.linkifyCallFrameAsNode(stackFrame, "timeline-details"));
     1243            var urlElement = WebInspector.TimelinePanel.FormattedRecord.prototype._linkifyCallFrame(stackFrame);
     1244            linkCell.appendChild(urlElement);
    12311245            row.appendChild(linkCell);
    12321246            framesTable.appendChild(row);
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r92587 r92598  
    241241            delete this._settingsScreen;
    242242        }
    243        
     243
    244244        if (!this._settingsScreen) {
    245245            this._settingsScreen = new WebInspector.SettingsScreen();
     
    520520    this.cssModel = new WebInspector.CSSStyleModel();
    521521    this.debuggerModel = new WebInspector.DebuggerModel();
     522    this.debuggerPresentationModel = new WebInspector.DebuggerPresentationModel();
    522523
    523524    this.searchController = new WebInspector.SearchController();
     
    13231324}
    13241325
    1325 WebInspector.linkifyResourceAsNode = function(url, preferredPanel, oneBasedLineNumber, classes, tooltipText)
    1326 {
    1327     preferredPanel = preferredPanel || "scripts";
    1328     // FIXME(62725): stack trace line/column numbers are one-based.
    1329     var lineNumber = oneBasedLineNumber ? oneBasedLineNumber - 1 : undefined;
    1330     return this.panels[preferredPanel].createAnchor(url, lineNumber, 0, classes, tooltipText);
    1331 }
    1332 
    1333 WebInspector.linkifyCallFrameAsNode = function(callFrame, classes, tooltipText)
    1334 {
    1335     // FIXME(62725): stack trace line/column numbers are one-based.
    1336     var columnNumber = callFrame.columnNumber ? callFrame.columnNumber - 1 : 0;
    1337     return this.panels.scripts.createAnchor(callFrame.url, callFrame.lineNumber - 1, columnNumber, classes, tooltipText);
     1326WebInspector.formatLinkText = function(url, lineNumber)
     1327{
     1328    var text = WebInspector.displayNameForURL(url);
     1329    if (lineNumber !== undefined)
     1330        text += ":" + (lineNumber + 1);
     1331    return text;
     1332}
     1333
     1334WebInspector.linkifyResourceAsNode = function(url, lineNumber, classes, tooltipText)
     1335{
     1336    var linkText = this.formatLinkText(url, lineNumber);
     1337    var anchor = this.linkifyURLAsNode(url, linkText, classes, false, tooltipText);
     1338    anchor.setAttribute("preferred_panel", "resources");
     1339    anchor.setAttribute("line_number", lineNumber);
     1340    return anchor;
    13381341}
    13391342
Note: See TracChangeset for help on using the changeset viewer.