2011-07-03 Vsevolod Vlasov <vsevik@chromium.org>
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Jul 2011 15:58:38 +0000 (15:58 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Jul 2011 15:58:38 +0000 (15:58 +0000)
        Reviewed by Alexey Proskuryakov.

        Web Inspector: Preflight OPTIONS requests are not shown on network panel for asynchronous XHRs.
        https://bugs.webkit.org/show_bug.cgi?id=63712

        * http/tests/inspector/network-preflight-options-expected.txt:
        * http/tests/inspector/network-preflight-options.html:
2011-07-03  Vsevolod Vlasov  <vsevik@chromium.org>

        Reviewed by Alexey Proskuryakov.

        Web Inspector: Preflight OPTIONS requests are not shown on network panel for asynchronous XHRs.
        https://bugs.webkit.org/show_bug.cgi?id=63712

        Added InspectorInstrumentation calls to preflight OPTIONS requests callbacks in DocumentThreadableLoader.

        * loader/DocumentThreadableLoader.cpp:
        (WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
        (WebCore::DocumentThreadableLoader::didReceiveResponse):
        (WebCore::DocumentThreadableLoader::didReceiveData):
        (WebCore::DocumentThreadableLoader::didFinishLoading):
        (WebCore::DocumentThreadableLoader::didFail):
        (WebCore::DocumentThreadableLoader::loadRequest):
        * loader/DocumentThreadableLoader.h:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/network-preflight-options-expected.txt
LayoutTests/http/tests/inspector/network-preflight-options.html
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentThreadableLoader.cpp
Source/WebCore/loader/DocumentThreadableLoader.h

index a52e4cd..86afc10 100644 (file)
@@ -1,3 +1,13 @@
+2011-07-03  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Web Inspector: Preflight OPTIONS requests are not shown on network panel for asynchronous XHRs.
+        https://bugs.webkit.org/show_bug.cgi?id=63712
+
+        * http/tests/inspector/network-preflight-options-expected.txt:
+        * http/tests/inspector/network-preflight-options.html:
+
 2011-07-03  Robert Hogan  <robert@webkit.org>
 
         Add platform-specific results after r90338
index 21940b5..836d372 100644 (file)
@@ -1,9 +1,15 @@
 CONSOLE MESSAGE: line 1: XMLHttpRequest cannot load http://localhost:8000/inspector/resources/cors-target.php?deny=yes. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
 CONSOLE MESSAGE: line 1: XMLHttpRequest cannot load http://localhost:8000/inspector/resources/cors-target.php?deny=yes. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+CONSOLE MESSAGE: line 1: XMLHttpRequest cannot load http://localhost:8000/inspector/resources/cors-target.php?deny=yes. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
+CONSOLE MESSAGE: line 1: XMLHttpRequest cannot load http://localhost:8000/inspector/resources/cors-target.php?deny=yes. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
 Tests that preflight OPTIONS requests appear in Network resources
 
 POST http://localhost:8000/inspector/resources/cors-target.php?deny=yes
 OPTIONS http://localhost:8000/inspector/resources/cors-target.php?deny=yes
 OPTIONS http://localhost:8000/inspector/resources/cors-target.php
 POST http://localhost:8000/inspector/resources/cors-target.php
+POST http://localhost:8000/inspector/resources/cors-target.php?deny=yes
+OPTIONS http://localhost:8000/inspector/resources/cors-target.php?deny=yes
+OPTIONS http://localhost:8000/inspector/resources/cors-target.php?async=yes
+POST http://localhost:8000/inspector/resources/cors-target.php?async=yes
 
index 65dc13d..e72bcf1 100644 (file)
@@ -3,10 +3,10 @@
 <script src="inspector-test.js"></script>
 <script type="text/javascript">
 
-function sendXHR(url, forcePreflight)
+function sendXHR(url, forcePreflight, async)
 {
     var xhr = new XMLHttpRequest();
-    xhr.open("POST", url, false);
+    xhr.open("POST", url, async);
     xhr.setRequestHeader("Content-Type", forcePreflight ? "application/xml" : "text/plain");
     try {
         xhr.send("<xml></xml>");  // Denied requests will cause exceptions.
@@ -17,22 +17,30 @@ function sendXHR(url, forcePreflight)
 function doCrossOriginXHR()
 {
     var targetURL = "http://localhost:8000/inspector/resources/cors-target.php";
+
     // Failed POSTs with no preflight check should result in a POST request being logged
-    sendXHR(targetURL + "?deny=yes", false);
+    sendXHR(targetURL + "?deny=yes", false, false);
     // Failed POSTs with preflight check should result in an OPTIONS request being logged
-    sendXHR(targetURL + "?deny=yes", true);
+    sendXHR(targetURL + "?deny=yes", true, false);
     // Successful POSTs with preflight check should result in an OPTIONS request followed by POST request being logged
-    // Generate request name based on timestamp to defeat caching (this is only relevant for repeated invocations of the test in signle instance of DRT)
-    sendXHR(targetURL + "?date=" + Date.now(), true);
+    // Generate request name based on timestamp to defeat OPTIONS request caching (this is only relevant for repeated invocations of the test in signle instance of DRT)
+    sendXHR(targetURL + "?date=" + Date.now(), true, false);
+
+    // And now send the same requests asynchronously
+    // Add redundant async parameter to ensure this request differs from the one above.
+    sendXHR(targetURL + "?deny=yes", false, true);
+    sendXHR(targetURL + "?deny=yes", true, true);
+    sendXHR(targetURL + "?async=yes&date=" + Date.now(), true, true);
 }
 
 var test = function()
 {
+    var postRequestsCount = 0;
     function onResource(event)
     {
         var resource = event.data;
         InspectorTest.addResult(resource.requestMethod + " " +  resource.url.replace(/[&?]date=\d+/, ""));
-        if (resource.requestMethod === "POST" && !/\?deny=yes/.test(resource.url))
+        if (resource.requestMethod === "POST" && ++postRequestsCount == 4)
             InspectorTest.completeTest();
     }
     WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.ResourceFinished, onResource);
index fb14ca0..39bb3b6 100644 (file)
@@ -1,3 +1,21 @@
+2011-07-03  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Web Inspector: Preflight OPTIONS requests are not shown on network panel for asynchronous XHRs.
+        https://bugs.webkit.org/show_bug.cgi?id=63712
+
+        Added InspectorInstrumentation calls to preflight OPTIONS requests callbacks in DocumentThreadableLoader.
+
+        * loader/DocumentThreadableLoader.cpp:
+        (WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
+        (WebCore::DocumentThreadableLoader::didReceiveResponse):
+        (WebCore::DocumentThreadableLoader::didReceiveData):
+        (WebCore::DocumentThreadableLoader::didFinishLoading):
+        (WebCore::DocumentThreadableLoader::didFail):
+        (WebCore::DocumentThreadableLoader::loadRequest):
+        * loader/DocumentThreadableLoader.h:
+
 2011-06-23  Robert Hogan  <robert@webkit.org>
 
         Reviewed by Simon Hausmann.
index 53e2cf2..eff6399 100644 (file)
 #include "ThreadableLoaderClient.h"
 #include <wtf/UnusedParam.h>
 
+#if ENABLE(INSPECTOR)
+#include "InspectorInstrumentation.h"
+#include "ProgressTracker.h"
+#endif
+
 namespace WebCore {
 
 void DocumentThreadableLoader::loadResourceSynchronously(Document* document, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options)
@@ -69,6 +74,9 @@ DocumentThreadableLoader::DocumentThreadableLoader(Document* document, Threadabl
     , m_options(options)
     , m_sameOriginRequest(securityOrigin()->canRequest(request.url()))
     , m_async(blockingBehavior == LoadAsynchronously)
+#if ENABLE(INSPECTOR)
+    , m_preflightRequestIdentifier(0)
+#endif
 {
     ASSERT(document);
     ASSERT(client);
@@ -178,6 +186,14 @@ void DocumentThreadableLoader::didReceiveResponse(unsigned long identifier, cons
 {
     ASSERT(m_client);
 
+#if ENABLE(INSPECTOR)
+    if (m_preflightRequestIdentifier) {
+        DocumentLoader* loader = m_document->frame()->loader()->documentLoader();
+        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willReceiveResourceResponse(m_document->frame(), m_preflightRequestIdentifier, response);
+        InspectorInstrumentation::didReceiveResourceResponse(cookie, m_preflightRequestIdentifier, loader, response);
+    }
+#endif
+
     String accessControlErrorDescription;
     if (m_actualRequest) {
         if (!passesAccessControlCheck(response, m_options.allowCredentials, securityOrigin(), accessControlErrorDescription)) {
@@ -211,6 +227,11 @@ void DocumentThreadableLoader::didReceiveData(SubresourceLoader* loader, const c
     ASSERT(m_client);
     ASSERT_UNUSED(loader, loader == m_loader);
 
+#if ENABLE(INSPECTOR)
+    if (m_preflightRequestIdentifier)
+        InspectorInstrumentation::didReceiveContentLength(m_document->frame(), m_preflightRequestIdentifier, 0, dataLength);
+#endif
+
     // Preflight data should be invisible to clients.
     if (m_actualRequest)
         return;
@@ -239,6 +260,11 @@ void DocumentThreadableLoader::didFinishLoading(SubresourceLoader* loader, doubl
 
 void DocumentThreadableLoader::didFinishLoading(unsigned long identifier, double finishTime)
 {
+#if ENABLE(INSPECTOR)
+    if (m_preflightRequestIdentifier)
+        InspectorInstrumentation::didFinishLoading(m_document->frame(), m_document->frame()->loader()->documentLoader(), m_preflightRequestIdentifier, finishTime);
+#endif
+
     if (m_actualRequest) {
         ASSERT(!m_sameOriginRequest);
         ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl);
@@ -253,6 +279,11 @@ void DocumentThreadableLoader::didFail(SubresourceLoader* loader, const Resource
     // m_loader may be null if we arrive here via SubresourceLoader::create in the ctor
     ASSERT_UNUSED(loader, loader == m_loader || !m_loader);
 
+#if ENABLE(INSPECTOR)
+    if (m_preflightRequestIdentifier)
+        InspectorInstrumentation::didFailLoading(m_document->frame(), m_document->frame()->loader()->documentLoader(), m_preflightRequestIdentifier, error);
+#endif
+
     m_client->didFail(error);
 }
 
@@ -323,6 +354,16 @@ void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Secur
         // Keep buffering the data for the preflight request.
         bool shouldBufferData = m_options.shouldBufferData || m_actualRequest;
 
+#if ENABLE(INSPECTOR)
+        if (m_actualRequest) {
+            ResourceRequest newRequest(request);
+            // Because willSendRequest only gets called during redirects, we initialize the identifier and the first willSendRequest here.
+            m_preflightRequestIdentifier = m_document->frame()->page()->progress()->createUniqueIdentifier();
+            ResourceResponse redirectResponse = ResourceResponse();
+            InspectorInstrumentation::willSendRequest(m_document->frame(), m_preflightRequestIdentifier, m_document->frame()->loader()->documentLoader(), newRequest, redirectResponse);
+        }
+#endif
+
         // Clear the loader so that any callbacks from SubresourceLoader::create will not have the old loader.
         m_loader = 0;
         m_loader = resourceLoadScheduler()->scheduleSubresourceLoad(m_document->frame(), this, request, ResourceLoadPriorityMedium, securityCheck, sendLoadCallbacks,
index 4c7727e..696e2e5 100644 (file)
@@ -105,6 +105,10 @@ namespace WebCore {
         bool m_sameOriginRequest;
         bool m_async;
         OwnPtr<ResourceRequest> m_actualRequest;  // non-null during Access Control preflight checks
+
+#if ENABLE(INSPECTOR)
+        unsigned long m_preflightRequestIdentifier;
+#endif
     };
 
 } // namespace WebCore