Commit e3b11138 authored by Jennifer Apacible's avatar Jennifer Apacible Committed by Commit Bot

[Picture in Picture] Fix crash when PiP triggered more than once.

This change fixes a browser crash when the PiP media controls button
is toggled more than once.

BUG: 817984 726621
Change-Id: I53d504b9de44b724a3992c709fa26c0fca9be5bc
Reviewed-on: https://chromium-review.googlesource.com/951909
Commit-Queue: apacible <apacible@chromium.org>
Reviewed-by: default avatarCJ DiMeglio <lethalantidote@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541736}
parent 0881a400
......@@ -31,11 +31,7 @@ PictureInPictureWindowController::PictureInPictureWindowController(
content::WebContents* initiator)
: initiator_(initiator) {
DCHECK(initiator_);
}
void PictureInPictureWindowController::Init() {
if (!window_)
window_ = OverlayWindow::Create();
window_ = OverlayWindow::Create();
window_->Init();
}
......@@ -52,9 +48,10 @@ void PictureInPictureWindowController::Close() {
void PictureInPictureWindowController::EmbedSurface(viz::SurfaceId surface_id) {
DCHECK(window_);
DCHECK(surface_id.is_valid());
embedder_.reset(new OverlaySurfaceEmbedder(window_.get()));
surface_id_ = surface_id;
if (!embedder_)
embedder_.reset(new OverlaySurfaceEmbedder(window_.get()));
embedder_->SetPrimarySurfaceId(surface_id_);
}
......
......@@ -36,7 +36,6 @@ class PictureInPictureWindowController
static PictureInPictureWindowController* GetOrCreateForWebContents(
content::WebContents* initiator);
void Init();
void Show();
void Close();
void EmbedSurface(viz::SurfaceId);
......
......@@ -44,8 +44,7 @@ IN_PROC_BROWSER_TEST_F(PictureInPictureWindowControllerBrowserTest,
SetUpWindowController(active_web_contents);
ASSERT_TRUE(window_controller() != nullptr);
ASSERT_TRUE(window_controller()->GetWindowForTesting() == nullptr);
window_controller()->Init();
ASSERT_TRUE(window_controller()->GetWindowForTesting() != nullptr);
ASSERT_FALSE(window_controller()->GetWindowForTesting()->IsVisible());
window_controller()->Show();
ASSERT_TRUE(window_controller()->GetWindowForTesting()->IsVisible());
......
......@@ -1411,10 +1411,10 @@ void Browser::UpdatePictureInPictureSurfaceId(viz::SurfaceId surface_id) {
if (!surface_id.is_valid())
return;
pip_window_controller_.reset(
PictureInPictureWindowController::GetOrCreateForWebContents(
tab_strip_model_->GetActiveWebContents()));
pip_window_controller_->Init();
if (!pip_window_controller_)
pip_window_controller_.reset(
PictureInPictureWindowController::GetOrCreateForWebContents(
tab_strip_model_->GetActiveWebContents()));
pip_window_controller_->EmbedSurface(surface_id);
pip_window_controller_->Show();
}
......
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