Reviewed by Pavel Feldman.
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jul 2011 14:38:40 +0000 (14:38 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jul 2011 14:38:40 +0000 (14:38 +0000)
Web Inspector: [refactoring] Remove dependencies of components requiring network resource list from network panel
https://bugs.webkit.org/show_bug.cgi?id=62477

Source/WebCore:

* inspector/front-end/AuditsPanel.js:
* inspector/front-end/ExtensionServer.js:
(WebInspector.ExtensionServer):
(WebInspector.ExtensionServer.prototype._inspectedURLChanged):
(WebInspector.ExtensionServer.prototype._onGetHAR):
(WebInspector.ExtensionServer.prototype.initExtensions):
* inspector/front-end/HAREntry.js:
(WebInspector.HARLog):
(WebInspector.HARLog.prototype.build):
* inspector/front-end/NetworkManager.js:
(WebInspector.NetworkLog):
(WebInspector.NetworkLog.prototype.get resources):
(WebInspector.NetworkLog.prototype._onInspectedURLChanged):
(WebInspector.NetworkLog.prototype._onResourceStarted):
* inspector/front-end/NetworkPanel.js:
(WebInspector.NetworkPanel.prototype._reset):
(WebInspector.NetworkPanel.prototype._copyAll):
(WebInspector.NetworkPanel.prototype._exportAll):
* inspector/front-end/inspector.js:
(WebInspector.reset):

LayoutTests:

* http/tests/inspector/resource-har-conversion.html:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/network/network-timing.html
LayoutTests/http/tests/inspector/network/ping.html
LayoutTests/http/tests/inspector/resource-har-conversion.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/AuditsPanel.js
Source/WebCore/inspector/front-end/ExtensionServer.js
Source/WebCore/inspector/front-end/HAREntry.js
Source/WebCore/inspector/front-end/NetworkManager.js
Source/WebCore/inspector/front-end/NetworkPanel.js
Source/WebCore/inspector/front-end/inspector.js

index e72923b..5c3acbb 100644 (file)
@@ -1,3 +1,12 @@
+2011-07-11  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [refactoring] Remove dependencies of components requiring network resource list from network panel
+        https://bugs.webkit.org/show_bug.cgi?id=62477
+
+        * http/tests/inspector/resource-har-conversion.html:
+
 2011-07-11  Adam Roben  <aroben@apple.com>
 
         Add back the win-xp and win-wk2 results that were deleted in r90699
index 7f87d30..649852d 100644 (file)
@@ -31,13 +31,14 @@ function test()
     {
         // inspector-test.js appears in network panel occasionally in Safari on
         // Mac, so checking two last resources.
-        var resourcesCount = WebInspector.panels.network.resources.length;
-        var resource1 = WebInspector.panels.network.resources[resourcesCount - 2];
+        var resources = WebInspector.networkLog.resources;
+        var resourcesCount = resources.length;
+        var resource1 = resources[resourcesCount - 2];
         InspectorTest.addResult(resource1.url);
         InspectorTest.assertGreaterOrEqual(100, resource1.latency * 1000, "Latency of the first resource");
         InspectorTest.assertGreaterOrEqual(300, resource1.duration * 1000, "Duration of the first resource");
 
-        var resource2 = WebInspector.panels.network.resources[resourcesCount - 1];
+        var resource2 = resources[resourcesCount - 1];
         InspectorTest.addResult(resource2.url);
         InspectorTest.assertGreaterOrEqual(100, resource2.latency * 1000, "Latency of the second resource");
         InspectorTest.assertGreaterOrEqual(100, resource2.duration * 1000, "Duration of the second resource");
index 8666bd1..e29b810 100644 (file)
@@ -26,8 +26,9 @@ function test()
     {
         // inspector-test.js appears in network panel occasionally in Safari on
         // Mac, so checking last resource.
-        var resourcesCount = WebInspector.panels.network.resources.length;
-        var resource = WebInspector.panels.network.resources[resourcesCount - 1];
+        var resources = WebInspector.networkLog.resources;
+        var resourcesCount = resources.length;
+        var resource = resources[resourcesCount - 1];
 
         InspectorTest.addResult(resource.url);
         InspectorTest.addResult("resource.isPingRequest(): " + resource.isPingRequest());
index e9400ba..2819f54 100644 (file)
@@ -27,9 +27,10 @@ var test = function()
     {
         function findResourceByURL(url)
         {
-            for (var id in WebInspector.networkResources) {
-                if (url.test(WebInspector.networkResources[id].url))
-                    return WebInspector.networkResources[id];
+            var resources = WebInspector.networkLog.resources;
+            for (var i = 0; i < resources.length; ++i) {
+                if (url.test(resources[i].url))
+                    return resources[i];
             }
         }
 
@@ -45,7 +46,7 @@ var test = function()
         }
 
         addCookieHeadersToResource(findResourceByURL(/inspector-test\.js$/));
-        var log = (new WebInspector.HARLog()).build();
+        var log = (new WebInspector.HARLog(WebInspector.networkLog.resources)).build();
         // Filter out favicon.ico requests that only appear on certain platforms.
         log.entries = log.entries.filter(function(entry) {
             return !/favicon\.ico$/.test(entry.request.url);
index b676639..8772627 100644 (file)
@@ -1,3 +1,31 @@
+2011-07-11  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [refactoring] Remove dependencies of components requiring network resource list from network panel
+        https://bugs.webkit.org/show_bug.cgi?id=62477
+
+        * inspector/front-end/AuditsPanel.js:
+        * inspector/front-end/ExtensionServer.js:
+        (WebInspector.ExtensionServer):
+        (WebInspector.ExtensionServer.prototype._inspectedURLChanged):
+        (WebInspector.ExtensionServer.prototype._onGetHAR):
+        (WebInspector.ExtensionServer.prototype.initExtensions):
+        * inspector/front-end/HAREntry.js:
+        (WebInspector.HARLog):
+        (WebInspector.HARLog.prototype.build):
+        * inspector/front-end/NetworkManager.js:
+        (WebInspector.NetworkLog):
+        (WebInspector.NetworkLog.prototype.get resources):
+        (WebInspector.NetworkLog.prototype._onInspectedURLChanged):
+        (WebInspector.NetworkLog.prototype._onResourceStarted):
+        * inspector/front-end/NetworkPanel.js:
+        (WebInspector.NetworkPanel.prototype._reset):
+        (WebInspector.NetworkPanel.prototype._copyAll):
+        (WebInspector.NetworkPanel.prototype._exportAll):
+        * inspector/front-end/inspector.js:
+        (WebInspector.reset):
+
 2011-07-11  Pavel Podivilov  <podivilov@chromium.org>
 
         Web Inspector: make SourceFrame a View.
index 41df23c..cc8c948 100644 (file)
@@ -122,7 +122,7 @@ WebInspector.AuditsPanel.prototype = {
 
     _executeAudit: function(categories, resultCallback)
     {
-        var resources = WebInspector.networkResources;
+        var resources = WebInspector.networkLog.resources;
 
         var rulesRemaining = 0;
         for (var i = 0; i < categories.length; ++i)
index 8383a2a..0669dde 100644 (file)
@@ -61,8 +61,6 @@ WebInspector.ExtensionServer = function()
     this._registerSubscriptionHandler("timeline-event-recorded", WebInspector.timelineManager.start.bind(WebInspector.timelineManager), WebInspector.timelineManager.stop.bind(WebInspector.timelineManager));
 
     window.addEventListener("message", this._onWindowMessage.bind(this), false);
-
-    WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._addRecordToTimeline, this);
 }
 
 WebInspector.ExtensionServer.prototype = {
@@ -93,6 +91,7 @@ WebInspector.ExtensionServer.prototype = {
 
     _inspectedURLChanged: function(event)
     {
+        this._resources = {};
         var url = event.data;
         this._postNotification("inspectedURLChanged", url);
     },
@@ -118,11 +117,6 @@ WebInspector.ExtensionServer.prototype = {
         delete this._clientObjects[auditRun.id];
     },
 
-    resetResources: function()
-    {
-        this._resources = {};
-    },
-
     _notifyResourceFinished: function(event)
     {
         var resource = event.data;
@@ -325,9 +319,10 @@ WebInspector.ExtensionServer.prototype = {
 
     _onGetHAR: function(request)
     {
-        var harLog = (new WebInspector.HARLog()).build();
+        var resources = WebInspector.networkLog.resources;
+        var harLog = (new WebInspector.HARLog(resources)).build();
         for (var i = 0; i < harLog.entries.length; ++i)
-            harLog.entries[i]._resourceId = this._resourceId(WebInspector.networkResources[i]);
+            harLog.entries[i]._resourceId = this._resourceId(resources[i]);
         return harLog;
     },
 
@@ -396,6 +391,7 @@ WebInspector.ExtensionServer.prototype = {
         // The networkManager is normally created after the ExtensionServer is constructed, but before initExtensions() is called.
         WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceFinished, this._notifyResourceFinished, this);
         WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, this._inspectedURLChanged, this);
+        WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._addRecordToTimeline, this);
 
         InspectorExtensionRegistry.getExtensionsAsync();
     },
index ef778f5..7313c9d 100644 (file)
@@ -206,8 +206,9 @@ WebInspector.HAREntry._toMilliseconds = function(time)
     return time === -1 ? -1 : Math.round(time * 1000);
 }
 
-WebInspector.HARLog = function()
+WebInspector.HARLog = function(resources)
 {
+    this._resources = resources;
 }
 
 WebInspector.HARLog.prototype = {
@@ -222,7 +223,7 @@ WebInspector.HARLog.prototype = {
                 version: webKitVersion ? webKitVersion[1] : "n/a"
             },
             pages: this._buildPages(),
-            entries: WebInspector.networkResources.map(this._convertResource.bind(this))
+            entries: this._resources.map(this._convertResource.bind(this))
         }
     },
 
index 1f3566f..ebe4d64 100644 (file)
@@ -316,3 +316,34 @@ WebInspector.NetworkDispatcher.prototype = {
         return resource;
     }
 }
+
+WebInspector.NetworkLog = function()
+{
+    this._resources = [];
+    WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceStarted, this._onResourceStarted, this);
+    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
+}
+
+WebInspector.NetworkLog.prototype = {
+    get resources()
+    {
+        return this._resources;
+    },
+
+    _frameNavigated: function(event)
+    {
+        if (!event.data.isMainFrame)
+            return;
+        // Preserve resources from the new session.
+        var oldResources = this._resources.splice(0, this._resources.length);
+        for (var i = 0; i < oldResources.length; ++i) {
+            if (oldResources[i].loaderId === event.data.loaderId)
+                this._resources.push(oldResources[i]);
+        }
+    },
+
+    _onResourceStarted: function(event)
+    {
+        this._resources.push(event.data);
+    }
+}
index b4a5b6a..a5a8536 100644 (file)
@@ -730,7 +730,6 @@ WebInspector.NetworkPanel.prototype = {
         this._viewsContainerElement.removeChildren();
         this._viewsContainerElement.appendChild(this._closeButtonElement);
         this._updateSummaryBar();
-        WebInspector.extensionServer.resetResources();
     },
 
     get resources()
@@ -1015,7 +1014,7 @@ WebInspector.NetworkPanel.prototype = {
     _copyAll: function()
     {
         var harArchive = {
-            log: (new WebInspector.HARLog()).build()
+            log: (new WebInspector.HARLog(this._resources)).build()
         };
         InspectorFrontendHost.copyText(JSON.stringify(harArchive));
     },
@@ -1044,7 +1043,7 @@ WebInspector.NetworkPanel.prototype = {
     _exportAll: function()
     {
         var harArchive = {
-            log: (new WebInspector.HARLog()).build()
+            log: (new WebInspector.HARLog(this._resources)).build()
         };
         InspectorFrontendHost.saveAs(WebInspector.mainResource.domain + ".har", JSON.stringify(harArchive));
     },
index 2283fe4..b5e3709 100644 (file)
@@ -409,11 +409,6 @@ var WebInspector = {
         this.panels.elements.updateFocusedNode(nodeId);
     },
 
-    get networkResources()
-    {
-        return this.panels.network.resources;
-    },
-
     networkResourceById: function(id)
     {
         return this.panels.network.resourceById(id);
@@ -500,6 +495,7 @@ WebInspector.doLoadedDone = function()
     this.drawer.visibleView = this.console;
     this.networkManager = new WebInspector.NetworkManager();
     this.resourceTreeModel = new WebInspector.ResourceTreeModel();
+    this.networkLog = new WebInspector.NetworkLog();
     this.domAgent = new WebInspector.DOMAgent();
 
     InspectorBackend.registerDomainDispatcher("Inspector", this);
@@ -1048,7 +1044,6 @@ WebInspector.reset = function()
             panel.reset();
     }
 
-    this.resources = {};
     this.highlightDOMNode(0);
 
     if (!WebInspector.settings.preserveConsoleLog.get())