WebCore:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 29 Oct 2006 08:47:23 +0000 (08:47 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 29 Oct 2006 08:47:23 +0000 (08:47 +0000)
        Reviewed by Maciej.

        - eliminate use of NSArray to carry form data around

        * WebCore.exp:
        * WebCore.xcodeproj/project.pbxproj:
        * bridge/mac/FormDataMac.h: Removed.
        * bridge/mac/FormDataMac.mm: Removed.
        * bridge/mac/FrameMac.h:
        * bridge/mac/WebCoreFrameBridge.h:
        * bridge/mac/WebCoreFrameBridge.mm:
        * html/HTMLFormElement.cpp:
        (WebCore::HTMLFormElement::submit):
        * loader/FormData.h:
        (WebCore::FormData::isEmpty):
        * loader/mac/FrameLoader.h:
        * loader/mac/FrameLoader.mm:
        (WebCore::FrameLoader::load):
        (WebCore::FrameLoader::post):
        (WebCore::FrameLoader::loadEmptyDocumentSynchronously):
        (WebCore::FrameLoader::loadResourceSynchronously):
        * loader/mac/LoaderFunctionsMac.mm:
        (WebCore::ServeSynchronousRequest):
        * loader/mac/WebFormDataStream.h:
        * loader/mac/WebFormDataStream.m:
        (WebCore::pairRetain):
        (WebCore::pairRelease):
        (WebCore::pairEqual):
        (WebCore::pairHash):
        (WebCore::closeCurrentStream):
        (WebCore::scheduleWithPair):
        (WebCore::advanceCurrentStream):
        (WebCore::openNextStream):
        (WebCore::formCreate):
        (WebCore::formFinalize):
        (WebCore::formOpen):
        (WebCore::formRead):
        (WebCore::formCanRead):
        (WebCore::formClose):
        (WebCore::formSchedule):
        (WebCore::formUnschedule):
        (WebCore::formEventCallback):
        (WebCore::setHTTPBody):
        * loader/mac/WebSubresourceLoader.h:
        * loader/mac/WebSubresourceLoader.mm:
        (WebCore::SubresourceLoader::create):
        * platform/network/mac/ResourceLoaderMac.mm:

WebKit:

        Reviewed by Maciej.

        - eliminate use of NSArray to carry form data around
          (the code in this framework was actually using the NSArray to hold a single
           NSData anyway, so I just went back to an NSData for now)

        * History/WebHistoryItem.m:
        (-[WebHistoryItem _setFormInfoFromRequest:]):
        (-[WebHistoryItem formData]):
        * History/WebHistoryItemPrivate.h:
        * WebCoreSupport/WebFrameLoaderClient.mm:
        (WebFrameLoaderClient::dispatchWillSubmitForm):
        * WebView/WebFrame.mm:
        (-[WebFrame _loadItem:withLoadType:]):

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

23 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bridge/mac/FormDataMac.h [deleted file]
WebCore/bridge/mac/FormDataMac.mm [deleted file]
WebCore/bridge/mac/FrameMac.h
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/html/HTMLFormElement.cpp
WebCore/loader/FormData.h
WebCore/loader/mac/FrameLoader.h
WebCore/loader/mac/FrameLoader.mm
WebCore/loader/mac/LoaderFunctionsMac.mm
WebCore/loader/mac/WebFormDataStream.h
WebCore/loader/mac/WebFormDataStream.m
WebCore/loader/mac/WebSubresourceLoader.h
WebCore/loader/mac/WebSubresourceLoader.mm
WebCore/platform/network/mac/ResourceLoaderMac.mm
WebKit/ChangeLog
WebKit/History/WebHistoryItem.m
WebKit/History/WebHistoryItemPrivate.h
WebKit/WebCoreSupport/WebFrameLoaderClient.mm
WebKit/WebView/WebFrame.mm

index 8f05fa40b26e43063acfc654309a138f431daac3..eea7c3a9a72c2f57692d95b4462d258e11233187 100644 (file)
@@ -1,3 +1,53 @@
+t2006-10-29  Darin Adler  <darin@apple.com>
+
+        Reviewed by Maciej.
+
+        - eliminate use of NSArray to carry form data around
+
+        * WebCore.exp:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bridge/mac/FormDataMac.h: Removed.
+        * bridge/mac/FormDataMac.mm: Removed.
+        * bridge/mac/FrameMac.h:
+        * bridge/mac/WebCoreFrameBridge.h:
+        * bridge/mac/WebCoreFrameBridge.mm:
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::submit):
+        * loader/FormData.h:
+        (WebCore::FormData::isEmpty):
+        * loader/mac/FrameLoader.h:
+        * loader/mac/FrameLoader.mm:
+        (WebCore::FrameLoader::load):
+        (WebCore::FrameLoader::post):
+        (WebCore::FrameLoader::loadEmptyDocumentSynchronously):
+        (WebCore::FrameLoader::loadResourceSynchronously):
+        * loader/mac/LoaderFunctionsMac.mm:
+        (WebCore::ServeSynchronousRequest):
+        * loader/mac/WebFormDataStream.h:
+        * loader/mac/WebFormDataStream.m:
+        (WebCore::pairRetain):
+        (WebCore::pairRelease):
+        (WebCore::pairEqual):
+        (WebCore::pairHash):
+        (WebCore::closeCurrentStream):
+        (WebCore::scheduleWithPair):
+        (WebCore::advanceCurrentStream):
+        (WebCore::openNextStream):
+        (WebCore::formCreate):
+        (WebCore::formFinalize):
+        (WebCore::formOpen):
+        (WebCore::formRead):
+        (WebCore::formCanRead):
+        (WebCore::formClose):
+        (WebCore::formSchedule):
+        (WebCore::formUnschedule):
+        (WebCore::formEventCallback):
+        (WebCore::setHTTPBody):
+        * loader/mac/WebSubresourceLoader.h:
+        * loader/mac/WebSubresourceLoader.mm:
+        (WebCore::SubresourceLoader::create):
+        * platform/network/mac/ResourceLoaderMac.mm:
+
 2006-10-29  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Darin.
index 56762d69d1505ac8b68dc079ac6f575ad7c82913..ce1da473b1450d5489f9dc381f2e9b744302382c 100644 (file)
@@ -301,7 +301,6 @@ _urlOriginalData
 _urlOriginalDataAsString
 _urlWithData
 _urlWithDataRelativeToURL
-_webSetHTTPBody
 _wkCGContextGetShouldSmoothFonts
 _wkClearGlyphVector
 _wkConvertCharToGlyphs
index 2bd9131b900611d5b604dfbdab13419092c0c26a..14e5805a284d27f9b72478a49ba8fb0eaaa7d0af 100644 (file)
                93F199EC08245E59001E9ABC /* XSLStyleSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = BC06F24A06D18A7E004A6FA3 /* XSLStyleSheet.h */; };
                93F199ED08245E59001E9ABC /* XSLTProcessor.h in Headers */ = {isa = PBXBuildFile; fileRef = BC06F24C06D18A7E004A6FA3 /* XSLTProcessor.h */; };
                93F199EE08245E59001E9ABC /* FormData.h in Headers */ = {isa = PBXBuildFile; fileRef = 93ABCE5E06E1A42E0085925B /* FormData.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               93F199EF08245E59001E9ABC /* FormDataMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B641F206E28C5C0055F610 /* FormDataMac.h */; };
                93F199F008245E59001E9ABC /* WebCoreView.h in Headers */ = {isa = PBXBuildFile; fileRef = BE855F7F0701E83500239769 /* WebCoreView.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93F199F108245E59001E9ABC /* WebDashboardRegion.h in Headers */ = {isa = PBXBuildFile; fileRef = 5150C2A10702629000AF642C /* WebDashboardRegion.h */; settings = {ATTRIBUTES = (Private, ); }; };
                93F19A1808245E59001E9ABC /* DeprecatedCString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F58784D502DE375901EA4122 /* DeprecatedCString.cpp */; };
                93F19B0308245E59001E9ABC /* XSLStyleSheet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC06F24906D18A7E004A6FA3 /* XSLStyleSheet.cpp */; };
                93F19B0408245E59001E9ABC /* XSLTProcessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC06F24B06D18A7E004A6FA3 /* XSLTProcessor.cpp */; };
                93F19B0508245E59001E9ABC /* FormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93ABCE5D06E1A42E0085925B /* FormData.cpp */; };
-               93F19B0608245E59001E9ABC /* FormDataMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93B641F106E28C5C0055F610 /* FormDataMac.mm */; };
                93F19B0708245E59001E9ABC /* WebCoreView.m in Sources */ = {isa = PBXBuildFile; fileRef = BE8560510701F91100239769 /* WebCoreView.m */; };
                93F19B0808245E59001E9ABC /* WebDashboardRegion.m in Sources */ = {isa = PBXBuildFile; fileRef = 5150C2A50702629800AF642C /* WebDashboardRegion.m */; };
                93F19B1308245E59001E9ABC /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C2869302846DCD018635CA /* ApplicationServices.framework */; };
                656D371E0ADBA5DE00A4554D /* WebDocumentLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebDocumentLoader.h; sourceTree = "<group>"; };
                656D371F0ADBA5DE00A4554D /* WebDocumentLoader.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = WebDocumentLoader.mm; sourceTree = "<group>"; };
                656D37200ADBA5DE00A4554D /* WebFormDataStream.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebFormDataStream.h; sourceTree = "<group>"; };
-               656D37210ADBA5DE00A4554D /* WebFormDataStream.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = WebFormDataStream.m; sourceTree = "<group>"; };
+               656D37210ADBA5DE00A4554D /* WebFormDataStream.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = WebFormDataStream.m; sourceTree = "<group>"; };
                656D37220ADBA5DE00A4554D /* WebFormState.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebFormState.h; sourceTree = "<group>"; };
                656D37230ADBA5DE00A4554D /* WebFormState.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = WebFormState.mm; sourceTree = "<group>"; };
                656D37240ADBA5DE00A4554D /* FrameLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoader.h; sourceTree = "<group>"; };
                93AE23200AAB521B00CD8A35 /* TextEncodingRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingRegistry.cpp; sourceTree = "<group>"; };
                93B0FD880A759BED0080AD44 /* StringImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = StringImplMac.mm; sourceTree = "<group>"; };
                93B0FD890A759BED0080AD44 /* StringMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = StringMac.mm; sourceTree = "<group>"; };
-               93B641F106E28C5C0055F610 /* FormDataMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FormDataMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
-               93B641F206E28C5C0055F610 /* FormDataMac.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = FormDataMac.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                93B70D4109EB0C7C009D8468 /* JSXMLHttpRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSXMLHttpRequest.cpp; sourceTree = "<group>"; };
                93B70D4209EB0C7C009D8468 /* JSXMLHttpRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSXMLHttpRequest.h; sourceTree = "<group>"; };
                93B70D4509EB0C7C009D8468 /* JSXSLTProcessor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSXSLTProcessor.cpp; sourceTree = "<group>"; };
                                55998A5D052B59CC0017A6C1 /* AXObjectCacheMac.mm */,
                                BCEA4945097F0F770094C9E4 /* BrowserExtensionMac.h */,
                                BCEA4946097F0F770094C9E4 /* BrowserExtensionMac.mm */,
-                               93B641F206E28C5C0055F610 /* FormDataMac.h */,
-                               93B641F106E28C5C0055F610 /* FormDataMac.mm */,
                                65BF023B0974819000C43196 /* FrameMac.h */,
                                65BF023C0974819000C43196 /* FrameMac.mm */,
                                9380F68609A143B2001FDB34 /* FrameViewMac.mm */,
                                93F199EC08245E59001E9ABC /* XSLStyleSheet.h in Headers */,
                                93F199ED08245E59001E9ABC /* XSLTProcessor.h in Headers */,
                                93F199EE08245E59001E9ABC /* FormData.h in Headers */,
-                               93F199EF08245E59001E9ABC /* FormDataMac.h in Headers */,
                                93F199F008245E59001E9ABC /* WebCoreView.h in Headers */,
                                93F199F108245E59001E9ABC /* WebDashboardRegion.h in Headers */,
                                550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */,
                                93F19B0308245E59001E9ABC /* XSLStyleSheet.cpp in Sources */,
                                93F19B0408245E59001E9ABC /* XSLTProcessor.cpp in Sources */,
                                93F19B0508245E59001E9ABC /* FormData.cpp in Sources */,
-                               93F19B0608245E59001E9ABC /* FormDataMac.mm in Sources */,
                                93F19B0708245E59001E9ABC /* WebCoreView.m in Sources */,
                                93F19B0808245E59001E9ABC /* WebDashboardRegion.m in Sources */,
                                550A0BC9085F6039007353D6 /* QualifiedName.cpp in Sources */,
diff --git a/WebCore/bridge/mac/FormDataMac.h b/WebCore/bridge/mac/FormDataMac.h
deleted file mode 100644 (file)
index bb87e58..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-namespace WebCore {
-
-    class FormData;
-
-    NSArray *arrayFromFormData(const FormData&);
-
-}
diff --git a/WebCore/bridge/mac/FormDataMac.mm b/WebCore/bridge/mac/FormDataMac.mm
deleted file mode 100644 (file)
index 6e547c8..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#include "config.h"
-#import "FormDataMac.h"
-
-#import <wtf/Assertions.h>
-#import "FormData.h"
-
-namespace WebCore {
-
-NSArray *arrayFromFormData(const FormData &d)
-{
-    size_t n = d.elements().size();
-    NSMutableArray *a = [NSMutableArray arrayWithCapacity:n];
-    for (size_t i = 0; i < n; ++i) {
-        const FormDataElement& e = d.elements()[i];
-        if (e.m_type == FormDataElement::data)
-            [a addObject:[NSData dataWithBytes:e.m_data.data() length:e.m_data.size()]];
-        else {
-            ASSERT(e.m_type == FormDataElement::encodedFile);
-            [a addObject:e.m_filename];
-        }
-    }
-    return a;
-}
-
-}
index e7f11095eba75553f6b41195969a79d535a504aa..073435e4fcbac8f536bb077ae0a7e61a4d8b3b23 100644 (file)
@@ -121,10 +121,11 @@ public:
     virtual Plugin* createPlugin(Element*, const KURL&,
         const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType);
 
-    void clear(bool clearWindowProperties = true);
+    virtual void clear(bool clearWindowProperties = true);
 
     void setBridge(WebCoreFrameBridge* p);
     WebCoreFrameBridge* bridge() const { return _bridge; }
+
     virtual void setView(FrameView*);
     virtual void frameDetached();
 
@@ -225,7 +226,7 @@ public:
     bool passSubframeEventToSubframe(MouseEventWithHitTestResults&, Frame* subframePart);
     bool passWheelEventToWidget(Widget*);
     
-    NSString* searchForLabelsAboveCell(RegularExpression* regExp, HTMLTableCellElement* cell);
+    NSString* searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
     NSString* searchForLabelsBeforeElement(NSArray* labels, Element* element);
     NSString* matchLabelsAgainstElement(NSArray* labels, Element* element);
 
index 7b83ca00ae25fa9bf2501d769e20f520da8d07da..7f39b40644013ae819331fbbb5d50487023033df 100644 (file)
@@ -394,7 +394,6 @@ typedef enum {
 - (NSURL*)originalRequestURL;
 - (void)frameDetached;
 - (void)receivedData:(NSData *)data textEncodingName:(NSString *)textEncodingName;
-- (NSData *)syncLoadResourceWithMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)requestHeaders postData:(NSArray *)postData finalURL:(NSURL **)finalNSURL responseHeaders:(NSDictionary **)responseHeaderDict statusCode:(int *)statusCode;
 
 @end
 
index 7f1300d16b2188f78deae7cef6a88fafd3947b9f..5bd0adee3a690a4bdf7e17d3aff99eac0cb79e03 100644 (file)
@@ -2069,79 +2069,6 @@ static NSCharacterSet *_getPostSmartSet(void)
     [self addData:data];
 }
 
-- (NSData *)syncLoadResourceWithMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)requestHeaders postData:(NSArray *)postData finalURL:(NSURL **)finalURL responseHeaders:(NSDictionary **)responseHeaderDict statusCode:(int *)statusCode
-{
-    // Since this is a subresource, we can load any URL (we ignore the return value).
-    // But we still want to know whether we should hide the referrer or not, so we call the canLoadURL method.
-    String referrer = m_frame->referrer();
-    bool hideReferrer;
-    m_frame->loader()->canLoad(URL, referrer, hideReferrer);
-    if (hideReferrer)
-        referrer = String();
-    
-    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];
-    [request setTimeoutInterval:10];
-    
-    // setHTTPMethod is not called for GET requests to work around <rdar://4464032>.
-    if (![method isEqualToString:@"GET"])
-        [request setHTTPMethod:method];
-    
-    if (postData)        
-        webSetHTTPBody(request, postData);
-    
-    NSEnumerator *e = [requestHeaders keyEnumerator];
-    NSString *key;
-    while ((key = (NSString *)[e nextObject]) != nil) {
-        [request addValue:[requestHeaders objectForKey:key] forHTTPHeaderField:key];
-    }
-    
-    if (isConditionalRequest(request))
-        [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
-    else
-        [request setCachePolicy:[m_frame->loader()->documentLoader()->request() cachePolicy]];
-    
-    if (!referrer.isNull())
-        setHTTPReferrer(request, referrer);
-    
-    [request setMainDocumentURL:[m_frame->page()->mainFrame()->loader()->documentLoader()->request() URL]];
-    [request setValue:m_frame->loader()->client()->userAgent([request URL]) forHTTPHeaderField:@"User-Agent"];
-    
-    NSError *error = nil;
-    id identifier = nil;    
-    NSURLRequest *newRequest = m_frame->loader()->requestFromDelegate(request, identifier, error);
-    
-    NSURLResponse *response = nil;
-    NSData *result = nil;
-    if (error == nil) {
-        ASSERT(newRequest != nil);
-        result = [NSURLConnection sendSynchronousRequest:newRequest returningResponse:&response error:&error];
-    }
-    
-    if (error == nil) {
-        *finalURL = [response URL];
-        if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
-            NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; 
-            *responseHeaderDict = [httpResponse allHeaderFields];
-            *statusCode = [httpResponse statusCode];
-        } else {
-            *responseHeaderDict = [NSDictionary dictionary];
-            *statusCode = 200;
-        }
-    } else {
-        *finalURL = URL;
-        *responseHeaderDict = [NSDictionary dictionary];
-        if ([error domain] == NSURLErrorDomain)
-            *statusCode = [error code];
-        else
-            *statusCode = 404;
-    }
-    
-    m_frame->loader()->sendRemainingDelegateMessages(identifier, response, [result length], error);
-    [request release];
-    
-    return result;
-}
-
 // -------------------
 
 - (FrameMac*)_frame
index 6212f6b39faf1d14bc58403f1a4a0332a246a6f6..c6e61d45aa0b3c6593956c32903ac117efcd8cd0 100644 (file)
@@ -325,7 +325,7 @@ bool HTMLFormElement::prepareSubmit()
     return m_doingsubmit;
 }
 
-void HTMLFormElement::submit( bool activateSubmitButton )
+void HTMLFormElement::submit(bool activateSubmitButton)
 {
     FrameView *view = document()->view();
     Frame *frame = document()->frame();
@@ -345,17 +345,14 @@ void HTMLFormElement::submit( bool activateSubmitButton )
     frame->clearRecordedFormValues();
     for (unsigned i = 0; i < formElements.size(); ++i) {
         HTMLGenericFormElement* current = formElements[i];
-        // Our app needs to get form values for password fields for doing password autocomplete,
-        // so we are more lenient in pushing values, and let the app decide what to save when.
         if (current->hasLocalName(inputTag)) {
-            HTMLInputElement *input = static_cast<HTMLInputElement*>(current);
+            HTMLInputElementinput = static_cast<HTMLInputElement*>(current);
             if (input->isTextField()) {
-                frame->recordFormValue(input->name().deprecatedString(), input->value().deprecatedString(), this);
+                frame->recordFormValue(input->name(), input->value(), this);
                 if (input->renderer() && input->inputType() == HTMLInputElement::SEARCH)
                     static_cast<RenderLineEdit*>(input->renderer())->addSearchResult();
             }
         }
-
         if (needButtonActivation) {
             if (current->isActivatedSubmit())
                 needButtonActivation = false;
index d98618faab019ef5e6d46813ad6c95af61f412a9..cd612df9965da1abc075833989ffceb0cf5b16b1 100644 (file)
@@ -49,6 +49,7 @@ public:
     void flatten(Vector<char>&) const; // omits files
     String flattenToString() const; // omits files
 
+    bool isEmpty() const { return m_elements.isEmpty(); }
     const Vector<FormDataElement>& elements() const { return m_elements; }
 
 private:
index 14fbf577210f48d2225cfcea6fadda4d563699ac..c708646baef7d0c45721e0d455784f9504890c4c 100644 (file)
 
 #ifdef __OBJC__
 
-@class WebCoreFrameBridge;
 @class WebCorePageState;
 
-@class NSArray;
+@class NSData;
 @class NSDate;
-@class NSURL;
-@class NSURLConnection;
-@class NSURLRequest;
-@class NSURLResponse;
 @class NSDictionary;
-@class NSEvent;
 @class NSError;
-@class NSData;
+@class NSEvent;
 @class NSMutableURLRequest;
+@class NSURL;
 @class NSURLAuthenticationChallenge;
+@class NSURLConnection;
+@class NSURLRequest;
+@class NSURLResponse;
 
 @protocol WebCoreResourceLoader;
 @protocol WebCoreResourceHandle;
 
 #else
 
-class WebCoreFrameBridge;
 class WebCorePageState;
 
-class NSArray;
+class NSData;
 class NSDate;
-class NSURL;
-class NSURLConnection;
-class NSURLRequest;
-class NSURLResponse;
 class NSDictionary;
-class NSEvent;
 class NSError;
-class NSData;
+class NSEvent;
 class NSMutableURLRequest;
+class NSURL;
 class NSURLAuthenticationChallenge;
+class NSURLConnection;
+class NSURLRequest;
+class NSURLResponse;
 
 #endif // __OBJC__
 
@@ -86,11 +82,14 @@ namespace WebCore {
 
     class DocumentLoader;
     class Element;
+    class FormData;
     class FormState;
     class Frame;
     class FrameLoadRequest;
     class FrameLoaderClient;
+    class KURL;
     class MainResourceLoader;
+    class ResourceRequest;
     class String;
     class SubresourceLoader;
     class WebResourceLoader;
@@ -147,10 +146,11 @@ namespace WebCore {
         void safeLoad(NSURL *);
         void load(const FrameLoadRequest&, bool userGesture, NSEvent* triggeringEvent,
             Element* submitForm, const HashMap<String, String>& formValues);
-        void load(NSURL *, const String& referrer, FrameLoadType, const String& target, NSEvent *event,
-            Element* form, const HashMap<String, String>& formValues);
-        void post(NSURL *, const String& referrer, const String& target, NSArray *postData, const String& contentType, NSEvent *,
-            Element* form, const HashMap<String, String>&);
+        void load(NSURL *, const String& referrer, FrameLoadType, const String& target,
+            NSEvent *event, Element* form, const HashMap<String, String>& formValues);
+        void post(NSURL *, const String& referrer, const String& target,
+            const FormData&, const String& contentType,
+            NSEvent *, Element* form, const HashMap<String, String>&);
         void load(NSURLRequest *);
         void load(NSURLRequest *, const String& frameName);
         void load(NSURLRequest *, NSDictionary *triggeringAaction, FrameLoadType, PassRefPtr<FormState>);
@@ -159,6 +159,9 @@ namespace WebCore {
 
         bool canLoad(NSURL *, const String& referrer, bool& hideReferrer);
 
+        void loadResourceSynchronously(const ResourceRequest&,
+            KURL& finalURL, NSDictionary *& responseHeaders, int& statusCode, Vector<char>& data);
+
         // Also not cool.
         void stopLoadingPlugIns();
         void stopLoadingSubresources();
index b903fcdcdd0ae0ecc0c48942265b60167de080f7..7b57763c1584eb3e4c15ae9fa1cd3fe3c637c358 100644 (file)
@@ -33,7 +33,6 @@
 #import "Document.h"
 #import "DOMElementInternal.h"
 #import "Element.h"
-#import "FormDataMac.h"
 #import "FrameLoadRequest.h"
 #import "FrameMac.h"
 #import "FramePrivate.h"
@@ -197,7 +196,7 @@ void FrameLoader::load(const FrameLoadRequest& request, bool userGesture, NSEven
             (request.m_frameName.length() ? (NSString *)request.m_frameName : nil), triggeringEvent, submitForm, formValues);
     } else
         post(request.m_request.url().getNSURL(), referrer, (request.m_frameName.length() ? (NSString *)request.m_frameName : nil), 
-            arrayFromFormData(request.m_request.httpBody()), request.m_request.httpContentType(), triggeringEvent, submitForm, formValues);
+            request.m_request.httpBody(), request.m_request.httpContentType(), triggeringEvent, submitForm, formValues);
 
     if (targetFrame && targetFrame != m_frame)
         [Mac(targetFrame)->bridge() activateWindow];
@@ -1759,7 +1758,7 @@ void FrameLoader::loadedResourceFromMemoryCache(NSURLRequest *request, NSURLResp
     sendRemainingDelegateMessages(identifier, response, length, error);
 }
 
-void FrameLoader::post(NSURL *URL, const String& referrer, const String& frameName, NSArray *postData, 
+void FrameLoader::post(NSURL *URL, const String& referrer, const String& frameName, const FormData& formData, 
     const String& contentType, NSEvent *event, Element* form, const HashMap<String, String>& formValues)
 {
     // When posting, use the NSURLRequestReloadIgnoringCacheData load flag.
@@ -1773,7 +1772,7 @@ void FrameLoader::post(NSURL *URL, const String& referrer, const String& frameNa
 
     setHTTPReferrer(request, referrer);
     [request setHTTPMethod:@"POST"];
-    webSetHTTPBody(request, postData);
+    setHTTPBody(request, formData);
     [request setValue:contentType forHTTPHeaderField:@"Content-Type"];
 
     NSDictionary *action = actionInformation(FrameLoadTypeStandard, true, event, URL);
@@ -1914,11 +1913,100 @@ void FrameLoader::loadEmptyDocumentSynchronously()
 {
     NSURL *url = [[NSURL alloc] initWithString:@""];
     NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
-    m_frame->loader()->load(request);
+    load(request);
     [request release];
     [url release];
 }
 
+void FrameLoader::loadResourceSynchronously(const ResourceRequest& request,
+            KURL& finalURL, NSDictionary *& responseHeaders, int& statusCode, Vector<char>& data)
+{
+#if 0
+    NSDictionary *headerDict = nil;
+    const HTTPHeaderMap& requestHeaders = request.httpHeaderFields();
+
+    if (!requestHeaders.isEmpty())
+        headerDict = [NSDictionary _webcore_dictionaryWithHeaderMap:requestHeaders];
+    
+    FormData postData;
+    if (!request.httpBody().elements().isEmpty())
+        postData = request.httpBody();
+    Vector<char> results([resultData length]);
+
+    memcpy(results.data(), [resultData bytes], [resultData length]);
+#endif
+
+    NSURL *URL = request.url().getNSURL();
+
+    // Since this is a subresource, we can load any URL (we ignore the return value).
+    // But we still want to know whether we should hide the referrer or not, so we call the canLoadURL method.
+    String referrer = m_frame->referrer();
+    bool hideReferrer;
+    canLoad(URL, referrer, hideReferrer);
+    if (hideReferrer)
+        referrer = String();
+    
+    NSMutableURLRequest *initialRequest = [[NSMutableURLRequest alloc] initWithURL:URL];
+    [initialRequest setTimeoutInterval:10];
+    
+    [initialRequest setHTTPMethod:request.httpMethod()];
+    
+    if (!request.httpBody().isEmpty())        
+        setHTTPBody(initialRequest, request.httpBody());
+    
+    HTTPHeaderMap::const_iterator end = request.httpHeaderFields().end();
+    for (HTTPHeaderMap::const_iterator it = request.httpHeaderFields().begin(); it != end; ++it)
+        [initialRequest addValue:it->second forHTTPHeaderField:it->first];
+    
+    if (isConditionalRequest(initialRequest))
+        [initialRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
+    else
+        [initialRequest setCachePolicy:[documentLoader()->request() cachePolicy]];
+    
+    if (!referrer.isNull())
+        setHTTPReferrer(initialRequest, referrer);
+    
+    [initialRequest setMainDocumentURL:[m_frame->page()->mainFrame()->loader()->documentLoader()->request() URL]];
+    [initialRequest setValue:client()->userAgent(URL) forHTTPHeaderField:@"User-Agent"];
+    
+    NSError *error = nil;
+    id identifier = nil;    
+    NSURLRequest *newRequest = requestFromDelegate(initialRequest, identifier, error);
+    
+    NSURLResponse *response = nil;
+    NSData *result = nil;
+    if (error == nil) {
+        ASSERT(newRequest != nil);
+        result = [NSURLConnection sendSynchronousRequest:newRequest returningResponse:&response error:&error];
+    }
+    
+    [initialRequest release];
+
+    if (error == nil) {
+        finalURL = [response URL];
+        if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
+            NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; 
+            responseHeaders = [httpResponse allHeaderFields];
+            statusCode = [httpResponse statusCode];
+        } else {
+            responseHeaders = [NSDictionary dictionary];
+            statusCode = 200;
+        }
+    } else {
+        finalURL = URL;
+        responseHeaders = [NSDictionary dictionary];
+        if ([error domain] == NSURLErrorDomain)
+            statusCode = [error code];
+        else
+            statusCode = 404;
+    }
+    
+    sendRemainingDelegateMessages(identifier, response, [result length], error);
+    
+    data.resize([result length]);
+    memcpy(data.data(), [result bytes], [result length]);
+}
+
 void FrameLoader::setClient(FrameLoaderClient* client)
 {
     ASSERT(client);
index a8be01583efb5e7d202b87939d0a55605c2237c3..83b1d989c8f2fd96de3628a7d4a4008d92209756 100644 (file)
@@ -34,7 +34,6 @@
 #import "FrameLoader.h"
 #import "FrameMac.h"
 #import "FormData.h"
-#import "FormDataMac.h"
 #import "FrameLoader.h"
 #import "Logging.h"
 #import "Request.h"
@@ -95,35 +94,18 @@ Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, const
     if (!frame)
         return Vector<char>();
     
-    WebCoreFrameBridge *bridge = frame->bridge();
-
     frame->didTellBridgeAboutLoad(request.url().url());
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    NSDictionary *headerDict = nil;
-    const HTTPHeaderMap& requestHeaders = request.httpHeaderFields();
-
-    if (!requestHeaders.isEmpty())
-        headerDict = [NSDictionary _webcore_dictionaryWithHeaderMap:requestHeaders];
-    
-    NSArray *postData = nil;
-    if (!request.httpBody().elements().isEmpty())
-        postData = arrayFromFormData(request.httpBody());
-
-    NSURL *finalNSURL = nil;
     NSDictionary *responseHeaderDict = nil;
     int statusCode = 0;
-    NSData *resultData = [bridge syncLoadResourceWithMethod:request.httpMethod() URL:request.url().getNSURL() customHeaders:headerDict postData:postData finalURL:&finalNSURL responseHeaders:&responseHeaderDict statusCode:&statusCode];
+    Vector<char> result;
+    frame->loader()->loadResourceSynchronously(request, finalURL, responseHeaderDict, statusCode, result);
     
-    finalURL = finalNSURL;
     responseHeaders = DeprecatedString::fromNSString(HeaderStringFromDictionary(responseHeaderDict, statusCode));
 
-    Vector<char> results([resultData length]);
-
-    memcpy(results.data(), [resultData bytes], [resultData length]);
-
-    return results;
+    return result;
 
     END_BLOCK_OBJC_EXCEPTIONS;
 
index caa84850eaf36b63fe730701a530913e3a46920e..75f192d0a2e671b5486b9644fdb3155a1a8128a2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-@class NSArray;
 @class NSMutableURLRequest;
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void webSetHTTPBody(NSMutableURLRequest *request, NSArray *formData);
-
-#ifdef __cplusplus
+namespace WebCore {
+    class FormData;
+    void setHTTPBody(NSMutableURLRequest *, const FormData&);
 }
-#endif
index ed292656f8b8784c452920f027cd16353689e4ce..b97eea91ac10ff1285976e30877ebe444e7eb6c7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #import "config.h"
 #import "WebFormDataStream.h"
 
-#import <sys/types.h>
+#import "CString.h"
+#import "FormData.h"
+#import "WebCoreSystemInterface.h"
 #import <sys/stat.h>
-
+#import <sys/types.h>
 #import <wtf/Assertions.h>
-#import "WebCoreSystemInterface.h"
 
-static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, void *context);
+namespace WebCore {
 
-typedef struct {
+static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, void* context);
+
+struct FormStreamFields {
     CFMutableSetRef scheduledRunLoopPairs;
-    CFMutableArrayRef formDataArray;
+    Vector<FormDataElement> remainingElements; // in reverse order
     CFReadStreamRef currentStream;
-    CFDataRef currentData;
+    char* currentData;
     CFReadStreamRef formStream;
-} FormStreamFields;
+};
 
-typedef struct {
+struct SchedulePair {
     CFRunLoopRef runLoop;
     CFStringRef mode;
-} SchedulePair;
+};
 
-static const void *pairRetain(CFAllocatorRef alloc, const void *value)
+static const void* pairRetain(CFAllocatorRef alloc, const void* value)
 {
-    const SchedulePair *pair = (const SchedulePair *)value;
+    const SchedulePair* pair = static_cast<const SchedulePair*>(value);
 
-    SchedulePair *result = CFAllocatorAllocate(alloc, sizeof(SchedulePair), 0);
+    SchedulePair* result = new SchedulePair;
     CFRetain(pair->runLoop);
     result->runLoop = pair->runLoop;
     result->mode = CFStringCreateCopy(alloc, pair->mode);
     return result;
 }
 
-static void pairRelease(CFAllocatorRef alloc, const void *value)
+static void pairRelease(CFAllocatorRef alloc, const voidvalue)
 {
-    const SchedulePair *pair = (const SchedulePair *)value;
+    const SchedulePair* pair = static_cast<const SchedulePair*>(value);
 
     CFRelease(pair->runLoop);
     CFRelease(pair->mode);
-    CFAllocatorDeallocate(alloc, (void *)pair);
+    delete pair;
 }
 
-static Boolean pairEqual(const void *a, const void *b)
+static Boolean pairEqual(const void* a, const void* b)
 {
-    const SchedulePair *pairA = (const SchedulePair *)a;
-    const SchedulePair *pairB = (const SchedulePair *)b;
+    const SchedulePair* pairA = static_cast<const SchedulePair*>(a);
+    const SchedulePair* pairB = static_cast<const SchedulePair*>(b);
 
     return pairA->runLoop == pairB->runLoop && CFEqual(pairA->mode, pairB->mode);
 }
 
-static CFHashCode pairHash(const void *value)
+static CFHashCode pairHash(const voidvalue)
 {
-    const SchedulePair *pair = (const SchedulePair *)value;
+    const SchedulePair* pair = static_cast<const SchedulePair*>(value);
 
-    return ((CFHashCode)pair->runLoop) ^ CFHash(pair->mode);
+    return (CFHashCode)pair->runLoop ^ CFHash(pair->mode);
 }
 
 static void closeCurrentStream(FormStreamFields *form)
@@ -96,14 +99,14 @@ static void closeCurrentStream(FormStreamFields *form)
         form->currentStream = NULL;
     }
     if (form->currentData) {
-        CFRelease(form->currentData);
-        form->currentData = NULL;
+        fastFree(form->currentData);
+        form->currentData = 0;
     }
 }
 
-static void scheduleWithPair(const void *value, void *context)
+static void scheduleWithPair(const void* value, void* context)
 {
-    const SchedulePair *pair = (const SchedulePair *)value;
+    const SchedulePair* pair = static_cast<const SchedulePair*>(value);
     CFReadStreamRef stream = (CFReadStreamRef)context;
 
     CFReadStreamScheduleWithRunLoop(stream, pair->runLoop, pair->mode);
@@ -113,28 +116,24 @@ static void advanceCurrentStream(FormStreamFields *form)
 {
     closeCurrentStream(form);
 
-    // Handle the case where we're at the end of the array.
-    if (CFArrayGetCount(form->formDataArray) == 0) {
+    if (form->remainingElements.isEmpty())
         return;
-    }
 
     // Create the new stream.
-    CFAllocatorRef alloc = CFGetAllocator(form->formDataArray);
-    CFTypeRef nextInput = CFArrayGetValueAtIndex(form->formDataArray, 0);
-    if (CFGetTypeID(nextInput) == CFDataGetTypeID()) {
-        // nextInput is a CFData containing an absolute path
-        CFDataRef data = (CFDataRef)nextInput;
-        form->currentStream = CFReadStreamCreateWithBytesNoCopy(alloc, CFDataGetBytePtr(data), CFDataGetLength(data), kCFAllocatorNull);
+    FormDataElement& nextInput = form->remainingElements.last();
+    if (nextInput.m_type == FormDataElement::data) {
+        size_t size = nextInput.m_data.size();
+        char* data = nextInput.m_data.releaseBuffer();
+        form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data), size, kCFAllocatorNull);
         form->currentData = data;
-        CFRetain(data);
     } else {
-        // nextInput is a CFString containing an absolute path
-        CFStringRef path = (CFStringRef)nextInput;
-        CFURLRef fileURL = CFURLCreateWithFileSystemPath(alloc, path, kCFURLPOSIXPathStyle, FALSE);
-        form->currentStream = CFReadStreamCreateWithFile(alloc, fileURL);
+        CFStringRef filename = nextInput.m_filename.createCFString();
+        CFURLRef fileURL = CFURLCreateWithFileSystemPath(0, filename, kCFURLPOSIXPathStyle, FALSE);
+        CFRelease(filename);
+        form->currentStream = CFReadStreamCreateWithFile(0, fileURL);
         CFRelease(fileURL);
     }
-    CFArrayRemoveValueAtIndex(form->formDataArray, 0);
+    form->remainingElements.removeLast();
 
     // Set up the callback.
     CFStreamClientContext context = { 0, form, NULL, NULL, NULL };
@@ -145,46 +144,49 @@ static void advanceCurrentStream(FormStreamFields *form)
     CFSetApplyFunction(form->scheduledRunLoopPairs, scheduleWithPair, form->currentStream);
 }
 
-static void openNextStream(FormStreamFields *form)
+static void openNextStream(FormStreamFieldsform)
 {
     // Skip over any streams we can't open.
     // For some purposes we might want to return an error, but the current NSURLConnection
     // can't really do anything useful with an error at this point, so this is better.
     advanceCurrentStream(form);
-    while (form->currentStream && !CFReadStreamOpen(form->currentStream)) {
+    while (form->currentStream && !CFReadStreamOpen(form->currentStream))
         advanceCurrentStream(form);
-    }
 }
 
-static void *formCreate(CFReadStreamRef stream, void *context)
+static void* formCreate(CFReadStreamRef stream, void* context)
 {
-    CFArrayRef formDataArray = (CFArrayRef)context;
+    const FormData* formData = static_cast<const FormData*>(context);
 
     CFSetCallBacks runLoopAndModeCallBacks = { 0, pairRetain, pairRelease, NULL, pairEqual, pairHash };
 
-    CFAllocatorRef alloc = CFGetAllocator(stream);
-    FormStreamFields *newInfo = CFAllocatorAllocate(alloc, sizeof(FormStreamFields), 0);
-    newInfo->scheduledRunLoopPairs = CFSetCreateMutable(alloc, 0, &runLoopAndModeCallBacks);
-    newInfo->formDataArray = CFArrayCreateMutableCopy(alloc, CFArrayGetCount(formDataArray), formDataArray);
+    FormStreamFields* newInfo = new FormStreamFields;
+    newInfo->scheduledRunLoopPairs = CFSetCreateMutable(0, 0, &runLoopAndModeCallBacks);
     newInfo->currentStream = NULL;
-    newInfo->currentData = NULL;
+    newInfo->currentData = 0;
     newInfo->formStream = stream; // Don't retain. That would create a reference cycle.
+
+    // Append in reverse order since we remove elements from the end.
+    size_t size = formData->elements().size();
+    newInfo->remainingElements.reserveCapacity(size);
+    for (size_t i = 0; i < size; ++i)
+        newInfo->remainingElements.append(formData->elements()[size - i - 1]);
+
     return newInfo;
 }
 
-static void formFinalize(CFReadStreamRef stream, void *context)
+static void formFinalize(CFReadStreamRef stream, voidcontext)
 {
-    FormStreamFields *form = (FormStreamFields *)context;
+    FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
-    closeCurrentStream(context);
+    closeCurrentStream(form);
     CFRelease(form->scheduledRunLoopPairs);
-    CFRelease(form->formDataArray);
-    CFAllocatorDeallocate(CFGetAllocator(stream), context);
+    delete form;
 }
 
-static Boolean formOpen(CFReadStreamRef stream, CFStreamError *error, Boolean *openComplete, void *context)
+static Boolean formOpen(CFReadStreamRef stream, CFStreamError* error, Boolean* openComplete, void* context)
 {
-    FormStreamFields *form = (FormStreamFields *)context;
+    FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
     openNextStream(form);
 
@@ -193,9 +195,9 @@ static Boolean formOpen(CFReadStreamRef stream, CFStreamError *error, Boolean *o
     return TRUE;
 }
 
-static CFIndex formRead(CFReadStreamRef stream, UInt8 *buffer, CFIndex bufferLength, CFStreamError *error, Boolean *atEOF, void *context)
+static CFIndex formRead(CFReadStreamRef stream, UInt8* buffer, CFIndex bufferLength, CFStreamError* error, Boolean* atEOF, void* context)
 {
-    FormStreamFields *form = (FormStreamFields *)context;
+    FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
     while (form->currentStream) {
         CFIndex bytesRead = CFReadStreamRead(form->currentStream, buffer, bufferLength);
@@ -216,9 +218,9 @@ static CFIndex formRead(CFReadStreamRef stream, UInt8 *buffer, CFIndex bufferLen
     return 0;
 }
 
-static Boolean formCanRead(CFReadStreamRef stream, void *context)
+static Boolean formCanRead(CFReadStreamRef stream, voidcontext)
 {
-    FormStreamFields *form = (FormStreamFields *)context;
+    FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
     while (form->currentStream && CFReadStreamGetStatus(form->currentStream) == kCFStreamStatusAtEnd) {
         openNextStream(form);
@@ -230,38 +232,36 @@ static Boolean formCanRead(CFReadStreamRef stream, void *context)
     return CFReadStreamHasBytesAvailable(form->currentStream);
 }
 
-static void formClose(CFReadStreamRef stream, void *context)
+static void formClose(CFReadStreamRef stream, voidcontext)
 {
-    FormStreamFields *form = (FormStreamFields *)context;
+    FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
     closeCurrentStream(form);
 }
 
-static void formSchedule(CFReadStreamRef stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, void *context)
+static void formSchedule(CFReadStreamRef stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, voidcontext)
 {
-    FormStreamFields *form = (FormStreamFields *)context;
+    FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
-    if (form->currentStream) {
+    if (form->currentStream)
         CFReadStreamScheduleWithRunLoop(form->currentStream, runLoop, runLoopMode);
-    }
     SchedulePair pair = { runLoop, runLoopMode };
     CFSetAddValue(form->scheduledRunLoopPairs, &pair);
 }
 
-static void formUnschedule(CFReadStreamRef stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, void *context)
+static void formUnschedule(CFReadStreamRef stream, CFRunLoopRef runLoop, CFStringRef runLoopMode, voidcontext)
 {
-    FormStreamFields *form = (FormStreamFields *)context;
+    FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
-    if (form->currentStream) {
+    if (form->currentStream)
         CFReadStreamUnscheduleFromRunLoop(form->currentStream, runLoop, runLoopMode);
-    }
     SchedulePair pair = { runLoop, runLoopMode };
     CFSetRemoveValue(form->scheduledRunLoopPairs, &pair);
 }
 
-static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, void *context)
+static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, voidcontext)
 {
-    FormStreamFields *form = (FormStreamFields *)context;
+    FormStreamFields* form = static_cast<FormStreamFields*>(context);
 
     switch (type) {
     case kCFStreamEventHasBytesAvailable:
@@ -290,37 +290,32 @@ static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, vo
     }
 }
 
-void webSetHTTPBody(NSMutableURLRequest *request, NSArray *formData)
+void setHTTPBody(NSMutableURLRequest *request, const FormData& formData)
 {
-    size_t count = [formData count];
+    size_t count = formData.elements().size();
 
     // Handle the common special case of one piece of form data, with no files.
     if (count == 1) {
-        id d = [formData objectAtIndex:0];
-        if ([d isKindOfClass:[NSData class]]) {
-            [request setHTTPBody:(NSData *)d];
+        const FormDataElement& element = formData.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];
+            [data release];
             return;
         }
     }
 
     // Precompute the content length so NSURLConnection doesn't use chunked mode.
     long long length = 0;
-    unsigned i;
-    for (i = 0; i < count; ++i) {
-        id data = [formData objectAtIndex:i];
-        if ([data isKindOfClass:[NSData class]]) {
-            NSData *d = data;
-            length += [d length];
-        } else if ([data isKindOfClass:[NSString class]]) {
-            NSString *s = data;
+    for (size_t i = 0; i < count; ++i) {
+        const FormDataElement& element = formData.elements()[i];
+        if (element.m_type == FormDataElement::data)
+            length += element.m_data.size();
+        else {
             struct stat sb;
-            int statResult = stat([s fileSystemRepresentation], &sb);
-            if (statResult == 0 && (sb.st_mode & S_IFMT) == S_IFREG) {
+            int statResult = stat(element.m_filename.utf8(), &sb);
+            if (statResult == 0 && (sb.st_mode & S_IFMT) == S_IFREG)
                 length += sb.st_size;
-            }
-        } else {
-            LOG_ERROR("item in form data array is neither NSData nor NSString");
-            return;
         }
     }
 
@@ -328,7 +323,11 @@ void webSetHTTPBody(NSMutableURLRequest *request, NSArray *formData)
     [request setValue:[NSString stringWithFormat:@"%lld", length] forHTTPHeaderField:@"Content-Length"];
 
     // Create and set the stream.
-    CFReadStreamRef stream = wkCreateCustomCFReadStream(formCreate, formFinalize, formOpen, formRead, formCanRead, formClose, formSchedule, formUnschedule, formData);
+    CFReadStreamRef stream = wkCreateCustomCFReadStream(formCreate, formFinalize,
+        formOpen, formRead, formCanRead, formClose, formSchedule, formUnschedule,
+        const_cast<FormData*>(&formData));
     [request setHTTPBodyStream:(NSInputStream *)stream];
     CFRelease(stream);
 }
+
+}
index 290e5ea1d6dd1bdd78cec38516ca27671e81e75d..55b6b3d675a8df046ec5ee47e8e47f69a3c05271 100644 (file)
@@ -40,6 +40,7 @@ class NSMutableURLRequest;
  
 namespace WebCore {
 
+    class FormData;
     class String;
     class ResourceLoader;
     class ResourceRequest;
index 7477914a805154942e2e9e6bd0850611d10428bc..b350fdf98c4e9e64e948d60fbc2a67d867d2bfa7 100644 (file)
@@ -34,7 +34,6 @@
 #import "LoaderFunctions.h"
 #import "LoaderNSURLExtras.h"
 #import "LoaderNSURLRequestExtras.h"
-#import "FormDataMac.h"
 #import "ResourceLoader.h"
 #import "WebCoreFrameBridge.h"
 #import "WebCoreSystemInterface.h"
@@ -82,8 +81,8 @@ PassRefPtr<SubresourceLoader> SubresourceLoader::create(Frame* frame, ResourceLo
 
     // FIXME: Because of <rdar://problem/4803505>, the method has to be set before the body.
     [newRequest setHTTPMethod:request.httpMethod()];
-    if (!request.httpBody().elements().isEmpty())
-        webSetHTTPBody(newRequest, arrayFromFormData(request.httpBody()));
+    if (!request.httpBody().isEmpty())
+        setHTTPBody(newRequest, request.httpBody());
 
     wkSupportsMultipartXMixedReplace(newRequest);
 
index 26b50a4d4050aa16b8e799926755c40a23cde344..b5c1b999e8dbc5fc8a8d6f995b86b7e31081d36a 100644 (file)
@@ -33,7 +33,6 @@
 #import "FrameLoader.h"
 #import "FrameMac.h"
 #import "KURL.h"
-#import "FormDataMac.h"
 #import "LoaderFunctions.h"
 #import "Logging.h"
 #import "WebCoreFrameBridge.h"
index 446bdef4a44b3d8a3fe019683eec8a6006cd5d33..96c6265654da8424a6e5610360b4aa64bda2569c 100644 (file)
@@ -1,3 +1,20 @@
+2006-10-29  Darin Adler  <darin@apple.com>
+
+        Reviewed by Maciej.
+
+        - eliminate use of NSArray to carry form data around
+          (the code in this framework was actually using the NSArray to hold a single
+           NSData anyway, so I just went back to an NSData for now)
+
+        * History/WebHistoryItem.m:
+        (-[WebHistoryItem _setFormInfoFromRequest:]):
+        (-[WebHistoryItem formData]):
+        * History/WebHistoryItemPrivate.h:
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::dispatchWillSubmitForm):
+        * WebView/WebFrame.mm:
+        (-[WebFrame _loadItem:withLoadType:]):
+
 2006-10-28  Darin Adler  <darin@apple.com>
 
         Reviewed by Maciej.
index 89e32a7799a5b04162a8a3fd0eddd3bed414d757..4d63aed7309f28a618d0ccc3e290964b048560c2 100644 (file)
@@ -74,7 +74,7 @@ NSString *WebHistoryItemChangedNotification = @"WebHistoryItemChangedNotificatio
     BOOL alwaysAttemptToUsePageCache;
     int visitCount;
     // info used to repost form data
-    NSArray *formData;
+    NSData *formData;
     NSString *formContentType;
     NSString *formReferrer;
     // info used to support RSS feeds
@@ -484,7 +484,7 @@ NSString *WebHistoryItemChangedNotification = @"WebHistoryItemChangedNotificatio
 
 - (void)_setFormInfoFromRequest:(NSURLRequest *)request
 {
-    NSArray *newData = nil;
+    NSData *newData = nil;
     NSString *newContentType = nil;
     NSString *newReferrer = nil;
     if ([[request HTTPMethod] _webkit_isCaseInsensitiveEqualToString:@"POST"]) {
@@ -492,13 +492,7 @@ NSString *WebHistoryItemChangedNotification = @"WebHistoryItemChangedNotificatio
 
         // FIXME: Eventually we have to make this smart enough to handle the case where
         // we have a stream for the body to handle the "data interspersed with files" feature.
-        NSData *body = [request HTTPBody];
-        if (body) {
-            body = [body copy];
-            newData = [[NSArray alloc] initWithObjects:body, nil];
-            [body release];
-        }
-
+        newData = [[request HTTPBody] copy];
         newContentType = [[request _web_HTTPContentType] copy];
         newReferrer = [[request _web_HTTPReferrer] copy];
     }
@@ -513,7 +507,7 @@ NSString *WebHistoryItemChangedNotification = @"WebHistoryItemChangedNotificatio
     _private->formReferrer = newReferrer;
 }
 
-- (NSArray *)formData
+- (NSData *)formData
 {
     return _private->formData;
 }
index 73900c777d81f2c79a759bbcef6f805cd49f90d6..8d0d6f61bd23b703f4f3999e24a514a0d334fca9 100644 (file)
@@ -52,7 +52,7 @@
 - (NSPoint)scrollPoint;
 - (NSArray *)documentState;
 - (BOOL)isTargetItem;
-- (NSArray *)formData;
+- (NSData *)formData;
 - (NSString *)formContentType;
 - (NSString *)formReferrer;
 - (NSString *)RSSFeedReferrer;
index 4a725f1cc8e8bd19ef13250cfac202815e0317e2..ade0f64edd88cec4b1aff07ddfa5ca787436b1ff 100644 (file)
@@ -690,7 +690,8 @@ void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function,
     NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithCapacity:formState->values().size()];
     HashMap<String, String>::const_iterator end = formState->values().end();
     for (HashMap<String, String>::const_iterator it = formState->values().begin(); it != end; ++it)
-        [dictionary setObject:it->second forKey:it->first];
+        if (!it->first.isNull() && !it->second.isNull())
+            [dictionary setObject:it->second forKey:it->first];
 
     [formDelegate frame:m_webFrame.get()
             sourceFrame:kit(formState->sourceFrame())
index ee4175e69c7fd6a72debb5477716274d96438b97..5d9f64085e1dc60db454d874960455997242d864 100644 (file)
@@ -413,7 +413,7 @@ static inline WebView *getWebView(WebFrame *webFrame)
     NSURL *itemURL = [item URL];
     NSURL *itemOriginalURL = [NSURL _web_URLWithDataAsString:[item originalURLString]];
     NSURL *currentURL = [[[self dataSource] request] URL];
-    NSArray *formData = [item formData];
+    NSData *formData = [item formData];
 
     // Are we navigating to an anchor within the page?
     // Note if we have child frames we do a real reload, since the child frames might not
@@ -483,7 +483,7 @@ static inline WebView *getWebView(WebFrame *webFrame)
             if (formData) {
                 [request setHTTPMethod:@"POST"];
                 [request _web_setHTTPReferrer:[item formReferrer]];
-                webSetHTTPBody(request, formData);
+                [request setHTTPBody:formData];
                 [request _web_setHTTPContentType:[item formContentType]];
 
                 // Slight hack to test if the NSURL cache contains the page we're going to.  We want