Reviewed by Geoff.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Nov 2006 06:49:17 +0000 (06:49 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Nov 2006 06:49:17 +0000 (06:49 +0000)
        - added ResourceError class and didFailWithError client method

        * WebCore.xcodeproj/project.pbxproj:
        * loader/icon/IconLoader.cpp:
        (WebCore::IconLoader::didFailWithError):
        (WebCore::IconLoader::didFinishLoading):
        * loader/icon/IconLoader.h:
        * loader/loader.cpp:
        (WebCore::Loader::receivedAllData):
        (WebCore::Loader::didFailWithError):
        * loader/loader.h:
        * loader/mac/SubresourceLoaderMac.mm:
        (WebCore::SubresourceLoader::didFail):
        (WebCore::SubresourceLoader::didCancel):
        * platform/cf/RetainPtr.h:
        (WebCore::):
        (WebCore::adoptCFReference):
        (WebCore::RetainPtr::RetainPtr):
        (WebCore::::adopt):
        * platform/network/ResourceError.cpp: Added.
        * platform/network/ResourceError.h: Added.
        (WebCore::ResourceError::ResourceError):
        (WebCore::ResourceError::domain):
        (WebCore::ResourceError::errorCode):
        (WebCore::ResourceError::failingURL):
        (WebCore::ResourceError::localizedDescription):
        (WebCore::ResourceError::unpackPlatformErrorIfNeeded):
        * platform/network/ResourceHandle.cpp:
        * platform/network/ResourceHandle.h:
        * platform/network/ResourceHandleClient.h:
        (WebCore::ResourceHandleClient::didFailWithError):
        * platform/network/cf/ResourceHandleCFNet.cpp:
        (WebCore::didFail):
        (WebCore::ResourceHandle::cancel):
        * platform/network/mac/ResourceErrorMac.mm: Added.
        (-[NSError WebCore]):
        * platform/network/mac/ResourceHandleMac.mm:
        (WebCore::ResourceHandle::reportError):
        * xml/xmlhttprequest.cpp:
        (WebCore::XMLHttpRequest::didFailWithError):
        (WebCore::XMLHttpRequest::didFinishLoading):
        * xml/xmlhttprequest.h:

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

19 files changed:
LayoutTests/http/tests/xmlhttprequest/cache-override.html
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/loader/icon/IconLoader.cpp
WebCore/loader/icon/IconLoader.h
WebCore/loader/loader.cpp
WebCore/loader/loader.h
WebCore/loader/mac/SubresourceLoaderMac.mm
WebCore/platform/cf/RetainPtr.h
WebCore/platform/network/ResourceError.cpp [new file with mode: 0644]
WebCore/platform/network/ResourceError.h [new file with mode: 0644]
WebCore/platform/network/ResourceHandle.cpp
WebCore/platform/network/ResourceHandle.h
WebCore/platform/network/ResourceHandleClient.h
WebCore/platform/network/cf/ResourceHandleCFNet.cpp
WebCore/platform/network/mac/ResourceErrorMac.mm [new file with mode: 0644]
WebCore/platform/network/mac/ResourceHandleMac.mm
WebCore/xml/xmlhttprequest.cpp
WebCore/xml/xmlhttprequest.h

index 38823914f6b6dad01ec65288af0124a9b083b88b..2722b56bf4b7fa7773397498301d87e88c136468 100644 (file)
@@ -110,7 +110,7 @@ Conditional XMLHttpRequest gets should pass 304 responses unchanged.</p>
             if (req.responseText == '<?xml version="1.0" encoding="windows-1251"?>\n<node>Проверка</node>\n')
                 log("async: Automatically cached response body is correct; status = " + req.status);
             else
-                log("async: Automatically cached response body is different from the expected one; status = " + req.status);
+                log("async: Automatically cached response body is different from the expected one; status = " + req.status + "; req.responseText='" + req.responseText + "' (expected '<?xml version=\"1.0\" encoding=\"windows-1251\"?>\n<node>Проверка</node>\n')");
 
             req = new XMLHttpRequest();
             req.onreadystatechange = processStateChange;
index dbbd53bd3d4ff69887485664c97f4a1385de8882..a6c973c222aa7a1b490f23028ef4e44c8cb951f0 100644 (file)
@@ -1,3 +1,50 @@
+2006-11-08  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Geoff.
+        
+        - added ResourceError class and didFailWithError client method
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/icon/IconLoader.cpp:
+        (WebCore::IconLoader::didFailWithError):
+        (WebCore::IconLoader::didFinishLoading):
+        * loader/icon/IconLoader.h:
+        * loader/loader.cpp:
+        (WebCore::Loader::receivedAllData):
+        (WebCore::Loader::didFailWithError):
+        * loader/loader.h:
+        * loader/mac/SubresourceLoaderMac.mm:
+        (WebCore::SubresourceLoader::didFail):
+        (WebCore::SubresourceLoader::didCancel):
+        * platform/cf/RetainPtr.h:
+        (WebCore::):
+        (WebCore::adoptCFReference):
+        (WebCore::RetainPtr::RetainPtr):
+        (WebCore::::adopt):
+        * platform/network/ResourceError.cpp: Added.
+        * platform/network/ResourceError.h: Added.
+        (WebCore::ResourceError::ResourceError):
+        (WebCore::ResourceError::domain):
+        (WebCore::ResourceError::errorCode):
+        (WebCore::ResourceError::failingURL):
+        (WebCore::ResourceError::localizedDescription):
+        (WebCore::ResourceError::unpackPlatformErrorIfNeeded):
+        * platform/network/ResourceHandle.cpp:
+        * platform/network/ResourceHandle.h:
+        * platform/network/ResourceHandleClient.h:
+        (WebCore::ResourceHandleClient::didFailWithError):
+        * platform/network/cf/ResourceHandleCFNet.cpp:
+        (WebCore::didFail):
+        (WebCore::ResourceHandle::cancel):
+        * platform/network/mac/ResourceErrorMac.mm: Added.
+        (-[NSError WebCore]):
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::ResourceHandle::reportError):
+        * xml/xmlhttprequest.cpp:
+        (WebCore::XMLHttpRequest::didFailWithError):
+        (WebCore::XMLHttpRequest::didFinishLoading):
+        * xml/xmlhttprequest.h:
+
 2006-11-08  Krzysztof Kowalczyk  <kkowalczyk@gmail.com>
 
         Reviewed by Maciej.
index b28ae5f841b6396bd7ebe0753df747d069c82802..8a5f2d36a51c41dd19d268489399b1fdc8d2769e 100644 (file)
                650E3F6A0AF6C168001FA3AD /* ResourceRequestMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 650E3F680AF6C168001FA3AD /* ResourceRequestMac.mm */; };
                650F53DC09D15DDA00C9B0C8 /* CSSGrammar.h in Headers */ = {isa = PBXBuildFile; fileRef = 650F53DB09D15DDA00C9B0C8 /* CSSGrammar.h */; };
                650F53DD09D15DDF00C9B0C8 /* CSSGrammar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6565814409D13043000E61D7 /* CSSGrammar.cpp */; };
+               651888880AFF3BF700164720 /* ResourceError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 651888860AFF3BF700164720 /* ResourceError.cpp */; };
+               651888890AFF3BF700164720 /* ResourceError.h in Headers */ = {isa = PBXBuildFile; fileRef = 651888870AFF3BF700164720 /* ResourceError.h */; };
+               6518888B0AFF3C1400164720 /* ResourceErrorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6518888A0AFF3C1400164720 /* ResourceErrorMac.mm */; };
                651B4D8509AC83370029F1EF /* DeprecatedStringList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 651B4D8309AC83370029F1EF /* DeprecatedStringList.cpp */; };
                651B4D8609AC83370029F1EF /* DeprecatedStringList.h in Headers */ = {isa = PBXBuildFile; fileRef = 651B4D8409AC83370029F1EF /* DeprecatedStringList.h */; };
                651B4D8F09AC859F0029F1EF /* DeprecatedStringListMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 651B4D8E09AC859F0029F1EF /* DeprecatedStringListMac.mm */; };
                650E3F670AF6C168001FA3AD /* ResourceRequestMac.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceRequestMac.h; sourceTree = "<group>"; };
                650E3F680AF6C168001FA3AD /* ResourceRequestMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceRequestMac.mm; sourceTree = "<group>"; };
                650F53DB09D15DDA00C9B0C8 /* CSSGrammar.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CSSGrammar.h; sourceTree = "<group>"; };
+               651888860AFF3BF700164720 /* ResourceError.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ResourceError.cpp; sourceTree = "<group>"; };
+               651888870AFF3BF700164720 /* ResourceError.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceError.h; sourceTree = "<group>"; };
+               6518888A0AFF3C1400164720 /* ResourceErrorMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceErrorMac.mm; sourceTree = "<group>"; };
                651B4D8309AC83370029F1EF /* DeprecatedStringList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DeprecatedStringList.cpp; sourceTree = "<group>"; };
                651B4D8409AC83370029F1EF /* DeprecatedStringList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DeprecatedStringList.h; sourceTree = "<group>"; };
                651B4D8E09AC859F0029F1EF /* DeprecatedStringListMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DeprecatedStringListMac.mm; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                65DADA170AFD878000CE53ED /* FormData.h */,
+                               651888860AFF3BF700164720 /* ResourceError.cpp */,
+                               651888870AFF3BF700164720 /* ResourceError.h */,
                                65DAD9FA0AFD86B400CE53ED /* FormData.cpp */,
                                656B84E70AEA1DAE00A095B4 /* mac */,
                                655A81BD0AEF67E6000975F0 /* HTTPHeaderMap.h */,
                656B84E70AEA1DAE00A095B4 /* mac */ = {
                        isa = PBXGroup;
                        children = (
+                               6518888A0AFF3C1400164720 /* ResourceErrorMac.mm */,
                                65DAD9FE0AFD86BF00CE53ED /* FormDataStreamMac.h */,
                                65DAD9FF0AFD86BF00CE53ED /* FormDataStreamMac.mm */,
                                656B84EA0AEA1DDA00A095B4 /* ResourceHandleMac.mm */,
                                14D824080AF93AEB0004F057 /* ChromeClient.h in Headers */,
                                65DADA000AFD86BF00CE53ED /* FormDataStreamMac.h in Headers */,
                                65DADA180AFD878000CE53ED /* FormData.h in Headers */,
+                               651888890AFF3BF700164720 /* ResourceError.h in Headers */,
                                148CF65E0B00561400A997FC /* Screen.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                                1402692D0AFE72D8005919E2 /* ScreenMac.mm in Sources */,
                                65DAD9FC0AFD86B400CE53ED /* FormData.cpp in Sources */,
                                65DADA010AFD86BF00CE53ED /* FormDataStreamMac.mm in Sources */,
+                               651888880AFF3BF700164720 /* ResourceError.cpp in Sources */,
+                               6518888B0AFF3C1400164720 /* ResourceErrorMac.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 1ae9332bb96c4f551ce71d710b65ef96b931a19d..5e7e5043c5a73daa83bbd5d3f74def9be0057827 100644 (file)
@@ -113,8 +113,14 @@ void IconLoader::didReceiveData(ResourceHandle*, const char* data, int size)
     m_buffer.append(data, size);
 }
 
+void IconLoader::didFailWithError(ResourceHandle* handle, const ResourceError&)
+{
+    finishLoading(handle->url());
+}
+
 void IconLoader::didFinishLoading(ResourceHandle* handle)
 {
+    ASSERT(handle == m_handle);
     finishLoading(handle->url());
 }
 
index 4f13d4205424951ba5919b801d0c7576641e01e7..c60a5db9c8f9b25899f86f37ce0013696a42f6ce 100644 (file)
@@ -50,6 +50,7 @@ private:
     virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
     virtual void didReceiveData(ResourceHandle*, const char*, int);
     virtual void didFinishLoading(ResourceHandle*);
+    virtual void didFailWithError(ResourceHandle*, const ResourceError&);
 
     void finishLoading(const KURL&);
     void clearLoadingState();
index d2ffb6275bf9ae178208ec895a378f7c8163e892..66d658b7a20e0deba9ec70cded99910ddadf2995 100644 (file)
@@ -103,18 +103,33 @@ void Loader::receivedAllData(ResourceHandle* job, PlatformData allData)
     CachedResource* object = req->cachedResource();
     DocLoader* docLoader = req->docLoader();
 
-    if (job->error() || job->isErrorPage()) {
-        docLoader->setLoadInProgress(true);
-        object->error();
-        docLoader->setLoadInProgress(false);
-        cache()->remove(object);
-    } else {
-        docLoader->setLoadInProgress(true);
-        object->data(req->buffer(), true);
-        object->setAllData(allData);
-        docLoader->setLoadInProgress(false);
-        object->finish();
-    }
+    docLoader->setLoadInProgress(true);
+    object->data(req->buffer(), true);
+    object->setAllData(allData);
+    docLoader->setLoadInProgress(false);
+    object->finish();
+
+    delete req;
+
+    servePendingRequests();
+}
+
+void Loader::didFailWithError(ResourceHandle* handle, const ResourceError& error)
+{
+    RequestMap::iterator i = m_requestsLoading.find(handle);
+    if (i == m_requestsLoading.end())
+        return;
+
+    Request* req = i->second;
+    m_requestsLoading.remove(i);
+
+    CachedResource* object = req->cachedResource();
+    DocLoader* docLoader = req->docLoader();
+
+    docLoader->setLoadInProgress(true);
+    object->error();
+    docLoader->setLoadInProgress(false);
+    cache()->remove(object);
 
     delete req;
 
index 22ccffd17b2d25b38eae3ecb3ab40abce3e72b5d..8610ffa69a1f83690ead23f6697344ae54bde503 100644 (file)
@@ -64,9 +64,10 @@ namespace WebCore {
 
     private:
         virtual void receivedResponse(ResourceHandle*, PlatformResponse);
-        virtual void didReceiveResponse(ResourceHandle* handle, const ResourceResponse& response);
+        virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
         virtual void didReceiveData(ResourceHandle*, const char*, int);
         virtual void receivedAllData(ResourceHandle*, PlatformData);
+        virtual void didFailWithError(ResourceHandle*, const ResourceError&);
 
         void servePendingRequests();
 
index c758fcd3ae009621cdd2962e173dcd44a375ffab..d9aef283095fcf6178f5ba0725ac047232010c6a 100644 (file)
@@ -183,7 +183,7 @@ void SubresourceLoader::didFail(NSError *error)
     RefPtr<SubresourceLoader> protect(this);
 
     if (RefPtr<ResourceHandle> handle = m_handle.release())
-        handle->reportError();
+        handle->reportError(error);
 
     if (cancelled())
         return;
@@ -199,7 +199,7 @@ void SubresourceLoader::didCancel(NSError *error)
     RefPtr<SubresourceLoader> protect(this);
     
     if (RefPtr<ResourceHandle> handle = m_handle.release())
-        handle->reportError();
+        handle->reportError(error);
 
     if (cancelled())
         return;
index b9153c7e005852f9315ab9e10cab60e49090294e..a352906f6c06f4dd27ec11b65b3fb08f1c1a089d 100644 (file)
@@ -39,6 +39,20 @@ namespace WebCore {
     // Unlike most most of our smart pointers, RetainPtr can take either the pointer type or the pointed-to type,
     // so both RetainPtr<NSDictionary> and RetainPtr<CFDictionaryRef> will work.
 
+    enum AdoptTag { Adopt };
+    
+    template <typename T> inline void adoptCFReference(T* ptr)
+    {
+    }
+
+#ifdef __OBJC__
+    inline void adoptCFReference(id ptr)
+    {
+        CFRetain(ptr);
+        [ptr release];
+    }
+#endif
+
     template <typename T> class RetainPtr
     {
     public:
@@ -48,6 +62,9 @@ namespace WebCore {
 
         RetainPtr() : m_ptr(0) {}
         RetainPtr(PtrType ptr) : m_ptr(ptr) { if (ptr) CFRetain(ptr); }
+
+        RetainPtr(AdoptTag, PtrType ptr) : m_ptr(ptr) { adoptCFReference(ptr); }
+
         RetainPtr(const RetainPtr& o) : m_ptr(o.m_ptr) { if (PtrType ptr = m_ptr) CFRetain(ptr); }
 
         ~RetainPtr() { if (PtrType ptr = m_ptr) CFRelease(ptr); }
@@ -70,6 +87,8 @@ namespace WebCore {
         RetainPtr& operator=(PtrType);
         template <typename U> RetainPtr& operator=(U*);
 
+        void adopt(PtrType);
+
         void swap(RetainPtr&);
 
     private:
@@ -111,6 +130,16 @@ namespace WebCore {
         return *this;
     }
 
+    template <typename T> inline void RetainPtr<T>::adopt(PtrType optr)
+    {
+        if (optr)
+            adoptCFReference(optr);
+        PtrType ptr = m_ptr;
+        m_ptr = optr;
+        if (ptr)
+            CFRelease(ptr);
+    }
+
     template <typename T> template <typename U> inline RetainPtr<T>& RetainPtr<T>::operator=(U* optr)
     {
         if (optr)
diff --git a/WebCore/platform/network/ResourceError.cpp b/WebCore/platform/network/ResourceError.cpp
new file mode 100644 (file)
index 0000000..13be3f2
--- /dev/null
@@ -0,0 +1,29 @@
+// -*- 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 "ResourceError.h"
+
diff --git a/WebCore/platform/network/ResourceError.h b/WebCore/platform/network/ResourceError.h
new file mode 100644 (file)
index 0000000..013f77f
--- /dev/null
@@ -0,0 +1,117 @@
+// -*- 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 ResourceError_H_
+#define ResourceError_H_
+
+#include "PlatformString.h"
+
+#if PLATFORM(MAC)
+#include "RetainPtr.h"
+#endif
+
+#ifdef __OBJC__
+@class NSError;
+#else
+class NSError;
+#endif
+
+namespace WebCore {
+
+    class ResourceError {
+    public:
+        ResourceError()
+            : m_errorCode(0)
+#if PLATFORM(MAC)
+            , m_dataIsUpToDate(true)
+#endif
+        {
+        }
+
+        ResourceError(const String& domain, int errorCode, const String& failingURL, const String& localizedDescription)
+            : m_domain(domain)
+            , m_errorCode(errorCode)
+            , m_failingURL(failingURL)
+            , m_localizedDescription(localizedDescription)
+#if PLATFORM(MAC)
+            , m_dataIsUpToDate(true)
+#endif
+        {
+        }
+
+#if PLATFORM(MAC)
+        ResourceError(NSError* error)
+            : m_dataIsUpToDate(false)
+            , m_platformError(error)
+        {
+        }
+#endif
+        
+#if 0
+        static const String CocoaErrorDomain;
+        static const String POSIXDomain;
+        static const String OSStatusDomain;
+        static const String MachDomain;
+        static const String WebKitDomain;
+#endif
+        
+        const String& domain() { unpackPlatformErrorIfNeeded(); return m_domain; }
+        int errorCode() { unpackPlatformErrorIfNeeded(); return m_errorCode; }
+        const String& failingURL() { unpackPlatformErrorIfNeeded(); return m_failingURL; }
+        const String& localizedDescription() { unpackPlatformErrorIfNeeded(); return m_localizedDescription; }
+
+#if PLATFORM(MAC)
+        operator NSError*() const;
+#endif
+
+    private:
+        void unpackPlatformErrorIfNeeded()
+        {
+#if PLATFORM(MAC)
+            if (!m_dataIsUpToDate)
+                unpackPlatformError();
+#endif
+        }
+
+#if PLATFORM(MAC)
+        void unpackPlatformError();
+#endif
+
+        String m_domain;
+        int m_errorCode;
+        String m_failingURL;
+        String m_localizedDescription;
+#if PLATFORM(MAC)
+        bool m_dataIsUpToDate;
+        mutable RetainPtr<NSError> m_platformError;
+#endif
+
+};
+
+} // namespace WebCore
+
+#endif // ResourceError_h_
index c40cc93dac49111caf94493d676c41bf7f3181f8..7690e4fffd67e812f526a7a5d4cce7e36015f142 100644 (file)
@@ -47,21 +47,6 @@ PassRefPtr<ResourceHandle> ResourceHandle::create(const ResourceRequest& request
     return 0;
 }
 
-bool ResourceHandle::isErrorPage() const
-{
-    return d->status != 0;
-}
-
-int ResourceHandle::error() const
-{
-    return d->status;
-}
-
-void ResourceHandle::setError(int e)
-{
-    d->status = e;
-}
-
 void ResourceHandle::kill()
 {
     if (d->m_loading){
index 15aba174b8ea62052a1ceca71769d274f3342dcb..6acce61d0e395a0eefae6f87c7f5cc1156940dcf 100644 (file)
@@ -45,9 +45,11 @@ typedef LONG_PTR LRESULT;
 #ifdef __OBJC__
 @class NSURLRequest;
 @class NSURLResponse;
+@class NSError;
 #else
 class NSURLRequest;
 class NSURLResponse;
+class NSError;
 #endif
 #endif
 
@@ -72,18 +74,13 @@ public:
 
     ~ResourceHandle();
 
-    int error() const;
-    void setError(int);
-    String errorText() const;
-    bool isErrorPage() const;
-    
     void kill();
 
 #if PLATFORM(MAC)
     NSURLRequest *willSendRequest(NSURLRequest *, NSURLResponse *);
     void addData(NSData *);
     void finishJobAndHandle(NSData *);
-    void reportError();
+    void reportError(NSError* error);
 #endif
 
 #if USE(WININET)
index e648bfd615ddd30e7eb2293bead1980b3d5182e2..b11bcc8182a17557ec05a9100e150af41b522735 100644 (file)
@@ -74,6 +74,7 @@ namespace WebCore {
 
     class KURL;
     class ResourceHandle;
+    class ResourceError;
     class ResourceRequest;
     class ResourceResponse;
 
@@ -90,7 +91,7 @@ namespace WebCore {
         virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&) { }
         virtual void didReceiveData(ResourceHandle*, const char*, int) { }
         virtual void didFinishLoading(ResourceHandle*) { }
-        // void didFailWithError(ResourceError*) { }
+        virtual void didFailWithError(ResourceHandle*, const ResourceError&) { }
 
         // cached response may be modified
         // void willCacheResponse(ResourceHandle*, CachedResourceResponse&) { }
index bd97300e14db4c9b51ce5cc40ab77f57f8537040..552739537ba9791eef561a4a8c7504d84b2b4b05 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "DocLoader.h"
 #include "Frame.h"
+#include "ResourceError.h"
 #include "FrameLoader.h"
 #include "ResourceHandle.h"
 #include "ResourceHandleInternal.h"
@@ -119,7 +120,7 @@ void didFinishLoading(CFURLConnectionRef conn, const void* clientInfo)
 
 void didFail(CFURLConnectionRef conn, CFStreamError error, const void* clientInfo) 
 {
-    ResourceHandle* job = (ResourceHandle*)clientInfo;
+    ResourceHandle* handle = (ResourceHandle*)clientInfo;
 
 #if defined(LOG_RESOURCELOADER_EVENTS)
     CFStringRef str = CFStringCreateWithFormat(0, 0, CFSTR("didFail(conn=%p, job = %p, error = {%d, %d})\n"), conn, job, error.domain, error.error);
@@ -127,10 +128,20 @@ void didFail(CFURLConnectionRef conn, CFStreamError error, const void* clientInf
     CFRelease(str);
 #endif
 
-    job->setError(1);
-    job->client()->receivedAllData(job, 0);
-    job->client()->didFinishLoading(job);
-    job->kill();
+    String domain;
+    switch(error.domain) {
+    case kCFStreamErrorDomainPOSIX:
+        domain = "NSPOSIXErrorDomain";
+        break;
+    case kCFStreamErrorDomainMacOSStatus:
+        domain = "NSOSStatusErrorDomain";
+        break;
+    }
+
+    // FIXME: we'd really like to include a failing URL and a localized description but you can't
+    // get a CFErrorRef out of an NSURLConnection, only a CFStreamError
+    handle->client()->didFailWithError(handle, ResourceError(domain, error.error, String(), String()));
+    handle->kill();
 }
 
 CFCachedURLResponseRef willCacheResponse(CFURLConnectionRef conn, CFCachedURLResponseRef cachedResponse, const void* clientInfo) 
@@ -269,10 +280,8 @@ void ResourceHandle::cancel()
         d->m_connection = 0;
     }
 
-    // Copied directly from ResourceHandleWin.cpp
-    setError(1);
-    d->m_client->receivedAllData(this, 0);
-    d->m_client->didFinishLoading(this);
+    // FIXME: need real cancel error
+    d->m_client->didFailWithError(this, ResourceError());
 }
 
 } // namespace WebCore
diff --git a/WebCore/platform/network/mac/ResourceErrorMac.mm b/WebCore/platform/network/mac/ResourceErrorMac.mm
new file mode 100644 (file)
index 0000000..d9cc7c5
--- /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. 
+ */
+
+#import "config.h"
+#import "KURL.h"
+#import "ResourceError.h"
+#import <Foundation/Foundation.h>
+
+@interface NSError (WebExtras)
+- (NSString *)_web_localizedDescription;
+@end
+
+namespace WebCore {
+
+void ResourceError::unpackPlatformError()
+{
+    m_domain = [m_platformError.get() domain];
+    m_errorCode = [m_platformError.get() code];
+
+    NSString* failingURLString = [[m_platformError.get() userInfo] valueForKey:@"NSErrorFailingURLStringKey"];
+    if (!failingURLString)
+        failingURLString = [[[m_platformError.get() userInfo] valueForKey:@"NSErrorFailingURLKey"] absoluteString];
+        
+    m_localizedDescription = [m_platformError.get() _web_localizedDescription];
+
+    m_dataIsUpToDate = true;
+}
+
+ResourceError::operator NSError*() const
+{
+    if (!m_platformError) {
+        RetainPtr<NSMutableDictionary> userInfo(Adopt, [[NSMutableDictionary alloc] init]);
+
+        if (!m_localizedDescription.isEmpty())
+            [userInfo.get() setValue:m_localizedDescription forKey:NSLocalizedDescriptionKey];
+
+        if (!m_failingURL.isEmpty()) {
+            [userInfo.get() setValue:m_failingURL forKey:@"NSErrorFailingURLStringKey"];
+            [userInfo.get() setValue:KURL(m_failingURL.deprecatedString()).getNSURL() forKey:@"NSErrorFailingURLKey"];
+        }
+
+        m_platformError.adopt([[NSError alloc] initWithDomain:m_domain code:m_errorCode userInfo:userInfo.get()]);
+    }
+
+    return m_platformError.get();
+}
+
+} // namespace WebCore
+
index b325e15f412026bdbbf3e50caf4b3466da6fed8c..297f7b55bcb35956c43bc972e9c741e7076b23e1 100644 (file)
@@ -31,6 +31,7 @@
 #import "DocLoader.h"
 #import "FrameLoader.h"
 #import "FrameMac.h"
+#import "ResourceError.h"
 #import "ResourceRequestMac.h"
 #import "ResourceResponse.h"
 #import "ResourceResponseMac.h"
@@ -130,10 +131,11 @@ void ResourceHandle::finishJobAndHandle(NSData *data)
     kill();
 }
 
-void ResourceHandle::reportError()
+void ResourceHandle::reportError(NSError* error)
 {
-    setError(1);
-    finishJobAndHandle(nil);
+    if (ResourceHandleClient* c = client())
+        c->didFailWithError(this, error);
+    kill();
 }
 
 } // namespace WebCore
index 2876305e08ec95ed8971bc60b800dbff0e1e8089..49a17425420159f82b2079f43b2e6f8cb7d517b5 100644 (file)
@@ -483,12 +483,17 @@ void XMLHttpRequest::processSyncLoadResults(const Vector<char>& data, const Reso
     didFinishLoading(0);
 }
 
-void XMLHttpRequest::didFinishLoading(ResourceHandle* loader)
+void XMLHttpRequest::didFailWithError(ResourceHandle* handle, const ResourceError&)
+{
+    didFinishLoading(handle);
+}
+
+void XMLHttpRequest::didFinishLoading(ResourceHandle* handle)
 {
     if (m_aborted)
         return;
         
-    ASSERT(loader == m_loader);
+    ASSERT(handle == m_loader);
 
     if (m_state < Sent)
         changeState(Sent);
index f2f17b740ed39b5436c9c5d7f6cbb600179423f4..1e510f1191116e36486acd3abdcc1c37c3ff8904 100644 (file)
@@ -85,6 +85,7 @@ private:
     virtual void willSendRequest(ResourceHandle*, ResourceRequest& request, const ResourceResponse& redirectResponse);
     virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
     virtual void didReceiveData(ResourceHandle*, const char* data, int size);
+    virtual void didFailWithError(ResourceHandle*, const ResourceError&);
     virtual void didFinishLoading(ResourceHandle*);
 
     void processSyncLoadResults(const Vector<char>& data, const ResourceResponse&);