webkitpresentationmodechanged is fired twice when exiting picture in picture
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Aug 2019 15:23:46 +0000 (15:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Aug 2019 15:23:46 +0000 (15:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193765

Patch by Peng Liu <peng.liu6@apple.com> on 2019-08-27
Reviewed by Jer Noble.

Source/WebCore:

This patch removes the extra "webkitpresentationmodechanged" event when the browser switches from
picture-in-picture or fullscreen to inline.

The bug was introduced by the fix for bug
https://bugs.webkit.org/show_bug.cgi?id=181095
But now we are using modern media controls and the fix is not necessary.
Reverting that fix can fix the issue.

Also, this patch gets rid of the unnecessary try to call a JavaScript function which is not available
in the modern media controls.

Test: media/presentationmodechanged-fired-once.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::exitFullscreen):
(WebCore::HTMLMediaElement::updateMediaControlsAfterPresentationModeChange):

LayoutTests:

* media/presentationmodechanged-fired-once-expected.txt: Added.
* media/presentationmodechanged-fired-once.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249141 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/media/presentationmodechanged-fired-once-expected.txt [new file with mode: 0644]
LayoutTests/media/presentationmodechanged-fired-once.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp

index 19028a5..043f6c8 100644 (file)
@@ -1,3 +1,13 @@
+2019-08-27  Peng Liu  <peng.liu6@apple.com>
+
+        webkitpresentationmodechanged is fired twice when exiting picture in picture
+        https://bugs.webkit.org/show_bug.cgi?id=193765
+
+        Reviewed by Jer Noble.
+
+        * media/presentationmodechanged-fired-once-expected.txt: Added.
+        * media/presentationmodechanged-fired-once.html: Added.
+
 2019-08-27  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Origin header not included in WebSocket handshake request when using platform WebSocket API
diff --git a/LayoutTests/media/presentationmodechanged-fired-once-expected.txt b/LayoutTests/media/presentationmodechanged-fired-once-expected.txt
new file mode 100644 (file)
index 0000000..ac3b636
--- /dev/null
@@ -0,0 +1,14 @@
+This tests that the "webkitpresentationmodechanged" event is fired only once when the browser switches back to inline from the picture-in-picture mode.
+
+RUN(internals.settings.setAllowsPictureInPictureMediaPlayback(true))
+RUN(video.src = findMediaFile("video", "content/test"))
+EVENT(canplaythrough)
+RUN(video.play())
+RUN(video.webkitSetPresentationMode("picture-in-picture"))
+EVENT(webkitpresentationmodechanged)
+EXPECTED (video.webkitPresentationMode == 'picture-in-picture') OK
+RUN(video.webkitSetPresentationMode("inline"))
+EVENT(webkitpresentationmodechanged)
+EXPECTED (video.webkitPresentationMode == 'inline') OK
+END OF TEST
+
diff --git a/LayoutTests/media/presentationmodechanged-fired-once.html b/LayoutTests/media/presentationmodechanged-fired-once.html
new file mode 100644 (file)
index 0000000..de83dea
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="video-test.js"></script>
+    <script src="media-file.js"></script>
+    <script>
+        var eventCount = 0;
+
+        function go()
+        {
+            findMediaElement();
+            run('internals.settings.setAllowsPictureInPictureMediaPlayback(true)');
+            run('video.src = findMediaFile("video", "content/test")');
+            waitForEventOnce('canplaythrough', canPlayThrough);
+        }
+
+        function canPlayThrough()
+        {
+            runWithKeyDown('video.play()');
+            runWithKeyDown('video.webkitSetPresentationMode("picture-in-picture")');
+            waitForEventOnce("webkitpresentationmodechanged", presentationModeChanged1);
+        }
+
+        function presentationModeChanged1()
+        {
+            testExpected("video.webkitPresentationMode", "picture-in-picture");
+            runWithKeyDown('video.webkitSetPresentationMode("inline")');
+            waitForEvent("webkitpresentationmodechanged", presentationModeChanged2);
+        }
+
+        function presentationModeChanged2()
+        {
+            switch (++eventCount)
+            {
+                case 1:
+                    testExpected("video.webkitPresentationMode", "inline");
+                    setTimeout(endTest, 200);
+                    break;
+                default:
+                    failTest("'webkitpresentationmodechanged' event fired again");
+                    break;
+            }
+        }
+    </script>
+</head>
+<body onload="go()">
+    <div>This tests that the "webkitpresentationmodechanged" event is fired only once when the browser switches back to inline from the picture-in-picture mode.</div>
+    <video controls></video>
+</body>
+</html>
index a01689e..567766b 100644 (file)
@@ -1,3 +1,27 @@
+2019-08-27  Peng Liu  <peng.liu6@apple.com>
+
+        webkitpresentationmodechanged is fired twice when exiting picture in picture
+        https://bugs.webkit.org/show_bug.cgi?id=193765
+
+        Reviewed by Jer Noble.
+
+        This patch removes the extra "webkitpresentationmodechanged" event when the browser switches from
+        picture-in-picture or fullscreen to inline.
+
+        The bug was introduced by the fix for bug
+        https://bugs.webkit.org/show_bug.cgi?id=181095
+        But now we are using modern media controls and the fix is not necessary.
+        Reverting that fix can fix the issue.
+
+        Also, this patch gets rid of the unnecessary try to call a JavaScript function which is not available
+        in the modern media controls.
+
+        Test: media/presentationmodechanged-fired-once.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::exitFullscreen):
+        (WebCore::HTMLMediaElement::updateMediaControlsAfterPresentationModeChange):
+
 2019-08-27  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Image pasted from screenshot into Mail compose window via share sheet has the wrong aspect ratio
index f64fe92..a4c60e4 100644 (file)
@@ -6121,7 +6121,6 @@ void HTMLMediaElement::exitFullscreen()
         else
             document().page()->chrome().client().exitVideoFullscreenForVideoElement(downcast<HTMLVideoElement>(*this));
         scheduleEvent(eventNames().webkitendfullscreenEvent);
-        scheduleEvent(eventNames().webkitpresentationmodechangedEvent);
     }
 }
 
@@ -7435,6 +7434,9 @@ void HTMLMediaElement::updateMediaControlsAfterPresentationModeChange()
     if (!m_mediaControlsHost || document().activeDOMObjectsAreSuspended() || document().activeDOMObjectsAreStopped())
         return;
 
+    if (RuntimeEnabledFeatures::sharedFeatures().modernMediaControlsEnabled())
+        return;
+
     setupAndCallJS([this](JSDOMGlobalObject& globalObject, JSC::ExecState& exec, ScriptController&, DOMWrapperWorld&) {
         auto& vm = globalObject.vm();
         auto scope = DECLARE_THROW_SCOPE(vm);