Changeset 75937 in webkit


Ignore:
Timestamp:
Jan 17, 2011 6:13:43 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

2011-01-17 Pavel Podivilov <podivilov@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: refactoring: encapsulate lazy initialization of SourceFrame.
https://bugs.webkit.org/show_bug.cgi?id=51738

  • http/tests/inspector/debugger-test2.js: (initialize_DebuggerTest.InspectorTest.showScriptSource): (initialize_DebuggerTest.InspectorTest._showScriptSource):
  • inspector/debugger-pause-in-eval-script-expected.txt:
  • inspector/debugger-pause-in-eval-script.html:

2011-01-17 Pavel Podivilov <podivilov@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: refactoring: encapsulate lazy initialization of SourceFrame.
https://bugs.webkit.org/show_bug.cgi?id=51738

Extract content loading logic from SourceView and ScriptView to ContentProvider implementations.
Pass ContentProvider in SourceFrame constructor to allow SourceFrame manage it's lazy initialization.

  • inspector/front-end/ScriptView.js: (WebInspector.ScriptView): (WebInspector.SourceFrameContentProviderForScript): (WebInspector.SourceFrameContentProviderForScript.prototype.requestContent.didRequestSource): (WebInspector.SourceFrameContentProviderForScript.prototype.requestContent): (WebInspector.SourceFrameContentProviderForScript.prototype.scripts):
  • inspector/front-end/ScriptsPanel.js: (WebInspector.ScriptsPanel.prototype._addScript): (WebInspector.ScriptsPanel.prototype.sourceFrameForScript): (WebInspector.ScriptsPanel.prototype._sourceFrameForResource):
  • inspector/front-end/SourceFrame.js: (WebInspector.SourceFrame): (WebInspector.SourceFrame.prototype.set visible): (WebInspector.SourceFrame.prototype._createTextViewer): (WebInspector.SourceFrame.prototype._breakpointAdded): (WebInspector.SourceFrame.prototype._breakpoints): (WebInspector.SourceFrame.prototype._sourceIDForLine): (WebInspector.SourceFrame.prototype._sourceIDSet): (WebInspector.SourceFrameContentProvider): (WebInspector.SourceFrameContentProvider.prototype.requestContent): (WebInspector.SourceFrameContentProvider.prototype.scripts):
  • inspector/front-end/SourceView.js: (WebInspector.SourceView): (WebInspector.SourceView.prototype.show): (WebInspector.SourceView.prototype.resize): (WebInspector.SourceView.prototype.performSearch.didFindSearchMatches): (WebInspector.SourceView.prototype.performSearch): (WebInspector.SourceView.prototype.revealLine): (WebInspector.SourceView.prototype.highlightLine): (WebInspector.SourceView.prototype._jumpToSearchResult): (WebInspector.SourceFrameContentProviderForResource): (WebInspector.SourceFrameContentProviderForResource.prototype.requestContent): (WebInspector.SourceFrameContentProviderForResource.prototype.scripts):
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r75934 r75937  
     12011-01-17  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: refactoring: encapsulate lazy initialization of SourceFrame.
     6        https://bugs.webkit.org/show_bug.cgi?id=51738
     7
     8        * http/tests/inspector/debugger-test2.js:
     9        (initialize_DebuggerTest.InspectorTest.showScriptSource):
     10        (initialize_DebuggerTest.InspectorTest._showScriptSource):
     11        * inspector/debugger-pause-in-eval-script-expected.txt:
     12        * inspector/debugger-pause-in-eval-script.html:
     13
    1142011-01-17  John Knottenbelt  <jknotten@chromium.org>
    215
  • trunk/LayoutTests/http/tests/inspector/debugger-test2.js

    r75791 r75937  
    122122InspectorTest.showScriptSource = function(scriptName, callback)
    123123{
    124     if (InspectorTest._scriptsAreParsed([scriptName]))
    125         InspectorTest._showScriptSource(scriptName, callback);
    126     else
     124    if (InspectorTest._scriptsAreParsed([scriptName])) {
     125        var scriptOrResource = InspectorTest._showScriptSource(scriptName);
     126        callback(scriptOrResource.sourceFrame);
     127    } else
    127128        InspectorTest._addSniffer(WebInspector.debuggerModel, "_parsedScriptSource", InspectorTest.showScriptSource.bind(InspectorTest, scriptName, callback));
    128 };
    129 
    130 InspectorTest.waitUntilCurrentSourceFrameIsLoaded = function(callback)
    131 {
    132     var sourceFrame = WebInspector.currentPanel.visibleView.sourceFrame;
    133     if (sourceFrame._loaded)
    134         callback(sourceFrame);
    135     else
    136         InspectorTest._addSniffer(sourceFrame, "setContent", callback.bind(null, sourceFrame));
    137129};
    138130
     
    178170        scriptsPanel._showScriptOrResource(scriptResource);
    179171    }
    180 
    181     InspectorTest.waitUntilCurrentSourceFrameIsLoaded(callback);
     172    return scriptResource;
    182173};
    183174
  • trunk/LayoutTests/inspector/debugger-pause-in-eval-script-expected.txt

    r69769 r75937  
    44Evaluated script in console.
    55Script execution paused.
    6 Execution line number: 4
    7 Execution line text:     debugger;
     6Call stack:
     7    0) testFunction (:4)
    88Script execution resumed.
    99Debugger was disabled.
  • trunk/LayoutTests/inspector/debugger-pause-in-eval-script.html

    r66596 r75937  
    2121    }
    2222
    23     function step2()
     23    function step2(callFrames)
    2424    {
    25         InspectorTest.waitUntilCurrentSourceFrameIsLoaded(step3);
    26     }
    27 
    28     function step3(sourceFrame)
    29     {
    30         InspectorTest.addResult("Execution line number: " + sourceFrame.executionLine);
    31         InspectorTest.addResult("Execution line text: " + sourceFrame._textModel.line(sourceFrame.executionLine - 1));
     25        InspectorTest.captureStackTrace(callFrames);
    3226        InspectorTest.completeDebuggerTest();
    3327    }
  • trunk/Source/WebCore/ChangeLog

    r75934 r75937  
     12011-01-17  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: refactoring: encapsulate lazy initialization of SourceFrame.
     6        https://bugs.webkit.org/show_bug.cgi?id=51738
     7
     8        Extract content loading logic from SourceView and ScriptView to ContentProvider implementations.
     9        Pass ContentProvider in SourceFrame constructor to allow SourceFrame manage it's lazy initialization.
     10
     11        * inspector/front-end/ScriptView.js:
     12        (WebInspector.ScriptView):
     13        (WebInspector.SourceFrameContentProviderForScript):
     14        (WebInspector.SourceFrameContentProviderForScript.prototype.requestContent.didRequestSource):
     15        (WebInspector.SourceFrameContentProviderForScript.prototype.requestContent):
     16        (WebInspector.SourceFrameContentProviderForScript.prototype.scripts):
     17        * inspector/front-end/ScriptsPanel.js:
     18        (WebInspector.ScriptsPanel.prototype._addScript):
     19        (WebInspector.ScriptsPanel.prototype.sourceFrameForScript):
     20        (WebInspector.ScriptsPanel.prototype._sourceFrameForResource):
     21        * inspector/front-end/SourceFrame.js:
     22        (WebInspector.SourceFrame):
     23        (WebInspector.SourceFrame.prototype.set visible):
     24        (WebInspector.SourceFrame.prototype._createTextViewer):
     25        (WebInspector.SourceFrame.prototype._breakpointAdded):
     26        (WebInspector.SourceFrame.prototype._breakpoints):
     27        (WebInspector.SourceFrame.prototype._sourceIDForLine):
     28        (WebInspector.SourceFrame.prototype._sourceIDSet):
     29        (WebInspector.SourceFrameContentProvider):
     30        (WebInspector.SourceFrameContentProvider.prototype.requestContent):
     31        (WebInspector.SourceFrameContentProvider.prototype.scripts):
     32        * inspector/front-end/SourceView.js:
     33        (WebInspector.SourceView):
     34        (WebInspector.SourceView.prototype.show):
     35        (WebInspector.SourceView.prototype.resize):
     36        (WebInspector.SourceView.prototype.performSearch.didFindSearchMatches):
     37        (WebInspector.SourceView.prototype.performSearch):
     38        (WebInspector.SourceView.prototype.revealLine):
     39        (WebInspector.SourceView.prototype.highlightLine):
     40        (WebInspector.SourceView.prototype._jumpToSearchResult):
     41        (WebInspector.SourceFrameContentProviderForResource):
     42        (WebInspector.SourceFrameContentProviderForResource.prototype.requestContent):
     43        (WebInspector.SourceFrameContentProviderForResource.prototype.scripts):
     44
    1452011-01-17  John Knottenbelt  <jknotten@chromium.org>
    246
  • trunk/Source/WebCore/inspector/front-end/ScriptView.js

    r75795 r75937  
    3030    this.element.addStyleClass("script-view");
    3131
    32     this.script = script;
    33 
    34     this._frameNeedsSetup = true;
    35     this._sourceFrameSetup = false;
    36     this.sourceFrame = new WebInspector.SourceFrame(this.element, [script], WebInspector.panels.scripts.canEditScripts());
     32    var contentProvider = new WebInspector.SourceFrameContentProviderForScript(script);
     33    this.sourceFrame = new WebInspector.SourceFrame(this.element, contentProvider, "", WebInspector.panels.scripts.canEditScripts());
    3734}
    3835
    3936WebInspector.ScriptView.prototype = {
    40     show: function(parentElement)
    41     {
    42         WebInspector.View.prototype.show.call(this, parentElement);
    43         this.setupSourceFrameIfNeeded();
    44         this.sourceFrame.visible = true;
    45         this.resize();
    46     },
    47 
    48     setupSourceFrameIfNeeded: function()
    49     {
    50         if (!this._frameNeedsSetup)
    51             return;
    52         delete this._frameNeedsSetup;
    53 
    54         this.attach();
    55 
    56         function didRequestSource(source)
    57         {
    58             source = source || WebInspector.UIString("<source is not available>");
    59             this.sourceFrame.setContent("text/javascript", this._prependWhitespace(source));
    60             this._sourceFrameSetup = true;
    61         }
    62         this.script.requestSource(didRequestSource.bind(this));
    63     },
    64 
    65     _prependWhitespace: function(content) {
    66         var prefix = "";
    67         for (var i = 0; i < this.script.startingLine - 1; ++i)
    68             prefix += "\n";
    69         return prefix + content;
    70     },
    71 
    72     attach: function()
    73     {
    74         if (!this.element.parentNode)
    75             document.getElementById("script-resource-views").appendChild(this.element);
    76     },
    77 
    7837    // The following methods are pulled from SourceView, since they are
    7938    // generic and work with ScriptView just fine.
    8039
     40    show: WebInspector.SourceView.prototype.show,
    8141    hide: WebInspector.SourceView.prototype.hide,
    8242    revealLine: WebInspector.SourceView.prototype.revealLine,
     
    9757
    9858WebInspector.ScriptView.prototype.__proto__ = WebInspector.View.prototype;
     59
     60
     61WebInspector.SourceFrameContentProviderForScript = function(script)
     62{
     63    WebInspector.SourceFrameContentProvider.call(this);
     64    this._script = script;
     65}
     66
     67WebInspector.SourceFrameContentProviderForScript.prototype = {
     68    requestContent: function(callback)
     69    {
     70        if (this._script.source) {
     71            callback("text/javascript", this._script.source);
     72            return;
     73        }
     74
     75        function didRequestSource(content)
     76        {
     77            var source;
     78            if (content) {
     79                var prefix = "";
     80                for (var i = 0; i < this._script.startingLine - 1; ++i)
     81                    prefix += "\n";
     82                source = prefix + content;
     83            } else
     84                source = WebInspector.UIString("<source is not available>");
     85            callback("text/javascript", source);
     86        }
     87        this._script.requestSource(didRequestSource.bind(this));
     88    },
     89
     90    scripts: function()
     91    {
     92        return [this._script];
     93    }
     94}
     95
     96WebInspector.SourceFrameContentProviderForScript.prototype.__proto__ = WebInspector.SourceFrameContentProvider.prototype;
  • trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js

    r75500 r75937  
    257257                // Resource is finished, bind the script right away.
    258258                script.resource = resource;
    259                 var view = WebInspector.ResourceView.existingResourceViewForResource(resource);
    260                 if (view && view.sourceFrame)
    261                     view.sourceFrame.addScript(script);
    262259            } else {
    263260                // Resource is not finished, bind the script later.
     
    537534            this.attach();
    538535
    539         view.setupSourceFrameIfNeeded();
    540536        return view.sourceFrame;
    541537    },
     
    555551            return null;
    556552
    557         if (!view.setupSourceFrameIfNeeded)
    558             return null;
    559 
    560         view.setupSourceFrameIfNeeded();
    561553        return view.sourceFrame;
    562554    },
  • trunk/Source/WebCore/inspector/front-end/SourceFrame.js

    r75795 r75937  
    2929 */
    3030
    31 WebInspector.SourceFrame = function(parentElement, scripts, canEditScripts)
     31WebInspector.SourceFrame = function(parentElement, contentProvider, url, canEditScripts)
    3232{
    3333    this._parentElement = parentElement;
    34     this._scripts = {};
    35     for (var i = 0; i < scripts.length; ++i)
    36         this._scripts[scripts[i].sourceID] = scripts[i];
     34    this._contentProvider = contentProvider;
     35    this._url = url;
    3736    this._canEditScripts = canEditScripts;
    3837
     
    4443    this._messageBubbles = {};
    4544
    46     this._loaded = false;
    4745    this._popoverObjectGroup = "popover";
    4846}
     
    5250    set visible(visible)
    5351    {
    54         this._visible = visible;
    55         this._createViewerIfNeeded();
     52        if (!this._contentRequested) {
     53            this._contentRequested = true;
     54            this._contentProvider.requestContent(this._createTextViewer.bind(this));
     55        }
    5656
    5757        if (visible) {
     
    6060            if (this._textViewer && this._scrollLeft)
    6161                this._textViewer.element.scrollLeft = this._scrollLeft;
     62            if (this._textViewer)
     63                this._textViewer.resize();
    6264        } else {
    6365            this._hidePopup();
     
    115117    },
    116118
    117     addScript: function(script)
    118     {
    119         this._scripts[script.sourceID] = script;
    120     },
    121 
    122119    clearMessages: function()
    123120    {
     
    140137    },
    141138
    142     setContent: function(mimeType, content, url)
    143     {
    144         this._loaded = true;
    145         this._textModel.setText(null, content);
    146         this._mimeType = mimeType;
    147         this._content = content;
    148         this._url = url;
    149         this._createViewerIfNeeded();
    150     },
    151 
    152139    get textModel()
    153140    {
     
    182169    },
    183170
    184     _createViewerIfNeeded: function()
    185     {
    186         if (!this._visible || !this._loaded || this._textViewer)
    187             return;
     171    _createTextViewer: function(mimeType, content)
     172    {
     173        this._content = content;
     174        this._textModel.setText(null, content);
    188175
    189176        this._textViewer = new WebInspector.TextViewer(this._textModel, WebInspector.platform, this._url);
     
    197184        this._textViewer.beginUpdates();
    198185
    199         this._textViewer.mimeType = this._mimeType;
     186        this._textViewer.mimeType = mimeType;
    200187        this._addExistingMessagesToSource();
    201188        this._updateExecutionLine();
     
    420407        var breakpoint = event.data;
    421408
    422         if (breakpoint.sourceID in this._scripts)
     409        if (breakpoint.sourceID in this._sourceIDSet())
    423410            this._addBreakpoint(breakpoint);
    424411    },
     
    847834    _breakpoints: function()
    848835    {
    849         var scripts = this._scripts;
    850         return WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID in scripts; });
     836        var sourceIDSet = this._sourceIDSet();
     837        return WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID in sourceIDSet; });
    851838    },
    852839
     
    861848        var sourceIDForLine = null;
    862849        var closestStartingLine = 0;
    863         for (var sourceID in this._scripts) {
    864             var script = this._scripts[sourceID];
    865             if (script.startingLine <= lineNumber && script.startingLine >= closestStartingLine) {
    866                 closestStartingLine = script.startingLine;
    867                 sourceIDForLine = sourceID;
     850        var scripts = this._contentProvider.scripts();
     851        for (var i = 0; i < scripts.length; ++i) {
     852            var startingLine = scripts[i].startingLine;
     853            if (startingLine <= lineNumber && startingLine >= closestStartingLine) {
     854                closestStartingLine = startingLine;
     855                sourceIDForLine = scripts[i].sourceID;
    868856            }
    869857        }
    870858        return sourceIDForLine;
     859    },
     860
     861    _sourceIDSet: function()
     862    {
     863        var scripts = this._contentProvider.scripts();
     864        var sourceIDSet = {};
     865        for (var i = 0; i < scripts.length; ++i)
     866            sourceIDSet[scripts[i].sourceID] = true;
     867        return sourceIDSet;
    871868    }
    872869}
    873870
    874871WebInspector.SourceFrame.prototype.__proto__ = WebInspector.Object.prototype;
     872
     873
     874WebInspector.SourceFrameContentProvider = function()
     875{
     876}
     877
     878WebInspector.SourceFrameContentProvider.prototype = {
     879    requestContent: function(callback)
     880    {
     881        // Should be implemented by subclasses.
     882    },
     883
     884    scripts: function()
     885    {
     886        // Should be implemented by subclasses.
     887    }
     888}
  • trunk/Source/WebCore/inspector/front-end/SourceView.js

    r75497 r75937  
    3333    this.element.addStyleClass("source");
    3434
    35     var scripts = WebInspector.debuggerModel.scriptsForURL(resource.url);
     35    var contentProvider = new WebInspector.SourceFrameContentProviderForResource(resource);
    3636    var canEditScripts = WebInspector.panels.scripts.canEditScripts() && resource.type === WebInspector.Resource.Type.Script;
    37     this.sourceFrame = new WebInspector.SourceFrame(this.element, scripts, canEditScripts);
    38     resource.addEventListener("finished", this._resourceLoadingFinished, this);
    39     this._frameNeedsSetup = true;
    40 }
    41 
    42 // This is a map from resource.type to mime types
    43 // found in WebInspector.SourceTokenizer.Registry.
    44 WebInspector.SourceView.DefaultMIMETypeForResourceType = {
    45     0: "text/html",
    46     1: "text/css",
    47     4: "text/javascript"
     37    this.sourceFrame = new WebInspector.SourceFrame(this.element, contentProvider, resource.url, canEditScripts);
    4838}
    4939
     
    5141    show: function(parentElement)
    5242    {
    53         WebInspector.ResourceView.prototype.show.call(this, parentElement);
    54         this.setupSourceFrameIfNeeded();
     43        WebInspector.View.prototype.show.call(this, parentElement);
    5544        this.sourceFrame.visible = true;
    56         this.resize();
    5745    },
    5846
     
    6755    resize: function()
    6856    {
    69         if (this.sourceFrame)
    70             this.sourceFrame.resize();
     57        this.sourceFrame.resize();
    7158    },
    7259
     
    8168    },
    8269
    83 
    84     setupSourceFrameIfNeeded: function()
    85     {
    86         if (!this._frameNeedsSetup)
    87             return;
    88 
    89         delete this._frameNeedsSetup;
    90         this.resource.requestContent(this._contentLoaded.bind(this));
    91     },
    92 
    9370    hasContent: function()
    9471    {
    9572        return true;
    96     },
    97 
    98     _contentLoaded: function(content)
    99     {
    100         var mimeType = this._canonicalMimeType(this.resource);
    101         this.sourceFrame.setContent(mimeType, content, this.resource.url);
    102         this._sourceFrameSetupFinished();
    103     },
    104 
    105     _canonicalMimeType: function(resource)
    106     {
    107         return WebInspector.SourceView.DefaultMIMETypeForResourceType[resource.type] || resource.mimeType;
    108     },
    109 
    110     _resourceLoadingFinished: function(event)
    111     {
    112         this._frameNeedsSetup = true;
    113         this._sourceFrameSetup = false;
    114         if (this.visible)
    115             this.setupSourceFrameIfNeeded();
    116         this.resource.removeEventListener("finished", this._resourceLoadingFinished, this);
    11773    },
    11874
     
    13995                finishedCallback(this, this._searchResults.length);
    14096        }
    141 
    14297        this.sourceFrame.findSearchMatches(query, didFindSearchMatches.bind(this));
    14398    },
     
    189144    revealLine: function(lineNumber)
    190145    {
    191         this.setupSourceFrameIfNeeded();
    192146        this.sourceFrame.revealLine(lineNumber);
    193147    },
     
    195149    highlightLine: function(lineNumber)
    196150    {
    197         this.setupSourceFrameIfNeeded();
    198151        this.sourceFrame.highlightLine(lineNumber);
    199152    },
     
    216169
    217170        this.sourceFrame.markAndRevealRange(foundRange);
    218     },
    219 
    220     _sourceFrameSetupFinished: function()
    221     {
    222         this._sourceFrameSetup = true;
    223         this.resize();
    224         if (this._delayedFindSearchMatches) {
    225             this._delayedFindSearchMatches();
    226             delete this._delayedFindSearchMatches;
     171    }
     172}
     173
     174WebInspector.SourceView.prototype.__proto__ = WebInspector.ResourceView.prototype;
     175
     176
     177WebInspector.SourceFrameContentProviderForResource = function(resource)
     178{
     179    WebInspector.SourceFrameContentProvider.call(this);
     180    this._resource = resource;
     181}
     182
     183//This is a map from resource.type to mime types
     184//found in WebInspector.SourceTokenizer.Registry.
     185WebInspector.SourceFrameContentProviderForResource.DefaultMIMETypeForResourceType = {
     186 0: "text/html",
     187 1: "text/css",
     188 4: "text/javascript"
     189}
     190
     191WebInspector.SourceFrameContentProviderForResource.prototype = {
     192    requestContent: function(callback)
     193    {
     194        function contentLoaded(content)
     195        {
     196            var mimeType = WebInspector.SourceFrameContentProviderForResource.DefaultMIMETypeForResourceType[this._resource.type] || this._resource.mimeType;
     197            callback(mimeType, content);
    227198        }
     199        this._resource.requestContent(contentLoaded.bind(this));
     200    },
     201
     202    scripts: function()
     203    {
     204        return WebInspector.debuggerModel.scriptsForURL(this._resource.url);
    228205    }
    229206}
    230207
    231 WebInspector.SourceView.prototype.__proto__ = WebInspector.ResourceView.prototype;
     208WebInspector.SourceFrameContentProviderForResource.prototype.__proto__ = WebInspector.SourceFrameContentProvider.prototype;
Note: See TracChangeset for help on using the changeset viewer.