From b5dcd20158a30d6015aab55b77bf2d3e4e6fe320 Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Wed, 10 Jun 2015 18:43:52 +0000 Subject: [PATCH] Explicitly keep track of active HTMLMediaElements in MediaSessions. https://bugs.webkit.org/show_bug.cgi?id=145829 Patch by Matt Rajca on 2015-06-10 Reviewed by Eric Carlson. * Modules/mediasession/MediaSession.cpp: Add support for keeping track of active media elements. (WebCore::MediaSession::addActiveMediaElement): * Modules/mediasession/MediaSession.h: * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::playInternal): If the paused attribute is true and the readyState attribute has the value HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, the media element becomes an active participating element of the media session. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185424 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 15 +++++++++++++++ Source/WebCore/Modules/mediasession/MediaSession.cpp | 13 +++---------- Source/WebCore/Modules/mediasession/MediaSession.h | 3 ++- Source/WebCore/html/HTMLMediaElement.cpp | 13 +++++++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 26c69d9..70d0d1c 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,18 @@ +2015-06-10 Matt Rajca + + Explicitly keep track of active HTMLMediaElements in MediaSessions. + https://bugs.webkit.org/show_bug.cgi?id=145829 + + Reviewed by Eric Carlson. + + * Modules/mediasession/MediaSession.cpp: Add support for keeping track of active media elements. + (WebCore::MediaSession::addActiveMediaElement): + * Modules/mediasession/MediaSession.h: + * html/HTMLMediaElement.cpp: + (WebCore::HTMLMediaElement::playInternal): If the paused attribute is true and the readyState attribute has the + value HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, the media element becomes an active participating element of the + media session. + 2015-06-10 Chris Dumez Drop unused argument for Node::didNotifySubtreeInsertions() diff --git a/Source/WebCore/Modules/mediasession/MediaSession.cpp b/Source/WebCore/Modules/mediasession/MediaSession.cpp index 7e9a2a3..c240d26 100644 --- a/Source/WebCore/Modules/mediasession/MediaSession.cpp +++ b/Source/WebCore/Modules/mediasession/MediaSession.cpp @@ -66,16 +66,9 @@ void MediaSession::removeMediaElement(HTMLMediaElement& element) m_participatingElements.remove(m_participatingElements.find(&element)); } -Vector MediaSession::activeParticipatingElements() const +void MediaSession::addActiveMediaElement(HTMLMediaElement& element) { - Vector elements; - - for (auto* element : m_participatingElements) { - if (element->isPlaying()) - elements.append(element); - } - - return elements; + m_activeParticipatingElements.add(&element); } void MediaSession::releaseSession() @@ -84,7 +77,7 @@ void MediaSession::releaseSession() void MediaSession::togglePlayback() { - for (auto* element : activeParticipatingElements()) { + for (auto* element : m_activeParticipatingElements) { if (element->paused()) element->play(); else diff --git a/Source/WebCore/Modules/mediasession/MediaSession.h b/Source/WebCore/Modules/mediasession/MediaSession.h index d2c31c1..87c8312 100644 --- a/Source/WebCore/Modules/mediasession/MediaSession.h +++ b/Source/WebCore/Modules/mediasession/MediaSession.h @@ -65,10 +65,11 @@ private: void addMediaElement(HTMLMediaElement&); void removeMediaElement(HTMLMediaElement&); - Vector activeParticipatingElements() const; + void addActiveMediaElement(HTMLMediaElement&); State m_currentState { State::Idle }; Vector m_participatingElements; + HashSet m_activeParticipatingElements; const String m_kind; RefPtr m_controls; diff --git a/Source/WebCore/html/HTMLMediaElement.cpp b/Source/WebCore/html/HTMLMediaElement.cpp index eb7004c..e4acbed 100644 --- a/Source/WebCore/html/HTMLMediaElement.cpp +++ b/Source/WebCore/html/HTMLMediaElement.cpp @@ -2829,6 +2829,19 @@ void HTMLMediaElement::playInternal() scheduleEvent(eventNames().waitingEvent); else if (m_readyState >= HAVE_FUTURE_DATA) scheduleEvent(eventNames().playingEvent); + +#if ENABLE(MEDIA_SESSION) + // 6.3 Activating a media session from a media element + // When the play() method is invoked, the paused attribute is true, and the readyState attribute has the value + // HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, then + // 1. Let media session be the value of the current media session. + // 2. If we are not currently in media session's list of active participating media elements then append + // ourselves to this list. + if (m_readyState == HAVE_ENOUGH_DATA || m_readyState == HAVE_FUTURE_DATA) { + if (m_session) + m_session->addActiveMediaElement(*this); + } +#endif } m_autoplaying = false; updatePlayState(); -- 1.8.3.1