Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm (275288 => 275289)
--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm 2021-03-31 17:15:43 UTC (rev 275288)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm 2021-03-31 17:21:57 UTC (rev 275289)
@@ -1557,33 +1557,11 @@
return WebCore::certificatesMatch(trust.get(), challenge.nsURLAuthenticationChallenge().protectionSpace.serverTrust);
}
-void NetworkSessionCocoa::continueDidReceiveChallenge(SessionWrapper& sessionWrapper, const WebCore::AuthenticationChallenge& challenge, NegotiatedLegacyTLS negotiatedLegacyTLS, NetworkDataTaskCocoa::TaskIdentifier taskIdentifier, NetworkDataTaskCocoa* networkDataTask, CompletionHandler<void(WebKit::AuthenticationChallengeDisposition, const WebCore::Credential&)>&& completionHandler)
-{
- if (!networkDataTask) {
-#if HAVE(NSURLSESSION_WEBSOCKET)
- if (auto* webSocketTask = sessionWrapper.webSocketDataTaskMap.get(taskIdentifier)) {
- // FIXME: Handle challenges for web socket.
- completionHandler(AuthenticationChallengeDisposition::PerformDefaultHandling, { });
- return;
- }
-#endif
- auto downloadID = sessionWrapper.downloadMap.get(taskIdentifier);
- if (downloadID) {
- if (auto* download = networkProcess().downloadManager().download(downloadID)) {
- WebCore::AuthenticationChallenge authenticationChallenge { challenge };
- // Received an authentication challenge for a download being resumed.
- download->didReceiveChallenge(authenticationChallenge, WTFMove(completionHandler));
- return;
- }
- }
- LOG(NetworkSession, "%llu didReceiveChallenge completionHandler (cancel)", taskIdentifier);
- completionHandler(AuthenticationChallengeDisposition::Cancel, { });
- return;
- }
- auto sessionID = this->sessionID();
+static CompletionHandler<void(WebKit::AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential)> createChallengeCompletionHandler(Ref<NetworkProcess>&& networkProcess, PAL::SessionID sessionID, const WebCore::AuthenticationChallenge& challenge, const String& partition, uint64_t taskIdentifier, CompletionHandler<void(WebKit::AuthenticationChallengeDisposition, const WebCore::Credential&)>&& completionHandler)
+ {
WebCore::AuthenticationChallenge authenticationChallenge { challenge };
- auto challengeCompletionHandler = [completionHandler = WTFMove(completionHandler), networkProcess = makeRef(networkProcess()), sessionID, authenticationChallenge, taskIdentifier, partition = networkDataTask->partition()](WebKit::AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential) mutable {
+ return [completionHandler = WTFMove(completionHandler), networkProcess = WTFMove(networkProcess), sessionID, authenticationChallenge, taskIdentifier, partition](WebKit::AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential) mutable {
#if !LOG_DISABLED
LOG(NetworkSession, "%llu didReceiveChallenge completionHandler %d", taskIdentifier, disposition);
#else
@@ -1609,13 +1587,40 @@
#endif
completionHandler(disposition, credential);
};
+}
+void NetworkSessionCocoa::continueDidReceiveChallenge(SessionWrapper& sessionWrapper, const WebCore::AuthenticationChallenge& challenge, NegotiatedLegacyTLS negotiatedLegacyTLS, NetworkDataTaskCocoa::TaskIdentifier taskIdentifier, NetworkDataTaskCocoa* networkDataTask, CompletionHandler<void(WebKit::AuthenticationChallengeDisposition, const WebCore::Credential&)>&& completionHandler)
+{
+ if (!networkDataTask) {
+#if HAVE(NSURLSESSION_WEBSOCKET)
+ if (auto* webSocketTask = sessionWrapper.webSocketDataTaskMap.get(taskIdentifier)) {
+ auto challengeCompletionHandler = createChallengeCompletionHandler(networkProcess(), sessionID(), challenge, webSocketTask->partition(), 0, WTFMove(completionHandler));
+ networkProcess().authenticationManager().didReceiveAuthenticationChallenge(sessionID(), webSocketTask->pageID(), nullptr, challenge, negotiatedLegacyTLS, WTFMove(challengeCompletionHandler));
+
+ return;
+ }
+#endif
+ auto downloadID = sessionWrapper.downloadMap.get(taskIdentifier);
+ if (downloadID) {
+ if (auto* download = networkProcess().downloadManager().download(downloadID)) {
+ WebCore::AuthenticationChallenge authenticationChallenge { challenge };
+ // Received an authentication challenge for a download being resumed.
+ download->didReceiveChallenge(authenticationChallenge, WTFMove(completionHandler));
+ return;
+ }
+ }
+ LOG(NetworkSession, "%llu didReceiveChallenge completionHandler (cancel)", taskIdentifier);
+ completionHandler(AuthenticationChallengeDisposition::Cancel, { });
+ return;
+ }
+
+ auto challengeCompletionHandler = createChallengeCompletionHandler(networkProcess(), sessionID(), challenge, networkDataTask->partition(), taskIdentifier, WTFMove(completionHandler));
if (negotiatedLegacyTLS == NegotiatedLegacyTLS::Yes
&& fastServerTrustEvaluationEnabled()
&& !networkDataTask->isTopLevelNavigation())
return challengeCompletionHandler(AuthenticationChallengeDisposition::Cancel, { });
- networkDataTask->didReceiveChallenge(WTFMove(authenticationChallenge), negotiatedLegacyTLS, WTFMove(challengeCompletionHandler));
+ networkDataTask->didReceiveChallenge(WebCore::AuthenticationChallenge { challenge }, negotiatedLegacyTLS, WTFMove(challengeCompletionHandler));
}
DMFWebsitePolicyMonitor *NetworkSessionCocoa::deviceManagementPolicyMonitor()
@@ -1645,7 +1650,7 @@
[nsRequest _setProperty:@NO forKey:(NSString *)_kCFURLConnectionPropertyShouldSniff];
RetainPtr<NSURLSessionWebSocketTask> task = [sessionSetForPage(webPageProxyID).sessionWithCredentialStorage.session webSocketTaskWithRequest:nsRequest.get()];
- return makeUnique<WebSocketTask>(channel, WTFMove(task));
+ return makeUnique<WebSocketTask>(channel, webPageProxyID, request, WTFMove(task));
}
void NetworkSessionCocoa::addWebSocketTask(WebPageProxyIdentifier webPageProxyID, WebSocketTask& task)
Modified: trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.h (275288 => 275289)
--- trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.h 2021-03-31 17:15:43 UTC (rev 275288)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.h 2021-03-31 17:21:57 UTC (rev 275289)
@@ -28,11 +28,16 @@
#if HAVE(NSURLSESSION_WEBSOCKET)
#include "DataReference.h"
+#include "WebPageProxyIdentifier.h"
#include <wtf/RetainPtr.h>
#include <wtf/WeakPtr.h>
OBJC_CLASS NSURLSessionWebSocketTask;
+namespace WebCore {
+class ResourceRequest;
+}
+
namespace WebKit {
class NetworkSession;
class NetworkSessionCocoa;
@@ -41,7 +46,7 @@
class WebSocketTask : public CanMakeWeakPtr<WebSocketTask> {
WTF_MAKE_FAST_ALLOCATED;
public:
- WebSocketTask(NetworkSocketChannel&, RetainPtr<NSURLSessionWebSocketTask>&&);
+ WebSocketTask(NetworkSocketChannel&, WebPageProxyIdentifier, const WebCore::ResourceRequest&, RetainPtr<NSURLSessionWebSocketTask>&&);
~WebSocketTask();
void sendString(const IPC::DataReference&, CompletionHandler<void()>&&);
@@ -59,6 +64,9 @@
NetworkSessionCocoa* networkSession();
+ WebPageProxyIdentifier pageID() const { return m_pageID; }
+ String partition() const { return m_partition; }
+
private:
void readNextMessage();
@@ -66,6 +74,8 @@
RetainPtr<NSURLSessionWebSocketTask> m_task;
bool m_receivedDidClose { false };
bool m_receivedDidConnect { false };
+ WebPageProxyIdentifier m_pageID;
+ String m_partition;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.mm (275288 => 275289)
--- trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.mm 2021-03-31 17:15:43 UTC (rev 275288)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/WebSocketTaskCocoa.mm 2021-03-31 17:21:57 UTC (rev 275289)
@@ -40,9 +40,11 @@
using namespace WebCore;
-WebSocketTask::WebSocketTask(NetworkSocketChannel& channel, RetainPtr<NSURLSessionWebSocketTask>&& task)
+WebSocketTask::WebSocketTask(NetworkSocketChannel& channel, WebPageProxyIdentifier webPageProxyID, const WebCore::ResourceRequest& request, RetainPtr<NSURLSessionWebSocketTask>&& task)
: m_channel(channel)
, m_task(WTFMove(task))
+ , m_pageID(webPageProxyID)
+ , m_partition(request.cachePartition())
{
readNextMessage();
m_channel.didSendHandshakeRequest(ResourceRequest { [m_task currentRequest] });