Commit 3174ddaf authored by Jennifer Apacible's avatar Jennifer Apacible Committed by Commit Bot

[Picture in Picture] Close window when starting PiP in another tab.

Currently, we don't close the existing Picture-in-Picture window when
the a new tab (i.e. content::WebContents) initiates Picture-in-Picture
mode. This change tears down Picture-in-Picture mode for the current
video before opening a new one.

This change also pauses the video on user gesture to close. When the
Picture-in-Picture window is closed, the video in tab will not continue
playing, even if it was playing in the window.

BUG: 823172
Change-Id: I15e4ada29c6447fd15751503e1ad41868a89e71a
Reviewed-on: https://chromium-review.googlesource.com/1044752
Commit-Queue: apacible <apacible@chromium.org>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556692}
parent 826318d1
......@@ -1413,6 +1413,12 @@ void Browser::UpdatePictureInPictureSurfaceId(const viz::SurfaceId& surface_id,
if (!pip_window_controller_ ||
pip_window_controller_->GetInitiatorWebContents() !=
tab_strip_model_->GetActiveWebContents()) {
// If there was already a controller, close the existing window before
// creating the next one.
if (pip_window_controller_)
pip_window_controller_->Close();
// Update |pip_window_controller_| for the current content::WebContents.
pip_window_controller_ =
content::PictureInPictureWindowController::GetOrCreateForWebContents(
tab_strip_model_->GetActiveWebContents());
......
......@@ -47,17 +47,7 @@ PictureInPictureWindowControllerImpl::~PictureInPictureWindowControllerImpl() {
if (initiator_->IsBeingDestroyed())
return;
// |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 (IsPlayerActive()) {
media_player_id_->first->Send(new MediaPlayerDelegateMsg_Pause(
media_player_id_->first->GetRoutingID(), media_player_id_->second));
media_player_id_->first->Send(
new MediaPlayerDelegateMsg_EndPictureInPictureMode(
media_player_id_->first->GetRoutingID(), media_player_id_->second));
}
OnLeavingPictureInPicture();
}
PictureInPictureWindowControllerImpl::PictureInPictureWindowControllerImpl(
......@@ -88,11 +78,7 @@ void PictureInPictureWindowControllerImpl::Close() {
surface_id_ = viz::SurfaceId();
if (IsPlayerActive()) {
media_player_id_->first->Send(
new MediaPlayerDelegateMsg_EndPictureInPictureMode(
media_player_id_->first->GetRoutingID(), media_player_id_->second));
}
OnLeavingPictureInPicture();
}
void PictureInPictureWindowControllerImpl::EmbedSurface(
......@@ -144,4 +130,15 @@ bool PictureInPictureWindowControllerImpl::TogglePlayPause() {
return true;
}
void PictureInPictureWindowControllerImpl::OnLeavingPictureInPicture() {
if (IsPlayerActive()) {
// Pause the current video so there is only one video playing at a time.
media_player_id_->first->Send(new MediaPlayerDelegateMsg_Pause(
media_player_id_->first->GetRoutingID(), media_player_id_->second));
media_player_id_->first->Send(
new MediaPlayerDelegateMsg_EndPictureInPictureMode(
media_player_id_->first->GetRoutingID(), media_player_id_->second));
}
}
} // namespace content
\ No newline at end of file
......@@ -52,6 +52,9 @@ class PictureInPictureWindowControllerImpl
CONTENT_EXPORT explicit PictureInPictureWindowControllerImpl(
WebContents* initiator);
// Signal to the media player that |this| is leaving Picture-in-Picture mode.
void OnLeavingPictureInPicture();
std::unique_ptr<OverlayWindow> window_;
std::unique_ptr<OverlaySurfaceEmbedder> embedder_;
WebContents* const initiator_;
......
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