Commit 73edf5e8 authored by Jennifer Apacible's avatar Jennifer Apacible Committed by Commit Bot

[Reland] [Picture in Picture] Pause active videos when leaving PiP mode.

There are two instances where PictureInPictureWindowController
is torn down:
1. Tab is closed (controller is tied to the tab's WebContents). In this
case, the player is also deleted, so there are no behavioral concerns.
2. A video on a different tab enters Picture-in-Picture mode. In this
case, the player from the earlier PiP'd tab may still be playing in that
tab, meaning there may be two(+) videos playing.

This change would pause the initial video, as the user has indicated
they want to PiP a new video.

This behavior will be up for further discussion with UX.

BUG: 823172
Change-Id: I3e1a58f496f5814a4a8aae40df3de23cd0ee6702
Reviewed-on: https://chromium-review.googlesource.com/1038303Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: apacible <apacible@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555416}
parent 87ee0123
...@@ -40,6 +40,29 @@ PictureInPictureWindowControllerImpl::GetOrCreateForWebContents( ...@@ -40,6 +40,29 @@ PictureInPictureWindowControllerImpl::GetOrCreateForWebContents(
PictureInPictureWindowControllerImpl::~PictureInPictureWindowControllerImpl() { PictureInPictureWindowControllerImpl::~PictureInPictureWindowControllerImpl() {
if (window_) if (window_)
window_->Close(); window_->Close();
// If the initiator WebContents is being destroyed, there is no need to put
// the video's media player in a post-Picture-in-Picture mode. In fact, some
// things, such as the MediaWebContentsObserver, may already been torn down.
if (initiator_->IsBeingDestroyed())
return;
content::MediaWebContentsObserver* observer =
static_cast<content::WebContentsImpl* const>(initiator_)
->media_web_contents_observer();
DCHECK(observer);
base::Optional<content::WebContentsObserver::MediaPlayerId> player_id =
observer->GetPictureInPictureVideoMediaPlayerId();
// |this| is torn down when there is a new Picture-in-Picture initiator, such
// as when a video in another tab requests to enter Picture-in-Picture. In
// cases like this, pause the current video so there is only one video
// playing at a time.
if (player_id.has_value() && observer->IsPlayerActive(*player_id)) {
player_id->first->Send(new MediaPlayerDelegateMsg_Pause(
player_id->first->GetRoutingID(), player_id->second));
}
} }
PictureInPictureWindowControllerImpl::PictureInPictureWindowControllerImpl( PictureInPictureWindowControllerImpl::PictureInPictureWindowControllerImpl(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment