2011-01-14 Andrey Kosyakov <caseq@chromium.org>
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jan 2011 12:25:39 +0000 (12:25 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jan 2011 12:25:39 +0000 (12:25 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: redirected resources not handled properly in Network panel
        https://bugs.webkit.org/show_bug.cgi?id=52292

        * inspector/Inspector.idl: Do not pass isMainResource to identifierForInitialRequest() (it's useless, as we may hit provisional load)
        * inspector/InspectorInstrumentation.cpp: Ditto.
        (WebCore::InspectorInstrumentation::identifierForInitialRequestImpl):
        * inspector/InspectorResourceAgent.cpp: Ditto.
        (WebCore::InspectorResourceAgent::identifierForInitialRequest):
        * inspector/InspectorResourceAgent.h: Ditto.
        * inspector/InspectorInstrumentation.cpp: Ditto.
        (WebCore::InspectorInstrumentation::identifierForInitialRequestImpl): Fix main resource detection.
        * inspector/front-end/AuditsPanel.js: WebInspector.networkResources now returns array, not map.
        * inspector/front-end/ConsoleView.js: User WebInspector.resourceById() to get resource
        (WebInspector.ConsoleMessage.prototype._formatMessage):
        * inspector/front-end/ExtensionServer.js: Ditto.
        (WebInspector.ExtensionServer.prototype._onRevealAndSelectResource):
        (WebInspector.ExtensionServer.prototype._onGetResourceContent):
        * inspector/front-end/HAREntry.js: WebInspector.networkResources now returns array, not map
        (WebInspector.HARLog.prototype.build):
        (WebInspector.HARLog.prototype._convertResource):
        * inspector/front-end/NetworkManager.js:
        (WebInspector.NetworkManager): Use appendResource, not refreshResource, when adding a new resource.
        (WebInspector.NetworkManager.prototype.identifierForInitialRequest):
        (WebInspector.NetworkManager.prototype.willSendRequest):
        (WebInspector.NetworkManager.prototype.didLoadResourceFromMemoryCache):
        (WebInspector.NetworkManager.prototype.setInitialContent):
        (WebInspector.NetworkManager.prototype.didCommitLoadForFrame):
        (WebInspector.NetworkManager.prototype.didCreateWebSocket):
        (WebInspector.NetworkManager.prototype._createResource): always register resource URL with ResourceTreeModel
        (WebInspector.NetworkManager.prototype._appendRedirect):
        * inspector/front-end/NetworkPanel.js:
        (WebInspector.NetworkPanel):
        (WebInspector.NetworkPanel.prototype.get resources):
        (WebInspector.NetworkPanel.prototype.resourceById):
        (WebInspector.NetworkPanel.prototype.appendResource): Add resource as new iff appendResource was added.
        (WebInspector.NetworkPanel.prototype.refreshResource): ditto.
        (WebInspector.NetworkPanel.prototype.mainResourceChanged): Clear console upon arrival of new main resource.
        * inspector/front-end/ResourceTreeModel.js: Expose unbindResourceURL, bind resources automatically upon creation.
        (WebInspector.ResourceTreeModel.prototype._clearResources):
        (WebInspector.ResourceTreeModel.prototype.unbindResourceURL):
        (WebInspector.ResourceTreeModel.prototype._addFramesRecursively):
        (WebInspector.ResourceTreeModel.prototype.createResource):
        * inspector/front-end/inspector.js:
        (WebInspector.resourceById):

2011-01-14  Andrey Kosyakov  <caseq@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: redirected resources not handled properly in Network panel
        Added test for redirected resource presence in HAR
        Changed test to request entire HAR log, not multiple HAR entries.
        https://bugs.webkit.org/show_bug.cgi?id=52292

        * http/tests/inspector/extensions-resources-redirect-expected.txt:
        * http/tests/inspector/extensions-resources-redirect.html:
        * http/tests/inspector/resource-har-conversion.html:
        * inspector/extensions-resources.html:

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/extensions-resources-redirect-expected.txt
LayoutTests/http/tests/inspector/extensions-resources-redirect.html
LayoutTests/http/tests/inspector/resource-har-conversion.html
LayoutTests/inspector/extensions-resources.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/Inspector.idl
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorResourceAgent.cpp
Source/WebCore/inspector/InspectorResourceAgent.h
Source/WebCore/inspector/front-end/AuditsPanel.js
Source/WebCore/inspector/front-end/ConsoleView.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/ResourceTreeModel.js
Source/WebCore/inspector/front-end/inspector.js

index e491ac0..4f68900 100644 (file)
@@ -1,3 +1,17 @@
+2011-01-14  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: redirected resources not handled properly in Network panel
+        Added test for redirected resource presence in HAR
+        Changed test to request entire HAR log, not multiple HAR entries.
+        https://bugs.webkit.org/show_bug.cgi?id=52292
+
+        * http/tests/inspector/extensions-resources-redirect-expected.txt:
+        * http/tests/inspector/extensions-resources-redirect.html:
+        * http/tests/inspector/resource-har-conversion.html:
+        * inspector/extensions-resources.html:
+
 2011-01-14  Hayato Ito  <hayato@chromium.org>
 
         Unreviewed chromium expectations update.
index e8c7b35..17a8bc4 100644 (file)
@@ -1,9 +1,18 @@
 Tests WebInspector extension API
 
+Page reloaded.
 Started extension.
 
 Running tests...
 RUNNING TEST: extension_testGetRedirectResourceContent
-content: , encoding: base64
+content: undefined, encoding: undefined
+RUNNING TEST: extension_testRedirectResourcesInHAR
+Resources in HAR:
+http://127.0.0.1:8000/inspector/extensions-resources-redirect.html
+http://127.0.0.1:8000/inspector/extensions-resources-test.js
+http://127.0.0.1:8000/inspector/extensions-test.js
+http://127.0.0.1:8000/inspector/inspector-test2.js
+http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?redirected=true
+http://127.0.0.1:8000/loading/resources/redirect-methods-result.php?status=302
 All tests done.
 
index c3b9479..b6d5b76 100755 (executable)
@@ -5,6 +5,20 @@
 <script src="extensions-test.js"></script>
 <script type="text/javascript">
 
+function extension_doRequest(callback)
+{
+    function callbackWrapper()
+    {
+        webInspector.resources.onFinished.removeListener(callbackWrapper);
+        callback();
+    }
+    webInspector.resources.onFinished.addListener(callbackWrapper);
+    webInspector.inspectedWindow.eval("doRequest()", function(result) {
+        if (result)
+            callbackWrapper();
+    });
+}
+
 function extension_testGetRedirectResourceContent(nextTest)
 {
     function onFinished()
@@ -18,17 +32,47 @@ function extension_testGetRedirectResourceContent(nextTest)
         output("content: " + content + ", encoding: " + encoding);
         nextTest();
     }
+    extension_doRequest(onFinished);
+}
 
-    webInspector.resources.onFinished.addListener(onFinished);
-    webInspector.inspectedWindow.eval("doRequest()");
+function extension_testRedirectResourcesInHAR(nextTest)
+{
+    function onFinished()
+    {
+        webInspector.resources.getHAR(onHAR);
+    }
+    function onHAR(har)
+    {
+        var entries = har.entries;
+        var urls = [];
+        for (var i = 0; i < entries.length; ++i)
+            urls.push(entries[i].request.url);
+        urls.sort();
+        output("Resources in HAR:\n" + urls.join("\n"));
+        nextTest();
+    }
+    extension_doRequest(onFinished);
 }
 
+var requestDone = false;
+
 function doRequest()
 {
+    // Only do request once per test suite, to make tests independent on each other.
+    // Returns true iff request is alredy done (so the caller shouldn't wait for onFinished).
+    if (requestDone)
+        return true;
+    requestDone = true;
     // We can't use XHR here -- the content for XHRs is pushed from back-end.
     var iframe = document.createElement("iframe");
     iframe.src = "/loading/resources/redirect-methods-result.php?status=302";
     document.body.appendChild(iframe);
+    return false;
+}
+
+var test = function()
+{
+    InspectorTest.reloadPage(InspectorTest.runExtensionTests);
 }
 
 </script>
index 4db518e..51c7894 100644 (file)
@@ -7,11 +7,6 @@
 
 var test = function()
 {
-    function getHAR(id)
-    {
-        return new WebInspector.HAREntry(WebInspector.networkResources[id]).build();
-    }
-
     function addCookieHeadersToResource(resource)
     {
         resource.requestHeaders = {
@@ -33,8 +28,9 @@ var test = function()
     InspectorTest.reloadPageIfNeeded(function() {
         InjectedScriptAccess.getDefault().evaluate("doXHR()", "console", function() {
             addCookieHeadersToResource(findResourceByURL(/inspector-test2\.js$/));
-            var resources = Object.keys(WebInspector.networkResources).map(getHAR).sort(InspectorTest.resourceURLComparer);
-            InspectorTest.addObject(resources, InspectorTest.HARNondeterministicPropertiesWithSize);
+            var entries = (new WebInspector.HARLog()).build().entries;
+            entries.sort(InspectorTest.resourceURLComparer);
+            InspectorTest.addObject(entries, InspectorTest.HARNondeterministicPropertiesWithSize);
             InspectorTest.completeTest();
         });
     });
index 0b50d1a..2f0f73c 100755 (executable)
@@ -37,7 +37,7 @@ function extension_testGetHAR(nextTest)
 function doXHR()
 {
     var xhr = new XMLHttpRequest();
-    xhr.open("GET", location.href, false);
+    xhr.open("GET", "", false);
     xhr.send(null);
 }
 
index 58bef4c..b49d7ef 100644 (file)
@@ -1,3 +1,52 @@
+2011-01-14  Andrey Kosyakov  <caseq@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: redirected resources not handled properly in Network panel
+        https://bugs.webkit.org/show_bug.cgi?id=52292
+
+        * inspector/Inspector.idl: Do not pass isMainResource to identifierForInitialRequest() (it's useless, as we may hit provisional load)
+        * inspector/InspectorInstrumentation.cpp: Ditto.
+        (WebCore::InspectorInstrumentation::identifierForInitialRequestImpl):
+        * inspector/InspectorResourceAgent.cpp: Ditto.
+        (WebCore::InspectorResourceAgent::identifierForInitialRequest):
+        * inspector/InspectorResourceAgent.h: Ditto.
+        * inspector/InspectorInstrumentation.cpp: Ditto.
+        (WebCore::InspectorInstrumentation::identifierForInitialRequestImpl): Fix main resource detection.
+        * inspector/front-end/AuditsPanel.js: WebInspector.networkResources now returns array, not map.
+        * inspector/front-end/ConsoleView.js: User WebInspector.resourceById() to get resource
+        (WebInspector.ConsoleMessage.prototype._formatMessage):
+        * inspector/front-end/ExtensionServer.js: Ditto.
+        (WebInspector.ExtensionServer.prototype._onRevealAndSelectResource):
+        (WebInspector.ExtensionServer.prototype._onGetResourceContent):
+        * inspector/front-end/HAREntry.js: WebInspector.networkResources now returns array, not map
+        (WebInspector.HARLog.prototype.build):
+        (WebInspector.HARLog.prototype._convertResource):
+        * inspector/front-end/NetworkManager.js:
+        (WebInspector.NetworkManager): Use appendResource, not refreshResource, when adding a new resource.
+        (WebInspector.NetworkManager.prototype.identifierForInitialRequest):
+        (WebInspector.NetworkManager.prototype.willSendRequest):
+        (WebInspector.NetworkManager.prototype.didLoadResourceFromMemoryCache):
+        (WebInspector.NetworkManager.prototype.setInitialContent):
+        (WebInspector.NetworkManager.prototype.didCommitLoadForFrame):
+        (WebInspector.NetworkManager.prototype.didCreateWebSocket):
+        (WebInspector.NetworkManager.prototype._createResource): always register resource URL with ResourceTreeModel
+        (WebInspector.NetworkManager.prototype._appendRedirect):
+        * inspector/front-end/NetworkPanel.js:
+        (WebInspector.NetworkPanel):
+        (WebInspector.NetworkPanel.prototype.get resources):
+        (WebInspector.NetworkPanel.prototype.resourceById):
+        (WebInspector.NetworkPanel.prototype.appendResource): Add resource as new iff appendResource was added.
+        (WebInspector.NetworkPanel.prototype.refreshResource): ditto.
+        (WebInspector.NetworkPanel.prototype.mainResourceChanged): Clear console upon arrival of new main resource.
+        * inspector/front-end/ResourceTreeModel.js: Expose unbindResourceURL, bind resources automatically upon creation.
+        (WebInspector.ResourceTreeModel.prototype._clearResources):
+        (WebInspector.ResourceTreeModel.prototype.unbindResourceURL):
+        (WebInspector.ResourceTreeModel.prototype._addFramesRecursively):
+        (WebInspector.ResourceTreeModel.prototype.createResource):
+        * inspector/front-end/inspector.js:
+        (WebInspector.resourceById):
+
 2011-01-14  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r75783.
index 87b38c2..3dbc007 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * 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
@@ -90,7 +90,7 @@ module core {
         [domain=Network] void resourceContent(in unsigned long frameId, in String url, in boolean base64Encode, out String content);
         [notify, domain=Network] void frameDetachedFromParent(out unsigned long frameId);
 
-        [notify, domain=Network] void identifierForInitialRequest(out long identifier, out String url, out Object loader, out boolean isMainResourceLoader, out Value callStack);
+        [notify, domain=Network] void identifierForInitialRequest(out long identifier, out String url, out Object loader, out Value callStack);
         [notify, domain=Network] void willSendRequest(out long identifier, out double time, out Object request, out Object redirectResponse);
         [notify, domain=Network] void markResourceAsCached(out long identifier);
         [notify, domain=Network] void didReceiveResponse(out long identifier, out double time, out String resourceType, out Object response);
index 9395dd5..89057a2 100644 (file)
@@ -1,5 +1,5 @@
 /*
-* Copyright (C) 2010 Google Inc. All rights reserved.
+* 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
@@ -382,7 +382,7 @@ void InspectorInstrumentation::identifierForInitialRequestImpl(InspectorControll
     ic->ensureSettingsLoaded();
 
     if (InspectorResourceAgent* resourceAgent = retrieveResourceAgent(ic))
-        resourceAgent->identifierForInitialRequest(identifier, request.url(), loader, ic->isMainResourceLoader(loader, request.url()));
+        resourceAgent->identifierForInitialRequest(identifier, request.url(), loader);
 }
 
 void InspectorInstrumentation::willSendRequestImpl(InspectorController* ic, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
index a425797..9fc562c 100644 (file)
@@ -283,7 +283,7 @@ InspectorResourceAgent::~InspectorResourceAgent()
 {
 }
 
-void InspectorResourceAgent::identifierForInitialRequest(unsigned long identifier, const KURL& url, DocumentLoader* loader, bool isMainResource)
+void InspectorResourceAgent::identifierForInitialRequest(unsigned long identifier, const KURL& url, DocumentLoader* loader)
 {
     RefPtr<InspectorObject> loaderObject = buildObjectForDocumentLoader(loader);
     RefPtr<ScriptCallStack> callStack = createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture, true);
@@ -292,7 +292,7 @@ void InspectorResourceAgent::identifierForInitialRequest(unsigned long identifie
         callStackValue = callStack->buildInspectorObject();
     else
         callStackValue = InspectorValue::null();
-    m_frontend->identifierForInitialRequest(identifier, url.string(), loaderObject, isMainResource, callStackValue);
+    m_frontend->identifierForInitialRequest(identifier, url.string(), loaderObject, callStackValue);
 }
 
 void InspectorResourceAgent::willSendRequest(unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse)
index f3f3211..1e77d58 100644 (file)
@@ -77,7 +77,7 @@ public:
 
     ~InspectorResourceAgent();
 
-    void identifierForInitialRequest(unsigned long identifier, const KURL&, DocumentLoader*, bool isMainResource);
+    void identifierForInitialRequest(unsigned long identifier, const KURL&, DocumentLoader*);
     void willSendRequest(unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse);
     void markResourceAsCached(unsigned long identifier);
     void didReceiveResponse(unsigned long identifier, DocumentLoader* laoder, const ResourceResponse&);
index c42077f..c639f47 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Google Inc. All rights reserved.
+ * 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
@@ -129,9 +129,7 @@ WebInspector.AuditsPanel.prototype = {
 
     _executeAudit: function(categories, resultCallback)
     {
-        var resources = [];
-        for (var id in WebInspector.networkResources)
-            resources.push(WebInspector.networkResources[id]);
+        var resources = WebInspector.networkResources;
 
         var rulesRemaining = 0;
         for (var i = 0; i < categories.length; ++i)
index c98552d..f2b7ca1 100644 (file)
@@ -668,7 +668,7 @@ WebInspector.ConsoleMessage.prototype = {
                 messageText = document.createTextNode(this._messageText);
                 break;
             case WebInspector.ConsoleMessage.MessageType.NetworkError:
-                var resource = this._requestId && WebInspector.panels.network.resources[this._requestId];
+                var resource = this._requestId && WebInspector.networkResourceById(this._requestId);
                 if (resource) {
                     stackTrace = resource.stackTrace;
 
index 373c855..1320efb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * 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
@@ -288,7 +288,7 @@ WebInspector.ExtensionServer.prototype = {
         var id = message.id;
         var resource = null;
 
-        resource = WebInspector.networkResources[id] || WebInspector.resourceForURL(id);
+        resource = WebInspector.networkResourceById(id) || WebInspector.resourceForURL(id);
         if (!resource)
             return this._status.E_NOTFOUND(typeof id + ": " + id);
 
@@ -318,7 +318,7 @@ WebInspector.ExtensionServer.prototype = {
             };
             this._dispatchCallback(message.requestId, port, response);
         }
-        var resource = WebInspector.networkResources[message.id];
+        var resource = WebInspector.networkResourceById(message.id);
         if (!resource)
             return this._status.E_NOTFOUND(message.id);
         resource.requestContent(onContentAvailable.bind(this));
index 6dfbd1b..4d690b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * 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
@@ -204,7 +204,7 @@ WebInspector.HARLog.prototype = {
                 version: webKitVersion ? webKitVersion[1] : "n/a"
             },
             pages: this._buildPages(),
-            entries: Object.keys(WebInspector.networkResources).map(this._convertResource.bind(this))
+            entries: WebInspector.networkResources.map(this._convertResource.bind(this))
         }
     },
 
@@ -228,11 +228,11 @@ WebInspector.HARLog.prototype = {
         }
     },
 
-    _convertResource: function(id)
+    _convertResource: function(resource)
     {
-        var entry = (new WebInspector.HAREntry(WebInspector.networkResources[id])).build();
+        var entry = (new WebInspector.HAREntry(resource)).build();
         if (this.includeResourceIds)
-            entry._resourceId = id;
+            entry._resourceId = resource.identifier;
         return entry;
     },
 
index 9c9381b..c8ff2e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
+ * 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
@@ -32,6 +32,7 @@ WebInspector.NetworkManager = function(resourceTreeModel)
 {
     this._resourcesById = {};
     this._resourceTreeModel = resourceTreeModel;
+    this._lastIdentifierForCachedResource = 0;
     InspectorBackend.registerDomainDispatcher("Network", this);
 }
 
@@ -86,18 +87,12 @@ WebInspector.NetworkManager.updateResourceWithCachedResource = function(resource
 }
 
 WebInspector.NetworkManager.prototype = {
-    identifierForInitialRequest: function(identifier, url, loader, isMainResource, callStack)
+    identifierForInitialRequest: function(identifier, url, loader, callStack)
     {
-        var resource = this._createResource(identifier, url, loader, callStack);
-        if (isMainResource) {
-            WebInspector.mainResource = resource;
-            resource.isMainResource = true;
-        }
-
-        // It is important to bind resource url early (before scripts compile).
-        this._resourceTreeModel.bindResourceURL(resource);
+        var resource = this._resourceTreeModel.createResource(identifier, url, loader, callStack);
+        this._resourcesById[identifier] = resource;
 
-        WebInspector.panels.network.refreshResource(resource);
+        WebInspector.panels.network.appendResource(resource);
         WebInspector.panels.audits.resourceStarted(resource);
     },
 
@@ -120,7 +115,7 @@ WebInspector.NetworkManager.prototype = {
         resource.startTime = time;
 
         if (isRedirect) {
-            WebInspector.panels.network.refreshResource(resource);
+            WebInspector.panels.network.appendResource(resource);
             WebInspector.panels.audits.resourceStarted(resource);
         } else
             WebInspector.panels.network.refreshResource(resource);
@@ -197,14 +192,14 @@ WebInspector.NetworkManager.prototype = {
 
     didLoadResourceFromMemoryCache: function(time, cachedResource)
     {
-        var resource = this._createResource(null, cachedResource.url, cachedResource.loader);
+        var resource = this._resourceTreeModel.createResource("cached:" + ++this._lastIdentifierForCachedResource, cachedResource.url, cachedResource.loader);
         WebInspector.NetworkManager.updateResourceWithCachedResource(resource, cachedResource);
         resource.cached = true;
         resource.requestMethod = "GET";
         resource.startTime = resource.responseReceivedTime = resource.endTime = time;
         resource.finished = true;
 
-        WebInspector.panels.network.refreshResource(resource);
+        WebInspector.panels.network.appendResource(resource);
         WebInspector.panels.audits.resourceStarted(resource);
         WebInspector.panels.audits.resourceFinished(resource);
         this._resourceTreeModel.addResourceToFrame(resource.loader.frameId, resource);
@@ -217,7 +212,7 @@ WebInspector.NetworkManager.prototype = {
 
     setInitialContent: function(identifier, sourceString, type)
     {
-        var resource = WebInspector.panels.network.resources[identifier];
+        var resource = WebInspector.networkResourceById(identifier);
         if (!resource)
             return;
 
@@ -230,14 +225,22 @@ WebInspector.NetworkManager.prototype = {
     didCommitLoadForFrame: function(frame, loader)
     {
         this._resourceTreeModel.didCommitLoadForFrame(frame, loader);
-        WebInspector.panels.network.refreshResource(WebInspector.mainResource);
+        if (!frame.parentId) {
+            var mainResource = this._resourceTreeModel.resourceForURL(frame.url);
+            if (mainResource) {
+                WebInspector.mainResource = mainResource;
+                mainResource.isMainResource = true;
+                WebInspector.panels.network.mainResourceChanged();
+            }
+        }
     },
 
     didCreateWebSocket: function(identifier, requestURL)
     {
-        var resource = this._createResource(identifier, requestURL);
+        var resource = this._resourceTreeModel.createResource(identifier, requestURL);
+        this._resourcesById[identifier] = resource;
         resource.type = WebInspector.Resource.Type.WebSocket;
-        WebInspector.panels.network.refreshResource(resource);
+        WebInspector.panels.network.appendResource(resource);
     },
 
     willSendWebSocketHandshakeRequest: function(identifier, time, request)
@@ -279,28 +282,22 @@ WebInspector.NetworkManager.prototype = {
         WebInspector.panels.network.refreshResource(resource);
     },
 
-    _createResource: function(identifier, url, loader, callStack)
-    {
-        var resource = WebInspector.ResourceTreeModel.createResource(identifier, url, loader, callStack);
-        this._resourcesById[identifier] = resource;
-        return resource;
-    },
-
     _appendRedirect: function(identifier, redirectURL)
     {
         var originalResource = this._resourcesById[identifier];
+        var previousRedirects = originalResource.redirects || [];
         originalResource.finished = true;
-        originalResource.identifier = null;
-
-        var newResource = this._createResource(identifier, redirectURL, originalResource.loader, originalResource.stackTrace);
-        newResource.redirects = originalResource.redirects || [];
+        originalResource.identifier = "redirected:" + identifier + "." + previousRedirects.length;
         delete originalResource.redirects;
-        newResource.redirects.push(originalResource);
-        if (originalResource.isMainResource) {
-            delete originalResource.isMainResource;
-            newResource.isMainResource = true;
-            WebInspector.mainResource = newResource;
-        }
+        // We bound resource early, but it happened to be a redirect and won't make it through to
+        // the resource tree -- so unbind it.
+        // FIXME: we should bind upon adding to the tree only (encapsulated into ResourceTreeModel),
+        // Script debugger should do explicit late binding on its own.
+        this._resourceTreeModel.unbindResourceURL(originalResource);
+        
+        var newResource = this._resourceTreeModel.createResource(identifier, redirectURL, originalResource.loader, originalResource.stackTrace);
+        newResource.redirects = previousRedirects.concat(originalResource);
+        this._resourcesById[identifier] = newResource;
         return newResource;
     }
 }
index f92179d..357144a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2007, 2008 Apple Inc.  All rights reserved.
  * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org>
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * 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
@@ -38,7 +38,6 @@ WebInspector.NetworkPanel = function()
     this._resources = [];
     this._resourcesById = {};
     this._resourcesByURL = {};
-    this._lastIdentifier = 0;
     this._staleResources = [];
     this._resourceGridNodes = {};
     this._mainResourceLoadTime = -1;
@@ -733,12 +732,6 @@ WebInspector.NetworkPanel.prototype = {
         this._preserveLogToggle.toggled = !this._preserveLogToggle.toggled;
     },
 
-    reset: function()
-    {
-        if (!this._preserveLogToggle.toggled)
-            this._reset();
-    },
-
     _reset: function()
     {
         this._popoverHelper.hidePopup();
@@ -771,32 +764,34 @@ WebInspector.NetworkPanel.prototype = {
 
     get resources()
     {
-        return this._resourcesById;
+        return this._resources;
     },
 
-    refreshResource: function(resource)
+    resourceById: function(id)
     {
-        if (!resource.identifier)
-            resource.identifier = "network:" + this._lastIdentifier++;
+        return this._resourcesById[id];
+    },
 
-        if (!this._resourcesById[resource.identifier]) {
-            this._resources.push(resource);
-            this._resourcesById[resource.identifier] = resource;
-            this._resourcesByURL[resource.url] = resource;
+    appendResource: function(resource)
+    {
+        this._resources.push(resource);
+        this._resourcesById[resource.identifier] = resource;
+        this._resourcesByURL[resource.url] = resource;
 
-            // Pull all the redirects of the main resource upon commit load.
-            if (resource.redirects) {
-                for (var i = 0; i < resource.redirects.length; ++i)
-                    this.refreshResource(resource.redirects[i]);
-            }
+        // Pull all the redirects of the main resource upon commit load.
+        if (resource.redirects) {
+            for (var i = 0; i < resource.redirects.length; ++i)
+                this.refreshResource(resource.redirects[i]);
         }
 
+        this.refreshResource(resource);
+    },
+
+    refreshResource: function(resource)
+    {
         this._staleResources.push(resource);
         this._scheduleRefresh();
 
-        if (!resource)
-            return;
-
         var oldView = WebInspector.ResourceView.existingResourceViewForResource(resource);
         if (!oldView)
             return;
@@ -809,6 +804,17 @@ WebInspector.NetworkPanel.prototype = {
             this.visibleView = newView;
     },
 
+    mainResourceChanged: function()
+    {
+        if (this._preserveLogToggle.toggled)
+            return;
+
+        this._reset();
+        // Now resurrect the main resource along with all redirects that lead to it.
+        var resourcesToAppend = (WebInspector.mainResource.redirects || []).concat(WebInspector.mainResource);
+        resourcesToAppend.forEach(this.appendResource, this);
+    },
+
     canShowSourceLine: function(url, line)
     {
         return !!this._resourcesByURL[url];
index 7c7b86d..eef2dc1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * 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
@@ -38,17 +38,6 @@ WebInspector.ResourceTreeModel = function()
     InspectorBackend.cachedResources(this._processCachedResources.bind(this));
 }
 
-WebInspector.ResourceTreeModel.createResource = function(identifier, url, loader, stackTrace)
-{
-    var resource = new WebInspector.Resource(identifier, url);
-    resource.loader = loader;
-    if (loader)
-        resource.documentURL = loader.url;
-    resource.stackTrace = stackTrace;
-
-    return resource;
-}
-
 WebInspector.ResourceTreeModel.prototype = {
     addOrUpdateFrame: function(frame)
     {
@@ -175,7 +164,7 @@ WebInspector.ResourceTreeModel.prototype = {
                 preservedResourcesForFrame.push(resource);
                 continue;
             }
-            this._unbindResourceURL(resource);
+            this.unbindResourceURL(resource);
         }
 
         delete this._resourcesByFrameId[frameId];
@@ -201,7 +190,7 @@ WebInspector.ResourceTreeModel.prototype = {
         return false;
     },
 
-    _unbindResourceURL: function(resource)
+    unbindResourceURL: function(resource)
     {
         var resourceForURL = this._resourcesByURL[resource.url];
         if (!resourceForURL)
@@ -226,13 +215,12 @@ WebInspector.ResourceTreeModel.prototype = {
 
     _addFramesRecursively: function(framePayload)
     {
-        var frameResource = WebInspector.ResourceTreeModel.createResource(null, framePayload.resource.url, framePayload.resource.loader);
+        var frameResource = this.createResource(null, framePayload.resource.url, framePayload.resource.loader);
         WebInspector.NetworkManager.updateResourceWithRequest(frameResource, framePayload.resource.request);
         WebInspector.NetworkManager.updateResourceWithResponse(frameResource, framePayload.resource.response);
         frameResource.type = WebInspector.Resource.Type["Document"];
         frameResource.finished = true;
 
-        this.bindResourceURL(frameResource);
         this.addOrUpdateFrame(framePayload);
         this.addResourceToFrame(framePayload.id, frameResource);
 
@@ -244,12 +232,24 @@ WebInspector.ResourceTreeModel.prototype = {
 
         for (var i = 0; i < framePayload.subresources.length; ++i) {
             var cachedResource = framePayload.subresources[i];
-            var resource = WebInspector.ResourceTreeModel.createResource(null, cachedResource.url, cachedResource.loader);
+            var resource = this.createResource(null, cachedResource.url, cachedResource.loader);
             WebInspector.NetworkManager.updateResourceWithCachedResource(resource, cachedResource);
             resource.finished = true;
-            this.bindResourceURL(resource);
             this.addResourceToFrame(framePayload.id, resource);
         }
         return frameResource;
+    },
+
+    createResource: function(identifier, url, loader, stackTrace)
+    {
+        var resource = new WebInspector.Resource(identifier, url);
+        resource.loader = loader;
+        if (loader) {
+            resource.documentURL = loader.url;
+            this.bindResourceURL(resource);
+        }
+        resource.stackTrace = stackTrace;
+
+        return resource;
     }
 }
index 681fc9e..32ec3bf 100644 (file)
@@ -443,6 +443,11 @@ var WebInspector = {
         return this.panels.network.resources;
     },
 
+    networkResourceById: function(id)
+    {
+        return this.panels.network.resourceById(id);
+    },
+
     forAllResources: function(callback)
     {
         WebInspector.resourceTreeModel.forAllResources(callback);