Title: [90834] trunk/Source/WebCore
Revision
90834
Author
[email protected]
Date
2011-07-12 11:47:18 -0700 (Tue, 12 Jul 2011)

Log Message

Implement didReceiveDataArray callback for CFNetwork based loader
https://bugs.webkit.org/show_bug.cgi?id=64130

Reviewed by David Kilzer.

Factor out the didReceiveDataArray code from ResourceHandleMac.mm into
a new method ResourceHandle::handleDataArray(). Implement the callback
in the CFNetwork loader code and call handleDataArray() to process
incoming data.

No new tests because the flag is not enabled for any bots.

* platform/network/ResourceHandle.h:
* platform/network/cf/ResourceHandleCFNet.cpp:
(WebCore::didReceiveDataArray):
(WebCore::ResourceHandle::createCFURLConnection):
(WebCore::ResourceHandle::handleDataArray):
* platform/network/mac/ResourceHandleMac.mm:
(-[WebCoreResourceHandleAsDelegate connection:didReceiveDataArray:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (90833 => 90834)


--- trunk/Source/WebCore/ChangeLog	2011-07-12 18:42:18 UTC (rev 90833)
+++ trunk/Source/WebCore/ChangeLog	2011-07-12 18:47:18 UTC (rev 90834)
@@ -1,3 +1,25 @@
+2011-07-12  Pratik Solanki  <[email protected]>
+
+        Implement didReceiveDataArray callback for CFNetwork based loader
+        https://bugs.webkit.org/show_bug.cgi?id=64130
+
+        Reviewed by David Kilzer.
+
+        Factor out the didReceiveDataArray code from ResourceHandleMac.mm into
+        a new method ResourceHandle::handleDataArray(). Implement the callback
+        in the CFNetwork loader code and call handleDataArray() to process
+        incoming data.
+
+        No new tests because the flag is not enabled for any bots.
+
+        * platform/network/ResourceHandle.h:
+        * platform/network/cf/ResourceHandleCFNet.cpp:
+        (WebCore::didReceiveDataArray):
+        (WebCore::ResourceHandle::createCFURLConnection):
+        (WebCore::ResourceHandle::handleDataArray):
+        * platform/network/mac/ResourceHandleMac.mm:
+        (-[WebCoreResourceHandleAsDelegate connection:didReceiveDataArray:]):
+
 2011-07-12  Emil A Eklund  <[email protected]>
 
         Switch preferred width/height and columns to to new layout types

Modified: trunk/Source/WebCore/platform/network/ResourceHandle.h (90833 => 90834)


--- trunk/Source/WebCore/platform/network/ResourceHandle.h	2011-07-12 18:42:18 UTC (rev 90833)
+++ trunk/Source/WebCore/platform/network/ResourceHandle.h	2011-07-12 18:47:18 UTC (rev 90834)
@@ -211,6 +211,10 @@
     static CFStringRef synchronousLoadRunLoopMode();
 #endif
 
+#if HAVE(CFNETWORK_DATA_ARRAY_CALLBACK)
+    void handleDataArray(CFArrayRef dataArray);
+#endif
+
 protected:
     ResourceHandle(const ResourceRequest&, ResourceHandleClient*, bool defersLoading, bool shouldContentSniff);
 

Modified: trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp (90833 => 90834)


--- trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp	2011-07-12 18:42:18 UTC (rev 90833)
+++ trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp	2011-07-12 18:47:18 UTC (rev 90834)
@@ -25,8 +25,6 @@
 
 #include "config.h"
 
-#if USE(CFNETWORK)
-
 #include "ResourceHandleInternal.h"
 
 #include "AuthenticationCF.h"
@@ -46,14 +44,22 @@
 #include "ResourceResponse.h"
 #include "SharedBuffer.h"
 #include <CFNetwork/CFNetwork.h>
-#include <WebKitSystemInterface/WebKitSystemInterface.h>
-#include <process.h> // for _beginthread()
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <wtf/HashMap.h>
 #include <wtf/Threading.h>
 #include <wtf/text/CString.h>
 
+#if PLATFORM(MAC) && USE(CFNETWORK)
+#include "WebCoreSystemInterface.h"
+#include "WebCoreURLResponse.h"
+#include <CFNetwork/CFURLConnectionPriv.h>
+#endif
+
+#if PLATFORM(WIN)
+#include <WebKitSystemInterface/WebKitSystemInterface.h>
+#include <process.h>
+
 // FIXME: Remove this declaration once it's in WebKitSupportLibrary.
 extern "C" {
 __declspec(dllimport) CFURLConnectionRef CFURLConnectionCreateWithProperties(
@@ -62,9 +68,12 @@
   CFURLConnectionClient *  client,
   CFDictionaryRef properties);
 }
+#endif
 
 namespace WebCore {
 
+#if USE(CFNETWORK)
+
 class WebCoreSynchronousLoaderClient : public ResourceHandleClient {
 public:
     static PassOwnPtr<WebCoreSynchronousLoaderClient> create(ResourceResponse& response, ResourceError& error)
@@ -205,6 +214,22 @@
     handle->client()->didReceiveResponse(handle, cfResponse);
 }
 
+#if HAVE(CFNETWORK_DATA_ARRAY_CALLBACK)
+static void didReceiveDataArray(CFURLConnectionRef conn, CFArrayRef dataArray, const void* clientInfo)
+{
+#if LOG_DISABLED
+    UNUSED_PARAM(conn);
+#endif
+    ResourceHandle* handle = static_cast<ResourceHandle*>(const_cast<void*>(clientInfo));
+    if (!handle->client())
+        return;
+
+    LOG(Network, "CFNet - didReceiveDataArray(conn=%p, handle=%p, arrayLength=%ld) (%s)", conn, handle, CFArrayGetCount(dataArray), handle->firstRequest().url().string().utf8().data());
+
+    handle->handleDataArray(dataArray);
+}
+#endif
+
 static void didReceiveData(CFURLConnectionRef conn, CFDataRef data, CFIndex originalLength, const void* clientInfo)
 {
 #if LOG_DISABLED
@@ -420,7 +445,11 @@
 
     RetainPtr<CFURLRequestRef> request(AdoptCF, makeFinalRequest(firstRequest(), shouldContentSniff));
 
+#if HAVE(CFNETWORK_DATA_ARRAY_CALLBACK)
+    CFURLConnectionClient_V6 client = { 6, this, 0, 0, 0, WebCore::willSendRequest, didReceiveResponse, didReceiveData, 0, didFinishLoading, didFail, willCacheResponse, didReceiveChallenge, didSendBodyData, shouldUseCredentialStorageCallback, 0, 0, 0, didReceiveDataArray};
+#else
     CFURLConnectionClient_V3 client = { 3, this, 0, 0, 0, WebCore::willSendRequest, didReceiveResponse, didReceiveData, 0, didFinishLoading, didFail, willCacheResponse, didReceiveChallenge, didSendBodyData, shouldUseCredentialStorageCallback, 0};
+#endif
     RetainPtr<CFDictionaryRef> connectionProperties(AdoptCF, createConnectionProperties(shouldUseCredentialStorage));
 
     d->m_connection.adoptCF(CFURLConnectionCreateWithProperties(0, request.get(), reinterpret_cast<CFURLConnectionClient*>(&client), connectionProperties.get()));
@@ -838,6 +867,40 @@
     return m_allowStoredCredentials;
 }
 
+#endif // USE(CFNETWORK)
+
+#if HAVE(CFNETWORK_DATA_ARRAY_CALLBACK)
+void ResourceHandle::handleDataArray(CFArrayRef dataArray)
+{
+    ASSERT(client());
+    if (client()->supportsDataArray()) {
+        client()->didReceiveDataArray(this, dataArray);
+        return;
+    }
+
+    CFIndex count = CFArrayGetCount(dataArray);
+    ASSERT(count);
+    if (count == 1) {
+        CFDataRef data = "" 0));
+        CFIndex length = CFDataGetLength(data);
+        client()->didReceiveData(this, reinterpret_cast<const char*>(CFDataGetBytePtr(data)), length, static_cast<int>(length));
+        return;
+    }
+
+    CFIndex totalSize = 0;
+    CFIndex index;
+    for (index = 0; index < count; index++)
+        totalSize += CFDataGetLength(static_cast<CFDataRef>(CFArrayGetValueAtIndex(dataArray, index)));
+
+    RetainPtr<CFMutableDataRef> mergedData(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, totalSize));
+    for (index = 0; index < count; index++) {
+        CFDataRef data = "" index));
+        CFDataAppendBytes(mergedData.get(), CFDataGetBytePtr(data), CFDataGetLength(data));
+    }
+
+    client()->didReceiveData(this, reinterpret_cast<const char*>(CFDataGetBytePtr(mergedData.get())), totalSize, static_cast<int>(totalSize));
+}
+#endif
+
 } // namespace WebCore
 
-#endif // USE(CFNETWORK)

Modified: trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm (90833 => 90834)


--- trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm	2011-07-12 18:42:18 UTC (rev 90833)
+++ trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm	2011-07-12 18:47:18 UTC (rev 90834)
@@ -808,27 +808,7 @@
     if (!m_handle || !m_handle->client())
         return;
 
-    if (m_handle->client()->supportsDataArray())
-        m_handle->client()->didReceiveDataArray(m_handle, reinterpret_cast<CFArrayRef>(dataArray));
-    else {
-        NSUInteger count = [dataArray count];
-        ASSERT(count);
-        if (count == 1) {
-            NSData *data = "" objectAtIndex:0];
-            m_handle->client()->didReceiveData(m_handle, static_cast<const char*>([data bytes]), [data length], static_cast<int>([data length]));
-        } else {
-            NSUInteger totalSize = 0;
-            for (NSData *data in dataArray)
-                totalSize += [data length];
-
-            RetainPtr<NSMutableData> mergedData(AdoptNS, [[NSMutableData alloc] initWithCapacity:totalSize]);
-            for (NSData *data in dataArray)
-                [mergedData.get() appendData:data];
-
-            m_handle->client()->didReceiveData(m_handle, static_cast<const char*>([mergedData.get() bytes]), totalSize, static_cast<int>(totalSize));
-        }
-    }
-
+    m_handle->handleDataArray(reinterpret_cast<CFArrayRef>(dataArray));
     // The call to didReceiveData above can cancel a load, and if so, the delegate (self) could have been deallocated by this point.
 }
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to