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.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@229959 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/platform/network/BlobResourceHandle.cpp b/Source/WebCore/platform/network/BlobResourceHandle.cpp
index a4ea684..6182be5 100644
--- a/Source/WebCore/platform/network/BlobResourceHandle.cpp
+++ b/Source/WebCore/platform/network/BlobResourceHandle.cpp
@@ -79,7 +79,7 @@
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 @@
}
#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
diff --git a/Source/WebCore/platform/network/PingHandle.h b/Source/WebCore/platform/network/PingHandle.h
index 48782ac..43a7d4a 100644
--- a/Source/WebCore/platform/network/PingHandle.h
+++ b/Source/WebCore/platform/network/PingHandle.h
@@ -78,9 +78,9 @@
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
diff --git a/Source/WebCore/platform/network/ResourceHandle.h b/Source/WebCore/platform/network/ResourceHandle.h
index 307b036..c3302fe 100644
--- a/Source/WebCore/platform/network/ResourceHandle.h
+++ b/Source/WebCore/platform/network/ResourceHandle.h
@@ -131,7 +131,7 @@
#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 @@
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);
diff --git a/Source/WebCore/platform/network/ResourceHandleClient.h b/Source/WebCore/platform/network/ResourceHandleClient.h
index 2a4abc0..d5ae51d1 100644
--- a/Source/WebCore/platform/network/ResourceHandleClient.h
+++ b/Source/WebCore/platform/network/ResourceHandleClient.h
@@ -79,8 +79,7 @@
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)
diff --git a/Source/WebCore/platform/network/SynchronousLoaderClient.cpp b/Source/WebCore/platform/network/SynchronousLoaderClient.cpp
index 4f12026..9ea02c6 100644
--- a/Source/WebCore/platform/network/SynchronousLoaderClient.cpp
+++ b/Source/WebCore/platform/network/SynchronousLoaderClient.cpp
@@ -55,10 +55,10 @@
}
#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
diff --git a/Source/WebCore/platform/network/SynchronousLoaderClient.h b/Source/WebCore/platform/network/SynchronousLoaderClient.h
index fe67bd6..f5f40d1 100644
--- a/Source/WebCore/platform/network/SynchronousLoaderClient.h
+++ b/Source/WebCore/platform/network/SynchronousLoaderClient.h
@@ -54,7 +54,7 @@
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 };
diff --git a/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegate.h b/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegate.h
index 3d373e3..3afc597 100644
--- a/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegate.h
+++ b/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegate.h
@@ -47,9 +47,6 @@
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);
diff --git a/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp b/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp
index ee0c52a..bbd44a0 100644
--- a/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp
+++ b/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp
@@ -363,15 +363,17 @@
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)
diff --git a/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.h b/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.h
index 09a6f00..072a851 100644
--- a/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.h
+++ b/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.h
@@ -61,7 +61,6 @@
void continueWillCacheResponse(CFCachedURLResponseRef) override;
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
Boolean canRespondToProtectionSpace(CFURLProtectionSpaceRef) override;
- void continueCanAuthenticateAgainstProtectionSpace(bool) override;
#endif
BinarySemaphore m_semaphore;
diff --git a/Source/WebCore/platform/network/mac/ResourceHandleMac.mm b/Source/WebCore/platform/network/mac/ResourceHandleMac.mm
index ef61b93..83f65a7 100644
--- a/Source/WebCore/platform/network/mac/ResourceHandleMac.mm
+++ b/Source/WebCore/platform/network/mac/ResourceHandleMac.mm
@@ -564,18 +564,12 @@
}
#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
diff --git a/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h b/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h
index 36550ab..917dd84 100644
--- a/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h
+++ b/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h
@@ -51,7 +51,6 @@
- (void)detachHandle;
- (id)initWithHandle:(WebCore::ResourceHandle*)handle messageQueue:(MessageQueue<Function<void()>>*)messageQueue;
-- (void)continueCanAuthenticateAgainstProtectionSpace:(BOOL)canAuthenticate;
- (void)continueWillCacheResponse:(NSCachedURLResponse *)response;
@end
diff --git a/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm b/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm
index 13d11a8..fdfec9c 100644
--- a/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm
+++ b/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm
@@ -114,12 +114,6 @@
[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 @@
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)];