[Mac] Wrap a resource and resource loader in a NSURLSession-like object for use by...
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Feb 2016 22:57:43 +0000 (22:57 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Feb 2016 22:57:43 +0000 (22:57 +0000)
commitfd1ef0998badafe34b5c4d308d835297f21f0b6a
tree4485ea2326f506953f8e7f19acacae6c1a103e4e
parent16b9576204663d8584527d8c67ad073db218d33b
[Mac] Wrap a resource and resource loader in a NSURLSession-like object for use by lower level frameworks
https://bugs.webkit.org/show_bug.cgi?id=153669

Reviewed by Alex Christensen.

Source/WebCore:

API Test: WebCore.WebCoreNSURLSession

Add a NSURLSession-like object, which wraps a CachedResourceLoader and CachedRawResource, which we can
hand to lower-level frameworks, so that network loads by those frameworks use WebKit's loader.

* platform/network/cocoa/WebCoreNSURLSession.h: Added.
* platform/network/cocoa/WebCoreNSURLSession.mm: Added.
(-[WebCoreNSURLSession initWithResourceLoader:delegate:delegateQueue:]):
(-[WebCoreNSURLSession dealloc]):
(-[WebCoreNSURLSession copyWithZone:]):
(-[WebCoreNSURLSession delegateQueue]):
(-[WebCoreNSURLSession configuration]):
(-[WebCoreNSURLSession loader]):
(-[WebCoreNSURLSession finishTasksAndInvalidate]):
(-[WebCoreNSURLSession invalidateAndCancel]):
(-[WebCoreNSURLSession resetWithCompletionHandler:]):
(-[WebCoreNSURLSession flushWithCompletionHandler:]):
(-[WebCoreNSURLSession getTasksWithCompletionHandler:]):
(-[WebCoreNSURLSession getAllTasksWithCompletionHandler:]):
(-[WebCoreNSURLSession dataTaskWithRequest:]):
(-[WebCoreNSURLSession dataTaskWithURL:]):
(-[WebCoreNSURLSession uploadTaskWithRequest:fromFile:]):
(-[WebCoreNSURLSession uploadTaskWithRequest:fromData:]):
(-[WebCoreNSURLSession uploadTaskWithStreamedRequest:]):
(-[WebCoreNSURLSession downloadTaskWithRequest:]):
(-[WebCoreNSURLSession downloadTaskWithURL:]):
(-[WebCoreNSURLSession downloadTaskWithResumeData:]):
(-[WebCoreNSURLSession streamTaskWithHostName:port:]):
(-[WebCoreNSURLSession streamTaskWithNetService:]):
(-[WebCoreNSURLSession isKindOfClass:]):

Add a C++ class which can act as a CachedRawResourceClient, passing the results back to a WebCoreNSURLSessionDataTask:

(WebCore::WebCoreNSURLSessionDataTaskClient::WebCoreNSURLSessionDataTaskClient):
(WebCore::WebCoreNSURLSessionDataTaskClient::dataSent):
(WebCore::WebCoreNSURLSessionDataTaskClient::responseReceived):
(WebCore::WebCoreNSURLSessionDataTaskClient::dataReceived):
(WebCore::WebCoreNSURLSessionDataTaskClient::redirectReceived):
(WebCore::WebCoreNSURLSessionDataTaskClient::notifyFinished):

Add a NSURLSessionDataTask-like object, which takes a request, then uses it to create and wrap a CachedRawResource.
Becase NSURSessionDataTask is intended to be used off-main-thread, care must be taken to dispatch back to the main-
(or web-) thread before calling CachedRawResource functions.

(-[WebCoreNSURLSessionDataTask initWithSession:identifier:URL:]):
(-[WebCoreNSURLSessionDataTask initWithSession:identifier:request:]):
(-[WebCoreNSURLSessionDataTask copyWithZone:]):
(-[WebCoreNSURLSessionDataTask _restart]):
(-[WebCoreNSURLSessionDataTask _cancel]):
(-[WebCoreNSURLSessionDataTask _finish]):
(-[WebCoreNSURLSessionDataTask _setDefersLoading:]):
(-[WebCoreNSURLSessionDataTask cancel]):
(-[WebCoreNSURLSessionDataTask suspend]):
(-[WebCoreNSURLSessionDataTask resume]):
(-[WebCoreNSURLSessionDataTask _timingData]):
(-[WebCoreNSURLSessionDataTask resource:sentBytes:totalBytesToBeSent:]):
(-[WebCoreNSURLSessionDataTask resource:receivedResponse:]):
(-[WebCoreNSURLSessionDataTask resource:receivedData:length:]):
(-[WebCoreNSURLSessionDataTask resource:receivedRedirect:request:]):
(-[WebCoreNSURLSessionDataTask resourceFinished:]):
* WebCore.xcodeproj/project.pbxproj: Add new files to project.

Tools:

Add an API test for WebCoreNSURLSession, testing that it behaves like a regulare NSURLSession, including
calling appropriate NSURLSessionDelegate callbacks.

Drive-by fix: Add a FeatureDefines.xcconfig to TestWebKitAPI.  Without this, the ENABLE macros in WebCore
header files will not match the one used when compiling WebCore, leading to strange crashes and weird
inconsistencies when calling, e.g., inline methods.

* TestWebKitAPI/Configurations/FeatureDefines.xcconfig: Added.
* TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/WebCoreNSURLSession.mm: Added.
(-[TestNSURLSessionLoaderDelegate webView:didCommitLoadForFrame:]):
(-[TestNSURLSessionDataDelegate URLSession:task:didCompleteWithError:]):
(-[TestNSURLSessionDataDelegate URLSession:dataTask:didReceiveResponse:completionHandler:]):
(-[TestNSURLSessionDataDelegate URLSession:dataTask:didReceiveData:]):
(TestWebKitAPI::WebCoreNSURLSessionTest::SetUp):
(TestWebKitAPI::WebCoreNSURLSessionTest::TearDown):
(TestWebKitAPI::TEST_F):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196082 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.h [new file with mode: 0644]
Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm [new file with mode: 0644]
Tools/ChangeLog
Tools/TestWebKitAPI/Configurations/FeatureDefines.xcconfig [new file with mode: 0644]
Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebCore/WebCoreNSURLSession.mm [new file with mode: 0644]