Diff
Modified: trunk/LayoutTests/ChangeLog (108830 => 108831)
--- trunk/LayoutTests/ChangeLog 2012-02-24 19:32:43 UTC (rev 108830)
+++ trunk/LayoutTests/ChangeLog 2012-02-24 19:35:27 UTC (rev 108831)
@@ -1,3 +1,13 @@
+2012-02-24 Min Qin <[email protected]>
+
+ Expose a setting to exempt media playback from user gesture requirement after a user gesture is initiated on loading/playing a media
+ https://bugs.webkit.org/show_bug.cgi?id=79167
+
+ Reviewed by Adam Barth.
+
+ * media/video-play-require-user-gesture-expected.txt: Added.
+ * media/video-play-require-user-gesture.html: Added.
+
2012-02-24 Philip Rogers <[email protected]>
Remove spurious mac-specific tests
Added: trunk/LayoutTests/media/video-play-require-user-gesture-expected.txt (0 => 108831)
--- trunk/LayoutTests/media/video-play-require-user-gesture-expected.txt (rev 0)
+++ trunk/LayoutTests/media/video-play-require-user-gesture-expected.txt 2012-02-24 19:35:27 UTC (rev 108831)
@@ -0,0 +1,17 @@
+Test that video play(), pause() and webkitEnterFullScreen() should not work unless a user clicked on the play button.
+
+EVENT(canplaythrough)
+
+* No user gesture initiated
+RUN(video.play())
+TEST(video.webkitEnterFullScreen()) THROWS(DOMException.INVALID_STATE_ERR) OK
+EXPECTED (video.paused == 'true') OK
+
+* User gesture initiated
+EVENT(playing)
+RUN(video.pause())
+EVENT(pause)
+EXPECTED (video.paused == 'true') OK
+RUN(video.webkitEnterFullScreen())
+END OF TEST
+
Added: trunk/LayoutTests/media/video-play-require-user-gesture.html (0 => 108831)
--- trunk/LayoutTests/media/video-play-require-user-gesture.html (rev 0)
+++ trunk/LayoutTests/media/video-play-require-user-gesture.html 2012-02-24 19:35:27 UTC (rev 108831)
@@ -0,0 +1,83 @@
+<html>
+ <head>
+ <title>Test that video play, pause and enterfullscreen does not work unless a user gesture is involved in playing a video</title>
+ <script src=""
+ <script src=""
+ <script src=""
+ <script>
+ var userGestureInitiated = 0;
+ if (window.internals)
+ window.internals.setMediaPlaybackRequiresUserGesture(document, true);
+
+ function click()
+ {
+ if (window.eventSender) {
+ var playCoords;
+ try {
+ playCoords = mediaControlsButtonCoordinates(video, "play-button");
+ } catch (exception) {
+ failTest(exception.description);
+ return;
+ }
+ var x = playCoords[0];
+ var y = playCoords[1];
+
+ userGestureInitiated = 1;
+ eventSender.mouseMoveTo(x, y);
+ eventSender.mouseDown();
+ eventSender.mouseUp();
+ }
+ }
+
+ function playing()
+ {
+ if (userGestureInitiated == 0) {
+ failTest("Should not play without user gesture.");
+ } else {
+ run("video.pause()");
+ }
+ }
+
+ function pause()
+ {
+ testExpected("video.paused", true);
+ // Now video.webkitEnterFullScreen() should no longer throw any exception.
+ // However, the video element may not always enter fullscreen. For example,
+ // chromium uses fullscreen API which still requires user gesture
+ try {
+ run("video.webkitEnterFullScreen()");
+ } catch(ex) {
+ failTest("video.webkitEnterFullScreen() still requires user gesture.");
+ }
+ endTest();
+ }
+
+ function canplaythrough()
+ {
+ consoleWrite("");
+ consoleWrite("* No user gesture initiated");
+ run("video.play()");
+ testException("video.webkitEnterFullScreen()", "DOMException.INVALID_STATE_ERR");
+ testExpected("video.paused", true);
+ consoleWrite("");
+
+ consoleWrite("* User gesture initiated");
+ click();
+ }
+
+ function start()
+ {
+ findMediaElement();
+ waitForEvent('canplaythrough', canplaythrough);
+ waitForEvent('playing', playing);
+ waitForEvent('pause', pause);
+ video.src = "" "content/test");
+ }
+ </script>
+ </head>
+
+ <body _onload_="start()">
+ <p>Test that video play(), pause() and webkitEnterFullScreen() should not work unless a user clicked on the play button.</p>
+ <video controls></video>
+ </body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (108830 => 108831)
--- trunk/Source/WebCore/ChangeLog 2012-02-24 19:32:43 UTC (rev 108830)
+++ trunk/Source/WebCore/ChangeLog 2012-02-24 19:35:27 UTC (rev 108831)
@@ -1,3 +1,26 @@
+2012-02-24 Min Qin <[email protected]>
+
+ Expose a setting to exempt media playback from user gesture requirement after a user gesture is initiated on loading/playing a media
+ https://bugs.webkit.org/show_bug.cgi?id=79167
+
+ Reviewed by Adam Barth.
+
+ Test: media/video-play-require-user-gesture.html
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::load):
+ (WebCore::HTMLMediaElement::play):
+ (WebCore::HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture):
+ (WebCore):
+ * html/HTMLMediaElement.h:
+ (HTMLMediaElement):
+ * testing/Internals.cpp:
+ (WebCore::Internals::setMediaPlaybackRequiresUserGesture):
+ (WebCore):
+ * testing/Internals.h:
+ (Internals):
+ * testing/Internals.idl:
+
2012-02-24 Adam Barth <[email protected]>
DOMWindow*.idl should have had the same license block as DOMWindow.idl did originally
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (108830 => 108831)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2012-02-24 19:32:43 UTC (rev 108830)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2012-02-24 19:35:27 UTC (rev 108831)
@@ -619,6 +619,8 @@
ec = INVALID_STATE_ERR;
else {
m_loadInitiatedByUserGesture = ScriptController::processingUserGesture();
+ if (m_loadInitiatedByUserGesture)
+ removeBehaviorsRestrictionsAfterFirstUserGesture();
prepareForLoad();
loadInternal();
}
@@ -2073,6 +2075,8 @@
if (userGestureRequiredForRateChange() && !ScriptController::processingUserGesture())
return;
+ if (ScriptController::processingUserGesture())
+ removeBehaviorsRestrictionsAfterFirstUserGesture();
Settings* settings = document()->settings();
if (settings && settings->needsSiteSpecificQuirks() && m_dispatchingCanPlayEvent && !m_loadInitiatedByUserGesture) {
@@ -4053,5 +4057,10 @@
return SecurityPolicy::generateReferrerHeader(document()->referrerPolicy(), m_currentSrc, frame->loader()->outgoingReferrer());
}
+void HTMLMediaElement::removeBehaviorsRestrictionsAfterFirstUserGesture()
+{
+ m_restrictions = NoRestrictions;
}
+
+}
#endif
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (108830 => 108831)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2012-02-24 19:32:43 UTC (rev 108830)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2012-02-24 19:35:27 UTC (rev 108831)
@@ -477,6 +477,8 @@
void changeNetworkStateFromLoadingToIdle();
+ void removeBehaviorsRestrictionsAfterFirstUserGesture();
+
#if ENABLE(MICRODATA)
virtual String itemValueText() const;
virtual void setItemValueText(const String&, ExceptionCode&);
Modified: trunk/Source/WebCore/testing/Internals.cpp (108830 => 108831)
--- trunk/Source/WebCore/testing/Internals.cpp 2012-02-24 19:32:43 UTC (rev 108830)
+++ trunk/Source/WebCore/testing/Internals.cpp 2012-02-24 19:35:27 UTC (rev 108831)
@@ -541,6 +541,16 @@
return checker->lastProcessedSequence();
}
+void Internals::setMediaPlaybackRequiresUserGesture(Document* document, bool enabled, ExceptionCode& ec)
+{
+ if (!document || !document->settings()) {
+ ec = INVALID_ACCESS_ERR;
+ return;
+ }
+
+ document->settings()->setMediaPlaybackRequiresUserGesture(enabled);
+}
+
Vector<String> Internals::userPreferredLanguages() const
{
return WebCore::userPreferredLanguages();
Modified: trunk/Source/WebCore/testing/Internals.h (108830 => 108831)
--- trunk/Source/WebCore/testing/Internals.h 2012-02-24 19:32:43 UTC (rev 108830)
+++ trunk/Source/WebCore/testing/Internals.h 2012-02-24 19:35:27 UTC (rev 108831)
@@ -106,6 +106,8 @@
int lastSpellCheckRequestSequence(Document*, ExceptionCode&);
int lastSpellCheckProcessedSequence(Document*, ExceptionCode&);
+ void setMediaPlaybackRequiresUserGesture(Document*, bool enabled, ExceptionCode&);
+
Vector<String> userPreferredLanguages() const;
void setUserPreferredLanguages(const Vector<String>&);
Modified: trunk/Source/WebCore/testing/Internals.idl (108830 => 108831)
--- trunk/Source/WebCore/testing/Internals.idl 2012-02-24 19:32:43 UTC (rev 108830)
+++ trunk/Source/WebCore/testing/Internals.idl 2012-02-24 19:35:27 UTC (rev 108831)
@@ -81,6 +81,8 @@
long lastSpellCheckRequestSequence(in Document document) raises (DOMException);
long lastSpellCheckProcessedSequence(in Document document) raises (DOMException);
+ void setMediaPlaybackRequiresUserGesture(in Document document, in boolean enabled) raises(DOMException);
+
#if defined(ENABLE_VIDEO_TRACK) && ENABLE_VIDEO_TRACK
void setShouldDisplayTrackKind(in Document document, in DOMString kind, in boolean enabled) raises (DOMException);
boolean shouldDisplayTrackKind(in Document document, in DOMString trackKind) raises (DOMException);