2006-11-14 Darin Adler <darin@apple.com>
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Nov 2006 18:06:07 +0000 (18:06 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Nov 2006 18:06:07 +0000 (18:06 +0000)
        Reviewed by Adam.

        Fix up usages of FormData within CFNet loader code.

        * platform/network/ResourceRequest.h:
        (WebCore::ResourceRequest::httpBody):
        * platform/network/cf/FormDataStreamCFNet.cpp:
        (WebCore::getStreamFormDatas): Store RefPtr<FormData>s in the
        streamFormDatas HashMap.
        (WebCore::formCreate):
        (WebCore::formFinalize): Removed delete because the remove() will deref
        and delete if necessary.
        (WebCore::setHTTPBody): Changed parameter to PassRefPtr.
        (WebCore::httpBodyFromStream):
        * platform/network/cf/FormDataStreamCFNet.h: Fix declarations.
        * platform/network/cf/ResourceRequestCFNet.cpp:
        (WebCore::getResourceRequest):

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

WebCore/ChangeLog
WebCore/platform/network/ResourceRequest.h
WebCore/platform/network/cf/FormDataStreamCFNet.cpp
WebCore/platform/network/cf/FormDataStreamCFNet.h
WebCore/platform/network/cf/ResourceRequestCFNet.cpp

index d72300872ad6a364109aac6d88bbc488df9a413a..418d0cd6e56981150de836c89883e2996efea6bf 100644 (file)
@@ -1,3 +1,23 @@
+2006-11-14  Darin Adler  <darin@apple.com>
+
+        Reviewed by Adam.
+
+        Fix up usages of FormData within CFNet loader code.
+
+        * platform/network/ResourceRequest.h:
+        (WebCore::ResourceRequest::httpBody):
+        * platform/network/cf/FormDataStreamCFNet.cpp:
+        (WebCore::getStreamFormDatas): Store RefPtr<FormData>s in the
+        streamFormDatas HashMap.
+        (WebCore::formCreate):
+        (WebCore::formFinalize): Removed delete because the remove() will deref
+        and delete if necessary.
+        (WebCore::setHTTPBody): Changed parameter to PassRefPtr.
+        (WebCore::httpBodyFromStream):
+        * platform/network/cf/FormDataStreamCFNet.h: Fix declarations.
+        * platform/network/cf/ResourceRequestCFNet.cpp:
+        (WebCore::getResourceRequest):
+
 2006-11-14  Greg Jackson  <gjspanner@gmail.com>
 
         Reviewed by Darin.
index e56be596a9bf4aaef8d10e034a5a1e3a850df63d..717bdc507c9d64f1c0a6bd7ebd18c42dc3b985bb 100644 (file)
@@ -114,8 +114,7 @@ namespace WebCore {
         String httpAccept() const { return httpHeaderField("Accept"); }
         void setHTTPAccept(const String& httpUserAgent) { setHTTPHeaderField("Accept", httpUserAgent); }
 
-        const PassRefPtr<FormData> httpBody() const { return m_httpBody; }
-        PassRefPtr<FormData> httpBody() { return m_httpBody; }
+        FormData* httpBody() const { return m_httpBody.get(); }
         void setHTTPBody(PassRefPtr<FormData> httpBody) { m_httpBody = httpBody; } 
         
         bool allowHTTPCookies() const { return m_allowHTTPCookies; }
index cdc5e049fea741cc67a3c43d46a6e6bee22e55e1..5fbd1aee2ab4911ebcb552b4a75bb3e0711e5ba6 100644 (file)
 
 namespace WebCore {
 
-static HashMap<CFReadStreamRef, const FormData*>* streamFormDatas = 0;
-
-static HashMap<CFReadStreamRef, const FormData*>* getStreamFormDatas()
+static HashMap<CFReadStreamRef, RefPtr<FormData> >& getStreamFormDatas()
 {
-    if (!streamFormDatas)
-        streamFormDatas = new HashMap<CFReadStreamRef, const FormData*>();
+    static HashMap<CFReadStreamRef, RefPtr<FormData> > streamFormDatas;
     return streamFormDatas;
 }
 
@@ -169,7 +166,7 @@ static void openNextStream(FormStreamFields* form)
 
 static void* formCreate(CFReadStreamRef stream, void* context)
 {
-    const FormData* formData = static_cast<const FormData*>(context);
+    FormData* formData = static_cast<FormData*>(context);
 
     CFSetCallBacks runLoopAndModeCallBacks = { 0, pairRetain, pairRelease, NULL, pairEqual, pairHash };
 
@@ -185,7 +182,7 @@ static void* formCreate(CFReadStreamRef stream, void* context)
     for (size_t i = 0; i < size; ++i)
         newInfo->remainingElements.append(formData->elements()[size - i - 1]);
 
-    getStreamFormDatas()->set(stream, new FormData(*formData));
+    getStreamFormDatas().set(stream, adoptRef(formData));
 
     return newInfo;
 }
@@ -194,8 +191,7 @@ static void formFinalize(CFReadStreamRef stream, void* context)
 {
     FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
-    delete getStreamFormDatas()->get(stream);
-    getStreamFormDatas()->remove(stream);
+    getStreamFormDatas().remove(stream);
 
     closeCurrentStream(form);
     CFRelease(form->scheduledRunLoopPairs);
@@ -307,16 +303,16 @@ static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, vo
     }
 }
 
-void setHTTPBody(CFMutableURLRequestRef request, const FormData& formData)
+void setHTTPBody(CFMutableURLRequestRef request, PassRefPtr<FormData> formData)
 {
-    size_t count = formData.elements().size();
+    size_t count = formData->elements().size();
 
     if (count == 0)
         return;
 
     // Handle the common special case of one piece of form data, with no files.
     if (count == 1) {
-        const FormDataElement& element = formData.elements()[0];
+        const FormDataElement& element = formData->elements()[0];
         if (element.m_type == FormDataElement::data) {
             CFDataRef data = CFDataCreate(0, reinterpret_cast<const UInt8 *>(element.m_data.data()), element.m_data.size());
             CFURLRequestSetHTTPRequestBody(request, data);
@@ -329,7 +325,7 @@ void setHTTPBody(CFMutableURLRequestRef request, const FormData& formData)
     bool haveLength = true;
     long long length = 0;
     for (size_t i = 0; i < count; ++i) {
-        const FormDataElement& element = formData.elements()[i];
+        const FormDataElement& element = formData->elements()[i];
         if (element.m_type == FormDataElement::data)
             length += element.m_data.size();
         else {
@@ -351,15 +347,15 @@ void setHTTPBody(CFMutableURLRequestRef request, const FormData& formData)
     static CFReadStreamCallBacks formDataStreamCallbacks = 
         { 1, formCreate, formFinalize, 0, formOpen, 0, formRead, 0, formCanRead, formClose, 0, 0, 0, formSchedule, formUnschedule};
 
-    CFReadStreamRef stream = CFReadStreamCreate(0, &formDataStreamCallbacks, const_cast<FormData*>(&formData));
+    CFReadStreamRef stream = CFReadStreamCreate(0, &formDataStreamCallbacks, formData.releaseRef());
     CFURLRequestSetHTTPRequestBodyStream(request, stream);
     CFRelease(stream);
 }
 
 
-const FormData* httpBodyFromStream(CFReadStreamRef stream)
+FormData* httpBodyFromStream(CFReadStreamRef stream)
 {
-    return getStreamFormDatas()->get(stream);
+    return getStreamFormDatas().get(stream).get();
 }
 
 }
index ae3c4f1b778a3bb7b3c009c31b8c574449e16ddb..aa8b0ad924d5f041fe82bcb51dec34fca55793fe 100644 (file)
 #define FormDataStreamCFNet_h_
 
 #include <CoreFoundation/CoreFoundation.h>
+#include <wtf/Forward.h>
 
 typedef struct _CFURLRequest* CFMutableURLRequestRef;
 
 namespace WebCore {
     class FormData;
-    void setHTTPBody(CFMutableURLRequestRef, const FormData&);
-    const FormData* httpBodyFromStream(CFReadStreamRef);
+    void setHTTPBody(CFMutableURLRequestRef, PassRefPtr<FormData>);
+    FormData* httpBodyFromStream(CFReadStreamRef);
 }
 
 #endif FormDataStreamCFNet_h_
index 60d4f90b8fc8eaa7d725fd16a8bfde687c6fc9eb..08eeb926a78ee9c65b52366112da8400ecb0237b 100644 (file)
@@ -59,11 +59,11 @@ namespace WebCore {
        
 
         if (CFDataRef bodyData = CFURLRequestCopyHTTPRequestBody(cfRequest)) {
-            request.setHTTPBody(FormData(CFDataGetBytePtr(bodyData), CFDataGetLength(bodyData)));
+            request.setHTTPBody(new FormData(CFDataGetBytePtr(bodyData), CFDataGetLength(bodyData)));
             CFRelease(bodyData);
         } else if (CFReadStreamRef bodyStream = CFURLRequestCopyHTTPRequestBodyStream(cfRequest)) {
-            if (const FormData* formData = httpBodyFromStream(bodyStream))
-                request.setHTTPBody(*formData);
+            if (FormData* formData = httpBodyFromStream(bodyStream))
+                request.setHTTPBody(formData);
             CFRelease(bodyStream);
         }
         // FIXME: what to do about arbitrary body streams?