Commit 87ee0123 authored by Jennifer Apacible's avatar Jennifer Apacible Committed by Commit Bot

[Picture-in-Picture] Treat WebContents-scoped controller per-tab.

Currently, the PictureInPictureWindowController is reset and torn down
whenever a new video goes into Picture-in-Picture mode. This is less
than ideal since the PictureInPictureWindowController is attached and
scoped to the lifetime of a WebContents via WebContentsUserData.

Rather, we should allow the natural teardown of the controller when
the initiator tabs is destroyed.

BUG: 823172
Change-Id: I7e13b8bf45899fd4ff4b3dbd34781d04ab15dc1d
Reviewed-on: https://chromium-review.googlesource.com/1034194
Commit-Queue: apacible <apacible@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555415}
parent e7da4b19
...@@ -1409,10 +1409,13 @@ void Browser::OnDidBlockFramebust(content::WebContents* web_contents, ...@@ -1409,10 +1409,13 @@ void Browser::OnDidBlockFramebust(content::WebContents* web_contents,
void Browser::UpdatePictureInPictureSurfaceId(const viz::SurfaceId& surface_id, void Browser::UpdatePictureInPictureSurfaceId(const viz::SurfaceId& surface_id,
const gfx::Size& natural_size) { const gfx::Size& natural_size) {
if (!pip_window_controller_) if (!pip_window_controller_ ||
pip_window_controller_.reset( pip_window_controller_->GetInitiatorWebContents() !=
tab_strip_model_->GetActiveWebContents()) {
pip_window_controller_ =
content::PictureInPictureWindowController::GetOrCreateForWebContents( content::PictureInPictureWindowController::GetOrCreateForWebContents(
tab_strip_model_->GetActiveWebContents())); tab_strip_model_->GetActiveWebContents());
}
pip_window_controller_->EmbedSurface(surface_id, natural_size); pip_window_controller_->EmbedSurface(surface_id, natural_size);
pip_window_controller_->Show(); pip_window_controller_->Show();
} }
......
...@@ -1001,8 +1001,12 @@ class Browser : public TabStripModelObserver, ...@@ -1001,8 +1001,12 @@ class Browser : public TabStripModelObserver,
std::unique_ptr<chrome::BrowserCommandController> command_controller_; std::unique_ptr<chrome::BrowserCommandController> command_controller_;
std::unique_ptr<content::PictureInPictureWindowController> // |pip_window_controller_| is held as a SupportsUserData attachment on the
pip_window_controller_; // content::WebContents, and thus scoped to the lifetime of the initiator
// content::WebContents.
// The current active Picture-in-Picture controller is held in case of
// updates to the relevant viz::SurfaceId.
content::PictureInPictureWindowController* pip_window_controller_ = nullptr;
// True if the browser window has been shown at least once. // True if the browser window has been shown at least once.
bool window_has_shown_; bool window_has_shown_;
......
...@@ -101,6 +101,10 @@ void PictureInPictureWindowControllerImpl::UpdateLayerBounds() { ...@@ -101,6 +101,10 @@ void PictureInPictureWindowControllerImpl::UpdateLayerBounds() {
embedder_->UpdateLayerBounds(); embedder_->UpdateLayerBounds();
} }
WebContents* PictureInPictureWindowControllerImpl::GetInitiatorWebContents() {
return initiator_;
}
bool PictureInPictureWindowControllerImpl::TogglePlayPause() { bool PictureInPictureWindowControllerImpl::TogglePlayPause() {
DCHECK(window_ && window_->IsActive()); DCHECK(window_ && window_->IsActive());
......
...@@ -39,6 +39,7 @@ class PictureInPictureWindowControllerImpl ...@@ -39,6 +39,7 @@ class PictureInPictureWindowControllerImpl
const gfx::Size& natural_size) override; const gfx::Size& natural_size) override;
CONTENT_EXPORT OverlayWindow* GetWindowForTesting() override; CONTENT_EXPORT OverlayWindow* GetWindowForTesting() override;
CONTENT_EXPORT void UpdateLayerBounds() override; CONTENT_EXPORT void UpdateLayerBounds() override;
CONTENT_EXPORT WebContents* GetInitiatorWebContents() override;
CONTENT_EXPORT bool TogglePlayPause() override; CONTENT_EXPORT bool TogglePlayPause() override;
private: private:
......
...@@ -39,6 +39,7 @@ class PictureInPictureWindowController { ...@@ -39,6 +39,7 @@ class PictureInPictureWindowController {
const gfx::Size& natural_size) = 0; const gfx::Size& natural_size) = 0;
virtual OverlayWindow* GetWindowForTesting() = 0; virtual OverlayWindow* GetWindowForTesting() = 0;
virtual void UpdateLayerBounds() = 0; virtual void UpdateLayerBounds() = 0;
virtual WebContents* GetInitiatorWebContents() = 0;
// Commands. // Commands.
// Returns true if the player is active (i.e. currently playing) after this // Returns true if the player is active (i.e. currently playing) after this
......
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