Custom protocol loading through AVFoundation does not support byte-range requests.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jan 2016 19:17:17 +0000 (19:17 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jan 2016 19:17:17 +0000 (19:17 +0000)
commitcaa52fb807a3ede43e51642b8db08555ce193bbf
tree804f31ce0ed2b5dd789519381d0ae0f254c6c330
parent3e4fea465821368537305e1827a21a1a8a7d776b
Custom protocol loading through AVFoundation does not support byte-range requests.
https://bugs.webkit.org/show_bug.cgi?id=152919
<rdar://problem/23664657>

Reviewed by Alex Christensen.

Source/WebCore:

Tests: http/tests/xmlhttprequest/blob-request-byte-range.html
       TestWebkitAPI/Tests/WebCore/ParsedContentRange.cpp

When loading data through the AVAssetResourceLoaderDelegateProtocol, AVFoundation will issue
requests for specific byte-ranges by adding a "Range:" HTTP header to the NSURLRequest it
passes to the delegate.  WebCore ignores this header, loads the entire resource, and replies
to the callback with the requested subset of the entire resource.

For byte-range requests near the end of a resource, this is inefficient, as the entire
resource up to, and including, the requested range must be loaded before any data can be
returned. Explicitly handle byte-range requests by creating a CachedResourceRequest with the
underlying NSURLRequest (which includes the "Range:" header) rather than just the request's
URL. BlobResourceHandle must be modified to add the "Content-Range:" response header to the
ResourceResponse.

To facilitate both generating and parsing the "Content-Range:" header, add a new
ParsedContentRange class for use by ResourceResponse and its clients. This class provides
methods both for parsing a "Content-Range" header value string, and for generating the
header value from elemental values.

* platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm:
(WebCore::WebCoreAVFResourceLoader::startLoading):
(WebCore::WebCoreAVFResourceLoader::responseReceived):
(WebCore::WebCoreAVFResourceLoader::fulfillRequestWithResource):
* platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::BlobResourceHandle):
(WebCore::BlobResourceHandle::didGetSize):
(WebCore::BlobResourceHandle::seek):
(WebCore::BlobResourceHandle::notifyResponseOnSuccess):
* platform/network/BlobResourceHandle.h:
* platform/network/HTTPHeaderNames.in:
* platform/network/ParsedContentRange.cpp: Added.
(WebCore::areContentRangeValuesValid):
(WebCore::parseContentRange):
(WebCore::ParsedContentRange::ParsedContentRange):
(WebCore::ParsedContentRange::headerValue):
* platform/network/ParsedContentRange.h: Added.
(WebCore::ParsedContentRange::ParsedContentRange):
(WebCore::ParsedContentRange::isValid):
(WebCore::ParsedContentRange::firstBytePosition):
(WebCore::ParsedContentRange::lastBytePosition):
(WebCore::ParsedContentRange::instanceLength):
* platform/network/ResourceResponseBase.cpp:
(WebCore::ResourceResponseBase::updateHeaderParsedState):
(WebCore::parseContentRangeInHeader):
(WebCore::ResourceResponseBase::contentRange):
* platform/network/ResourceResponseBase.h:
* CMakeLists.txt:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:

Tools:

Add tests for new ParsedContntRange class.

* TestWebKitAPI/PlatformWin.cmake:
* TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj:
* TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/ParsedContentRange.cpp: Added.
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195764 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
LayoutTests/http/tests/xmlhttprequest/blob-request-byte-range-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/blob-request-byte-range.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm
Source/WebCore/platform/network/BlobResourceHandle.cpp
Source/WebCore/platform/network/BlobResourceHandle.h
Source/WebCore/platform/network/HTTPHeaderNames.in
Source/WebCore/platform/network/ParsedContentRange.cpp [new file with mode: 0644]
Source/WebCore/platform/network/ParsedContentRange.h [new file with mode: 0644]
Source/WebCore/platform/network/ResourceResponseBase.cpp
Source/WebCore/platform/network/ResourceResponseBase.h
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformWin.cmake
Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj
Tools/TestWebKitAPI/TestWebKitAPI.vcxproj/TestWebKitAPI.vcxproj.filters
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebCore/ParsedContentRange.cpp [new file with mode: 0644]