| 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 d77204149ea63e355658a4ac626326305a7e18e0..be8b21a65531439b946a5e2399f93afb5c7e130a 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));
|
| @@ -1641,16 +1641,20 @@ 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 (muted() && RuntimeEnabledFeatures::autoplayMutedVideosEnabled()) {
|
| + m_autoplayVisibilityObserver = new ElementVisibilityObserver(this, WTF::bind<bool>(&HTMLMediaElement::visibilityChangedForAutoplay, this));
|
| + m_autoplayVisibilityObserver->start();
|
| + } else {
|
| + m_paused = false;
|
| + invalidateCachedTime();
|
| + scheduleEvent(EventTypeNames::play);
|
| + scheduleNotifyPlaying();
|
| + m_autoplaying = false;
|
| + }
|
| }
|
| }
|
|
|
| @@ -3641,6 +3645,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);
|
| @@ -3853,6 +3858,15 @@ void HTMLMediaElement::recordAutoplaySourceMetric(int source)
|
| }
|
| }
|
|
|
| +void HTMLMediaElement::visibilityChangedForAutoplay(bool visibility) {
|
| + if (!visibility)
|
| + return;
|
| +
|
| + playInternal();
|
| + m_autoplayVisibilityObserver->stop();
|
| + m_autoplayVisibilityObserver = nullptr;
|
| +}
|
| +
|
| void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
|
| {
|
| if (!ThreadHeap::isHeapObjectAlive(m_audioSourceNode)) {
|
|
|