Title: [280920] trunk
Revision
280920
Author
[email protected]
Date
2021-08-11 11:08:49 -0700 (Wed, 11 Aug 2021)

Log Message

Media element is not always autoplaying when going from background to foreground if it is initially not in viewport
https://bugs.webkit.org/show_bug.cgi?id=228955
Source/WebCore:

Reviewed by Eric Carlson.

In case video element is autoplayable but is paused, we should try to autoplay even if we are not interrupted due to invisible autoplay.
Covered by API test.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::updateShouldAutoplay):

Tools:

rdar://81751653

Reviewed by Eric Carlson.

* TestWebKitAPI/Tests/WebKit/GetUserMedia.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (280919 => 280920)


--- trunk/Source/WebCore/ChangeLog	2021-08-11 17:59:01 UTC (rev 280919)
+++ trunk/Source/WebCore/ChangeLog	2021-08-11 18:08:49 UTC (rev 280920)
@@ -1,5 +1,18 @@
 2021-08-11  Youenn Fablet  <[email protected]>
 
+        Media element is not always autoplaying when going from background to foreground if it is initially not in viewport
+        https://bugs.webkit.org/show_bug.cgi?id=228955
+
+        Reviewed by Eric Carlson.
+
+        In case video element is autoplayable but is paused, we should try to autoplay even if we are not interrupted due to invisible autoplay.
+        Covered by API test.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::updateShouldAutoplay):
+
+2021-08-11  Youenn Fablet  <[email protected]>
+
         Remove --no-demangle XLinker option from WebCore
         https://bugs.webkit.org/show_bug.cgi?id=228949
 

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (280919 => 280920)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-08-11 17:59:01 UTC (rev 280919)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2021-08-11 18:08:49 UTC (rev 280920)
@@ -8092,12 +8092,16 @@
         return;
 
     bool canAutoplay = mediaSession().autoplayPermitted();
-    if (canAutoplay
-        && mediaSession().state() == PlatformMediaSession::Interrupted
-        && mediaSession().interruptionType() == PlatformMediaSession::InvisibleAutoplay)
-        mediaSession().endInterruption(PlatformMediaSession::MayResumePlaying);
-    else if (!canAutoplay
-        && mediaSession().state() != PlatformMediaSession::Interrupted)
+
+    if (canAutoplay) {
+        if (mediaSession().state() == PlatformMediaSession::Interrupted) {
+            if (mediaSession().interruptionType() == PlatformMediaSession::InvisibleAutoplay)
+                mediaSession().endInterruption(PlatformMediaSession::MayResumePlaying);
+        } else if (!isPlaying())
+            resumeAutoplaying();
+        return;
+    }
+    if (mediaSession().state() != PlatformMediaSession::Interrupted)
         mediaSession().beginInterruption(PlatformMediaSession::InvisibleAutoplay);
 }
 

Modified: trunk/Tools/ChangeLog (280919 => 280920)


--- trunk/Tools/ChangeLog	2021-08-11 17:59:01 UTC (rev 280919)
+++ trunk/Tools/ChangeLog	2021-08-11 18:08:49 UTC (rev 280920)
@@ -1,3 +1,13 @@
+2021-08-11  Youenn Fablet  <[email protected]>
+
+        Media element is not always autoplaying when going from background to foreground if it is initially not in viewport
+        https://bugs.webkit.org/show_bug.cgi?id=228955
+        rdar://81751653
+
+        Reviewed by Eric Carlson.
+
+        * TestWebKitAPI/Tests/WebKit/GetUserMedia.mm:
+
 2021-08-11  Lauro Moura  <[email protected]>
 
         [WPE] Handle escape key in wpeKeySymForKeyRef

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/GetUserMedia.mm (280919 => 280920)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/GetUserMedia.mm	2021-08-11 17:59:01 UTC (rev 280919)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/GetUserMedia.mm	2021-08-11 18:08:49 UTC (rev 280920)
@@ -800,6 +800,101 @@
 }
 #endif // ENABLE(GPU_PROCESS)
 
+#if PLATFORM(MAC)
+static const char* visibilityTestText = R"DOCDOCDOC(
+<html><body>
+<div id='log'></div>
+<video id='localVideo' autoplay muted playsInline width=160></video>
+<script>
+let string = '';
+_onload_ = () => {
+    for (let i = 0; i < 1000; ++i)
+        string += '<br>test';
+    if (window.internals)
+        internals.setMediaElementRestrictions(localVideo, "invisibleautoplaynotpermitted");
+    document._onvisibilitychange_ = () => window.webkit.messageHandlers.gum.postMessage("PASS");
+    window.webkit.messageHandlers.gum.postMessage("PASS");
+}
+
+function capture()
+{
+    navigator.mediaDevices.getUserMedia({video : true}).then(stream => {
+        log.innerHTML = string;
+        localVideo.srcObject = stream;
+        window.webkit.messageHandlers.gum.postMessage("PASS");
+    });
+}
+
+async function checkLocalVideoPlaying()
+{
+    let counter = 0;
+    while (++counter < 200) {
+        if (!localVideo.paused)
+            return "PASS";
+        await new Promise(resolve => setTimeout(resolve, 50));
+    }
+    return "FAIL";
+}
+
+function doTest()
+{
+    log.innerHTML = '';
+    checkLocalVideoPlaying().then(result => {
+        window.webkit.messageHandlers.gum.postMessage(result);
+    });
+}
+
+</script>
+</body></html>
+)DOCDOCDOC";
+
+TEST(WebKit, AutoplayOnVisibilityChange)
+{
+    TestWebKitAPI::HTTPServer server({
+        { "/", { visibilityTestText } }
+    }, TestWebKitAPI::HTTPServer::Protocol::Http, nullptr, nullptr, 9090);
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+    auto context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+    configuration.get().processPool = (WKProcessPool *)context.get();
+
+    auto messageHandler = adoptNS([[GUMMessageHandler alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"gum"];
+
+    auto preferences = [configuration preferences];
+    preferences._mediaCaptureRequiresSecureConnection = NO;
+    configuration.get()._mediaCaptureEnabled = YES;
+    preferences._mockCaptureDevicesEnabled = YES;
+
+    done = false;
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
+
+    auto delegate = adoptNS([[UserMediaCaptureUIDelegate alloc] init]);
+    webView.get().UIDelegate = delegate.get();
+
+    [webView loadRequest:server.request()];
+    TestWebKitAPI::Util::run(&done);
+
+    done = false;
+    auto *hostWindow = [webView hostWindow];
+    [hostWindow miniaturize:hostWindow];
+    TestWebKitAPI::Util::run(&done);
+
+    done = false;
+    [webView stringByEvaluatingJavaScript:@"capture()"];
+    TestWebKitAPI::Util::run(&done);
+
+    done = false;
+    [hostWindow deminiaturize:hostWindow];
+    TestWebKitAPI::Util::run(&done);
+
+    done = false;
+    [webView stringByEvaluatingJavaScript:@"doTest()"];
+    TestWebKitAPI::Util::run(&done);
+}
+#endif // PLATFORM(MAC)
+
 } // namespace TestWebKitAPI
 
 #endif // ENABLE(MEDIA_STREAM)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to