Diff
Modified: trunk/Source/WebCore/ChangeLog (191456 => 191457)
--- trunk/Source/WebCore/ChangeLog 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebCore/ChangeLog 2015-10-22 18:00:29 UTC (rev 191457)
@@ -1,3 +1,13 @@
+2015-10-22 Alex Christensen <achristen...@webkit.org>
+
+ Initial NSURLSession WebResourceLoader implementation
+ https://bugs.webkit.org/show_bug.cgi?id=150355
+
+ Reviewed by Antti Koivisto.
+
+ * platform/network/cf/AuthenticationChallenge.h:
+ (WebCore::AuthenticationChallenge::AuthenticationChallenge): Export constructor for use in WebKit2.
+
2015-10-22 Frederic Wang <fred.w...@free.fr>
[Mac] Add support for the USE_TYPO_METRICS flag
Modified: trunk/Source/WebCore/platform/network/cf/AuthenticationChallenge.h (191456 => 191457)
--- trunk/Source/WebCore/platform/network/cf/AuthenticationChallenge.h 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebCore/platform/network/cf/AuthenticationChallenge.h 2015-10-22 18:00:29 UTC (rev 191457)
@@ -55,7 +55,7 @@
CFURLAuthChallengeRef cfURLAuthChallengeRef() const { return m_cfChallenge.get(); }
#else
- AuthenticationChallenge(NSURLAuthenticationChallenge *);
+ WEBCORE_EXPORT AuthenticationChallenge(NSURLAuthenticationChallenge *);
id sender() const { return m_sender.get(); }
NSURLAuthenticationChallenge *nsURLAuthenticationChallenge() const { return m_nsChallenge.get(); }
Modified: trunk/Source/WebKit2/ChangeLog (191456 => 191457)
--- trunk/Source/WebKit2/ChangeLog 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebKit2/ChangeLog 2015-10-22 18:00:29 UTC (rev 191457)
@@ -1,3 +1,72 @@
+2015-10-22 Alex Christensen <achristen...@webkit.org>
+
+ Initial NSURLSession WebResourceLoader implementation
+ https://bugs.webkit.org/show_bug.cgi?id=150355
+
+ Reviewed by Antti Koivisto.
+
+ * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+ (WebKit::NetworkConnectionToWebProcess::convertMainResourceLoadToDownload):
+ (WebKit::NetworkConnectionToWebProcess::cookiesForDOM):
+ * NetworkProcess/NetworkResourceLoader.cpp:
+ (WebKit::NetworkResourceLoader::~NetworkResourceLoader):
+ (WebKit::NetworkResourceLoader::startNetworkLoad):
+ (WebKit::NetworkResourceLoader::setDefersLoading):
+ (WebKit::NetworkResourceLoader::cleanup):
+ (WebKit::NetworkResourceLoader::didConvertHandleToDownload):
+ (WebKit::NetworkResourceLoader::abort):
+ (WebKit::NetworkResourceLoader::willPerformHTTPRedirection):
+ (WebKit::NetworkResourceLoader::didReceiveChallenge):
+ (WebKit::NetworkResourceLoader::didReceiveResponse):
+ (WebKit::NetworkResourceLoader::didReceiveData):
+ (WebKit::NetworkResourceLoader::didCompleteWithError):
+ (WebKit::NetworkResourceLoader::didReceiveResponseAsync):
+ (WebKit::NetworkResourceLoader::willSendRequestAsync):
+ (WebKit::NetworkResourceLoader::continueWillSendRequest):
+ (WebKit::NetworkResourceLoader::continueDidReceiveResponse):
+ (WebKit::NetworkResourceLoader::didSendData):
+ (WebKit::NetworkResourceLoader::receivedCancellation):
+ (WebKit::NetworkResourceLoader::startBufferingTimerIfNeeded):
+ (WebKit::NetworkResourceLoader::bufferingTimerFired):
+ (WebKit::NetworkResourceLoader::validateCacheEntry):
+ (WebKit::NetworkResourceLoader::sendAbortingOnFailure):
+ (WebKit::NetworkResourceLoader::canAuthenticateAgainstProtectionSpaceAsync):
+ (WebKit::NetworkResourceLoader::continueCanAuthenticateAgainstProtectionSpace):
+ (WebKit::NetworkResourceLoader::supportsDataArray):
+ * NetworkProcess/NetworkResourceLoader.h:
+ (WebKit::NetworkResourceLoader::create):
+ (WebKit::NetworkResourceLoader::currentRequest):
+ (WebKit::NetworkResourceLoader::handle):
+ * NetworkProcess/NetworkSession.h: Added.
+ (WebKit::NetworkSessionTaskClient::~NetworkSessionTaskClient):
+ (WebKit::NetworkingDataTask::client):
+ (WebKit::NetworkingDataTask::clearClient):
+ (WebKit::NetworkSession::~NetworkSession):
+ * NetworkProcess/cocoa/NetworkSessionCocoa.mm: Added.
+ (toNSURLSessionResponseDisposition):
+ (toNSURLSessionAuthChallengeDisposition):
+ (-[NetworkSessionDelegate initWithNetworkSession:]):
+ (-[NetworkSessionDelegate URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]):
+ (-[NetworkSessionDelegate URLSession:task:didReceiveChallenge:completionHandler:]):
+ (-[NetworkSessionDelegate URLSession:task:didCompleteWithError:]):
+ (-[NetworkSessionDelegate URLSession:dataTask:didReceiveResponse:completionHandler:]):
+ (-[NetworkSessionDelegate URLSession:dataTask:didReceiveData:]):
+ (WebKit::NetworkSession::create):
+ (WebKit::NetworkSession::singleton):
+ (WebKit::configurationForType):
+ (WebKit::NetworkSession::NetworkSession):
+ (WebKit::NetworkSession::createDataTaskWithRequest):
+ (WebKit::NetworkSession::dataTaskForIdentifier):
+ (WebKit::NetworkingDataTask::NetworkingDataTask):
+ (WebKit::NetworkingDataTask::~NetworkingDataTask):
+ (WebKit::NetworkingDataTask::suspend):
+ (WebKit::NetworkingDataTask::resume):
+ (WebKit::NetworkingDataTask::taskIdentifier):
+ * NetworkProcess/mac/NetworkResourceLoaderMac.mm:
+ (WebKit::NetworkResourceLoader::willCacheResponseAsync):
+ * WebKit2.xcodeproj/project.pbxproj:
+ * config.h:
+
2015-10-22 Philippe Normand <pnorm...@igalia.com>
Unreviewed, GTK build fix for disabled redirected XComposite window support.
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp (191456 => 191457)
--- trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkConnectionToWebProcess.cpp 2015-10-22 18:00:29 UTC (rev 191457)
@@ -36,6 +36,7 @@
#include "NetworkResourceLoaderMessages.h"
#include "RemoteNetworkingContext.h"
#include "SessionTracker.h"
+#include <WebCore/NotImplemented.h>
#include <WebCore/PingHandle.h>
#include <WebCore/PlatformCookieJar.h>
#include <WebCore/ResourceLoaderOptions.h>
@@ -197,12 +198,17 @@
return;
}
+#if USE(NETWORK_SESSION)
+ // FIXME: Do something here.
+ notImplemented();
+#else
networkProcess.downloadManager().convertHandleToDownload(downloadID, loader->handle(), request, response);
// Unblock the URL connection operation queue.
loader->handle()->continueDidReceiveResponse();
loader->didConvertHandleToDownload();
+#endif
}
void NetworkConnectionToWebProcess::cookiesForDOM(SessionID sessionID, const URL& firstParty, const URL& url, String& result)
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (191456 => 191457)
--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp 2015-10-22 18:00:29 UTC (rev 191457)
@@ -47,12 +47,15 @@
#include <WebCore/CertificateInfo.h>
#include <WebCore/HTTPHeaderNames.h>
#include <WebCore/NotImplemented.h>
-#include <WebCore/ResourceHandle.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 {
@@ -116,7 +119,11 @@
NetworkResourceLoader::~NetworkResourceLoader()
{
ASSERT(RunLoop::isMain());
+#if USE(NETWORK_SESSION)
+ ASSERT(!m_task);
+#else
ASSERT(!m_handle);
+#endif
ASSERT(!isSynchronous() || !m_synchronousLoadData->delayedReply);
}
@@ -180,7 +187,13 @@
#endif
bool shouldSniff = m_parameters.contentSniffingPolicy == SniffContent;
+#if USE(NETWORK_SESSION)
+ UNUSED_PARAM(shouldSniff); // FIXME: Use this.
+ m_task = NetworkSession::singleton()->createDataTaskWithRequest(m_currentRequest, *this);
+ m_task->resume();
+#else
m_handle = ResourceHandle::create(m_networkingContext.get(), m_currentRequest, this, m_defersLoading, shouldSniff);
+#endif
}
void NetworkResourceLoader::setDefersLoading(bool defers)
@@ -188,10 +201,15 @@
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
if (!m_defersLoading)
start();
}
@@ -204,25 +222,40 @@
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
// 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);
m_didConvertHandleToDownload = true;
}
+#endif
void NetworkResourceLoader::abort()
{
ASSERT(RunLoop::isMain());
+#if USE(NETWORK_SESSION)
+ if (m_task)
+ m_task->suspend();
+ // FIXME: Do something with the network cache here.
+ notImplemented();
+#else
if (m_handle && !m_didConvertHandleToDownload) {
m_handle->cancel();
@@ -234,10 +267,51 @@
}
#endif
}
-
+#endif
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)
+{
+ 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);
@@ -428,6 +502,8 @@
sendAbortingOnFailure(Messages::WebResourceLoader::WillSendRequest(m_currentRequest, redirectResponse));
}
+#endif // USE(NETWORK_SESSION)
+
void NetworkResourceLoader::continueWillSendRequest(const ResourceRequest& newRequest)
{
#if PLATFORM(COCOA)
@@ -438,24 +514,41 @@
#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 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 !USE(NETWORK_SESSION)
+
void NetworkResourceLoader::didSendData(ResourceHandle* handle, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
{
ASSERT_UNUSED(handle, handle == m_handle);
@@ -520,6 +613,8 @@
didFail(m_handle.get(), cancelledError(m_currentRequest));
}
+#endif // !USE(NETWORK_SESSION)
+
void NetworkResourceLoader::startBufferingTimerIfNeeded()
{
if (isSynchronous())
@@ -532,7 +627,9 @@
void NetworkResourceLoader::bufferingTimerFired()
{
ASSERT(m_bufferedData);
+#if !USE(NETWORK_SESSION)
ASSERT(m_handle);
+#endif
if (!m_bufferedData->size())
return;
@@ -600,7 +697,9 @@
void NetworkResourceLoader::validateCacheEntry(std::unique_ptr<NetworkCache::Entry> entry)
{
+#if !USE(NETWORK_SESSION)
ASSERT(!m_handle);
+#endif
// 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.
@@ -663,7 +762,7 @@
return result;
}
-#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
+#if USE(PROTECTION_SPACE_AUTH_CALLBACK) && !USE(NETWORK_SESSION)
void NetworkResourceLoader::canAuthenticateAgainstProtectionSpaceAsync(ResourceHandle* handle, const ProtectionSpace& protectionSpace)
{
ASSERT(RunLoop::isMain());
@@ -685,14 +784,21 @@
}
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();
+#else
m_handle->continueCanAuthenticateAgainstProtectionSpace(result);
+#endif
}
#endif
-#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
+#if USE(NETWORK_CFDATA_ARRAY_CALLBACK) && !USE(NETWORK_SESSION)
bool NetworkResourceLoader::supportsDataArray()
{
notImplemented();
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h (191456 => 191457)
--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h 2015-10-22 18:00:29 UTC (rev 191457)
@@ -35,7 +35,6 @@
#include "ShareableResource.h"
#include <WebCore/CacheValidation.h>
#include <WebCore/ResourceError.h>
-#include <WebCore/ResourceHandleClient.h>
#include <WebCore/ResourceLoaderOptions.h>
#include <WebCore/ResourceRequest.h>
#include <WebCore/ResourceResponse.h>
@@ -44,11 +43,19 @@
#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;
namespace WebCore {
class BlobDataFileReference;
+#if !USE(NETWORK_SESSION)
class ResourceHandle;
+#endif
class ResourceRequest;
}
@@ -59,7 +66,14 @@
class RemoteNetworkingContext;
class SandboxExtension;
-class NetworkResourceLoader : public RefCounted<NetworkResourceLoader>, public WebCore::ResourceHandleClient, public IPC::MessageSender {
+class NetworkResourceLoader
+ : public RefCounted<NetworkResourceLoader>
+#if USE(NETWORK_SESSION)
+ , public NetworkSessionTaskClient
+#else
+ , public WebCore::ResourceHandleClient
+#endif
+ , public IPC::MessageSender {
public:
static Ref<NetworkResourceLoader> create(const NetworkResourceLoadParameters& parameters, NetworkConnectionToWebProcess* connection)
{
@@ -77,7 +91,9 @@
// Changes with redirects.
WebCore::ResourceRequest& currentRequest() { return m_currentRequest; }
+#if !USE(NETWORK_SESSION)
WebCore::ResourceHandle* handle() const { return m_handle.get(); }
+#endif
void didConvertHandleToDownload();
void start();
@@ -117,6 +133,14 @@
virtual IPC::Connection* messageSenderConnection() override;
virtual uint64_t messageSenderDestinationID() override { return m_parameters.identifier; }
+#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 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;
@@ -148,6 +172,7 @@
virtual void willCacheResponseAsync(WebCore::ResourceHandle*, NSCachedURLResponse *) override;
#endif
#endif
+#endif // USE(NETWORK_SESSION)
#if ENABLE(NETWORK_CACHE)
void didRetrieveCacheEntry(std::unique_ptr<NetworkCache::Entry>);
@@ -177,7 +202,11 @@
RefPtr<NetworkConnectionToWebProcess> m_connection;
RefPtr<RemoteNetworkingContext> m_networkingContext;
+#if USE(NETWORK_SESSION)
+ RefPtr<NetworkingDataTask> m_task;
+#else
RefPtr<WebCore::ResourceHandle> m_handle;
+#endif
WebCore::ResourceRequest m_currentRequest;
WebCore::ResourceResponse m_response;
Added: trunk/Source/WebKit2/NetworkProcess/NetworkSession.h (0 => 191457)
--- trunk/Source/WebKit2/NetworkProcess/NetworkSession.h (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkSession.h 2015-10-22 18:00:29 UTC (rev 191457)
@@ -0,0 +1,123 @@
+/*
+ * 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 NetworkSession_h
+#define NetworkSession_h
+
+OBJC_CLASS NSURLSession;
+OBJC_CLASS NSURLSessionDataTask;
+OBJC_CLASS NSOperationQueue;
+OBJC_CLASS NetworkSessionDelegate;
+
+#include <wtf/HashMap.h>
+#include <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+class AuthenticationChallenge;
+class Credential;
+class ResourceError;
+class ResourceRequest;
+class ResourceResponse;
+class SharedBuffer;
+}
+
+namespace WebKit {
+
+enum class ResponseDisposition {
+ Cancel,
+ Allow,
+ BecomeDownload
+};
+
+enum class AuthenticationChallengeDisposition {
+ UseCredential,
+ PerformDefaultHandling,
+ Cancel,
+ RejectProtectionSpace
+};
+
+class NetworkSession;
+
+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 didCompleteWithError(const WebCore::ResourceError&) = 0;
+
+ virtual ~NetworkSessionTaskClient() { }
+};
+
+class NetworkingDataTask : public RefCounted<NetworkingDataTask> {
+ friend class NetworkSession;
+public:
+ void suspend();
+ void resume();
+
+ uint64_t taskIdentifier();
+
+ ~NetworkingDataTask();
+
+ NetworkSessionTaskClient* client() { return m_client; }
+ void clearClient() { m_client = nullptr; }
+
+private:
+ explicit NetworkingDataTask(NetworkSession&, NetworkSessionTaskClient&, RetainPtr<NSURLSessionDataTask>);
+
+ NetworkSession& m_session;
+ RetainPtr<NSURLSessionDataTask> m_task;
+ NetworkSessionTaskClient* m_client;
+};
+
+class NetworkSession : public RefCounted<NetworkSession> {
+ friend class NetworkingDataTask;
+public:
+ enum class Type {
+ Normal,
+ Ephemeral
+ };
+
+ RefPtr<NetworkingDataTask> createDataTaskWithRequest(const WebCore::ResourceRequest&, NetworkSessionTaskClient&);
+
+ static Ref<NetworkSession> singleton(); // FIXME: This shouldn't actually be a singleton.
+ NetworkingDataTask* dataTaskForIdentifier(uint64_t);
+
+ ~NetworkSession() { ASSERT(m_dataTaskMap.isEmpty()); }
+private:
+ static Ref<NetworkSession> create(Type);
+
+ NetworkSession(Type);
+ HashMap<uint64_t, NetworkingDataTask*> m_dataTaskMap;
+ RetainPtr<NSURLSession> m_session;
+ RetainPtr<NetworkSessionDelegate> m_sessionDelegate;
+};
+
+} // namespace WebKit
+
+#endif // NetworkSession_h
Added: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (0 => 191457)
--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm 2015-10-22 18:00:29 UTC (rev 191457)
@@ -0,0 +1,236 @@
+/*
+ * 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"
+#import "NetworkSession.h"
+
+#if USE(NETWORK_SESSION)
+
+#import <Foundation/NSURLSession.h>
+
+#import <WebCore/AuthenticationChallenge.h>
+#import <WebCore/Credential.h>
+#import <WebCore/ResourceError.h>
+#import <WebCore/ResourceRequest.h>
+#import <WebCore/ResourceResponse.h>
+#import <WebCore/SharedBuffer.h>
+#import <wtf/MainThread.h>
+#import <wtf/NeverDestroyed.h>
+
+static NSURLSessionResponseDisposition toNSURLSessionResponseDisposition(WebKit::ResponseDisposition disposition)
+{
+ switch (disposition) {
+ case WebKit::ResponseDisposition::Cancel:
+ return NSURLSessionResponseCancel;
+ case WebKit::ResponseDisposition::Allow:
+ return NSURLSessionResponseAllow;
+ case WebKit::ResponseDisposition::BecomeDownload:
+ return NSURLSessionResponseBecomeDownload;
+ }
+}
+
+static NSURLSessionAuthChallengeDisposition toNSURLSessionAuthChallengeDisposition(WebKit::AuthenticationChallengeDisposition disposition)
+{
+ switch (disposition) {
+ case WebKit::AuthenticationChallengeDisposition::UseCredential:
+ return NSURLSessionAuthChallengeUseCredential;
+ case WebKit::AuthenticationChallengeDisposition::PerformDefaultHandling:
+ return NSURLSessionAuthChallengePerformDefaultHandling;
+ case WebKit::AuthenticationChallengeDisposition::Cancel:
+ return NSURLSessionAuthChallengeCancelAuthenticationChallenge;
+ case WebKit::AuthenticationChallengeDisposition::RejectProtectionSpace:
+ return NSURLSessionAuthChallengeRejectProtectionSpace;
+ }
+}
+
+@interface NetworkSessionDelegate : NSObject <NSURLSessionDataDelegate> {
+ WebKit::NetworkSession* _session;
+}
+
+- (id)initWithNetworkSession:(WebKit::NetworkSession&)session;
+
+@end
+
+@implementation NetworkSessionDelegate
+
+- (id)initWithNetworkSession:(WebKit::NetworkSession&)session
+{
+ self = [super init];
+ if (!self)
+ return nil;
+
+ _session = &session;
+
+ return self;
+}
+
+- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest *))completionHandler
+{
+ UNUSED_PARAM(session);
+
+ if (auto* networkingTask = _session->dataTaskForIdentifier(task.taskIdentifier)) {
+ if (auto* client = networkingTask->client()) {
+ client->willPerformHTTPRedirection(response, request, ^(const WebCore::ResourceRequest& request)
+ {
+ completionHandler(request.nsURLRequest(WebCore::UpdateHTTPBody));
+ }
+ );
+ }
+ }
+}
+
+- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
+{
+ UNUSED_PARAM(session);
+
+ if (auto* networkingTask = _session->dataTaskForIdentifier(task.taskIdentifier)) {
+ if (auto* client = networkingTask->client()) {
+ client->didReceiveChallenge(challenge, ^(WebKit::AuthenticationChallengeDisposition disposition, const WebCore::Credential& credential)
+ {
+ completionHandler(toNSURLSessionAuthChallengeDisposition(disposition), credential.nsCredential());
+ }
+ );
+ }
+ }
+}
+
+- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
+{
+ UNUSED_PARAM(session);
+
+ if (auto* networkingTask = _session->dataTaskForIdentifier(task.taskIdentifier)) {
+ if (auto* client = networkingTask->client())
+ client->didCompleteWithError(error);
+ }
+}
+
+- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler
+{
+ UNUSED_PARAM(session);
+
+ if (auto* networkingTask = _session->dataTaskForIdentifier(dataTask.taskIdentifier)) {
+ if (auto* client = networkingTask->client()) {
+ ASSERT(isMainThread());
+ WebCore::ResourceResponse resourceResponse(response);
+ client->didReceiveResponse(response, ^(WebKit::ResponseDisposition responseDisposition)
+ {
+ completionHandler(toNSURLSessionResponseDisposition(responseDisposition));
+ }
+ );
+ }
+ }
+}
+
+- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
+{
+ UNUSED_PARAM(session);
+
+ if (auto* networkingTask = _session->dataTaskForIdentifier(dataTask.taskIdentifier)) {
+ if (auto* client = networkingTask->client())
+ client->didReceiveData(WebCore::SharedBuffer::wrapNSData(data));
+ }
+}
+
+@end
+
+namespace WebKit {
+
+Ref<NetworkSession> NetworkSession::create(Type type)
+{
+ return adoptRef(*new NetworkSession(type));
+}
+
+Ref<NetworkSession> NetworkSession::singleton()
+{
+ static NeverDestroyed<Ref<NetworkSession>> sharedInstance(NetworkSession::create(Type::Normal));
+ return sharedInstance.get().copyRef();
+}
+
+static NSURLSessionConfiguration *configurationForType(NetworkSession::Type type)
+{
+ switch (type) {
+ case NetworkSession::Type::Normal:
+ return [NSURLSessionConfiguration defaultSessionConfiguration];
+ case NetworkSession::Type::Ephemeral:
+ return [NSURLSessionConfiguration ephemeralSessionConfiguration];
+ }
+}
+
+NetworkSession::NetworkSession(Type type)
+{
+ m_sessionDelegate = adoptNS([[NetworkSessionDelegate alloc] initWithNetworkSession:*this]);
+
+ NSURLSessionConfiguration *configuration = configurationForType(type);
+ m_session = [NSURLSession sessionWithConfiguration:configuration delegate:static_cast<id>(m_sessionDelegate.get()) delegateQueue:[NSOperationQueue mainQueue]];
+}
+
+RefPtr<NetworkingDataTask> NetworkSession::createDataTaskWithRequest(const WebCore::ResourceRequest& request, NetworkSessionTaskClient& client)
+{
+ RefPtr<NetworkingDataTask> task = adoptRef(new NetworkingDataTask(*this, client, [m_session dataTaskWithRequest:request.nsURLRequest(WebCore::UpdateHTTPBody)]));
+ return task;
+}
+
+NetworkingDataTask* NetworkSession::dataTaskForIdentifier(uint64_t taskIdentifier)
+{
+ ASSERT(isMainThread());
+ return m_dataTaskMap.get(taskIdentifier);
+}
+
+NetworkingDataTask::NetworkingDataTask(NetworkSession& session, NetworkSessionTaskClient& client, RetainPtr<NSURLSessionDataTask> task)
+ : m_session(session)
+ , m_task(task)
+ , m_client(&client)
+{
+ ASSERT(!m_session.m_dataTaskMap.contains(taskIdentifier()));
+ ASSERT(isMainThread());
+ m_session.m_dataTaskMap.add(taskIdentifier(), this);
+}
+
+NetworkingDataTask::~NetworkingDataTask()
+{
+ ASSERT(m_session.m_dataTaskMap.contains(taskIdentifier()));
+ ASSERT(m_session.m_dataTaskMap.get(taskIdentifier()) == this);
+ ASSERT(isMainThread());
+ m_session.m_dataTaskMap.remove(taskIdentifier());
+}
+
+void NetworkingDataTask::suspend()
+{
+ [m_task suspend];
+}
+
+void NetworkingDataTask::resume()
+{
+ [m_task resume];
+}
+
+uint64_t NetworkingDataTask::taskIdentifier()
+{
+ return [m_task taskIdentifier];
+}
+
+}
+
+#endif
Modified: trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm (191456 => 191457)
--- trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebKit2/NetworkProcess/mac/NetworkResourceLoaderMac.mm 2015-10-22 18:00:29 UTC (rev 191457)
@@ -94,7 +94,7 @@
m_handle->continueWillCacheResponse(cfResponse);
}
-#else
+#elif !USE(NETWORK_SESSION)
void NetworkResourceLoader::willCacheResponseAsync(ResourceHandle* handle, NSCachedURLResponse *nsResponse)
{
Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (191456 => 191457)
--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2015-10-22 18:00:29 UTC (rev 191457)
@@ -1049,6 +1049,8 @@
5272B28A1406985D0096A5D0 /* StatisticsData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5272B2881406985D0096A5D0 /* StatisticsData.cpp */; };
5272B28B1406985D0096A5D0 /* StatisticsData.h in Headers */ = {isa = PBXBuildFile; fileRef = 5272B2891406985D0096A5D0 /* StatisticsData.h */; };
528C37C1195CBB1A00D8B9CC /* WKBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9F28101958F478008CAC72 /* WKBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 5C20CB9D1BB0DCFA00895BB1 /* NetworkSessionCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C20CB9B1BB0DCD200895BB1 /* NetworkSessionCocoa.mm */; };
+ 5C20CBA01BB1ECD800895BB1 /* NetworkSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C20CB9E1BB0DD1800895BB1 /* NetworkSession.h */; };
5DA6ED0A1490606900B41D12 /* DynamicLinkerEnvironmentExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DA6ED081490606900B41D12 /* DynamicLinkerEnvironmentExtractor.h */; };
5DA6ED0B1490606900B41D12 /* DynamicLinkerEnvironmentExtractor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5DA6ED091490606900B41D12 /* DynamicLinkerEnvironmentExtractor.mm */; };
6501BD1A12F1243400E9F248 /* WKBundleInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65B86F1712F11D7B00B7DD8A /* WKBundleInspector.cpp */; };
@@ -3247,6 +3249,8 @@
51FD18B41651FBAD00DBE1CE /* NetworkResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkResourceLoader.h; path = NetworkProcess/NetworkResourceLoader.h; sourceTree = "<group>"; };
5272B2881406985D0096A5D0 /* StatisticsData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StatisticsData.cpp; sourceTree = "<group>"; };
5272B2891406985D0096A5D0 /* StatisticsData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StatisticsData.h; sourceTree = "<group>"; };
+ 5C20CB9B1BB0DCD200895BB1 /* NetworkSessionCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkSessionCocoa.mm; path = NetworkProcess/cocoa/NetworkSessionCocoa.mm; sourceTree = "<group>"; };
+ 5C20CB9E1BB0DD1800895BB1 /* NetworkSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkSession.h; path = NetworkProcess/NetworkSession.h; sourceTree = "<group>"; };
5D442A5516D5856700AC3331 /* PluginService.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PluginService.entitlements; sourceTree = "<group>"; };
5DA6ED081490606900B41D12 /* DynamicLinkerEnvironmentExtractor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicLinkerEnvironmentExtractor.h; sourceTree = "<group>"; };
5DA6ED091490606900B41D12 /* DynamicLinkerEnvironmentExtractor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DynamicLinkerEnvironmentExtractor.mm; sourceTree = "<group>"; };
@@ -5565,6 +5569,7 @@
51FD18B31651FBAD00DBE1CE /* NetworkResourceLoader.cpp */,
51FD18B41651FBAD00DBE1CE /* NetworkResourceLoader.h */,
E1525517170109FB003D7ADB /* NetworkResourceLoader.messages.in */,
+ 5C20CB9E1BB0DD1800895BB1 /* NetworkSession.h */,
E1B78470163F24690007B692 /* RemoteNetworkingContext.h */,
);
name = NetworkProcess;
@@ -5909,6 +5914,7 @@
7EC4F0F818E4A922008056AF /* cocoa */ = {
isa = PBXGroup;
children = (
+ 5C20CB9B1BB0DCD200895BB1 /* NetworkSessionCocoa.mm */,
7EC4F0F918E4A945008056AF /* NetworkProcessCocoa.mm */,
);
name = cocoa;
@@ -8299,6 +8305,7 @@
378E1A4A18208CD60031007A /* WKNSString.h in Headers */,
378E1A4E18208D700031007A /* WKNSURL.h in Headers */,
37FC194B18510D6A008CFA47 /* WKNSURLAuthenticationChallenge.h in Headers */,
+ 5C20CBA01BB1ECD800895BB1 /* NetworkSession.h in Headers */,
37183D57182F4E700080C811 /* WKNSURLExtras.h in Headers */,
37BF2F061947DEB400723C48 /* WKNSURLRequest.h in Headers */,
BC407602124FF0270068F20A /* WKNumber.h in Headers */,
@@ -9850,6 +9857,7 @@
BCE469791214F2B4000B98EB /* WebFrameListenerProxy.cpp in Sources */,
BC111A5F112F4FBB00337BAB /* WebFrameLoaderClient.cpp in Sources */,
2D28F3E71885CCC1004B9EAE /* WebFrameLoaderClientIOS.mm in Sources */,
+ 5C20CB9D1BB0DCFA00895BB1 /* NetworkSessionCocoa.mm in Sources */,
9391F2CA121B679A00EBF7E8 /* WebFrameNetworkingContext.mm in Sources */,
BCB9F6A11123A84B00A137E0 /* WebFramePolicyListenerProxy.cpp in Sources */,
BC111B0E112F5E4F00337BAB /* WebFrameProxy.cpp in Sources */,
Modified: trunk/Source/WebKit2/config.h (191456 => 191457)
--- trunk/Source/WebKit2/config.h 2015-10-22 17:17:56 UTC (rev 191456)
+++ trunk/Source/WebKit2/config.h 2015-10-22 18:00:29 UTC (rev 191457)
@@ -73,7 +73,10 @@
#ifndef HAVE_WINDOW_SERVER_OCCLUSION_NOTIFICATIONS
#define HAVE_WINDOW_SERVER_OCCLUSION_NOTIFICATIONS 1
#endif
+#ifndef USE_NETWORK_SESSION
+#define USE_NETWORK_SESSION 0
#endif
+#endif
#ifndef HAVE_SEC_ACCESS_CONTROL
#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000)