[Curl] Move error generation task into ResourceError
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Sep 2017 23:02:23 +0000 (23:02 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Sep 2017 23:02:23 +0000 (23:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176963

Patch by Basuke Suzuki <Basuke.Suzuki@sony.com> on 2017-09-18
Reviewed by Alex Christensen.

* platform/Curl.cmake:
* platform/network/curl/CurlContext.cpp:
(WebCore::CurlHandle::errorDescription):
(WebCore::CurlHandle::errorDescription const):
* platform/network/curl/CurlContext.h:
* platform/network/curl/ResourceError.h:
(WebCore::ResourceError::setSslErrors):
(WebCore::ResourceError::hasSSLConnectError const): Deleted.
(WebCore::ResourceError::doPlatformIsolatedCopy): Deleted.
* platform/network/curl/ResourceErrorCurl.cpp: Added.
(WebCore::ResourceError::httpError):
(WebCore::ResourceError::sslError):
(WebCore::ResourceError::hasSSLConnectError const):
(WebCore::ResourceError::doPlatformIsolatedCopy):
(WebCore::ResourceError::platformCompare):
* platform/network/curl/ResourceHandleCurlDelegate.cpp:
(WebCore::ResourceHandleCurlDelegate::notifyFail):
(WebCore::ResourceHandleCurlDelegate::didFail):
* platform/network/curl/ResourceHandleCurlDelegate.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/Curl.cmake
Source/WebCore/platform/network/curl/CurlContext.cpp
Source/WebCore/platform/network/curl/CurlContext.h
Source/WebCore/platform/network/curl/ResourceError.h
Source/WebCore/platform/network/curl/ResourceErrorCurl.cpp [new file with mode: 0644]
Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp
Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.h

index 8aa5ee0..26f9691 100644 (file)
@@ -1,3 +1,30 @@
+2017-09-18  Basuke Suzuki  <Basuke.Suzuki@sony.com>
+
+        [Curl] Move error generation task into ResourceError
+        https://bugs.webkit.org/show_bug.cgi?id=176963
+
+        Reviewed by Alex Christensen.
+
+        * platform/Curl.cmake:
+        * platform/network/curl/CurlContext.cpp:
+        (WebCore::CurlHandle::errorDescription):
+        (WebCore::CurlHandle::errorDescription const):
+        * platform/network/curl/CurlContext.h:
+        * platform/network/curl/ResourceError.h:
+        (WebCore::ResourceError::setSslErrors):
+        (WebCore::ResourceError::hasSSLConnectError const): Deleted.
+        (WebCore::ResourceError::doPlatformIsolatedCopy): Deleted.
+        * platform/network/curl/ResourceErrorCurl.cpp: Added.
+        (WebCore::ResourceError::httpError):
+        (WebCore::ResourceError::sslError):
+        (WebCore::ResourceError::hasSSLConnectError const):
+        (WebCore::ResourceError::doPlatformIsolatedCopy):
+        (WebCore::ResourceError::platformCompare):
+        * platform/network/curl/ResourceHandleCurlDelegate.cpp:
+        (WebCore::ResourceHandleCurlDelegate::notifyFail):
+        (WebCore::ResourceHandleCurlDelegate::didFail):
+        * platform/network/curl/ResourceHandleCurlDelegate.h:
+
 2017-09-18  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r222170.
index f2f6308..0795a51 100644 (file)
@@ -16,6 +16,7 @@ list(APPEND WebCore_SOURCES
     platform/network/curl/FormDataStreamCurl.cpp
     platform/network/curl/MultipartHandle.cpp
     platform/network/curl/ProxyServerCurl.cpp
+    platform/network/curl/ResourceErrorCurl.cpp
     platform/network/curl/ResourceHandleCurl.cpp
     platform/network/curl/ResourceHandleCurlDelegate.cpp
     platform/network/curl/ResourceResponseCurl.cpp
index 0f5d48d..89e4230 100644 (file)
@@ -77,8 +77,6 @@ static CString cookieJarPath()
 
 // CurlContext -------------------------------------------------------------------
 
-const char* const CurlContext::errorDomain = "CurlErrorDomain";
-
 CurlContext::CurlContext()
 : m_cookieJarFileName { cookieJarPath() }
 , m_cookieJar { std::make_unique<CookieJarCurlFileSystem>() }
@@ -265,9 +263,14 @@ CurlHandle::~CurlHandle()
     curl_easy_cleanup(m_handle);
 }
 
+const String CurlHandle::errorDescription(CURLcode errorCode)
+{
+    return String(curl_easy_strerror(errorCode));
+}
+
 const String CurlHandle::errorDescription() const
 {
-    return String(curl_easy_strerror(m_errorCode));
+    return errorDescription(m_errorCode);
 }
 
 void CurlHandle::initialize()
index 14e98a0..4ddcfb1 100644 (file)
@@ -104,8 +104,6 @@ public:
         const String url() const;
     };
 
-    static const char* const errorDomain;
-
     static CurlContext& singleton()
     {
         static CurlContext shared;
@@ -229,6 +227,7 @@ public:
     CURLcode errorCode() const { return m_errorCode; }
     void setErrorCode(CURLcode errorCode) { m_errorCode = errorCode; }
 
+    static const String errorDescription(CURLcode);
     const String errorDescription() const;
 
     void enableShareHandle();
index bbe956f..64c1309 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2006 Apple Inc.  All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #pragma once
 
-#include "CurlContext.h"
 #include "ResourceErrorBase.h"
 
 namespace WebCore {
 
 class ResourceError : public ResourceErrorBase {
     friend class ResourceErrorBase;
+
 public:
     ResourceError(Type type = Type::Null)
         : ResourceErrorBase(type)
@@ -43,17 +44,19 @@ public:
     {
     }
 
-    ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, unsigned sslErrors, Type type = Type::General)
-        : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription, type)
-        , m_sslErrors(sslErrors)
-    {
-    }
+    static ResourceError httpError(int errorCode, const URL& failingURL);
+    static ResourceError sslError(int errorCode, unsigned sslErrors, const URL& failingURL);
 
     unsigned sslErrors() const { return m_sslErrors; }
-    bool hasSSLConnectError() const { return errorCode() == CURLE_SSL_CONNECT_ERROR; }
+    void setSslErrors(unsigned sslErrors) { m_sslErrors = sslErrors; }
+    bool hasSSLConnectError() const;
+
+    static bool platformCompare(const ResourceError& a, const ResourceError& b);
 
 private:
-    void doPlatformIsolatedCopy(const ResourceError&) { }
+    void doPlatformIsolatedCopy(const ResourceError&);
+
+    static const char* const curlErrorDomain;
 
     unsigned m_sslErrors { 0 };
 };
diff --git a/Source/WebCore/platform/network/curl/ResourceErrorCurl.cpp b/Source/WebCore/platform/network/curl/ResourceErrorCurl.cpp
new file mode 100644 (file)
index 0000000..e70057d
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 "ResourceError.h"
+
+#if USE(CURL)
+
+#include "CurlContext.h"
+
+namespace WebCore {
+
+const char* const ResourceError::curlErrorDomain = "CurlErrorDomain";
+
+ResourceError ResourceError::httpError(int errorCode, const URL& failingURL)
+{
+    return ResourceError(curlErrorDomain, errorCode, failingURL, CurlHandle::errorDescription(static_cast<CURLcode>(errorCode)));
+}
+
+ResourceError ResourceError::sslError(int errorCode, unsigned sslErrors, const URL& failingURL)
+{
+    ResourceError resourceError = ResourceError::httpError(errorCode, failingURL);
+    resourceError.setSslErrors(sslErrors);
+    return resourceError;
+}
+
+bool ResourceError::hasSSLConnectError() const
+{
+    return errorCode() == CURLE_SSL_CONNECT_ERROR;
+}
+
+void ResourceError::doPlatformIsolatedCopy(const ResourceError& other)
+{
+    m_sslErrors = other.m_sslErrors;
+}
+
+bool ResourceError::platformCompare(const ResourceError& a, const ResourceError& b)
+{
+    return a.sslErrors() == b.sslErrors();
+}
+
+} // namespace WebCore
+
+#endif
index 3d28616..f506ede 100644 (file)
@@ -284,19 +284,17 @@ void ResourceHandleCurlDelegate::notifyFinish()
 
 void ResourceHandleCurlDelegate::notifyFail()
 {
-    String domain = CurlContext::errorDomain;
-    int errorCode = m_curlHandle.errorCode();
-    URL failingURL = m_curlHandle.getEffectiveURL();
-    String errorDescription = m_curlHandle.errorDescription();
-    unsigned sslErrors = m_sslVerifier.sslErrors();
+    ResourceError resourceError = ResourceError::httpError(m_curlHandle.errorCode(), m_firstRequest.url());
+    if (m_sslVerifier.sslErrors())
+        resourceError.setSslErrors(m_sslVerifier.sslErrors());
 
     if (isMainThread())
-        didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
+        didFail(resourceError);
     else {
-        callOnMainThread([protectedThis = makeRef(*this), domain = domain.isolatedCopy(), errorCode, failingURL = failingURL.isolatedCopy(), errorDescription = errorDescription.isolatedCopy(), sslErrors] {
+        callOnMainThread([protectedThis = makeRef(*this), error = resourceError.isolatedCopy()] {
             if (!protectedThis->m_handle)
                 return;
-            protectedThis->didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
+            protectedThis->didFail(error);
         });
     }
 }
@@ -525,14 +523,14 @@ void ResourceHandleCurlDelegate::didFinish(NetworkLoadMetrics networkLoadMetrics
     }
 }
 
-void ResourceHandleCurlDelegate::didFail(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, unsigned sslErrors)
+void ResourceHandleCurlDelegate::didFail(const ResourceError& resourceError)
 {
     if (!m_handle)
         return;
 
     if (m_handle->client()) {
         CurlCacheManager::getInstance().didFail(*m_handle);
-        m_handle->client()->didFail(m_handle, ResourceError(domain, errorCode, failingURL, localizedDescription, sslErrors));
+        m_handle->client()->didFail(m_handle, resourceError);
     }
 }
 
index 7fe2e09..09958b1 100644 (file)
@@ -81,7 +81,7 @@ private:
     void prepareSendData(char*, size_t blockSize, size_t numberOfBlocks);
 
     void didFinish(NetworkLoadMetrics);
-    void didFail(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, unsigned sslErrors);
+    void didFail(const ResourceError&);
 
     void handleDataURL();