Title: [276932] trunk
Revision
276932
Author
[email protected]
Date
2021-05-03 15:53:36 -0700 (Mon, 03 May 2021)

Log Message

WKWebView: WKURLSchemeHandler request don't have Range headers for custom scheme videos
https://bugs.webkit.org/show_bug.cgi?id=203302
<rdar://63750321>

Reviewed by Jer Noble and Geoff Garen.

Source/WebCore:

* platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm:
(WebCore::WebCoreAVFResourceLoader::startLoading):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (276931 => 276932)


--- trunk/Source/WebCore/ChangeLog	2021-05-03 22:29:27 UTC (rev 276931)
+++ trunk/Source/WebCore/ChangeLog	2021-05-03 22:53:36 UTC (rev 276932)
@@ -1,3 +1,14 @@
+2021-05-03  Alex Christensen  <[email protected]>
+
+        WKWebView: WKURLSchemeHandler request don't have Range headers for custom scheme videos
+        https://bugs.webkit.org/show_bug.cgi?id=203302
+        <rdar://63750321>
+
+        Reviewed by Jer Noble and Geoff Garen.
+
+        * platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm:
+        (WebCore::WebCoreAVFResourceLoader::startLoading):
+
 2021-05-03  Aditya Keerthi  <[email protected]>
 
         [iOS][FCR] Missing fill color on slider ticks

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm (276931 => 276932)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm	2021-05-03 22:29:27 UTC (rev 276931)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/WebCoreAVFResourceLoader.mm	2021-05-03 22:53:36 UTC (rev 276932)
@@ -246,6 +246,13 @@
     ResourceRequest request(nsRequest);
     request.setPriority(ResourceLoadPriority::Low);
 
+    if (AVAssetResourceLoadingDataRequest *dataRequest = [m_avRequest dataRequest]; dataRequest.requestedLength
+        && !request.hasHTTPHeaderField(HTTPHeaderName::Range)
+        && !request.url().protocolIsBlob()) {
+        String rangeEnd = dataRequest.requestsAllDataToEndOfResource ? "*"_s : makeString(dataRequest.requestedOffset + dataRequest.requestedLength - 1);
+        request.addHTTPHeaderField(HTTPHeaderName::Range, makeString("bytes=", dataRequest.requestedOffset, '-', rangeEnd));
+    }
+
     if (auto* loader = m_parent->player()->cachedResourceLoader()) {
         m_resourceMediaLoader = CachedResourceMediaLoader::create(*this, *loader, ResourceRequest(request));
         if (m_resourceMediaLoader)

Modified: trunk/Tools/ChangeLog (276931 => 276932)


--- trunk/Tools/ChangeLog	2021-05-03 22:29:27 UTC (rev 276931)
+++ trunk/Tools/ChangeLog	2021-05-03 22:53:36 UTC (rev 276932)
@@ -1,3 +1,13 @@
+2021-05-03  Alex Christensen  <[email protected]>
+
+        WKWebView: WKURLSchemeHandler request don't have Range headers for custom scheme videos
+        https://bugs.webkit.org/show_bug.cgi?id=203302
+        <rdar://63750321>
+
+        Reviewed by Jer Noble and Geoff Garen.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm:
+
 2021-05-03  Fujii Hironori  <[email protected]>
 
         REGRESSION(r275810): [WebKitTestRunner] fast/text/basic/004.html fails after running fast/layoutformattingcontext tests

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm (276931 => 276932)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm	2021-05-03 22:29:27 UTC (rev 276931)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm	2021-05-03 22:53:36 UTC (rev 276932)
@@ -1473,3 +1473,53 @@
     TestWebKitAPI::Util::run(&receivedScriptMessage);
     EXPECT_WK_STREQ(@"Document URL: redirectone://bar.com/anothertest.html", [lastScriptMessage body]);
 }
+
+TEST(URLSchemeHandler, Ranges)
+{
+    RetainPtr<NSData> videoData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"]];
+
+    auto handler = adoptNS([[TestURLSchemeHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"ranges"];
+    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
+    __block bool foundRangeRequest = false;
+    [handler setStartURLSchemeTaskHandler:^(WKWebView *, id<WKURLSchemeTask> task) {
+        if ([task.request.URL.path isEqualToString:@"/main.html"]) {
+            NSString *html = @"<video autoplay _onplaying_=\"alert('playing')\"><source src='' type='video/mp4'></video>";
+            [task didReceiveResponse:[[[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:html.length textEncodingName:nil] autorelease]];
+            [task didReceiveData:[html dataUsingEncoding:NSUTF8StringEncoding]];
+            [task didFinish];
+            return;
+        }
+
+        NSString *requestRange = [task.request.allHTTPHeaderFields objectForKey:@"Range"];
+        EXPECT_TRUE(requestRange);
+
+        String requestRangeString(requestRange);
+        String rangeBytes = "bytes="_s;
+        auto begin = requestRangeString.find(rangeBytes, 0);
+        ASSERT(begin != notFound);
+        auto dash = requestRangeString.find('-', begin);
+        ASSERT(dash != notFound);
+        auto end = requestRangeString.length();
+
+        auto rangeBeginString = requestRangeString.substring(begin + rangeBytes.length(), dash - begin - rangeBytes.length());
+        auto rangeEndString = requestRangeString.substring(dash + 1, end - dash - 1);
+        auto rangeBegin = rangeBeginString.toUInt64Strict();
+        auto rangeEnd = rangeEndString == "*" ? [videoData length] : rangeEndString.toUInt64Strict();
+
+        auto response = adoptNS([[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"https://webkit.org/"] statusCode:206 HTTPVersion:@"HTTP/1.1" headerFields:@{
+            @"Content-Range" : [NSString stringWithFormat:@"bytes %llu-%llu/%lu", rangeBegin, rangeEnd, (unsigned long)[videoData length]],
+            @"Content-Length" : [NSString stringWithFormat:@"%llu", rangeEnd - rangeBegin + 1]
+        }]);
+
+        [task didReceiveResponse:response.get()];
+        [task didReceiveData:[videoData subdataWithRange:NSMakeRange(rangeBegin, rangeEnd - rangeBegin)]];
+        [task didFinish];
+        foundRangeRequest = true;
+    }];
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"ranges:///main.html"]]];
+    EXPECT_WK_STREQ([webView _test_waitForAlert], "playing");
+    EXPECT_TRUE(foundRangeRequest);
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to