[iOS] Add a hack to work around buggy video control library
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2019 00:28:55 +0000 (00:28 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2019 00:28:55 +0000 (00:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194615
<rdar://problem/46146946>

Reviewed by Jer Noble.

Source/WebCore:

Test: media/ios/video-volume-ios-quirk.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setVolume): Change m_volume for one turn of the runloop.
(WebCore::HTMLMediaElement::cancelPendingTasks): Clear the task queue used to restore m_volume.
(WebCore::HTMLMediaElement::closeTaskQueues): Close it.
* html/HTMLMediaElement.h:

LayoutTests:

* media/ios/video-volume-ios-quirk-expected.txt: Added.
* media/ios/video-volume-ios-quirk.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/media/ios/video-volume-ios-quirk-expected.txt [new file with mode: 0644]
LayoutTests/media/ios/video-volume-ios-quirk.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h

index 581b719..15a3d8d 100644 (file)
@@ -1,3 +1,14 @@
+2019-02-13  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] Add a hack to work around buggy video control library
+        https://bugs.webkit.org/show_bug.cgi?id=194615
+        <rdar://problem/46146946>
+
+        Reviewed by Jer Noble.
+
+        * media/ios/video-volume-ios-quirk-expected.txt: Added.
+        * media/ios/video-volume-ios-quirk.html: Added.
+
 2019-02-13  Jer Noble  <jer.noble@apple.com>
 
         Entering fullscreen inside a shadow root will not set fullscreen pseudoclasses outside of root
diff --git a/LayoutTests/media/ios/video-volume-ios-quirk-expected.txt b/LayoutTests/media/ios/video-volume-ios-quirk-expected.txt
new file mode 100644 (file)
index 0000000..04340b8
--- /dev/null
@@ -0,0 +1,13 @@
+
+Test 'volume' attribute
+
+EXPECTED (video.volume == '1') OK
+RUN(video.volume = 0.5)
+EXPECTED (video.volume == '0.5') OK
+RUN(video.volume = 0)
+EXPECTED (video.volume == '0') OK
+TEST(video.volume = 1.5) THROWS(DOMException.INDEX_SIZE_ERR) OK
+TEST(video.volume = -0.5) THROWS(DOMException.INDEX_SIZE_ERR) OK
+EXPECTED (video.volume == '1') OK
+END OF TEST
+
diff --git a/LayoutTests/media/ios/video-volume-ios-quirk.html b/LayoutTests/media/ios/video-volume-ios-quirk.html
new file mode 100644 (file)
index 0000000..3be41b3
--- /dev/null
@@ -0,0 +1,19 @@
+<video controls></video>
+<p>Test 'volume' attribute<p>
+<script src=../media-file.js></script>
+<script src=../video-test.js></script>
+<script>
+    testExpected("video.volume", 1.0);
+    run("video.volume = 0.5");
+    testExpected("video.volume", 0.5);
+    run("video.volume = 0");
+    testExpected("video.volume", 0);
+    testDOMException("video.volume = 1.5", "DOMException.INDEX_SIZE_ERR");
+    testDOMException("video.volume = -0.5", "DOMException.INDEX_SIZE_ERR");
+    video.src = findMediaFile("video", "content/test");
+
+       setTimeout(function() { 
+           testExpected("video.volume", 1.0);
+        endTest();
+       } , 100);
+</script>
index 236590a..d05b130 100644 (file)
@@ -1,3 +1,19 @@
+2019-02-13  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] Add a hack to work around buggy video control library
+        https://bugs.webkit.org/show_bug.cgi?id=194615
+        <rdar://problem/46146946>
+
+        Reviewed by Jer Noble.
+
+        Test: media/ios/video-volume-ios-quirk.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setVolume): Change m_volume for one turn of the runloop.
+        (WebCore::HTMLMediaElement::cancelPendingTasks): Clear the task queue used to restore m_volume.
+        (WebCore::HTMLMediaElement::closeTaskQueues): Close it.
+        * html/HTMLMediaElement.h:
+
 2019-02-13  Jer Noble  <jer.noble@apple.com>
 
         [Cocoa] Media elements will restart network buffering just before suspending
index 3d1e343..88eae18 100644 (file)
@@ -3722,10 +3722,10 @@ ExceptionOr<void> HTMLMediaElement::setVolume(double volume)
     if (!(volume >= 0 && volume <= 1))
         return Exception { IndexSizeError };
 
-#if !PLATFORM(IOS_FAMILY)
     if (m_volume == volume)
         return { };
 
+#if !PLATFORM(IOS_FAMILY)
     if (volume && processingUserGestureForMedia())
         removeBehaviorsRestrictionsAfterFirstUserGesture(MediaElementSession::AllRestrictions & ~MediaElementSession::RequireUserGestureToControlControlsManager);
 
@@ -3738,7 +3738,19 @@ ExceptionOr<void> HTMLMediaElement::setVolume(double volume)
         pauseInternal();
         setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
     }
+#else
+    auto oldVolume = m_volume;
+    m_volume = volume;
+
+    if (m_volumeRevertTaskQueue.hasPendingTask())
+        return { };
+
+    m_volumeRevertTaskQueue.scheduleTask([this, oldVolume] {
+        m_volume = oldVolume;
+    });
+
 #endif
+    
     return { };
 }
 
@@ -5527,6 +5539,9 @@ void HTMLMediaElement::cancelPendingTasks()
     m_updateMediaStateTask.cancelTask();
     m_mediaEngineUpdatedTask.cancelTask();
     m_updatePlayStateTask.cancelTask();
+#if PLATFORM(IOS_FAMILY)
+    m_volumeRevertTaskQueue.cancelTask();
+#endif
 }
 
 void HTMLMediaElement::userCancelledLoad()
@@ -5705,6 +5720,9 @@ void HTMLMediaElement::closeTaskQueues()
     m_encryptedMediaQueue.close();
 #endif
     m_asyncEventQueue.close();
+#if PLATFORM(IOS_FAMILY)
+    m_volumeRevertTaskQueue.close();
+#endif
 }
 
 void HTMLMediaElement::contextDestroyed()
index b90dc29..34e184a 100644 (file)
@@ -967,6 +967,9 @@ private:
     GenericTaskQueue<Timer> m_playbackTargetIsWirelessQueue;
     RefPtr<TimeRanges> m_playedTimeRanges;
     GenericEventQueue m_asyncEventQueue;
+#if PLATFORM(IOS_FAMILY)
+    DeferrableTask<Timer> m_volumeRevertTaskQueue;
+#endif
 
     PlayPromiseVector m_pendingPlayPromises;