Web Inspector: Fix inconsistencies in NetworkUISourceCodeProvider implementation.
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Sep 2012 07:40:56 +0000 (07:40 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Sep 2012 07:40:56 +0000 (07:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=95752

Reviewed by Alexander Pavlov.

Source/WebCore:

NetworkUISourceCodeProvider does not receive ResourceAdded event until resource is finished anymore.
StylesSourceMapping now listens for workspace event instead of being called directly by NetworkUISourceCodeProvider.
StylesSourceMapping is now created from inspector.js.
ProjectDidReset event introduced instead of setTimeout hacks in mappings.

* inspector/front-end/NetworkUISourceCodeProvider.js:
(WebInspector.NetworkUISourceCodeProvider):
(WebInspector.NetworkUISourceCodeProvider.prototype._resourceAdded):
(WebInspector.NetworkUISourceCodeProvider.prototype._projectWillReset):
(WebInspector.NetworkUISourceCodeProvider.prototype._projectDidReset):
* inspector/front-end/ResourceTreeModel.js:
(WebInspector.ResourceTreeModel):
(WebInspector.ResourceTreeModel.prototype._onRequestFinished):
* inspector/front-end/ScriptSnippetModel.js:
(WebInspector.ScriptSnippetModel):
(WebInspector.ScriptSnippetModel.prototype._projectWillReset):
(WebInspector.ScriptSnippetModel.prototype._projectDidReset):
* inspector/front-end/StylesSourceMapping.js:
(WebInspector.StylesSourceMapping):
(WebInspector.StylesSourceMapping.prototype._uiSourceCodeAddedToWorkspace):
(WebInspector.StylesSourceMapping.prototype._addUISourceCode):
(WebInspector.StylesSourceMapping.prototype._reset):
* inspector/front-end/Workspace.js:
(WebInspector.WorkspaceController.prototype._mainFrameNavigated):
(WebInspector.Project.prototype.reset):
* inspector/front-end/inspector.js:

LayoutTests:

* http/tests/inspector/network/network-request-revision-content-expected.txt:
* http/tests/inspector/network/network-request-revision-content.html:
* inspector/console/console-uncaught-exception-expected.txt:
* inspector/debugger/network-uisourcecode-provider-expected.txt:
* inspector/debugger/network-uisourcecode-provider.html:
* inspector/debugger/script-snippet-model.html:
* inspector/debugger/scripts-panel.html:

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/network/network-request-revision-content-expected.txt
LayoutTests/http/tests/inspector/network/network-request-revision-content.html
LayoutTests/inspector/console/console-uncaught-exception-expected.txt
LayoutTests/inspector/debugger/network-uisourcecode-provider-expected.txt
LayoutTests/inspector/debugger/network-uisourcecode-provider.html
LayoutTests/inspector/debugger/script-snippet-model.html
LayoutTests/inspector/debugger/scripts-panel.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/NetworkUISourceCodeProvider.js
Source/WebCore/inspector/front-end/ResourceTreeModel.js
Source/WebCore/inspector/front-end/ScriptSnippetModel.js
Source/WebCore/inspector/front-end/StylesSourceMapping.js
Source/WebCore/inspector/front-end/Workspace.js
Source/WebCore/inspector/front-end/inspector.js

index f6dcb1a..97715be 100644 (file)
@@ -1,3 +1,18 @@
+2012-09-04  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Fix inconsistencies in NetworkUISourceCodeProvider implementation.
+        https://bugs.webkit.org/show_bug.cgi?id=95752
+
+        Reviewed by Alexander Pavlov.
+
+        * http/tests/inspector/network/network-request-revision-content-expected.txt:
+        * http/tests/inspector/network/network-request-revision-content.html:
+        * inspector/console/console-uncaught-exception-expected.txt:
+        * inspector/debugger/network-uisourcecode-provider-expected.txt:
+        * inspector/debugger/network-uisourcecode-provider.html:
+        * inspector/debugger/script-snippet-model.html:
+        * inspector/debugger/scripts-panel.html:
+
 2012-09-06  Adam Barth  <abarth@webkit.org>
 
         Chromium should call restrictScaleFactorToInitialScaleIfNotUserScalable unless/until userScalable is supported directly.
index 93a9541..f91ba4f 100644 (file)
@@ -1,6 +1,6 @@
 Tests how revision requests content if original content was not loaded yet.
 
 Bug 63631
-http://127.0.0.1:8000/inspector/network/resource/style.css
+http://127.0.0.1:8000/inspector/network/resources/style.css
 
 
index e7d39b5..1553c4a 100644 (file)
@@ -7,14 +7,13 @@ function loadStylesheet()
     var css = document.createElement("link");
     css.rel = "stylesheet";
     css.type = "text/css";
-    css.href = "resource/style.css";
+    css.href = "resources/style.css";
     document.head.appendChild(css);
 }
 
 function test()
 {
-    InspectorTest.addConsoleSniffer(step2, true);
-    InspectorTest.addSniffer(WebInspector.NetworkUISourceCodeProvider.prototype, "_resourceAdded", true);
+    WebInspector.workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, step2);
     InspectorTest.evaluateInPage("loadStylesheet()");
 
     var resource;
index 84dd7d0..46cf0bb 100644 (file)
@@ -4,7 +4,7 @@ CONSOLE MESSAGE: line 6: Error: Exception in setTimeout callback.
 Tests that uncaught exceptions are logged into console.Bug 47250.
 
 
-Error: Exception in inline script. uncaught-in-iframe.html:18
-Error: Exception in 'load' event listener. uncaught-in-iframe.html:11
+Error: Exception in inline script. resources/uncaught-in-iframe.html:18
+Error: Exception in 'load' event listener. resources/uncaught-in-iframe.html:11
 Error: Exception in setTimeout callback. uncaught-in-iframe.html:6
 
index 04991f2..9eb1be5 100644 (file)
@@ -1,50 +1,25 @@
 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: http://fake.url/1
 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: http://fake.url/2
 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
+UISourceCode: http://fake.url/3
 Mime type: text/css
 UISourceCode content: <stylesheet resource content>
 
index 9d927f6..3a3c1a1 100644 (file)
@@ -7,7 +7,7 @@
 function test()
 {
     var mockContentsMap = {};
-    var lastResouceId = 1;
+    var lastResourceId = 0;
 
     NetworkAgent.getResponseBody = function(requestId, callback)
     {
@@ -19,10 +19,10 @@ function test()
         callback(undefined, mockContentsMap[url], false);
     }
 
-    function createResourceMock(type, withPendingRequest, content)
+    function createResourceMock(type, content)
     {
         var documentURL = "http://fake.url";
-        var resourceId = ++lastResouceId + "";
+        var resourceId = ++lastResourceId + "";
         var url = documentURL + "/" + resourceId;
         var frameId = "frame-id";
         var loaderId = "loader-id";
@@ -39,13 +39,7 @@ function test()
             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);
+        var resource = new WebInspector.Resource(null, url, documentURL, frameId, loaderId, type, mimeType);
         mockContentsMap[url] = content;
         WebInspector.resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resource);
 
@@ -67,46 +61,12 @@ function test()
     }
 
     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);
+            var resource = createResourceMock(WebInspector.resourceTypes.Document, "<document resource content>");
 
             function uiSourceCodeAdded(uiSourceCode)
             {
@@ -119,7 +79,7 @@ function test()
             var networkUISourceCodeProvider = createNetworkUISourceCodeProvider();
             InspectorTest.addResult("Creating resource.");
             InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded);
-            var resource = createResourceMock(WebInspector.resourceTypes.Script, false, "<script resource content>");
+            var resource = createResourceMock(WebInspector.resourceTypes.Script, "<script resource content>");
 
             function uiSourceCodeAdded(uiSourceCode)
             {
@@ -127,36 +87,12 @@ function test()
             }
         },
 
-        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>");
+            var resource = createResourceMock(WebInspector.resourceTypes.Stylesheet, "<stylesheet resource content>");
 
             function uiSourceCodeAdded(uiSourceCode)
             {
index 79e9dd2..ebd8996 100644 (file)
@@ -15,6 +15,7 @@ function test()
     WebInspector.experimentsSettings.snippetsSupport = {};
     WebInspector.experimentsSettings.snippetsSupport.isEnabled = function() { return true; };
     var workspace = new WebInspector.Workspace();
+    var workspaceController = new WebInspector.WorkspaceController(workspace);
     WebInspector.scriptSnippetModel = new WebInspector.ScriptSnippetModel(workspace);
 
     InspectorTest.runDebuggerTestSuite([
@@ -27,11 +28,11 @@ function test()
             WebInspector.scriptSnippetModel.renameScriptSnippet(snippetJavaScriptSource, snippetName);
             workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCodeAdded);
             InspectorTest.addResult("Resetting snippet script mapping.");
-            workspace.project().reset();
-            InspectorTest.assertTrue(!workspace.uiSourceCodes().length, "Snippets script mapping should not have any uiSourceCodes after reset.");
+            workspaceController._mainFrameNavigated();
 
             function uiSourceCodeAdded(event)
             {
+                InspectorTest.assertEquals(1, workspace.uiSourceCodes().length, "Only one snippet uiSourceCode should be present after project navigation.");
                 var uiSourceCode = event.data;
                 if (uiSourceCode.url.indexOf(snippetName) === -1)
                     return;
index e5bcc38..69f441b 100644 (file)
@@ -64,6 +64,7 @@ function test()
         function testReset(next)
         {
             var workspace = new WebInspector.Workspace();
+            var workspaceController = new WebInspector.WorkspaceController(workspace);
             var panel = new WebInspector.ScriptsPanel(workspace);
             panel.show();
 
@@ -77,7 +78,7 @@ function test()
 
             InspectorTest.dumpScriptsNavigator(panel._navigator);
 
-            workspace.project().reset();
+            workspaceController._mainFrameNavigated();
             workspace.project().addUISourceCode(uiSourceCodeBar);
             InspectorTest.dumpScriptsNavigator(panel._navigator);
 
index 5eb3b8e..544ad5d 100644 (file)
@@ -1,3 +1,37 @@
+2012-09-04  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Fix inconsistencies in NetworkUISourceCodeProvider implementation.
+        https://bugs.webkit.org/show_bug.cgi?id=95752
+
+        Reviewed by Alexander Pavlov.
+
+        NetworkUISourceCodeProvider does not receive ResourceAdded event until resource is finished anymore.
+        StylesSourceMapping now listens for workspace event instead of being called directly by NetworkUISourceCodeProvider.
+        StylesSourceMapping is now created from inspector.js.
+        ProjectDidReset event introduced instead of setTimeout hacks in mappings.
+
+        * inspector/front-end/NetworkUISourceCodeProvider.js:
+        (WebInspector.NetworkUISourceCodeProvider):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._resourceAdded):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._projectWillReset):
+        (WebInspector.NetworkUISourceCodeProvider.prototype._projectDidReset):
+        * inspector/front-end/ResourceTreeModel.js:
+        (WebInspector.ResourceTreeModel):
+        (WebInspector.ResourceTreeModel.prototype._onRequestFinished):
+        * inspector/front-end/ScriptSnippetModel.js:
+        (WebInspector.ScriptSnippetModel):
+        (WebInspector.ScriptSnippetModel.prototype._projectWillReset):
+        (WebInspector.ScriptSnippetModel.prototype._projectDidReset):
+        * inspector/front-end/StylesSourceMapping.js:
+        (WebInspector.StylesSourceMapping):
+        (WebInspector.StylesSourceMapping.prototype._uiSourceCodeAddedToWorkspace):
+        (WebInspector.StylesSourceMapping.prototype._addUISourceCode):
+        (WebInspector.StylesSourceMapping.prototype._reset):
+        * inspector/front-end/Workspace.js:
+        (WebInspector.WorkspaceController.prototype._mainFrameNavigated):
+        (WebInspector.Project.prototype.reset):
+        * inspector/front-end/inspector.js:
+
 2012-09-06  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r127700.
index 1d529e1..f1625f6 100644 (file)
@@ -36,8 +36,8 @@ 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._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._projectWillReset, this);
+    this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectDidReset, this._projectDidReset, this);
 
     this._uiSourceCodeForResource = {};
 }
@@ -59,76 +59,38 @@ WebInspector.NetworkUISourceCodeProvider.prototype = {
     },
 
     /**
-     * @param {WebInspector.Resource} resource
-     */
-    _styleResourceAdded: function(resource)
-    {
-        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;
+        if (this._uiSourceCodeForResource[resource.url])
+            return;
+        var uiSourceCode;
         switch (resource.type) {
         case WebInspector.resourceTypes.Stylesheet:
-            this._styleResourceAdded(resource);
+            uiSourceCode = new WebInspector.StyleSource(resource);
             break;
         case WebInspector.resourceTypes.Document:
+            uiSourceCode = new WebInspector.JavaScriptSource(resource.url, resource, resource, false);
+            break;
         case WebInspector.resourceTypes.Script:
-            this._scriptResourceAdded(resource);
+            uiSourceCode = new WebInspector.JavaScriptSource(resource.url, resource, resource, true);
             break;
         }
+        if (uiSourceCode) {
+            this._uiSourceCodeForResource[resource.url] = uiSourceCode;
+            this._workspace.project().addUISourceCode(uiSourceCode);
+        }
     },
 
-    _reset: function()
+    _projectWillReset: 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);
+    },
+
+    _projectDidReset: function()
+    {
+        this._populate();
     }
 }
index 20b0ef6..d503dae 100644 (file)
@@ -35,8 +35,7 @@
  */
 WebInspector.ResourceTreeModel = function(networkManager)
 {
-    networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestUpdated, this._onRequestUpdated, this);
-    networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished, this._onRequestUpdated, this);
+    networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished, this._onRequestFinished, this);
     networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestUpdateDropped, this._onRequestUpdateDropped, this);
 
     WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this);
@@ -172,7 +171,7 @@ WebInspector.ResourceTreeModel.prototype = {
     /**
      * @param {WebInspector.Event} event
      */
-    _onRequestUpdated: function(event)
+    _onRequestFinished: function(event)
     {
         if (!this._cachedResourcesProcessed)
             return;
index 0605f7c..60a6672 100644 (file)
@@ -43,7 +43,8 @@ WebInspector.ScriptSnippetModel = function(workspace)
     this._snippetStorage = new WebInspector.SnippetStorage("script", "Script snippet #");
     this._lastSnippetEvaluationIndexSetting = WebInspector.settings.createSetting("lastSnippetEvaluationIndex", 0);
     this._snippetScriptMapping = new WebInspector.SnippetScriptMapping(this);
-    this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
+    this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._projectWillReset, this);
+    this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectDidReset, this._projectDidReset, this);
     this._loadSnippets();
 }
 
@@ -352,13 +353,17 @@ WebInspector.ScriptSnippetModel.prototype = {
         return snippetId;
     },
 
-    _reset: function()
+    _projectWillReset: function()
     {
         var removedUISourceCodes = this._releasedUISourceCodes();
         this._uiSourceCodeForScriptId = {};
         this._scriptForUISourceCode = new Map();
         this._snippetJavaScriptSourceForSnippetId = {};
-        setTimeout(this._loadSnippets.bind(this), 0);
+    },
+
+    _projectDidReset: function()
+    {
+        this._loadSnippets();
     }
 }
 
index d70cce2..0767e9a 100644 (file)
 /**
  * @constructor
  * @implements {WebInspector.SourceMapping}
-*/
-WebInspector.StylesSourceMapping = function()
+ * @param {WebInspector.Workspace} workspace
+ */
+WebInspector.StylesSourceMapping = function(workspace)
 {
+    this._workspace = workspace;
+    this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
+    this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
+
     this._uiSourceCodeForURL = {};
 }
 
 WebInspector.StylesSourceMapping.prototype = {
     /**
-     * @param {WebInspector.UISourceCode} uiSourceCode
-     */
-    addUISourceCode: function(uiSourceCode)
-    {
-        this._uiSourceCodeForURL[uiSourceCode.url] = uiSourceCode;
-        WebInspector.cssModel.setSourceMapping(uiSourceCode.url, this);
-    },
-
-    /**
      * @param {WebInspector.RawLocation} rawLocation
      * @return {WebInspector.UILocation}
      */
@@ -69,7 +65,28 @@ WebInspector.StylesSourceMapping.prototype = {
         return new WebInspector.CSSLocation(uiSourceCode.contentURL() || "", lineNumber);
     },
 
-    reset: function()
+    _uiSourceCodeAddedToWorkspace: function(event)
+    {
+        var uiSourceCode = /** @type {WebInspector.UISourceCode} */ event.data;
+        if (!uiSourceCode.url || this._uiSourceCodeForURL[uiSourceCode.url])
+            return;
+        if (uiSourceCode.contentType() !== WebInspector.resourceTypes.StyleSheet)
+            return;
+            
+        this._addUISourceCode(uiSourceCode);
+    },
+
+    /**
+     * @param {WebInspector.UISourceCode} uiSourceCode
+     */
+    _addUISourceCode: function(uiSourceCode)
+    {
+        this._uiSourceCodeForURL[uiSourceCode.url] = uiSourceCode;
+        uiSourceCode.setSourceMapping(this);
+        WebInspector.cssModel.setSourceMapping(uiSourceCode.url, this);
+    },
+
+    _reset: function()
     {
         this._uiSourceCodeForURL = {};
         WebInspector.cssModel.resetSourceMappings();
index 6ccf405..05087c8 100644 (file)
@@ -41,7 +41,9 @@ WebInspector.WorkspaceController.prototype = {
     _mainFrameNavigated: function()
     {
         WebInspector.Revision.filterOutStaleRevisions();
+        this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectWillReset, this._workspace.project());
         this._workspace.project().reset();
+        this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectDidReset, this._workspace.project());
     }
 }
 
@@ -62,7 +64,6 @@ WebInspector.Project = function(workspace)
 WebInspector.Project.prototype = {
     reset: function()
     {
-        this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectWillReset, this);
         this._uiSourceCodes = [];
     },
 
@@ -131,7 +132,8 @@ WebInspector.Workspace = function()
 
 WebInspector.Workspace.Events = {
     UISourceCodeContentCommitted: "UISourceCodeContentCommitted",
-    ProjectWillReset: "ProjectWillReset"
+    ProjectWillReset: "ProjectWillReset",
+    ProjectDidReset: "ProjectDidReset"
 }
 
 WebInspector.Workspace.prototype = {
index 782964f..ffc1f7b 100644 (file)
@@ -524,6 +524,7 @@ WebInspector._doLoadedDoneWithCapabilities = function()
     this.scriptSnippetModel = new WebInspector.ScriptSnippetModel(this.workspace);
     new WebInspector.DebuggerScriptMapping(this.workspace);
     new WebInspector.NetworkUISourceCodeProvider(this.workspace);
+    new WebInspector.StylesSourceMapping(this.workspace);
     if (WebInspector.experimentsSettings.sass.isEnabled())
         new WebInspector.SASSSourceMapping(this.workspace);