Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| index a73f6a0f70b68bac03cdee412eb07269ac935c11..e028b31c064c2525953a1c9a804d71ae159e49e1 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -35,6 +35,7 @@ |
| #include "core/dom/Attribute.h" |
| #include "core/dom/DOMException.h" |
| #include "core/dom/ElementTraversal.h" |
| +#include "core/dom/ElementVisibilityObserver.h" |
| #include "core/dom/Fullscreen.h" |
| #include "core/dom/shadow/ShadowRoot.h" |
| #include "core/events/Event.h" |
| @@ -354,7 +355,6 @@ private: |
| Member<HTMLMediaElement> m_element; |
| }; |
| - |
| void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric) |
| { |
| DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayHistogram, ("Blink.MediaElement.Autoplay", NumberOfAutoplayMetrics)); |
| @@ -450,6 +450,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
| , m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)) |
| , m_autoplayHelper(AutoplayExperimentHelper::create(m_autoplayHelperClient.get())) |
| , m_remotePlaybackClient(nullptr) |
| + , m_autoplayVisibilityObserver(nullptr) |
| { |
| ThreadState::current()->registerPreFinalizer(this); |
| @@ -1641,16 +1642,22 @@ void HTMLMediaElement::setReadyState(ReadyState state) |
| // Check for autoplay, and record metrics about it if needed. |
| if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { |
| recordAutoplaySourceMetric(AutoplaySourceAttribute); |
| + |
| // If the autoplay experiment says that it's okay to play now, |
| // then don't require a user gesture. |
| m_autoplayHelper->becameReadyToPlay(); |
| if (!isGestureNeededForPlayback()) { |
| - m_paused = false; |
| - invalidateCachedTime(); |
| - scheduleEvent(EventTypeNames::play); |
| - scheduleNotifyPlaying(); |
| - m_autoplaying = false; |
| + if (isHTMLVideoElement() && muted() && RuntimeEnabledFeatures::autoplayMutedVideosEnabled()) { |
| + m_autoplayVisibilityObserver = new ElementVisibilityObserver(this, WTF::bind<bool>(&HTMLMediaElement::onVisibilityChangedForAutoplay, this)); |
|
esprehn
2016/06/21 21:28:41
do you actually need to pass the <bool> like this?
mlamouri (slow - plz ping)
2016/06/21 21:32:11
AFAIK, this is required to compile.
|
| + m_autoplayVisibilityObserver->start(); |
| + } else { |
| + m_paused = false; |
| + invalidateCachedTime(); |
| + scheduleEvent(EventTypeNames::play); |
| + scheduleNotifyPlaying(); |
| + m_autoplaying = false; |
| + } |
| } |
| } |
| @@ -3649,6 +3656,7 @@ DEFINE_TRACE(HTMLMediaElement) |
| visitor->trace(m_autoplayHelperClient); |
| visitor->trace(m_autoplayHelper); |
| visitor->trace(m_srcObject); |
| + visitor->trace(m_autoplayVisibilityObserver); |
| visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::clearWeakMembers>(this); |
| Supplementable<HTMLMediaElement>::trace(visitor); |
| HTMLElement::trace(visitor); |
| @@ -3879,6 +3887,25 @@ void HTMLMediaElement::recordAutoplaySourceMetric(int source) |
| } |
| } |
| +void HTMLMediaElement::onVisibilityChangedForAutoplay(bool isVisible) |
| +{ |
| + if (!isVisible) |
| + return; |
| + |
| + if (shouldAutoplay()) { |
| + m_paused = false; |
| + invalidateCachedTime(); |
| + scheduleEvent(EventTypeNames::play); |
| + scheduleNotifyPlaying(); |
| + m_autoplaying = false; |
| + |
| + updatePlayState(); |
| + } |
| + |
| + m_autoplayVisibilityObserver->stop(); |
| + m_autoplayVisibilityObserver = nullptr; |
| +} |
| + |
| void HTMLMediaElement::clearWeakMembers(Visitor* visitor) |
| { |
| if (!ThreadHeap::isHeapObjectAlive(m_audioSourceNode)) { |