Commit d6a13562 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Picture in Picture] Fix resize observer crash

Fix resize observer crash in PiP interstitial when
we detach, re-attach and detach the video element.

BUG=870449

Change-Id: I6989587384cf34c5b6da8cbaec3ab8ca48b58f94
Reviewed-on: https://chromium-review.googlesource.com/1162514Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580628}
parent 82e5e5f2
...@@ -74,4 +74,21 @@ TEST_F(HTMLVideoElementTest, PictureInPictureInterstitialAndTextContainer) { ...@@ -74,4 +74,21 @@ TEST_F(HTMLVideoElementTest, PictureInPictureInterstitialAndTextContainer) {
SetFakeCcLayer(nullptr); SetFakeCcLayer(nullptr);
} }
TEST_F(HTMLVideoElementTest, PictureInPictureInterstitial_Reattach) {
scoped_refptr<cc::Layer> layer = cc::Layer::Create();
SetFakeCcLayer(layer.get());
video()->SetBooleanAttribute(HTMLNames::controlsAttr, true);
video()->SetSrc("http://example.com/foo.mp4");
test::RunPendingTasks();
// Simulate entering Picture-in-Picture.
video()->OnEnteredPictureInPicture();
// Try detaching and reattaching. This should not crash.
GetDocument().body()->removeChild(video());
GetDocument().body()->appendChild(video());
GetDocument().body()->removeChild(video());
}
} // namespace blink } // namespace blink
...@@ -116,11 +116,25 @@ void PictureInPictureInterstitial::Hide() { ...@@ -116,11 +116,25 @@ void PictureInPictureInterstitial::Hide() {
GetVideoElement().CcLayer()->SetIsDrawable(true); GetVideoElement().CcLayer()->SetIsDrawable(true);
} }
Node::InsertionNotificationRequest PictureInPictureInterstitial::InsertedInto(
ContainerNode* root) {
if (GetVideoElement().isConnected() && !resize_observer_) {
resize_observer_ =
ResizeObserver::Create(GetVideoElement().GetDocument(),
new VideoElementResizeObserverDelegate(this));
resize_observer_->observe(&GetVideoElement());
}
return HTMLDivElement::InsertedInto(root);
}
void PictureInPictureInterstitial::RemovedFrom(ContainerNode*) { void PictureInPictureInterstitial::RemovedFrom(ContainerNode*) {
DCHECK(!GetVideoElement().isConnected()); DCHECK(!GetVideoElement().isConnected());
resize_observer_->disconnect(); if (resize_observer_) {
resize_observer_.Clear(); resize_observer_->disconnect();
resize_observer_.Clear();
}
} }
void PictureInPictureInterstitial::NotifyElementSizeChanged( void PictureInPictureInterstitial::NotifyElementSizeChanged(
......
...@@ -36,6 +36,7 @@ class PictureInPictureInterstitial final : public HTMLDivElement { ...@@ -36,6 +36,7 @@ class PictureInPictureInterstitial final : public HTMLDivElement {
HTMLVideoElement& GetVideoElement() const { return *video_element_; } HTMLVideoElement& GetVideoElement() const { return *video_element_; }
// Node override. // Node override.
Node::InsertionNotificationRequest InsertedInto(ContainerNode*) override;
void RemovedFrom(ContainerNode*) override; void RemovedFrom(ContainerNode*) override;
// Element: // Element:
......
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