Reviewed by Maciej
authorbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Nov 2006 03:54:33 +0000 (03:54 +0000)
committerbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Nov 2006 03:54:33 +0000 (03:54 +0000)
        Made FormData Shared, and pass it around as such.

        * WebCore.xcodeproj/project.pbxproj: Reordered some items
        * html/HTMLFormElement.cpp:
        (WebCore::HTMLFormElement::formData):
        (WebCore::HTMLFormElement::submit):
        * html/HTMLFormElement.h:
        * loader/FrameLoader.cpp:
        (WebCore::FormSubmission::FormSubmission):
        (WebCore::FrameLoader::submitForm):
        * loader/FrameLoader.h:
        * loader/mac/FrameLoaderMac.mm:
        (WebCore::FrameLoader::post):
        (WebCore::FrameLoader::loadResourceSynchronously):
        * loader/mac/SubresourceLoaderMac.mm:
        (WebCore::SubresourceLoader::create):
        * platform/network/FormData.h: Made FormData shared
        * platform/network/ResourceHandle.h:
        * platform/network/ResourceHandle.cpp:
        (WebCore::ResourceHandle::postData):
        * platform/network/ResourceRequest.h:
        (WebCore::ResourceRequest::httpBody):
        (WebCore::ResourceRequest::setHTTPBody):
        * platform/network/mac/ResourceRequestMac.mm:
        (WebCore::getResourceRequest):
        (WebCore::nsURLRequest):

        * platform/network/mac/FormDataStreamMac.h:
        * platform/network/mac/FormDataStreamMac.mm:
        (WebCore::getStreamFormDatas): Hash Streams to RefPtr<FormData>s
        (WebCore::formCreate):
        (WebCore::formFinalize):
        (WebCore::setHTTPBody):
        (WebCore::httpBodyFromStream):

        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::send):

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

16 files changed:
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/html/HTMLFormElement.cpp
WebCore/html/HTMLFormElement.h
WebCore/loader/FrameLoader.cpp
WebCore/loader/FrameLoader.h
WebCore/loader/mac/FrameLoaderMac.mm
WebCore/loader/mac/SubresourceLoaderMac.mm
WebCore/platform/network/FormData.h
WebCore/platform/network/ResourceHandle.cpp
WebCore/platform/network/ResourceHandle.h
WebCore/platform/network/ResourceRequest.h
WebCore/platform/network/mac/FormDataStreamMac.h
WebCore/platform/network/mac/FormDataStreamMac.mm
WebCore/platform/network/mac/ResourceRequestMac.mm
WebCore/xml/xmlhttprequest.cpp

index e6a9c2ad8f8fe8664eed414d6969918acf6381b8..e5c4b20f34ecf4529da448e74f8cfab59b993e5f 100644 (file)
@@ -1,3 +1,45 @@
+2006-11-13  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Maciej
+
+        Made FormData Shared, and pass it around as such.
+
+        * WebCore.xcodeproj/project.pbxproj: Reordered some items
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::formData):
+        (WebCore::HTMLFormElement::submit):
+        * html/HTMLFormElement.h:
+        * loader/FrameLoader.cpp:
+        (WebCore::FormSubmission::FormSubmission):
+        (WebCore::FrameLoader::submitForm):
+        * loader/FrameLoader.h:
+        * loader/mac/FrameLoaderMac.mm:
+        (WebCore::FrameLoader::post):
+        (WebCore::FrameLoader::loadResourceSynchronously):
+        * loader/mac/SubresourceLoaderMac.mm:
+        (WebCore::SubresourceLoader::create):
+        * platform/network/FormData.h: Made FormData shared
+        * platform/network/ResourceHandle.h:
+        * platform/network/ResourceHandle.cpp:
+        (WebCore::ResourceHandle::postData): 
+        * platform/network/ResourceRequest.h:
+        (WebCore::ResourceRequest::httpBody):
+        (WebCore::ResourceRequest::setHTTPBody): 
+        * platform/network/mac/ResourceRequestMac.mm:
+        (WebCore::getResourceRequest):
+        (WebCore::nsURLRequest): 
+
+        * platform/network/mac/FormDataStreamMac.h:
+        * platform/network/mac/FormDataStreamMac.mm:
+        (WebCore::getStreamFormDatas): Hash Streams to RefPtr<FormData>s
+        (WebCore::formCreate):
+        (WebCore::formFinalize):
+        (WebCore::setHTTPBody):
+        (WebCore::httpBodyFromStream):
+
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::send):
+
 2006-11-13  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by harrison
index 87db54394f0521d65dabe4417d387962a570ef77..36af3e190365ca440a2d23bfce3c03479db0a91b 100644 (file)
                        isa = PBXGroup;
                        children = (
                                65DADA170AFD878000CE53ED /* FormData.h */,
+                               65DAD9FA0AFD86B400CE53ED /* FormData.cpp */,
                                651888860AFF3BF700164720 /* ResourceError.cpp */,
                                651888870AFF3BF700164720 /* ResourceError.h */,
-                               65DAD9FA0AFD86B400CE53ED /* FormData.cpp */,
                                656B84E70AEA1DAE00A095B4 /* mac */,
                                655A81BD0AEF67E6000975F0 /* HTTPHeaderMap.h */,
                                656B85370AEA1F9A00A095B4 /* ResourceHandle.h */,
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
                        projectRoot = "";
-                       shouldCheckCompatibility = 1;
                        targets = (
                                93F198A508245E59001E9ABC /* WebCore */,
                                DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
index 23754d6ae28228dbb4d8533f44c8780ad536d18d..d36fd117c3a6618ddb89f8ecb7f50d2616375b9a 100644 (file)
@@ -184,7 +184,7 @@ static DeprecatedCString encodeCString(const CString& cstr)
     return encoded;
 }
 
-bool HTMLFormElement::formData(FormData& result) const
+PassRefPtr<FormData> HTMLFormElement::formData() const
 {
     DeprecatedCString enc_string = ""; // used for non-multipart data
 
@@ -204,6 +204,8 @@ bool HTMLFormElement::formData(FormData& result) const
             encoding = Latin1Encoding();
     }
 
+    RefPtr<FormData> result = new FormData();
+    
     for (unsigned i = 0; i < formElements.size(); ++i) {
         HTMLGenericFormElement* current = formElements[i];
         FormDataList lst(encoding);
@@ -265,13 +267,13 @@ bool HTMLFormElement::formData(FormData& result) const
                     hstr += "\r\n\r\n";
 
                     // append body
-                    result.appendData(hstr.data(), hstr.length());
+                    result->appendData(hstr.data(), hstr.length());
                     const FormDataListItem& item = lst.list()[j + 1];
                     if (size_t dataSize = item.m_data.length())
-                        result.appendData(item.m_data, dataSize);
+                        result->appendData(item.m_data, dataSize);
                     else if (!item.m_path.isEmpty())
-                        result.appendFile(item.m_path);
-                    result.appendData("\r\n", 2);
+                        result->appendFile(item.m_path);
+                    result->appendData("\r\n", 2);
 
                     ++j;
                 }
@@ -283,8 +285,8 @@ bool HTMLFormElement::formData(FormData& result) const
     if (m_multipart)
         enc_string = ("--" + m_boundary.deprecatedString() + "--\r\n").ascii();
 
-    result.appendData(enc_string.data(), enc_string.length());
-    return true;
+    result->appendData(enc_string.data(), enc_string.length());
+    return result;
 }
 
 void HTMLFormElement::parseEnctype(const String& type)
@@ -373,13 +375,11 @@ void HTMLFormElement::submit(Event* event, bool activateSubmitButton)
     if (!m_post)
         m_multipart = false;
     
-    FormData postData;
-    if (formData(postData)) {
-        if (m_post)
-            frame->loader()->submitForm("POST", m_url, postData, m_target, enctype(), boundary(), event);
-        else
-            frame->loader()->submitForm("GET", m_url, postData, m_target, String(), String(), event);
-    }
+    RefPtr<FormData> postData = formData();
+    if (m_post)
+        frame->loader()->submitForm("POST", m_url, postData, m_target, enctype(), boundary(), event);
+    else
+        frame->loader()->submitForm("GET", m_url, postData, m_target, String(), String(), event);
 
     if (needButtonActivation && firstSuccessfulSubmitButton)
         firstSuccessfulSubmitButton->setActivatedSubmit(false);
index 22f3ebe9ee56ce1c19d1cd2b80b68d2fd9886b78..24190bd7c85bf9a7ad7e1dd271d6fd28bc1f20b8 100644 (file)
@@ -124,7 +124,7 @@ public:
 
 private:
     void parseEnctype(const String&);
-    bool formData(FormData&) const;
+    PassRefPtr<FormData> formData() const;
 
     unsigned formElementIndex(HTMLGenericFormElement*);
 
index 2626b404f630a1f69f83c79704a835639a72467f..36e5b2a6e65acf6e57724ae97813d727c6b86e71 100644 (file)
@@ -86,13 +86,13 @@ using namespace EventNames;
 struct FormSubmission {
     const char* action;
     String URL;
-    FormData data;
+    RefPtr<FormData> data;
     String target;
     String contentType;
     String boundary;
     RefPtr<Event> event;
 
-    FormSubmission(const char* a, const String& u, const FormData& d, const String& t,
+    FormSubmission(const char* a, const String& u, PassRefPtr<FormData> d, const String& t,
             const String& ct, const String& b, PassRefPtr<Event> e)
         : action(a)
         , URL(u)
@@ -420,9 +420,11 @@ void FrameLoader::submitFormAgain()
             form->contentType, form->boundary, form->event.get());
 }
 
-void FrameLoader::submitForm(const char* action, const String& url, const FormData& formData,
+void FrameLoader::submitForm(const char* action, const String& url, PassRefPtr<FormData> formData,
     const String& target, const String& contentType, const String& boundary, Event* event)
 {
+    ASSERT(formData.get());
+    
     KURL u = completeURL(url.isNull() ? "" : url);
     if (!u.isValid())
         return;
@@ -438,7 +440,7 @@ void FrameLoader::submitForm(const char* action, const String& url, const FormDa
     if (m_isRunningScript) {
         if (m_deferredFormSubmission)
             return;
-        m_deferredFormSubmission.set(new FormSubmission(action, url, formData, target,
+        m_deferredFormSubmission.set(new FormSubmission(action, url, formData.get(), target,
             contentType, boundary, event));
         return;
     }
@@ -457,16 +459,16 @@ void FrameLoader::submitForm(const char* action, const String& url, const FormDa
         DeprecatedString encodedBody;
         if (equalIgnoringCase(contentType, "multipart/form-data"))
             // FIXME: is this correct? I suspect not, but what site can we test this on?
-            encodedBody = KURL::encode_string(formData.flattenToString().deprecatedString());
+            encodedBody = KURL::encode_string(formData.get()->flattenToString().deprecatedString());
         else if (equalIgnoringCase(contentType, "text/plain")) {
             // Convention seems to be to decode, and s/&/\n/
-            encodedBody = formData.flattenToString().deprecatedString();
+            encodedBody = formData.get()->flattenToString().deprecatedString();
             encodedBody.replace('&', '\n');
             encodedBody.replace('+', ' ');
             encodedBody = KURL::decode_string(encodedBody); // Decode the rest of it
             encodedBody = KURL::encode_string(encodedBody); // Recode for the URL
         } else
-            encodedBody = KURL::encode_string(formData.flattenToString().deprecatedString());
+            encodedBody = KURL::encode_string(formData.get()->flattenToString().deprecatedString());
 
         DeprecatedString query = u.query();
         if (!query.isEmpty())
@@ -478,9 +480,9 @@ void FrameLoader::submitForm(const char* action, const String& url, const FormDa
 
     if (strcmp(action, "GET") == 0) {
         if (!mailtoForm)
-            u.setQuery(formData.flattenToString().deprecatedString());
+            u.setQuery(formData.get()->flattenToString().deprecatedString());
     } else {
-        frameRequest.resourceRequest().setHTTPBody(formData);
+        frameRequest.resourceRequest().setHTTPBody(formData.get());
         frameRequest.resourceRequest().setHTTPMethod("POST");
 
         // construct some user headers if necessary
index 97a35df3325be6b6605827c7971b8d85fef35595..9f882e3dd3e18ec5de9ce0f4a7b5350b341abefc 100644 (file)
@@ -176,7 +176,7 @@ namespace WebCore {
         void load(const KURL&, const String& referrer, FrameLoadType, const String& target,
             Event*, Element* form, const HashMap<String, String>& formValues);
         void post(const KURL&, const String& referrer, const String& target,
-            const FormData&, const String& contentType,
+            PassRefPtr<FormData>, const String& contentType,
             Event*, Element* form, const HashMap<String, String>& formValues);
 #if PLATFORM(MAC)
         void load(NSURLRequest *);
@@ -343,7 +343,7 @@ namespace WebCore {
         Frame* createFrame(const KURL& URL, const String& name, Element* ownerElement, const String& referrer);
         Frame* loadSubframe(Element* ownerElement, const KURL& URL, const String& name, const String& referrer);
 
-        void submitForm(const char* action, const String& URL, const FormData&, const String& target, const String& contentType, const String& boundary, Event*);
+        void submitForm(const char* action, const String& URL, PassRefPtr<FormData>, const String& target, const String& contentType, const String& boundary, Event*);
         void submitFormAgain();
         void submitForm(const FrameLoadRequest&, Event*);
 
index d11c60dd5f2effc14245e7dea8aceeae8e33204c..b67dcf81aa9225bb8d8efc4a88ac776f3f7c7b48 100644 (file)
@@ -1099,7 +1099,7 @@ void FrameLoader::loadedResourceFromMemoryCache(NSURLRequest *request, NSURLResp
     sendRemainingDelegateMessages(identifier, response, length, error);
 }
 
-void FrameLoader::post(const KURL& URL, const String& referrer, const String& frameName, const FormData& formData, 
+void FrameLoader::post(const KURL& URL, const String& referrer, const String& frameName, PassRefPtr<FormData> formData, 
     const String& contentType, Event* event, Element* form, const HashMap<String, String>& formValues)
 {
     // When posting, use the NSURLRequestReloadIgnoringCacheData load flag.
@@ -1206,8 +1206,9 @@ void FrameLoader::loadResourceSynchronously(const ResourceRequest& request, Vect
     
     [initialRequest setHTTPMethod:request.httpMethod()];
     
-    if (!request.httpBody().isEmpty())        
-        setHTTPBody(initialRequest, request.httpBody());
+    RefPtr<FormData> formData = request.httpBody();
+    if (formData && !formData->isEmpty())        
+        setHTTPBody(initialRequest, formData);
     
     HTTPHeaderMap::const_iterator end = request.httpHeaderFields().end();
     for (HTTPHeaderMap::const_iterator it = request.httpHeaderFields().begin(); it != end; ++it)
index d9aef283095fcf6178f5ba0725ac047232010c6a..272be58068d0a4c60b919b6cf550365c1b58baa7 100644 (file)
@@ -73,8 +73,9 @@ PassRefPtr<SubresourceLoader> SubresourceLoader::create(Frame* frame, ResourceHa
 
     // FIXME: Because of <rdar://problem/4803505>, the method has to be set before the body.
     [newRequest setHTTPMethod:request.httpMethod()];
-    if (!request.httpBody().isEmpty())
-        setHTTPBody(newRequest, request.httpBody());
+    RefPtr<FormData> formData = request.httpBody();
+    if (formData && !formData->isEmpty())
+        setHTTPBody(newRequest, formData);
 
     wkSupportsMultipartXMixedReplace(newRequest);
 
index cd612df9965da1abc075833989ffceb0cf5b16b1..cdfefeb97eb214c7f482f8678d6ef73c67f2d0ee 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "DeprecatedValueList.h"
 #include "PlatformString.h"
+#include "Shared.h"
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -37,12 +38,12 @@ public:
     String m_filename;
 };
 
-class FormData {
+class FormData : public Shared<FormData> {
 public:
     FormData() { } 
     FormData(const void* data, size_t);
     FormData(const CString&);
-
+    
     void appendData(const void* data, size_t);
     void appendFile(const String& filename);
 
index 7690e4fffd67e812f526a7a5d4cce7e36015f142..40b63a6942e27a044d4bcb09554dabe87bf85264 100644 (file)
@@ -67,7 +67,7 @@ const KURL& ResourceHandle::url() const
     return d->m_request.url();
 }
 
-const FormData& ResourceHandle::postData() const
+const PassRefPtr<FormData> ResourceHandle::postData() const
 {
     return d->m_request.httpBody();
 }
index 6acce61d0e395a0eefae6f87c7f5cc1156940dcf..251e1c83f457acc5c41055e0f741aa6fe760c013 100644 (file)
@@ -111,7 +111,7 @@ public:
     const HTTPHeaderMap& requestHeaders() const;
     const KURL& url() const;
     const String& method() const;
-    const FormData& postData() const;
+    const PassRefPtr<FormData> postData() const;
 
 private:
     bool start(DocLoader*);
index 340950c98e5f3a55c69ff6099f0614f2e9b146d4..e56be596a9bf4aaef8d10e034a5a1e3a850df63d 100644 (file)
@@ -114,9 +114,9 @@ namespace WebCore {
         String httpAccept() const { return httpHeaderField("Accept"); }
         void setHTTPAccept(const String& httpUserAgent) { setHTTPHeaderField("Accept", httpUserAgent); }
 
-        const FormData& httpBody() const { return m_httpBody; }
-        FormData& httpBody() { return m_httpBody; }
-        void setHTTPBody(const FormData& httpBody) { m_httpBody = httpBody; } 
+        const PassRefPtr<FormData> httpBody() const { return m_httpBody; }
+        PassRefPtr<FormData> httpBody() { return m_httpBody; }
+        void setHTTPBody(PassRefPtr<FormData> httpBody) { m_httpBody = httpBody; } 
         
         bool allowHTTPCookies() const { return m_allowHTTPCookies; }
         void setAllowHTTPCookies(bool allowHTTPCookies) { m_allowHTTPCookies = allowHTTPCookies; }
@@ -131,7 +131,7 @@ namespace WebCore {
         KURL m_mainDocumentURL;
         String m_httpMethod;
         HTTPHeaderMap m_httpHeaderFields;
-        FormData m_httpBody;
+        RefPtr<FormData> m_httpBody;
         bool m_allowHTTPCookies;
     };
 
index 870550ffd44cf4ce1ed00e785ba6e95305435494..595a414309aad820625bfbeec733223f61309a10 100644 (file)
 #ifndef FormDataStreamMac_h_
 #define FormDataStreamMac_h_
 
+#include "FormData.h"
+
 @class NSMutableURLRequest;
 
 namespace WebCore {
     class FormData;
-    void setHTTPBody(NSMutableURLRequest *, const FormData&);
-    const FormData* httpBodyFromStream(NSInputStream* stream);
+    void setHTTPBody(NSMutableURLRequest *, PassRefPtr<FormData>);
+    const PassRefPtr<FormData> httpBodyFromStream(NSInputStream* stream);
 }
 
 #endif // FormDataStreamMac_h_
index 1fb149659eb36fd101cf93af68f122893e203678..ff83554be76a1a7b3bf9e87fd43df3ac356e8f8e 100644 (file)
 
 namespace WebCore {
 
-static HashMap<CFReadStreamRef, const FormData*>* streamFormDatas = 0;
+static HashMap<CFReadStreamRef, RefPtr<FormData> >* streamFormDatas = 0;
 
-static HashMap<CFReadStreamRef, const FormData*>* getStreamFormDatas()
+static HashMap<CFReadStreamRef, RefPtr<FormData> >* getStreamFormDatas()
 {
     if (!streamFormDatas)
-        streamFormDatas = new HashMap<CFReadStreamRef, const FormData*>();
+        streamFormDatas = new HashMap<CFReadStreamRef, RefPtr<FormData> >();
     return streamFormDatas;
 }
 
@@ -166,7 +166,7 @@ static void openNextStream(FormStreamFields* form)
 
 static void* formCreate(CFReadStreamRef stream, void* context)
 {
-    const FormData* formData = static_cast<const FormData*>(context);
+    RefPtr<FormData> formData = static_cast<FormData*>(context);
 
     CFSetCallBacks runLoopAndModeCallBacks = { 0, pairRetain, pairRelease, NULL, pairEqual, pairHash };
 
@@ -182,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, formData);
 
     return newInfo;
 }
@@ -191,7 +191,6 @@ static void formFinalize(CFReadStreamRef stream, void* context)
 {
     FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
-    delete getStreamFormDatas()->get(stream);
     getStreamFormDatas()->remove(stream);
 
     closeCurrentStream(form);
@@ -305,13 +304,13 @@ static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, vo
     }
 }
 
-void setHTTPBody(NSMutableURLRequest *request, const FormData& formData)
+void setHTTPBody(NSMutableURLRequest *request, PassRefPtr<FormData> formData)
 {
-    size_t count = formData.elements().size();
+    size_t count = formData.get()->elements().size();
 
     // 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.get()->elements()[0];
         if (element.m_type == FormDataElement::data) {
             NSData *data = [[NSData alloc] initWithBytes:element.m_data.data() length:element.m_data.size()];
             [request setHTTPBody:data];
@@ -323,7 +322,7 @@ void setHTTPBody(NSMutableURLRequest *request, const FormData& formData)
     // Precompute the content length so NSURLConnection doesn't use chunked mode.
     long long length = 0;
     for (size_t i = 0; i < count; ++i) {
-        const FormDataElement& element = formData.elements()[i];
+        const FormDataElement& element = formData.get()->elements()[i];
         if (element.m_type == FormDataElement::data)
             length += element.m_data.size();
         else {
@@ -340,15 +339,15 @@ void setHTTPBody(NSMutableURLRequest *request, const FormData& formData)
     // Create and set the stream.
     CFReadStreamRef stream = wkCreateCustomCFReadStream(formCreate, formFinalize,
         formOpen, formRead, formCanRead, formClose, formSchedule, formUnschedule,
-        const_cast<FormData*>(&formData));
+        formData.get());
     [request setHTTPBodyStream:(NSInputStream *)stream];
     CFRelease(stream);
 }
 
 
-const FormData* httpBodyFromStream(NSInputStream* stream)
+const PassRefPtr<FormData> httpBodyFromStream(NSInputStream* stream)
 {
-    return getStreamFormDatas()->get((CFReadStreamRef)stream);
+    return PassRefPtr<FormData>(getStreamFormDatas()->get((CFReadStreamRef)stream));
 }
 
 }
index 9af6e75e4a2e593601771b19ad67c2c49b8c47ac..685eaf0612a515e2821f7c4e526e318628d4d35a 100644 (file)
@@ -52,10 +52,10 @@ namespace WebCore {
             request.setHTTPHeaderField(name, [headers objectForKey:name]);
 
         if (NSData* bodyData = [nsRequest HTTPBody])
-            request.setHTTPBody(FormData([bodyData bytes], [bodyData length]));
+            request.setHTTPBody(PassRefPtr<FormData>(new FormData([bodyData bytes], [bodyData length])));
         else if (NSInputStream* bodyStream = [nsRequest HTTPBodyStream])
-            if (const FormData* formData = httpBodyFromStream(bodyStream))
-                request.setHTTPBody(*formData);
+            if (const PassRefPtr<FormData> formData = httpBodyFromStream(bodyStream))
+                request.setHTTPBody(formData);
         // FIXME: what to do about arbitrary body streams?
     }
 
@@ -74,8 +74,9 @@ namespace WebCore {
         for (HTTPHeaderMap::const_iterator it = request.httpHeaderFields().begin(); it != end; ++it)
             [nsRequest setValue:it->second forHTTPHeaderField:it->first];
 
-        if (!request.httpBody().isEmpty())
-            setHTTPBody(nsRequest, request.httpBody());
+        RefPtr<FormData> formData = request.httpBody();
+        if (formData && !formData->isEmpty())
+            setHTTPBody(nsRequest, formData);
 
         return [nsRequest autorelease];
     }
index 49a17425420159f82b2079f43b2e6f8cb7d517b5..5bf664859f9cbcc8e89623a4b9981f51f0d1edaa 100644 (file)
@@ -318,7 +318,7 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
         if (!m_encoding.isValid()) // FIXME: report an error?
             m_encoding = UTF8Encoding();
 
-        request.setHTTPBody(m_encoding.encode(body.characters(), body.length()));
+        request.setHTTPBody(PassRefPtr<FormData>(new FormData(m_encoding.encode(body.characters(), body.length()))));
     }
 
     if (m_requestHeaders.size() > 0)