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