Use completion handlers for ResourceHandleClient::canAuthenticateAgainstProtectionSpa...
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Mar 2018 06:19:02 +0000 (06:19 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Mar 2018 06:19:02 +0000 (06:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183966

Reviewed by Chris Dumez.

No change in behavior.

* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::canAuthenticateAgainstProtectionSpaceAsync):
* loader/ResourceLoader.h:
* platform/network/BlobResourceHandle.cpp:
* platform/network/PingHandle.h:
* platform/network/ResourceHandle.h:
* platform/network/ResourceHandleClient.h:
* platform/network/SynchronousLoaderClient.cpp:
(WebCore::SynchronousLoaderClient::canAuthenticateAgainstProtectionSpaceAsync):
* platform/network/SynchronousLoaderClient.h:
* platform/network/cf/ResourceHandleCFURLConnectionDelegate.h:
* platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp:
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::canRespondToProtectionSpace):
* platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.h:
* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::canAuthenticateAgainstProtectionSpace):
(WebCore::ResourceHandle::continueCanAuthenticateAgainstProtectionSpace): Deleted.
* platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h:
* platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:canAuthenticateAgainstProtectionSpace:]):
(-[WebCoreResourceHandleAsOperationQueueDelegate continueCanAuthenticateAgainstProtectionSpace:]): Deleted.

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/ResourceLoader.cpp
Source/WebCore/loader/ResourceLoader.h
Source/WebCore/platform/network/BlobResourceHandle.cpp
Source/WebCore/platform/network/PingHandle.h
Source/WebCore/platform/network/ResourceHandle.h
Source/WebCore/platform/network/ResourceHandleClient.h
Source/WebCore/platform/network/SynchronousLoaderClient.cpp
Source/WebCore/platform/network/SynchronousLoaderClient.h
Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegate.h
Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp
Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.h
Source/WebCore/platform/network/mac/ResourceHandleMac.mm
Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h
Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm

index 51f9ebc..c1ab2b9 100644 (file)
@@ -1,3 +1,34 @@
+2018-03-23  Alex Christensen  <achristensen@webkit.org>
+
+        Use completion handlers for ResourceHandleClient::canAuthenticateAgainstProtectionSpaceAsync
+        https://bugs.webkit.org/show_bug.cgi?id=183966
+
+        Reviewed by Chris Dumez.
+
+        No change in behavior.
+
+        * loader/ResourceLoader.cpp:
+        (WebCore::ResourceLoader::canAuthenticateAgainstProtectionSpaceAsync):
+        * loader/ResourceLoader.h:
+        * platform/network/BlobResourceHandle.cpp:
+        * platform/network/PingHandle.h:
+        * platform/network/ResourceHandle.h:
+        * platform/network/ResourceHandleClient.h:
+        * platform/network/SynchronousLoaderClient.cpp:
+        (WebCore::SynchronousLoaderClient::canAuthenticateAgainstProtectionSpaceAsync):
+        * platform/network/SynchronousLoaderClient.h:
+        * platform/network/cf/ResourceHandleCFURLConnectionDelegate.h:
+        * platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp:
+        (WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::canRespondToProtectionSpace):
+        * platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.h:
+        * platform/network/mac/ResourceHandleMac.mm:
+        (WebCore::ResourceHandle::canAuthenticateAgainstProtectionSpace):
+        (WebCore::ResourceHandle::continueCanAuthenticateAgainstProtectionSpace): Deleted.
+        * platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h:
+        * platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
+        (-[WebCoreResourceHandleAsOperationQueueDelegate connection:canAuthenticateAgainstProtectionSpace:]):
+        (-[WebCoreResourceHandleAsOperationQueueDelegate continueCanAuthenticateAgainstProtectionSpace:]): Deleted.
+
 2018-03-24  Chris Dumez  <cdumez@apple.com>
 
         Use SecurityOriginData more consistently in Service Worker code
index b795441..7d090b3 100644 (file)
@@ -736,9 +736,9 @@ void ResourceLoader::didReceiveAuthenticationChallenge(ResourceHandle* handle, c
 }
 
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-void ResourceLoader::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle* handle, const ProtectionSpace& protectionSpace)
+void ResourceLoader::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace& protectionSpace, CompletionHandler<void(bool)>&& completionHandler)
 {
-    handle->continueCanAuthenticateAgainstProtectionSpace(canAuthenticateAgainstProtectionSpace(protectionSpace));
+    completionHandler(canAuthenticateAgainstProtectionSpace(protectionSpace));
 }
 
 bool ResourceLoader::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace)
index d45a0e3..b0648ca 100644 (file)
@@ -199,7 +199,7 @@ private:
     bool shouldUseCredentialStorage(ResourceHandle*) override { return shouldUseCredentialStorage(); }
     void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&) override;
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&) override;
+    void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&, CompletionHandler<void(bool)>&&) override;
 #endif
     void receivedCancellation(ResourceHandle*, const AuthenticationChallenge& challenge) override { receivedCancellation(challenge); }
 #if PLATFORM(IOS)
index a4ea684..6182be5 100644 (file)
@@ -79,7 +79,7 @@ public:
     void didFail(ResourceHandle*, const ResourceError&) final;
     void willSendRequestAsync(ResourceHandle*, ResourceRequest&&, ResourceResponse&&, CompletionHandler<void(ResourceRequest&&)>&&) final;
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&) final;
+    void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&, CompletionHandler<void(bool)>&&) final;
 #endif
 
 private:
@@ -102,10 +102,10 @@ void BlobResourceSynchronousLoader::willSendRequestAsync(ResourceHandle*, Resour
 }
 
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-void BlobResourceSynchronousLoader::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle* handle, const ProtectionSpace&)
+void BlobResourceSynchronousLoader::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&, CompletionHandler<void(bool)>&& completionHandler)
 {
     ASSERT_NOT_REACHED();
-    handle->continueCanAuthenticateAgainstProtectionSpace(false);
+    completionHandler(false);
 }
 #endif
 
index 48782ac..43a7d4a 100644 (file)
@@ -78,9 +78,9 @@ private:
     bool shouldUseCredentialStorage(ResourceHandle*) final { return m_shouldUseCredentialStorage; }
     void timeoutTimerFired() { pingLoadComplete(ResourceError { String(), 0, m_currentRequest.url(), ASCIILiteral("Load timed out"), ResourceError::Type::Timeout }); }
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&)
+    void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&, CompletionHandler<void(bool)>&& completionHandler)
     {
-        m_handle->continueCanAuthenticateAgainstProtectionSpace(false);
+        completionHandler(false);
         pingLoadComplete(ResourceError { String { }, 0, m_currentRequest.url(), ASCIILiteral("Not allowed to authenticate"), ResourceError::Type::AccessControl });
     }
 #endif
index 307b036..c3302fe 100644 (file)
@@ -131,7 +131,7 @@ public:
 #endif
 
 #if PLATFORM(COCOA) && USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    bool canAuthenticateAgainstProtectionSpace(const ProtectionSpace&);
+    void canAuthenticateAgainstProtectionSpace(const ProtectionSpace&, CompletionHandler<void(bool)>&&);
 #endif
 
 #if PLATFORM(COCOA)
@@ -211,11 +211,6 @@ public:
     WEBCORE_EXPORT ResourceHandleClient* client() const;
     WEBCORE_EXPORT void clearClient();
 
-#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    // Called in response to ResourceHandleClient::canAuthenticateAgainstProtectionSpaceAsync().
-    WEBCORE_EXPORT void continueCanAuthenticateAgainstProtectionSpace(bool);
-#endif
-
     // Called in response to ResourceHandleClient::willCacheResponseAsync().
 #if USE(CFURLCONNECTION)
     WEBCORE_EXPORT void continueWillCacheResponse(CFCachedURLResponseRef);
index 2a4abc0..d5ae51d 100644 (file)
@@ -79,8 +79,7 @@ public:
     WEBCORE_EXPORT virtual void didReceiveResponseAsync(ResourceHandle*, ResourceResponse&&, CompletionHandler<void()>&&) = 0;
 
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    // Client will pass an updated request using ResourceHandle::continueCanAuthenticateAgainstProtectionSpace() when ready.
-    WEBCORE_EXPORT virtual void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&) = 0;
+    WEBCORE_EXPORT virtual void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&, CompletionHandler<void(bool)>&&) = 0;
 #endif
     // Client will pass an updated request using ResourceHandle::continueWillCacheResponse() when ready.
 #if USE(CFURLCONNECTION)
index 4f12026..9ea02c6 100644 (file)
@@ -55,10 +55,10 @@ bool SynchronousLoaderClient::shouldUseCredentialStorage(ResourceHandle*)
 }
 
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-void SynchronousLoaderClient::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle* handle, const ProtectionSpace&)
+void SynchronousLoaderClient::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&, CompletionHandler<void(bool)>&& completionHandler)
 {
     // FIXME: We should ask FrameLoaderClient. <http://webkit.org/b/65196>
-    handle->continueCanAuthenticateAgainstProtectionSpace(true);
+    completionHandler(true);
 }
 #endif
 
index fe67bd6..f5f40d1 100644 (file)
@@ -54,7 +54,7 @@ private:
     void didFinishLoading(ResourceHandle*) override;
     void didFail(ResourceHandle*, const ResourceError&) override;
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&) override;
+    void canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle*, const ProtectionSpace&, CompletionHandler<void(bool)>&&) override;
 #endif
 
     bool m_allowStoredCredentials { false };
index 3d373e3..3afc597 100644 (file)
@@ -47,9 +47,6 @@ public:
     virtual void releaseHandle();
 
     virtual void continueWillCacheResponse(CFCachedURLResponseRef) = 0;
-#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    virtual void continueCanAuthenticateAgainstProtectionSpace(bool) = 0;
-#endif // USE(PROTECTION_SPACE_AUTH_CALLBACK)
 
 protected:
     RetainPtr<CFURLResponseRef> synthesizeRedirectResponseIfNecessary(CFURLRequestRef, CFURLResponseRef);
index ee0c52a..bbd44a0 100644 (file)
@@ -363,15 +363,17 @@ Boolean ResourceHandleCFURLConnectionDelegateWithOperationQueue::canRespondToPro
     auto work = [protectedThis = makeRef(*this), protectionSpace = RetainPtr<CFURLProtectionSpaceRef>(protectionSpace)] () mutable {
         auto& handle = protectedThis->m_handle;
         
-        if (!protectedThis->hasHandle()) {
-            protectedThis->continueCanAuthenticateAgainstProtectionSpace(false);
-            return;
+        auto completionHandler = [protectedThis = WTFMove(protectedThis)] (bool result) mutable {
+            protectedThis->m_boolResult = canAuthenticate;
+            protectedThis->m_semaphore.signal();
         }
+        
+        if (!handle)
+            return completionHandler(false);
 
         LOG(Network, "CFNet - ResourceHandleCFURLConnectionDelegateWithOperationQueue::canRespondToProtectionSpace(handle=%p) (%s)", handle, handle->firstRequest().url().string().utf8().data());
 
-        ProtectionSpace coreProtectionSpace = ProtectionSpace(protectionSpace.get());
-        handle->canAuthenticateAgainstProtectionSpace(coreProtectionSpace);
+        handle->canAuthenticateAgainstProtectionSpace(ProtectionSpace(protectionSpace.get()), WTFMove(completionHandler));
     };
     
     if (m_messageQueue)
index 09a6f00..072a851 100644 (file)
@@ -61,7 +61,6 @@ private:
     void continueWillCacheResponse(CFCachedURLResponseRef) override;
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
     Boolean canRespondToProtectionSpace(CFURLProtectionSpaceRef) override;
-    void continueCanAuthenticateAgainstProtectionSpace(bool) override;
 #endif
 
     BinarySemaphore m_semaphore;
index ef61b93..83f65a7 100644 (file)
@@ -564,18 +564,12 @@ bool ResourceHandle::tryHandlePasswordBasedAuthentication(const AuthenticationCh
 }
 
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-bool ResourceHandle::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace)
+void ResourceHandle::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace, CompletionHandler<void(bool)>&& completionHandler)
 {
     if (ResourceHandleClient* client = this->client())
-        client->canAuthenticateAgainstProtectionSpaceAsync(this, protectionSpace);
+        client->canAuthenticateAgainstProtectionSpaceAsync(this, protectionSpace, WTFMove(completionHandler));
     else
-        continueCanAuthenticateAgainstProtectionSpace(false);
-    return false; // Ignored by caller.
-}
-
-void ResourceHandle::continueCanAuthenticateAgainstProtectionSpace(bool result)
-{
-    [(id)delegate() continueCanAuthenticateAgainstProtectionSpace:result];
+        completionHandler(false);
 }
 #endif
 
index 36550ab..917dd84 100644 (file)
@@ -51,7 +51,6 @@ class ResourceHandle;
 
 - (void)detachHandle;
 - (id)initWithHandle:(WebCore::ResourceHandle*)handle messageQueue:(MessageQueue<Function<void()>>*)messageQueue;
-- (void)continueCanAuthenticateAgainstProtectionSpace:(BOOL)canAuthenticate;
 - (void)continueWillCacheResponse:(NSCachedURLResponse *)response;
 @end
 
index 13d11a8..fdfec9c 100644 (file)
@@ -114,12 +114,6 @@ static bool scheduledWithCustomRunLoopMode(const std::optional<SchedulePairHashS
     [super dealloc];
 }
 
-- (void)continueCanAuthenticateAgainstProtectionSpace:(BOOL)canAuthenticate
-{
-    m_boolResult = canAuthenticate;
-    dispatch_semaphore_signal(m_semaphore);
-}
-
 - (void)continueWillCacheResponse:(NSCachedURLResponse *)response
 {
     m_cachedResponseResult = response;
@@ -206,7 +200,10 @@ static bool scheduledWithCustomRunLoopMode(const std::optional<SchedulePairHashS
             dispatch_semaphore_signal(m_semaphore);
             return;
         }
-        m_handle->canAuthenticateAgainstProtectionSpace(ProtectionSpace(protectionSpace.get()));
+        m_handle->canAuthenticateAgainstProtectionSpace(ProtectionSpace(protectionSpace.get()), [self, protectedSelf = WTFMove(protectedSelf)] (bool result) mutable {
+            m_boolResult = result;
+            dispatch_semaphore_signal(m_semaphore);
+        });
     };
 
     [self callFunctionOnMainThread:WTFMove(work)];