Share more code between NETWORK_SESSION and non-NETWORK_SESSION NetworkResourceLoaders
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Nov 2015 00:14:49 +0000 (00:14 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Nov 2015 00:14:49 +0000 (00:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150742

Reviewed by Darin Adler.

r191457 added enough code to NetworkResourceLoader to load most resources successfully if there are no errors.
It passed about 80% of LayoutTests/http and crashed sometimes.
This passes about 95% of LayoutTests/http and does not crash on any of the LayoutTests/http.
It should not change behavior of the non-NETWORK_SESSION code which is currently the default in trunk.

* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::abort):
(WebKit::NetworkResourceLoader::sharedDidReceiveResponse):
(WebKit::NetworkResourceLoader::sharedDidReceiveBuffer):
(WebKit::NetworkResourceLoader::sharedDidFinishLoading):
(WebKit::NetworkResourceLoader::sharedDidFail):
(WebKit::NetworkResourceLoader::sharedWillSendRedirectedRequest):
(WebKit::NetworkResourceLoader::willPerformHTTPRedirection):
(WebKit::NetworkResourceLoader::didReceiveChallenge):
(WebKit::NetworkResourceLoader::didReceiveResponse):
(WebKit::NetworkResourceLoader::didReceiveData):
(WebKit::NetworkResourceLoader::didCompleteWithError):
(WebKit::NetworkResourceLoader::didReceiveResponseAsync):
(WebKit::NetworkResourceLoader::didReceiveBuffer):
(WebKit::NetworkResourceLoader::didFinishLoading):
(WebKit::NetworkResourceLoader::didFail):
(WebKit::NetworkResourceLoader::willSendRequestAsync):
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/NetworkSession.h:
(WebKit::NetworkSessionTaskClient::~NetworkSessionTaskClient):

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

Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.h
Source/WebKit2/NetworkProcess/NetworkSession.h

index d1e24ae7e2d0cd86681b08fb8459329947ddf6ad..b15a52ad37f99d2c85c97b0b28dd0d655ec721f2 100644 (file)
@@ -1,3 +1,36 @@
+2015-10-31  Alex Christensen  <achristensen@webkit.org>
+
+        Share more code between NETWORK_SESSION and non-NETWORK_SESSION NetworkResourceLoaders
+        https://bugs.webkit.org/show_bug.cgi?id=150742
+
+        Reviewed by Darin Adler.
+
+        r191457 added enough code to NetworkResourceLoader to load most resources successfully if there are no errors.
+        It passed about 80% of LayoutTests/http and crashed sometimes.
+        This passes about 95% of LayoutTests/http and does not crash on any of the LayoutTests/http.
+        It should not change behavior of the non-NETWORK_SESSION code which is currently the default in trunk.
+
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::abort):
+        (WebKit::NetworkResourceLoader::sharedDidReceiveResponse):
+        (WebKit::NetworkResourceLoader::sharedDidReceiveBuffer):
+        (WebKit::NetworkResourceLoader::sharedDidFinishLoading):
+        (WebKit::NetworkResourceLoader::sharedDidFail):
+        (WebKit::NetworkResourceLoader::sharedWillSendRedirectedRequest):
+        (WebKit::NetworkResourceLoader::willPerformHTTPRedirection):
+        (WebKit::NetworkResourceLoader::didReceiveChallenge):
+        (WebKit::NetworkResourceLoader::didReceiveResponse):
+        (WebKit::NetworkResourceLoader::didReceiveData):
+        (WebKit::NetworkResourceLoader::didCompleteWithError):
+        (WebKit::NetworkResourceLoader::didReceiveResponseAsync):
+        (WebKit::NetworkResourceLoader::didReceiveBuffer):
+        (WebKit::NetworkResourceLoader::didFinishLoading):
+        (WebKit::NetworkResourceLoader::didFail):
+        (WebKit::NetworkResourceLoader::willSendRequestAsync):
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/NetworkSession.h:
+        (WebKit::NetworkSessionTaskClient::~NetworkSessionTaskClient):
+
 2015-10-28  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Inner height behavior when the keyboard is shown should match on WKWebView and MobileSafari
index 89131b212418b6d45582d922304e8cfae28d2e41..2c50973b808c8f01396e4f01c08c358e6a52074f 100644 (file)
@@ -271,51 +271,8 @@ void NetworkResourceLoader::abort()
     cleanup();
 }
 
-#if USE(NETWORK_SESSION)
-
-void NetworkResourceLoader::willPerformHTTPRedirection(const WebCore::ResourceResponse&, const WebCore::ResourceRequest& request, std::function<void(const WebCore::ResourceRequest&)> completionHandler)
-{
-    notImplemented();
-    completionHandler(request);
-}
-
-void NetworkResourceLoader::didReceiveChallenge(const WebCore::AuthenticationChallenge& challenge, std::function<void(AuthenticationChallengeDisposition, const WebCore::Credential&)> completionHandler)
+NetworkResourceLoader::ShouldContinueDidReceiveResponse NetworkResourceLoader::sharedDidReceiveResponse(const WebCore::ResourceResponse& receivedResponse)
 {
-    notImplemented();
-    completionHandler(AuthenticationChallengeDisposition::PerformDefaultHandling, WebCore::Credential());
-}
-
-void NetworkResourceLoader::didReceiveResponse(WebCore::ResourceResponse& response, std::function<void(ResponseDisposition)> completionHandler)
-{
-    ASSERT(isMainThread());
-    m_response = response;
-    m_response.setSource(ResourceResponse::Source::Network);
-    if (m_parameters.needsCertificateInfo)
-        m_response.includeCertificateInfo();
-    
-    bool shouldWaitContinueDidReceiveResponse = originalRequest().requester() == ResourceRequest::Requester::Main;
-    if (!sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveResponse(m_response, shouldWaitContinueDidReceiveResponse)))
-        return;
-    completionHandler(ResponseDisposition::Allow);
-}
-
-void NetworkResourceLoader::didReceiveData(RefPtr<WebCore::SharedBuffer> buffer)
-{
-    ASSERT(buffer);
-    sendBufferMaybeAborting(*buffer, buffer->size());
-}
-
-void NetworkResourceLoader::didCompleteWithError(const WebCore::ResourceError&)
-{
-    send(Messages::WebResourceLoader::DidFinishResourceLoad(WTF::monotonicallyIncreasingTime()));
-}
-
-#else
-
-void NetworkResourceLoader::didReceiveResponseAsync(ResourceHandle* handle, const ResourceResponse& receivedResponse)
-{
-    ASSERT_UNUSED(handle, handle == m_handle);
-
     m_response = receivedResponse;
 
     m_response.setSource(ResourceResponse::Source::Network);
@@ -350,7 +307,7 @@ void NetworkResourceLoader::didReceiveResponseAsync(ResourceHandle* handle, cons
             m_synchronousLoadData->response = m_response;
         else {
             if (!sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveResponse(m_response, shouldWaitContinueDidReceiveResponse)))
-                return;
+                return ShouldContinueDidReceiveResponse::No;
         }
     }
 
@@ -360,21 +317,12 @@ void NetworkResourceLoader::didReceiveResponseAsync(ResourceHandle* handle, cons
     shouldContinueDidReceiveResponse = shouldContinueDidReceiveResponse || m_cacheEntryForValidation;
 #endif
     if (!shouldContinueDidReceiveResponse)
-        return;
-
-    m_handle->continueDidReceiveResponse();
-}
-
-void NetworkResourceLoader::didReceiveData(ResourceHandle*, const char* /* data */, unsigned /* length */, int /* encodedDataLength */)
-{
-    // The NetworkProcess should never get a didReceiveData callback.
-    // We should always be using didReceiveBuffer.
-    ASSERT_NOT_REACHED();
+        return ShouldContinueDidReceiveResponse::No;
+    return ShouldContinueDidReceiveResponse::Yes;
 }
 
-void NetworkResourceLoader::didReceiveBuffer(ResourceHandle* handle, PassRefPtr<SharedBuffer> buffer, int reportedEncodedDataLength)
+void NetworkResourceLoader::sharedDidReceiveBuffer(RefPtr<WebCore::SharedBuffer>&& buffer, int reportedEncodedDataLength)
 {
-    ASSERT_UNUSED(handle, handle == m_handle);
 #if ENABLE(NETWORK_CACHE)
     ASSERT(!m_cacheEntryForValidation);
 
@@ -400,10 +348,8 @@ void NetworkResourceLoader::didReceiveBuffer(ResourceHandle* handle, PassRefPtr<
     sendBufferMaybeAborting(*buffer, encodedDataLength);
 }
 
-void NetworkResourceLoader::didFinishLoading(ResourceHandle* handle, double finishTime)
+void NetworkResourceLoader::sharedDidFinishLoading(double finishTime)
 {
-    ASSERT_UNUSED(handle, handle == m_handle);
-
 #if ENABLE(NETWORK_CACHE)
     if (NetworkCache::singleton().isEnabled()) {
         if (m_cacheEntryForValidation) {
@@ -457,9 +403,9 @@ void NetworkResourceLoader::didFinishLoading(ResourceHandle* handle, double fini
     cleanup();
 }
 
-void NetworkResourceLoader::didFail(ResourceHandle* handle, const ResourceError& error)
+void NetworkResourceLoader::sharedDidFail(const WebCore::ResourceError& error)
 {
-    ASSERT_UNUSED(handle, !handle || handle == m_handle);
+    ASSERT(!error.isNull());
 
 #if ENABLE(NETWORK_CACHE)
     m_cacheEntryForValidation = nullptr;
@@ -474,10 +420,8 @@ void NetworkResourceLoader::didFail(ResourceHandle* handle, const ResourceError&
     cleanup();
 }
 
-void NetworkResourceLoader::willSendRequestAsync(ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& redirectResponse)
+void NetworkResourceLoader::sharedWillSendRedirectedRequest(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& redirectResponse)
 {
-    ASSERT_UNUSED(handle, handle == m_handle);
-
     // We only expect to get the willSendRequest callback from ResourceHandle as the result of a redirect.
     ASSERT(!redirectResponse.isNull());
     ASSERT(RunLoop::isMain());
@@ -501,6 +445,81 @@ void NetworkResourceLoader::willSendRequestAsync(ResourceHandle* handle, const R
     }
     sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(m_currentRequest, redirectResponse));
 }
+    
+#if USE(NETWORK_SESSION)
+
+void NetworkResourceLoader::willPerformHTTPRedirection(const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, std::function<void(const WebCore::ResourceRequest&)> completionHandler)
+{
+    sharedWillSendRedirectedRequest(request, response);
+    completionHandler(request);
+}
+
+void NetworkResourceLoader::didReceiveChallenge(const WebCore::AuthenticationChallenge& challenge, std::function<void(AuthenticationChallengeDisposition, const WebCore::Credential&)> completionHandler)
+{
+    notImplemented();
+    completionHandler(AuthenticationChallengeDisposition::PerformDefaultHandling, WebCore::Credential());
+}
+
+void NetworkResourceLoader::didReceiveResponse(const WebCore::ResourceResponse& response, std::function<void(ResponseDisposition)> completionHandler)
+{
+    ASSERT(isMainThread());
+    sharedDidReceiveResponse(response);
+    completionHandler(ResponseDisposition::Allow);
+}
+
+void NetworkResourceLoader::didReceiveData(RefPtr<WebCore::SharedBuffer>&& buffer)
+{
+    ASSERT(buffer);
+    sharedDidReceiveBuffer(WTF::move(buffer), buffer->size());
+}
+
+void NetworkResourceLoader::didCompleteWithError(const WebCore::ResourceError& error)
+{
+    if (error.isNull())
+        sharedDidFinishLoading(WTF::monotonicallyIncreasingTime());
+    else
+        sharedDidFail(error);
+}
+
+#else
+
+void NetworkResourceLoader::didReceiveResponseAsync(ResourceHandle* handle, const ResourceResponse& receivedResponse)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    if (sharedDidReceiveResponse(receivedResponse) == ShouldContinueDidReceiveResponse::Yes)
+        m_handle->continueDidReceiveResponse();
+}
+
+void NetworkResourceLoader::didReceiveData(ResourceHandle*, const char* /* data */, unsigned /* length */, int /* encodedDataLength */)
+{
+    // The NetworkProcess should never get a didReceiveData callback.
+    // We should always be using didReceiveBuffer.
+    ASSERT_NOT_REACHED();
+}
+
+void NetworkResourceLoader::didReceiveBuffer(ResourceHandle* handle, PassRefPtr<WebCore::SharedBuffer> buffer, int reportedEncodedDataLength)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    sharedDidReceiveBuffer(WTF::move(buffer), reportedEncodedDataLength);
+}
+
+void NetworkResourceLoader::didFinishLoading(ResourceHandle* handle, double finishTime)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    sharedDidFinishLoading(finishTime);
+}
+
+void NetworkResourceLoader::didFail(ResourceHandle* handle, const ResourceError& error)
+{
+    ASSERT_UNUSED(handle, !handle || handle == m_handle);
+    sharedDidFail(error);
+}
+
+void NetworkResourceLoader::willSendRequestAsync(ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& redirectResponse)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    sharedWillSendRedirectedRequest(request, redirectResponse);
+}
 
 #endif // USE(NETWORK_SESSION)
     
index 2ff835ad60d2e9c049253f3ef1ca2220eb54fa28..44ab90bb50dd054d87704010e2075c130f201318 100644 (file)
@@ -133,12 +133,22 @@ private:
     virtual IPC::Connection* messageSenderConnection() override;
     virtual uint64_t messageSenderDestinationID() override { return m_parameters.identifier; }
 
+    enum ShouldContinueDidReceiveResponse {
+        Yes,
+        No
+    };
+    ShouldContinueDidReceiveResponse sharedDidReceiveResponse(const WebCore::ResourceResponse&);
+        void sharedWillSendRedirectedRequest(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
+    void sharedDidReceiveBuffer(RefPtr<WebCore::SharedBuffer>&&, int reportedEncodedDataLength);
+    void sharedDidFail(const WebCore::ResourceError&);
+    void sharedDidFinishLoading(double finishTime);
+
 #if USE(NETWORK_SESSION)
     // NetworkSessionTaskClient.
     virtual void willPerformHTTPRedirection(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, std::function<void(const WebCore::ResourceRequest&)>) final override;
     virtual void didReceiveChallenge(const WebCore::AuthenticationChallenge&, std::function<void(AuthenticationChallengeDisposition, const WebCore::Credential&)>) final override;
-    virtual void didReceiveResponse(WebCore::ResourceResponse&, std::function<void(ResponseDisposition)>) final override;
-    virtual void didReceiveData(RefPtr<WebCore::SharedBuffer>) final override;
+    virtual void didReceiveResponse(const WebCore::ResourceResponse&, std::function<void(ResponseDisposition)>) final override;
+    virtual void didReceiveData(RefPtr<WebCore::SharedBuffer>&&) final override;
     virtual void didCompleteWithError(const WebCore::ResourceError&) final override;
 #else
     // ResourceHandleClient
index 69a1189070b8ece52c11a0e64318012b26d37dcb..4483e5bfdd7dfea1ba4854a3726c33b1f899063c 100644 (file)
@@ -67,8 +67,8 @@ class NetworkSessionTaskClient {
 public:
     virtual void willPerformHTTPRedirection(const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, std::function<void(const WebCore::ResourceRequest&)>) = 0;
     virtual void didReceiveChallenge(const WebCore::AuthenticationChallenge&, std::function<void(AuthenticationChallengeDisposition, const WebCore::Credential&)>) = 0;
-    virtual void didReceiveResponse(WebCore::ResourceResponse&, std::function<void(ResponseDisposition)>) = 0;
-    virtual void didReceiveData(RefPtr<WebCore::SharedBuffer>) = 0;
+    virtual void didReceiveResponse(const WebCore::ResourceResponse&, std::function<void(ResponseDisposition)>) = 0;
+    virtual void didReceiveData(RefPtr<WebCore::SharedBuffer>&&) = 0;
     virtual void didCompleteWithError(const WebCore::ResourceError&) = 0;
 
     virtual ~NetworkSessionTaskClient() { }