Title: [120112] trunk
Revision
120112
Author
commit-qu...@webkit.org
Date
2012-06-12 13:37:16 -0700 (Tue, 12 Jun 2012)

Log Message

Disable autoplay when user gesture is required for media playback
https://bugs.webkit.org/show_bug.cgi?id=88897

Patch by Min Qin <qin...@google.com> on 2012-06-12
Reviewed by Adam Barth.

When user gesture is required for media playback, we should block autoplay.
Otherwise, people will use autoplay instead of video.play() to bypass the gesture requirement.
Test: media/no-autoplay-with-user-gesture-requirement.html

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

Modified Paths

Added Paths

Diff

Added: trunk/LayoutTests/media/no-autoplay-with-user-gesture-requirement-expected.txt (0 => 120112)


--- trunk/LayoutTests/media/no-autoplay-with-user-gesture-requirement-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/no-autoplay-with-user-gesture-requirement-expected.txt	2012-06-12 20:37:16 UTC (rev 120112)
@@ -0,0 +1,7 @@
+Test that media autoplay should not work if user gesture is required for playback.
+
+EXPECTED (video.paused == 'true') OK
+EVENT(canplaythrough)
+EXPECTED (video.paused == 'true') OK
+END OF TEST
+

Added: trunk/LayoutTests/media/no-autoplay-with-user-gesture-requirement.html (0 => 120112)


--- trunk/LayoutTests/media/no-autoplay-with-user-gesture-requirement.html	                        (rev 0)
+++ trunk/LayoutTests/media/no-autoplay-with-user-gesture-requirement.html	2012-06-12 20:37:16 UTC (rev 120112)
@@ -0,0 +1,48 @@
+<html>
+    <head>
+        <title>Test that media autoplay should not work if user gesture is required for playback</title>
+        <script src=""
+        <script src=""
+        <script>
+            if (window.internals) 
+                window.internals.settings.setMediaPlaybackRequiresUserGesture(true);
+
+            function cleanGestureRequirement() {
+                if (window.internals) 
+                    window.internals.settings.setMediaPlaybackRequiresUserGesture(false);
+            }
+
+            function testPlay()
+            {
+                cleanGestureRequirement();
+                failTest("play event should not fire without user gesture.");
+            }
+
+            function testPaused()
+            {
+                testExpected("video.paused", true);
+                cleanGestureRequirement(); 
+                endTest();
+            }
+
+            function canplaythrough()
+            {
+                 setTimeout(testPaused, 500);
+            }
+
+            function start()
+            {
+                 findMediaElement();
+                 video.src = "" "content/test");
+                 testExpected("video.paused", true);
+                 waitForEvent('canplaythrough', canplaythrough);
+                 waitForEvent('play', testPlay);
+            }
+        </script>
+    </head>
+
+    <body _onload_="start()">
+    <p>Test that media autoplay should not work if user gesture is required for playback.</p>
+    <video controls autoplay></video>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (120111 => 120112)


--- trunk/Source/WebCore/ChangeLog	2012-06-12 20:37:15 UTC (rev 120111)
+++ trunk/Source/WebCore/ChangeLog	2012-06-12 20:37:16 UTC (rev 120112)
@@ -1,3 +1,17 @@
+2012-06-12  Min Qin  <qin...@google.com>
+
+        Disable autoplay when user gesture is required for media playback
+        https://bugs.webkit.org/show_bug.cgi?id=88897
+
+        Reviewed by Adam Barth.
+
+        When user gesture is required for media playback, we should block autoplay.
+        Otherwise, people will use autoplay instead of video.play() to bypass the gesture requirement.
+        Test: media/no-autoplay-with-user-gesture-requirement.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setReadyState):
+
 2012-06-12  Shrey Banga  <ba...@chromium.org>
 
         HTML parser should yield more to improve perceived page load time

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (120111 => 120112)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-06-12 20:37:15 UTC (rev 120111)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2012-06-12 20:37:16 UTC (rev 120112)
@@ -1693,7 +1693,7 @@
         if (isPotentiallyPlaying && oldState <= HAVE_CURRENT_DATA)
             scheduleEvent(eventNames().playingEvent);
 
-        if (m_autoplaying && m_paused && autoplay() && !document()->isSandboxed(SandboxAutomaticFeatures)) {
+        if (m_autoplaying && m_paused && autoplay() && !document()->isSandboxed(SandboxAutomaticFeatures) && !userGestureRequiredForRateChange()) {
             m_paused = false;
             invalidateCachedTime();
             scheduleEvent(eventNames().playEvent);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to