Chromium Code Reviews| Index: media/blink/webmediaplayer_impl.cc |
| diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc |
| index a195bbffe433dd586df6ba14be3dffe79a5891dd..82f021eb57feac1ad0954c592152b681b6e6898d 100644 |
| --- a/media/blink/webmediaplayer_impl.cc |
| +++ b/media/blink/webmediaplayer_impl.cc |
| @@ -63,6 +63,7 @@ |
| #include "third_party/WebKit/public/web/WebDocument.h" |
| #include "third_party/WebKit/public/web/WebFrame.h" |
| #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| +#include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| #include "third_party/WebKit/public/web/WebView.h" |
| #if defined(OS_ANDROID) |
| @@ -1962,9 +1963,12 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote, |
| bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); |
| bool can_play_backgrounded = is_backgrounded_video && !is_remote && |
| hasAudio() && IsResumeBackgroundVideosEnabled(); |
| - bool is_background_playing = delegate_->IsBackgroundVideoPlaybackUnlocked(); |
| - bool background_suspended = !is_streaming && is_backgrounded_video && |
| - !(can_play_backgrounded && is_background_playing); |
| + bool is_background_playing_allowed = |
|
DaleCurtis
2017/02/13 22:44:54
Needs a comment explaining use of the user gesture
sandersd (OOO until July 31)
2017/02/13 22:56:20
Indeed; the entire design goal of this function is
whywhat
2017/02/14 01:36:28
Something like play_called_with_user_gesture_ set
whywhat
2017/02/15 17:13:12
I simplified the whole background logic in Compute
|
| + blink::WebUserGestureIndicator::isProcessingUserGesture() || |
| + delegate_->IsBackgroundVideoPlaybackUnlocked(); |
| + bool background_suspended = |
| + !is_streaming && is_backgrounded_video && |
| + !(can_play_backgrounded && is_background_playing_allowed); |
| bool background_pause_suspended = |
| !is_streaming && is_backgrounded && paused_ && have_future_data; |
| @@ -2099,8 +2103,9 @@ void WebMediaPlayerImpl::FinishMemoryUsageReport(int64_t demuxer_memory_usage) { |
| } |
| void WebMediaPlayerImpl::ScheduleIdlePauseTimer() { |
| - // Only schedule the pause timer if we're playing and are suspended. |
| - if (paused_ || !pipeline_controller_.IsSuspended()) |
| + // Only schedule the pause timer if we're not paused or paused but going to |
| + // resume when foregrounded, and are suspended. |
| + if ((paused_ && !paused_when_hidden_) || !pipeline_controller_.IsSuspended()) |
| return; |
| #if defined(OS_ANDROID) |
| @@ -2148,14 +2153,18 @@ void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { |
| } |
| bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const { |
| -#if !defined(OS_ANDROID) |
| - // On desktop, this behavior is behind the feature flag. |
| - if (!IsBackgroundVideoTrackOptimizationEnabled()) |
| - return false; |
| -#endif |
| + if (IsBackgroundedSuspendEnabled()) { |
| + // If we intend to pause background videos, pause them as long as |
| + // they're not remote or audible and unlocked for background |
| + // playback. |
| + return hasVideo() && !isRemote() && |
| + (!hasAudio() || !delegate_->IsBackgroundVideoPlaybackUnlocked()); |
| + } |
| - // Pause video-only players that match the criteria for being optimized. |
| - return !hasAudio() && IsBackgroundOptimizationCandidate(); |
| + // Otherwise only pause if the optimization is on and it's a video-only |
| + // optimization candidate. |
| + return IsBackgroundVideoTrackOptimizationEnabled() && !hasAudio() && |
| + IsBackgroundOptimizationCandidate(); |
| } |
| bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const { |