Commit 403b4008 authored by zqzhang's avatar zqzhang Committed by Commit bot

Fix a crash and possible memory leak in AutoplayUmaHelper

There's a crash in
AutoplayUmaHelper::onVisibilityChangedForVideoMutedPlayMethod().
It might be possible that the callback is called after the observer
is released. This CL adds additional nullcheck to avoid the crash.

This CL also fixes a possible memory leak by changing
wrapPersistent to wrapWeakPersistent.

BUG=638595

Review-Url: https://codereview.chromium.org/2249223003
Cr-Commit-Position: refs/heads/master@{#412574}
parent 184ac615
......@@ -81,7 +81,7 @@ void AutoplayUmaHelper::didMoveToNewDocument(Document& oldDocument)
void AutoplayUmaHelper::onVisibilityChangedForVideoMutedPlayMethod(bool isVisible)
{
if (!isVisible)
if (!isVisible || !m_videoMutedPlayMethodVisibilityObserver)
return;
recordVideoAutoplayMutedPlayMethodBecomesVisibleUma(true);
......@@ -115,7 +115,7 @@ void AutoplayUmaHelper::handlePlayingEvent()
{
if (m_source == AutoplaySource::Method && m_element->isHTMLVideoElement() && m_element->muted()) {
if (!m_videoMutedPlayMethodVisibilityObserver) {
m_videoMutedPlayMethodVisibilityObserver = new ElementVisibilityObserver(m_element, WTF::bind(&AutoplayUmaHelper::onVisibilityChangedForVideoMutedPlayMethod, wrapPersistent(this)));
m_videoMutedPlayMethodVisibilityObserver = new ElementVisibilityObserver(m_element, WTF::bind(&AutoplayUmaHelper::onVisibilityChangedForVideoMutedPlayMethod, wrapWeakPersistent(this)));
m_videoMutedPlayMethodVisibilityObserver->start();
m_element->document().domWindow()->addEventListener(EventTypeNames::unload, this, false);
}
......
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