NetworkLoad::didReceiveResponse should pass its completion handler to its client
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Sep 2018 17:36:19 +0000 (17:36 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Sep 2018 17:36:19 +0000 (17:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188701

Reviewed by Michael Catanzaro.

Right now we have a confusing enum ShouldContinueDidReceiveResponse and a complicated flow
that involves many objects and implicitly using NetworkLoad's destructor as part of the
loading flow.  This makes the responsibilities of the objects clear.

* NetworkProcess/Downloads/PendingDownload.cpp:
(WebKit::PendingDownload::didReceiveResponse):
* NetworkProcess/Downloads/PendingDownload.h:
* NetworkProcess/NetworkCORSPreflightChecker.cpp:
(WebKit::NetworkCORSPreflightChecker::didReceiveResponse):
(WebKit::NetworkCORSPreflightChecker::didReceiveResponseNetworkSession): Deleted.
* NetworkProcess/NetworkCORSPreflightChecker.h:
* NetworkProcess/NetworkDataTask.cpp:
(WebKit::NetworkDataTask::didReceiveResponse):
* NetworkProcess/NetworkDataTask.h:
* NetworkProcess/NetworkLoad.cpp:
(WebKit::NetworkLoad::~NetworkLoad):
(WebKit::NetworkLoad::convertTaskToDownload):
(WebKit::NetworkLoad::didReceiveResponse):
(WebKit::NetworkLoad::notifyDidReceiveResponse):
(WebKit::NetworkLoad::continueDidReceiveResponse): Deleted.
(WebKit::NetworkLoad::didReceiveResponseNetworkSession): Deleted.
* NetworkProcess/NetworkLoad.h:
* NetworkProcess/NetworkLoadClient.h:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::~NetworkResourceLoader):
(WebKit::NetworkResourceLoader::didReceiveResponse):
(WebKit::NetworkResourceLoader::didFinishWithRedirectResponse):
(WebKit::NetworkResourceLoader::continueDidReceiveResponse):
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/PingLoad.cpp:
(WebKit::PingLoad::didReceiveResponse):
(WebKit::PingLoad::didReceiveResponseNetworkSession): Deleted.
* NetworkProcess/PingLoad.h:
* NetworkProcess/PreconnectTask.cpp:
(WebKit::PreconnectTask::didReceiveResponse):
* NetworkProcess/PreconnectTask.h:
* NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
(WebKit::NetworkCache::SpeculativeLoad::didReceiveResponse):
* NetworkProcess/cache/NetworkCacheSpeculativeLoad.h:
* NetworkProcess/capture/NetworkDataTaskReplay.cpp:
(WebKit::NetworkCapture::NetworkDataTaskReplay::didReceiveResponse):

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

21 files changed:
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/Downloads/DownloadManager.cpp
Source/WebKit/NetworkProcess/Downloads/DownloadManager.h
Source/WebKit/NetworkProcess/Downloads/PendingDownload.cpp
Source/WebKit/NetworkProcess/Downloads/PendingDownload.h
Source/WebKit/NetworkProcess/NetworkCORSPreflightChecker.cpp
Source/WebKit/NetworkProcess/NetworkCORSPreflightChecker.h
Source/WebKit/NetworkProcess/NetworkDataTask.cpp
Source/WebKit/NetworkProcess/NetworkDataTask.h
Source/WebKit/NetworkProcess/NetworkLoad.cpp
Source/WebKit/NetworkProcess/NetworkLoad.h
Source/WebKit/NetworkProcess/NetworkLoadClient.h
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit/NetworkProcess/NetworkResourceLoader.h
Source/WebKit/NetworkProcess/PingLoad.cpp
Source/WebKit/NetworkProcess/PingLoad.h
Source/WebKit/NetworkProcess/PreconnectTask.cpp
Source/WebKit/NetworkProcess/PreconnectTask.h
Source/WebKit/NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheSpeculativeLoad.h
Source/WebKit/NetworkProcess/capture/NetworkDataTaskReplay.cpp

index df4aa02..6a1375f 100644 (file)
@@ -1,3 +1,52 @@
+2018-09-25  Alex Christensen  <achristensen@webkit.org>
+
+        NetworkLoad::didReceiveResponse should pass its completion handler to its client
+        https://bugs.webkit.org/show_bug.cgi?id=188701
+
+        Reviewed by Michael Catanzaro.
+
+        Right now we have a confusing enum ShouldContinueDidReceiveResponse and a complicated flow
+        that involves many objects and implicitly using NetworkLoad's destructor as part of the
+        loading flow.  This makes the responsibilities of the objects clear.
+
+        * NetworkProcess/Downloads/PendingDownload.cpp:
+        (WebKit::PendingDownload::didReceiveResponse):
+        * NetworkProcess/Downloads/PendingDownload.h:
+        * NetworkProcess/NetworkCORSPreflightChecker.cpp:
+        (WebKit::NetworkCORSPreflightChecker::didReceiveResponse):
+        (WebKit::NetworkCORSPreflightChecker::didReceiveResponseNetworkSession): Deleted.
+        * NetworkProcess/NetworkCORSPreflightChecker.h:
+        * NetworkProcess/NetworkDataTask.cpp:
+        (WebKit::NetworkDataTask::didReceiveResponse):
+        * NetworkProcess/NetworkDataTask.h:
+        * NetworkProcess/NetworkLoad.cpp:
+        (WebKit::NetworkLoad::~NetworkLoad):
+        (WebKit::NetworkLoad::convertTaskToDownload):
+        (WebKit::NetworkLoad::didReceiveResponse):
+        (WebKit::NetworkLoad::notifyDidReceiveResponse):
+        (WebKit::NetworkLoad::continueDidReceiveResponse): Deleted.
+        (WebKit::NetworkLoad::didReceiveResponseNetworkSession): Deleted.
+        * NetworkProcess/NetworkLoad.h:
+        * NetworkProcess/NetworkLoadClient.h:
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::~NetworkResourceLoader):
+        (WebKit::NetworkResourceLoader::didReceiveResponse):
+        (WebKit::NetworkResourceLoader::didFinishWithRedirectResponse):
+        (WebKit::NetworkResourceLoader::continueDidReceiveResponse):
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/PingLoad.cpp:
+        (WebKit::PingLoad::didReceiveResponse):
+        (WebKit::PingLoad::didReceiveResponseNetworkSession): Deleted.
+        * NetworkProcess/PingLoad.h:
+        * NetworkProcess/PreconnectTask.cpp:
+        (WebKit::PreconnectTask::didReceiveResponse):
+        * NetworkProcess/PreconnectTask.h:
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoad.cpp:
+        (WebKit::NetworkCache::SpeculativeLoad::didReceiveResponse):
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoad.h:
+        * NetworkProcess/capture/NetworkDataTaskReplay.cpp:
+        (WebKit::NetworkCapture::NetworkDataTaskReplay::didReceiveResponse):
+
 2018-09-24  Alex Christensen  <achristensen@webkit.org>
 
         Build fix.
index 630cea5..1e28fc9 100644 (file)
@@ -85,10 +85,10 @@ void DownloadManager::willDecidePendingDownloadDestination(NetworkDataTask& netw
     ASSERT_UNUSED(addResult, addResult.isNewEntry);
 }
 
-void DownloadManager::convertNetworkLoadToDownload(DownloadID downloadID, std::unique_ptr<NetworkLoad>&& networkLoad, Vector<RefPtr<WebCore::BlobDataFileReference>>&& blobFileReferences, const ResourceRequest& request, const ResourceResponse& response)
+void DownloadManager::convertNetworkLoadToDownload(DownloadID downloadID, std::unique_ptr<NetworkLoad>&& networkLoad, ResponseCompletionHandler&& completionHandler, Vector<RefPtr<WebCore::BlobDataFileReference>>&& blobFileReferences, const ResourceRequest& request, const ResourceResponse& response)
 {
     ASSERT(!m_pendingDownloads.contains(downloadID));
-    m_pendingDownloads.add(downloadID, std::make_unique<PendingDownload>(WTFMove(networkLoad), downloadID, request, response));
+    m_pendingDownloads.add(downloadID, std::make_unique<PendingDownload>(WTFMove(networkLoad), WTFMove(completionHandler), downloadID, request, response));
 }
 
 void DownloadManager::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, SandboxExtension::Handle&& sandboxExtensionHandle, bool allowOverwrite)
index 7919d27..51d0ef1 100644 (file)
@@ -79,7 +79,7 @@ public:
     void dataTaskBecameDownloadTask(DownloadID, std::unique_ptr<Download>&&);
     void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
     void willDecidePendingDownloadDestination(NetworkDataTask&, ResponseCompletionHandler&&);
-    void convertNetworkLoadToDownload(DownloadID, std::unique_ptr<NetworkLoad>&&, Vector<RefPtr<WebCore::BlobDataFileReference>>&&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
+    void convertNetworkLoadToDownload(DownloadID, std::unique_ptr<NetworkLoad>&&, ResponseCompletionHandler&&,  Vector<RefPtr<WebCore::BlobDataFileReference>>&&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
     void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
 
     void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&);
index 7aad1db..a099ab3 100644 (file)
@@ -47,7 +47,7 @@ PendingDownload::PendingDownload(NetworkLoadParameters&& parameters, DownloadID
     send(Messages::DownloadProxy::DidStart(m_networkLoad->currentRequest(), suggestedName));
 }
 
-PendingDownload::PendingDownload(std::unique_ptr<NetworkLoad>&& networkLoad, DownloadID downloadID, const ResourceRequest& request, const ResourceResponse& response)
+PendingDownload::PendingDownload(std::unique_ptr<NetworkLoad>&& networkLoad, ResponseCompletionHandler&& completionHandler, DownloadID downloadID, const ResourceRequest& request, const ResourceResponse& response)
     : m_networkLoad(WTFMove(networkLoad))
 {
     m_isAllowedToAskUserForCredentials = m_networkLoad->isAllowedToAskUserForCredentials();
@@ -55,7 +55,7 @@ PendingDownload::PendingDownload(std::unique_ptr<NetworkLoad>&& networkLoad, Dow
     m_networkLoad->setPendingDownloadID(downloadID);
     send(Messages::DownloadProxy::DidStart(request, String()));
 
-    m_networkLoad->convertTaskToDownload(*this, request, response);
+    m_networkLoad->convertTaskToDownload(*this, request, response, WTFMove(completionHandler));
 }
 
 void PendingDownload::willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse)
@@ -85,6 +85,11 @@ IPC::Connection* PendingDownload::messageSenderConnection()
     return NetworkProcess::singleton().parentProcessConnection();
 }
 
+void PendingDownload::didReceiveResponse(WebCore::ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)
+{
+    completionHandler(WebCore::PolicyAction::Download);
+}
+
 uint64_t PendingDownload::messageSenderDestinationID()
 {
     return m_networkLoad->pendingDownloadID().downloadID();
index af990c1..a383749 100644 (file)
@@ -43,7 +43,7 @@ class PendingDownload : public NetworkLoadClient, public IPC::MessageSender {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     PendingDownload(NetworkLoadParameters&&, DownloadID, NetworkSession&, const String& suggestedName);
-    PendingDownload(std::unique_ptr<NetworkLoad>&&, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
+    PendingDownload(std::unique_ptr<NetworkLoad>&&, ResponseCompletionHandler&&, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
 
     void continueWillSendRequest(WebCore::ResourceRequest&&);
     void cancel();
@@ -54,7 +54,7 @@ private:
     bool isSynchronous() const override { return false; }
     bool isAllowedToAskUserForCredentials() const final { return m_isAllowedToAskUserForCredentials; }
     void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse) override;
-    ShouldContinueDidReceiveResponse didReceiveResponse(WebCore::ResourceResponse&&) override { return ShouldContinueDidReceiveResponse::No; };
+    void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) override;
     void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override { };
     void didFinishLoading(const WebCore::NetworkLoadMetrics&) override { };
     void didFailLoading(const WebCore::ResourceError&) override;
index 9c52d92..1e5646e 100644 (file)
@@ -106,9 +106,9 @@ void NetworkCORSPreflightChecker::didReceiveChallenge(WebCore::AuthenticationCha
     NetworkProcess::singleton().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.pageID, m_parameters.frameID, challenge, WTFMove(completionHandler));
 }
 
-void NetworkCORSPreflightChecker::didReceiveResponseNetworkSession(WebCore::ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)
+void NetworkCORSPreflightChecker::didReceiveResponse(WebCore::ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)
 {
-    RELEASE_LOG_IF_ALLOWED("didReceiveResponseNetworkSession");
+    RELEASE_LOG_IF_ALLOWED("didReceiveResponse");
 
     if (m_shouldCaptureExtraNetworkLoadMetrics)
         m_loadInformation.response = response;
index 4e55ea0..056df12 100644 (file)
@@ -65,7 +65,7 @@ public:
 private:
     void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&) final;
     void didReceiveChallenge(WebCore::AuthenticationChallenge&&, ChallengeCompletionHandler&&) final;
-    void didReceiveResponseNetworkSession(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
+    void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
     void didReceiveData(Ref<WebCore::SharedBuffer>&&) final;
     void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&) final;
     void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) final;
index ddbf3b7..cf4e64d 100644 (file)
@@ -113,7 +113,7 @@ void NetworkDataTask::didReceiveResponse(ResourceResponse&& response, ResponseCo
             return;
         }
     }
-    m_client->didReceiveResponseNetworkSession(WTFMove(response), WTFMove(completionHandler));
+    m_client->didReceiveResponse(WTFMove(response), WTFMove(completionHandler));
 }
 
 bool NetworkDataTask::shouldCaptureExtraNetworkLoadMetrics() const
index 75a0a4a..408f09a 100644 (file)
@@ -60,7 +60,7 @@ class NetworkDataTaskClient {
 public:
     virtual void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&) = 0;
     virtual void didReceiveChallenge(WebCore::AuthenticationChallenge&&, ChallengeCompletionHandler&&) = 0;
-    virtual void didReceiveResponseNetworkSession(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) = 0;
+    virtual void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) = 0;
     virtual void didReceiveData(Ref<WebCore::SharedBuffer>&&) = 0;
     virtual void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&) = 0;
     virtual void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) = 0;
index bd3f424..9ae6501 100644 (file)
@@ -121,8 +121,6 @@ NetworkLoad::~NetworkLoad()
     ASSERT(RunLoop::isMain());
     if (m_redirectCompletionHandler)
         m_redirectCompletionHandler({ });
-    if (m_responseCompletionHandler)
-        m_responseCompletionHandler(PolicyAction::Ignore);
     if (m_task)
         m_task->clearClient();
 }
@@ -176,14 +174,6 @@ void NetworkLoad::continueWillSendRequest(WebCore::ResourceRequest&& newRequest)
         redirectCompletionHandler(ResourceRequest(m_currentRequest));
 }
 
-void NetworkLoad::continueDidReceiveResponse()
-{
-    if (m_responseCompletionHandler) {
-        auto responseCompletionHandler = std::exchange(m_responseCompletionHandler, nullptr);
-        responseCompletionHandler(PolicyAction::Use);
-    }
-}
-
 bool NetworkLoad::shouldCaptureExtraNetworkLoadMetrics() const
 {
     return m_client.get().shouldCaptureExtraNetworkLoadMetrics();
@@ -194,17 +184,16 @@ bool NetworkLoad::isAllowedToAskUserForCredentials() const
     return m_client.get().isAllowedToAskUserForCredentials();
 }
 
-void NetworkLoad::convertTaskToDownload(PendingDownload& pendingDownload, const ResourceRequest& updatedRequest, const ResourceResponse& response)
+void NetworkLoad::convertTaskToDownload(PendingDownload& pendingDownload, const ResourceRequest& updatedRequest, const ResourceResponse& response, ResponseCompletionHandler&& completionHandler)
 {
     if (!m_task)
-        return;
+        return completionHandler(PolicyAction::Ignore);
 
     m_client = pendingDownload;
     m_currentRequest = updatedRequest;
     m_task->setPendingDownload(pendingDownload);
-
-    if (m_responseCompletionHandler)
-        NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), std::exchange(m_responseCompletionHandler, nullptr), response);
+    
+    NetworkProcess::singleton().findPendingDownloadLocation(*m_task.get(), WTFMove(completionHandler), response);
 }
 
 void NetworkLoad::setPendingDownloadID(DownloadID downloadID)
@@ -269,7 +258,7 @@ void NetworkLoad::didReceiveChallenge(AuthenticationChallenge&& challenge, Chall
         NetworkProcess::singleton().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.webPageID, m_parameters.webFrameID, challenge, WTFMove(completionHandler));
 }
 
-void NetworkLoad::didReceiveResponseNetworkSession(ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)
+void NetworkLoad::didReceiveResponse(ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)
 {
     ASSERT(RunLoop::isMain());
     ASSERT(!m_throttle);
@@ -301,11 +290,7 @@ void NetworkLoad::notifyDidReceiveResponse(ResourceResponse&& response, Response
     if (m_parameters.needsCertificateInfo)
         response.includeCertificateInfo();
 
-    if (m_client.get().didReceiveResponse(WTFMove(response)) == NetworkLoadClient::ShouldContinueDidReceiveResponse::No) {
-        m_responseCompletionHandler = WTFMove(completionHandler);
-        return;
-    }
-    completionHandler(PolicyAction::Use);
+    m_client.get().didReceiveResponse(WTFMove(response), WTFMove(completionHandler));
 }
 
 void NetworkLoad::didReceiveData(Ref<SharedBuffer>&& buffer)
index 99c9209..00a9630 100644 (file)
@@ -59,9 +59,8 @@ public:
     const NetworkLoadParameters& parameters() const { return m_parameters; }
 
     void continueWillSendRequest(WebCore::ResourceRequest&&);
-    void continueDidReceiveResponse();
 
-    void convertTaskToDownload(PendingDownload&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
+    void convertTaskToDownload(PendingDownload&, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, ResponseCompletionHandler&&);
     void setPendingDownloadID(DownloadID);
     void setSuggestedFilename(const String&);
     void setPendingDownload(PendingDownload&);
@@ -81,7 +80,7 @@ private:
     // NetworkDataTaskClient
     void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&) final;
     void didReceiveChallenge(WebCore::AuthenticationChallenge&&, ChallengeCompletionHandler&&) final;
-    void didReceiveResponseNetworkSession(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
+    void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
     void didReceiveData(Ref<WebCore::SharedBuffer>&&) final;
     void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&) final;
     void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) final;
@@ -95,7 +94,6 @@ private:
     const NetworkLoadParameters m_parameters;
     CompletionHandler<void(WebCore::ResourceRequest&&)> m_redirectCompletionHandler;
     RefPtr<NetworkDataTask> m_task;
-    ResponseCompletionHandler m_responseCompletionHandler;
     
     struct Throttle;
     std::unique_ptr<Throttle> m_throttle;
index 5bbfb0e..4692fd7 100644 (file)
@@ -34,10 +34,13 @@ namespace WebCore {
 class NetworkLoadMetrics;
 class ProtectionSpace;
 class SharedBuffer;
+enum class PolicyAction;
 }
 
 namespace WebKit {
 
+using ResponseCompletionHandler = CompletionHandler<void(WebCore::PolicyAction)>;
+
 class NetworkLoadClient {
 public:
     virtual ~NetworkLoadClient() { }
@@ -48,8 +51,7 @@ public:
 
     virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) = 0;
     virtual void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse) = 0;
-    enum class ShouldContinueDidReceiveResponse { No, Yes };
-    virtual ShouldContinueDidReceiveResponse didReceiveResponse(WebCore::ResourceResponse&&) = 0;
+    virtual void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) = 0;
     virtual void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) = 0;
     virtual void didFinishLoading(const WebCore::NetworkLoadMetrics&) = 0;
     virtual void didFailLoading(const WebCore::ResourceError&) = 0;
index 435d9c6..90bd301 100644 (file)
@@ -134,6 +134,8 @@ NetworkResourceLoader::~NetworkResourceLoader()
     ASSERT(RunLoop::isMain());
     ASSERT(!m_networkLoad);
     ASSERT(!isSynchronous() || !m_synchronousLoadData->delayedReply);
+    if (m_responseCompletionHandler)
+        m_responseCompletionHandler(PolicyAction::Ignore);
 }
 
 bool NetworkResourceLoader::canUseCache(const ResourceRequest& request) const
@@ -344,7 +346,8 @@ void NetworkResourceLoader::convertToDownload(DownloadID downloadID, const Resou
         return;
     }
 
-    NetworkProcess::singleton().downloadManager().convertNetworkLoadToDownload(downloadID, std::exchange(m_networkLoad, nullptr), WTFMove(m_fileReferences), request, response);
+    ASSERT(m_responseCompletionHandler);
+    NetworkProcess::singleton().downloadManager().convertNetworkLoadToDownload(downloadID, std::exchange(m_networkLoad, nullptr), WTFMove(m_responseCompletionHandler), WTFMove(m_fileReferences), request, response);
 }
 
 void NetworkResourceLoader::abort()
@@ -426,7 +429,7 @@ bool NetworkResourceLoader::shouldInterruptLoadForCSPFrameAncestorsOrXFrameOptio
     return false;
 }
 
-auto NetworkResourceLoader::didReceiveResponse(ResourceResponse&& receivedResponse) -> ShouldContinueDidReceiveResponse
+void NetworkResourceLoader::didReceiveResponse(ResourceResponse&& receivedResponse, ResponseCompletionHandler&& completionHandler)
 {
     RELEASE_LOG_IF_ALLOWED("didReceiveResponse: (pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ", httpStatusCode = %d, length = %" PRId64 ")", m_parameters.webPageID, m_parameters.webFrameID, m_parameters.identifier, receivedResponse.httpStatusCode(), receivedResponse.expectedContentLength());
 
@@ -456,11 +459,11 @@ auto NetworkResourceLoader::didReceiveResponse(ResourceResponse&& receivedRespon
             m_cacheEntryForValidation = nullptr;
     }
     if (m_cacheEntryForValidation)
-        return ShouldContinueDidReceiveResponse::Yes;
+        return completionHandler(PolicyAction::Use);
 
     if (isMainResource() && shouldInterruptLoadForCSPFrameAncestorsOrXFrameOptions(m_response)) {
         send(Messages::WebResourceLoader::StopLoadingAfterXFrameOptionsOrContentSecurityPolicyDenied { });
-        return ShouldContinueDidReceiveResponse::No;
+        return completionHandler(PolicyAction::Ignore);
     }
 
     if (m_networkLoadChecker) {
@@ -470,21 +473,24 @@ auto NetworkResourceLoader::didReceiveResponse(ResourceResponse&& receivedRespon
                 if (protectedThis->m_networkLoad)
                     protectedThis->didFailLoading(error);
             });
-            return ShouldContinueDidReceiveResponse::No;
+            return completionHandler(PolicyAction::Ignore);
         }
     }
 
     auto response = sanitizeResponseIfPossible(ResourceResponse { m_response }, ResourceResponse::SanitizationType::CrossOriginSafe);
     if (isSynchronous()) {
         m_synchronousLoadData->response = WTFMove(response);
-        return ShouldContinueDidReceiveResponse::Yes;
+        return completionHandler(PolicyAction::Use);
     }
 
     // We wait to receive message NetworkResourceLoader::ContinueDidReceiveResponse before continuing a load for
     // a main resource because the embedding client must decide whether to allow the load.
     bool willWaitForContinueDidReceiveResponse = isMainResource();
     send(Messages::WebResourceLoader::DidReceiveResponse { response, willWaitForContinueDidReceiveResponse });
-    return willWaitForContinueDidReceiveResponse ? ShouldContinueDidReceiveResponse::No : ShouldContinueDidReceiveResponse::Yes;
+    if (willWaitForContinueDidReceiveResponse)
+        m_responseCompletionHandler = WTFMove(completionHandler);
+    else
+        completionHandler(PolicyAction::Use);
 }
 
 void NetworkResourceLoader::didReceiveBuffer(Ref<SharedBuffer>&& buffer, int reportedEncodedDataLength)
@@ -631,7 +637,7 @@ void NetworkResourceLoader::continueWillSendRedirectedRequest(ResourceRequest&&
 void NetworkResourceLoader::didFinishWithRedirectResponse(ResourceResponse&& redirectResponse)
 {
     redirectResponse.setType(ResourceResponse::Type::Opaqueredirect);
-    didReceiveResponse(WTFMove(redirectResponse));
+    didReceiveResponse(WTFMove(redirectResponse), [] (auto) { });
 
     WebCore::NetworkLoadMetrics networkLoadMetrics;
     networkLoadMetrics.markComplete();
@@ -706,15 +712,11 @@ void NetworkResourceLoader::continueWillSendRequest(ResourceRequest&& newRequest
 
 void NetworkResourceLoader::continueDidReceiveResponse()
 {
-    if (m_cacheEntryWaitingForContinueDidReceiveResponse) {
+    if (m_cacheEntryWaitingForContinueDidReceiveResponse)
         continueProcessingCachedEntryAfterDidReceiveResponse(WTFMove(m_cacheEntryWaitingForContinueDidReceiveResponse));
-        return;
-    }
 
-    // FIXME: Remove this check once BlobResourceHandle implements didReceiveResponseAsync correctly.
-    // Currently, it does not wait for response, so the load is likely to finish before continueDidReceiveResponse.
-    if (m_networkLoad)
-        m_networkLoad->continueDidReceiveResponse();
+    if (m_responseCompletionHandler)
+        m_responseCompletionHandler(PolicyAction::Use);
 }
 
 void NetworkResourceLoader::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
index d897748..96edab3 100644 (file)
@@ -97,7 +97,7 @@ public:
     bool isSynchronous() const override;
     bool isAllowedToAskUserForCredentials() const override { return m_isAllowedToAskUserForCredentials; }
     void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&&) override;
-    ShouldContinueDidReceiveResponse didReceiveResponse(WebCore::ResourceResponse&&) override;
+    void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) override;
     void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override;
     void didFinishLoading(const WebCore::NetworkLoadMetrics&) override;
     void didFailLoading(const WebCore::ResourceError&) override;
@@ -206,6 +206,7 @@ private:
     std::unique_ptr<NetworkCache::Entry> m_cacheEntryWaitingForContinueDidReceiveResponse;
     std::unique_ptr<NetworkLoadChecker> m_networkLoadChecker;
     bool m_shouldRestartLoad { false };
+    ResponseCompletionHandler m_responseCompletionHandler;
 
     std::optional<NetworkActivityTracker> m_networkActivityTracker;
 };
index 9facd8f..983a42a 100644 (file)
@@ -122,9 +122,9 @@ void PingLoad::didReceiveChallenge(AuthenticationChallenge&&, ChallengeCompletio
     didFinish(ResourceError { String(), 0, currentURL(), "Failed HTTP authentication"_s, ResourceError::Type::AccessControl });
 }
 
-void PingLoad::didReceiveResponseNetworkSession(ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)
+void PingLoad::didReceiveResponse(ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)
 {
-    RELEASE_LOG_IF_ALLOWED("didReceiveResponseNetworkSession - httpStatusCode: %d", response.httpStatusCode());
+    RELEASE_LOG_IF_ALLOWED("didReceiveResponse - httpStatusCode: %d", response.httpStatusCode());
     auto weakThis = makeWeakPtr(*this);
     completionHandler(PolicyAction::Ignore);
     if (!weakThis)
index e47bf17..9f0c6b8 100644 (file)
@@ -56,7 +56,7 @@ private:
 
     void willPerformHTTPRedirection(WebCore::ResourceResponse&&, WebCore::ResourceRequest&&, RedirectCompletionHandler&&) final;
     void didReceiveChallenge(WebCore::AuthenticationChallenge&&, ChallengeCompletionHandler&&) final;
-    void didReceiveResponseNetworkSession(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
+    void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
     void didReceiveData(Ref<WebCore::SharedBuffer>&&) final;
     void didCompleteWithError(const WebCore::ResourceError&, const WebCore::NetworkLoadMetrics&) final;
     void didSendData(uint64_t totalBytesSent, uint64_t totalBytesExpectedToSend) final;
index 421de34..7a99849 100644 (file)
@@ -68,10 +68,10 @@ void PreconnectTask::willSendRedirectedRequest(ResourceRequest&&, ResourceReques
     ASSERT_NOT_REACHED();
 }
 
-auto PreconnectTask::didReceiveResponse(ResourceResponse&&) -> ShouldContinueDidReceiveResponse
+void PreconnectTask::didReceiveResponse(ResourceResponse&& response, ResponseCompletionHandler&& completionHandler)
 {
     ASSERT_NOT_REACHED();
-    return ShouldContinueDidReceiveResponse::No;
+    completionHandler(PolicyAction::Ignore);
 }
 
 void PreconnectTask::didReceiveBuffer(Ref<SharedBuffer>&&, int reportedEncodedDataLength)
index 213aedf..8f93fdc 100644 (file)
@@ -51,7 +51,7 @@ private:
     bool isAllowedToAskUserForCredentials() const final { return false; }
     void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) final;
     void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse) final;
-    ShouldContinueDidReceiveResponse didReceiveResponse(WebCore::ResourceResponse&&) final;
+    void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) final;
     void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) final;
     void didFinishLoading(const WebCore::NetworkLoadMetrics&) final;
     void didFailLoading(const WebCore::ResourceError&) final;
index 282afd7..7b40ab1 100644 (file)
@@ -80,7 +80,7 @@ void SpeculativeLoad::willSendRedirectedRequest(ResourceRequest&& request, Resou
     didComplete();
 }
 
-auto SpeculativeLoad::didReceiveResponse(ResourceResponse&& receivedResponse) -> ShouldContinueDidReceiveResponse
+void SpeculativeLoad::didReceiveResponse(ResourceResponse&& receivedResponse, ResponseCompletionHandler&& completionHandler)
 {
     m_response = receivedResponse;
 
@@ -93,7 +93,7 @@ auto SpeculativeLoad::didReceiveResponse(ResourceResponse&& receivedResponse) ->
     else
         m_cacheEntry = nullptr;
 
-    return ShouldContinueDidReceiveResponse::Yes;
+    completionHandler(PolicyAction::Use);
 }
 
 void SpeculativeLoad::didReceiveBuffer(Ref<SharedBuffer>&& buffer, int reportedEncodedDataLength)
index 6cab956..6ce77f9 100644 (file)
@@ -56,7 +56,7 @@ private:
     bool isSynchronous() const override { return false; }
     bool isAllowedToAskUserForCredentials() const final { return false; }
     void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse) override;
-    ShouldContinueDidReceiveResponse didReceiveResponse(WebCore::ResourceResponse&&) override;
+    void didReceiveResponse(WebCore::ResourceResponse&&, ResponseCompletionHandler&&) override;
     void didReceiveBuffer(Ref<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override;
     void didFinishLoading(const WebCore::NetworkLoadMetrics&) override;
     void didFailLoading(const WebCore::ResourceError&) override;
index 3db77e7..d56c74e 100644 (file)
@@ -240,7 +240,7 @@ void NetworkDataTaskReplay::didReceiveResponse(WebCore::ResourceResponse&& respo
     DEBUG_LOG("URL = " STRING_SPECIFIER, DEBUG_STR(m_firstRequest.url().string()));
 
     ASSERT(m_client);
-    m_client->didReceiveResponseNetworkSession(WTFMove(response), [this, protectedThis = makeRef(*this)](WebCore::PolicyAction policyAction) {
+    m_client->didReceiveResponse(WTFMove(response), [this, protectedThis = makeRef(*this)](WebCore::PolicyAction policyAction) {
         DEBUG_LOG("didReceiveResponse callback (%u)", static_cast<unsigned>(policyAction));
 
         if (m_state == State::Canceling || m_state == State::Completed) {