From 31dba079cf3041945529750234190fc24ed92ab5 Mon Sep 17 00:00:00 2001 From: Teng-Hui Zhu Date: Fri, 23 Dec 2011 10:40:01 -0800 Subject: Only allow user gesture to play video Basically, once a guesture trigger a video to load, play or pause, then no need for future gesture to interact with the video. Change-Id: I0631ea0d5efc1f6fff89e1eaaebee0e601403b27 --- Source/WebCore/html/HTMLMediaElement.cpp | 34 +++++++++++++++++++++++++++----- Source/WebCore/html/HTMLMediaElement.h | 4 ++++ 2 files changed, 33 insertions(+), 5 deletions(-) (limited to 'Source/WebCore/html') diff --git a/Source/WebCore/html/HTMLMediaElement.cpp b/Source/WebCore/html/HTMLMediaElement.cpp index e1f4227..ae0571c 100644 --- a/Source/WebCore/html/HTMLMediaElement.cpp +++ b/Source/WebCore/html/HTMLMediaElement.cpp @@ -178,6 +178,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum , m_completelyLoaded(false) #if PLATFORM(ANDROID) , m_lastTouch(0) + , m_userGestureInitiated(false) #endif { LOG(Media, "HTMLMediaElement::HTMLMediaElement"); @@ -187,8 +188,8 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) // Enable the Media Element to listen to all the touch events document->addListenerTypeIfNeeded(eventNames().touchstartEvent); + m_restrictions |= RequireUserGestureForRateChangeRestriction; #endif - } HTMLMediaElement::~HTMLMediaElement() @@ -515,6 +516,9 @@ void HTMLMediaElement::load(bool isUserGesture, ExceptionCode& ec) ec = INVALID_STATE_ERR; else { m_loadInitiatedByUserGesture = isUserGesture; +#if PLATFORM(ANDROID) + m_userGestureInitiated |= isUserGesture; +#endif prepareForLoad(); loadInternal(); } @@ -1417,9 +1421,19 @@ void HTMLMediaElement::play(bool isUserGesture) { LOG(Media, "HTMLMediaElement::play(isUserGesture : %s)", boolString(isUserGesture)); - if (m_restrictions & RequireUserGestureForRateChangeRestriction && !isUserGesture) + if (m_restrictions & RequireUserGestureForRateChangeRestriction && !isUserGesture +#if PLATFORM(ANDROID) + && !m_userGestureInitiated +#endif + ) return; +#if PLATFORM(ANDROID) + // B/c we set the restriction to require gesture for rate change for + // Android, when we don't early return, we can safely set this to true. + m_userGestureInitiated = true; +#endif + Document* doc = document(); Settings* settings = doc->settings(); if (settings && settings->needsSiteSpecificQuirks() && m_dispatchingCanPlayEvent && !m_loadInitiatedByUserGesture) { @@ -1466,9 +1480,17 @@ void HTMLMediaElement::pause(bool isUserGesture) { LOG(Media, "HTMLMediaElement::pause(isUserGesture : %s)", boolString(isUserGesture)); - if (m_restrictions & RequireUserGestureForRateChangeRestriction && !isUserGesture) + if (m_restrictions & RequireUserGestureForRateChangeRestriction && !isUserGesture +#if PLATFORM(ANDROID) + && !m_userGestureInitiated +#endif + ) return; - +#if PLATFORM(ANDROID) + // B/c we set the restriction to require gesture for rate change for + // Android, when we don't early return, we can safely set this to true. + m_userGestureInitiated = true; +#endif pauseInternal(); } @@ -2406,8 +2428,10 @@ void HTMLMediaElement::defaultEventHandler(Event* event) // It is really hard to hit the play/pause button on mobile devices. // This allows user to click the video area to toggle play/pause state. if (event->type() == eventNames().clickEvent - && !hasEventListeners(eventNames().clickEvent)) + && !hasEventListeners(eventNames().clickEvent)) { + m_userGestureInitiated = true; togglePlayState(); + } #endif HTMLElement::defaultEventHandler(event); #endif diff --git a/Source/WebCore/html/HTMLMediaElement.h b/Source/WebCore/html/HTMLMediaElement.h index 987cf87..2144ea1 100644 --- a/Source/WebCore/html/HTMLMediaElement.h +++ b/Source/WebCore/html/HTMLMediaElement.h @@ -420,6 +420,10 @@ private: #if PLATFORM(ANDROID) double m_lastTouch; + // When user gesture invoke load, play or pause, this turns to be true. + // After this becomes true, we ignore the user gesture requirement for play + // and pause. + bool m_userGestureInitiated; #endif }; -- cgit v1.1