Commit 98a5ecf7 authored by Tommy Steimel's avatar Tommy Steimel Committed by Commit Bot

[Media Controls] Prevent crash when video is removed on click

This CL adds an isConnected check in the overlay play button's click
positioning check to prevent a crash when trying to access the layout
data after it's been removed.

Bug: 870490, 881772
Change-Id: Ic005ae9d3acc2945ed67645bfe98a237c89e38f0
Reviewed-on: https://chromium-review.googlesource.com/1217065Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590058}
parent a1f0a5bb
<!DOCTYPE html>
<html>
<title>Test that when a video is removed on click it does not crash.</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../media-controls.js"></script>
<video controls width=500 preload=none src="../content/60_sec_video.webm"></video>
<script>
async_test(t => {
const video = document.querySelector('video');
video.addEventListener('click', t.step_func_done(() => {
video.parentNode.removeChild(video);
}), { once: true });
video.addEventListener('loadedmetadata', t.step_func(() => {
const coords = getOverlayPlayButtonEdgeCoordinates();
singleTapAtCoordinates(coords[0], coords[1]);
}));
function getOverlayPlayButtonEdgeCoordinates() {
const overlayPlayBtn = mediaControlsOverlayPlayButton(video);
const rect = overlayPlayBtn.getBoundingClientRect();
const x = rect.left + 5;
const y = rect.top + 5;
return [x, y];
}
video.load();
});
</script>
</html>
...@@ -296,9 +296,12 @@ bool MediaControlOverlayPlayButtonElement::ShouldCausePlayPause( ...@@ -296,9 +296,12 @@ bool MediaControlOverlayPlayButtonElement::ShouldCausePlayPause(
bool MediaControlOverlayPlayButtonElement::IsMouseEventOnInternalButton( bool MediaControlOverlayPlayButtonElement::IsMouseEventOnInternalButton(
const MouseEvent& mouse_event) const { const MouseEvent& mouse_event) const {
// If no position data available, default to yes. // If we don't have the necessary pieces to calculate whether the event is
if (!mouse_event.HasPosition()) // within the bounds of the button, default to yes.
if (!mouse_event.HasPosition() || !isConnected() ||
!GetDocument().GetLayoutView()) {
return true; return true;
}
// Find the zoom-adjusted internal button bounding box. // Find the zoom-adjusted internal button bounding box.
DOMRect* box = internal_button_->getBoundingClientRect(); DOMRect* box = internal_button_->getBoundingClientRect();
......
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