Web Inspector: Create JavaScriptSources based on network resources.
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Sep 2012 16:34:08 +0000 (16:34 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Sep 2012 16:34:08 +0000 (16:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=95352

Reviewed by Pavel Feldman.

Source/WebCore:

Introduced NetworkUISourceCodeProvider that is listening for ResourceTreeModel and creates UISourceCodes for them.
RawSourceCode does not create uiSourceCodes based on resource anymore (this is done by NetworkUISourceCodeProvider instead).
Moved script <-> uiSourceCode binding logic from RawSourceCode to ResourceScriptMapping.
Removed rawSourceCode as it was not needed anymore.

Tests: inspector/debugger/network-uisourcecode-provider.html
       inspector/debugger/resource-script-mapping.html

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/compile-front-end.py:
* inspector/front-end/CompilerScriptMapping.js:
* inspector/front-end/JavaScriptSource.js:
(WebInspector.JavaScriptSource):
* inspector/front-end/NetworkUISourceCodeProvider.js: Renamed from Source/WebCore/inspector/front-end/StylesUISourceCodeProvider.js.
(WebInspector.NetworkUISourceCodeProvider):
(WebInspector.NetworkUISourceCodeProvider.prototype._populate):
(WebInspector.NetworkUISourceCodeProvider.prototype._styleResourceAdded):
(WebInspector.NetworkUISourceCodeProvider.prototype._scriptResourceAdded.resourceFinished):
(WebInspector.NetworkUISourceCodeProvider.prototype._scriptResourceAdded):
(WebInspector.NetworkUISourceCodeProvider.prototype._addJavaScriptSource):
(WebInspector.NetworkUISourceCodeProvider.prototype._addUISourceCode):
(WebInspector.NetworkUISourceCodeProvider.prototype._resourceAdded):
(WebInspector.NetworkUISourceCodeProvider.prototype._reset):
* inspector/front-end/RawSourceCode.js:
* inspector/front-end/ResourceScriptMapping.js:
(WebInspector.ResourceScriptMapping):
(WebInspector.ResourceScriptMapping.prototype.rawLocationToUILocation):
(WebInspector.ResourceScriptMapping.prototype._bindUISourceCodeToScripts):
(WebInspector.ResourceScriptMapping.prototype._scriptsForSourceURL):
(WebInspector.ResourceScriptMapping.prototype._addOrReplaceTemporaryUISourceCode.get var):
(WebInspector.ResourceScriptMapping.prototype._addOrReplaceTemporaryUISourceCode):
(WebInspector.ResourceScriptMapping.prototype.get _uiSourceCodeReplaced):
(WebInspector.ResourceScriptMapping.prototype._reset):
* inspector/front-end/ScriptSnippetModel.js:
(WebInspector.ScriptSnippetModel.prototype._addScriptSnippet):
(WebInspector.ScriptSnippetModel.prototype._createUISourceCodeForScript):
(WebInspector.SnippetJavaScriptSource):
* inspector/front-end/UISourceCode.js:
(WebInspector.UISourceCode):
(WebInspector.UISourceCode.prototype.uiLocationToRawLocation):
(WebInspector.UISourceCode.prototype.setSourceMapping):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/inspector.html:
* inspector/front-end/inspector.js:

LayoutTests:

Removed raw-source-code.html test as RawSourceCode was removed by this patch.
Added resource-script-mapping.html to test script <-> uiSourceCode binding behavior.
Added network-uisourcecode-provider.html to test uiSourceCode creation behavior.
Updated dynamic-script-tag.html to better match expected behavior.

* http/tests/inspector/network/network-request-revision-content.html:
* http/tests/inspector/workspace-test.js: Added.
(initialize_WorkspaceTest.InspectorTest.createWorkspace):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent.uiSourceCodeReplaced):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeAddedEvent.uiSourceCodeAdded):
(initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeAddedEvent):
(initialize_WorkspaceTest.InspectorTest.addMockUISourceCodeToWorkspace):
(initialize_WorkspaceTest.InspectorTest._defaultUISourceCodeProviderEventHandler):
(initialize_WorkspaceTest.InspectorTest.dumpUISourceCode.didRequestContent):
(initialize_WorkspaceTest.InspectorTest.dumpUISourceCode):
(initialize_WorkspaceTest):
* inspector/debugger/breakpoint-manager.html:
* inspector/debugger/dynamic-script-tag-expected.txt:
* inspector/debugger/dynamic-script-tag.html:
* inspector/debugger/network-uisourcecode-provider-expected.txt: Added.
* inspector/debugger/network-uisourcecode-provider.html: Added.
* inspector/debugger/raw-source-code-expected.txt: Removed.
* inspector/debugger/raw-source-code.html: Removed.
* inspector/debugger/resource-script-mapping-expected.txt: Added.
* inspector/debugger/resource-script-mapping.html: Added.
* inspector/debugger/scripts-panel.html:
* inspector/debugger/source-frame-count.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@127427 268f45cc-cd09-0410-ab3c-d52691b4dbfc

27 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/network/network-request-revision-content.html
LayoutTests/http/tests/inspector/workspace-test.js [new file with mode: 0644]
LayoutTests/inspector/debugger/breakpoint-manager.html
LayoutTests/inspector/debugger/dynamic-script-tag-expected.txt
LayoutTests/inspector/debugger/dynamic-script-tag.html
LayoutTests/inspector/debugger/network-uisourcecode-provider-expected.txt [new file with mode: 0644]
LayoutTests/inspector/debugger/network-uisourcecode-provider.html [new file with mode: 0644]
LayoutTests/inspector/debugger/raw-source-code-expected.txt [deleted file]
LayoutTests/inspector/debugger/raw-source-code.html [deleted file]
LayoutTests/inspector/debugger/resource-script-mapping-expected.txt [new file with mode: 0644]
LayoutTests/inspector/debugger/resource-script-mapping.html [new file with mode: 0644]
LayoutTests/inspector/debugger/scripts-panel.html
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/inspector/compile-front-end.py
Source/WebCore/inspector/front-end/CompilerScriptMapping.js
Source/WebCore/inspector/front-end/JavaScriptSource.js
Source/WebCore/inspector/front-end/NetworkUISourceCodeProvider.js [moved from Source/WebCore/inspector/front-end/StylesUISourceCodeProvider.js with 61% similarity]
Source/WebCore/inspector/front-end/RawSourceCode.js
Source/WebCore/inspector/front-end/ResourceScriptMapping.js
Source/WebCore/inspector/front-end/ScriptSnippetModel.js
Source/WebCore/inspector/front-end/UISourceCode.js
Source/WebCore/inspector/front-end/WebKit.qrc
Source/WebCore/inspector/front-end/inspector.html
Source/WebCore/inspector/front-end/inspector.js

index bbd8689..9fd13c3 100644 (file)
@@ -1,3 +1,39 @@
+2012-09-03  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Create JavaScriptSources based on network resources.
+        https://bugs.webkit.org/show_bug.cgi?id=95352
+
+        Reviewed by Pavel Feldman.
+
+        Removed raw-source-code.html test as RawSourceCode was removed by this patch.
+        Added resource-script-mapping.html to test script <-> uiSourceCode binding behavior.
+        Added network-uisourcecode-provider.html to test uiSourceCode creation behavior.
+        Updated dynamic-script-tag.html to better match expected behavior.
+
+        * http/tests/inspector/network/network-request-revision-content.html:
+        * http/tests/inspector/workspace-test.js: Added.
+        (initialize_WorkspaceTest.InspectorTest.createWorkspace):
+        (initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent.uiSourceCodeReplaced):
+        (initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent):
+        (initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeAddedEvent.uiSourceCodeAdded):
+        (initialize_WorkspaceTest.InspectorTest.waitForWorkspaceUISourceCodeAddedEvent):
+        (initialize_WorkspaceTest.InspectorTest.addMockUISourceCodeToWorkspace):
+        (initialize_WorkspaceTest.InspectorTest._defaultUISourceCodeProviderEventHandler):
+        (initialize_WorkspaceTest.InspectorTest.dumpUISourceCode.didRequestContent):
+        (initialize_WorkspaceTest.InspectorTest.dumpUISourceCode):
+        (initialize_WorkspaceTest):
+        * inspector/debugger/breakpoint-manager.html:
+        * inspector/debugger/dynamic-script-tag-expected.txt:
+        * inspector/debugger/dynamic-script-tag.html:
+        * inspector/debugger/network-uisourcecode-provider-expected.txt: Added.
+        * inspector/debugger/network-uisourcecode-provider.html: Added.
+        * inspector/debugger/raw-source-code-expected.txt: Removed.
+        * inspector/debugger/raw-source-code.html: Removed.
+        * inspector/debugger/resource-script-mapping-expected.txt: Added.
+        * inspector/debugger/resource-script-mapping.html: Added.
+        * inspector/debugger/scripts-panel.html:
+        * inspector/debugger/source-frame-count.html:
+
 2012-09-03  Tommy Widenflycht  <tommyw@google.com>
 
         MediaStream API: Add Ice-related functionality to RTCPeerConnection
index d6837c6..e7d39b5 100644 (file)
@@ -14,7 +14,7 @@ function loadStylesheet()
 function test()
 {
     InspectorTest.addConsoleSniffer(step2, true);
-    InspectorTest.addSniffer(WebInspector.StylesUISourceCodeProvider.prototype, "_resourceAdded", true);
+    InspectorTest.addSniffer(WebInspector.NetworkUISourceCodeProvider.prototype, "_resourceAdded", true);
     InspectorTest.evaluateInPage("loadStylesheet()");
 
     var resource;
diff --git a/LayoutTests/http/tests/inspector/workspace-test.js b/LayoutTests/http/tests/inspector/workspace-test.js
new file mode 100644 (file)
index 0000000..4ba7367
--- /dev/null
@@ -0,0 +1,68 @@
+var initialize_WorkspaceTest = function() {
+
+InspectorTest.testWorkspace;
+InspectorTest.createWorkspace = function()
+{
+    InspectorTest.testWorkspace = new WebInspector.Workspace();
+    InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, InspectorTest._defaultUISourceCodeProviderEventHandler);
+    InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, InspectorTest._defaultUISourceCodeProviderEventHandler);
+    InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, InspectorTest._defaultUISourceCodeProviderEventHandler);
+}
+
+InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent = function(callback)
+{
+    InspectorTest.testWorkspace.removeEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, InspectorTest._defaultUISourceCodeProviderEventHandler);
+    InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, uiSourceCodeReplaced);
+
+    function uiSourceCodeReplaced(event)
+    {
+        InspectorTest.testWorkspace.removeEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, uiSourceCodeReplaced);
+        InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, InspectorTest._defaultUISourceCodeProviderEventHandler);
+        callback(event.data.uiSourceCode, event.data.oldUISourceCode);
+    }
+}
+
+InspectorTest.waitForWorkspaceUISourceCodeAddedEvent = function(callback)
+{
+    InspectorTest.testWorkspace.removeEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, InspectorTest._defaultUISourceCodeProviderEventHandler);
+    InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCodeAdded);
+
+    function uiSourceCodeAdded(event)
+    {
+        InspectorTest.testWorkspace.removeEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCodeAdded);
+        InspectorTest.testWorkspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, InspectorTest._defaultUISourceCodeProviderEventHandler);
+        callback(event.data);
+    }
+}
+
+InspectorTest.addMockUISourceCodeToWorkspace = function(url, type, content)
+{
+    var isDocument = type === WebInspector.resourceTypes.Document;
+    var mockContentProvider = new WebInspector.StaticContentProvider(type, content);
+    var uiSourceCode = new WebInspector.JavaScriptSource(url, null, mockContentProvider, !isDocument);
+    InspectorTest.testWorkspace.project().addUISourceCode(uiSourceCode);
+}
+
+InspectorTest._defaultUISourceCodeProviderEventHandler = function(event)
+{
+    throw new Error("Unexpected UISourceCodeProvider event: " + event.type + ".");
+}
+
+InspectorTest.dumpUISourceCode = function(uiSourceCode, callback)
+{
+    InspectorTest.addResult("UISourceCode: " + uiSourceCode.url);
+    if (uiSourceCode instanceof WebInspector.JavaScriptSource) {
+        InspectorTest.addResult("UISourceCode is editable: " + uiSourceCode._isEditable);
+        InspectorTest.addResult("UISourceCode is content script: " + uiSourceCode.isContentScript);
+    }
+    uiSourceCode.requestContent(didRequestContent);
+
+    function didRequestContent(content, contentEncoded, mimeType)
+    {
+        InspectorTest.addResult("Mime type: " + mimeType);
+        InspectorTest.addResult("UISourceCode content: " + content);
+        callback();
+    }
+}
+
+};
index fb3d0d7..c3db09e 100644 (file)
@@ -111,7 +111,8 @@ function test()
     WorkspaceMock.prototype = {
         _addUISourceCode: function(url)
         {
-            var uiSourceCode = new WebInspector.JavaScriptSource(url, null, null, defaultMapping, false);
+            var uiSourceCode = new WebInspector.JavaScriptSource(url, null, null, false);
+            uiSourceCode.setSourceMapping(defaultMapping);
             uiSourceCodes[url] = uiSourceCode;
             this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCode);
             return uiSourceCode;
index 6930c8f..7615330 100644 (file)
@@ -1,12 +1,28 @@
-CONSOLE MESSAGE: line 1: 123
-Tests that dynamically added script tag gets its own JavaScriptSource and is not bound to the resource. Bug 87119
+Tests that inline scripts and document.write scripts get different uiSourceCodes with different URLs. Bug 87119
 
 Debugger was enabled.
+Dumping scripts:
+script1: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html
+Is anonymous:false
+Is inline script:true
+script2: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html
+Is anonymous:false
+Is inline script:false
+script3: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html
 Is anonymous:false
 Is inline script:false
-dynamic-script-tag.html
-UI name: dynamic-script-tag.html
+Dumping uiSourceCodes:
+UISourceCode: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html (1)
+UISourceCode is editable: true
+UISourceCode is content script: false
+Mime type: text/javascript
+UISourceCode content: function bar() { }
+UI resource: null
+UISourceCode: file:///usr/local/google/home/vsevik/chromium/src/third_party/WebKit/LayoutTests/inspector/debugger/dynamic-script-tag.html (2)
+UISourceCode is editable: true
+UISourceCode is content script: false
+Mime type: text/javascript
+UISourceCode content: function foo() { }
 UI resource: null
-UI content: console.log(123)
 Debugger was disabled.
 
index b45368c..527987b 100644 (file)
@@ -2,51 +2,79 @@
 <head>
 <script src="../../http/tests/inspector/inspector-test.js"></script>
 <script src="../../http/tests/inspector/debugger-test.js"></script>
-
+<script src="../../http/tests/inspector/workspace-test.js"></script>
 <script>
+document.write("<scrip" + "t>function foo() { }</sc" + "ript>");
+var scriptElement = document.createElement("script");
+scriptElement.textContent = "function bar() { }";
+document.head.appendChild(scriptElement);
 
-function createScriptTag()
-{
-    var script = document.createElement("script");
-    script.innerHTML = "console.log(123)";
-    document.head.appendChild(script);
-}
-
-function test()
+var test = function()
 {
     InspectorTest.startDebuggerTest(step1);
 
     function step1()
     {
-        InspectorTest.evaluateInPage("createScriptTag()");
-        WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, step2);
-    }
+        var model = WebInspector.debuggerModel;
 
-    function step2(event)
-    {
-        var script = event.data;
-        script.requestContent(callback);
-        function callback(content)
+        var scripts = Object.values(WebInspector.debuggerModel.scripts);
+        function filterOutStandaloneScripts(script)
         {
-            if (content !== "console.log(123)")
-                return;
+            return script.sourceURL.indexOf("dynamic-script-tag.html") !== -1;
+        }
+        scripts = scripts.filter(filterOutStandaloneScripts);
+
+        function compareScriptFunction(script1, script2)
+        {
+            return script1.sourceURL.localeCompare(script2.sourceURL);
+        }
+        scripts.sort(compareScriptFunction);
+        InspectorTest.assertEquals(3, scripts.length, "Wrong scripts count.");
+
+        var uiSourceCodes = [];
+        InspectorTest.addResult("Dumping scripts:");
+        for (var i = 0; i < scripts.length; ++i) {
+            var script = scripts[i];
+            InspectorTest.addResult("script" + (i+1) + ": " + script.sourceURL);
             InspectorTest.addResult("Is anonymous:" + script.isAnonymousScript());
             InspectorTest.addResult("Is inline script:" + script.isInlineScript());
-            InspectorTest.addResult(new WebInspector.ParsedURL(script.sourceURL).displayName);
-            // Invoke post source map install.
-            setTimeout(step3.bind(this, script), 0);
+            if (!script.isInlineScript())
+                uiSourceCodes.push(script.rawLocationToUILocation(0, 0).uiSourceCode);
         }
-    }
 
-    function step3(script)
-    {
-        var uiLocation = script.rawLocationToUILocation(0, 0);
-        InspectorTest.addResult("UI name: " + uiLocation.uiSourceCode.parsedURL.displayName);
-        InspectorTest.addResult("UI resource: " + uiLocation.uiSourceCode.resource());
-        uiLocation.uiSourceCode.requestContent(callback);
-        function callback(content)
+        function compareUISourceCodeFunction(uiSourceCode1, uiSourceCode2)
+        {
+            return uiSourceCode1.url.localeCompare(uiSourceCode2.url);
+        }
+        uiSourceCodes.sort(compareUISourceCodeFunction);
+
+        var seenUISourceCodes = new Map();
+        InspectorTest.assertEquals(2, uiSourceCodes.length, "Wrong uiSourceCodes count.");
+        InspectorTest.addResult("Dumping uiSourceCodes:");
+        
+        var index = 0;
+        dumpNextUISourceCode();
+        function dumpNextUISourceCode()
+        {
+            if (index >= uiSourceCodes.length) {
+                uiSourceCodesDumped();
+                return;
+            }
+            var uiSourceCode = uiSourceCodes[index];
+            InspectorTest.dumpUISourceCode(uiSourceCode, uiSourceCodeDumped);
+
+            function uiSourceCodeDumped()
+            {
+                InspectorTest.addResult("UI resource: " + uiSourceCode.resource());
+                InspectorTest.assertTrue(!seenUISourceCodes.get(uiSourceCode), "UISourceCode matches two scripts: " + uiSourceCode.url);
+                seenUISourceCodes.put(uiSourceCode, uiSourceCode);
+                ++index;
+                dumpNextUISourceCode();
+            }
+        }
+        
+        function uiSourceCodesDumped()
         {
-            InspectorTest.addResult("UI content: " + content);
             InspectorTest.completeDebuggerTest();
         }
     }
@@ -54,10 +82,7 @@ function test()
 </script>
 </head>
 <body onload="runTest()">
-<p>
-Tests that dynamically added script tag gets its own JavaScriptSource and is not bound to the resource.
+<p>Tests that inline scripts and document.write scripts get different uiSourceCodes with different URLs.
 <a href="https://bugs.webkit.org/show_bug.cgi?id=87119">Bug 87119</a>
-</p>
 </body>
-
 </html>
diff --git a/LayoutTests/inspector/debugger/network-uisourcecode-provider-expected.txt b/LayoutTests/inspector/debugger/network-uisourcecode-provider-expected.txt
new file mode 100644 (file)
index 0000000..04991f2
--- /dev/null
@@ -0,0 +1,50 @@
+Tests NetworkUISourceCodeProvider class.
+
+
+Running: testDocumentResourceWithPendingRequest
+Creating request.
+Finishing request.
+UISourceCode: http://fake.url/2
+UISourceCode is editable: false
+UISourceCode is content script: false
+Mime type: text/html
+UISourceCode content: <document request content>
+
+Running: testDocumentResource
+Creating resource.
+UISourceCode: http://fake.url/3
+UISourceCode is editable: false
+UISourceCode is content script: false
+Mime type: text/html
+UISourceCode content: <document resource content>
+
+Running: testScriptResourceWithPendingRequest
+Creating request.
+Finishing request.
+UISourceCode: http://fake.url/4
+UISourceCode is editable: true
+UISourceCode is content script: false
+Mime type: text/javascript
+UISourceCode content: <script request content>
+
+Running: testScriptResource
+Creating resource.
+UISourceCode: http://fake.url/5
+UISourceCode is editable: true
+UISourceCode is content script: false
+Mime type: text/javascript
+UISourceCode content: <script resource content>
+
+Running: testStylesheetResourceWithPendingRequest
+Creating request.
+UISourceCode: http://fake.url/6
+Finishing request.
+Mime type: text/css
+UISourceCode content: <stylesheet request content>
+
+Running: testStylesheetResource
+Creating resource.
+UISourceCode: http://fake.url/7
+Mime type: text/css
+UISourceCode content: <stylesheet resource content>
+
diff --git a/LayoutTests/inspector/debugger/network-uisourcecode-provider.html b/LayoutTests/inspector/debugger/network-uisourcecode-provider.html
new file mode 100644 (file)
index 0000000..9d927f6
--- /dev/null
@@ -0,0 +1,173 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/debugger-test.js"></script>
+<script src="../../http/tests/inspector/workspace-test.js"></script>
+<script>
+function test()
+{
+    var mockContentsMap = {};
+    var lastResouceId = 1;
+
+    NetworkAgent.getResponseBody = function(requestId, callback)
+    {
+        callback(undefined, mockContentsMap[requestId], false);
+    }
+
+    PageAgent.getResourceContent = function(frameId, url, callback)
+    {
+        callback(undefined, mockContentsMap[url], false);
+    }
+
+    function createResourceMock(type, withPendingRequest, content)
+    {
+        var documentURL = "http://fake.url";
+        var resourceId = ++lastResouceId + "";
+        var url = documentURL + "/" + resourceId;
+        var frameId = "frame-id";
+        var loaderId = "loader-id";
+        var mimeType;
+        switch (type) {
+        case WebInspector.resourceTypes.Document:
+            mimeType = "text/html";
+            break;
+        case WebInspector.resourceTypes.Script:
+            mimeType = "text/javascript";
+            break;
+        case WebInspector.resourceTypes.Stylesheet:
+            mimeType = "text/css";
+            break;
+        }
+
+        if (withPendingRequest) {
+            var request = new WebInspector.NetworkRequest(resourceId, url, "http://fake.url", frameId, loaderId);
+            request.type = type;
+            request.mimeType = mimeType;
+            mockContentsMap[resourceId] = content;
+        }
+        var resource = new WebInspector.Resource(request, url, documentURL, frameId, loaderId, type, mimeType);
+        mockContentsMap[url] = content;
+        WebInspector.resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resource);
+
+        return resource;
+    }
+
+    function finishResource(resource)
+    {
+        resource.request.finished = true;
+        resource.request.dispatchEventToListeners(WebInspector.NetworkRequest.Events.FinishedLoading, resource.request);
+    }
+
+    function createNetworkUISourceCodeProvider()
+    {
+        InspectorTest.createWorkspace();
+        WebInspector.resourceTreeModel = new WebInspector.Object();
+        var networkUISourceCodeProvider = new WebInspector.NetworkUISourceCodeProvider(InspectorTest.testWorkspace);
+        return networkUISourceCodeProvider;
+    }
+
+    InspectorTest.runTestSuite([
+        function testDocumentResourceWithPendingRequest(next)
+        {
+            var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
+
+            InspectorTest.addResult("Creating request.");
+            var resource = createResourceMock(WebInspector.resourceTypes.Document, true, "<document request content>");
+
+            InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
+            InspectorTest.addResult("Finishing request.");
+            finishResource(resource);
+
+            function uiSourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.dumpUISourceCode(uiSourceCode, next);
+            }
+        },
+
+        function testDocumentResource(next)
+        {
+            var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
+            InspectorTest.addResult("Creating resource.");
+            InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
+            var resource = createResourceMock(WebInspector.resourceTypes.Document, false, "<document resource content>");
+
+            function uiSourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.dumpUISourceCode(uiSourceCode, next);
+            }
+        },
+
+        function testScriptResourceWithPendingRequest(next)
+        {
+            var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
+
+            InspectorTest.addResult("Creating request.");
+            var resource = createResourceMock(WebInspector.resourceTypes.Script, true, "<script request content>");
+
+            InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
+            InspectorTest.addResult("Finishing request.");
+            finishResource(resource);
+
+            function uiSourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.dumpUISourceCode(uiSourceCode, next);
+            }
+        },
+
+        function testScriptResource(next)
+        {
+            var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
+            InspectorTest.addResult("Creating resource.");
+            InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
+            var resource = createResourceMock(WebInspector.resourceTypes.Script, false, "<script resource content>");
+
+            function uiSourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.dumpUISourceCode(uiSourceCode, next);
+            }
+        },
+
+        function testStylesheetResourceWithPendingRequest(next)
+        {
+            var endTestCallsLeft = 2;
+            var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
+            InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
+            InspectorTest.addResult("Creating request.");
+            var resource = createResourceMock(WebInspector.resourceTypes.Stylesheet, true, "<stylesheet request content>");
+            InspectorTest.addResult("Finishing request.");
+            finishResource(resource);
+            endTest();
+
+            function uiSourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.dumpUISourceCode(uiSourceCode, endTest);
+            }
+
+            function endTest()
+            {
+                if (--endTestCallsLeft)
+                    return;
+                next();
+            }
+        },
+
+        function testStylesheetResource(next)
+        {
+            var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
+            InspectorTest.addResult("Creating resource.");
+            InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
+            var resource = createResourceMock(WebInspector.resourceTypes.Stylesheet, false, "<stylesheet resource content>");
+
+            function uiSourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.dumpUISourceCode(uiSourceCode, next);
+            }
+        },
+    ]);
+};
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests NetworkUISourceCodeProvider class.</p>
+</body>
+</html>
diff --git a/LayoutTests/inspector/debugger/raw-source-code-expected.txt b/LayoutTests/inspector/debugger/raw-source-code-expected.txt
deleted file mode 100644 (file)
index e071806..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-Tests RawSourceCode class.
-
-
-Running: testScriptWithoutResource
-UISourceCode: foo.js
-UISourceCode is content script: true
-Mime type: text/javascript
-Script source: <script source>
-
-Running: testHTMLWithPendingResource
-Adding first script for pending request.
-UISourceCode: index.html
-UISourceCode is content script: false
-Mime type: text/html
-Script source:   <script><script source 1></script>
-Adding second script for pending request.
-UISourceCode: index.html
-UISourceCode is content script: false
-Mime type: text/html
-Script source:   <script><script source 1></script> <script><script source 2></script>
-Finishing request.
-UISourceCode: index.html
-UISourceCode is content script: false
-Mime type: text/html
-Script source: <resource content>
-
-Running: testHTMLWithFinishedResource
-UISourceCode: index.html
-UISourceCode is content script: false
-Mime type: text/html
-Script source: <resource content>
-
diff --git a/LayoutTests/inspector/debugger/raw-source-code.html b/LayoutTests/inspector/debugger/raw-source-code.html
deleted file mode 100644 (file)
index 4532b8e..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-<html>
-<head>
-<script src="../../http/tests/inspector/inspector-test.js"></script>
-<script src="../../http/tests/inspector/debugger-test.js"></script>
-
-<script>
-
-function test()
-{
-    var mockContentsMap = {};
-    var lastRequestId = 1;
-
-    NetworkAgent.getResponseBody = function(requestId, callback)
-    {
-        callback(undefined, mockContentsMap[requestId], false);
-    }
-
-    PageAgent.getResourceContent = function(frameId, url, callback)
-    {
-        callback(undefined, mockContentsMap[url], false);
-    }
-
-    function createRequestMock(type, finished, content)
-    {
-        var requestId = ++lastRequestId + "";
-        var url = "http://fake.url/" + requestId;
-        WebInspector.resourceTreeModel._addFrame(new WebInspector.ResourceTreeFrame(WebInspector.resourceTreeModel, null, {id: "frame-id"}));
-        var request = new WebInspector.NetworkRequest(requestId, url, "http://fake.url", "frame-id", "loader-id");
-        request.type = type === "document" ? WebInspector.resourceTypes.Document : WebInspector.resourceTypes.Script;
-        request.mimeType = type === "document" ? "text/html" : "text/javascript";
-
-        WebInspector.networkManager._dispatcher._startNetworkRequest(request);
-        if (finished)
-            finishRequest(request);
-
-        mockContentsMap[requestId] = content;
-        mockContentsMap[url] = content;
-        return request;
-    }
-
-    function finishRequest(request) { WebInspector.networkManager._dispatcher._updateNetworkRequest(request); WebInspector.networkManager._dispatcher._finishNetworkRequest(request); }
-    function createPendingRequestMock(type, content) { return createRequestMock(type, false, content); }
-    function createFinishedRequestMock(type, content) { return createRequestMock(type, true, content); }
-
-    function createScriptFormatterMock()
-    {
-        var mapping = {
-            originalToFormatted: function(lineNumber, columnNumber) { return [lineNumber * 2, columnNumber * 2]; },
-            formattedToOriginal: function(lineNumber, columnNumber) { return [Math.floor(lineNumber / 2), Math.floor(columnNumber / 2)]; }
-        };
-        var formatter = {
-            formatContent: function(mimeType, content, callback) { formatter._callback = callback.bind(null, "<formatted> " + content, mapping); },
-            finish: function() { formatter._callback(); }
-        };
-        return formatter;
-    };
-
-    function createRawSourceCode(script, request, compilerSourceMapping)
-    {
-        var resource = null;
-        if (request && request.finished) {
-            resource = WebInspector.resourceForURL(request.url)
-            request = null;
-        }
-        var rawSourceCode = new WebInspector.RawSourceCode("id", script, resource, request, compilerSourceMapping);
-        rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeChanged, defaultUISourceCodeChangedHandler);
-        return rawSourceCode;
-    }
-
-    function waitForUISourceCodeChangedEvent(rawSourceCode, callback)
-    {
-        rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeChanged, defaultUISourceCodeChangedHandler);
-        rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeChanged, uiSourceCodeChanged);
-        function uiSourceCodeChanged(event)
-        {
-            rawSourceCode.removeEventListener(WebInspector.RawSourceCode.Events.UISourceCodeChanged, uiSourceCodeChanged);
-            rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeChanged, defaultUISourceCodeChangedHandler);
-            callback(event);
-        }
-    }
-
-    function defaultUISourceCodeChangedHandler()
-    {
-        throw new Error("Unexpected UISourceCodeChanged event.");
-    }
-
-    function createRawLocation(lineNumber, columnNumber)
-    {
-        return { lineNumber: lineNumber, columnNumber: columnNumber };
-    }
-
-    InspectorTest.runTestSuite([
-        function testScriptWithoutResource(next)
-        {
-            WebInspector.debuggerModel._reset();
-            var script = InspectorTest.createScriptMock("foo.js", 0, 0, true, "<script source>");
-            var rawSourceCode = createRawSourceCode(script, null);
-
-            var uiSourceCode = rawSourceCode.uiSourceCode();
-            InspectorTest.addResult("UISourceCode: " + rawSourceCode.uiSourceCode().url);
-            InspectorTest.addResult("UISourceCode is content script: " + uiSourceCode.isContentScript);
-            InspectorTest.checkUILocation(uiSourceCode, 0, 5, rawSourceCode.rawLocationToUILocation(createRawLocation(0, 5)));
-            InspectorTest.checkRawLocation(script, 10, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 10, 0));
-            uiSourceCode.requestContent(didRequestContent);
-
-            function didRequestContent(content, contentEncoded, mimeType)
-            {
-                InspectorTest.addResult("Mime type: " + mimeType);
-                InspectorTest.addResult("Script source: " + content);
-                next();
-            }
-        },
-
-        function testHTMLWithPendingResource(next)
-        {
-            WebInspector.debuggerModel._reset();
-            var script1 = InspectorTest.createScriptMock("index.html", 0, 10, false, "<script source 1>");
-            var script2 = InspectorTest.createScriptMock("index.html", 0, 45, false, "<script source 2>");
-            var request = createPendingRequestMock("document", "<resource content>");
-            InspectorTest.addResult("Adding first script for pending request.");
-            var rawSourceCode = createRawSourceCode(script1, request);
-
-            InspectorTest.assertTrue(!rawSourceCode.uiSourceCode());
-
-            waitForUISourceCodeChangedEvent(rawSourceCode, uiSourceCodeAdded);
-            rawSourceCode.rawLocationToUILocation(createRawLocation(0, 10));
-            function uiSourceCodeAdded(event)
-            {
-                InspectorTest.assertTrue(!event.data.oldUISourceCode);
-                InspectorTest.assertTrue(!!rawSourceCode.uiSourceCode());
-                var uiSourceCode = rawSourceCode.uiSourceCode();
-                InspectorTest.addResult("UISourceCode: " + uiSourceCode.url);
-                InspectorTest.addResult("UISourceCode is content script: " + uiSourceCode.isContentScript);
-                uiSourceCode.requestContent(didRequestContent);
-
-                function didRequestContent(content, contentEncoded, mimeType)
-                {
-                    InspectorTest.addResult("Mime type: " + mimeType);
-                    InspectorTest.addResult("Script source: " + content);
-
-                    waitForUISourceCodeChangedEvent(rawSourceCode, uiSourceCodeChangedAfterScriptAdded);
-                    InspectorTest.addResult("Adding second script for pending request.");
-                    rawSourceCode.addScript(script2);
-                  }
-            }
-
-            function uiSourceCodeChangedAfterScriptAdded(event)
-            {
-                InspectorTest.assertTrue(event.data.oldUISourceCode);
-                InspectorTest.assertTrue(!!rawSourceCode.uiSourceCode());
-                var uiSourceCode = rawSourceCode.uiSourceCode();
-                InspectorTest.addResult("UISourceCode: " + uiSourceCode.url);
-                InspectorTest.addResult("UISourceCode is content script: " + uiSourceCode.isContentScript);
-                uiSourceCode.requestContent(didRequestContent);
-
-                function didRequestContent(content, contentEncoded, mimeType)
-                {
-                    InspectorTest.addResult("Mime type: " + mimeType);
-                    InspectorTest.addResult("Script source: " + content);
-
-                    waitForUISourceCodeChangedEvent(rawSourceCode, uiSourceCodeChangedAfterRequestFinished);
-                    InspectorTest.addResult("Finishing request.");
-                    finishRequest(request);
-                }
-              }
-
-            function uiSourceCodeChangedAfterRequestFinished(event)
-            {
-                InspectorTest.assertTrue(event.data.oldUISourceCode);
-                InspectorTest.assertTrue(!!rawSourceCode.uiSourceCode());
-                var uiSourceCode = rawSourceCode.uiSourceCode();
-                InspectorTest.addResult("UISourceCode: " + uiSourceCode.url);
-                InspectorTest.addResult("UISourceCode is content script: " + uiSourceCode.isContentScript);
-                uiSourceCode.requestContent(didRequestContent);
-
-                function didRequestContent(content, contentEncoded, mimeType)
-                {
-                    InspectorTest.addResult("Mime type: " + mimeType);
-                    InspectorTest.addResult("Script source: " + content);
-
-                    next();
-                }
-              }
-        },
-
-        function testHTMLWithFinishedResource(next)
-        {
-            WebInspector.debuggerModel._reset();
-            var script1 = InspectorTest.createScriptMock("index.html", 1, 10, false, "<script source 1>");
-            var script2 = InspectorTest.createScriptMock("index.html", 5, 45, false, "<script\nsource\n2>");
-            var request = createFinishedRequestMock("document", "<resource content>");
-            var rawSourceCode = createRawSourceCode(script1, request);
-
-            InspectorTest.assertTrue(!!rawSourceCode.uiSourceCode());
-            var uiSourceCode = rawSourceCode.uiSourceCode();
-            InspectorTest.addResult("UISourceCode: " + uiSourceCode.url);
-            InspectorTest.addResult("UISourceCode is content script: " + uiSourceCode.isContentScript);
-            uiSourceCode.requestContent(didRequestContent);
-
-            function didRequestContent(content, contentEncoded, mimeType)
-            {
-                InspectorTest.addResult("Mime type: " + mimeType);
-                InspectorTest.addResult("Script source: " + content);
-
-                rawSourceCode.addScript(script2);
-                InspectorTest.checkUILocation(uiSourceCode, 1, 20, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 20)));
-                InspectorTest.checkRawLocation(script1, 1, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 1, 0));
-                InspectorTest.checkRawLocation(script2, 6, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 6, 0));
-
-                next();
-            }
-        }
-    ]);
-};
-
-</script>
-
-</head>
-
-<body onload="runTest()">
-<p>Tests RawSourceCode class.</p>
-
-</body>
-</html>
diff --git a/LayoutTests/inspector/debugger/resource-script-mapping-expected.txt b/LayoutTests/inspector/debugger/resource-script-mapping-expected.txt
new file mode 100644 (file)
index 0000000..afa9c21
--- /dev/null
@@ -0,0 +1,71 @@
+Tests ResourceScriptMapping class.
+
+
+Running: testScriptWithPendingResource
+Adding script for pending request.
+UISourceCode: foo.js
+UISourceCode is editable: true
+UISourceCode is content script: true
+Mime type: text/javascript
+UISourceCode content: <content script source>
+Adding uiSourceCode for finished resource.
+UISourceCode: foo.js
+UISourceCode is editable: true
+UISourceCode is content script: true
+Mime type: text/javascript
+UISourceCode content: <content script resource content>
+
+Running: testScriptWithFinishedResource
+Adding uiSourceCode for finished resource.
+UISourceCode: foo.js
+UISourceCode is editable: true
+UISourceCode is content script: false
+Mime type: text/javascript
+UISourceCode content: <script resource content>
+Adding script for finished request.
+UISourceCode: foo.js
+UISourceCode is editable: true
+UISourceCode is content script: false
+Mime type: text/javascript
+UISourceCode content: <script resource content>
+
+Running: testHTMLWithPendingResource
+Adding first script for pending request.
+UISourceCode: index.html
+UISourceCode is editable: false
+UISourceCode is content script: false
+Mime type: text/html
+UISourceCode content:   <script><script source 1></script>
+Adding second script for pending request.
+UISourceCode: index.html
+UISourceCode is editable: false
+UISourceCode is content script: false
+Mime type: text/html
+UISourceCode content:   <script><script source 1></script> <script><script source 2></script>
+Adding uiSourceCode for finished resource.
+UISourceCode: index.html
+UISourceCode is editable: false
+UISourceCode is content script: false
+Mime type: text/html
+UISourceCode content: <resource content>
+
+Running: testHTMLWithFinishedResource
+Adding uiSourceCode for finished resource.
+UISourceCode: index.html
+UISourceCode is editable: false
+UISourceCode is content script: false
+Mime type: text/html
+UISourceCode content: <resource content>
+Adding first script for finished request.
+UISourceCode: index.html
+UISourceCode is editable: false
+UISourceCode is content script: false
+Mime type: text/html
+UISourceCode content: <resource content>
+Adding second script for finished request.
+UISourceCode: index.html
+UISourceCode is editable: false
+UISourceCode is content script: false
+Mime type: text/html
+UISourceCode content: <resource content>
+
diff --git a/LayoutTests/inspector/debugger/resource-script-mapping.html b/LayoutTests/inspector/debugger/resource-script-mapping.html
new file mode 100644 (file)
index 0000000..69e7d5a
--- /dev/null
@@ -0,0 +1,198 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/debugger-test.js"></script>
+<script src="../../http/tests/inspector/workspace-test.js"></script>
+<script>
+function test()
+{
+    var workspace;
+    function createResourceScriptMapping()
+    {
+        InspectorTest.createWorkspace();
+        var resourceScriptMapping = new WebInspector.ResourceScriptMapping(InspectorTest.testWorkspace);
+        return resourceScriptMapping;
+    }
+
+    InspectorTest.runTestSuite([
+        function testScriptWithPendingResource(next)
+        {
+            var script;
+            WebInspector.debuggerModel._reset();
+            var resourceScriptMapping = createResourceScriptMapping();
+            var url = "foo.js";
+            step1();
+
+            function step1()
+            {
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
+                InspectorTest.addResult("Adding script for pending request.");
+                script = InspectorTest.createScriptMock(url, 0, 0, true, "<content script source>");
+                resourceScriptMapping.addScript(script);
+            }
+
+            function uiSourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.checkUILocation(uiSourceCode, 0, 5, script.rawLocationToUILocation(0, 5));
+                InspectorTest.checkRawLocation(script, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
+                InspectorTest.dumpUISourceCode(uiSourceCode, step2);
+            }
+
+            function step2()
+            {
+                InspectorTest.addResult("Adding uiSourceCode for finished resource.");
+                InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent(uiSourceCodeReplacedWithResource);
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(function() { });
+                InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Script, "<content script resource content>");
+            }
+
+            function uiSourceCodeReplacedWithResource(uiSourceCode, oldUISourceCode)
+            {
+                InspectorTest.checkUILocation(uiSourceCode, 0, 5, script.rawLocationToUILocation(0, 5));
+                InspectorTest.checkRawLocation(script, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
+                InspectorTest.dumpUISourceCode(uiSourceCode, next);
+            }
+        },
+
+        function testScriptWithFinishedResource(next)
+        {
+            var script;
+            WebInspector.debuggerModel._reset();
+            var mockUISourceCode;
+            var resourceScriptMapping = createResourceScriptMapping();
+            var url = "foo.js";
+            step1();
+
+            function step1()
+            {
+                InspectorTest.addResult("Adding uiSourceCode for finished resource.");
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeForResourceAdded);
+                InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Script, "<script resource content>");
+            }
+
+            function uiSourceCodeForResourceAdded(uiSourceCode)
+            {
+                mockUISourceCode = uiSourceCode;
+                InspectorTest.dumpUISourceCode(uiSourceCode, step2);
+            }
+
+            function step2()
+            {
+                InspectorTest.addResult("Adding script for finished request.");
+                script = InspectorTest.createScriptMock(url, 0, 0, false, "<script source>");
+                resourceScriptMapping.addScript(script);
+                InspectorTest.checkUILocation(mockUISourceCode, 0, 5, script.rawLocationToUILocation(0, 5));
+                InspectorTest.checkRawLocation(script, 10, 0, mockUISourceCode.uiLocationToRawLocation(10, 0));
+                InspectorTest.dumpUISourceCode(mockUISourceCode, next);
+            }
+        },
+
+        function testHTMLWithPendingResource(next)
+        {
+            var script1;
+            var script2;
+            WebInspector.debuggerModel._reset();
+            var resourceScriptMapping = createResourceScriptMapping();
+            var url = "index.html";
+            step1();
+
+            function step1()
+            {
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
+                InspectorTest.addResult("Adding first script for pending request.");
+                script1 = InspectorTest.createScriptMock(url, 0, 10, false, "<script source 1>");
+                resourceScriptMapping.addScript(script1);
+            }
+
+            function uiSourceCodeAdded(uiSourceCode)
+            {
+                InspectorTest.checkUILocation(uiSourceCode, 0, 5, script1.rawLocationToUILocation(0, 5));
+                InspectorTest.checkRawLocation(script1, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
+                InspectorTest.dumpUISourceCode(uiSourceCode, step2);
+            }
+
+            function step2()
+            {
+                InspectorTest.addResult("Adding second script for pending request.");
+                InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent(uiSourceCodeReplaced);
+                script2 = InspectorTest.createScriptMock(url, 0, 45, false, "<script source 2>");
+                resourceScriptMapping.addScript(script2);
+            }
+
+            function uiSourceCodeReplaced(uiSourceCode, oldUISourceCode)
+            {
+                InspectorTest.checkUILocation(uiSourceCode, 0, 5, script2.rawLocationToUILocation(0, 5));
+                InspectorTest.checkRawLocation(script1, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
+                InspectorTest.dumpUISourceCode(uiSourceCode, step3);
+            }
+
+            function step3()
+            {
+                InspectorTest.addResult("Adding uiSourceCode for finished resource.");
+                InspectorTest.waitForWorkspaceUISourceCodeReplacedEvent(uiSourceCodeReplacedWithResource);
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(function() { });
+                InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Document, "<resource content>");
+            }
+
+            function uiSourceCodeReplacedWithResource(uiSourceCode, oldUISourceCode)
+            {
+                InspectorTest.checkUILocation(uiSourceCode, 0, 5, script1.rawLocationToUILocation(0, 5));
+                InspectorTest.checkRawLocation(script1, 10, 0, uiSourceCode.uiLocationToRawLocation(10, 0));
+                InspectorTest.dumpUISourceCode(uiSourceCode, next);
+            }
+        },
+
+        function testHTMLWithFinishedResource(next)
+        {
+            var script1;
+            var script2;
+            WebInspector.debuggerModel._reset();
+            var mockUISourceCode;
+            var resourceScriptMapping = createResourceScriptMapping();
+            var url = "index.html";
+            step1();
+
+            function step1()
+            {
+                InspectorTest.addResult("Adding uiSourceCode for finished resource.");
+                InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeForResourceAdded);
+                InspectorTest.addMockUISourceCodeToWorkspace(url, WebInspector.resourceTypes.Document, "<resource content>");
+            }
+
+            function uiSourceCodeForResourceAdded(uiSourceCode)
+            {
+                mockUISourceCode = uiSourceCode;
+                InspectorTest.dumpUISourceCode(uiSourceCode, step2);
+            }
+
+            function step2()
+            {
+                InspectorTest.addResult("Adding first script for finished request.");
+                script1 = InspectorTest.createScriptMock(url, 1, 10, false, "<script source 1>");
+                resourceScriptMapping.addScript(script1);
+                InspectorTest.checkUILocation(mockUISourceCode, 1, 20, script1.rawLocationToUILocation(1, 20));
+                InspectorTest.checkRawLocation(script1, 1, 0, mockUISourceCode.uiLocationToRawLocation(1, 0));
+                InspectorTest.checkRawLocation(script1, 6, 0, mockUISourceCode.uiLocationToRawLocation(6, 0));
+                InspectorTest.dumpUISourceCode(mockUISourceCode, step3);
+            }
+
+            function step3()
+            {
+                InspectorTest.addResult("Adding second script for finished request.");
+                script2 = InspectorTest.createScriptMock(url, 5, 45, false, "<script\nsource\n2>");
+                resourceScriptMapping.addScript(script2);
+                InspectorTest.checkUILocation(mockUISourceCode, 1, 20, script1.rawLocationToUILocation(1, 20));
+                InspectorTest.checkRawLocation(script1, 1, 0, mockUISourceCode.uiLocationToRawLocation(1, 0));
+                InspectorTest.checkRawLocation(script2, 6, 0, mockUISourceCode.uiLocationToRawLocation(6, 0));
+                InspectorTest.dumpUISourceCode(mockUISourceCode, next);
+            }
+        }
+    ]);
+};
+
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests ResourceScriptMapping class.</p>
+</body>
+</html>
index a2fd591..e5bcc38 100644 (file)
@@ -24,7 +24,7 @@ function test()
     
     function createUISouceCode(url)
     {
-        var uiSourceCode = new WebInspector.JavaScriptSource(url, null, contentProvider, null, false);
+        var uiSourceCode = new WebInspector.JavaScriptSource(url, null, contentProvider, false);
         uiSourceCode.requestContent = function(callback)
         {
             InspectorTest.addResult("Source requested for " + url);
index 6acd910..1c43f54 100644 (file)
@@ -1,3 +1,56 @@
+2012-09-03  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Create JavaScriptSources based on network resources.
+        https://bugs.webkit.org/show_bug.cgi?id=95352
+
+        Reviewed by Pavel Feldman.
+
+        Introduced NetworkUISourceCodeProvider that is listening for ResourceTreeModel and creates UISourceCodes for them.
+        RawSourceCode does not create uiSourceCodes based on resource anymore (this is done by NetworkUISourceCodeProvider instead).
+        Moved script <-> uiSourceCode binding logic from RawSourceCode to ResourceScriptMapping.
+        Removed rawSourceCode as it was not needed anymore.
+
+        Tests: inspector/debugger/network-uisourcecode-provider.html
+               inspector/debugger/resource-script-mapping.html
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/compile-front-end.py:
+        * inspector/front-end/CompilerScriptMapping.js:
+        * inspector/front-end/JavaScriptSource.js:
+        (WebInspector.JavaScriptSource):
+        * inspector/front-end/NetworkUISourceCodeProvider.js: Renamed from Source/WebCore/inspector/front-end/StylesUISourceCodeProvider.js.
+        (WebInspector.NetworkUISourceCodeProvider):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._populate):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._styleResourceAdded):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._scriptResourceAdded.resourceFinished):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._scriptResourceAdded):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._addJavaScriptSource):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._addUISourceCode):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._resourceAdded):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._reset):
+        * inspector/front-end/RawSourceCode.js:
+        * inspector/front-end/ResourceScriptMapping.js:
+        (WebInspector.ResourceScriptMapping):
+        (WebInspector.ResourceScriptMapping.prototype.rawLocationToUILocation):
+        (WebInspector.ResourceScriptMapping.prototype._bindUISourceCodeToScripts):
+        (WebInspector.ResourceScriptMapping.prototype._scriptsForSourceURL):
+        (WebInspector.ResourceScriptMapping.prototype._addOrReplaceTemporaryUISourceCode.get var):
+        (WebInspector.ResourceScriptMapping.prototype._addOrReplaceTemporaryUISourceCode):
+        (WebInspector.ResourceScriptMapping.prototype.get _uiSourceCodeReplaced):
+        (WebInspector.ResourceScriptMapping.prototype._reset):
+        * inspector/front-end/ScriptSnippetModel.js:
+        (WebInspector.ScriptSnippetModel.prototype._addScriptSnippet):
+        (WebInspector.ScriptSnippetModel.prototype._createUISourceCodeForScript):
+        (WebInspector.SnippetJavaScriptSource):
+        * inspector/front-end/UISourceCode.js:
+        (WebInspector.UISourceCode):
+        (WebInspector.UISourceCode.prototype.uiLocationToRawLocation):
+        (WebInspector.UISourceCode.prototype.setSourceMapping):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/inspector.html:
+        * inspector/front-end/inspector.js:
+
 2012-09-03  Andrey Adaikin  <aandrey@chromium.org>
 
         Web Inspector: [WebGL] Make the injected __resourceObject property non-enumerable
index 9fea291..002ae08 100644 (file)
             'inspector/front-end/NetworkLog.js',
             'inspector/front-end/NetworkPanelDescriptor.js',
             'inspector/front-end/NetworkRequest.js',
+            'inspector/front-end/NetworkUISourceCodeProvider.js',
             'inspector/front-end/Object.js',
             'inspector/front-end/ObjectPopoverHelper.js',
             'inspector/front-end/ObjectPropertiesSection.js',
             'inspector/front-end/PresentationConsoleMessageHelper.js',
             'inspector/front-end/ProgressBar.js',
             'inspector/front-end/PropertiesSection.js',
-            'inspector/front-end/RawSourceCode.js',
             'inspector/front-end/RemoteObject.js',
             'inspector/front-end/Resource.js',
             'inspector/front-end/ResourceScriptMapping.js',
             'inspector/front-end/StatusBarButton.js',
             'inspector/front-end/StyleSource.js',
             'inspector/front-end/StylesSourceMapping.js',
-            'inspector/front-end/StylesUISourceCodeProvider.js',
             'inspector/front-end/TabbedPane.js',
             'inspector/front-end/TestController.js',
             'inspector/front-end/TextEditor.js',
index 8afa3ae..81b049f 100755 (executable)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\inspector\front-end\NetworkUISourceCodeProvider.js"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\inspector\front-end\NetworkRequest.js"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\inspector\front-end\RawSourceCode.js"
-                                       >
-                               </File>
-                               <File
                                        RelativePath="..\inspector\front-end\RemoteObject.js"
                                        >
                                </File>
                                        >
                                </File>
                                <File
-                                       RelativePath="..\inspector\front-end\StylesUISourceCodeProvider.js"
-                                       >
-                               </File>
-                               <File
                                        RelativePath="..\inspector\front-end\StyleSource.js"
                                        >
                                </File>
index c76f570..6baca12 100755 (executable)
@@ -82,6 +82,7 @@ modules = [
             "JavaScriptSource.js",
             "Linkifier.js",
             "NetworkLog.js",
+            "NetworkUISourceCodeProvider.js",
             "PresentationConsoleMessageHelper.js",
             "SASSSourceMapping.js",
             "Script.js",
@@ -91,9 +92,7 @@ modules = [
             "SourceMapping.js",
             "StyleSource.js",
             "StylesSourceMapping.js",
-            "StylesUISourceCodeProvider.js",
             "TimelineManager.js",
-            "RawSourceCode.js",
             "RemoteObject.js",
             "Resource.js",
             "ResourceScriptMapping.js",
index 8096d56..05c0051 100644 (file)
@@ -120,7 +120,8 @@ WebInspector.CompilerScriptMapping.prototype = {
                 contentProvider = new WebInspector.StaticContentProvider(WebInspector.resourceTypes.Script, sourceContent);
             else
                 contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL);
-            var uiSourceCode = new WebInspector.JavaScriptSource(sourceURL, null, contentProvider, this, false);
+            var uiSourceCode = new WebInspector.JavaScriptSource(sourceURL, null, contentProvider, false);
+            uiSourceCode.setSourceMapping(this);
             uiSourceCode.isContentScript = script.isContentScript;
             this._uiSourceCodeByURL[sourceURL] = uiSourceCode;
             this._sourceMapForUISourceCode.put(uiSourceCode, sourceMap);
index 2ac4953..a641c2d 100644 (file)
  * @param {string} url
  * @param {WebInspector.Resource} resource
  * @param {WebInspector.ContentProvider} contentProvider
- * @param {WebInspector.SourceMapping} sourceMapping
  */
-WebInspector.JavaScriptSource = function(url, resource, contentProvider, sourceMapping, isEditable)
+WebInspector.JavaScriptSource = function(url, resource, contentProvider, isEditable)
 {
-    WebInspector.UISourceCode.call(this, url, resource, contentProvider, sourceMapping);
+    WebInspector.UISourceCode.call(this, url, resource, contentProvider);
     this._isEditable = isEditable;
 }
 
  * @constructor
  * @param {WebInspector.Workspace} workspace
  */
-WebInspector.StylesUISourceCodeProvider = function(workspace)
+WebInspector.NetworkUISourceCodeProvider = function(workspace)
 {
     this._workspace = workspace;
     WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, this._resourceAdded, this);
     this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
     this._stylesSourceMapping = new WebInspector.StylesSourceMapping();
+
+    this._uiSourceCodeForResource = {};
 }
 
-WebInspector.StylesUISourceCodeProvider.prototype = {
+WebInspector.NetworkUISourceCodeProvider.prototype = {
     _populate: function()
     {
         function populateFrame(frame)
@@ -57,20 +59,74 @@ WebInspector.StylesUISourceCodeProvider.prototype = {
     },
 
     /**
-     * @param {WebInspector.Event} event
+     * @param {WebInspector.Resource} resource
      */
-    _resourceAdded: function(event)
+    _styleResourceAdded: function(resource)
     {
-        var resource = /** @type {WebInspector.Resource} */ event.data;
-        if (resource.type !== WebInspector.resourceTypes.Stylesheet)
-            return;
         var uiSourceCode = new WebInspector.StyleSource(resource);
         this._stylesSourceMapping.addUISourceCode(uiSourceCode);
+        this._addUISourceCode(uiSourceCode);
+    },
+
+    /**
+     * @param {WebInspector.Resource} resource
+     */
+    _scriptResourceAdded: function(resource)
+    {
+        if (resource.request && !resource.request.finished) {
+            resource.request.addEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, resourceFinished, this);
+            return;
+        }
+        this._addJavaScriptSource(resource);
+        
+        function resourceFinished()
+        {
+            resource.request.removeEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, resourceFinished, this);
+            this._addJavaScriptSource(resource);
+        }
+    },
+
+    /**
+     * @param {WebInspector.Resource} resource
+     */
+    _addJavaScriptSource: function(resource)
+    {
+        if (this._uiSourceCodeForResource[resource.url])
+            return;
+        var isDocument = resource.type === WebInspector.resourceTypes.Document;
+        var uiSourceCode = new WebInspector.JavaScriptSource(resource.url, resource, resource, !isDocument);
+        this._uiSourceCodeForResource[resource.url] = uiSourceCode;
+        this._addUISourceCode(uiSourceCode);
+    },
+
+    /**
+     * @param {WebInspector.UISourceCode} uiSourceCode
+     */
+    _addUISourceCode: function(uiSourceCode)
+    {
         this._workspace.project().addUISourceCode(uiSourceCode);
     },
 
+    /**
+     * @param {WebInspector.Event} event
+     */
+    _resourceAdded: function(event)
+    {
+        var resource = /** @type {WebInspector.Resource} */ event.data;
+        switch (resource.type) {
+        case WebInspector.resourceTypes.Stylesheet:
+            this._styleResourceAdded(resource);
+            break;
+        case WebInspector.resourceTypes.Document:
+        case WebInspector.resourceTypes.Script:
+            this._scriptResourceAdded(resource);
+            break;
+        }
+    },
+
     _reset: function()
     {
+        this._uiSourceCodeForResource = {};
         this._stylesSourceMapping.reset();
         // FIXME: We should not populate until the ProjectWillReset event was handled by all listeners. Introduce ProjectDidReset event for that matter.
         setTimeout(this._populate.bind(this), 0);
index 7e1b44c..e69de29 100644 (file)
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// RawSourceCode represents JavaScript resource or HTML resource with inlined scripts
-// as it came from network.
-
-/**
- * @constructor
- * @extends {WebInspector.Object}
- * @param {string} id
- * @param {WebInspector.Script} script
- * @param {WebInspector.Resource} resource
- * @param {WebInspector.NetworkRequest} request
- * @param {WebInspector.SourceMapping} sourceMapping
- */
-WebInspector.RawSourceCode = function(id, script, resource, request, sourceMapping)
-{
-    this.id = id;
-    this.url = script.sourceURL;
-    this.isContentScript = script.isContentScript;
-    this._scripts = [script];
-    this._resource = resource;
-    this._pendingRequest = request;
-    this._sourceMapping = sourceMapping;
-
-    this._uiSourceCode = null;
-    if (this._pendingRequest)
-        this._pendingRequest.addEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, this._finishedLoading, this);
-    else
-        this._uiSourceCode = this._createUISourceCode();
-}
-
-WebInspector.RawSourceCode.Events = {
-    UISourceCodeChanged: "us-source-code-changed"
-}
-
-WebInspector.RawSourceCode.prototype = {
-    /**
-     * @param {WebInspector.Script} script
-     */
-    addScript: function(script)
-    {
-        this._scripts.push(script);
-        if (this._temporaryUISourceCode) {
-            var oldUISourceCode = this._temporaryUISourceCode;
-            this._temporaryUISourceCode = this._createUISourceCode();
-            this.dispatchEventToListeners(WebInspector.RawSourceCode.Events.UISourceCodeChanged, { uiSourceCode: this._temporaryUISourceCode, oldUISourceCode: oldUISourceCode });
-        }
-    },
-
-    /**
-     * @param {WebInspector.DebuggerModel.Location} rawLocation
-     * @return {WebInspector.UILocation}
-     */
-    rawLocationToUILocation: function(rawLocation)
-    {
-        var uiSourceCode = this._uiSourceCode || this._temporaryUISourceCode;
-        if (!uiSourceCode) {
-            this._temporaryUISourceCode = this._createUISourceCode();
-            uiSourceCode = this._temporaryUISourceCode;
-            this.dispatchEventToListeners(WebInspector.RawSourceCode.Events.UISourceCodeChanged, { uiSourceCode: uiSourceCode });
-        }
-        return new WebInspector.UILocation(uiSourceCode, rawLocation.lineNumber, rawLocation.columnNumber || 0);
-    },
-
-    /**
-     * @return {WebInspector.UISourceCode}
-     */
-    _createUISourceCode: function()
-    {
-        var isStandaloneScript = this._scripts.length === 1 && !this._scripts[0].isInlineScript();
-
-        var contentProvider;
-        if (this._resource)
-            contentProvider = this._resource;
-        else if (isStandaloneScript)
-            contentProvider = this._scripts[0];
-        else
-            contentProvider = new WebInspector.ConcatenatedScriptsContentProvider(this._scripts);
-
-        var uiSourceCode = new WebInspector.JavaScriptSource(this.url, this._resource, contentProvider, this._sourceMapping, isStandaloneScript);
-        uiSourceCode.isContentScript = this.isContentScript;
-        return uiSourceCode;
-    },
-
-    /**
-     * @param {WebInspector.UISourceCode} uiSourceCode
-     * @param {number} lineNumber
-     * @param {number} columnNumber
-     * @return {WebInspector.RawLocation}
-     */
-    uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
-    {
-        if (this.url)
-            return WebInspector.debuggerModel.createRawLocationByURL(this.url, lineNumber, columnNumber);
-        return WebInspector.debuggerModel.createRawLocation(this._scripts[0], lineNumber, columnNumber);
-    },
-
-    /**
-     * @return {WebInspector.UISourceCode|null}
-     */
-    uiSourceCode: function()
-    {
-        return this._uiSourceCode || this._temporaryUISourceCode;
-    },
-
-    _finishedLoading: function(event)
-    {
-        this._resource = WebInspector.resourceForURL(this._pendingRequest.url);
-        delete this._pendingRequest;
-        var oldUISourceCode = this._uiSourceCode || this._temporaryUISourceCode;
-        delete this._temporaryUISourceCode;
-        this._uiSourceCode = this._createUISourceCode();
-        this.dispatchEventToListeners(WebInspector.RawSourceCode.Events.UISourceCodeChanged, { uiSourceCode: this._uiSourceCode, oldUISourceCode: oldUISourceCode });
-    }
-}
-
-WebInspector.RawSourceCode.prototype.__proto__ = WebInspector.Object.prototype;
index a16389c..02eb62e 100644 (file)
 WebInspector.ResourceScriptMapping = function(workspace)
 {
     this._workspace = workspace;
-    /** @type {Array.<WebInspector.RawSourceCode>} */
-    this._rawSourceCodes = [];
-    /** @type {Object.<string, WebInspector.RawSourceCode>} */
-    this._rawSourceCodeForScriptId = {};
-    /** @type {Object.<string, WebInspector.RawSourceCode>} */
-    this._rawSourceCodeForURL = {};
-    /** @type {Object.<string, WebInspector.RawSourceCode>} */
-    this._rawSourceCodeForDocumentURL = {};
-    this._rawSourceCodeForUISourceCode = new Map();
     this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
+    this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
+
+    /** @type {Object.<string, WebInspector.UISourceCode>} */
+    this._uiSourceCodeForScriptId = {};
+    this._scriptIdForUISourceCode = new Map();
+    this._temporaryUISourceCodes = new Map();
+    /** @type {Object.<string, number>} */
+    this._nextDynamicScriptIndexForURL = {};
 }
 
 WebInspector.ResourceScriptMapping.prototype = {
@@ -56,8 +55,9 @@ WebInspector.ResourceScriptMapping.prototype = {
     rawLocationToUILocation: function(rawLocation)
     {
         var debuggerModelLocation = /** @type {WebInspector.DebuggerModel.Location} */ rawLocation;
-        var rawSourceCode = this._rawSourceCodeForScriptId[debuggerModelLocation.scriptId];
-        return rawSourceCode.rawLocationToUILocation(debuggerModelLocation);
+        var script = WebInspector.debuggerModel.scriptForId(debuggerModelLocation.scriptId);
+        var uiSourceCode = this._uiSourceCodeForScriptId[debuggerModelLocation.scriptId];
+        return new WebInspector.UILocation(uiSourceCode, debuggerModelLocation.lineNumber, debuggerModelLocation.columnNumber || 0);
     },
 
     /**
@@ -68,8 +68,9 @@ WebInspector.ResourceScriptMapping.prototype = {
      */
     uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
     {
-        var rawSourceCode = this._rawSourceCodeForUISourceCode.get(uiSourceCode);
-        return rawSourceCode.uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber);
+        var scriptId = this._scriptIdForUISourceCode.get(uiSourceCode);
+        var script = WebInspector.debuggerModel.scriptForId(scriptId);
+        return WebInspector.debuggerModel.createRawLocation(script, lineNumber, columnNumber);
     },
 
     /**
@@ -77,137 +78,147 @@ WebInspector.ResourceScriptMapping.prototype = {
      */
     addScript: function(script)
     {
-        var resource = null;
-        var request = null;
+        console.assert(!this._uiSourceCodeForScriptId[script.scriptId]);
+
+        var isDynamicScript = false;
         if (!script.isAnonymousScript()) {
-            // First lookup the resource that has already been loaded.
-            resource = WebInspector.resourceForURL(script.sourceURL);
-            // Ignore resource in case it has not yet finished loading.
-            if (resource && resource.request && !resource.request.finished)
-                resource = null;
-            // Only bind inline and standalone scripts.
-            if (resource && !this._shouldBindScriptToContentProvider(script, resource))
-                resource = null;
-            if (!resource) {
-                // When there is no resource, lookup in-flight requests.
-                request = WebInspector.networkManager.inflightRequestForURL(script.sourceURL);
-                // Only bind inline and standalone scripts.
-                if (request && !this._shouldBindScriptToContentProvider(script, request))
-                  request = null;
-            }
-        }
-        console.assert(!resource || !request);
-
-        var isInlineScript = script.isInlineScript() && (request || resource);
-        // If either of these exists, we bind script to the resource.
-        if (isInlineScript) {
-            var rawSourceCode = this._rawSourceCodeForDocumentURL[script.sourceURL];
-            if (rawSourceCode) {
-                rawSourceCode.addScript(script);
-                this._bindScriptToRawSourceCode(script, rawSourceCode);
-                return;
-            }
+            var uiSourceCode = this._workspace.uiSourceCodeForURL(script.sourceURL);
+            isDynamicScript = !!uiSourceCode && uiSourceCode.contentType() === WebInspector.resourceTypes.Document && !script.isInlineScript();
+            if (uiSourceCode && !isDynamicScript && !this._temporaryUISourceCodes.get(uiSourceCode))
+                this._bindUISourceCodeToScripts(uiSourceCode, [script]);
         }
+        if (!this._uiSourceCodeForScriptId[script.scriptId])
+            this._addOrReplaceTemporaryUISourceCode(script, isDynamicScript);
 
-        var rawSourceCode = new WebInspector.RawSourceCode(script.scriptId, script, resource, request, this);
-        this._rawSourceCodes.push(rawSourceCode);
-        this._bindScriptToRawSourceCode(script, rawSourceCode);
-        if (isInlineScript)
-            this._rawSourceCodeForDocumentURL[script.sourceURL] = rawSourceCode;
-
-        if (rawSourceCode.uiSourceCode())
-            this._uiSourceCodeAdded(rawSourceCode, rawSourceCode.uiSourceCode());
-        rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeChanged, this._handleUISourceCodeChanged, this);
+        console.assert(this._uiSourceCodeForScriptId[script.scriptId]);
     },
 
     /**
-     * @param {WebInspector.Script} script
-     * @param {WebInspector.ContentProvider} contentProvider
-     * @return {boolean}
+     * @param {WebInspector.UISourceCode} uiSourceCode
+     * @param {Array.<WebInspector.Script>} scripts
      */
-    _shouldBindScriptToContentProvider: function(script, contentProvider)
+    _bindUISourceCodeToScripts: function(uiSourceCode, scripts)
     {
-        if (script.isInlineScript())
-            return contentProvider.contentType() === WebInspector.resourceTypes.Document;
-        return contentProvider.contentType() === WebInspector.resourceTypes.Script;
+        console.assert(scripts.length);
+
+        for (var i = 0; i < scripts.length; ++i) {
+            this._uiSourceCodeForScriptId[scripts[i].scriptId] = uiSourceCode;
+            scripts[i].setSourceMapping(this);
+        }
+        uiSourceCode.isContentScript = scripts[0].isContentScript;
+        uiSourceCode.setSourceMapping(this);
+        this._scriptIdForUISourceCode.put(uiSourceCode, scripts[0].scriptId);
     },
 
     /**
-     * @param {WebInspector.Event} event
+     * @param {string} sourceURL
+     * @param {boolean} isInlineScript
+     * @return {Array.<WebInspector.Script>}
      */
-    _handleUISourceCodeChanged: function(event)
+    _scriptsForSourceURL: function(sourceURL, isInlineScript)
     {
-        var rawSourceCode = /** @type {WebInspector.RawSourceCode} */ event.target;
-        var uiSourceCode = /** @type {WebInspector.UISourceCode} */ event.data.uiSourceCode;
-        var oldUISourceCode = /** @type {WebInspector.UISourceCode} */ event.data.oldUISourceCode;
-        if (!oldUISourceCode)
-            this._uiSourceCodeAdded(rawSourceCode, uiSourceCode);
-        else
-            this._uiSourceCodeReplaced(rawSourceCode, oldUISourceCode, uiSourceCode);
+        function filter(script)
+        {
+            return script.sourceURL === sourceURL && script.isInlineScript() === isInlineScript;
+        }
+
+        return Object.values(WebInspector.debuggerModel.scripts).filter(filter);
     },
 
     /**
-     * @param {WebInspector.RawSourceCode} rawSourceCode
-     * @paran {WebInspector.UISourceCode} uiSourceCode
+     * @param {WebInspector.Script} script
+     * @param {boolean} isDynamicScript
      */
-    _uiSourceCodeAdded: function(rawSourceCode, uiSourceCode)
+    _addOrReplaceTemporaryUISourceCode: function(script, isDynamicScript)
     {
-        if (!uiSourceCode.url)
-            return;
-        this._rawSourceCodeForUISourceCode.put(uiSourceCode, rawSourceCode);
-        this._workspace.project().addUISourceCode(uiSourceCode);
+        var scripts = script.isInlineScript() ? this._scriptsForSourceURL(script.sourceURL, true) : [script];
+
+        var oldUISourceCode;
+        for (var i = 0; i < scripts.length; ++i) {
+            oldUISourceCode = this._uiSourceCodeForScriptId[scripts[i].scriptId];
+            if (oldUISourceCode)
+                break;
+        }
+        console.assert(!oldUISourceCode || this._temporaryUISourceCodes.get(oldUISourceCode));
+
+        var contentProvider = script.isInlineScript() ? new WebInspector.ConcatenatedScriptsContentProvider(scripts) : script;
+        var url = script.sourceURL;
+        if (isDynamicScript) {
+            var nextIndex = this._nextDynamicScriptIndexForURL[script.sourceURL] || 1;
+            url += " (" + nextIndex + ")";
+            this._nextDynamicScriptIndexForURL[script.sourceURL] = nextIndex + 1;
+        }
+        var uiSourceCode = new WebInspector.JavaScriptSource(url, null, contentProvider, !script.isInlineScript());
+        this._temporaryUISourceCodes.put(uiSourceCode, uiSourceCode);
+        this._bindUISourceCodeToScripts(uiSourceCode, scripts);
+
+        if (!script.sourceURL)
+            return uiSourceCode;
+
+        if (oldUISourceCode)
+            this._uiSourceCodeReplaced(oldUISourceCode, uiSourceCode);
+        else
+            this._workspace.project().addUISourceCode(uiSourceCode);
+        return uiSourceCode;
     },
 
-    /**
-     * @param {WebInspector.RawSourceCode} rawSourceCode
-     * @param {WebInspector.UISourceCode} oldUISourceCode
-     * @param {WebInspector.UISourceCode} uiSourceCode
-     */
-    _uiSourceCodeReplaced: function(rawSourceCode, oldUISourceCode, uiSourceCode)
+    _uiSourceCodeAddedToWorkspace: function(event)
     {
-        if (!uiSourceCode.url)
+        var uiSourceCode = /** @type {WebInspector.UISourceCode} */ event.data;
+        console.assert(!this._scriptIdForUISourceCode.get(uiSourceCode) || this._temporaryUISourceCodes.get(uiSourceCode));
+        if (!uiSourceCode.url || this._temporaryUISourceCodes.get(uiSourceCode))
             return;
-        this._rawSourceCodeForUISourceCode.remove(oldUISourceCode);
-        this._rawSourceCodeForUISourceCode.put(uiSourceCode, rawSourceCode);
-
-        for (var i = 0; i < rawSourceCode._scripts.length; ++i)
-            rawSourceCode._scripts[i].setSourceMapping(this);
-        this._workspace.project().replaceUISourceCode(oldUISourceCode, uiSourceCode);
+        this._addUISourceCode(uiSourceCode);
     },
 
     /**
-     * @param {WebInspector.RawSourceCode} rawSourceCode
-     * @paran {WebInspector.UISourceCode} uiSourceCode
+     * @param {WebInspector.UISourceCode} uiSourceCode
      */
-    _uiSourceCodeRemoved: function(rawSourceCode, uiSourceCode)
+    _addUISourceCode: function(uiSourceCode)
     {
-        if (!uiSourceCode.url)
+        var isInlineScript;
+        switch (uiSourceCode.contentType()) {
+        case WebInspector.resourceTypes.Document:
+            isInlineScript = true;
+            break;
+        case WebInspector.resourceTypes.Script:
+            isInlineScript = false;
+            break;
+        default:
+            return;
+        }
+
+        var scripts = this._scriptsForSourceURL(uiSourceCode.url, isInlineScript);
+        if (!scripts.length)
             return;
-        this._rawSourceCodeForUISourceCode.remove(uiSourceCode);
+
+        var oldUISourceCode = this._uiSourceCodeForScriptId[scripts[0].scriptId];
+        this._bindUISourceCodeToScripts(uiSourceCode, scripts);
+
+        if (oldUISourceCode) {
+            console.assert(this._temporaryUISourceCodes.get(oldUISourceCode));
+            this._uiSourceCodeReplaced(oldUISourceCode, uiSourceCode);
+        }
+
+        console.assert(this._scriptIdForUISourceCode.get(uiSourceCode) && !this._temporaryUISourceCodes.get(uiSourceCode));
     },
 
     /**
-     * @param {WebInspector.Script} script
-     * @param {WebInspector.RawSourceCode} rawSourceCode
+     * @param {WebInspector.UISourceCode} oldUISourceCode
+     * @param {WebInspector.UISourceCode} uiSourceCode
      */
-    _bindScriptToRawSourceCode: function(script, rawSourceCode)
+    _uiSourceCodeReplaced: function(oldUISourceCode, uiSourceCode)
     {
-        this._rawSourceCodeForScriptId[script.scriptId] = rawSourceCode;
-        this._rawSourceCodeForURL[script.sourceURL] = rawSourceCode;
-        script.setSourceMapping(this);
+        this._temporaryUISourceCodes.remove(oldUISourceCode);
+        this._scriptIdForUISourceCode.remove(oldUISourceCode);
+        this._workspace.project().replaceUISourceCode(oldUISourceCode, uiSourceCode);
     },
 
     _reset: function()
     {
-        for (var i = 0; i < this._rawSourceCodes.length; ++i) {
-            var rawSourceCode = this._rawSourceCodes[i];
-            this._uiSourceCodeRemoved(rawSourceCode, rawSourceCode.uiSourceCode());
-            rawSourceCode.removeAllListeners();
-        }
-        this._rawSourceCodes = [];
-        this._rawSourceCodeForScriptId = {};
-        this._rawSourceCodeForURL = {};
-        this._rawSourceCodeForDocumentURL = {};
-        this._rawSourceCodeForUISourceCode.clear();
-    }
+        this._uiSourceCodeForScriptId = {};
+        this._scriptIdForUISourceCode.clear();
+        this._temporaryUISourceCodes.clear();
+        this._nextDynamicScriptIndexForURL = {};
+    },
 }
index d92a2d3..0605f7c 100644 (file)
@@ -81,6 +81,7 @@ WebInspector.ScriptSnippetModel.prototype = {
     _addScriptSnippet: function(snippet)
     {
         var snippetJavaScriptSource = new WebInspector.SnippetJavaScriptSource(snippet.id, snippet.name, new WebInspector.SnippetContentProvider(snippet), this);
+        snippetJavaScriptSource.setSourceMapping(this._snippetScriptMapping); 
         this._snippetJavaScriptSourceForSnippetId[snippet.id] = snippetJavaScriptSource;
         this._workspace.project().addUISourceCode(snippetJavaScriptSource);
         return snippetJavaScriptSource;
@@ -278,7 +279,8 @@ WebInspector.ScriptSnippetModel.prototype = {
      */
     _createUISourceCodeForScript: function(script)
     {
-        var uiSourceCode = new WebInspector.JavaScriptSource(script.sourceURL, null, script, this._snippetScriptMapping, false);
+        var uiSourceCode = new WebInspector.JavaScriptSource(script.sourceURL, null, script, false);
+        uiSourceCode.setSourceMapping(this._snippetScriptMapping); 
         uiSourceCode.isSnippetEvaluation = true;
         this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode;
         this._scriptForUISourceCode.put(uiSourceCode, script);
@@ -372,7 +374,7 @@ WebInspector.ScriptSnippetModel.prototype.__proto__ = WebInspector.Object.protot
  */
 WebInspector.SnippetJavaScriptSource = function(snippetId, snippetName, contentProvider, scriptSnippetModel)
 {
-    WebInspector.JavaScriptSource.call(this, snippetName, null, contentProvider, scriptSnippetModel.scriptMapping, true);
+    WebInspector.JavaScriptSource.call(this, snippetName, null, contentProvider, true);
     this._snippetId = snippetId;
     this._scriptSnippetModel = scriptSnippetModel;
     this.isSnippet = true;
index 17aaaa0..47c8c34 100644 (file)
  * @param {string} url
  * @param {WebInspector.Resource} resource
  * @param {WebInspector.ContentProvider} contentProvider
- * @param {WebInspector.SourceMapping=} sourceMapping
  */
-WebInspector.UISourceCode = function(url, resource, contentProvider, sourceMapping)
+WebInspector.UISourceCode = function(url, resource, contentProvider)
 {
     this._url = url;
     this._resource = resource;
     this._parsedURL = new WebInspector.ParsedURL(url);
     this._contentProvider = contentProvider;
-    this._sourceMapping = sourceMapping;
     this.isContentScript = false;
     /**
      * @type Array.<function(?string,boolean,string)>
@@ -384,6 +382,8 @@ WebInspector.UISourceCode.prototype = {
      */
     uiLocationToRawLocation: function(lineNumber, columnNumber)
     {
+        if (!this._sourceMapping)
+            return null;
         var location = this._formatterMapping.formattedToOriginal(lineNumber, columnNumber);
         return this._sourceMapping.uiLocationToRawLocation(this, location[0], location[1]);
     },
@@ -537,6 +537,14 @@ WebInspector.UISourceCode.prototype = {
         return null;
     },
 
+    /**
+     * @param {WebInspector.SourceMapping} sourceMapping
+     */
+    setSourceMapping: function(sourceMapping)
+    {
+        this._sourceMapping = sourceMapping;
+    },
+
     formattedChanged: function()
     {
     }
index 5de89ad..75b8914 100644 (file)
     <file>NavigatorView.js</file>
     <file>NetworkItemView.js</file>
     <file>NetworkLog.js</file>
+    <file>NetworkUISourceCodeProvider.js</file>
     <file>NetworkManager.js</file>
     <file>NetworkPanel.js</file>
     <file>NetworkPanelDescriptor.js</file>
     <file>ProgressBar.js</file>
     <file>PropertiesSection.js</file>
     <file>PropertiesSidebarPane.js</file>
-    <file>RawSourceCode.js</file>
     <file>RemoteObject.js</file>
     <file>Resource.js</file>
     <file>RequestCookiesView.js</file>
     <file>StyleSheetOutlineDialog.js</file>
     <file>StyleSource.js</file>
     <file>StylesSourceMapping.js</file>
-    <file>StylesUISourceCodeProvider.js</file>
     <file>StylesSidebarPane.js</file>
     <file>TabbedEditorContainer.js</file>
     <file>TabbedPane.js</file>
index 1beefed..cb9b8e8 100644 (file)
@@ -139,7 +139,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     <script type="text/javascript" src="Workspace.js"></script>
     <script type="text/javascript" src="BreakpointManager.js"></script>
     <script type="text/javascript" src="ContentProviders.js"></script>
-    <script type="text/javascript" src="RawSourceCode.js"></script>
     <script type="text/javascript" src="ResourceScriptMapping.js"></script>
     <script type="text/javascript" src="CompilerScriptMapping.js"></script>
     <script type="text/javascript" src="SASSSourceMapping.js"></script>
@@ -162,8 +161,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     <script type="text/javascript" src="ScriptSnippetModel.js"></script>
     <script type="text/javascript" src="ProgressBar.js"></script>
     <script type="text/javascript" src="StylesSourceMapping.js"></script>
-    <script type="text/javascript" src="StylesUISourceCodeProvider.js"></script>
     <script type="text/javascript" src="StyleSource.js"></script>
+    <script type="text/javascript" src="NetworkUISourceCodeProvider.js"></script>
     <script type="text/javascript" src="ElementsPanelDescriptor.js"></script>
     <script type="text/javascript" src="NetworkPanelDescriptor.js"></script>
     <script type="text/javascript" src="ScriptsPanelDescriptor.js"></script>
index 3b98ed7..782964f 100644 (file)
@@ -523,7 +523,7 @@ WebInspector._doLoadedDoneWithCapabilities = function()
 
     this.scriptSnippetModel = new WebInspector.ScriptSnippetModel(this.workspace);
     new WebInspector.DebuggerScriptMapping(this.workspace);
-    new WebInspector.StylesUISourceCodeProvider(this.workspace);
+    new WebInspector.NetworkUISourceCodeProvider(this.workspace);
     if (WebInspector.experimentsSettings.sass.isEnabled())
         new WebInspector.SASSSourceMapping(this.workspace);