WebCore:
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Oct 2006 11:08:12 +0000 (11:08 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Oct 2006 11:08:12 +0000 (11:08 +0000)
        Reviewed by Anders.

        - added ResourceResponse class and didReceiveResponse delegate call

        * WebCore.xcodeproj/project.pbxproj: Added new files.
        * bridge/mac/WebCoreFrameBridge.h: Removed no longer needed
        expiresTimeForResponse: method.
        * dom/XMLTokenizer.cpp:
        (WebCore::openFunc): Updated to use ResourceResponse.
        * loader/FrameLoader.h: Update loadResourceSynchronously to
        use ResourceResponse.
        * loader/LoaderFunctions.h:
        * loader/icon/IconLoader.cpp:
        (IconLoader::didReceiveResponse): Updated from receivedResponse
        and made cross-platform.
        * loader/icon/IconLoader.h: updated for above change
        * loader/loader.cpp:
        (WebCore::Loader::receivedResponse): reduced to just saving
        the PlatformResponse (ideally we'd phase out use of this).
        (WebCore::Loader::didReceivedResponse): most of the ReceivedResponse
        logic.
        * loader/loader.h:
        * loader/mac/FrameLoaderMac.mm:
        (WebCore::FrameLoader::loadResourceSynchronously): Return results
        as ResourceResponse.
        * loader/mac/IconLoaderMac.mm: remove receivedResponse.
        * loader/mac/LoaderFunctionsMac.mm:
        (WebCore::ServeSynchronousRequest): take ResourceResponse as
        argument.
        * platform/network/ResourceHandle.cpp:
        * platform/network/ResourceHandle.h: Remove calls for
        broken out response pieces.
        * platform/network/ResourceHandleClient.h:
        (WebCore::ResourceHandleClient::didReceiveResponse): New
        delegate method.
        * platform/network/ResourceHandleInternal.h:
        (WebCore::ResourceHandleInternal::ResourceHandleInternal): Remove
        storage of response bits, we're not gonna return them
        seprately any more.
        * platform/network/ResourceResponse.h: Added.
        (WebCore::ResourceResponse::ResourceResponse): Freshly
        implemented. Same for below.
        (WebCore::ResourceResponse::url):
        (WebCore::ResourceResponse::mimeType):
        (WebCore::ResourceResponse::expectedContentLength):
        (WebCore::ResourceResponse::textEncodingName):
        (WebCore::ResourceResponse::suggestedFilename):
        (WebCore::ResourceResponse::httpStatusCode):
        (WebCore::ResourceResponse::setHTTPStatusCode):
        (WebCore::ResourceResponse::httpHeaderField):
        (WebCore::ResourceResponse::httpHeaderFields):
        (WebCore::ResourceResponse::isMultipart):
        (WebCore::ResourceResponse::setExpirationDate):
        (WebCore::ResourceResponse::expirationDate):
        * platform/network/cf/ResourceHandleCFNet.cpp:
        (WebCore::didReceiveResponse): Send didReceiveResponse
        client method.
        * platform/network/cf/ResourceResponseCFNet.h: Added.
        * platform/network/cf/ResourceResponseCFNet.mm: Added.
        (getResourceResponse): Helper function to get a ResourceResponse
        from CFURLResponseRef.
        * platform/network/mac/ResourceHandleMac.mm:
        (WebCore::ResourceHandleInternal::~ResourceHandleInternal):
        Don't bother cleaning up fields we no longer have.
        (WebCore::ResourceHandle::receivedResponse): Send
        didReceiveResponse client method.
        * platform/network/mac/ResourceResponseMac.h: Added.
        * platform/network/mac/ResourceResponseMac.mm: Added.
        (getResourceResponse): Helper function to get a ResourceResponse
        from an NSURLResponse*.
        * rendering/HitTestResult.cpp:
        * xml/XSLTProcessor.cpp:
        (WebCore::docLoaderFunc): Prepare for use of ResourceResponse.
        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::getResponseText): Store http response
        info in the form of a ResourceResponse, change all methods to
        account for this.
        (WebCore::XMLHttpRequest::getResponseXML):
        (WebCore::XMLHttpRequest::XMLHttpRequest):
        (WebCore::XMLHttpRequest::open):
        (WebCore::XMLHttpRequest::send):
        (WebCore::XMLHttpRequest::getAllResponseHeaders):
        (WebCore::XMLHttpRequest::getResponseHeader):
        (WebCore::XMLHttpRequest::getStatus):
        (WebCore::XMLHttpRequest::getStatusText):
        (WebCore::XMLHttpRequest::processSyncLoadResults):
        (WebCore::XMLHttpRequest::didFinishLoading):
        (WebCore::XMLHttpRequest::didReceiveResponse):
        (WebCore::XMLHttpRequest::didReceiveData):
        * xml/xmlhttprequest.h:

WebKit:

        Reviewed by Anders.

        - added ResourceResponse class and didReceiveResponse delegate call

        * WebCoreSupport/WebFrameBridge.mm: Removed no longer needed
        expiresTimeForResponse: method.

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

30 files changed:
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/dom/XMLTokenizer.cpp
WebCore/loader/FrameLoader.h
WebCore/loader/LoaderFunctions.h
WebCore/loader/icon/IconLoader.cpp
WebCore/loader/icon/IconLoader.h
WebCore/loader/loader.cpp
WebCore/loader/loader.h
WebCore/loader/mac/FrameLoaderMac.mm
WebCore/loader/mac/IconLoaderMac.mm
WebCore/loader/mac/LoaderFunctionsMac.mm
WebCore/platform/network/ResourceHandle.cpp
WebCore/platform/network/ResourceHandle.h
WebCore/platform/network/ResourceHandleClient.h
WebCore/platform/network/ResourceHandleInternal.h
WebCore/platform/network/ResourceResponse.h [new file with mode: 0644]
WebCore/platform/network/cf/ResourceHandleCFNet.cpp
WebCore/platform/network/cf/ResourceResponseCFNet.cpp [new file with mode: 0644]
WebCore/platform/network/cf/ResourceResponseCFNet.h [new file with mode: 0644]
WebCore/platform/network/mac/ResourceHandleMac.mm
WebCore/platform/network/mac/ResourceResponseMac.h [new file with mode: 0644]
WebCore/platform/network/mac/ResourceResponseMac.mm [new file with mode: 0644]
WebCore/rendering/HitTestResult.cpp
WebCore/xml/XSLTProcessor.cpp
WebCore/xml/xmlhttprequest.cpp
WebCore/xml/xmlhttprequest.h
WebKit/ChangeLog
WebKit/WebCoreSupport/WebFrameBridge.mm

index 678e14658ed996e7568cb6325820ba5f8cdf03a6..b47f695fdaec9fe29d8466a35427df739fa8044b 100644 (file)
@@ -1,3 +1,96 @@
+2006-10-29  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Anders.
+
+        - added ResourceResponse class and didReceiveResponse delegate call
+        
+        * WebCore.xcodeproj/project.pbxproj: Added new files.
+        * bridge/mac/WebCoreFrameBridge.h: Removed no longer needed
+        expiresTimeForResponse: method.
+        * dom/XMLTokenizer.cpp:
+        (WebCore::openFunc): Updated to use ResourceResponse.
+        * loader/FrameLoader.h: Update loadResourceSynchronously to
+        use ResourceResponse.
+        * loader/LoaderFunctions.h:
+        * loader/icon/IconLoader.cpp:
+        (IconLoader::didReceiveResponse): Updated from receivedResponse
+        and made cross-platform.
+        * loader/icon/IconLoader.h: updated for above change
+        * loader/loader.cpp:
+        (WebCore::Loader::receivedResponse): reduced to just saving
+        the PlatformResponse (ideally we'd phase out use of this).
+        (WebCore::Loader::didReceivedResponse): most of the ReceivedResponse 
+        logic.
+        * loader/loader.h:
+        * loader/mac/FrameLoaderMac.mm:
+        (WebCore::FrameLoader::loadResourceSynchronously): Return results
+        as ResourceResponse.
+        * loader/mac/IconLoaderMac.mm: remove receivedResponse.
+        * loader/mac/LoaderFunctionsMac.mm:
+        (WebCore::ServeSynchronousRequest): take ResourceResponse as
+        argument.
+        * platform/network/ResourceHandle.cpp:
+        * platform/network/ResourceHandle.h: Remove calls for
+        broken out response pieces.
+        * platform/network/ResourceHandleClient.h:
+        (WebCore::ResourceHandleClient::didReceiveResponse): New
+        delegate method.
+        * platform/network/ResourceHandleInternal.h:
+        (WebCore::ResourceHandleInternal::ResourceHandleInternal): Remove
+        storage of response bits, we're not gonna return them
+        seprately any more.
+        * platform/network/ResourceResponse.h: Added.
+        (WebCore::ResourceResponse::ResourceResponse): Freshly
+        implemented. Same for below.
+        (WebCore::ResourceResponse::url):
+        (WebCore::ResourceResponse::mimeType):
+        (WebCore::ResourceResponse::expectedContentLength):
+        (WebCore::ResourceResponse::textEncodingName):
+        (WebCore::ResourceResponse::suggestedFilename):
+        (WebCore::ResourceResponse::httpStatusCode):
+        (WebCore::ResourceResponse::setHTTPStatusCode):
+        (WebCore::ResourceResponse::httpHeaderField):
+        (WebCore::ResourceResponse::httpHeaderFields):
+        (WebCore::ResourceResponse::isMultipart):
+        (WebCore::ResourceResponse::setExpirationDate):
+        (WebCore::ResourceResponse::expirationDate):
+        * platform/network/cf/ResourceHandleCFNet.cpp:
+        (WebCore::didReceiveResponse): Send didReceiveResponse
+        client method.
+        * platform/network/cf/ResourceResponseCFNet.h: Added.
+        * platform/network/cf/ResourceResponseCFNet.mm: Added.
+        (getResourceResponse): Helper function to get a ResourceResponse 
+        from CFURLResponseRef.
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::ResourceHandleInternal::~ResourceHandleInternal):
+        Don't bother cleaning up fields we no longer have.
+        (WebCore::ResourceHandle::receivedResponse): Send
+        didReceiveResponse client method.
+        * platform/network/mac/ResourceResponseMac.h: Added.
+        * platform/network/mac/ResourceResponseMac.mm: Added.
+        (getResourceResponse): Helper function to get a ResourceResponse 
+        from an NSURLResponse*.
+        * rendering/HitTestResult.cpp:
+        * xml/XSLTProcessor.cpp:
+        (WebCore::docLoaderFunc): Prepare for use of ResourceResponse.
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::getResponseText): Store http response
+        info in the form of a ResourceResponse, change all methods to
+        account for this.
+        (WebCore::XMLHttpRequest::getResponseXML):
+        (WebCore::XMLHttpRequest::XMLHttpRequest):
+        (WebCore::XMLHttpRequest::open):
+        (WebCore::XMLHttpRequest::send):
+        (WebCore::XMLHttpRequest::getAllResponseHeaders):
+        (WebCore::XMLHttpRequest::getResponseHeader):
+        (WebCore::XMLHttpRequest::getStatus):
+        (WebCore::XMLHttpRequest::getStatusText):
+        (WebCore::XMLHttpRequest::processSyncLoadResults):
+        (WebCore::XMLHttpRequest::didFinishLoading):
+        (WebCore::XMLHttpRequest::didReceiveResponse):
+        (WebCore::XMLHttpRequest::didReceiveData):
+        * xml/xmlhttprequest.h:
+
 2006-10-29  Darin Adler  <darin@apple.com>
 
         - fix build
index da8afaf30f90292b2b7f8e787d0a6fc651d4a631..6a6829759c66f4bdf5f654157bdecfdcdc424619 100644 (file)
                6582A16309999D6D00BEEB6D /* SystemTimeMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */; };
                6582A17809999EA000BEEB6D /* DeprecatedStringMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6582A17709999EA000BEEB6D /* DeprecatedStringMac.mm */; };
                658436860AE01B7400E53753 /* FrameLoadRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 658436850AE01B7400E53753 /* FrameLoadRequest.h */; };
+               658821660AF4CDF700F01D1F /* ResourceResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 658821650AF4CDF700F01D1F /* ResourceResponse.h */; };
+               6588216B0AF4CE1200F01D1F /* ResourceResponseMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 658821680AF4CE1200F01D1F /* ResourceResponseMac.h */; };
+               6588216C0AF4CE1200F01D1F /* ResourceResponseMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 658821690AF4CE1200F01D1F /* ResourceResponseMac.mm */; };
                65901A4409FC6039005BD752 /* WebCoreStringTruncator.h in Headers */ = {isa = PBXBuildFile; fileRef = 65901A4209FC6039005BD752 /* WebCoreStringTruncator.h */; settings = {ATTRIBUTES = (Private, ); }; };
                65901A4509FC6039005BD752 /* WebCoreStringTruncator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 65901A4309FC6039005BD752 /* WebCoreStringTruncator.mm */; };
                6593923709AE4346002C531F /* KURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6593923509AE4346002C531F /* KURL.cpp */; };
                6582A15509999D6D00BEEB6D /* SystemTimeMac.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SystemTimeMac.cpp; sourceTree = "<group>"; };
                6582A17709999EA000BEEB6D /* DeprecatedStringMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DeprecatedStringMac.mm; sourceTree = "<group>"; };
                658436850AE01B7400E53753 /* FrameLoadRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FrameLoadRequest.h; sourceTree = "<group>"; };
+               658821650AF4CDF700F01D1F /* ResourceResponse.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceResponse.h; sourceTree = "<group>"; };
+               658821680AF4CE1200F01D1F /* ResourceResponseMac.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceResponseMac.h; sourceTree = "<group>"; };
+               658821690AF4CE1200F01D1F /* ResourceResponseMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceResponseMac.mm; sourceTree = "<group>"; };
                65901A4209FC6039005BD752 /* WebCoreStringTruncator.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebCoreStringTruncator.h; sourceTree = "<group>"; };
                65901A4309FC6039005BD752 /* WebCoreStringTruncator.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreStringTruncator.mm; sourceTree = "<group>"; };
                6593923509AE4346002C531F /* KURL.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = KURL.cpp; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                656B84E70AEA1DAE00A095B4 /* mac */,
-                               6522BCDE09C9DAA800C9BA7A /* ResourceRequest.h */,
                                655A81BD0AEF67E6000975F0 /* HTTPHeaderMap.h */,
                                656B85370AEA1F9A00A095B4 /* ResourceHandle.h */,
                                656B84DC0AEA1D3100A095B4 /* ResourceHandle.cpp */,
                                656B84DE0AEA1D3100A095B4 /* ResourceHandleClient.h */,
                                656B84DF0AEA1D3100A095B4 /* ResourceHandleInternal.h */,
+                               6522BCDE09C9DAA800C9BA7A /* ResourceRequest.h */,
+                               658821650AF4CDF700F01D1F /* ResourceResponse.h */,
                        );
                        path = network;
                        sourceTree = "<group>";
                        isa = PBXGroup;
                        children = (
                                656B84EA0AEA1DDA00A095B4 /* ResourceHandleMac.mm */,
+                               658821680AF4CE1200F01D1F /* ResourceResponseMac.h */,
+                               658821690AF4CE1200F01D1F /* ResourceResponseMac.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                655A81BE0AEF67E6000975F0 /* HTTPHeaderMap.h in Headers */,
                                930500200AF025D300FFF491 /* ClipboardAccessPolicy.h in Headers */,
                                9307F1D80AF2D59000DBA31A /* HitTestResult.h in Headers */,
+                               658821660AF4CDF700F01D1F /* ResourceResponse.h in Headers */,
+                               6588216B0AF4CE1200F01D1F /* ResourceResponseMac.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                853CA9F00AEEC657002372DC /* RenderPath.cpp in Sources */,
                                654F68880AF1B7C50065BDD6 /* CachedResourceMac.mm in Sources */,
                                9307F1D70AF2D59000DBA31A /* HitTestResult.cpp in Sources */,
+                               6588216C0AF4CE1200F01D1F /* ResourceResponseMac.mm in Sources */,
                                932E16090AF578340025F408 /* FrameLoader.cpp in Sources */,
                                93E227E00AF589AD00D48324 /* DocumentLoader.cpp in Sources */,
                                93E227E10AF589AD00D48324 /* MainResourceLoader.cpp in Sources */,
index 0eb574e66064c3913ec049f009de70d91e3a6574..35ba8d4dc4c824e870df8118e6fe872450ffe751 100644 (file)
@@ -439,8 +439,6 @@ typedef enum {
 - (void)addMessageToConsole:(NSDictionary *)message;
 - (void)runOpenPanelForFileButtonWithResultListener:(id <WebCoreOpenPanelResultListener>)resultListener;
 
-- (time_t)expiresTimeForResponse:(NSURLResponse *)response;
-
 - (void)activateWindow;
 - (void)deactivateWindow;
 
index bcb67fe49b6c7c867926d312044c8e313642463a..ef79cecec9f9834114a03dc3529ecb9037bab770 100644 (file)
@@ -42,6 +42,7 @@
 #include "LoaderFunctions.h"
 #include "ProcessingInstruction.h"
 #include "ResourceHandle.h"
+#include "ResourceResponse.h"
 #include <libxml/parser.h>
 #include <libxml/parserInternals.h>
 #include <wtf/Platform.h>
@@ -459,9 +460,8 @@ static void* openFunc(const char* uri)
 
     KURL kurl(uri);
     ResourceRequest request(kurl);
-    KURL finalURL;
-    DeprecatedString headers;
-    Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, request, finalURL, headers);
+    ResourceResponse response;
+    Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, request, response);
     
     return new OffsetBuffer(data);
 }
index 4b1d3fa8c9ed3e8281287921bfacba04a6fbc44e..2de02fbe14a9bef33e429405f691cb403a494ca9 100644 (file)
@@ -91,6 +91,7 @@ namespace WebCore {
     class KURL;
     class MainResourceLoader;
     class ResourceRequest;
+    class ResourceResponse;
     class String;
     class SubresourceLoader;
     class ResourceLoader;
@@ -167,8 +168,7 @@ namespace WebCore {
         bool canLoad(NSURL *, const String& referrer, bool& hideReferrer);
 #endif
 
-        void loadResourceSynchronously(const ResourceRequest&,
-            KURL& finalURL, NSDictionary *& responseHeaders, int& statusCode, Vector<char>& data);
+        void loadResourceSynchronously(const ResourceRequest& request, Vector<char>& data, ResourceResponse& r);
 
         // Also not cool.
         void stopLoadingPlugIns();
index f6339139c45b14a35a66ab4403381fe8ba328dab..369816dc41cc60d381345651d7e8f2aa9899661d 100644 (file)
@@ -51,7 +51,7 @@ class Loader;
 class Request;
 class ResourceRequest;
 
-Vector<char> ServeSynchronousRequest(Loader*, DocLoader*, const ResourceRequest&, KURL& finalURL, DeprecatedString& headers);
+Vector<char> ServeSynchronousRequest(Loader*, DocLoader*, const ResourceRequest&, ResourceResponse&);
 
 void CheckCacheObjectStatus(DocLoader*, CachedResource*);
 bool CheckIfReloading(DocLoader*);
@@ -59,7 +59,6 @@ bool IsResponseURLEqualToURL(PlatformResponse , const String& URL);
 DeprecatedString ResponseURL(PlatformResponse);
 DeprecatedString ResponseMIMEType(PlatformResponse);
 bool ResponseIsMultipart(PlatformResponse);
-time_t CacheObjectExpiresTime(DocLoader*, PlatformResponse);
 NSString* HeaderStringFromDictionary(NSDictionary* headers, int statusCode);
 
 }
index 5f8b0e5400dbd24d705db7a9e2741504a3b2ce8c..376c3da587cb727b1f2d00d312a49c1f33f1c9ec 100644 (file)
@@ -30,6 +30,7 @@
 #include "loader/icon/IconDatabase.h"
 #include "Logging.h"
 #include "page/Frame.h"
+#include "ResourceResponse.h"
 
 #if PLATFORM(MAC)
 #include "FrameMac.h"
@@ -86,6 +87,12 @@ void IconLoader::stopLoading()
     m_data.clear();
 }
 
+void IconLoader::didReceiveResponse(ResourceHandle* resourceLoader, const ResourceResponse& response)
+{
+    ASSERT(resourceLoader);
+    m_httpStatusCode = response.httpStatusCode();
+}
+
 void IconLoader::didReceiveData(ResourceHandle* resourceLoader, const char* data, int size)
 {
     ASSERT(resourceLoader == m_resourceLoader);
index 42fbed8e4f54c4c0285a45fbc2ac65bf6cfe8ee5..e7beff4fa7cfcc1b96042d3f893a6aea4eb633d5 100644 (file)
@@ -40,8 +40,8 @@ public:
     void startLoading();
     void stopLoading();
     
-// ResourceHandleClient delegate methods
-    virtual void receivedResponse(ResourceHandle*, PlatformResponse);
+    // ResourceHandleClient delegate methods
+    virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
     virtual void didReceiveData(ResourceHandle*, const char*, int);
     virtual void didFinishLoading(ResourceHandle*);
 private:
index 9cbac40e3764f26b7e5d16ef0a138f30f135976c..85c00c4db89cd18cc7c99ad59070bed2e5e1921d 100644 (file)
@@ -38,6 +38,7 @@
 #include "LoaderFunctions.h"
 #include "Request.h"
 #include "ResourceHandle.h"
+#include "ResourceResponse.h"
 #include <wtf/Assertions.h>
 #include <wtf/Vector.h>
 
@@ -118,18 +119,24 @@ void Loader::receivedAllData(ResourceHandle* job, PlatformData allData)
     servePendingRequests();
 }
 
-void Loader::receivedResponse(ResourceHandle* job, PlatformResponse response)
+void Loader::receivedResponse(ResourceHandle* handle, PlatformResponse response)
 {
-    Request* req = m_requestsLoading.get(job);
+    Request* req = m_requestsLoading.get(handle);
     ASSERT(req);
 #if !PLATFORM(WIN)
     // FIXME: the win32 platform does not have PlatformResponse yet.
     ASSERT(response);
 #endif
     req->cachedResource()->setResponse(response);
-    req->cachedResource()->setExpireDate(CacheObjectExpiresTime(req->docLoader(), response), false);
+}
+
+void Loader::didReceivedResponse(ResourceHandle* handle, const ResourceResponse& response)
+{
+    Request* req = m_requestsLoading.get(handle);
+    ASSERT(req);
+    req->cachedResource()->setExpireDate(response.expirationDate(), false);
     
-    String encoding = job->responseEncoding();
+    String encoding = response.textEncodingName();
     if (!encoding.isNull())
         req->cachedResource()->setEncoding(encoding);
     
@@ -138,10 +145,10 @@ void Loader::receivedResponse(ResourceHandle* job, PlatformResponse response)
         static_cast<CachedImage*>(req->cachedResource())->clear();
         if (req->docLoader()->frame())
             req->docLoader()->frame()->checkCompleted();
-    } else if (ResponseIsMultipart(response)) {
+     } else if (response.isMultipart()) {
         req->setIsMultipart(true);
         if (!req->cachedResource()->isImage())
-            job->cancel();
+            handle->cancel();
     }
 }
 
index eb36b8305b55baec52786d8d301fcefa124e8ca0..fbc9b72cea86ff046379e8220f0c0fab4b067220 100644 (file)
@@ -64,6 +64,7 @@ namespace WebCore {
 
     private:
         virtual void receivedResponse(ResourceHandle*, PlatformResponse);
+        virtual void didReceivedResponse(ResourceHandle* handle, const ResourceResponse& response);
         virtual void didReceiveData(ResourceHandle*, const char*, int);
         virtual void receivedAllData(ResourceHandle*, PlatformData);
 
index 1f0ec330a78d09a3cae55e9c90b7b73dd5a54c8b..8e26c8d531ec4e004dad8c205185600da7a19afd 100644 (file)
@@ -43,6 +43,8 @@
 #import "LoaderNSURLRequestExtras.h"
 #import "Page.h"
 #import "Plugin.h"
+#import "ResourceResponse.h"
+#import "ResourceResponseMac.h"
 #import "WebCoreFrameBridge.h"
 #import "WebCoreIconDatabaseBridge.h"
 #import "WebCorePageState.h"
@@ -1877,8 +1879,7 @@ void FrameLoader::loadEmptyDocumentSynchronously()
     [url release];
 }
 
-void FrameLoader::loadResourceSynchronously(const ResourceRequest& request,
-            KURL& finalURL, NSDictionary *& responseHeaders, int& statusCode, Vector<char>& data)
+void FrameLoader::loadResourceSynchronously(const ResourceRequest& request, Vector<char>& data, ResourceResponse& r)
 {
 #if 0
     NSDictionary *headerDict = nil;
@@ -1941,23 +1942,14 @@ void FrameLoader::loadResourceSynchronously(const ResourceRequest& request,
     
     [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 == nil)
+        getResourceResponse(r, response);
+    else {
+        r = ResourceResponse(URL, String(), 0, String(), String());
         if ([error domain] == NSURLErrorDomain)
-            statusCode = [error code];
+            r.setHTTPStatusCode([error code]);
         else
-            statusCode = 404;
+            r.setHTTPStatusCode(404);
     }
     
     sendRemainingDelegateMessages(identifier, response, [result length], error);
index 004afb4f336e2c575aedd1d3078c8d3f33161100..9a1b1a4459bf272fc85846b6eb49af245db2dfa8 100644 (file)
 
 using namespace WebCore;
 
-void IconLoader::receivedResponse(ResourceHandle* resourceLoader, NSURLResponse* responsePtr)
-{
-    ASSERT(resourceLoader);
-    ASSERT(responsePtr);
-    
-    id response = responsePtr;
-    if ([response isKindOfClass:[NSHTTPURLResponse class]])
-        m_httpStatusCode = [response statusCode];
-    else
-        m_httpStatusCode = 0;
-}
-
 void IconLoader::notifyIconChanged(const KURL& iconURL)
 {
     m_frame->loader()->notifyIconChanged(iconURL.getNSURL());
index d5413dcbb848f7243ce976ee2ff8af6bf02ab111..78cc3363f57a4c054bce6b61506fc3d916c39e86 100644 (file)
@@ -87,7 +87,7 @@ NSString *HeaderStringFromDictionary(NSDictionary *headers, int statusCode)
     return headerString;
 }
 
-Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, const ResourceRequest& request, KURL &finalURL, DeprecatedString &responseHeaders)
+Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, const ResourceRequest& request, ResourceResponse& response)
 {
     FrameMac *frame = static_cast<FrameMac *>(docLoader->frame());
     
@@ -98,12 +98,8 @@ Vector<char> ServeSynchronousRequest(Loader *loader, DocLoader *docLoader, const
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    NSDictionary *responseHeaderDict = nil;
-    int statusCode = 0;
     Vector<char> result;
-    frame->loader()->loadResourceSynchronously(request, finalURL, responseHeaderDict, statusCode, result);
-    
-    responseHeaders = DeprecatedString::fromNSString(HeaderStringFromDictionary(responseHeaderDict, statusCode));
+    frame->loader()->loadResourceSynchronously(request, result, response);
 
     return result;
 
@@ -200,21 +196,6 @@ bool ResponseIsMultipart(PlatformResponse response)
     return false;
 }
 
-time_t CacheObjectExpiresTime(DocLoader *docLoader, PlatformResponse response)
-{
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    
-    FrameMac *frame = static_cast<FrameMac *>(docLoader->frame());
-    if (frame) {
-        WebCoreFrameBridge *bridge = frame->bridge();
-        return [bridge expiresTimeForResponse:(NSURLResponse *)response];
-    }
-    
-    END_BLOCK_OBJC_EXCEPTIONS;
-    
-    return 0;
-}
-
 void CachedResource::setResponse(PlatformResponse response)
 {
     HardRetain(response);
index 4d0bf8f737d726498791d3b8808367cf8a1b4923..c40cc93dac49111caf94493d676c41bf7f3181f8 100644 (file)
@@ -62,19 +62,6 @@ void ResourceHandle::setError(int e)
     d->status = e;
 }
 
-String ResourceHandle::responseEncoding() const
-{
-    retrieveResponseEncoding();
-    
-    return d->m_responseEncoding;
-}
-
-String ResourceHandle::responseHTTPHeadersAsString() const
-{
-    assembleResponseHeaders();
-    return d->responseHeaders;
-}
-
 void ResourceHandle::kill()
 {
     if (d->m_loading){
index 57b1243957e5de78621dcbcb8dd1548bbaea5b56..ac81944c411edf25d365adc48bfb90e55b217f6f 100644 (file)
@@ -75,9 +75,6 @@ public:
     String errorText() const;
     bool isErrorPage() const;
     
-    String responseEncoding() const;
-
-    String responseHTTPHeadersAsString() const;
     void kill();
 
 #if PLATFORM(MAC)
@@ -121,9 +118,6 @@ public:
 private:
     bool start(DocLoader*);
 
-    void assembleResponseHeaders() const;
-    void retrieveResponseEncoding() const;
-
     ResourceHandleInternal* d;
 };
 
index ece27eea8b03bf80d440e169ea24793914accdc3..76465d2067e38bdac4bfad64ea8f5e952e956445 100644 (file)
@@ -74,6 +74,7 @@ namespace WebCore {
 
     class KURL;
     class ResourceHandle;
+    class ResourceResponse;
 
     class ResourceHandleClient {
     public:
@@ -85,7 +86,7 @@ namespace WebCore {
         // void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&) { }
         // void didCancelAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&) { }
 
-        // void didReceiveResponse(ResourceHandle*, const ResourceResponse&) { }
+        virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&) { }
         virtual void didReceiveData(ResourceHandle*, const char*, int) { }
         virtual void didFinishLoading(ResourceHandle*) { }
         // void didFailWithError(ResourceError*) { }
index dd28b5c3207ee787e7a4a9287304911be6b86e59..d155d1bc86dac9eb835a248b773763ef16717a8a 100644 (file)
@@ -66,15 +66,10 @@ namespace WebCore {
             : m_client(c)
             , m_request(request)
             , status(0)
-            , 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)
@@ -103,21 +98,14 @@ namespace WebCore {
         ResourceRequest m_request;
         
         int status;
-        String m_responseEncoding;
-        DeprecatedString responseHeaders;
 
-        bool assembledResponseHeaders;
-        bool m_retrievedResponseEncoding;
-    
         bool m_loading;
         bool m_cancelled;
 
 #if USE(CFNETWORK)
         CFURLConnectionRef m_connection;
 #elif PLATFORM(MAC)
-        WebCoreResourceLoaderImp* loader;
         RefPtr<WebCore::SubresourceLoader> m_subresourceLoader;
-        NSURLResponse* response;
 #endif
 #if USE(WININET)
         HANDLE m_fileHandle;
diff --git a/WebCore/platform/network/ResourceResponse.h b/WebCore/platform/network/ResourceResponse.h
new file mode 100644 (file)
index 0000000..d9993f7
--- /dev/null
@@ -0,0 +1,88 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 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
+ * 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. 
+ */
+
+#ifndef ResourceResponse_h_
+#define ResourceResponse_h_
+
+#include "HTTPHeaderMap.h"
+#include "KURL.h"
+
+namespace WebCore {
+
+class ResourceResponse {
+public:
+
+    ResourceResponse() : m_expectedContentLength(0), m_httpStatusCode(0) {}
+
+    ResourceResponse(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename)
+        : m_url(url)
+        , m_mimeType(mimeType)
+        , m_expectedContentLength(expectedLength)
+        , m_textEncodingName(textEncodingName)
+        , m_suggestedFilename(filename)
+        , m_httpStatusCode(0)
+    {
+    }
+    const KURL& url() const { return m_url; }
+    const String& mimeType() const { return m_mimeType; }
+    long long expectedContentLength() const { return m_expectedContentLength; }
+    const String& textEncodingName() const { return m_textEncodingName; }
+
+    // FIXME should compute this on the fly
+    const String& suggestedFilename() const { return m_suggestedFilename; }
+
+    int httpStatusCode() const { return m_httpStatusCode; }
+    void setHTTPStatusCode(int statusCode) { m_httpStatusCode = statusCode; }
+    const String& httpStatusText() const { return m_httpStatusText; }
+    void setHTTPStatusText(const String& statusText) { m_httpStatusText = statusText; }
+    String httpHeaderField(const String& name) const { return m_httpHeaderFields.get(name); }
+    const HTTPHeaderMap& httpHeaderFields() const { return m_httpHeaderFields; }
+    HTTPHeaderMap& httpHeaderFields() { return m_httpHeaderFields; }
+
+    // possibly add calculated expiration info
+    // lastModifiedDate (date)
+
+    bool isMultipart() const { return m_mimeType == "multipart/x-mixed-replace"; }
+
+    void setExpirationDate(time_t expirationDate) { m_expirationDate = expirationDate; }
+    time_t expirationDate() const { return m_expirationDate; }
+
+ private:
+    KURL m_url;
+    String m_mimeType;
+    long long m_expectedContentLength;
+    String m_textEncodingName;
+    String m_suggestedFilename;
+    int m_httpStatusCode;
+    String m_httpStatusText;
+    HTTPHeaderMap m_httpHeaderFields;
+    time_t m_expirationDate;
+};
+
+} // namespace WebCore
+
+#endif // ResourceResponse_h_
index 9b2fd48376621b027b36c84c8cc79b127e394a09..e761a3746a259159bfc44e8a257312c864f4eca3 100644 (file)
 
 #if USE(CFNETWORK)
 
-#include "ResourceHandle.h"
-#include "ResourceHandleInternal.h"
 #include "DocLoader.h"
 #include "Frame.h"
+#include "ResourceHandle.h"
+#include "ResourceHandleInternal.h"
+#include "ResourceResponse.h"
+#include "ResourceResponseCFNet.h"
 
 #include <WTF/HashMap.h>
 
@@ -78,17 +80,22 @@ CFURLRequestRef willSendRequest(CFURLConnectionRef conn, CFURLRequestRef request
     return request;
 }
 
-void didReceiveResponse(CFURLConnectionRef conn, CFURLResponseRef response, const void* clientInfo) 
+void didReceiveResponse(CFURLConnectionRef conn, CFURLResponseRef cfResponse, const void* clientInfo) 
 {
-    ResourceHandle* job = (ResourceHandle*)clientInfo;
+    ResourceHandle* handle = (ResourceHandle*)clientInfo;
 
 #if defined(LOG_RESOURCELOADER_EVENTS)
-    CFStringRef str = CFStringCreateWithFormat(0, 0, CFSTR("didReceiveResponse(conn=%p, job = %p)\n"), conn, job);
+    CFStringRef str = CFStringCreateWithFormat(0, 0, CFSTR("didReceiveResponse(conn=%p, job = %p)\n"), conn, handle);
     CFShow(str);
     CFRelease(str);
 #endif
 
-    job->client()->receivedResponse(job, response);
+    if (ResourceHandleClient* client = handle->client()) {
+      client->receivedResponse(handle, cfResponse);
+      ResourceResponse response;
+      getResourceResponse(response, cfResponse);
+      client->didReceiveResponse(handle, response);
+    }
 }
 
 void didReceiveData(CFURLConnectionRef conn, CFDataRef data, CFIndex originalLength, const void* clientInfo) 
diff --git a/WebCore/platform/network/cf/ResourceResponseCFNet.cpp b/WebCore/platform/network/cf/ResourceResponseCFNet.cpp
new file mode 100644 (file)
index 0000000..080834e
--- /dev/null
@@ -0,0 +1,72 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 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
+ * 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"
+#include "ResourceResponseCFNet.h"
+
+#include "ResourceResponse.h"
+#include <CFNetwork/CFURLResponsePriv.h>
+
+// We would like a better value for a maximum time_t,
+// but there is no way to do that in C with any certainty.
+// INT_MAX should work well enough for our purposes.
+#define MAX_TIME_T ((time_t)INT_MAX)    
+
+namespace WebCore {
+
+   void getResourceResponse(ResourceResponse& response, CFURLResponseRef cfResponse)
+   {
+       // FIXME: we may need to do MIME type sniffing here (unless that is done
+       // in CFURLResponseGetMIMEType
+
+       response = ResourceResponse(CFURLResponseGetURL(cfResponse), CFURLResponseGetMIMEType(cfResponse), CFURLResponseGetExpectedContentLength(cfResponse), CFURLResponseGetTextEncodingName(cfResponse), /* suggestedFilename */ "");
+
+       CFAbsoluteTime expiration = CFURLResponseGetExpirationTime(cfResponse);
+       response.setExpirationDate(expiration > MAX_TIME_T ? MAX_TIME_T : (time_t)expiration);
+
+       CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(cfResponse);
+       if (httpResponse) {
+           response.setHTTPStatusCode(CFHTTPMessageGetResponseStatusCode(httpResponse));
+
+           CFStringRef statusLine = CFHTTPMessageCopyResponseStatusLine(httpResponse);
+           String statusText(statusLine);
+           CFRelease(statusLine);
+           int spacePos = statusText.find(" ");
+           if (spacePos != -1)
+               statusText = statusText.substring(spacePos + 1);
+           response.setHTTPStatusText(statusText);
+
+           CFDictionaryRef headers = CFHTTPMessageCopyAllHeaderFields(httpResponse);
+           CFIndex headerCount = CFDictionaryGetCount(headers);
+           Vector<const void*, 128> keys(headerCount);
+           Vector<const void*, 128> values(headerCount);
+           CFDictionaryGetKeysAndValues(headers, keys.data(), values.data());
+           for (int i = 0; i < headerCount; ++i)
+               response.httpHeaderFields().set((CFStringRef)keys[i], (CFStringRef)values[i]);
+       }
+   }
+
+}
diff --git a/WebCore/platform/network/cf/ResourceResponseCFNet.h b/WebCore/platform/network/cf/ResourceResponseCFNet.h
new file mode 100644 (file)
index 0000000..f5f110d
--- /dev/null
@@ -0,0 +1,40 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 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
+ * 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. 
+ */
+
+#ifndef ResourceResponseCFNet_h_
+#define ResourceResponseCFNet_h_
+
+typedef struct _CFURLResponse* CFURLResponseRef;
+
+namespace WebCore {
+
+    class ResourceResponse;
+
+    void getResourceResponse(ResourceResponse& response, CFURLResponseRef cfResponse);
+
+}
+
+#endif // ResourceResponseCFNet_h_
index 962e79331e390c6160b32051435cb743f5f1a7ae..d86ddb2421ecc64fae0f0a0fb1cc8aae01414773 100644 (file)
@@ -35,6 +35,8 @@
 #import "KURL.h"
 #import "LoaderFunctions.h"
 #import "Logging.h"
+#import "ResourceResponse.h"
+#import "ResourceResponseMac.h"
 #import "WebCoreFrameBridge.h"
 #import "SubresourceLoader.h"
 
@@ -42,8 +44,6 @@ namespace WebCore {
     
 ResourceHandleInternal::~ResourceHandleInternal()
 {
-    HardRelease(response);
-    HardRelease(loader);
 }
 
 ResourceHandle::~ResourceHandle()
@@ -88,40 +88,18 @@ bool ResourceHandle::start(DocLoader* docLoader)
     return false;
 }
 
-void ResourceHandle::assembleResponseHeaders() const
+void ResourceHandle::receivedResponse(NSURLResponse* nsResponse)
 {
-    if (!d->assembledResponseHeaders) {
-        if ([d->response isKindOfClass:[NSHTTPURLResponse class]]) {
-            NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)d->response;
-            NSDictionary *headers = [httpResponse allHeaderFields];
-            d->responseHeaders = DeprecatedString::fromNSString(HeaderStringFromDictionary(headers, [httpResponse statusCode]));
-        }
-        d->assembledResponseHeaders = true;
-    }
-}
+    ASSERT(nsResponse);
 
-void ResourceHandle::retrieveResponseEncoding() const
-{
-    if (!d->m_retrievedResponseEncoding) {
-        NSString *textEncodingName = [d->response textEncodingName];
-        if (textEncodingName)
-            d->m_responseEncoding = textEncodingName;
-        d->m_retrievedResponseEncoding = true;
+    if (client()) {
+        client()->receivedResponse(this, nsResponse);
+        ResourceResponse response;
+        getResourceResponse(response, nsResponse);
+        client()->didReceiveResponse(this, response);
     }
 }
 
-void ResourceHandle::receivedResponse(NSURLResponse* response)
-{
-    ASSERT(response);
-
-    d->assembledResponseHeaders = false;
-    d->m_retrievedResponseEncoding = false;
-    d->response = response;
-    HardRetain(d->response);
-    if (client())
-        client()->receivedResponse(this, response);
-}
-
 void ResourceHandle::cancel()
 {
     d->m_subresourceLoader->cancel();
diff --git a/WebCore/platform/network/mac/ResourceResponseMac.h b/WebCore/platform/network/mac/ResourceResponseMac.h
new file mode 100644 (file)
index 0000000..193f6b5
--- /dev/null
@@ -0,0 +1,40 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 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
+ * 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. 
+ */
+
+#ifndef ResourceResponseMac_h_
+#define ResourceResponseMac_h_
+
+@class NSURLResponse;
+
+namespace WebCore {
+
+    class ResourceResponse;
+
+    void getResourceResponse(ResourceResponse& response, NSURLResponse *nsResponse);
+
+}
+
+#endif // ResourceResponseMac_h_
diff --git a/WebCore/platform/network/mac/ResourceResponseMac.mm b/WebCore/platform/network/mac/ResourceResponseMac.mm
new file mode 100644 (file)
index 0000000..51c882e
--- /dev/null
@@ -0,0 +1,71 @@
+// -*- mode: c++; c-basic-offset: 4 -*-
+/*
+ * Copyright (C) 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
+ * 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. 
+ */
+
+#import "config.h"
+#import "ResourceResponseMac.h"
+
+#import "ResourceResponse.h"
+
+#import <Foundation/Foundation.h>
+
+@interface NSURLResponse (FoundationSecretsWebCoreKnowsAbout)
+- (NSTimeInterval)_calculatedExpiration;
+@end
+
+// We would like a better value for a maximum time_t,
+// but there is no way to do that in C with any certainty.
+// INT_MAX should work well enough for our purposes.
+#define MAX_TIME_T ((time_t)INT_MAX)    
+
+namespace WebCore {
+
+   void getResourceResponse(ResourceResponse& response, NSURLResponse *nsResponse)
+   {
+       response = ResourceResponse([nsResponse URL], [nsResponse MIMEType], [nsResponse expectedContentLength], [nsResponse textEncodingName], [nsResponse suggestedFilename]);
+
+       NSTimeInterval expiration = [nsResponse _calculatedExpiration];
+       expiration += kCFAbsoluteTimeIntervalSince1970;
+       response.setExpirationDate(expiration > MAX_TIME_T ? MAX_TIME_T : (time_t)expiration);
+
+
+       if ([nsResponse isKindOfClass:[NSHTTPURLResponse class]]) {
+           NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)nsResponse;
+
+           response.setHTTPStatusCode([httpResponse statusCode]);
+
+           // FIXME: it would be nice to have a way to get the real
+           // status text eventually
+           response.setHTTPStatusText("OK");
+           
+           NSDictionary *headers = [httpResponse allHeaderFields];
+           NSEnumerator *e = [headers keyEnumerator];
+           NSString *name;
+           while ((name = [e nextObject]))
+               response.httpHeaderFields().set(name, [headers objectForKey:name]);
+       } 
+   }
+
+}
index 8130c63fbce1875f44aac8df92367f721fc04c13..f8407e2ce16a01d67bf96f291e9e7c7718bf061c 100644 (file)
@@ -27,7 +27,7 @@
 #include "Frame.h"
 #include "FrameTree.h"
 #include "HTMLElement.h"
-#include "PlatformScrollbar.h"
+#include "PlatformScrollBar.h"
 #include "RenderObject.h"
 
 namespace WebCore {
index 354aa87bdd2f3487c0c883b682a8b22f4f0086e5..1beccf5848e7a6acdbbedecdf7a43cdfe80cd1e2 100644 (file)
@@ -36,6 +36,7 @@
 #include "HTMLTokenizer.h"
 #include "LoaderFunctions.h"
 #include "ResourceHandle.h"
+#include "ResourceResponse.h"
 #include "Text.h"
 #include "loader.h"
 #include "markup.h"
@@ -85,12 +86,11 @@ static xmlDocPtr docLoaderFunc(const xmlChar *uri,
             KURL url((const char*)base, (const char*)uri);
             xmlFree(base);
             ResourceRequest request(url);
-            KURL finalURL;
-            DeprecatedString headers;
+            ResourceResponse response;
             xmlGenericErrorFunc oldErrorFunc = xmlGenericError;
             void *oldErrorContext = xmlGenericErrorContext;
             
-            Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, request, finalURL, headers);
+            Vector<char> data = ServeSynchronousRequest(cache()->loader(), globalDocLoader, request, response);
         
             xmlSetGenericErrorFunc(0, parseErrorFunc);
             // We don't specify an encoding here. Neither Gecko nor WinIE respects
index 02264b86e3f39b62c39a4978dee89dcd07afbd72..50d9b610d41cad3a1522df6ca7cfe17f1f0ce842 100644 (file)
@@ -144,7 +144,7 @@ XMLHttpRequestState XMLHttpRequest::getReadyState() const
 
 String XMLHttpRequest::getResponseText() const
 {
-    return m_response;
+    return m_responseText;
 }
 
 Document* XMLHttpRequest::getResponseXML() const
@@ -156,7 +156,7 @@ Document* XMLHttpRequest::getResponseXML() const
         if (responseIsXML()) {
             m_responseXML = m_doc->implementation()->createDocument();
             m_responseXML->open();
-            m_responseXML->write(m_response);
+            m_responseXML->write(m_responseText);
             m_responseXML->finishParsing();
             m_responseXML->close();
         }
@@ -191,7 +191,7 @@ XMLHttpRequest::XMLHttpRequest(Document* d)
     , m_async(true)
     , m_loader(0)
     , m_state(Uninitialized)
-    , m_response("", 0)
+    , m_responseText("", 0)
     , m_createdDocument(false)
     , m_aborted(false)
 {
@@ -246,8 +246,8 @@ void XMLHttpRequest::open(const String& method, const KURL& url, bool async, con
 
     // clear stuff from possible previous load
     m_requestHeaders.clear();
-    m_responseHeaders = String();
-    m_response = "";
+    m_response = ResourceResponse();
+    m_responseText = "";
     m_createdDocument = false;
     m_responseXML = 0;
 
@@ -325,17 +325,16 @@ void XMLHttpRequest::send(const String& body, ExceptionCode& ec)
 
     if (!m_async) {
         Vector<char> data;
-        KURL finalURL;
-        DeprecatedString headers;
+        ResourceResponse response;
 
         {
             // 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(), request, finalURL, headers);
+            data = ServeSynchronousRequest(cache()->loader(), m_doc->docLoader(), request, response);
         }
 
         m_loader = 0;
-        processSyncLoadResults(data, finalURL, headers);
+        processSyncLoadResults(data, response);
     
         return;
     }
@@ -402,40 +401,23 @@ String XMLHttpRequest::getRequestHeader(const String& name) const
 
 String XMLHttpRequest::getAllResponseHeaders() const
 {
-    if (m_responseHeaders.isEmpty())
-        return String();
+    Vector<UChar> stringBuilder;
+    String separator(": ");
 
-    int endOfLine = m_responseHeaders.find("\n");
-    if (endOfLine == -1)
-        return String();
+    HTTPHeaderMap::const_iterator end = m_response.httpHeaderFields().end();
+    for (HTTPHeaderMap::const_iterator it = m_response.httpHeaderFields().begin(); it!= end; ++it) {
+        stringBuilder.append(it->first.characters(), it->first.length());
+        stringBuilder.append(separator.characters(), separator.length());
+        stringBuilder.append(it->second.characters(), it->second.length());
+        stringBuilder.append((UChar)'\n');
+    }
 
-    return m_responseHeaders.substring(endOfLine + 1) + "\n";
+    return String::adopt(stringBuilder);
 }
 
 String XMLHttpRequest::getResponseHeader(const String& name) const
 {
-    return getSpecificHeader(m_responseHeaders.deprecatedString(), name.deprecatedString());
-}
-
-DeprecatedString XMLHttpRequest::getSpecificHeader(const DeprecatedString& headers, const DeprecatedString& name)
-{
-    if (headers.isEmpty())
-        return DeprecatedString();
-
-    RegularExpression headerLinePattern(name + ":", false);
-
-    int matchLength;
-    int headerLinePos = headerLinePattern.match(headers, 0, &matchLength);
-    while (headerLinePos != -1) {
-        if (headerLinePos == 0 || headers[headerLinePos-1] == '\n')
-            break;
-        headerLinePos = headerLinePattern.match(headers, headerLinePos + 1, &matchLength);
-    }
-    if (headerLinePos == -1)
-        return DeprecatedString();
-    
-    int endOfLine = headers.find("\n", headerLinePos + matchLength);
-    return headers.mid(headerLinePos + matchLength, endOfLine - (headerLinePos + matchLength)).stripWhiteSpace();
+    return m_response.httpHeaderField(name);
 }
 
 bool XMLHttpRequest::responseIsXML() const
@@ -453,26 +435,13 @@ int XMLHttpRequest::getStatus(ExceptionCode& ec) const
     if (m_state == Uninitialized)
         return 0;
     
-    if (m_responseHeaders.isEmpty()) {
+    if (m_response.httpStatusCode() == 0) {
         if (m_state != Receiving && m_state != Loaded)
             // status MUST be available in these states, but we don't get any headers from non-HTTP requests
             ec = INVALID_STATE_ERR;
-        return 0;
     }
-    
-    int endOfLine = m_responseHeaders.find("\n");
-    String firstLine = endOfLine == -1 ? m_responseHeaders : m_responseHeaders.substring(0, endOfLine);
-    int codeStart = firstLine.find(" ");
-    int codeEnd = firstLine.find(" ", codeStart + 1);
-    ASSERT(codeStart != -1);
-    ASSERT(codeEnd != -1);
-  
-    String number = firstLine.substring(codeStart + 1, codeEnd - (codeStart + 1));
-    bool ok = false;
-    int code = number.toInt(&ok);
-    ASSERT(ok);
 
-    return code;
+    return m_response.httpStatusCode();
 }
 
 String XMLHttpRequest::getStatusText(ExceptionCode& ec) const
@@ -480,31 +449,25 @@ String XMLHttpRequest::getStatusText(ExceptionCode& ec) const
     if (m_state == Uninitialized)
         return "";
     
-    if (m_responseHeaders.isEmpty()) {
+    if (m_response.httpStatusCode() == 0) {
         if (m_state != Receiving && m_state != Loaded)
             // statusText MUST be available in these states, but we don't get any headers from non-HTTP requests
             ec = INVALID_STATE_ERR;
         return String();
     }
-  
-    int endOfLine = m_responseHeaders.find("\n");
-    String firstLine = endOfLine == -1 ? m_responseHeaders : m_responseHeaders.substring(0, endOfLine);
-    int codeStart = firstLine.find(" ");
-    int codeEnd = firstLine.find(" ", codeStart + 1);
-    ASSERT(codeStart != -1);
-    ASSERT(codeEnd != -1);
-  
-    return firstLine.substring(codeEnd + 1, endOfLine - (codeEnd + 1)).stripWhiteSpace();
+
+    // FIXME: should try to preserve status text in response
+    return "OK";
 }
 
-void XMLHttpRequest::processSyncLoadResults(const Vector<char>& data, const KURL& finalURL, const DeprecatedString& headers)
+void XMLHttpRequest::processSyncLoadResults(const Vector<char>& data, const ResourceResponse& response)
 {
-    if (!urlMatchesDocumentDomain(finalURL)) {
+    if (!urlMatchesDocumentDomain(response.url())) {
         abort();
         return;
     }
 
-    m_responseHeaders = headers;
+    didReceiveResponse(0, response);
     changeState(Sent);
     if (m_aborted)
         return;
@@ -523,14 +486,11 @@ void XMLHttpRequest::didFinishLoading(ResourceHandle* loader)
 {
     ASSERT(loader == m_loader);
 
-    if (m_responseHeaders.isEmpty() && m_loader)
-        m_responseHeaders = m_loader->responseHTTPHeadersAsString();
-
     if (m_state < Sent)
         changeState(Sent);
 
     if (m_decoder)
-        m_response += m_decoder->flush();
+        m_responseText += m_decoder->flush();
 
     bool hadLoader = m_loader;
     m_loader = 0;
@@ -553,21 +513,21 @@ void XMLHttpRequest::receivedRedirect(ResourceHandle*, const KURL& m_url)
         abort();
 }
 
-void XMLHttpRequest::didReceiveData(ResourceHandle*, const char* data, int len)
+void XMLHttpRequest::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
 {
-    if (m_responseHeaders.isEmpty() && m_loader)
-        m_responseHeaders = m_loader->responseHTTPHeadersAsString();
+    m_response = response;
+    m_encoding = getCharset(m_mimeTypeOverride);
+    if (m_encoding.isEmpty())
+        m_encoding = response.textEncodingName();
+
+}
 
+void XMLHttpRequest::didReceiveData(ResourceHandle*, const char* data, int len)
+{
     if (m_state < Sent)
         changeState(Sent);
   
     if (!m_decoder) {
-        m_encoding = getCharset(m_mimeTypeOverride);
-        if (m_encoding.isEmpty())
-            m_encoding = getCharset(getResponseHeader("Content-Type"));
-        if (m_encoding.isEmpty() && m_loader)
-            m_encoding = m_loader->responseEncoding();
-    
         if (!m_encoding.isEmpty())
             m_decoder = new TextResourceDecoder("text/plain", m_encoding);
         else if (responseIsXML())
@@ -584,7 +544,7 @@ void XMLHttpRequest::didReceiveData(ResourceHandle*, const char* data, int len)
 
     String decoded = m_decoder->decode(data, len);
 
-    m_response += decoded;
+    m_responseText += decoded;
 
     if (!m_aborted) {
         if (m_state != Receiving)
index fceb14e8a37083a8e399a6eccfc1d52579f3b19a..adef105711878002c2b393e33fce0451c96fcd57 100644 (file)
@@ -26,6 +26,7 @@
 #include <wtf/Vector.h>
 #include "KURL.h"
 #include "ResourceHandleClient.h"
+#include "ResourceResponse.h"
 #include "PlatformString.h"
 #include "HTTPHeaderMap.h"
 #include "StringHash.h"
@@ -82,15 +83,15 @@ private:
     bool urlMatchesDocumentDomain(const KURL&) const;
 
     virtual void receivedRedirect(ResourceHandle*, const KURL&);
+    virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
     virtual void didReceiveData(ResourceHandle*, const char* data, int size);
     virtual void didFinishLoading(ResourceHandle*);
 
-    void processSyncLoadResults(const Vector<char>& data, const KURL& finalURL, const DeprecatedString& headers);
+    void processSyncLoadResults(const Vector<char>& data, const ResourceResponse&);
 
     bool responseIsXML() const;
 
     String getRequestHeader(const String& name) const;
-    static DeprecatedString getSpecificHeader(const DeprecatedString& headers, const DeprecatedString& name);
 
     void changeState(XMLHttpRequestState newState);
     void callReadyStateChangeListener();
@@ -101,19 +102,18 @@ private:
 
     KURL m_url;
     DeprecatedString m_method;
-    bool m_async;
     HTTPHeaderMap m_requestHeaders;
+    String m_mimeTypeOverride;
+    bool m_async;
 
     RefPtr<ResourceHandle> m_loader;
-
     XMLHttpRequestState m_state;
 
-    RefPtr<TextResourceDecoder> m_decoder;
+    ResourceResponse m_response;
     String m_encoding;
-    String m_responseHeaders;
-    String m_mimeTypeOverride;
 
-    String m_response;
+    RefPtr<TextResourceDecoder> m_decoder;
+    String m_responseText;
     mutable bool m_createdDocument;
     mutable RefPtr<Document> m_responseXML;
 
index 54246292a37b001abf5acab2d629e550884559a7..29e5c2703e3af5f5d77f4626817dce030bf8d561 100644 (file)
@@ -1,3 +1,12 @@
+2006-10-29  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Anders.
+
+        - added ResourceResponse class and didReceiveResponse delegate call
+
+        * WebCoreSupport/WebFrameBridge.mm: Removed no longer needed
+        expiresTimeForResponse: method.
+
 2006-10-29  Darin Adler  <darin@apple.com>
 
         - update for the WebCore rename
index 87aada3255d047c799072113d441c794aaf0dc6b..398a23a3d1ec72ab7e3214e7de9b299dcd613a35 100644 (file)
 - (NSView *)_findLastViewInKeyViewLoop;
 @end
 
-@interface NSURLResponse (FoundationSecretsWebBridgeKnowsAbout)
-- (NSTimeInterval)_calculatedExpiration;
-@end
-
 @interface NSView (JavaPluginSecrets)
 - (jobject)pollForAppletInWindow:(NSWindow *)window;
 @end
@@ -492,23 +488,6 @@ NSString *WebPluginContainerKey =   @"WebPluginContainer";
     [[wv _UIDelegateForwarder] webView:wv setStatusText:status];
 }
 
-// We would like a better value for a maximum time_t,
-// but there is no way to do that in C with any certainty.
-// INT_MAX should work well enough for our purposes.
-#define MAX_TIME_T ((time_t)INT_MAX)    
-
-- (time_t)expiresTimeForResponse:(NSURLResponse *)response
-{
-    // This check can be removed when the new Foundation method
-    // has been around long enough for everyone to have it.
-    ASSERT([response respondsToSelector:@selector(_calculatedExpiration)]);
-
-    NSTimeInterval expiration = [response _calculatedExpiration];
-    expiration += kCFAbsoluteTimeIntervalSince1970;
-    
-    return expiration > MAX_TIME_T ? MAX_TIME_T : (time_t)expiration;
-}
-
 - (void)close
 {
     [super close];