Title: [94760] trunk
Revision
94760
Author
podivi...@chromium.org
Date
2011-09-08 08:05:35 -0700 (Thu, 08 Sep 2011)

Log Message

Web Inspector: do not re-create RawSourceCode when toggling pretty-print mode.
https://bugs.webkit.org/show_bug.cgi?id=67647

1) Implement RawSourceCode.setFormatted that allows toggling pretty-print mode on the fly without resetting everything.
2) Add RawSourceCode unit tests.
3) Remove source mapping listeners and console messages from presentation model (they live in RawSourceCode now).

Reviewed by Yury Semikhatsky.

Source/WebCore:

Test: inspector/debugger/raw-source-code.html

* inspector/front-end/DebuggerPresentationModel.js:
(WebInspector.DebuggerPresentationModel):
(WebInspector.DebuggerPresentationModel.prototype.linkifyLocation):
(WebInspector.DebuggerPresentationModel.prototype._addScript):
(WebInspector.DebuggerPresentationModel.prototype._sourceMappingUpdated):
(WebInspector.DebuggerPresentationModel.prototype.setFormatSource):
(WebInspector.DebuggerPresentationModel.prototype._createRawSourceCodeId):
(WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
* inspector/front-end/ScriptsPanel.js:
(WebInspector.ScriptsPanel.prototype._toggleFormatSource):
* inspector/front-end/SourceFile.js:
(WebInspector.RawSourceCode):
(WebInspector.RawSourceCode.prototype.get uiSourceCode):
(WebInspector.RawSourceCode.prototype.setFormatted):
(WebInspector.RawSourceCode.prototype.rawLocationToUILocation):
(WebInspector.RawSourceCode.prototype._saveSourceMapping):

LayoutTests:

* inspector/debugger/raw-source-code-expected.txt: Added.
* inspector/debugger/raw-source-code.html: Added.
* inspector/debugger/script-formatter.html:
* inspector/debugger/source-file.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (94759 => 94760)


--- trunk/LayoutTests/ChangeLog	2011-09-08 14:46:01 UTC (rev 94759)
+++ trunk/LayoutTests/ChangeLog	2011-09-08 15:05:35 UTC (rev 94760)
@@ -1,3 +1,19 @@
+2011-09-06  Pavel Podivilov  <podivi...@chromium.org>
+
+        Web Inspector: do not re-create RawSourceCode when toggling pretty-print mode.
+        https://bugs.webkit.org/show_bug.cgi?id=67647
+
+        1) Implement RawSourceCode.setFormatted that allows toggling pretty-print mode on the fly without resetting everything.
+        2) Add RawSourceCode unit tests.
+        3) Remove source mapping listeners and console messages from presentation model (they live in RawSourceCode now).
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/debugger/raw-source-code-expected.txt: Added.
+        * inspector/debugger/raw-source-code.html: Added.
+        * inspector/debugger/script-formatter.html:
+        * inspector/debugger/source-file.html:
+
 2011-09-08  Cary Clark  <carycl...@google.com>
 
         Unreviewed; new baselines (Skia on Mac, next chunk of files)

Added: trunk/LayoutTests/inspector/debugger/raw-source-code-expected.txt (0 => 94760)


--- trunk/LayoutTests/inspector/debugger/raw-source-code-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/raw-source-code-expected.txt	2011-09-08 15:05:35 UTC (rev 94760)
@@ -0,0 +1,17 @@
+Tests RawSourceCode class.
+
+
+Running: testScriptWithoutResource
+
+Running: testHTMLWithPendingResource
+
+Running: testHTMLWithFinishedResource
+
+Running: testContentEdited
+
+Running: testForceUpdateSourceMapping
+
+Running: testFormattingWithFinishedResource
+
+Running: testFormattingWithPendingResource
+
Property changes on: trunk/LayoutTests/inspector/debugger/raw-source-code-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/debugger/raw-source-code.html (0 => 94760)


--- trunk/LayoutTests/inspector/debugger/raw-source-code.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/raw-source-code.html	2011-09-08 15:05:35 UTC (rev 94760)
@@ -0,0 +1,346 @@
+<html>
+<head>
+<script src=""
+
+<script>
+
+function test()
+{
+    function createScriptMock(url, startLine, startColumn, isContentScript, source)
+    {
+        var lineCount = source.lineEndings().length;
+        var endLine = startLine + lineCount - 1;
+        var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.lineEndings()[lineCount - 2];
+        var script = new WebInspector.Script(null, url, startLine, startColumn, endLine, endColumn, undefined, undefined, isContentScript);
+        script.requestSource = function(callback) { callback(source); };
+        return script;
+    }
+
+    function createResourceMock(type, finished, content)
+    {
+        var resource = {};
+        resource.type = type === "document" ? WebInspector.Resource.Type.Document : WebInspector.Resource.Type.Script;
+        resource.finished = finished;
+        resource.content = content;
+        resource.requestContent = function(callback) { callback(resource.content); };
+        resource.finish = function() { resource.finished = true; resource.dispatchEventToListeners("finished"); };
+        resource.__proto__ = WebInspector.Object.prototype;
+        return resource;
+    }
+    function createPendingResourceMock(type, content) { return createResourceMock(type, false, content); }
+    function createFinishedResourceMock(type, content) { return createResourceMock(type, true, content); }
+
+    function createScriptFormatterMock()
+    {
+        var sourceMapping = {
+            originalToFormatted: function(location)
+            {
+                var formattedLocation = {};
+                formattedLocation.lineNumber = location.lineNumber * 2;
+                formattedLocation.columnNumber = location.columnNumber * 2;
+                return formattedLocation;
+            },
+
+            formattedToOriginal: function(location)
+            {
+                var originalLocation = {};
+                originalLocation.lineNumber = Math.floor(location.lineNumber / 2);
+                originalLocation.columnNumber = Math.floor(location.columnNumber / 2);
+                return originalLocation;
+            }
+        };
+        var formatter = {
+            formatContent: function(mimeType, content, callback) { formatter._callback = callback.bind(null, "<formatted> " + content, sourceMapping); },
+            finish: function() { formatter._callback(); }
+        };
+        return formatter;
+      };
+
+    function createRawSourceCode(script, resource, formatted)
+    {
+        var rawSourceCode = new WebInspector.RawSourceCode("id", script, resource, createScriptFormatterMock(), !!formatted);
+        rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, defaultSourceMappingUpdatedHandler);
+        return rawSourceCode;
+    }
+
+    function waitForSourceMappingEvent(rawSourceCode, callback)
+    {
+        rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, defaultSourceMappingUpdatedHandler);
+        rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, sourceMappingUpdated);
+        function sourceMappingUpdated(event)
+        {
+            rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, sourceMappingUpdated);
+            rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, defaultSourceMappingUpdatedHandler);
+            callback(event);
+        }
+    }
+
+    function defaultSourceMappingUpdatedHandler()
+    {
+        throw "Unexpected SourceMappingUpdated event.";
+    }
+
+    InspectorTest.runTestSuite([
+        function testScriptWithoutResource(next)
+        {
+            var script = createScriptMock("foo.js", 0, 0, true, "<script source>");
+            var rawSourceCode = createRawSourceCode(script, null);
+
+            InspectorTest.assertTrue(!!rawSourceCode.uiSourceCode);
+            var uiSourceCode = rawSourceCode.uiSourceCode;
+            InspectorTest.assertEquals("foo.js", uiSourceCode.url);
+            InspectorTest.assertEquals(true, uiSourceCode.isContentScript);
+            InspectorTest.assertEquals(rawSourceCode, uiSourceCode.rawSourceCode);
+            uiSourceCode.requestContent(didRequestContent);
+
+            function didRequestContent(mimeType, content)
+            {
+                InspectorTest.assertEquals("text/_javascript_", mimeType);
+                InspectorTest.assertEquals("<script source>", content);
+                next();
+            }
+        },
+
+        function testHTMLWithPendingResource(next)
+        {
+            var script1 = createScriptMock("index.html", 0, 10, false, "<script source 1>");
+            var script2 = createScriptMock("index.html", 0, 45, false, "<script source 2>");
+            var resource = createPendingResourceMock("document", "<resource content>");
+            var rawSourceCode = createRawSourceCode(script1, resource);
+
+            InspectorTest.assertTrue(!rawSourceCode.uiSourceCode);
+            waitForSourceMappingEvent(rawSourceCode, mappingReady);
+            resource.finish();
+
+            function mappingReady(event)
+            {
+                InspectorTest.assertTrue(!event.data.oldSourceCode);
+                var uiSourceCode = rawSourceCode.uiSourceCode;
+                InspectorTest.assertEquals("index.html", uiSourceCode.url);
+                InspectorTest.assertEquals(false, uiSourceCode.isContentScript);
+                uiSourceCode.requestContent(didRequestContent);
+            }
+
+            function didRequestContent(mimeType, content)
+            {
+                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("<resource content>", content);
+
+                rawSourceCode.addScript(script2);
+                rawSourceCode.forceUpdateSourceMapping();
+                next();
+            }
+        },
+
+        function testHTMLWithFinishedResource(next)
+        {
+            var script1 = createScriptMock("index.html", 0, 10, false, "<script source 1>");
+            var script2 = createScriptMock("index.html", 0, 45, false, "<script source 2>");
+            var resource = createFinishedResourceMock("document", "<resource content>");
+            var rawSourceCode = createRawSourceCode(script1, resource);
+
+            InspectorTest.assertTrue(!!rawSourceCode.uiSourceCode);
+            var uiSourceCode = rawSourceCode.uiSourceCode;
+            InspectorTest.assertEquals("index.html", uiSourceCode.url);
+            InspectorTest.assertEquals(false, uiSourceCode.isContentScript);
+            uiSourceCode.requestContent(didRequestContent);
+
+            function didRequestContent(mimeType, content)
+            {
+                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("<resource content>", content);
+
+                rawSourceCode.addScript(script2);
+                rawSourceCode.forceUpdateSourceMapping();
+                next();
+            }
+        },
+
+        function testContentEdited(next)
+        {
+            var script = createScriptMock("foo.js", 0, 0, true, "<script source>");
+            var resource = createFinishedResourceMock("script", "<resource content>");
+            var rawSourceCode = createRawSourceCode(script, resource);
+
+            InspectorTest.assertTrue(!!rawSourceCode.uiSourceCode);
+            rawSourceCode.uiSourceCode.requestContent(didRequestContent);
+
+            function didRequestContent(mimeType, content)
+            {
+                InspectorTest.assertEquals("text/_javascript_", mimeType);
+                InspectorTest.assertEquals("<resource content>", content);
+
+                waitForSourceMappingEvent(rawSourceCode, mappingReadyAfterEdit);
+                resource.content = "<edited resource content>";
+                rawSourceCode.contentEdited();
+            }
+
+            function mappingReadyAfterEdit()
+            {
+                rawSourceCode.uiSourceCode.requestContent(didRequestContentAfterEdit);
+            }
+
+            function didRequestContentAfterEdit(mimeType, content)
+            {
+                InspectorTest.assertEquals(mimeType, "text/_javascript_");
+                InspectorTest.assertEquals("<edited resource content>", content);
+                next();
+            }
+        },
+
+        function testForceUpdateSourceMapping(next)
+        {
+            var script1 = createScriptMock("index.html", 0, 10, false, "<script source 1>");
+            var script2 = createScriptMock("index.html", 0, 45, false, "<script source 2>");
+            var script3 = createScriptMock("index.html", 1, 10, false, "<script source 3>");
+            var resource = createPendingResourceMock("document", "<resource content>");
+            var rawSourceCode = createRawSourceCode(script1, resource);
+
+            InspectorTest.assertTrue(!rawSourceCode.uiSourceCode);
+            waitForSourceMappingEvent(rawSourceCode, requestContent);
+            rawSourceCode.forceUpdateSourceMapping();
+
+            function requestContent()
+            {
+                rawSourceCode.uiSourceCode.requestContent(didRequestContentOneScript);
+            }
+
+            function didRequestContentOneScript(mimeType, content)
+            {
+                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("  <script><script source 1></" + "script>", content);
+
+                rawSourceCode.forceUpdateSourceMapping();
+                rawSourceCode.addScript(script2);
+                waitForSourceMappingEvent(rawSourceCode, requestContentTwoScripts);
+                rawSourceCode.forceUpdateSourceMapping();
+            }
+
+            function requestContentTwoScripts()
+            {
+                rawSourceCode.uiSourceCode.requestContent(didRequestContentTwoScripts);
+            }
+
+            function didRequestContentTwoScripts(mimeType, content)
+            {
+                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("  <script><script source 1></" + "script> <script><script source 2></" + "script>", content);
+
+                rawSourceCode.forceUpdateSourceMapping();
+                waitForSourceMappingEvent(rawSourceCode, requestContentResource);
+                resource.finish();
+            }
+
+            function requestContentResource()
+            {
+                rawSourceCode.uiSourceCode.requestContent(didRequestContentResource);
+            }
+
+            function didRequestContentResource(mimeType, content)
+            {
+                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("<resource content>", content);
+
+                rawSourceCode.addScript(script3);
+                rawSourceCode.forceUpdateSourceMapping();
+
+                next();
+            }
+        },
+
+        function testFormattingWithFinishedResource(next)
+        {
+            var script = createScriptMock("foo.js", 0, 0, true, "<script source>");
+            var resource = createFinishedResourceMock("script", "<resource content>");
+            var rawSourceCode = createRawSourceCode(script, resource, false);
+
+            InspectorTest.assertTrue(!!rawSourceCode.uiSourceCode);
+            var uiSourceCode = rawSourceCode.uiSourceCode;
+            var uiLocation = rawSourceCode.rawLocationToUILocation({ lineNumber : 1, columnNumber: 2 });
+            InspectorTest.assertEquals(uiSourceCode, uiLocation.uiSourceCode);
+            InspectorTest.assertEquals(1, uiLocation.lineNumber);
+            InspectorTest.assertEquals(2, uiLocation.columnNumber);
+            uiSourceCode.requestContent(didRequestContent);
+
+            function didRequestContent(mimeType, content)
+            {
+                InspectorTest.assertEquals("text/_javascript_", mimeType);
+                InspectorTest.assertEquals("<resource content>", content);
+
+                rawSourceCode.setFormatted(true);
+                waitForSourceMappingEvent(rawSourceCode, requestFormattedContent);
+                rawSourceCode._formatter.finish();
+            }
+
+            function requestFormattedContent()
+            {
+                var uiSourceCode = rawSourceCode.uiSourceCode;
+                var uiLocation = rawSourceCode.rawLocationToUILocation({ lineNumber : 1, columnNumber: 2 });
+                InspectorTest.assertEquals(uiSourceCode, uiLocation.uiSourceCode);
+                InspectorTest.assertEquals(2, uiLocation.lineNumber);
+                InspectorTest.assertEquals(4, uiLocation.columnNumber);
+                uiSourceCode.requestContent(didRequestFormattedContent);
+            }
+
+            function didRequestFormattedContent(mimeType, content)
+            {
+                InspectorTest.assertEquals(mimeType, "text/_javascript_");
+                InspectorTest.assertEquals("<formatted> <resource content>", content);
+
+                waitForSourceMappingEvent(rawSourceCode, requestNotFormattedContent);
+                rawSourceCode.setFormatted(false);
+            }
+
+            function requestNotFormattedContent()
+            {
+                var uiSourceCode = rawSourceCode.uiSourceCode;
+                var uiLocation = rawSourceCode.rawLocationToUILocation({ lineNumber : 1, columnNumber: 2 });
+                InspectorTest.assertEquals(uiSourceCode, uiLocation.uiSourceCode);
+                InspectorTest.assertEquals(1, uiLocation.lineNumber);
+                InspectorTest.assertEquals(2, uiLocation.columnNumber);
+                uiSourceCode.requestContent(didRequestNotFormattedContent);
+            }
+
+            function didRequestNotFormattedContent(mimeType, content)
+            {
+                InspectorTest.assertEquals("text/_javascript_", mimeType);
+                InspectorTest.assertEquals("<resource content>", content);
+
+                next();
+            }
+        },
+
+        function testFormattingWithPendingResource(next)
+        {
+            var script = createScriptMock("foo.js", 0, 0, true, "<script source>");
+            var resource = createPendingResourceMock("script", "<resource content>");
+            var rawSourceCode = createRawSourceCode(script, resource, true);
+
+            InspectorTest.assertTrue(!rawSourceCode.uiSourceCode);
+            resource.finish();
+            waitForSourceMappingEvent(rawSourceCode, checkMapping);
+            rawSourceCode._formatter.finish();
+
+            function checkMapping()
+            {
+                var uiSourceCode = rawSourceCode.uiSourceCode;
+                var uiLocation = rawSourceCode.rawLocationToUILocation({ lineNumber : 1, columnNumber: 2 });
+                InspectorTest.assertEquals(uiSourceCode, uiLocation.uiSourceCode);
+                InspectorTest.assertEquals(2, uiLocation.lineNumber);
+                InspectorTest.assertEquals(4, uiLocation.columnNumber);
+
+                next();
+            }
+        }
+    ]);
+};
+
+</script>
+
+</head>
+
+<body _onload_="runTest()">
+<p>Tests RawSourceCode class.</p>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/debugger/raw-source-code.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/inspector/debugger/script-formatter.html (94759 => 94760)


--- trunk/LayoutTests/inspector/debugger/script-formatter.html	2011-09-08 14:46:01 UTC (rev 94759)
+++ trunk/LayoutTests/inspector/debugger/script-formatter.html	2011-09-08 15:05:35 UTC (rev 94760)
@@ -185,16 +185,10 @@
             function didEvaluate()
             {
                 dumpConsoleMessageURLs();
-                panel._presentationModel.addEventListener(WebInspector.DebuggerPresentationModel.Events.UISourceCodeAdded,  uiSourceCodeReplaced);
+                InspectorTest.addSniffer(WebInspector, "formatLinkText", setTimeout.bind(window, didFormatLinkText, 0));
                 panel._toggleFormatSource();
             }
 
-            function uiSourceCodeReplaced(event)
-            {
-                if (event.data.uiSourceCode.url.indexOf("script-formatter.html") !== -1)
-                    InspectorTest.runAfterPendingDispatches(didFormatLinkText);
-            }
-
             function didFormatLinkText()
             {
                 dumpConsoleMessageURLs();

Modified: trunk/LayoutTests/inspector/debugger/source-file.html (94759 => 94760)


--- trunk/LayoutTests/inspector/debugger/source-file.html	2011-09-08 14:46:01 UTC (rev 94759)
+++ trunk/LayoutTests/inspector/debugger/source-file.html	2011-09-08 15:05:35 UTC (rev 94760)
@@ -81,7 +81,7 @@
         function testFormattedConvertLocation(next)
         {
             var script = new WebInspector.Script("1", "foo.js", 0, 0, 20, 80, undefined, undefined, false);
-            var rawSourceCode = new WebInspector.RawSourceCode("id", script, mockScriptFormatter, true);
+            var rawSourceCode = new WebInspector.RawSourceCode("id", script, null, mockScriptFormatter, true);
 
             function didCreateSourceMapping()
             {
@@ -96,7 +96,7 @@
         {
             var script1 = new WebInspector.Script("1", "foo.js", 10, 20, 30, 40, undefined, undefined, false);
             var script2 = new WebInspector.Script("2", "foo.js", 50, 60, 70, 80, undefined, undefined, false);
-            var rawSourceCode = new WebInspector.RawSourceCode("id", script1, mockScriptFormatter, true);
+            var rawSourceCode = new WebInspector.RawSourceCode("id", script1, null, mockScriptFormatter, true);
             rawSourceCode.addScript(script2);
 
             function didCreateSourceMapping()

Modified: trunk/Source/WebCore/ChangeLog (94759 => 94760)


--- trunk/Source/WebCore/ChangeLog	2011-09-08 14:46:01 UTC (rev 94759)
+++ trunk/Source/WebCore/ChangeLog	2011-09-08 15:05:35 UTC (rev 94760)
@@ -1,3 +1,33 @@
+2011-09-06  Pavel Podivilov  <podivi...@chromium.org>
+
+        Web Inspector: do not re-create RawSourceCode when toggling pretty-print mode.
+        https://bugs.webkit.org/show_bug.cgi?id=67647
+
+        1) Implement RawSourceCode.setFormatted that allows toggling pretty-print mode on the fly without resetting everything.
+        2) Add RawSourceCode unit tests.
+        3) Remove source mapping listeners and console messages from presentation model (they live in RawSourceCode now).
+
+        Reviewed by Yury Semikhatsky.
+
+        Test: inspector/debugger/raw-source-code.html
+
+        * inspector/front-end/DebuggerPresentationModel.js:
+        (WebInspector.DebuggerPresentationModel):
+        (WebInspector.DebuggerPresentationModel.prototype.linkifyLocation):
+        (WebInspector.DebuggerPresentationModel.prototype._addScript):
+        (WebInspector.DebuggerPresentationModel.prototype._sourceMappingUpdated):
+        (WebInspector.DebuggerPresentationModel.prototype.setFormatSource):
+        (WebInspector.DebuggerPresentationModel.prototype._createRawSourceCodeId):
+        (WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
+        * inspector/front-end/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel.prototype._toggleFormatSource):
+        * inspector/front-end/SourceFile.js:
+        (WebInspector.RawSourceCode):
+        (WebInspector.RawSourceCode.prototype.get uiSourceCode):
+        (WebInspector.RawSourceCode.prototype.setFormatted):
+        (WebInspector.RawSourceCode.prototype.rawLocationToUILocation):
+        (WebInspector.RawSourceCode.prototype._saveSourceMapping):
+
 2011-09-08  Alexander Pavlov  <apav...@chromium.org>
 
         Web Inspector: [REGRESSION] Clear console shortcut Ctrl + L broken

Modified: trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js (94759 => 94760)


--- trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2011-09-08 14:46:01 UTC (rev 94759)
+++ trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2011-09-08 15:05:35 UTC (rev 94760)
@@ -37,8 +37,6 @@
     this._formatter = new WebInspector.ScriptFormatter();
     this._rawSourceCode = {};
     this._messages = [];
-    // FIXME: move this to RawSourceCode when it's not re-created in pretty-print mode.
-    this._sourceMappingListeners = [];
 
     this._presentationCallFrames = [];
     this._selectedCallFrameIndex = 0;
@@ -98,16 +96,6 @@
         rawSourceCode.createSourceMappingIfNeeded(didCreateSourceMapping);
     },
 
-    addSourceMappingListener: function(sourceURL, scriptId, listener)
-    {
-        this._sourceMappingListeners.push(listener);
-    },
-
-    removeSourceMappingListener: function(sourceURL, scriptId, listener)
-    {
-        // FIXME: implement this.
-    },
-
     linkifyLocation: function(sourceURL, lineNumber, columnNumber, classes)
     {
         var linkText = WebInspector.formatLinkText(sourceURL, lineNumber);
@@ -132,7 +120,7 @@
             this._scriptLocationToUILocation(sourceURL, null, lineNumber, columnNumber, didGetLocation.bind(this));
         }
         updateAnchor.call(this);
-        this.addSourceMappingListener(sourceURL, null, updateAnchor.bind(this));
+        rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, updateAnchor, this);
         return anchor;
     },
 
@@ -155,18 +143,25 @@
             return;
         }
 
-        rawSourceCode = new WebInspector.RawSourceCode(rawSourceCodeId, script, this._formatter, this._formatSource);
+        var resource;
+        if (script.sourceURL)
+            resource = WebInspector.networkManager.inflightResourceForURL(script.sourceURL) || WebInspector.resourceForURL(script.sourceURL);
+        rawSourceCode = new WebInspector.RawSourceCode(rawSourceCodeId, script, resource, this._formatter, this._formatSource);
         this._rawSourceCode[rawSourceCodeId] = rawSourceCode;
+        if (rawSourceCode.uiSourceCode)
+            this._updateSourceMapping(rawSourceCode, null);
         rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, this._sourceMappingUpdated, this);
     },
 
     _sourceMappingUpdated: function(event)
     {
-        for (var i = 0; i < this._sourceMappingListeners.length; ++i)
-            this._sourceMappingListeners[i]();
-
         var rawSourceCode = event.target;
         var oldUISourceCode = event.data.oldUISourceCode;
+        this._updateSourceMapping(rawSourceCode, oldUISourceCode);
+    },
+
+    _updateSourceMapping: function(rawSourceCode, oldUISourceCode)
+    {
         var uiSourceCode = rawSourceCode.uiSourceCode;
 
         if (!oldUISourceCode)
@@ -181,11 +176,7 @@
             var eventData = { uiSourceCode: uiSourceCode, oldUISourceCode: oldUISourceCode };
             this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.UISourceCodeReplaced, eventData);
         }
-        this._restoreBreakpoints(uiSourceCode);
-    },
 
-    _restoreBreakpoints: function(uiSourceCode)
-    {
         this._breakpointManager.uiSourceCodeAdded(uiSourceCode);
         var breakpoints = this._breakpointManager.breakpointsForUISourceCode(uiSourceCode);
         for (var lineNumber in breakpoints)
@@ -262,23 +253,17 @@
         this._formatSource = formatSource;
 
         this._breakpointManager.reset();
-        for (var id in this._rawSourceCode)
-            this._rawSourceCode[id].removeEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, this._sourceMappingUpdated, this);
-        this._rawSourceCode = {};
-        var messages = this._messages;
-        this._messages = [];
 
-        var scripts = WebInspector.debuggerModel.scripts;
-        for (var id in scripts)
-            this._addScript(scripts[id]);
+        for (var id in this._rawSourceCode) {
+            this._rawSourceCode[id].messages = [];
+            this._rawSourceCode[id].setFormatted(this._formatSource);
+        }
 
+        var messages = this._messages;
+        this._messages = [];
         for (var i = 0; i < messages.length; ++i)
             this._addConsoleMessage(messages[i]);
 
-        // FIXME: move this to RawSourceCode.
-        for (var i = 0; i < this._sourceMappingListeners.length; ++i)
-            this._sourceMappingListeners[i]();
-
         if (WebInspector.debuggerModel.callFrames)
             this._debuggerPaused();
     },
@@ -446,15 +431,13 @@
 
     _createRawSourceCodeId: function(sourceURL, scriptId)
     {
-        var prefix = this._formatSource ? "deobfuscated:" : "";
-        return prefix + (sourceURL || scriptId);
+        return sourceURL || scriptId;
     },
 
     _debuggerReset: function()
     {
         this._rawSourceCode = {};
         this._messages = [];
-        this._sourceMappingListeners = [];
         this._presentationCallFrames = [];
         this._selectedCallFrameIndex = 0;
         this._breakpointManager.debuggerReset();

Modified: trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js (94759 => 94760)


--- trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js	2011-09-08 14:46:01 UTC (rev 94759)
+++ trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js	2011-09-08 15:05:35 UTC (rev 94760)
@@ -1132,7 +1132,6 @@
 
     _toggleFormatSource: function()
     {
-        WebInspector.panels.scripts.reset();
         this._toggleFormatSourceButton.toggled = !this._toggleFormatSourceButton.toggled;
         this._presentationModel.setFormatSource(this._toggleFormatSourceButton.toggled);
     },

Modified: trunk/Source/WebCore/inspector/front-end/SourceFile.js (94759 => 94760)


--- trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-09-08 14:46:01 UTC (rev 94759)
+++ trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-09-08 15:05:35 UTC (rev 94760)
@@ -35,18 +35,15 @@
  * @constructor
  * @extends {WebInspector.Object}
  */
-WebInspector.RawSourceCode = function(id, script, formatter, formatted)
+WebInspector.RawSourceCode = function(id, script, resource, formatter, formatted)
 {
-    this._scripts = [script];
-    this._formatter = formatter;
-    this._formatted = formatted;
-
-    if (script.sourceURL)
-        this._resource = WebInspector.networkManager.inflightResourceForURL(script.sourceURL) || WebInspector.resourceForURL(script.sourceURL);
-
     this.id = id;
     this.url = ""
     this.isContentScript = script.isContentScript;
+    this._scripts = [script];
+    this._formatter = formatter;
+    this._formatted = formatted;
+    this._resource = resource;
     this.messages = [];
 
     this._useTemporaryContent = this._resource && !this._resource.finished;
@@ -70,14 +67,15 @@
 
     get uiSourceCode()
     {
-        // FIXME: extract UISourceCode from RawSourceCode (currently RawSourceCode implements methods from both interfaces).
-        return this;
+        return this._uiSourceCode;
     },
 
-    get rawSourceCode()
+    setFormatted: function(formatted)
     {
-        // FIXME: extract UISourceCode from RawSourceCode (currently RawSourceCode implements methods from both interfaces).
-        return this;
+        if (this._formatted === formatted)
+            return;
+        this._formatted = formatted;
+        this._updateSourceMapping();
     },
 
     contentEdited: function()
@@ -94,7 +92,7 @@
     rawLocationToUILocation: function(rawLocation)
     {
         var location = this._mapping ? this._mapping.originalToFormatted(rawLocation) : rawLocation;
-        return new WebInspector.UILocation(this, location.lineNumber, location.columnNumber);
+        return new WebInspector.UILocation(this.uiSourceCode, location.lineNumber, location.columnNumber);
     },
 
     uiLocationToRawLocation: function(lineNumber, columnNumber)
@@ -120,12 +118,6 @@
         return closestScript;
     },
 
-    requestContent: function(callback)
-    {
-        // FIXME: remove this.
-        this._uiSourceCode.requestContent(callback);
-    },
-
     createSourceMappingIfNeeded: function(callback)
     {
         // FIXME: remove createSourceMappingIfNeeded, client should listen to SourceMappingUpdated event instead.
@@ -184,7 +176,7 @@
     _createSourceMapping: function(originalContentProvider, callback)
     {
         if (!this._formatted) {
-            setTimeout(callback.bind(null, originalContentProvider, null), 0);
+            callback(originalContentProvider, null);
             return;
         }
 
@@ -202,9 +194,7 @@
 
     _saveSourceMapping: function(contentProvider, mapping)
     {
-        var oldUISourceCode;
-        if (this._uiSourceCode)
-            oldUISourceCode = this;
+        var oldUISourceCode = this._uiSourceCode;
         var uiSourceCodeId = (this._formatted ? "deobfuscated:" : "") + (this._scripts[0].sourceURL || this._scripts[0].scriptId);
         this._uiSourceCode = new WebInspector.UISourceCode(uiSourceCodeId, this.url, this.isContentScript, this, contentProvider);
         this._mapping = mapping;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to