Commit 3dcea969 authored by podivilov@chromium.org's avatar podivilov@chromium.org
Browse files

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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75937 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 865c6af3
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 John Knottenbelt <jknotten@chromium.org>
 
Reviewed by Jeremy Orlow.
......
......@@ -121,21 +121,13 @@ InspectorTest._resumedScript = function()
InspectorTest.showScriptSource = function(scriptName, callback)
{
if (InspectorTest._scriptsAreParsed([scriptName]))
InspectorTest._showScriptSource(scriptName, callback);
else
if (InspectorTest._scriptsAreParsed([scriptName])) {
var scriptOrResource = InspectorTest._showScriptSource(scriptName);
callback(scriptOrResource.sourceFrame);
} else
InspectorTest._addSniffer(WebInspector.debuggerModel, "_parsedScriptSource", InspectorTest.showScriptSource.bind(InspectorTest, scriptName, callback));
};
InspectorTest.waitUntilCurrentSourceFrameIsLoaded = function(callback)
{
var sourceFrame = WebInspector.currentPanel.visibleView.sourceFrame;
if (sourceFrame._loaded)
callback(sourceFrame);
else
InspectorTest._addSniffer(sourceFrame, "setContent", callback.bind(null, sourceFrame));
};
InspectorTest._scriptsAreParsed = function(scripts)
{
var scriptSelect = document.getElementById("scripts-files");
......@@ -177,8 +169,7 @@ InspectorTest._showScriptSource = function(scriptName, callback)
scriptResource = options[pageScriptIndex].representedObject;
scriptsPanel._showScriptOrResource(scriptResource);
}
InspectorTest.waitUntilCurrentSourceFrameIsLoaded(callback);
return scriptResource;
};
InspectorTest.expandProperties = function(properties, callback)
......
......@@ -3,8 +3,8 @@ Tests that debugger will stop on "debugger" statement in a function that was add
Debugger was enabled.
Evaluated script in console.
Script execution paused.
Execution line number: 4
Execution line text: debugger;
Call stack:
0) testFunction (:4)
Script execution resumed.
Debugger was disabled.
......@@ -20,15 +20,9 @@ var test = function()
InspectorTest.waitUntilPaused(step2);
}
function step2()
function step2(callFrames)
{
InspectorTest.waitUntilCurrentSourceFrameIsLoaded(step3);
}
function step3(sourceFrame)
{
InspectorTest.addResult("Execution line number: " + sourceFrame.executionLine);
InspectorTest.addResult("Execution line text: " + sourceFrame._textModel.line(sourceFrame.executionLine - 1));
InspectorTest.captureStackTrace(callFrames);
InspectorTest.completeDebuggerTest();
}
}
......
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):
2011-01-17 John Knottenbelt <jknotten@chromium.org>
 
Reviewed by Jeremy Orlow.
......
......@@ -29,55 +29,15 @@ WebInspector.ScriptView = function(script)
this.element.addStyleClass("script-view");
this.script = script;
this._frameNeedsSetup = true;
this._sourceFrameSetup = false;
this.sourceFrame = new WebInspector.SourceFrame(this.element, [script], WebInspector.panels.scripts.canEditScripts());
var contentProvider = new WebInspector.SourceFrameContentProviderForScript(script);
this.sourceFrame = new WebInspector.SourceFrame(this.element, contentProvider, "", WebInspector.panels.scripts.canEditScripts());
}
WebInspector.ScriptView.prototype = {
show: function(parentElement)
{
WebInspector.View.prototype.show.call(this, parentElement);
this.setupSourceFrameIfNeeded();
this.sourceFrame.visible = true;
this.resize();
},
setupSourceFrameIfNeeded: function()
{
if (!this._frameNeedsSetup)
return;
delete this._frameNeedsSetup;
this.attach();
function didRequestSource(source)
{
source = source || WebInspector.UIString("<source is not available>");
this.sourceFrame.setContent("text/javascript", this._prependWhitespace(source));
this._sourceFrameSetup = true;
}
this.script.requestSource(didRequestSource.bind(this));
},
_prependWhitespace: function(content) {
var prefix = "";
for (var i = 0; i < this.script.startingLine - 1; ++i)
prefix += "\n";
return prefix + content;
},
attach: function()
{
if (!this.element.parentNode)
document.getElementById("script-resource-views").appendChild(this.element);
},
// The following methods are pulled from SourceView, since they are
// generic and work with ScriptView just fine.
show: WebInspector.SourceView.prototype.show,
hide: WebInspector.SourceView.prototype.hide,
revealLine: WebInspector.SourceView.prototype.revealLine,
highlightLine: WebInspector.SourceView.prototype.highlightLine,
......@@ -96,3 +56,41 @@ WebInspector.ScriptView.prototype = {
}
WebInspector.ScriptView.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.SourceFrameContentProviderForScript = function(script)
{
WebInspector.SourceFrameContentProvider.call(this);
this._script = script;
}
WebInspector.SourceFrameContentProviderForScript.prototype = {
requestContent: function(callback)
{
if (this._script.source) {
callback("text/javascript", this._script.source);
return;
}
function didRequestSource(content)
{
var source;
if (content) {
var prefix = "";
for (var i = 0; i < this._script.startingLine - 1; ++i)
prefix += "\n";
source = prefix + content;
} else
source = WebInspector.UIString("<source is not available>");
callback("text/javascript", source);
}
this._script.requestSource(didRequestSource.bind(this));
},
scripts: function()
{
return [this._script];
}
}
WebInspector.SourceFrameContentProviderForScript.prototype.__proto__ = WebInspector.SourceFrameContentProvider.prototype;
......@@ -256,9 +256,6 @@ WebInspector.ScriptsPanel.prototype = {
if (resource.finished) {
// Resource is finished, bind the script right away.
script.resource = resource;
var view = WebInspector.ResourceView.existingResourceViewForResource(resource);
if (view && view.sourceFrame)
view.sourceFrame.addScript(script);
} else {
// Resource is not finished, bind the script later.
if (!resource._scriptsPendingResourceLoad) {
......@@ -536,7 +533,6 @@ WebInspector.ScriptsPanel.prototype = {
if (!this.element.parentNode)
this.attach();
view.setupSourceFrameIfNeeded();
return view.sourceFrame;
},
......@@ -554,10 +550,6 @@ WebInspector.ScriptsPanel.prototype = {
if (!view)
return null;
if (!view.setupSourceFrameIfNeeded)
return null;
view.setupSourceFrameIfNeeded();
return view.sourceFrame;
},
......
......@@ -28,12 +28,11 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
WebInspector.SourceFrame = function(parentElement, scripts, canEditScripts)
WebInspector.SourceFrame = function(parentElement, contentProvider, url, canEditScripts)
{
this._parentElement = parentElement;
this._scripts = {};
for (var i = 0; i < scripts.length; ++i)
this._scripts[scripts[i].sourceID] = scripts[i];
this._contentProvider = contentProvider;
this._url = url;
this._canEditScripts = canEditScripts;
this._textModel = new WebInspector.TextEditorModel();
......@@ -43,7 +42,6 @@ WebInspector.SourceFrame = function(parentElement, scripts, canEditScripts)
this._rowMessages = {};
this._messageBubbles = {};
this._loaded = false;
this._popoverObjectGroup = "popover";
}
......@@ -51,14 +49,18 @@ WebInspector.SourceFrame.prototype = {
set visible(visible)
{
this._visible = visible;
this._createViewerIfNeeded();
if (!this._contentRequested) {
this._contentRequested = true;
this._contentProvider.requestContent(this._createTextViewer.bind(this));
}
if (visible) {
if (this._textViewer && this._scrollTop)
this._textViewer.element.scrollTop = this._scrollTop;
if (this._textViewer && this._scrollLeft)
this._textViewer.element.scrollLeft = this._scrollLeft;
if (this._textViewer)
this._textViewer.resize();
} else {
this._hidePopup();
if (this._textViewer) {
......@@ -114,11 +116,6 @@ WebInspector.SourceFrame.prototype = {
this._addMessageToSource(msg);
},
addScript: function(script)
{
this._scripts[script.sourceID] = script;
},
clearMessages: function()
{
for (var line in this._messageBubbles) {
......@@ -139,16 +136,6 @@ WebInspector.SourceFrame.prototype = {
this._textViewer.revalidateDecorationsAndPaint();
},
setContent: function(mimeType, content, url)
{
this._loaded = true;
this._textModel.setText(null, content);
this._mimeType = mimeType;
this._content = content;
this._url = url;
this._createViewerIfNeeded();
},
get textModel()
{
return this._textModel;
......@@ -181,10 +168,10 @@ WebInspector.SourceFrame.prototype = {
delete this._lineToHighlight;
},
_createViewerIfNeeded: function()
_createTextViewer: function(mimeType, content)
{
if (!this._visible || !this._loaded || this._textViewer)
return;
this._content = content;
this._textModel.setText(null, content);
this._textViewer = new WebInspector.TextViewer(this._textModel, WebInspector.platform, this._url);
var element = this._textViewer.element;
......@@ -196,7 +183,7 @@ WebInspector.SourceFrame.prototype = {
this._textViewer.beginUpdates();
this._textViewer.mimeType = this._mimeType;
this._textViewer.mimeType = mimeType;
this._addExistingMessagesToSource();
this._updateExecutionLine();
this._updateDiffDecorations();
......@@ -419,7 +406,7 @@ WebInspector.SourceFrame.prototype = {
{
var breakpoint = event.data;
if (breakpoint.sourceID in this._scripts)
if (breakpoint.sourceID in this._sourceIDSet())
this._addBreakpoint(breakpoint);
},
......@@ -846,8 +833,8 @@ WebInspector.SourceFrame.prototype = {
_breakpoints: function()
{
var scripts = this._scripts;
return WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID in scripts; });
var sourceIDSet = this._sourceIDSet();
return WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID in sourceIDSet; });
},
_findBreakpoint: function(lineNumber)
......@@ -860,15 +847,42 @@ WebInspector.SourceFrame.prototype = {
{
var sourceIDForLine = null;
var closestStartingLine = 0;
for (var sourceID in this._scripts) {
var script = this._scripts[sourceID];
if (script.startingLine <= lineNumber && script.startingLine >= closestStartingLine) {
closestStartingLine = script.startingLine;
sourceIDForLine = sourceID;
var scripts = this._contentProvider.scripts();
for (var i = 0; i < scripts.length; ++i) {
var startingLine = scripts[i].startingLine;
if (startingLine <= lineNumber && startingLine >= closestStartingLine) {
closestStartingLine = startingLine;
sourceIDForLine = scripts[i].sourceID;
}
}
return sourceIDForLine;
},
_sourceIDSet: function()
{
var scripts = this._contentProvider.scripts();
var sourceIDSet = {};
for (var i = 0; i < scripts.length; ++i)
sourceIDSet[scripts[i].sourceID] = true;
return sourceIDSet;
}
}
WebInspector.SourceFrame.prototype.__proto__ = WebInspector.Object.prototype;
WebInspector.SourceFrameContentProvider = function()
{
}
WebInspector.SourceFrameContentProvider.prototype = {
requestContent: function(callback)
{
// Should be implemented by subclasses.
},
scripts: function()
{
// Should be implemented by subclasses.
}
}
......@@ -32,28 +32,16 @@ WebInspector.SourceView = function(resource)
this.element.addStyleClass("source");
var scripts = WebInspector.debuggerModel.scriptsForURL(resource.url);
var contentProvider = new WebInspector.SourceFrameContentProviderForResource(resource);
var canEditScripts = WebInspector.panels.scripts.canEditScripts() && resource.type === WebInspector.Resource.Type.Script;
this.sourceFrame = new WebInspector.SourceFrame(this.element, scripts, canEditScripts);
resource.addEventListener("finished", this._resourceLoadingFinished, this);
this._frameNeedsSetup = true;
}
// This is a map from resource.type to mime types
// found in WebInspector.SourceTokenizer.Registry.
WebInspector.SourceView.DefaultMIMETypeForResourceType = {
0: "text/html",
1: "text/css",
4: "text/javascript"
this.sourceFrame = new WebInspector.SourceFrame(this.element, contentProvider, resource.url, canEditScripts);
}
WebInspector.SourceView.prototype = {
show: function(parentElement)
{
WebInspector.ResourceView.prototype.show.call(this, parentElement);
this.setupSourceFrameIfNeeded();
WebInspector.View.prototype.show.call(this, parentElement);
this.sourceFrame.visible = true;
this.resize();
},
hide: function()
......@@ -66,8 +54,7 @@ WebInspector.SourceView.prototype = {
resize: function()
{
if (this.sourceFrame)
this.sourceFrame.resize();
this.sourceFrame.resize();
},
get scrollTop()
......@@ -80,42 +67,11 @@ WebInspector.SourceView.prototype = {
this.sourceFrame.scrollTop = scrollTop;
},
setupSourceFrameIfNeeded: function()
{
if (!this._frameNeedsSetup)
return;
delete this._frameNeedsSetup;
this.resource.requestContent(this._contentLoaded.bind(this));
},
hasContent: function()
{
return true;
},
_contentLoaded: function(content)
{
var mimeType = this._canonicalMimeType(this.resource);
this.sourceFrame.setContent(mimeType, content, this.resource.url);
this._sourceFrameSetupFinished();
},
_canonicalMimeType: function(resource)
{
return WebInspector.SourceView.DefaultMIMETypeForResourceType[resource.type] || resource.mimeType;
},
_resourceLoadingFinished: function(event)
{
this._frameNeedsSetup = true;
this._sourceFrameSetup = false;
if (this.visible)
this.setupSourceFrameIfNeeded();
this.resource.removeEventListener("finished", this._resourceLoadingFinished, this);
},
// The rest of the methods in this prototype need to be generic enough to work with a ScriptView.
// The ScriptView prototype pulls these methods into it's prototype to avoid duplicate code.
......@@ -138,7 +94,6 @@ WebInspector.SourceView.prototype = {
if (this._searchResults)
finishedCallback(this, this._searchResults.length);
}
this.sourceFrame.findSearchMatches(query, didFindSearchMatches.bind(this));
},
......@@ -188,13 +143,11 @@ WebInspector.SourceView.prototype = {
revealLine: function(lineNumber)
{
this.setupSourceFrameIfNeeded();
this.sourceFrame.revealLine(lineNumber);
},
highlightLine: function(lineNumber)
{
this.setupSourceFrameIfNeeded();
this.sourceFrame.highlightLine(lineNumber);
},
......@@ -215,17 +168,41 @@ WebInspector.SourceView.prototype = {
return;
this.sourceFrame.markAndRevealRange(foundRange);
},
}
}
_sourceFrameSetupFinished: function()
WebInspector.SourceView.prototype.__proto__ = WebInspector.ResourceView.prototype;
WebInspector.SourceFrameContentProviderForResource = function(resource)
{
WebInspector.SourceFrameContentProvider.call(this);
this._resource = resource;
}
//This is a map from resource.type to mime types
//found in WebInspector.SourceTokenizer.Registry.
WebInspector.SourceFrameContentProviderForResource.DefaultMIMETypeForResourceType = {
0: "text/html",
1: "text/css",
4: "text/javascript"
}
WebInspector.SourceFrameContentProviderForResource.prototype = {
requestContent: function(callback)
{
this._sourceFrameSetup = true;
this.resize();
if (this._delayedFindSearchMatches) {
this._delayedFindSearchMatches();
delete this._delayedFindSearchMatches;
function contentLoaded(content)
{
var mimeType = WebInspector.SourceFrameContentProviderForResource.DefaultMIMETypeForResourceType[this._resource.type] || this._resource.mimeType;
callback(mimeType, content);
}
this._resource.requestContent(contentLoaded.bind(this));
},
scripts: function()
{
return WebInspector.debuggerModel.scriptsForURL(this._resource.url);
}
}
WebInspector.SourceView.prototype.__proto__ = WebInspector.ResourceView.prototype;
WebInspector.SourceFrameContentProviderForResource.prototype.__proto__ = WebInspector.SourceFrameContentProvider.prototype;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment