Changeset 75937 in webkit
- Timestamp:
- Jan 17, 2011 6:13:43 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r75934 r75937 1 2011-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 1 14 2011-01-17 John Knottenbelt <jknotten@chromium.org> 2 15 -
trunk/LayoutTests/http/tests/inspector/debugger-test2.js
r75791 r75937 122 122 InspectorTest.showScriptSource = function(scriptName, callback) 123 123 { 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 127 128 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 else136 InspectorTest._addSniffer(sourceFrame, "setContent", callback.bind(null, sourceFrame));137 129 }; 138 130 … … 178 170 scriptsPanel._showScriptOrResource(scriptResource); 179 171 } 180 181 InspectorTest.waitUntilCurrentSourceFrameIsLoaded(callback); 172 return scriptResource; 182 173 }; 183 174 -
trunk/LayoutTests/inspector/debugger-pause-in-eval-script-expected.txt
r69769 r75937 4 4 Evaluated script in console. 5 5 Script execution paused. 6 Execution line number: 4 7 Execution line text: debugger; 6 Call stack: 7 0) testFunction (:4) 8 8 Script execution resumed. 9 9 Debugger was disabled. -
trunk/LayoutTests/inspector/debugger-pause-in-eval-script.html
r66596 r75937 21 21 } 22 22 23 function step2( )23 function step2(callFrames) 24 24 { 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); 32 26 InspectorTest.completeDebuggerTest(); 33 27 } -
trunk/Source/WebCore/ChangeLog
r75934 r75937 1 2011-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 1 45 2011-01-17 John Knottenbelt <jknotten@chromium.org> 2 46 -
trunk/Source/WebCore/inspector/front-end/ScriptView.js
r75795 r75937 30 30 this.element.addStyleClass("script-view"); 31 31 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()); 37 34 } 38 35 39 36 WebInspector.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 78 37 // The following methods are pulled from SourceView, since they are 79 38 // generic and work with ScriptView just fine. 80 39 40 show: WebInspector.SourceView.prototype.show, 81 41 hide: WebInspector.SourceView.prototype.hide, 82 42 revealLine: WebInspector.SourceView.prototype.revealLine, … … 97 57 98 58 WebInspector.ScriptView.prototype.__proto__ = WebInspector.View.prototype; 59 60 61 WebInspector.SourceFrameContentProviderForScript = function(script) 62 { 63 WebInspector.SourceFrameContentProvider.call(this); 64 this._script = script; 65 } 66 67 WebInspector.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 96 WebInspector.SourceFrameContentProviderForScript.prototype.__proto__ = WebInspector.SourceFrameContentProvider.prototype; -
trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js
r75500 r75937 257 257 // Resource is finished, bind the script right away. 258 258 script.resource = resource; 259 var view = WebInspector.ResourceView.existingResourceViewForResource(resource);260 if (view && view.sourceFrame)261 view.sourceFrame.addScript(script);262 259 } else { 263 260 // Resource is not finished, bind the script later. … … 537 534 this.attach(); 538 535 539 view.setupSourceFrameIfNeeded();540 536 return view.sourceFrame; 541 537 }, … … 555 551 return null; 556 552 557 if (!view.setupSourceFrameIfNeeded)558 return null;559 560 view.setupSourceFrameIfNeeded();561 553 return view.sourceFrame; 562 554 }, -
trunk/Source/WebCore/inspector/front-end/SourceFrame.js
r75795 r75937 29 29 */ 30 30 31 WebInspector.SourceFrame = function(parentElement, scripts, canEditScripts)31 WebInspector.SourceFrame = function(parentElement, contentProvider, url, canEditScripts) 32 32 { 33 33 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; 37 36 this._canEditScripts = canEditScripts; 38 37 … … 44 43 this._messageBubbles = {}; 45 44 46 this._loaded = false;47 45 this._popoverObjectGroup = "popover"; 48 46 } … … 52 50 set visible(visible) 53 51 { 54 this._visible = visible; 55 this._createViewerIfNeeded(); 52 if (!this._contentRequested) { 53 this._contentRequested = true; 54 this._contentProvider.requestContent(this._createTextViewer.bind(this)); 55 } 56 56 57 57 if (visible) { … … 60 60 if (this._textViewer && this._scrollLeft) 61 61 this._textViewer.element.scrollLeft = this._scrollLeft; 62 if (this._textViewer) 63 this._textViewer.resize(); 62 64 } else { 63 65 this._hidePopup(); … … 115 117 }, 116 118 117 addScript: function(script)118 {119 this._scripts[script.sourceID] = script;120 },121 122 119 clearMessages: function() 123 120 { … … 140 137 }, 141 138 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 152 139 get textModel() 153 140 { … … 182 169 }, 183 170 184 _create ViewerIfNeeded: 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); 188 175 189 176 this._textViewer = new WebInspector.TextViewer(this._textModel, WebInspector.platform, this._url); … … 197 184 this._textViewer.beginUpdates(); 198 185 199 this._textViewer.mimeType = this._mimeType;186 this._textViewer.mimeType = mimeType; 200 187 this._addExistingMessagesToSource(); 201 188 this._updateExecutionLine(); … … 420 407 var breakpoint = event.data; 421 408 422 if (breakpoint.sourceID in this._s cripts)409 if (breakpoint.sourceID in this._sourceIDSet()) 423 410 this._addBreakpoint(breakpoint); 424 411 }, … … 847 834 _breakpoints: function() 848 835 { 849 var s cripts = this._scripts;850 return WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID in s cripts; });836 var sourceIDSet = this._sourceIDSet(); 837 return WebInspector.debuggerModel.queryBreakpoints(function(b) { return b.sourceID in sourceIDSet; }); 851 838 }, 852 839 … … 861 848 var sourceIDForLine = null; 862 849 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; 868 856 } 869 857 } 870 858 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; 871 868 } 872 869 } 873 870 874 871 WebInspector.SourceFrame.prototype.__proto__ = WebInspector.Object.prototype; 872 873 874 WebInspector.SourceFrameContentProvider = function() 875 { 876 } 877 878 WebInspector.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 33 33 this.element.addStyleClass("source"); 34 34 35 var scripts = WebInspector.debuggerModel.scriptsForURL(resource.url);35 var contentProvider = new WebInspector.SourceFrameContentProviderForResource(resource); 36 36 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); 48 38 } 49 39 … … 51 41 show: function(parentElement) 52 42 { 53 WebInspector.ResourceView.prototype.show.call(this, parentElement); 54 this.setupSourceFrameIfNeeded(); 43 WebInspector.View.prototype.show.call(this, parentElement); 55 44 this.sourceFrame.visible = true; 56 this.resize();57 45 }, 58 46 … … 67 55 resize: function() 68 56 { 69 if (this.sourceFrame) 70 this.sourceFrame.resize(); 57 this.sourceFrame.resize(); 71 58 }, 72 59 … … 81 68 }, 82 69 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 93 70 hasContent: function() 94 71 { 95 72 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);117 73 }, 118 74 … … 139 95 finishedCallback(this, this._searchResults.length); 140 96 } 141 142 97 this.sourceFrame.findSearchMatches(query, didFindSearchMatches.bind(this)); 143 98 }, … … 189 144 revealLine: function(lineNumber) 190 145 { 191 this.setupSourceFrameIfNeeded();192 146 this.sourceFrame.revealLine(lineNumber); 193 147 }, … … 195 149 highlightLine: function(lineNumber) 196 150 { 197 this.setupSourceFrameIfNeeded();198 151 this.sourceFrame.highlightLine(lineNumber); 199 152 }, … … 216 169 217 170 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 174 WebInspector.SourceView.prototype.__proto__ = WebInspector.ResourceView.prototype; 175 176 177 WebInspector.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. 185 WebInspector.SourceFrameContentProviderForResource.DefaultMIMETypeForResourceType = { 186 0: "text/html", 187 1: "text/css", 188 4: "text/javascript" 189 } 190 191 WebInspector.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); 227 198 } 199 this._resource.requestContent(contentLoaded.bind(this)); 200 }, 201 202 scripts: function() 203 { 204 return WebInspector.debuggerModel.scriptsForURL(this._resource.url); 228 205 } 229 206 } 230 207 231 WebInspector.Source View.prototype.__proto__ = WebInspector.ResourceView.prototype;208 WebInspector.SourceFrameContentProviderForResource.prototype.__proto__ = WebInspector.SourceFrameContentProvider.prototype;
Note: See TracChangeset
for help on using the changeset viewer.