2008-10-15 Adele Peterson <adele@apple.com>
authoradele@apple.com <adele@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Oct 2008 21:53:46 +0000 (21:53 +0000)
committeradele@apple.com <adele@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Oct 2008 21:53:46 +0000 (21:53 +0000)
        Reviewed by Sam Weinig.

        Implement didSendBodyData delegate method, and use older code path when that delegate doesn't exist.

        * platform/network/ResourceHandle.h:
        * platform/network/mac/FormDataStreamMac.mm: (WebCore::formRead):
        * platform/network/mac/ResourceHandleMac.mm:
        (WebCore::ResourceHandle::didSendBodyDataDelegateExists):
        (WebCore::ResourceHandle::start):
        (WebCore::ResourceHandle::cancel):
        (-[WebCoreResourceHandleAsDelegate connection:willSendRequest:redirectResponse:]):
        (-[WebCoreResourceHandleAsDelegate connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:]):
        (-[WebCoreResourceHandleAsDelegate connectionDidFinishLoading:]):
        (-[WebCoreResourceHandleAsDelegate connection:didFailWithError:]):

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

WebCore/ChangeLog
WebCore/platform/network/ResourceHandle.h
WebCore/platform/network/mac/FormDataStreamMac.mm
WebCore/platform/network/mac/ResourceHandleMac.mm

index 27148d1..8a73ad0 100644 (file)
@@ -1,3 +1,20 @@
+2008-10-15  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Implement didSendBodyData delegate method, and use older code path when that delegate doesn't exist. 
+
+        * platform/network/ResourceHandle.h:
+        * platform/network/mac/FormDataStreamMac.mm: (WebCore::formRead):
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::ResourceHandle::didSendBodyDataDelegateExists):
+        (WebCore::ResourceHandle::start):
+        (WebCore::ResourceHandle::cancel):
+        (-[WebCoreResourceHandleAsDelegate connection:willSendRequest:redirectResponse:]):
+        (-[WebCoreResourceHandleAsDelegate connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:]):
+        (-[WebCoreResourceHandleAsDelegate connectionDidFinishLoading:]):
+        (-[WebCoreResourceHandleAsDelegate connection:didFailWithError:]):
+
 2008-10-15  Peter Kasting  <pkasting@google.com>
 
         Reviewed by David Hyatt.
index 3213481..61ba512 100644 (file)
@@ -103,7 +103,10 @@ public:
 
     static void loadResourceSynchronously(const ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>& data, Frame* frame);
     static bool willLoadFromCache(ResourceRequest&);
-    
+#if PLATFORM(MAC)
+    static bool didSendBodyDataDelegateExists();
+#endif
+
     ~ResourceHandle();
 
 #if PLATFORM(MAC) || USE(CFNETWORK) || USE(CURL)
index b643dbf..c024da4 100644 (file)
@@ -249,9 +249,11 @@ static CFIndex formRead(CFReadStreamRef stream, UInt8* buffer, CFIndex bufferLen
             *atEOF = FALSE;
             form->bytesSent += bytesRead;
 
-            // FIXME: Figure out how to only do this when a ResourceHandleClient is available.
-            DidSendDataCallbackData* data = new DidSendDataCallbackData(stream, form->bytesSent, form->streamLength);
-            callOnMainThread(performDidSendDataCallback, data);
+            if (!ResourceHandle::didSendBodyDataDelegateExists()) {
+                // FIXME: Figure out how to only do this when a ResourceHandleClient is available.
+                DidSendDataCallbackData* data = new DidSendDataCallbackData(stream, form->bytesSent, form->streamLength);
+                callOnMainThread(performDidSendDataCallback, data);
+            }
 
             return bytesRead;
         }
index 1af3bde..78887e4 100644 (file)
@@ -109,6 +109,17 @@ ResourceHandle::~ResourceHandle()
     releaseDelegate();
 }
 
+static const double MaxFoundationVersionWithoutdidSendBodyDataDelegate = 677.21;
+bool ResourceHandle::didSendBodyDataDelegateExists()
+{
+// FIXME: Refine this check as the delegate becomes more widely available.
+#ifdef BUILDING_ON_LEOPARD
+    return NSFoundationVersionNumber > MaxFoundationVersionWithoutdidSendBodyDataDelegate;
+#else
+    return false;
+#endif
+}
+
 bool ResourceHandle::start(Frame* frame)
 {
     if (!frame)
@@ -136,8 +147,9 @@ bool ResourceHandle::start(Frame* frame)
         delegate = d->m_proxy.get();
     } else 
         delegate = ResourceHandle::delegate();
-    
-    associateStreamWithResourceHandle([d->m_request.nsURLRequest() HTTPBodyStream], this);
+
+    if (!ResourceHandle::didSendBodyDataDelegateExists())
+        associateStreamWithResourceHandle([d->m_request.nsURLRequest() HTTPBodyStream], this);
 
     NSURLConnection *connection;
     
@@ -196,7 +208,8 @@ bool ResourceHandle::start(Frame* frame)
 
 void ResourceHandle::cancel()
 {
-    disassociateStreamWithResourceHandle([d->m_request.nsURLRequest() HTTPBodyStream]);
+    if (!ResourceHandle::didSendBodyDataDelegateExists())
+        disassociateStreamWithResourceHandle([d->m_request.nsURLRequest() HTTPBodyStream]);
     [d->m_connection.get() cancel];
 }
 
@@ -447,13 +460,15 @@ void ResourceHandle::receivedCancellation(const AuthenticationChallenge& challen
     m_url = copy;
 #endif
 
-    // The client may change the request's body stream, in which case we have to re-associate
-    // the handle with the new stream so upload progress callbacks continue to work correctly.
-    NSInputStream* oldBodyStream = [newRequest HTTPBodyStream];
-    NSInputStream* newBodyStream = [request.nsURLRequest() HTTPBodyStream];
-    if (oldBodyStream != newBodyStream) {
-        disassociateStreamWithResourceHandle(oldBodyStream);
-        associateStreamWithResourceHandle(newBodyStream, m_handle);
+    if (!ResourceHandle::didSendBodyDataDelegateExists()) {
+        // The client may change the request's body stream, in which case we have to re-associate
+        // the handle with the new stream so upload progress callbacks continue to work correctly.
+        NSInputStream* oldBodyStream = [newRequest HTTPBodyStream];
+        NSInputStream* newBodyStream = [request.nsURLRequest() HTTPBodyStream];
+        if (oldBodyStream != newBodyStream) {
+            disassociateStreamWithResourceHandle(oldBodyStream);
+            associateStreamWithResourceHandle(newBodyStream, m_handle);
+        }
     }
 
     return request.nsURLRequest();
@@ -521,12 +536,23 @@ void ResourceHandle::receivedCancellation(const AuthenticationChallenge& challen
     m_handle->client()->willStopBufferingData(m_handle, (const char*)[data bytes], static_cast<int>([data length]));
 }
 
+- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
+{
+    if (!m_handle || !m_handle->client())
+        return;
+    CallbackGuard guard;
+    m_handle->client()->didSendData(m_handle, totalBytesWritten, totalBytesExpectedToWrite);
+}
+
 - (void)connectionDidFinishLoading:(NSURLConnection *)con
 {
     if (!m_handle || !m_handle->client())
         return;
     CallbackGuard guard;
-    disassociateStreamWithResourceHandle([m_handle->request().nsURLRequest() HTTPBodyStream]);
+
+    if (!ResourceHandle::didSendBodyDataDelegateExists())
+        disassociateStreamWithResourceHandle([m_handle->request().nsURLRequest() HTTPBodyStream]);
+
     m_handle->client()->didFinishLoading(m_handle);
 }
 
@@ -535,7 +561,10 @@ void ResourceHandle::receivedCancellation(const AuthenticationChallenge& challen
     if (!m_handle || !m_handle->client())
         return;
     CallbackGuard guard;
-    disassociateStreamWithResourceHandle([m_handle->request().nsURLRequest() HTTPBodyStream]);
+
+    if (!ResourceHandle::didSendBodyDataDelegateExists())
+        disassociateStreamWithResourceHandle([m_handle->request().nsURLRequest() HTTPBodyStream]);
+
     m_handle->client()->didFail(m_handle, error);
 }