[WK2] Extract networking code out of NetworkResourceLoader class to improve reusability
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 22:39:15 +0000 (22:39 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Nov 2015 22:39:15 +0000 (22:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150898

Reviewed by Alex Christensen.

Extract networking code out of NetworkResourceLoader class to improve
reusability (will be used for speculative revalidation) and simplify
the NetworkResourceLoader.

* CMakeLists.txt:
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
* NetworkProcess/NetworkLoad.cpp: Added.
* NetworkProcess/NetworkLoad.h: Added.
* NetworkProcess/NetworkLoadClient.h: Added.
* NetworkProcess/NetworkLoadParameters.cpp: Added.
* NetworkProcess/NetworkLoadParameters.h: Added.
* NetworkProcess/NetworkResourceLoader.cpp:
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/mac/NetworkLoadMac.mm: Added.
* NetworkProcess/mac/NetworkResourceLoaderMac.mm:
(WebKit::NetworkResourceLoader::willCacheResponseAsync):
* WebKit2.xcodeproj/project.pbxproj:

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

14 files changed:
Source/WebKit2/CMakeLists.txt
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit2/NetworkProcess/NetworkLoad.cpp [new file with mode: 0644]
Source/WebKit2/NetworkProcess/NetworkLoad.h [new file with mode: 0644]
Source/WebKit2/NetworkProcess/NetworkLoadClient.h [new file with mode: 0644]
Source/WebKit2/NetworkProcess/NetworkLoadParameters.cpp [new file with mode: 0644]
Source/WebKit2/NetworkProcess/NetworkLoadParameters.h [new file with mode: 0644]
Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit2/NetworkProcess/NetworkResourceLoader.h
Source/WebKit2/NetworkProcess/mac/NetworkLoadMac.mm [new file with mode: 0644]
Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm
Source/WebKit2/PlatformMac.cmake
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index ded4617..6cd9676 100644 (file)
@@ -162,6 +162,8 @@ endif ()
 
 set(NetworkProcess_COMMON_SOURCES
     NetworkProcess/NetworkConnectionToWebProcess.cpp
+    NetworkProcess/NetworkLoad.cpp
+    NetworkProcess/NetworkLoadParameters.cpp
     NetworkProcess/NetworkProcess.cpp
     NetworkProcess/NetworkProcessPlatformStrategies.cpp
     NetworkProcess/NetworkResourceLoader.cpp
index fa87969..21b179b 100644 (file)
@@ -1,3 +1,29 @@
+2015-11-04  Chris Dumez  <cdumez@apple.com>
+
+        [WK2] Extract networking code out of NetworkResourceLoader class to improve reusability
+        https://bugs.webkit.org/show_bug.cgi?id=150898
+
+        Reviewed by Alex Christensen.
+
+        Extract networking code out of NetworkResourceLoader class to improve
+        reusability (will be used for speculative revalidation) and simplify
+        the NetworkResourceLoader.
+
+        * CMakeLists.txt:
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
+        * NetworkProcess/NetworkLoad.cpp: Added.
+        * NetworkProcess/NetworkLoad.h: Added.
+        * NetworkProcess/NetworkLoadClient.h: Added.
+        * NetworkProcess/NetworkLoadParameters.cpp: Added.
+        * NetworkProcess/NetworkLoadParameters.h: Added.
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/mac/NetworkLoadMac.mm: Added.
+        * NetworkProcess/mac/NetworkResourceLoaderMac.mm:
+        (WebKit::NetworkResourceLoader::willCacheResponseAsync):
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2015-11-04  Beth Dakin  <bdakin@apple.com>
 
         Link preview doesn't work on XHTML pages with Content-Type header as 
index 0a23b7f..2b2152e 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "NetworkBlobRegistry.h"
 #include "NetworkConnectionToWebProcessMessages.h"
+#include "NetworkLoad.h"
 #include "NetworkProcess.h"
 #include "NetworkResourceLoadParameters.h"
 #include "NetworkResourceLoader.h"
@@ -202,10 +203,10 @@ void NetworkConnectionToWebProcess::convertMainResourceLoadToDownload(uint64_t m
     // FIXME: Do something here.
     notImplemented();
 #else
-    networkProcess.downloadManager().convertHandleToDownload(downloadID, loader->handle(), request, response);
+    networkProcess.downloadManager().convertHandleToDownload(downloadID, loader->networkLoad()->handle(), request, response);
 
     // Unblock the URL connection operation queue.
-    loader->handle()->continueDidReceiveResponse();
+    loader->networkLoad()->handle()->continueDidReceiveResponse();
     
     loader->didConvertHandleToDownload();
 #endif
diff --git a/Source/WebKit2/NetworkProcess/NetworkLoad.cpp b/Source/WebKit2/NetworkProcess/NetworkLoad.cpp
new file mode 100644 (file)
index 0000000..0e3ea90
--- /dev/null
@@ -0,0 +1,355 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(NETWORK_PROCESS)
+#include "NetworkLoad.h"
+
+#include "AuthenticationManager.h"
+#include "NetworkProcess.h"
+#include "SessionTracker.h"
+#include "WebErrors.h"
+#include <WebCore/NotImplemented.h>
+#include <WebCore/SessionID.h>
+#include <wtf/MainThread.h>
+
+#if !USE(NETWORK_SESSION)
+#include <WebCore/ResourceHandle.h>
+#endif
+
+namespace WebKit {
+
+using namespace WebCore;
+
+NetworkLoad::NetworkLoad(NetworkLoadClient& client, const NetworkLoadParameters& parameters)
+    : m_client(client)
+    , m_parameters(parameters)
+    , m_networkingContext(RemoteNetworkingContext::create(parameters.sessionID, parameters.shouldClearReferrerOnHTTPSToHTTPRedirect))
+    , m_currentRequest(parameters.request)
+{
+#if USE(NETWORK_SESSION)
+    m_task = SessionTracker::networkSession(parameters.sessionID)->createDataTaskWithRequest(parameters.request, *this);
+    m_task->resume();
+#else
+    m_handle = ResourceHandle::create(m_networkingContext.get(), parameters.request, this, parameters.defersLoading, parameters.contentSniffingPolicy == SniffContent);
+#endif
+}
+
+NetworkLoad::~NetworkLoad()
+{
+    ASSERT(RunLoop::isMain());
+#if USE(NETWORK_SESSION)
+    m_task->clearClient();
+#else
+    if (m_handle)
+        m_handle->clearClient();
+#endif
+}
+
+void NetworkLoad::setDefersLoading(bool defers)
+{
+#if USE(NETWORK_SESSION)
+    // FIXME: Do something here.
+    notImplemented();
+#else
+    if (m_handle)
+        m_handle->setDefersLoading(defers);
+#endif
+}
+
+void NetworkLoad::cancel()
+{
+#if USE(NETWORK_SESSION)
+    m_task->cancel();
+#else
+    if (m_handle)
+        m_handle->cancel();
+#endif
+}
+
+void NetworkLoad::continueWillSendRequest(const WebCore::ResourceRequest& newRequest)
+{
+#if PLATFORM(COCOA)
+    m_currentRequest.updateFromDelegatePreservingOldProperties(newRequest.nsURLRequest(DoNotUpdateHTTPBody));
+#elif USE(SOUP)
+    // FIXME: Implement ResourceRequest::updateFromDelegatePreservingOldProperties. See https://bugs.webkit.org/show_bug.cgi?id=126127.
+    m_currentRequest.updateFromDelegatePreservingOldProperties(newRequest);
+#endif
+
+    if (m_currentRequest.isNull()) {
+#if USE(NETWORK_SESSION)
+        // FIXME: Do something here.
+        notImplemented();
+#else
+        m_handle->cancel();
+        didFail(m_handle.get(), cancelledError(m_currentRequest));
+#endif
+        return;
+    }
+
+#if USE(NETWORK_SESSION)
+    // FIXME: Do something here.
+    notImplemented();
+#else
+    m_handle->continueWillSendRequest(m_currentRequest);
+#endif
+}
+
+void NetworkLoad::continueDidReceiveResponse()
+{
+#if USE(NETWORK_SESSION)
+    // FIXME: Do something here.
+    notImplemented();
+#else
+    m_handle->continueDidReceiveResponse();
+#endif
+}
+
+NetworkLoadClient::ShouldContinueDidReceiveResponse NetworkLoad::sharedDidReceiveResponse(const ResourceResponse& receivedResponse)
+{
+    ResourceResponse response = receivedResponse;
+    response.setSource(ResourceResponse::Source::Network);
+    if (m_parameters.needsCertificateInfo)
+        response.includeCertificateInfo();
+
+    return m_client.didReceiveResponse(response);
+}
+
+void NetworkLoad::sharedWillSendRedirectedRequest(const ResourceRequest& request, const ResourceResponse& redirectResponse)
+{
+    // We only expect to get the willSendRequest callback from ResourceHandle as the result of a redirect.
+    ASSERT(!redirectResponse.isNull());
+    ASSERT(RunLoop::isMain());
+
+    m_currentRequest = request;
+    m_client.willSendRedirectedRequest(request, redirectResponse);
+}
+
+#if USE(NETWORK_SESSION)
+
+void NetworkLoad::willPerformHTTPRedirection(const ResourceResponse& response, const ResourceRequest& request, std::function<void(const ResourceRequest&)> completionHandler)
+{
+    sharedWillSendRedirectedRequest(request, response);
+    completionHandler(request);
+}
+
+void NetworkLoad::didReceiveChallenge(const AuthenticationChallenge& challenge, std::function<void(AuthenticationChallengeDisposition, const Credential&)> completionHandler)
+{
+    notImplemented();
+    completionHandler(AuthenticationChallengeDisposition::PerformDefaultHandling, Credential());
+}
+
+void NetworkLoad::didReceiveResponse(const ResourceResponse& response, std::function<void(ResponseDisposition)> completionHandler)
+{
+    ASSERT(isMainThread());
+    sharedDidReceiveResponse(response);
+    completionHandler(ResponseDisposition::Allow);
+}
+
+void NetworkLoad::didReceiveData(RefPtr<SharedBuffer>&& buffer)
+{
+    ASSERT(buffer);
+    auto size = buffer->size();
+    m_client.didReceiveBuffer(WTF::move(buffer), size);
+}
+
+void NetworkLoad::didCompleteWithError(const ResourceError& error)
+{
+    if (error.isNull())
+        m_client.didFinishLoading(WTF::monotonicallyIncreasingTime());
+    else
+        m_client.didFailLoading(error);
+}
+
+#else
+
+void NetworkLoad::didReceiveResponseAsync(ResourceHandle* handle, const ResourceResponse& receivedResponse)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    if (sharedDidReceiveResponse(receivedResponse) == NetworkLoadClient::ShouldContinueDidReceiveResponse::Yes)
+        m_handle->continueDidReceiveResponse();
+}
+
+void NetworkLoad::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 NetworkLoad::didReceiveBuffer(ResourceHandle* handle, PassRefPtr<SharedBuffer> buffer, int reportedEncodedDataLength)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    m_client.didReceiveBuffer(WTF::move(buffer), reportedEncodedDataLength);
+}
+
+void NetworkLoad::didFinishLoading(ResourceHandle* handle, double finishTime)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    m_client.didFinishLoading(finishTime);
+}
+
+void NetworkLoad::didFail(ResourceHandle* handle, const ResourceError& error)
+{
+    ASSERT_UNUSED(handle, !handle || handle == m_handle);
+    ASSERT(!error.isNull());
+
+    m_client.didFailLoading(error);
+}
+
+void NetworkLoad::willSendRequestAsync(ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& redirectResponse)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    sharedWillSendRedirectedRequest(request, redirectResponse);
+}
+
+#endif // USE(NETWORK_SESSION)
+
+#if USE(PROTECTION_SPACE_AUTH_CALLBACK) && !USE(NETWORK_SESSION)
+void NetworkLoad::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle* handle, const ProtectionSpace& protectionSpace)
+{
+    ASSERT(RunLoop::isMain());
+    ASSERT_UNUSED(handle, handle == m_handle);
+
+    // Handle server trust evaluation at platform-level if requested, for performance reasons.
+    if (protectionSpace.authenticationScheme() == ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested
+        && !NetworkProcess::singleton().canHandleHTTPSServerTrustEvaluation()) {
+        continueCanAuthenticateAgainstProtectionSpace(false);
+        return;
+    }
+
+    if (m_client.isSynchronous()) {
+        // FIXME: We should ask the WebProcess like the asynchronous case below does.
+        // This is currently impossible as the WebProcess is blocked waiting on this synchronous load.
+        // It's possible that we can jump straight to the UI process to resolve this.
+        continueCanAuthenticateAgainstProtectionSpace(true);
+        return;
+    }
+
+    m_client.canAuthenticateAgainstProtectionSpaceAsync(protectionSpace);
+}
+#endif
+
+#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
+void NetworkLoad::continueCanAuthenticateAgainstProtectionSpace(bool result)
+{
+#if USE(NETWORK_SESSION)
+    // FIXME: Do something here.
+    notImplemented();
+#else
+    m_handle->continueCanAuthenticateAgainstProtectionSpace(result);
+#endif
+}
+#endif
+
+#if USE(NETWORK_CFDATA_ARRAY_CALLBACK) && !USE(NETWORK_SESSION)
+bool NetworkLoad::supportsDataArray()
+{
+    notImplemented();
+    return false;
+}
+
+void NetworkLoad::didReceiveDataArray(ResourceHandle*, CFArrayRef)
+{
+    ASSERT_NOT_REACHED();
+    notImplemented();
+}
+#endif
+
+#if !USE(NETWORK_SESSION)
+
+void NetworkLoad::didSendData(ResourceHandle* handle, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+
+    m_client.didSendData(bytesSent, totalBytesToBeSent);
+}
+
+void NetworkLoad::wasBlocked(ResourceHandle* handle)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+
+    didFail(handle, WebKit::blockedError(m_currentRequest));
+}
+
+void NetworkLoad::cannotShowURL(ResourceHandle* handle)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+
+    didFail(handle, WebKit::cannotShowURLError(m_currentRequest));
+}
+
+bool NetworkLoad::shouldUseCredentialStorage(ResourceHandle* handle)
+{
+    ASSERT_UNUSED(handle, handle == m_handle || !m_handle); // m_handle will be 0 if called from ResourceHandle::start().
+
+    // When the WebProcess is handling loading a client is consulted each time this shouldUseCredentialStorage question is asked.
+    // In NetworkProcess mode we ask the WebProcess client up front once and then reuse the cached answer.
+
+    // We still need this sync version, because ResourceHandle itself uses it internally, even when the delegate uses an async one.
+
+    return m_parameters.allowStoredCredentials == AllowStoredCredentials;
+}
+
+void NetworkLoad::didReceiveAuthenticationChallenge(ResourceHandle* handle, const AuthenticationChallenge& challenge)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+    // NetworkResourceLoader does not know whether the request is cross origin, so Web process computes an applicable credential policy for it.
+    ASSERT(m_parameters.clientCredentialPolicy != DoNotAskClientForCrossOriginCredentials);
+
+    if (m_parameters.clientCredentialPolicy == DoNotAskClientForAnyCredentials) {
+        challenge.authenticationClient()->receivedRequestToContinueWithoutCredential(challenge);
+        return;
+    }
+
+    NetworkProcess::singleton().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.webPageID, m_parameters.webFrameID, challenge);
+}
+
+void NetworkLoad::didCancelAuthenticationChallenge(ResourceHandle* handle, const AuthenticationChallenge&)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+
+    // This function is probably not needed (see <rdar://problem/8960124>).
+    notImplemented();
+}
+
+void NetworkLoad::receivedCancellation(ResourceHandle* handle, const AuthenticationChallenge&)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+
+    m_handle->cancel();
+    didFail(m_handle.get(), cancelledError(m_currentRequest));
+}
+
+#endif // !USE(NETWORK_SESSION)
+
+#if PLATFORM(COCOA)
+
+#endif
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
diff --git a/Source/WebKit2/NetworkProcess/NetworkLoad.h b/Source/WebKit2/NetworkProcess/NetworkLoad.h
new file mode 100644 (file)
index 0000000..3747c33
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NetworkLoad_h
+#define NetworkLoad_h
+
+#if ENABLE(NETWORK_PROCESS)
+
+#include "NetworkLoadClient.h"
+#include "NetworkLoadParameters.h"
+#include "RemoteNetworkingContext.h"
+
+#if USE(NETWORK_SESSION)
+#include "NetworkSession.h"
+#else
+#include <WebCore/ResourceHandleClient.h>
+#endif
+
+namespace WebKit {
+
+class NetworkLoad
+#if USE(NETWORK_SESSION)
+    : public NetworkSessionTaskClient
+#else
+    : public WebCore::ResourceHandleClient
+#endif
+{
+public:
+    NetworkLoad(NetworkLoadClient&, const NetworkLoadParameters&);
+    ~NetworkLoad();
+
+    void setDefersLoading(bool);
+    void cancel();
+
+    void clearCurrentRequest() { m_currentRequest = WebCore::ResourceRequest(); }
+
+    void continueWillSendRequest(const WebCore::ResourceRequest&);
+    void continueDidReceiveResponse();
+
+#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(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
+    virtual void willSendRequestAsync(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse) override;
+    virtual void didSendData(WebCore::ResourceHandle*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override;
+    virtual void didReceiveResponseAsync(WebCore::ResourceHandle*, const WebCore::ResourceResponse&) override;
+    virtual void didReceiveData(WebCore::ResourceHandle*, const char*, unsigned, int encodedDataLength) override;
+    virtual void didReceiveBuffer(WebCore::ResourceHandle*, PassRefPtr<WebCore::SharedBuffer>, int encodedDataLength) override;
+    virtual void didFinishLoading(WebCore::ResourceHandle*, double finishTime) override;
+    virtual void didFail(WebCore::ResourceHandle*, const WebCore::ResourceError&) override;
+    virtual void wasBlocked(WebCore::ResourceHandle*) override;
+    virtual void cannotShowURL(WebCore::ResourceHandle*) override;
+    virtual bool shouldUseCredentialStorage(WebCore::ResourceHandle*) override;
+    virtual void didReceiveAuthenticationChallenge(WebCore::ResourceHandle*, const WebCore::AuthenticationChallenge&) override;
+    virtual void didCancelAuthenticationChallenge(WebCore::ResourceHandle*, const WebCore::AuthenticationChallenge&) override;
+    virtual void receivedCancellation(WebCore::ResourceHandle*, const WebCore::AuthenticationChallenge&) override;
+    virtual bool usesAsyncCallbacks() override { return true; }
+    virtual bool loadingSynchronousXHR() override { return m_client.isSynchronous(); }
+
+#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
+    virtual void canAuthenticateAgainstProtectionSpaceAsync(WebCore::ResourceHandle*, const WebCore::ProtectionSpace&) override;
+#endif
+#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
+    virtual bool supportsDataArray() override;
+    virtual void didReceiveDataArray(WebCore::ResourceHandle*, CFArrayRef) override;
+#endif
+#if PLATFORM(COCOA)
+#if USE(CFNETWORK)
+    virtual void willCacheResponseAsync(WebCore::ResourceHandle*, CFCachedURLResponseRef) override;
+#else
+    virtual void willCacheResponseAsync(WebCore::ResourceHandle*, NSCachedURLResponse *) override;
+#endif
+#endif
+#endif // USE(NETWORK_SESSION)
+
+#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
+    void continueCanAuthenticateAgainstProtectionSpace(bool);
+#endif
+
+#if !USE(NETWORK_SESSION)
+    WebCore::ResourceHandle* handle() const { return m_handle.get(); }
+#endif
+
+private:
+    NetworkLoadClient::ShouldContinueDidReceiveResponse sharedDidReceiveResponse(const WebCore::ResourceResponse&);
+    void sharedWillSendRedirectedRequest(const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
+
+    NetworkLoadClient& m_client;
+    const NetworkLoadParameters m_parameters;
+    RefPtr<RemoteNetworkingContext> m_networkingContext;
+#if USE(NETWORK_SESSION)
+    RefPtr<NetworkDataTask> m_task;
+#else
+    RefPtr<WebCore::ResourceHandle> m_handle;
+#endif
+
+    WebCore::ResourceRequest m_currentRequest; // Updated on redirects.
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
+
+#endif // NetworkLoad_h
diff --git a/Source/WebKit2/NetworkProcess/NetworkLoadClient.h b/Source/WebKit2/NetworkProcess/NetworkLoadClient.h
new file mode 100644 (file)
index 0000000..ba486b7
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NetworkLoadClient_h
+#define NetworkLoadClient_h
+
+#if ENABLE(NETWORK_PROCESS)
+
+#include <WebCore/ResourceError.h>
+#include <WebCore/ResourceRequest.h>
+#include <WebCore/ResourceResponse.h>
+#include <WebCore/SharedBuffer.h>
+#include <wtf/Forward.h>
+
+#if PLATFORM(COCOA)
+typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
+#endif
+
+namespace WebCore {
+class ProtectionSpace;
+}
+
+namespace WebKit {
+
+class NetworkLoadClient {
+public:
+    virtual ~NetworkLoadClient() { }
+
+    virtual bool isSynchronous() const = 0;
+
+    virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) = 0;
+    virtual void canAuthenticateAgainstProtectionSpaceAsync(const WebCore::ProtectionSpace&) = 0;
+    virtual void willSendRedirectedRequest(const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse) = 0;
+    enum class ShouldContinueDidReceiveResponse { No, Yes };
+    virtual ShouldContinueDidReceiveResponse didReceiveResponse(const WebCore::ResourceResponse&) = 0;
+    virtual void didReceiveBuffer(RefPtr<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) = 0;
+    virtual void didFinishLoading(double finishTime) = 0;
+    virtual void didFailLoading(const WebCore::ResourceError&) = 0;
+
+#if PLATFORM(COCOA)
+    virtual void willCacheResponseAsync(CFCachedURLResponseRef) = 0;
+#endif
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
+
+#endif // NetworkLoadClient_h
+
diff --git a/Source/WebKit2/NetworkProcess/NetworkLoadParameters.cpp b/Source/WebKit2/NetworkProcess/NetworkLoadParameters.cpp
new file mode 100644 (file)
index 0000000..d0b7b11
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(NETWORK_PROCESS)
+#include "NetworkLoadParameters.h"
+
+#include "NetworkResourceLoadParameters.h"
+
+namespace WebKit {
+
+NetworkLoadParameters::NetworkLoadParameters(const NetworkResourceLoadParameters& parameters)
+    : webPageID(parameters.webPageID)
+    , webFrameID(parameters.webFrameID)
+    , sessionID(parameters.sessionID)
+    , request(parameters.request)
+    , contentSniffingPolicy(parameters.contentSniffingPolicy)
+    , allowStoredCredentials(parameters.allowStoredCredentials)
+    , clientCredentialPolicy(parameters.clientCredentialPolicy)
+    , shouldClearReferrerOnHTTPSToHTTPRedirect(parameters.shouldClearReferrerOnHTTPSToHTTPRedirect)
+    , defersLoading(parameters.defersLoading)
+    , needsCertificateInfo(parameters.needsCertificateInfo)
+{
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
diff --git a/Source/WebKit2/NetworkProcess/NetworkLoadParameters.h b/Source/WebKit2/NetworkProcess/NetworkLoadParameters.h
new file mode 100644 (file)
index 0000000..7cb3762
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NetworkLoadParameters_h
+#define NetworkLoadParameters_h
+
+#if ENABLE(NETWORK_PROCESS)
+
+#include <WebCore/ResourceLoaderOptions.h>
+#include <WebCore/ResourceRequest.h>
+#include <WebCore/SessionID.h>
+
+namespace WebKit {
+
+class NetworkResourceLoadParameters;
+
+class NetworkLoadParameters {
+public:
+    NetworkLoadParameters() = default;
+    NetworkLoadParameters(const NetworkResourceLoadParameters&);
+
+    uint64_t webPageID { 0 };
+    uint64_t webFrameID { 0 };
+    WebCore::SessionID sessionID { WebCore::SessionID::emptySessionID() };
+    WebCore::ResourceRequest request;
+    WebCore::ContentSniffingPolicy contentSniffingPolicy { WebCore::SniffContent };
+    WebCore::StoredCredentials allowStoredCredentials { WebCore::DoNotAllowStoredCredentials };
+    WebCore::ClientCredentialPolicy clientCredentialPolicy { WebCore::DoNotAskClientForAnyCredentials };
+    bool shouldClearReferrerOnHTTPSToHTTPRedirect { true };
+    bool defersLoading { false };
+    bool needsCertificateInfo { false };
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
+
+#endif // NetworkLoadParameters_h
index 0846a50..85d4211 100644 (file)
 
 #if ENABLE(NETWORK_PROCESS)
 
-#include "AuthenticationManager.h"
 #include "DataReference.h"
 #include "Logging.h"
 #include "NetworkBlobRegistry.h"
 #include "NetworkCache.h"
 #include "NetworkConnectionToWebProcess.h"
+#include "NetworkLoad.h"
 #include "NetworkProcess.h"
 #include "NetworkProcessConnectionMessages.h"
 #include "NetworkResourceLoadParameters.h"
-#include "RemoteNetworkingContext.h"
-#include "SessionTracker.h"
 #include "ShareableResource.h"
 #include "SharedMemory.h"
 #include "WebCoreArgumentCoders.h"
-#include "WebErrors.h"
 #include "WebResourceLoaderMessages.h"
 #include <WebCore/BlobDataFileReference.h>
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/HTTPHeaderNames.h>
-#include <WebCore/NotImplemented.h>
+#include <WebCore/ProtectionSpace.h>
 #include <WebCore/SharedBuffer.h>
 #include <WebCore/SynchronousLoaderClient.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/MainThread.h>
 
-#if !USE(NETWORK_SESSION)
-#include <WebCore/ResourceHandle.h>
-#endif
-
 using namespace WebCore;
 
 namespace WebKit {
@@ -120,11 +113,7 @@ NetworkResourceLoader::NetworkResourceLoader(const NetworkResourceLoadParameters
 NetworkResourceLoader::~NetworkResourceLoader()
 {
     ASSERT(RunLoop::isMain());
-#if USE(NETWORK_SESSION)
-    ASSERT(!m_task);
-#else
-    ASSERT(!m_handle);
-#endif
+    ASSERT(!m_networkLoad);
     ASSERT(!isSynchronous() || !m_synchronousLoadData->delayedReply);
 }
 
@@ -140,8 +129,6 @@ void NetworkResourceLoader::start()
     if (m_defersLoading)
         return;
 
-    m_currentRequest = originalRequest();
-
 #if ENABLE(NETWORK_CACHE)
     if (!NetworkCache::singleton().isEnabled() || sessionID().isEphemeral() || !originalRequest().url().protocolIsInHTTPFamily()) {
         startNetworkLoad();
@@ -173,10 +160,8 @@ void NetworkResourceLoader::start()
 #endif
 }
 
-void NetworkResourceLoader::startNetworkLoad()
+void NetworkResourceLoader::startNetworkLoad(const Optional<ResourceRequest>& updatedRequest)
 {
-    m_networkingContext = RemoteNetworkingContext::create(sessionID(), m_parameters.shouldClearReferrerOnHTTPSToHTTPRedirect);
-
     consumeSandboxExtensions();
 
     if (isSynchronous() || m_parameters.maximumBufferingTime > 0_ms)
@@ -187,14 +172,10 @@ void NetworkResourceLoader::startNetworkLoad()
         m_bufferedDataForCache = WebCore::SharedBuffer::create();
 #endif
 
-    bool shouldSniff = m_parameters.contentSniffingPolicy == SniffContent;
-#if USE(NETWORK_SESSION)
-    UNUSED_PARAM(shouldSniff); // FIXME: Use this.
-    m_task = SessionTracker::networkSession(sessionID())->createDataTaskWithRequest(m_currentRequest, *this);
-    m_task->resume();
-#else
-    m_handle = ResourceHandle::create(m_networkingContext.get(), m_currentRequest, this, m_defersLoading, shouldSniff);
-#endif
+    NetworkLoadParameters parameters = m_parameters;
+    if (updatedRequest)
+        parameters.request = updatedRequest.value();
+    m_networkLoad = std::make_unique<NetworkLoad>(*this, parameters);
 }
 
 void NetworkResourceLoader::setDefersLoading(bool defers)
@@ -202,15 +183,9 @@ void NetworkResourceLoader::setDefersLoading(bool defers)
     if (m_defersLoading == defers)
         return;
     m_defersLoading = defers;
-#if USE(NETWORK_SESSION)
-    // FIXME: Do something here.
-    notImplemented();
-#else
-    if (m_handle) {
-        m_handle->setDefersLoading(defers);
-        return;
-    }
-#endif
+
+    m_networkLoad->setDefersLoading(defers);
+
     if (!m_defersLoading)
         start();
 }
@@ -223,42 +198,24 @@ void NetworkResourceLoader::cleanup()
 
     invalidateSandboxExtensions();
 
-#if USE(NETWORK_SESSION)
-    if (m_task) {
-        m_task->clearClient();
-        m_task = nullptr;
-    }
-#else
-    if (m_handle) {
-        m_handle->clearClient();
-        m_handle = nullptr;
-    }
-#endif
+    m_networkLoad = nullptr;
 
     // This will cause NetworkResourceLoader to be destroyed and therefore we do it last.
     m_connection->didCleanupResourceLoader(*this);
 }
 
-#if !USE(NETWORK_SESSION)
 void NetworkResourceLoader::didConvertHandleToDownload()
 {
-    ASSERT(m_handle);
+    ASSERT(m_networkLoad);
     m_didConvertHandleToDownload = true;
 }
-#endif
 
 void NetworkResourceLoader::abort()
 {
     ASSERT(RunLoop::isMain());
 
-#if USE(NETWORK_SESSION)
-    if (m_task)
-        m_task->cancel();
-    // FIXME: Do something with the network cache here.
-    notImplemented();
-#else
-    if (m_handle && !m_didConvertHandleToDownload) {
-        m_handle->cancel();
+    if (m_networkLoad && !m_didConvertHandleToDownload) {
+        m_networkLoad->cancel();
 
 #if ENABLE(NETWORK_CACHE)
         if (NetworkCache::singleton().isEnabled()) {
@@ -268,17 +225,14 @@ void NetworkResourceLoader::abort()
         }
 #endif
     }
-#endif
+
     cleanup();
 }
 
-NetworkResourceLoader::ShouldContinueDidReceiveResponse NetworkResourceLoader::sharedDidReceiveResponse(const WebCore::ResourceResponse& receivedResponse)
+auto NetworkResourceLoader::didReceiveResponse(const ResourceResponse& receivedResponse) -> ShouldContinueDidReceiveResponse
 {
     m_response = receivedResponse;
 
-    m_response.setSource(ResourceResponse::Source::Network);
-    if (m_parameters.needsCertificateInfo)
-        m_response.includeCertificateInfo();
     // For multipart/x-mixed-replace didReceiveResponseAsync gets called multiple times and buffering would require special handling.
     if (!isSynchronous() && m_response.isMultipart())
         m_bufferedData = nullptr;
@@ -322,7 +276,7 @@ NetworkResourceLoader::ShouldContinueDidReceiveResponse NetworkResourceLoader::s
     return ShouldContinueDidReceiveResponse::Yes;
 }
 
-void NetworkResourceLoader::sharedDidReceiveBuffer(RefPtr<WebCore::SharedBuffer>&& buffer, int reportedEncodedDataLength)
+void NetworkResourceLoader::didReceiveBuffer(RefPtr<SharedBuffer>&& buffer, int reportedEncodedDataLength)
 {
 #if ENABLE(NETWORK_CACHE)
     ASSERT(!m_cacheEntryForValidation);
@@ -349,7 +303,7 @@ void NetworkResourceLoader::sharedDidReceiveBuffer(RefPtr<WebCore::SharedBuffer>
     sendBufferMaybeAborting(*buffer, encodedDataLength);
 }
 
-void NetworkResourceLoader::sharedDidFinishLoading(double finishTime)
+void NetworkResourceLoader::didFinishLoading(double finishTime)
 {
 #if ENABLE(NETWORK_CACHE)
     if (NetworkCache::singleton().isEnabled()) {
@@ -404,7 +358,7 @@ void NetworkResourceLoader::sharedDidFinishLoading(double finishTime)
     cleanup();
 }
 
-void NetworkResourceLoader::sharedDidFail(const WebCore::ResourceError& error)
+void NetworkResourceLoader::didFailLoading(const ResourceError& error)
 {
     ASSERT(!error.isNull());
 
@@ -421,221 +375,47 @@ void NetworkResourceLoader::sharedDidFail(const WebCore::ResourceError& error)
     cleanup();
 }
 
-void NetworkResourceLoader::sharedWillSendRedirectedRequest(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& redirectResponse)
+void NetworkResourceLoader::willSendRedirectedRequest(const ResourceRequest& request, const ResourceResponse& redirectResponse)
 {
-    // We only expect to get the willSendRequest callback from ResourceHandle as the result of a redirect.
-    ASSERT(!redirectResponse.isNull());
-    ASSERT(RunLoop::isMain());
-
-    m_currentRequest = request;
-
 #if ENABLE(NETWORK_CACHE)
     WebCore::updateRedirectChainStatus(m_redirectChainCacheStatus, redirectResponse);
 #endif
 
     if (isSynchronous()) {
+        ResourceRequest overridenRequest = request;
         // FIXME: This needs to be fixed to follow the redirect correctly even for cross-domain requests.
         // This includes at least updating host records, and comparing the current request instead of the original request here.
-        if (!protocolHostAndPortAreEqual(originalRequest().url(), m_currentRequest.url())) {
+        if (!protocolHostAndPortAreEqual(originalRequest().url(), request.url())) {
             ASSERT(m_synchronousLoadData->error.isNull());
             m_synchronousLoadData->error = SynchronousLoaderClient::platformBadResponseError();
-            m_currentRequest = ResourceRequest();
+            m_networkLoad->clearCurrentRequest();
+            overridenRequest = ResourceRequest();
         }
-        continueWillSendRequest(m_currentRequest);
+        continueWillSendRequest(overridenRequest);
         return;
     }
-    sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(m_currentRequest, redirectResponse));
+    sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(request, 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);
-    auto size = buffer->size();
-    sharedDidReceiveBuffer(WTF::move(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)
-    
 void NetworkResourceLoader::continueWillSendRequest(const ResourceRequest& newRequest)
 {
-#if PLATFORM(COCOA)
-    m_currentRequest.updateFromDelegatePreservingOldProperties(newRequest.nsURLRequest(DoNotUpdateHTTPBody));
-#elif USE(SOUP)
-    // FIXME: Implement ResourceRequest::updateFromDelegatePreservingOldProperties. See https://bugs.webkit.org/show_bug.cgi?id=126127.
-    m_currentRequest.updateFromDelegatePreservingOldProperties(newRequest);
-#endif
-
-    if (m_currentRequest.isNull()) {
-#if USE(NETWORK_SESSION)
-        // FIXME: Do something here.
-        notImplemented();
-#else
-        m_handle->cancel();
-        didFail(m_handle.get(), cancelledError(m_currentRequest));
-#endif
-        return;
-    }
-
-#if USE(NETWORK_SESSION)
-    // FIXME: Do something here.
-    notImplemented();
-#else
-    m_handle->continueWillSendRequest(m_currentRequest);
-#endif
+    m_networkLoad->continueWillSendRequest(newRequest);
 }
 
 void NetworkResourceLoader::continueDidReceiveResponse()
 {
     // 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 USE(NETWORK_SESSION)
-    // FIXME: Do something here.
-    notImplemented();
-#else
-    if (!m_handle)
-        return;
-
-    m_handle->continueDidReceiveResponse();
-#endif
+    if (m_networkLoad)
+        m_networkLoad->continueDidReceiveResponse();
 }
 
-#if !USE(NETWORK_SESSION)
-
-void NetworkResourceLoader::didSendData(ResourceHandle* handle, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
+void NetworkResourceLoader::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
 {
-    ASSERT_UNUSED(handle, handle == m_handle);
-
     if (!isSynchronous())
         send(Messages::WebResourceLoader::DidSendData(bytesSent, totalBytesToBeSent));
 }
 
-void NetworkResourceLoader::wasBlocked(ResourceHandle* handle)
-{
-    ASSERT_UNUSED(handle, handle == m_handle);
-
-    didFail(handle, WebKit::blockedError(m_currentRequest));
-}
-
-void NetworkResourceLoader::cannotShowURL(ResourceHandle* handle)
-{
-    ASSERT_UNUSED(handle, handle == m_handle);
-
-    didFail(handle, WebKit::cannotShowURLError(m_currentRequest));
-}
-
-bool NetworkResourceLoader::shouldUseCredentialStorage(ResourceHandle* handle)
-{
-    ASSERT_UNUSED(handle, handle == m_handle || !m_handle); // m_handle will be 0 if called from ResourceHandle::start().
-
-    // When the WebProcess is handling loading a client is consulted each time this shouldUseCredentialStorage question is asked.
-    // In NetworkProcess mode we ask the WebProcess client up front once and then reuse the cached answer.
-
-    // We still need this sync version, because ResourceHandle itself uses it internally, even when the delegate uses an async one.
-
-    return m_parameters.allowStoredCredentials == AllowStoredCredentials;
-}
-
-void NetworkResourceLoader::didReceiveAuthenticationChallenge(ResourceHandle* handle, const AuthenticationChallenge& challenge)
-{
-    ASSERT_UNUSED(handle, handle == m_handle);
-    // NetworkResourceLoader does not know whether the request is cross origin, so Web process computes an applicable credential policy for it.
-    ASSERT(m_parameters.clientCredentialPolicy != DoNotAskClientForCrossOriginCredentials);
-
-    if (m_parameters.clientCredentialPolicy == DoNotAskClientForAnyCredentials) {
-        challenge.authenticationClient()->receivedRequestToContinueWithoutCredential(challenge);
-        return;
-    }
-
-    NetworkProcess::singleton().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.webPageID, m_parameters.webFrameID, challenge);
-}
-
-void NetworkResourceLoader::didCancelAuthenticationChallenge(ResourceHandle* handle, const AuthenticationChallenge&)
-{
-    ASSERT_UNUSED(handle, handle == m_handle);
-
-    // This function is probably not needed (see <rdar://problem/8960124>).
-    notImplemented();
-}
-
-void NetworkResourceLoader::receivedCancellation(ResourceHandle* handle, const AuthenticationChallenge&)
-{
-    ASSERT_UNUSED(handle, handle == m_handle);
-
-    m_handle->cancel();
-    didFail(m_handle.get(), cancelledError(m_currentRequest));
-}
-
-#endif // !USE(NETWORK_SESSION)
-
 void NetworkResourceLoader::startBufferingTimerIfNeeded()
 {
     if (isSynchronous())
@@ -648,9 +428,8 @@ void NetworkResourceLoader::startBufferingTimerIfNeeded()
 void NetworkResourceLoader::bufferingTimerFired()
 {
     ASSERT(m_bufferedData);
-#if !USE(NETWORK_SESSION)
-    ASSERT(m_handle);
-#endif
+    ASSERT(m_networkLoad);
+
     if (!m_bufferedData->size())
         return;
 
@@ -718,24 +497,23 @@ void NetworkResourceLoader::didRetrieveCacheEntry(std::unique_ptr<NetworkCache::
 
 void NetworkResourceLoader::validateCacheEntry(std::unique_ptr<NetworkCache::Entry> entry)
 {
-#if !USE(NETWORK_SESSION)
-    ASSERT(!m_handle);
-#endif
+    ASSERT(!m_networkLoad);
 
     // If the request is already conditional then the revalidation was not triggered by the disk cache
     // and we should not overwrite the existing conditional headers.
-    if (!m_currentRequest.isConditional()) {
+    ResourceRequest revalidationRequest = originalRequest();
+    if (!revalidationRequest.isConditional()) {
         String eTag = entry->response().httpHeaderField(WebCore::HTTPHeaderName::ETag);
         String lastModified = entry->response().httpHeaderField(WebCore::HTTPHeaderName::LastModified);
         if (!eTag.isEmpty())
-            m_currentRequest.setHTTPHeaderField(WebCore::HTTPHeaderName::IfNoneMatch, eTag);
+            revalidationRequest.setHTTPHeaderField(WebCore::HTTPHeaderName::IfNoneMatch, eTag);
         if (!lastModified.isEmpty())
-            m_currentRequest.setHTTPHeaderField(WebCore::HTTPHeaderName::IfModifiedSince, lastModified);
+            revalidationRequest.setHTTPHeaderField(WebCore::HTTPHeaderName::IfModifiedSince, lastModified);
     }
 
     m_cacheEntryForValidation = WTF::move(entry);
 
-    startNetworkLoad();
+    startNetworkLoad(revalidationRequest);
 }
 #endif
 
@@ -783,53 +561,19 @@ bool NetworkResourceLoader::sendAbortingOnFailure(T&& message, unsigned messageS
     return result;
 }
 
-#if USE(PROTECTION_SPACE_AUTH_CALLBACK) && !USE(NETWORK_SESSION)
-void NetworkResourceLoader::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle* handle, const ProtectionSpace& protectionSpace)
+void NetworkResourceLoader::canAuthenticateAgainstProtectionSpaceAsync(const ProtectionSpace& protectionSpace)
 {
-    ASSERT(RunLoop::isMain());
-    ASSERT_UNUSED(handle, handle == m_handle);
-
-    // Handle server trust evaluation at platform-level if requested, for performance reasons.
-    if (protectionSpace.authenticationScheme() == ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested
-        && !NetworkProcess::singleton().canHandleHTTPSServerTrustEvaluation()) {
-        continueCanAuthenticateAgainstProtectionSpace(false);
-        return;
-    }
-
-    if (isSynchronous()) {
-        // FIXME: We should ask the WebProcess like the asynchronous case below does.
-        // This is currently impossible as the WebProcess is blocked waiting on this synchronous load.
-        // It's possible that we can jump straight to the UI process to resolve this.
-        continueCanAuthenticateAgainstProtectionSpace(true);
-        return;
-    }
-    sendAbortingOnFailure(Messages::WebResourceLoader::CanAuthenticateAgainstProtectionSpace(protectionSpace));
-}
-#endif
-
 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-void NetworkResourceLoader::continueCanAuthenticateAgainstProtectionSpace(bool result)
-{
-#if USE(NETWORK_SESSION)
-    // FIXME: Do something here.
-    notImplemented();
+    sendAbortingOnFailure(Messages::WebResourceLoader::CanAuthenticateAgainstProtectionSpace(protectionSpace));
 #else
-    m_handle->continueCanAuthenticateAgainstProtectionSpace(result);
-#endif
-}
+    UNUSED_PARAM(protectionSpace);
 #endif
-
-#if USE(NETWORK_CFDATA_ARRAY_CALLBACK) && !USE(NETWORK_SESSION)
-bool NetworkResourceLoader::supportsDataArray()
-{
-    notImplemented();
-    return false;
 }
 
-void NetworkResourceLoader::didReceiveDataArray(ResourceHandle*, CFArrayRef)
+#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
+void NetworkResourceLoader::continueCanAuthenticateAgainstProtectionSpace(bool result)
 {
-    ASSERT_NOT_REACHED();
-    notImplemented();
+    m_networkLoad->continueCanAuthenticateAgainstProtectionSpace(result);
 }
 #endif
 
index 8b423dc..0e9e909 100644 (file)
 #include "MessageSender.h"
 #include "NetworkCache.h"
 #include "NetworkConnectionToWebProcessMessages.h"
+#include "NetworkLoadClient.h"
 #include "NetworkResourceLoadParameters.h"
 #include "ShareableResource.h"
 #include <WebCore/CacheValidation.h>
-#include <WebCore/ResourceError.h>
 #include <WebCore/ResourceLoaderOptions.h>
-#include <WebCore/ResourceRequest.h>
-#include <WebCore/ResourceResponse.h>
 #include <WebCore/SessionID.h>
 #include <WebCore/Timer.h>
-#include <wtf/MainThread.h>
-#include <wtf/RunLoop.h>
-
-#if USE(NETWORK_SESSION)
-#include "NetworkSession.h"
-#else
-#include <WebCore/ResourceHandleClient.h>
-#endif
-
-typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
+#include <wtf/Optional.h>
 
 namespace WebCore {
 class BlobDataFileReference;
-#if !USE(NETWORK_SESSION)
-class ResourceHandle;
-#endif
 class ResourceRequest;
 }
 
@@ -63,16 +49,12 @@ namespace WebKit {
 
 class NetworkConnectionToWebProcess;
 class NetworkResourceLoadParameters;
-class RemoteNetworkingContext;
+class NetworkLoad;
 class SandboxExtension;
 
 class NetworkResourceLoader
     : public RefCounted<NetworkResourceLoader>
-#if USE(NETWORK_SESSION)
-    , public NetworkSessionTaskClient
-#else
-    , public WebCore::ResourceHandleClient
-#endif
+    , public NetworkLoadClient
     , public IPC::MessageSender {
 public:
     static Ref<NetworkResourceLoader> create(const NetworkResourceLoadParameters& parameters, NetworkConnectionToWebProcess* connection)
@@ -88,12 +70,8 @@ public:
 
     const WebCore::ResourceRequest& originalRequest() const { return m_parameters.request; }
 
-    // Changes with redirects.
-    WebCore::ResourceRequest& currentRequest() { return m_currentRequest; }
+    NetworkLoad* networkLoad() const { return m_networkLoad.get(); }
 
-#if !USE(NETWORK_SESSION)
-    WebCore::ResourceHandle* handle() const { return m_handle.get(); }
-#endif
     void didConvertHandleToDownload();
 
     void start();
@@ -103,7 +81,9 @@ public:
 
 #if PLATFORM(COCOA)
     static size_t fileBackedResourceMinimumSize();
+    virtual void willCacheResponseAsync(CFCachedURLResponseRef) override;
 #endif
+
     // Message handlers.
     void didReceiveNetworkResourceLoaderMessage(IPC::Connection&, IPC::MessageDecoder&);
 
@@ -126,6 +106,16 @@ public:
 
     struct SynchronousLoadData;
 
+    // NetworkLoadClient.
+    virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override;
+    virtual void canAuthenticateAgainstProtectionSpaceAsync(const WebCore::ProtectionSpace&) override;
+    virtual bool isSynchronous() const override;
+    virtual void willSendRedirectedRequest(const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse) override;
+    virtual ShouldContinueDidReceiveResponse didReceiveResponse(const WebCore::ResourceResponse&) override;
+    virtual void didReceiveBuffer(RefPtr<WebCore::SharedBuffer>&&, int reportedEncodedDataLength) override;
+    virtual void didFinishLoading(double finishTime) override;
+    virtual void didFailLoading(const WebCore::ResourceError&) override;
+
 private:
     NetworkResourceLoader(const NetworkResourceLoadParameters&, NetworkConnectionToWebProcess*, PassRefPtr<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>);
 
@@ -133,63 +123,12 @@ 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(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
-    virtual void willSendRequestAsync(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse) override;
-    virtual void didSendData(WebCore::ResourceHandle*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override;
-    virtual void didReceiveResponseAsync(WebCore::ResourceHandle*, const WebCore::ResourceResponse&) override;
-    virtual void didReceiveData(WebCore::ResourceHandle*, const char*, unsigned, int encodedDataLength) override;
-    virtual void didReceiveBuffer(WebCore::ResourceHandle*, PassRefPtr<WebCore::SharedBuffer>, int encodedDataLength) override;
-    virtual void didFinishLoading(WebCore::ResourceHandle*, double finishTime) override;
-    virtual void didFail(WebCore::ResourceHandle*, const WebCore::ResourceError&) override;
-    virtual void wasBlocked(WebCore::ResourceHandle*) override;
-    virtual void cannotShowURL(WebCore::ResourceHandle*) override;
-    virtual bool shouldUseCredentialStorage(WebCore::ResourceHandle*) override;
-    virtual void didReceiveAuthenticationChallenge(WebCore::ResourceHandle*, const WebCore::AuthenticationChallenge&) override;
-    virtual void didCancelAuthenticationChallenge(WebCore::ResourceHandle*, const WebCore::AuthenticationChallenge&) override;
-    virtual void receivedCancellation(WebCore::ResourceHandle*, const WebCore::AuthenticationChallenge&) override;
-    virtual bool usesAsyncCallbacks() override { return true; }
-    virtual bool loadingSynchronousXHR() override { return isSynchronous(); }
-
-#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
-    virtual void canAuthenticateAgainstProtectionSpaceAsync(WebCore::ResourceHandle*, const WebCore::ProtectionSpace&) override;
-#endif
-#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
-    virtual bool supportsDataArray() override;
-    virtual void didReceiveDataArray(WebCore::ResourceHandle*, CFArrayRef) override;
-#endif
-#if PLATFORM(COCOA)
-#if USE(CFNETWORK)
-    virtual void willCacheResponseAsync(WebCore::ResourceHandle*, CFCachedURLResponseRef) override;
-#else
-    virtual void willCacheResponseAsync(WebCore::ResourceHandle*, NSCachedURLResponse *) override;
-#endif
-#endif
-#endif // USE(NETWORK_SESSION)
-
 #if ENABLE(NETWORK_CACHE)
     void didRetrieveCacheEntry(std::unique_ptr<NetworkCache::Entry>);
     void validateCacheEntry(std::unique_ptr<NetworkCache::Entry>);
 #endif
 
-    void startNetworkLoad();
+    void startNetworkLoad(const Optional<WebCore::ResourceRequest>& updatedRequest = { });
     void continueDidReceiveResponse();
 
     void cleanup();
@@ -200,8 +139,6 @@ private:
     void bufferingTimerFired();
     bool sendBufferMaybeAborting(const WebCore::SharedBuffer&, size_t encodedDataLength);
 
-    bool isSynchronous() const;
-
     void consumeSandboxExtensions();
     void invalidateSandboxExtensions();
 
@@ -211,14 +148,8 @@ private:
 
     RefPtr<NetworkConnectionToWebProcess> m_connection;
 
-    RefPtr<RemoteNetworkingContext> m_networkingContext;
-#if USE(NETWORK_SESSION)
-    RefPtr<NetworkDataTask> m_task;
-#else
-    RefPtr<WebCore::ResourceHandle> m_handle;
-#endif
+    std::unique_ptr<NetworkLoad> m_networkLoad;
 
-    WebCore::ResourceRequest m_currentRequest;
     WebCore::ResourceResponse m_response;
 
     size_t m_bytesReceived;
diff --git a/Source/WebKit2/NetworkProcess/mac/NetworkLoadMac.mm b/Source/WebKit2/NetworkProcess/mac/NetworkLoadMac.mm
new file mode 100644 (file)
index 0000000..f98e490
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if ENABLE(NETWORK_PROCESS)
+#import "NetworkLoad.h"
+
+#import <WebCore/CFNetworkSPI.h>
+#import <WebCore/ResourceHandle.h>
+
+namespace WebKit {
+
+using namespace WebCore;
+
+#if USE(CFNETWORK)
+
+void NetworkLoad::willCacheResponseAsync(ResourceHandle* handle, CFCachedURLResponseRef cfResponse)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+
+    m_client.willCacheResponseAsync(cfResponse);
+
+    m_handle->continueWillCacheResponse(cfResponse);
+}
+
+#elif !USE(NETWORK_SESSION)
+
+void NetworkLoad::willCacheResponseAsync(ResourceHandle* handle, NSCachedURLResponse *nsResponse)
+{
+    ASSERT_UNUSED(handle, handle == m_handle);
+
+    m_client.willCacheResponseAsync([nsResponse _CFCachedURLResponse]);
+
+    m_handle->continueWillCacheResponse(nsResponse);
+}
+
+#endif // !USE(CFNETWORK)
+
+} // namespace WebKit
+
+#endif // ENABLE(NETWORK_PROCESS)
index f82227a..8a286e6 100644 (file)
@@ -33,6 +33,7 @@
 #import <WebCore/CFNetworkSPI.h>
 #import <WebCore/ResourceHandle.h>
 #import <WebCore/SharedBuffer.h>
+#import <wtf/MainThread.h>
 
 using namespace WebCore;
 
@@ -82,32 +83,12 @@ size_t NetworkResourceLoader::fileBackedResourceMinimumSize()
     return SharedMemory::systemPageSize();
 }
 
-#if USE(CFNETWORK)
-
-void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, CFCachedURLResponseRef cfResponse)
+void NetworkResourceLoader::willCacheResponseAsync(CFCachedURLResponseRef cfResponse)
 {
-    ASSERT_UNUSED(handle, handle == m_handle);
-
     if (m_bytesReceived >= fileBackedResourceMinimumSize())
         NetworkDiskCacheMonitor::monitorFileBackingStoreCreation(cfResponse, this);
-
-    m_handle->continueWillCacheResponse(cfResponse);
 }
 
-#elif !USE(NETWORK_SESSION)
-
-void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, NSCachedURLResponse *nsResponse)
-{
-    ASSERT_UNUSED(handle, handle == m_handle);
-
-    if (m_bytesReceived >= fileBackedResourceMinimumSize())
-        NetworkDiskCacheMonitor::monitorFileBackingStoreCreation([nsResponse _CFCachedURLResponse], this);
-
-    m_handle->continueWillCacheResponse(nsResponse);
-}
-
-#endif // !USE(CFNETWORK)
-
 } // namespace WebKit
 
 #endif // ENABLE(NETWORK_PROCESS)
index 6c65fcc..3f5d2e4 100644 (file)
@@ -18,6 +18,7 @@ list(APPEND WebKit2_SOURCES
     NetworkProcess/cocoa/NetworkProcessCocoa.mm
 
     NetworkProcess/mac/NetworkDiskCacheMonitor.mm
+    NetworkProcess/mac/NetworkLoadMac.mm
     NetworkProcess/mac/NetworkProcessMac.mm
     NetworkProcess/mac/NetworkResourceLoaderMac.mm
     NetworkProcess/mac/RemoteNetworkingContext.mm
index 33584a0..35d974f 100644 (file)
                834B25121A842C8700CFB150 /* NetworkCacheStatistics.h in Headers */ = {isa = PBXBuildFile; fileRef = 834B25101A842C8700CFB150 /* NetworkCacheStatistics.h */; };
                8360349F1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */; };
                836034A01ACB34D600626549 /* WebSQLiteDatabaseTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */; };
+               836EEB801BE9EC9E006B4B82 /* NetworkLoadMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 836EEB7F1BE9EC9E006B4B82 /* NetworkLoadMac.mm */; };
                8372DB251A674C8F00C697C5 /* WKPageDiagnosticLoggingClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 8372DB241A674C8F00C697C5 /* WKPageDiagnosticLoggingClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                8372DB281A67562800C697C5 /* WebPageDiagnosticLoggingClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8372DB261A67562800C697C5 /* WebPageDiagnosticLoggingClient.cpp */; };
                8372DB291A67562800C697C5 /* WebPageDiagnosticLoggingClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 8372DB271A67562800C697C5 /* WebPageDiagnosticLoggingClient.h */; };
                83891B691A68BEBC0030F386 /* _WKDiagnosticLoggingDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 83891B681A68BEBC0030F386 /* _WKDiagnosticLoggingDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                83891B6C1A68C30B0030F386 /* DiagnosticLoggingClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 83891B6A1A68C30B0030F386 /* DiagnosticLoggingClient.h */; };
                83891B6D1A68C30B0030F386 /* DiagnosticLoggingClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83891B6B1A68C30B0030F386 /* DiagnosticLoggingClient.mm */; };
+               839149641BEA838500D2D953 /* NetworkLoadParameters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 839149621BEA838500D2D953 /* NetworkLoadParameters.cpp */; };
+               839149651BEA838500D2D953 /* NetworkLoadParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 839149631BEA838500D2D953 /* NetworkLoadParameters.h */; };
+               839902021BE9A02B000F3653 /* NetworkLoad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 839901FF1BE9A01B000F3653 /* NetworkLoad.cpp */; };
+               839902031BE9A02B000F3653 /* NetworkLoad.h in Headers */ = {isa = PBXBuildFile; fileRef = 839901FE1BE9A01B000F3653 /* NetworkLoad.h */; };
                83BDCCB91AC5FDB6003F6441 /* NetworkCacheStatistics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83BDCCB81AC5FDB6003F6441 /* NetworkCacheStatistics.cpp */; };
+               83D454D71BE9D3C4006C93BD /* NetworkLoadClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D454D61BE9D3C4006C93BD /* NetworkLoadClient.h */; };
                84477853176FCC0800CDC7BB /* InjectedBundleHitTestResultMediaType.h in Headers */ = {isa = PBXBuildFile; fileRef = 84477851176FCAC100CDC7BB /* InjectedBundleHitTestResultMediaType.h */; };
                868160D0187645570021E79D /* WindowServerConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 868160CF187645370021E79D /* WindowServerConnection.mm */; };
                86E67A251910B9D100004AB7 /* ProcessThrottler.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E67A21190F411800004AB7 /* ProcessThrottler.h */; };
                834B25101A842C8700CFB150 /* NetworkCacheStatistics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheStatistics.h; sourceTree = "<group>"; };
                8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSQLiteDatabaseTracker.cpp; sourceTree = "<group>"; };
                8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSQLiteDatabaseTracker.h; sourceTree = "<group>"; };
+               836EEB7F1BE9EC9E006B4B82 /* NetworkLoadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkLoadMac.mm; sourceTree = "<group>"; };
                8372DB241A674C8F00C697C5 /* WKPageDiagnosticLoggingClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPageDiagnosticLoggingClient.h; sourceTree = "<group>"; };
                8372DB261A67562800C697C5 /* WebPageDiagnosticLoggingClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPageDiagnosticLoggingClient.cpp; sourceTree = "<group>"; };
                8372DB271A67562800C697C5 /* WebPageDiagnosticLoggingClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPageDiagnosticLoggingClient.h; sourceTree = "<group>"; };
                83891B681A68BEBC0030F386 /* _WKDiagnosticLoggingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKDiagnosticLoggingDelegate.h; sourceTree = "<group>"; };
                83891B6A1A68C30B0030F386 /* DiagnosticLoggingClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiagnosticLoggingClient.h; sourceTree = "<group>"; };
                83891B6B1A68C30B0030F386 /* DiagnosticLoggingClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DiagnosticLoggingClient.mm; sourceTree = "<group>"; };
+               839149621BEA838500D2D953 /* NetworkLoadParameters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkLoadParameters.cpp; path = NetworkProcess/NetworkLoadParameters.cpp; sourceTree = "<group>"; };
+               839149631BEA838500D2D953 /* NetworkLoadParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkLoadParameters.h; path = NetworkProcess/NetworkLoadParameters.h; sourceTree = "<group>"; };
+               839901FE1BE9A01B000F3653 /* NetworkLoad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkLoad.h; path = NetworkProcess/NetworkLoad.h; sourceTree = "<group>"; };
+               839901FF1BE9A01B000F3653 /* NetworkLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkLoad.cpp; path = NetworkProcess/NetworkLoad.cpp; sourceTree = "<group>"; };
                83BDCCB81AC5FDB6003F6441 /* NetworkCacheStatistics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheStatistics.cpp; sourceTree = "<group>"; };
+               83D454D61BE9D3C4006C93BD /* NetworkLoadClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkLoadClient.h; path = NetworkProcess/NetworkLoadClient.h; sourceTree = "<group>"; };
                84477851176FCAC100CDC7BB /* InjectedBundleHitTestResultMediaType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundleHitTestResultMediaType.h; sourceTree = "<group>"; };
                868160CD18763D4B0021E79D /* WindowServerConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WindowServerConnection.h; sourceTree = "<group>"; };
                868160CF187645370021E79D /* WindowServerConnection.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WindowServerConnection.mm; sourceTree = "<group>"; };
                                513A16491630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp */,
                                513A164A1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h */,
                                513A164B1630A9BF005D7D22 /* NetworkConnectionToWebProcess.messages.in */,
+                               839901FF1BE9A01B000F3653 /* NetworkLoad.cpp */,
+                               839901FE1BE9A01B000F3653 /* NetworkLoad.h */,
+                               83D454D61BE9D3C4006C93BD /* NetworkLoadClient.h */,
+                               839149621BEA838500D2D953 /* NetworkLoadParameters.cpp */,
+                               839149631BEA838500D2D953 /* NetworkLoadParameters.h */,
                                510CC7DF16138E2900D03ED3 /* NetworkProcess.cpp */,
                                510CC7E016138E2900D03ED3 /* NetworkProcess.h */,
                                51A8A6171627F5BB000D90E9 /* NetworkProcess.messages.in */,
                                E17AE2C116B9C139001C42F1 /* com.apple.WebKit.NetworkProcess.sb.in */,
                                5167EE9E170377BF007681CA /* NetworkDiskCacheMonitor.h */,
                                5167EE9F170377BF007681CA /* NetworkDiskCacheMonitor.mm */,
+                               836EEB7F1BE9EC9E006B4B82 /* NetworkLoadMac.mm */,
                                51A8A6151627F3F9000D90E9 /* NetworkProcessMac.mm */,
                                51E3B67E16F266B3009968DC /* NetworkResourceLoaderMac.mm */,
                                E1B78472163F253E0007B692 /* RemoteNetworkingContext.mm */,
                                376311FD1A3FB5F7005A2E51 /* _WKSameDocumentNavigationType.h in Headers */,
                                376311FE1A3FB600005A2E51 /* _WKSameDocumentNavigationTypeInternal.h in Headers */,
                                1A002D44196B338900B9AD44 /* _WKSessionState.h in Headers */,
+                               839902031BE9A02B000F3653 /* NetworkLoad.h in Headers */,
                                1A002D43196B337000B9AD44 /* _WKSessionStateInternal.h in Headers */,
                                2D6B371B18A967AD0042AE80 /* _WKThumbnailView.h in Headers */,
                                2DACE64E18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h in Headers */,
                                1A8EF4CB1252403700F7067F /* PluginControllerProxy.h in Headers */,
                                1A8EF96F1252AF6B00F7067F /* PluginControllerProxyMessages.h in Headers */,
                                1A179780137EE82C00F97D45 /* PluginCreationParameters.h in Headers */,
+                               83D454D71BE9D3C4006C93BD /* NetworkLoadClient.h in Headers */,
                                7C3F8C91173AF52D007B7F39 /* PluginInformation.h in Headers */,
                                1AEFCC1211D01F96008219D3 /* PluginInfoStore.h in Headers */,
                                1A3D610213A7CC2A00F95D4E /* PluginModuleInfo.h in Headers */,
                                1AAB4A8D1296F0A20023952F /* SandboxExtension.h in Headers */,
                                E1E552C516AE065F004ED653 /* SandboxInitializationParameters.h in Headers */,
                                0F931C1C18C5711900DBA7C3 /* ScrollingTreeOverflowScrollingNodeIOS.h in Headers */,
+                               839149651BEA838500D2D953 /* NetworkLoadParameters.h in Headers */,
                                51D130541382EAC000351EDD /* SecItemRequestData.h in Headers */,
                                51D130561382EAC000351EDD /* SecItemResponseData.h in Headers */,
                                E179088F169BAA6A006904C7 /* SecItemShim.h in Headers */,
                                BC032DA510F437D10058C15A /* ArgumentDecoder.cpp in Sources */,
                                BC032DA710F437D10058C15A /* ArgumentEncoder.cpp in Sources */,
                                C59C4A5818B81174007BDCB6 /* AssistedNodeInformation.cpp in Sources */,
+                               839902021BE9A02B000F3653 /* NetworkLoad.cpp in Sources */,
                                515E7727183DD6F60007203F /* AsyncRequest.cpp in Sources */,
                                BCEE966C112FAF57006BCC24 /* Attachment.cpp in Sources */,
                                E1A31735134CEA80007C9A4F /* AttributedString.mm in Sources */,
                                9F54F88F16488E87007DF81A /* ChildProcessMac.mm in Sources */,
                                51FAEC3B1B0657680009C4E7 /* ChildProcessMessageReceiver.cpp in Sources */,
                                E1513C66166EABB200149FCB /* ChildProcessProxy.cpp in Sources */,
+                               839149641BEA838500D2D953 /* NetworkLoadParameters.cpp in Sources */,
                                1A2A4B0E1586A2240090C9E9 /* ColorSpaceData.mm in Sources */,
                                1A6F9FB711E1408500DB1371 /* CommandLinePOSIX.cpp in Sources */,
                                37BEC4E019491486008B4286 /* CompletionHandlerCallChecker.mm in Sources */,
                                4A3CC18C19B0641500D14AEF /* UserMediaPermissionRequestProxy.cpp in Sources */,
                                E4E864921B16750100C82F40 /* VersionChecks.mm in Sources */,
                                2DAF4FFB1B636181006013D6 /* ViewGestureController.cpp in Sources */,
+                               836EEB801BE9EC9E006B4B82 /* NetworkLoadMac.mm in Sources */,
                                2DF9593B18A42412009785A1 /* ViewGestureControllerIOS.mm in Sources */,
                                2D125C5F1857EA05003BA3CB /* ViewGestureControllerMac.mm in Sources */,
                                2D1B5D5D185869C8006C6596 /* ViewGestureControllerMessageReceiver.cpp in Sources */,