Reviewed by Darin.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Oct 2006 21:53:08 +0000 (21:53 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Oct 2006 21:53:08 +0000 (21:53 +0000)
        - More movement towards the final network API.

        Changed ResourceLoader::create to take a ResurceRequest and start
        the load. Removed methods relating to setting request
        headers. Removed methods relating to metaData. Added some more
        convenience methods to ResourceRequest.

        * dom/XMLTokenizer.cpp:
        (WebCore::openFunc):
        * loader/LoaderFunctions.h:
        * loader/icon/IconLoader.cpp:
        (IconLoader::startLoading):
        (IconLoader::didFinishLoading):
        * loader/icon/IconLoader.h:
        * loader/loader.cpp:
        (WebCore::Loader::servePendingRequests):
        * loader/mac/LoaderFunctionsMac.mm:
        (WebCore::ServeSynchronousRequest):
        * platform/gdk/FrameGdk.cpp:
        (WebCore::FrameGdkClientDefault::openURL):
        (WebCore::FrameGdkClientDefault::submitForm):
        * platform/network/ResourceLoader.cpp:
        (WebCore::ResourceLoader::ResourceLoader):
        (WebCore::ResourceLoader::create):
        (WebCore::ResourceLoader::responseHTTPHeadersAsString):
        (WebCore::ResourceLoader::url):
        (WebCore::ResourceLoader::postData):
        (WebCore::ResourceLoader::method):
        (WebCore::ResourceLoader::client):
        * platform/network/ResourceLoader.h:
        * platform/network/ResourceLoaderInternal.h:
        (WebCore::ResourceLoaderInternal::ResourceLoaderInternal):
        * platform/network/ResourceRequest.h:
        (WebCore::ResourceRequest::ResourceRequest):
        (WebCore::ResourceRequest::httpAccept):
        (WebCore::ResourceRequest::setHTTPAccept):
        (WebCore::ResourceRequest::addHTTPHeaderFields):
        * platform/network/mac/ResourceLoaderMac.mm:
        (WebCore::ResourceLoader::start):
        (WebCore::ResourceLoader::receivedResponse):
        * platform/qt/FrameQtClient.cpp:
        (WebCore::FrameQtClientDefault::openURL):
        (WebCore::FrameQtClientDefault::submitForm):
        * platform/win/TemporaryLinkStubs.cpp:
        (WebCore::ResourceLoader::retrieveResponseEncoding):
        * xml/XSLTProcessor.cpp:
        (WebCore::docLoaderFunc):
        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::send):
        (WebCore::XMLHttpRequest::didFinishLoading):
        (WebCore::XMLHttpRequest::didReceiveData):
        * xml/xmlhttprequest.h:

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

18 files changed:
WebCore/ChangeLog
WebCore/dom/XMLTokenizer.cpp
WebCore/loader/LoaderFunctions.h
WebCore/loader/icon/IconLoader.cpp
WebCore/loader/icon/IconLoader.h
WebCore/loader/loader.cpp
WebCore/loader/mac/LoaderFunctionsMac.mm
WebCore/platform/gdk/FrameGdk.cpp
WebCore/platform/network/ResourceLoader.cpp
WebCore/platform/network/ResourceLoader.h
WebCore/platform/network/ResourceLoaderInternal.h
WebCore/platform/network/ResourceRequest.h
WebCore/platform/network/mac/ResourceLoaderMac.mm
WebCore/platform/qt/FrameQtClient.cpp
WebCore/platform/win/TemporaryLinkStubs.cpp
WebCore/xml/XSLTProcessor.cpp
WebCore/xml/xmlhttprequest.cpp
WebCore/xml/xmlhttprequest.h

index b5ba7bd4da583a156f8185d1c43b5f3b186c46cb..56602a7deeeae2d9036fd47acc2ce773c66e9a06 100644 (file)
@@ -1,3 +1,60 @@
+2006-10-24  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Darin.
+
+        - More movement towards the final network API.
+        
+        Changed ResourceLoader::create to take a ResurceRequest and start
+        the load. Removed methods relating to setting request
+        headers. Removed methods relating to metaData. Added some more
+        convenience methods to ResourceRequest.
+
+        * dom/XMLTokenizer.cpp:
+        (WebCore::openFunc):
+        * loader/LoaderFunctions.h:
+        * loader/icon/IconLoader.cpp:
+        (IconLoader::startLoading):
+        (IconLoader::didFinishLoading):
+        * loader/icon/IconLoader.h:
+        * loader/loader.cpp:
+        (WebCore::Loader::servePendingRequests):
+        * loader/mac/LoaderFunctionsMac.mm:
+        (WebCore::ServeSynchronousRequest):
+        * platform/gdk/FrameGdk.cpp:
+        (WebCore::FrameGdkClientDefault::openURL):
+        (WebCore::FrameGdkClientDefault::submitForm):
+        * platform/network/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::ResourceLoader):
+        (WebCore::ResourceLoader::create):
+        (WebCore::ResourceLoader::responseHTTPHeadersAsString):
+        (WebCore::ResourceLoader::url):
+        (WebCore::ResourceLoader::postData):
+        (WebCore::ResourceLoader::method):
+        (WebCore::ResourceLoader::client):
+        * platform/network/ResourceLoader.h:
+        * platform/network/ResourceLoaderInternal.h:
+        (WebCore::ResourceLoaderInternal::ResourceLoaderInternal):
+        * platform/network/ResourceRequest.h:
+        (WebCore::ResourceRequest::ResourceRequest):
+        (WebCore::ResourceRequest::httpAccept):
+        (WebCore::ResourceRequest::setHTTPAccept):
+        (WebCore::ResourceRequest::addHTTPHeaderFields):
+        * platform/network/mac/ResourceLoaderMac.mm:
+        (WebCore::ResourceLoader::start):
+        (WebCore::ResourceLoader::receivedResponse):
+        * platform/qt/FrameQtClient.cpp:
+        (WebCore::FrameQtClientDefault::openURL):
+        (WebCore::FrameQtClientDefault::submitForm):
+        * platform/win/TemporaryLinkStubs.cpp:
+        (WebCore::ResourceLoader::retrieveResponseEncoding):
+        * xml/XSLTProcessor.cpp:
+        (WebCore::docLoaderFunc):
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::send):
+        (WebCore::XMLHttpRequest::didFinishLoading):
+        (WebCore::XMLHttpRequest::didReceiveData):
+        * xml/xmlhttprequest.h:
+
 2006-10-24  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Geoff.
index 89ec9775fadbc476d06637e436a3c265296d7129..445aafceb045f15a2576a16617606a6ff3ce647b 100644 (file)
@@ -457,10 +457,11 @@ static void* openFunc(const char* uri)
     if (!globalDocLoader || !shouldAllowExternalLoad(uri))
         return &globalDescriptor;
 
+    KURL kurl(uri);
+    ResourceRequest request(kurl);
     KURL finalURL;
-    RefPtr<ResourceLoader> loader = ResourceLoader::create(0, "GET", uri);
     DeprecatedString headers;
-    Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, loader.get(), finalURL, headers);
+    Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, request, finalURL, headers);
     
     return new OffsetBuffer(data);
 }
index b411c4c967400cb079833ec7dd134524668d7f1b..8ff919a0ecc677a990d4a8f9b167f55f5a3a0142 100644 (file)
 #include <wtf/HashMap.h>
 #include "PlatformString.h"
 #include "ResourceLoaderClient.h"  // Defines PlatformResponse
+#include "ResourceRequest.h"
 
 #ifdef __OBJC__
 @class NSDictionary;
 @class NSString;
 
 @interface NSDictionary (WebCore_Extras)
-+ (id)_webcore_dictionaryWithHeaderMap:(const HashMap<WebCore::String, WebCore::String>&)headerMap;
++ (id)_webcore_dictionaryWithHeaderMap:(const WebCore::ResourceRequest::HTTPHeaderMap&)headerMap;
 @end
 
 #else
@@ -48,9 +49,9 @@ class DeprecatedString;
 class DocLoader;
 class Loader;
 class Request;
+class ResourceRequest;
 
-
-Vector<char> ServeSynchronousRequest(Loader*, DocLoader*, ResourceLoader*, KURL& finalURL, DeprecatedString& headers);
+Vector<char> ServeSynchronousRequest(Loader*, DocLoader*, const ResourceRequest&, KURL& finalURL, DeprecatedString& headers);
 
 void CheckCacheObjectStatus(DocLoader*, CachedResource*);
 bool CheckIfReloading(DocLoader*);
index 90c179c3625ff691bfb424b09dd7e99aed8032c0..f3d7b10ea572420a80414ddcd5c5592085282667 100644 (file)
@@ -62,19 +62,20 @@ void IconLoader::startLoading()
         return;
     
     m_httpStatusCode = 0;
-    m_resourceLoader = ResourceLoader::create(this, "GET", m_frame->iconURL());
     
     // A frame may be documentless - one example is viewing a PDF directly
     if (!m_frame->document()) {
         // FIXME - http://bugzilla.opendarwin.org/show_bug.cgi?id=10902
         // Once the loader infrastructure will cleanly let us load an icon without a DocLoader, we can implement this
         LOG(IconDatabase, "Documentless-frame - icon won't be loaded");
-    } else if (!m_resourceLoader->start(m_frame->document()->docLoader())) {
+    } 
+    
+    m_url = m_frame->iconURL();
+    ResourceRequest request(m_url);
+    m_resourceLoader = ResourceLoader::create(request, this, m_frame->document()->docLoader());
+
+    if (!m_resourceLoader)
         LOG_ERROR("Failed to start load for icon at url %s", m_frame->iconURL().url().ascii());
-        if (m_resourceLoader)
-            m_resourceLoader->kill();
-        m_resourceLoader = 0;
-    }
 }
 
 void IconLoader::stopLoading()
@@ -114,7 +115,7 @@ void IconLoader::didFinishLoading(ResourceLoader* resourceLoader)
     IconDatabase* iconDatabase = IconDatabase::sharedIconDatabase();
     ASSERT(iconDatabase);
     
-    KURL iconURL(resourceLoader->url());
+    KURL iconURL(m_url);
     
     if (data)
         iconDatabase->setIconDataForIconURL(data, size, iconURL.url());
index af11f2514028640807eed0742a029efc2a0bd0c2..fb7505d69083436887f9cef294a36914d81f2249 100644 (file)
@@ -48,7 +48,8 @@ private:
     IconLoader(Frame* frame);
     
     void notifyIconChanged(const KURL& iconURL);
-    
+
+    KURL m_url;
     RefPtr<ResourceLoader> m_resourceLoader;
     Frame* m_frame;
     
index 1b6fdb66b1d5c1be605fe6b00b67d79897f990ce..0958ae8de61f1491f71b4f36b7d32e9979e9c8d6 100644 (file)
@@ -68,22 +68,23 @@ void Loader::servePendingRequests()
     // get the first pending request
     Request* req = m_requestsPending.take(0);
 
-    KURL u(req->cachedObject()->url().deprecatedString());
-    RefPtr<ResourceLoader> loader = ResourceLoader::create(this, "GET", u);
+    ResourceRequest request(req->cachedObject()->url());
 
     if (!req->cachedObject()->accept().isEmpty())
-        loader->addMetaData("accept", req->cachedObject()->accept());
+        request.setHTTPAccept(req->cachedObject()->accept());
     if (req->docLoader())  {
         KURL r = req->docLoader()->doc()->URL();
         if (r.protocol().startsWith("http") && r.path().isEmpty())
             r.setPath("/");
-        loader->addMetaData("referrer", r.url());
+        request.setHTTPReferrer(r.url());
         DeprecatedString domain = r.host();
         if (req->docLoader()->doc()->isHTMLDocument())
             domain = static_cast<HTMLDocument*>(req->docLoader()->doc())->domain().deprecatedString();
     }
+    
+    RefPtr<ResourceLoader> loader = ResourceLoader::create(request, this, req->docLoader());
 
-    if (loader->start(req->docLoader()))
+    if (loader)
         m_requestsLoading.add(loader.get(), req);
 }
 
index 95968b56bfbee854c4f3dc4604164e6ebfd98041..6979f5eb12482923f5db9cfb95112282663aea2f 100644 (file)
@@ -38,6 +38,7 @@
 #import "Logging.h"
 #import "Request.h"
 #import "ResourceLoader.h"
+#import "ResourceRequest.h"
 #import "WebCoreFrameBridge.h"
 #import "loader.h"
 #import <wtf/Vector.h>
@@ -47,12 +48,12 @@ using namespace WebCore;
 
 @implementation NSDictionary (WebCore_Extras)
 
-+ (id)_webcore_dictionaryWithHeaderMap:(const HashMap<String, String>&)headerMap
++ (id)_webcore_dictionaryWithHeaderMap:(const ResourceRequest::HTTPHeaderMap&)headerMap
 {
     NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
     
-    HashMap<String, String>::const_iterator end = headerMap.end();
-    for (HashMap<String, String>::const_iterator it = headerMap.begin(); it != end; ++it)
+    ResourceRequest::HTTPHeaderMap::const_iterator end = headerMap.end();
+    for (ResourceRequest::HTTPHeaderMap::const_iterator it = headerMap.begin(); it != end; ++it)
         [headers setValue:it->second forKey:it->first];
     
     return [headers autorelease];
@@ -86,7 +87,7 @@ NSString *HeaderStringFromDictionary(NSDictionary *headers, int statusCode)
     return headerString;
 }
 
-Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, ResourceLoader *job, KURL &finalURL, DeprecatedString &responseHeaders)
+Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, const ResourceRequest& request, KURL &finalURL, DeprecatedString &responseHeaders)
 {
     FrameMac *frame = static_cast<FrameMac *>(docLoader->frame());
     
@@ -95,27 +96,25 @@ Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, Resou
     
     WebCoreFrameBridge *bridge = frame->bridge();
 
-    frame->didTellBridgeAboutLoad(job->url().url());
+    frame->didTellBridgeAboutLoad(request.url().url());
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSDictionary *headerDict = nil;
-    const HashMap<String, String>& requestHeaders = job->requestHeaders();
+    const ResourceRequest::HTTPHeaderMap& requestHeaders = request.httpHeaderFields();
 
     if (!requestHeaders.isEmpty())
         headerDict = [NSDictionary _webcore_dictionaryWithHeaderMap:requestHeaders];
     
     NSArray *postData = nil;
-    if (!job->postData().elements().isEmpty())
-        postData = arrayFromFormData(job->postData());
+    if (!request.httpBody().elements().isEmpty())
+        postData = arrayFromFormData(request.httpBody());
 
     NSURL *finalNSURL = nil;
     NSDictionary *responseHeaderDict = nil;
     int statusCode = 0;
-    NSData *resultData = [bridge syncLoadResourceWithMethod:job->method() URL:job->url().getNSURL() customHeaders:headerDict postData:postData finalURL:&finalNSURL responseHeaders:&responseHeaderDict statusCode:&statusCode];
+    NSData *resultData = [bridge syncLoadResourceWithMethod:request.httpMethod() URL:request.url().getNSURL() customHeaders:headerDict postData:postData finalURL:&finalNSURL responseHeaders:&responseHeaderDict statusCode:&statusCode];
     
-    job->kill();
-
     finalURL = finalNSURL;
     responseHeaders = DeprecatedString::fromNSString(HeaderStringFromDictionary(responseHeaderDict, statusCode));
 
index 64f9a35c2a5859ae6fad758a5bd300bcbfa7e76a..a327cc0c3bea8025cfa1622fbbb82b142fe288f4 100644 (file)
@@ -92,16 +92,19 @@ void FrameGdkClientDefault::openURL(const KURL& url)
     m_frame->didOpenURL(url);
     m_beginCalled = false;
 
-    RefPtr<ResourceLoader> loader = ResourceLoader::create(this, "GET", url);
-    loader->start(0);
+    ResourceRequest request(url);
+    RefPtr<ResourceLoader> loader = ResourceLoader::create(request, this, 0);
 }
 
 void FrameGdkClientDefault::submitForm(const String& method, const KURL& url, const FormData* postData)
 {
     m_beginCalled = false;
 
-    RefPtr<ResourceLoader> loader = ResourceLoader::create(this, method, url, *postData);
-    loader->start(0);
+    ResourceRequest request(url);
+    request.setHTTPMethod(method);
+    request.setHTTPBody(*postData);
+
+    RefPtr<ResourceLoader> loader = ResourceLoader::create(request, this, 0);
 }
 
 void FrameGdkClientDefault::receivedResponse(ResourceLoader*, PlatformResponse)
index ae8620439f508ab143c5814dae28739084fc46f3..6f7fd791c488774785238868e80c2d28fd2b9062 100644 (file)
 
 namespace WebCore {
 
-ResourceLoader::ResourceLoader(ResourceLoaderClient* client, const String& method, const KURL& url)
-    : d(new ResourceLoaderInternal(this, client, method, url))
+ResourceLoader::ResourceLoader(const ResourceRequest& request, ResourceLoaderClient* client)
+    : d(new ResourceLoaderInternal(this, request, client))
 {
 }
 
-ResourceLoader::ResourceLoader(ResourceLoaderClient* client, const String& method, const KURL& url, const FormData& postData)
-    : d(new ResourceLoaderInternal(this, client, method, url, postData))
+PassRefPtr<ResourceLoader> ResourceLoader::create(const ResourceRequest& request, ResourceLoaderClient* client, DocLoader* dl)
 {
-}
-
-PassRefPtr<ResourceLoader> ResourceLoader::create(ResourceLoaderClient* client, const String& method, const KURL& url)
-{
-    return new ResourceLoader(client, method, url);
-}
+    RefPtr<ResourceLoader> newLoader(new ResourceLoader(request, client));
+    
+    if (newLoader->start(dl))
+        return newLoader.release();
 
-PassRefPtr<ResourceLoader> ResourceLoader::create(ResourceLoaderClient* client, const String& method, const KURL& url, const FormData& postData)
-{
-    return new ResourceLoader(client, method, url, postData);
+    return 0;
 }
 
 bool ResourceLoader::isErrorPage() const
@@ -74,36 +69,10 @@ String ResourceLoader::responseEncoding() const
     return d->m_responseEncoding;
 }
 
-void ResourceLoader::setRequestHeaders(const HashMap<String, String>& requestHeaders)
-{
-    d->m_requestHeaders = requestHeaders;
-}
-
-const HashMap<String, String>& ResourceLoader::requestHeaders() const
-{
-    return d->m_requestHeaders;
-}
-
-String ResourceLoader::queryMetaData(const String& key) const
-{
-    if (key == "HTTP-Headers") {
-        assembleResponseHeaders();
-        return d->responseHeaders;
-    } 
-
-    return d->metaData.get(key); 
-}
-
-void ResourceLoader::addMetaData(const String& key, const String& value)
+String ResourceLoader::responseHTTPHeadersAsString() const
 {
-    d->metaData.set(key, value);
-}
-
-void ResourceLoader::addMetaData(const HashMap<String, String>& keysAndValues)
-{
-    HashMap<String, String>::const_iterator end = keysAndValues.end();
-    for (HashMap<String, String>::const_iterator it = keysAndValues.begin(); it != end; ++it)
-        d->metaData.set(it->first, it->second);
+    assembleResponseHeaders();
+    return d->responseHeaders;
 }
 
 void ResourceLoader::kill()
@@ -116,24 +85,29 @@ void ResourceLoader::kill()
     }
 }
 
-KURL ResourceLoader::url() const
+const ResourceRequest::HTTPHeaderMap& ResourceLoader::requestHeaders() const
+{
+    return d->m_request.httpHeaderFields();
+}
+
+const KURL& ResourceLoader::url() const
 {
-    return d->URL;
+    return d->m_request.url();
 }
 
-FormData ResourceLoader::postData() const
+const FormData& ResourceLoader::postData() const
 {
-    return d->postData;
+    return d->m_request.httpBody();
 }
 
-String ResourceLoader::method() const
+const String& ResourceLoader::method() const
 {
-    return d->method;
+    return d->m_request.httpMethod();
 }
 
 ResourceLoaderClient* ResourceLoader::client() const
 {
-    return d->client;
+    return d->m_client;
 }
 
 } // namespace WebCore
index c226f9f03233d8269675db5e1fae06f2466d86e2..70929ce90c8910a2145dd623c17d4505a45b63d2 100644 (file)
@@ -27,6 +27,7 @@
 #define ResourceLoader_h
 
 #include "ResourceLoaderClient.h" // for PlatformResponse
+#include "ResourceRequest.h"
 #include "StringHash.h"
 #include "Timer.h"
 #include <wtf/HashMap.h>
@@ -61,35 +62,23 @@ class ResourceLoaderInternal;
 
 class ResourceLoader : public Shared<ResourceLoader> {
 private:
-    ResourceLoader(ResourceLoaderClient*, const String& method, const KURL&);
-    ResourceLoader(ResourceLoaderClient*, const String& method, const KURL&, const FormData& postData);
+    ResourceLoader(const ResourceRequest&, ResourceLoaderClient*);
 
 public:
-    static PassRefPtr<ResourceLoader> create(ResourceLoaderClient*, const String& method, const KURL&);
-    static PassRefPtr<ResourceLoader> create(ResourceLoaderClient*, const String& method, const KURL&, const FormData& postData);    
+    // FIXME: should not need the DocLoader
+    static PassRefPtr<ResourceLoader> create(const ResourceRequest&, ResourceLoaderClient*, DocLoader*);
 
     ~ResourceLoader();
 
-    bool start(DocLoader*);
-    bool startHTTPRequest(const String& referrer);
-
     int error() const;
     void setError(int);
     String errorText() const;
     bool isErrorPage() const;
     
-    void setRequestHeaders(const HashMap<String, String>& requestHeaders);
-    const HashMap<String, String>& requestHeaders() const;
-    
     String responseEncoding() const;
-    String queryMetaData(const String&) const;
-    void addMetaData(const String& key, const String& value);
-    void addMetaData(const HashMap<String, String>&);
-    void kill();
 
-    KURL url() const;
-    String method() const;
-    FormData postData() const;
+    String responseHTTPHeadersAsString() const;
+    void kill();
 
 #if PLATFORM(MAC)
     void setLoader(WebCoreResourceLoaderImp*);
@@ -121,7 +110,14 @@ public:
 
     void receivedResponse(PlatformResponse);
 
+    const ResourceRequest::HTTPHeaderMap& requestHeaders() const;
+    const KURL& url() const;
+    const String& method() const;
+    const FormData& postData() const;
+
 private:
+    bool start(DocLoader*);
+
     void assembleResponseHeaders() const;
     void retrieveResponseEncoding() const;
 
index c965c0f87133874aa14253524d6b84763b4438ce..b95d4c3367d25b96357fe327e082cea520b349f6 100644 (file)
@@ -58,11 +58,10 @@ namespace WebCore {
     class ResourceLoaderInternal
     {
     public:
-        ResourceLoaderInternal(ResourceLoader* job, ResourceLoaderClient* c, const String& method, const KURL& u)
-            : client(c)
+        ResourceLoaderInternal(ResourceLoader* loader, const ResourceRequest& request, ResourceLoaderClient* c)
+            : m_client(c)
+            , m_request(request)
             , status(0)
-            , URL(u)
-            , method(method)
             , assembledResponseHeaders(true)
             , m_retrievedResponseEncoding(true)
             , m_loading(false)
@@ -75,7 +74,7 @@ namespace WebCore {
 #endif
 #if USE(WININET)
             , m_fileHandle(INVALID_HANDLE_VALUE)
-            , m_fileLoadTimer(job, &ResourceLoader::fileLoadTimer)
+            , m_fileLoadTimer(loader, &ResourceLoader::fileLoadTimer)
             , m_resourceHandle(0)
             , m_secondaryHandle(0)
             , m_jobId(0)
@@ -93,54 +92,13 @@ namespace WebCore {
         {
         }
         
-        ResourceLoaderInternal(ResourceLoader* job, ResourceLoaderClient* c, const String& method, const KURL& u, const FormData& p)
-            : client(c)
-            , status(0)
-            , URL(u)
-            , method(method)
-            , postData(p)
-            , assembledResponseHeaders(true)
-            , m_retrievedResponseEncoding(true)
-            , m_loading(false)
-            , m_cancelled(false)
-#if USE(CFNETWORK)
-            , m_connection(0)
-#elif PLATFORM(MAC)
-            , loader(nil)
-            , response(nil)
-#endif
-#if USE(WININET)
-            , m_fileHandle(INVALID_HANDLE_VALUE)
-            , m_fileLoadTimer(job, &ResourceLoader::fileLoadTimer)
-            , m_resourceHandle(0)
-            , m_secondaryHandle(0)
-            , m_jobId(0)
-            , m_threadId(0)
-            , m_writing(false)
-            , m_formDataString(0)
-            , m_formDataLength(0)
-            , m_bytesRemainingToWrite(0)
-            , m_hasReceivedResponse(false)
-            , m_resend(false)
-#endif
-#if USE(CURL)
-            , m_handle(0)
-#endif
-        {
-        }
-
         ~ResourceLoaderInternal();
         
-        ResourceLoaderClient* client;
-        
-        int status;
-        HashMap<String, String> metaData;
-        KURL URL;
-        String method;
-        FormData postData;
+        ResourceLoaderClient* m_client;
         
-        HashMap<String, String> m_requestHeaders;
+        ResourceRequest m_request;
         
+        int status;
         String m_responseEncoding;
         DeprecatedString responseHeaders;
 
index 8d31c612469526fb2bf0808ff18021aa0b785fb0..9aa74c57bb3784e757b479910e3dd218d5b86677 100644 (file)
@@ -57,6 +57,7 @@ namespace WebCore {
             : m_url(url)
             , m_cachePolicy(UseProtocolCachePolicy)
             , m_timeoutInterval(defaultTimeoutInterval)
+            , m_httpMethod("GET")
             , m_allowHTTPCookies(true)
         {
         }
@@ -65,6 +66,7 @@ namespace WebCore {
             : m_url(url)
             , m_cachePolicy(policy)
             , m_timeoutInterval(defaultTimeoutInterval)
+            , m_httpMethod("GET")
             , m_allowHTTPCookies(true)
         {
             setHTTPReferrer(referrer);
@@ -98,6 +100,7 @@ namespace WebCore {
         String httpHeaderField(const String& name) const { return m_httpHeaderFields.get(name); }
         void setHTTPHeaderField(const String& name, const String& value) { m_httpHeaderFields.set(name, value); }
         void addHTTPHeaderField(const String& name, const String& value);
+        void addHTTPHeaderFields(const HTTPHeaderMap& headerFields);
         
         String httpContentType() const { return httpHeaderField("Content-Type");  }
         void setHTTPContentType(const String& httpContentType) { setHTTPHeaderField("Content-Type", httpContentType); }
@@ -107,7 +110,10 @@ namespace WebCore {
         
         String httpUserAgent() const { return httpHeaderField("User-Agent"); }
         void setHTTPUserAgent(const String& httpUserAgent) { setHTTPHeaderField("User-Agent", httpUserAgent); }
-        
+
+        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; } 
@@ -136,6 +142,14 @@ namespace WebCore {
             result.first->second += "," + value;
     }
 
+    // FIXME: probably shouldn't inline this
+    inline void ResourceRequest::addHTTPHeaderFields(const HTTPHeaderMap& headerFields)
+    {
+        HTTPHeaderMap::const_iterator end = headerFields.end();
+        for (HTTPHeaderMap::const_iterator it = headerFields.begin(); it != end; ++it)
+            addHTTPHeaderField(it->first, it->second);
+    }
+
 } // namespace WebCore
 
 #endif // ResourceRequest_H_
index 6388bf123345773b217dfc35e4c777bf99374ef1..bb0f476046ce1418d3ecda559c150ad9189299d4 100644 (file)
@@ -80,8 +80,8 @@ bool ResourceLoader::start(DocLoader* docLoader)
 
     NSDictionary* headerDict = nil;
     
-    if (!d->m_requestHeaders.isEmpty())
-        headerDict = [[NSDictionary _webcore_dictionaryWithHeaderMap:d->m_requestHeaders] retain];
+    if (!d->m_request.httpHeaderFields().isEmpty())
+        headerDict = [[NSDictionary _webcore_dictionaryWithHeaderMap:d->m_request.httpHeaderFields()] retain];
 
     if (!postData().elements().isEmpty())
         handle = [bridge startLoadingResource:resourceLoader withMethod:method() URL:url().getNSURL() customHeaders:headerDict postData:arrayFromFormData(postData())];
@@ -134,8 +134,8 @@ void ResourceLoader::receivedResponse(NSURLResponse* response)
     d->m_retrievedResponseEncoding = false;
     d->response = response;
     HardRetain(d->response);
-    if (d->client)
-        d->client->receivedResponse(this, response);
+    if (client())
+        client()->receivedResponse(this, response);
 }
 
 void ResourceLoader::cancel()
index db0c75ba7a754dc20be2f831e3a943a9f0290759..eb4fa5515d5864cd311aecb3ddae12aa959c8f89 100644 (file)
@@ -66,8 +66,8 @@ void FrameQtClientDefault::openURL(const KURL& url)
     m_frame->didOpenURL(url);
     m_assignedMimetype = false;
 
-    RefPtr<ResourceLoader> loader = ResourceLoader::create(this, "GET", url);
-    loader->start(m_frame->document() ? m_frame->document()->docLoader() : 0);
+    RequestRequest request(url);
+    RefPtr<ResourceLoader> loader = ResourceLoader::create(request, this, m_frame->document() ? m_frame->document()->docLoader() : 0);
 }
 
 void FrameQtClientDefault::submitForm(const String& method, const KURL& url, const FormData* postData)
@@ -76,8 +76,11 @@ void FrameQtClientDefault::submitForm(const String& method, const KURL& url, con
 
     m_assignedMimetype = false;
 
-    RefPtr<ResourceLoader> loader = ResourceLoader::create(this, method, url, *postData);
-    loader->start(m_frame->document() ? m_frame->document()->docLoader() : 0);
+    ResourceRequest request(url);
+    request.setHTTPMethod(method);
+    request.setHTTPBody(*postData);
+
+    RefPtr<ResourceLoader> loader = ResourceLoader::create(request, this, m_frame->document() ? m_frame->document()->docLoader() : 0);
 }
 
 void FrameQtClientDefault::checkLoaded()
index 46b151a9c7949777f165d2f13caa82d13a307daf..be98f3c4f560f8c4980b770c3b47a9abdceed064 100644 (file)
@@ -244,7 +244,6 @@ void refreshPlugins(bool) { }
 
 void ResourceLoader::assembleResponseHeaders() const { }
 void ResourceLoader::retrieveResponseEncoding() const {}
-bool ResourceLoader::startHTTPRequest(const String& referrer) { return false; }
 
 
 Vector<char> ServeSynchronousRequest(Loader*, DocLoader*, ResourceLoader*, KURL&, DeprecatedString&) { notImplemented(); return Vector<char>(); }
index 0b85756aad26b97b3b62641c88956f6644d4b90b..68577eba9a6c1da979d2cb15ad7256a5314812ae 100644 (file)
@@ -84,13 +84,13 @@ static xmlDocPtr docLoaderFunc(const xmlChar *uri,
             xmlChar *base = xmlNodeGetBase(context->document->doc, context->node);
             KURL url((const char*)base, (const char*)uri);
             xmlFree(base);
+            ResourceRequest request(url);
             KURL finalURL;
-            RefPtr<ResourceLoader> loader = ResourceLoader::create(0, "GET", url);
             DeprecatedString headers;
             xmlGenericErrorFunc oldErrorFunc = xmlGenericError;
             void *oldErrorContext = xmlGenericErrorContext;
             
-            Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, loader.get(), finalURL, headers);
+            Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, request, finalURL, headers);
         
             xmlSetGenericErrorFunc(0, parseErrorFunc);
             // We don't specify an encoding here. Neither Gecko nor WinIE respects
index d7eb0b7148a1eb2ec099580f7eb83ad0ba06c0dd..d84785f86af4ea8469176233b80bc3456fa38cc4 100644 (file)
@@ -297,6 +297,8 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
 
     m_aborted = false;
 
+    ResourceRequest request(m_url);
+    
     if (!body.isNull() && m_method != "GET" && m_method != "HEAD" && (m_url.protocol().lower() == "http" || m_url.protocol().lower() == "https")) {
         String contentType = getRequestHeader("Content-Type");
         String charset;
@@ -314,16 +316,17 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
         if (!m_encoding.isValid()) // FIXME: report an error?
             m_encoding = UTF8Encoding();
 
-        m_loader = ResourceLoader::create(m_async ? this : 0, m_method, m_url, m_encoding.encode(body.characters(), body.length()));
+        request.setHTTPBody(m_encoding.encode(body.characters(), body.length()));
     } else {
         // FIXME: HEAD requests just crash; see <rdar://4460899> and the commented out tests in http/tests/xmlhttprequest/methods.html.
+        // FIXME: the radar is fixed, should conditionalize this
         if (m_method == "HEAD")
             m_method = "GET";
-        m_loader = ResourceLoader::create(m_async ? this : 0, m_method, m_url);
     }
+    request.setHTTPMethod(m_method);
 
     if (m_requestHeaders.size() > 0)
-        m_loader->setRequestHeaders(m_requestHeaders);
+        request.addHTTPHeaderFields(m_requestHeaders);
 
     if (!m_async) {
         Vector<char> data;
@@ -333,7 +336,7 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
         {
             // avoid deadlock in case the loader wants to use JS on a background thread
             KJS::JSLock::DropAllLocks dropLocks;
-            data = ServeSynchronousRequest(cache()->loader(), m_doc->docLoader(), m_loader.get(), finalURL, headers);
+            data = ServeSynchronousRequest(cache()->loader(), m_doc->docLoader(), request, finalURL, headers);
         }
 
         m_loader = 0;
@@ -351,11 +354,10 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
         gcProtectNullTolerant(KJS::ScriptInterpreter::getDOMObject(this));
     }
   
-    // start can return false here, for example if we're no longer attached to a page.
+    // create can return null here, for example if we're no longer attached to a page.
     // this is true while running onunload handlers
-    // FIXME: Maybe start can return false for other reasons too?
-    if (!m_loader->start(m_doc->docLoader()))
-        m_loader = 0;
+    // FIXME: Maybe create can return false for other reasons too?
+    m_loader = ResourceLoader::create(request, this, m_doc->docLoader());
 }
 
 void XMLHttpRequest::abort()
@@ -527,7 +529,7 @@ void XMLHttpRequest::didFinishLoading(ResourceLoader* loader)
     ASSERT(loader == m_loader);
 
     if (m_responseHeaders.isEmpty() && m_loader)
-        m_responseHeaders = m_loader->queryMetaData("HTTP-Headers");
+        m_responseHeaders = m_loader->responseHTTPHeadersAsString();
 
     if (m_state < Sent)
         changeState(Sent);
@@ -559,7 +561,7 @@ void XMLHttpRequest::receivedRedirect(ResourceLoader*, const KURL& m_url)
 void XMLHttpRequest::didReceiveData(ResourceLoader*, const char* data, int len)
 {
     if (m_responseHeaders.isEmpty() && m_loader)
-        m_responseHeaders = m_loader->queryMetaData("HTTP-Headers");
+        m_responseHeaders = m_loader->responseHTTPHeadersAsString();
 
     if (m_state < Sent)
         changeState(Sent);
index d38b452303c56b0b8acaffa5706971e2b84a4280..98f319f05ae6e94598264ff4a9c3bcfc6f5593f0 100644 (file)
@@ -27,6 +27,7 @@
 #include "KURL.h"
 #include "ResourceLoaderClient.h"
 #include "PlatformString.h"
+#include "ResourceRequest.h"
 #include "StringHash.h"
 
 namespace WebCore {
@@ -101,7 +102,7 @@ private:
     KURL m_url;
     DeprecatedString m_method;
     bool m_async;
-    HashMap<String, String> m_requestHeaders;
+    ResourceRequest::HTTPHeaderMap m_requestHeaders;
 
     RefPtr<ResourceLoader> m_loader;