Chromium Code Reviews| 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 a577e6bcd7236ca592683384c57bd4a7ce84b39c..ad75aa483de9c01d28ed6296317b6f9d7941aa23 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -26,6 +26,7 @@ |
| #include "core/html/HTMLMediaElement.h" |
| +#include <limits> |
| #include "bindings/core/v8/ExceptionState.h" |
| #include "bindings/core/v8/Microtask.h" |
| #include "bindings/core/v8/ScriptController.h" |
| @@ -35,6 +36,7 @@ |
| #include "core/css/MediaList.h" |
| #include "core/dom/Attribute.h" |
| #include "core/dom/DOMException.h" |
| +#include "core/dom/DocumentUserGestureToken.h" |
| #include "core/dom/ElementTraversal.h" |
| #include "core/dom/ElementVisibilityObserver.h" |
| #include "core/dom/Fullscreen.h" |
| @@ -97,7 +99,6 @@ |
| #include "wtf/MathExtras.h" |
| #include "wtf/PtrUtil.h" |
| #include "wtf/text/CString.h" |
| -#include <limits> |
| #ifndef BLINK_MEDIA_LOG |
| #define BLINK_MEDIA_LOG DVLOG(3) |
| @@ -2315,10 +2316,15 @@ void HTMLMediaElement::pause() { |
| // Only buffer aggressively on a user-initiated pause. Other types of pauses |
| // (which go directly to pauseInternal()) should not cause this behavior. |
| - if (webMediaPlayer() && UserGestureIndicator::utilizeUserGesture()) |
| + if (webMediaPlayer() && UserGestureIndicator::utilizeUserGesture()) { |
| webMediaPlayer()->setBufferingStrategy( |
| WebMediaPlayer::BufferingStrategy::Aggressive); |
| + // Don't allow webpages to override user-initiated pause. |
| + if (hasVideo() && computeLockedPendingUserGesture(document())) |
| + m_lockedPendingUserGesture = true; |
| + } |
| + |
| if (m_autoplayVisibilityObserver) { |
| m_autoplayVisibilityObserver->stop(); |
| m_autoplayVisibilityObserver = nullptr; |
| @@ -3120,10 +3126,13 @@ void HTMLMediaElement::playbackStateChanged() { |
| if (!webMediaPlayer()) |
| return; |
| + // playbackStateChanged() is always a result of a user gesture. |
| + UserGestureIndicator gestureIndicator( |
| + DocumentUserGestureToken::create(&document())); |
|
mlamouri (slow - plz ping)
2017/02/17 12:31:31
You can create the user gesture token from the cal
whywhat
2017/02/17 16:30:24
So the callers don't know a user gesture. Ideally
|
| if (webMediaPlayer()->paused()) |
| - pauseInternal(); |
| + pause(); |
| else |
| - playInternal(); |
| + play(); |
|
mlamouri (slow - plz ping)
2017/02/17 12:31:31
I'm not sure I follow the reason why this is no lo
whywhat
2017/02/17 16:30:24
So that we respect the user gesture token and unlo
|
| } |
| void HTMLMediaElement::requestSeek(double time) { |
| @@ -3185,6 +3194,11 @@ void HTMLMediaElement::remotePlaybackStarted() { |
| remotePlaybackClient()->stateChanged(WebRemotePlaybackState::Connected); |
| } |
| +void HTMLMediaElement::wasBackgrounded() { |
| + if (hasVideo() && computeLockedPendingUserGesture(document())) |
| + m_lockedPendingUserGesture = true; |
|
mlamouri (slow - plz ping)
2017/02/17 12:31:31
We should probably discuss this more but I think t
whywhat
2017/02/17 16:30:25
I want to reuse the user gesture lock to enforce t
|
| +} |
| + |
| bool HTMLMediaElement::hasSelectedVideoTrack() { |
| DCHECK(RuntimeEnabledFeatures::backgroundVideoTrackOptimizationEnabled()); |
| @@ -3209,6 +3223,10 @@ bool HTMLMediaElement::isAutoplayingMuted() { |
| return !paused() && muted() && isLockedPendingUserGesture(); |
| } |
| +bool HTMLMediaElement::isBackgroundVideoPlaybackUnlocked() { |
| + return !isLockedPendingUserGesture(); |
| +} |
| + |
| void HTMLMediaElement::requestReload(const WebURL& newUrl) { |
| DCHECK(webMediaPlayer()); |
| DCHECK(!m_srcObject); |
| @@ -3853,7 +3871,7 @@ void HTMLMediaElement::unlockUserGesture() { |
| } |
| bool HTMLMediaElement::isGestureNeededForPlayback() const { |
| - if (!m_lockedPendingUserGesture) |
| + if (!isLockedPendingUserGesture()) |
| return false; |
| return isGestureNeededForPlaybackIfPendingUserGestureIsLocked(); |