Title: [221346] releases/WebKitGTK/webkit-2.18/Source
Revision
221346
Author
carlo...@webkit.org
Date
2017-08-30 00:58:39 -0700 (Wed, 30 Aug 2017)

Log Message

Merge r221059 - Introduce a new CompletionHandler type and use it for NetworkDataTaskClient's completion handlers to help catch bugs
https://bugs.webkit.org/show_bug.cgi?id=175832

Reviewed by Alex Christensen.

Source/WebKit:

Use new CompletionHandler type for NetworkDataTaskClient's completion handlers to help catch bugs.
It actually already found a bug in our HTTP 0.9 error handling which is fixed in this patch
as well.

* NetworkProcess/NetworkDataTask.cpp:
(WebKit::NetworkDataTask::didReceiveResponse):
* NetworkProcess/NetworkDataTask.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::tryPasswordBasedAuthentication):
* Shared/Authentication/AuthenticationManager.cpp:
(WebKit::AuthenticationManager::tryUseCertificateInfoForChallenge):
* Shared/Authentication/AuthenticationManager.h:
* Shared/Authentication/mac/AuthenticationManager.mac.mm:
(WebKit::AuthenticationManager::tryUseCertificateInfoForChallenge):

Source/WTF:

Introduce a new CompletionHandler type which wraps a WTF::Function and ensures via assertions
that the function is always called once and only once.

* WTF.xcodeproj/project.pbxproj:
* wtf/CompletionHandler.h: Added.
(WTF::CompletionHandler<Out):

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.18/Source/WTF/ChangeLog (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WTF/ChangeLog	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WTF/ChangeLog	2017-08-30 07:58:39 UTC (rev 221346)
@@ -1,3 +1,17 @@
+2017-08-22  Chris Dumez  <cdu...@apple.com>
+
+        Introduce a new CompletionHandler type and use it for NetworkDataTaskClient's completion handlers to help catch bugs
+        https://bugs.webkit.org/show_bug.cgi?id=175832
+
+        Reviewed by Alex Christensen.
+
+        Introduce a new CompletionHandler type which wraps a WTF::Function and ensures via assertions
+        that the function is always called once and only once.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CompletionHandler.h: Added.
+        (WTF::CompletionHandler<Out):
+
 2017-08-20  Sam Weinig  <s...@webkit.org>
 
         StringView could use a function to strip leading/trailing characters without allocation

Added: releases/WebKitGTK/webkit-2.18/Source/WTF/wtf/CompletionHandler.h (0 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WTF/wtf/CompletionHandler.h	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.18/Source/WTF/wtf/CompletionHandler.h	2017-08-30 07:58:39 UTC (rev 221346)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017 Apple 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 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.
+ */
+
+#pragma once
+
+#include "Function.h"
+
+namespace WTF {
+
+template<typename> class CompletionHandler;
+
+// Wraps a WTF::Function to make sure it is always called once and only once.
+template <typename Out, typename... In>
+class CompletionHandler<Out(In...)> {
+public:
+    CompletionHandler() = default;
+
+    template<typename CallableType, class = typename std::enable_if<std::is_rvalue_reference<CallableType&&>::value>::type>
+    CompletionHandler(CallableType&& callable)
+        : m_function(WTFMove(callable))
+    {
+    }
+
+    CompletionHandler(CompletionHandler&&) = default;
+    CompletionHandler& operator=(CompletionHandler&&) = default;
+
+    ~CompletionHandler()
+    {
+        ASSERT_WITH_MESSAGE(!m_function, "Completion handler should always be called");
+    }
+
+    explicit operator bool() const { return !!m_function; }
+
+    Out operator()(In... in)
+    {
+        ASSERT_WITH_MESSAGE(m_function, "Completion handler should not be called more than once");
+        auto function = WTFMove(m_function);
+        return function(std::forward<In>(in)...);
+    }
+
+private:
+    WTF::Function<Out(In...)> m_function;
+};
+
+} // namespace WTF
+
+using WTF::CompletionHandler;

Modified: releases/WebKitGTK/webkit-2.18/Source/WebKit/ChangeLog (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WebKit/ChangeLog	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WebKit/ChangeLog	2017-08-30 07:58:39 UTC (rev 221346)
@@ -1,3 +1,26 @@
+2017-08-22  Chris Dumez  <cdu...@apple.com>
+
+        Introduce a new CompletionHandler type and use it for NetworkDataTaskClient's completion handlers to help catch bugs
+        https://bugs.webkit.org/show_bug.cgi?id=175832
+
+        Reviewed by Alex Christensen.
+
+        Use new CompletionHandler type for NetworkDataTaskClient's completion handlers to help catch bugs.
+        It actually already found a bug in our HTTP 0.9 error handling which is fixed in this patch
+        as well.
+
+        * NetworkProcess/NetworkDataTask.cpp:
+        (WebKit::NetworkDataTask::didReceiveResponse):
+        * NetworkProcess/NetworkDataTask.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTaskCocoa::tryPasswordBasedAuthentication):
+        * Shared/Authentication/AuthenticationManager.cpp:
+        (WebKit::AuthenticationManager::tryUseCertificateInfoForChallenge):
+        * Shared/Authentication/AuthenticationManager.h:
+        * Shared/Authentication/mac/AuthenticationManager.mac.mm:
+        (WebKit::AuthenticationManager::tryUseCertificateInfoForChallenge):
+
 2017-08-22  Zan Dobersek  <zdober...@igalia.com>
 
         [GTK][WPE] Rename StorageProcessMainGtk.cpp to StorageProcessMainGLib.cpp

Modified: releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/NetworkDataTask.cpp (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/NetworkDataTask.cpp	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/NetworkDataTask.cpp	2017-08-30 07:58:39 UTC (rev 221346)
@@ -103,6 +103,7 @@
         auto url = ""
         std::optional<uint16_t> port = url.port();
         if (port && !isDefaultPortForProtocol(port.value(), url.protocol())) {
+            completionHandler({ });
             cancel();
             m_client->didCompleteWithError({ String(), 0, url, "Cancelled load from '" + url.stringCenterEllipsizedToLength() + "' because it is using HTTP/0.9." });
             return;

Modified: releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/NetworkDataTask.h (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/NetworkDataTask.h	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/NetworkDataTask.h	2017-08-30 07:58:39 UTC (rev 221346)
@@ -36,7 +36,7 @@
 #include <WebCore/ResourceLoaderOptions.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/Timer.h>
-#include <wtf/Function.h>
+#include <wtf/CompletionHandler.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -54,9 +54,9 @@
 class PendingDownload;
 enum class AuthenticationChallengeDisposition;
 
-typedef Function<void(const WebCore::ResourceRequest&)> RedirectCompletionHandler;
-typedef Function<void(AuthenticationChallengeDisposition, const WebCore::Credential&)> ChallengeCompletionHandler;
-typedef Function<void(WebCore::PolicyAction)> ResponseCompletionHandler;
+using RedirectCompletionHandler = CompletionHandler<void(const WebCore::ResourceRequest&)>;
+using ChallengeCompletionHandler = CompletionHandler<void(AuthenticationChallengeDisposition, const WebCore::Credential&)>;
+using ResponseCompletionHandler = CompletionHandler<void(WebCore::PolicyAction)>;
 
 class NetworkDataTaskClient {
 public:

Modified: releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.h	2017-08-30 07:58:39 UTC (rev 221346)
@@ -73,7 +73,7 @@
 private:
     NetworkDataTaskCocoa(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::StoredCredentials, WebCore::ContentSniffingPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
 
-    bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, const ChallengeCompletionHandler&);
+    bool tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge&, ChallengeCompletionHandler&);
 
     RefPtr<SandboxExtension> m_sandboxExtension;
     RetainPtr<NSURLSessionDataTask> m_task;

Modified: releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2017-08-30 07:58:39 UTC (rev 221346)
@@ -254,7 +254,7 @@
         WebCore::deleteFile(filename);
 }
 
-bool NetworkDataTaskCocoa::tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge& challenge, const ChallengeCompletionHandler& completionHandler)
+bool NetworkDataTaskCocoa::tryPasswordBasedAuthentication(const WebCore::AuthenticationChallenge& challenge, ChallengeCompletionHandler& completionHandler)
 {
     if (!challenge.protectionSpace().isPasswordBased())
         return false;

Modified: releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/AuthenticationManager.cpp (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/AuthenticationManager.cpp	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/AuthenticationManager.cpp	2017-08-30 07:58:39 UTC (rev 221346)
@@ -189,7 +189,7 @@
 
 // Currently, only Mac knows how to respond to authentication challenges with certificate info.
 #if !HAVE(SEC_IDENTITY)
-bool AuthenticationManager::tryUseCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const CertificateInfo&, const ChallengeCompletionHandler&)
+bool AuthenticationManager::tryUseCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const CertificateInfo&, ChallengeCompletionHandler&)
 {
     return false;
 }

Modified: releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/AuthenticationManager.h (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/AuthenticationManager.h	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/AuthenticationManager.h	2017-08-30 07:58:39 UTC (rev 221346)
@@ -30,8 +30,8 @@
 #include "NetworkProcessSupplement.h"
 #include "WebProcessSupplement.h"
 #include <WebCore/AuthenticationChallenge.h>
+#include <wtf/CompletionHandler.h>
 #include <wtf/Forward.h>
-#include <wtf/Function.h>
 #include <wtf/HashMap.h>
 
 namespace WebCore {
@@ -54,7 +54,7 @@
     Cancel,
     RejectProtectionSpace
 };
-typedef Function<void(AuthenticationChallengeDisposition, const WebCore::Credential&)> ChallengeCompletionHandler;
+using ChallengeCompletionHandler = CompletionHandler<void(AuthenticationChallengeDisposition, const WebCore::Credential&)>;
 
 class AuthenticationManager : public WebProcessSupplement, public NetworkProcessSupplement, public IPC::MessageReceiver {
     WTF_MAKE_NONCOPYABLE(AuthenticationManager);
@@ -105,7 +105,7 @@
     // IPC::MessageReceiver
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
 
-    bool tryUseCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const WebCore::CertificateInfo&, const ChallengeCompletionHandler&);
+    bool tryUseCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const WebCore::CertificateInfo&, ChallengeCompletionHandler&);
 
     uint64_t addChallengeToChallengeMap(Challenge&&);
     bool shouldCoalesceChallenge(uint64_t pageID, uint64_t challengeID, const WebCore::AuthenticationChallenge&) const;

Modified: releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/mac/AuthenticationManager.mac.mm (221345 => 221346)


--- releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/mac/AuthenticationManager.mac.mm	2017-08-30 07:31:32 UTC (rev 221345)
+++ releases/WebKitGTK/webkit-2.18/Source/WebKit/Shared/Authentication/mac/AuthenticationManager.mac.mm	2017-08-30 07:58:39 UTC (rev 221346)
@@ -69,7 +69,7 @@
 }
 
 // FIXME: This function creates an identity from a certificate, which should not be needed. We should pass an identity over IPC (as we do on iOS).
-bool AuthenticationManager::tryUseCertificateInfoForChallenge(const AuthenticationChallenge& challenge, const CertificateInfo& certificateInfo, const ChallengeCompletionHandler& completionHandler)
+bool AuthenticationManager::tryUseCertificateInfoForChallenge(const AuthenticationChallenge& challenge, const CertificateInfo& certificateInfo, ChallengeCompletionHandler& completionHandler)
 {
     if (certificateInfo.isEmpty())
         return false;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to