Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Unified Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2075563003: [Android, Media] Don't unlock MediaStream elements; instead allow MS to autoplay without a gesture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
index ed596d00d9df66b3052914fec0e6c9c47b0352e2..af2469c15f6eb4ccbbf85bb5bbe3dce9fba86f62 100644
--- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
@@ -441,6 +441,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
, m_remoteRoutesAvailable(false)
, m_playingRemotely(false)
, m_inOverlayFullscreenVideo(false)
+ , m_unlockedUserGestureForMediaStream(false)
, m_audioTracks(AudioTrackList::create(*this))
, m_videoTracks(VideoTrackList::create(*this))
, m_textTracks(nullptr)
@@ -455,12 +456,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
DVLOG(MEDIA_LOG_LEVEL) << "HTMLMediaElement(" << (void*)this << ")";
- // If any experiment is enabled, then we want to enable a user gesture by
- // default, otherwise the experiment does nothing.
- if ((document.settings() && document.settings()->mediaPlaybackRequiresUserGesture())
- || m_autoplayHelper->isExperimentEnabled()) {
- m_lockedPendingUserGesture = true;
- }
+ m_lockedPendingUserGesture = needToLockPendingUserGesture(document);
setHasCustomStyleCallbacks();
addElementToDocumentMap(this, &document);
@@ -499,10 +495,8 @@ void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument)
// If any experiment is enabled, then we want to enable a user gesture by
// default, otherwise the experiment does nothing.
- bool oldDocumentRequiresUserGesture = (oldDocument.settings() && oldDocument.settings()->mediaPlaybackRequiresUserGesture())
- || m_autoplayHelper->isExperimentEnabled();
- bool newDocumentRequiresUserGesture = (document().settings() && document().settings()->mediaPlaybackRequiresUserGesture())
- || m_autoplayHelper->isExperimentEnabled();
+ bool oldDocumentRequiresUserGesture = needToLockPendingUserGesture(oldDocument);
+ bool newDocumentRequiresUserGesture = needToLockPendingUserGesture(document());
if (newDocumentRequiresUserGesture && !oldDocumentRequiresUserGesture) {
m_lockedPendingUserGesture = true;
}
@@ -696,7 +690,12 @@ void HTMLMediaElement::setSrc(const AtomicString& url)
void HTMLMediaElement::setSrcObject(MediaStreamDescriptor* srcObject)
{
DVLOG(MEDIA_LOG_LEVEL) << "setSrcObject(" << (void*)this << ")";
+
m_srcObject = srcObject;
+
+ if (m_unlockedUserGestureForMediaStream)
+ lockUserGesture();
+
invokeLoadAlgorithm();
}
@@ -1011,6 +1010,9 @@ void HTMLMediaElement::loadResource(const WebMediaPlayerSource& source, ContentT
// cache is an internal detail not exposed through the media element API.
m_currentSrc = url;
+ if (m_unlockedUserGestureForMediaStream)
+ lockUserGesture();
+
if (m_audioSourceNode)
m_audioSourceNode->onCurrentSrcChanged(m_currentSrc);
@@ -1036,6 +1038,7 @@ void HTMLMediaElement::loadResource(const WebMediaPlayerSource& source, ContentT
bool isMediaStream = source.isMediaStream() || (source.isURL() && isMediaStreamURL(url.getString()));
if (isMediaStream) {
m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByStream);
+ m_unlockedUserGestureForMediaStream = true;
} else {
m_mediaSource = HTMLMediaSource::lookup(url.getString());
@@ -3699,6 +3702,19 @@ bool HTMLMediaElement::isLockedPendingUserGesture() const
void HTMLMediaElement::unlockUserGesture()
{
m_lockedPendingUserGesture = false;
+ m_unlockedUserGestureForMediaStream = false;
+}
+
+void HTMLMediaElement::lockUserGesture()
+{
+ m_lockedPendingUserGesture = needToLockPendingUserGesture(document());
+ m_unlockedUserGestureForMediaStream = false;
+}
+
+bool HTMLMediaElement::needToLockPendingUserGesture(const Document& document) const
+{
+ return (document.settings() && document.settings()->mediaPlaybackRequiresUserGesture())
+ || m_autoplayHelper->isExperimentEnabled();
}
bool HTMLMediaElement::isGestureNeededForPlayback() const

Powered by Google App Engine
This is Rietveld 408576698