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 9ae9d1d0dab809b057dec678a4eef22686c8db50..33f65578742eb9d33ebf83d41106028723663fd0 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -302,7 +302,7 @@ public: |
| bool muted() const override { return m_element->muted(); } |
| void setMuted(bool muted) override { m_element->setMuted(muted); } |
| void playInternal() override { m_element->playInternal(); } |
| - bool isUserGestureRequiredForPlay() const override { return m_element->isUserGestureRequiredForPlay(); } |
| + bool isLockedPendingUserGesture() const override { return m_element->isLockedPendingUserGesture(); } |
| void removeUserGestureRequirement() override { m_element->removeUserGestureRequirement(); } |
| void recordAutoplayMetric(AutoplayMetrics metric) override { m_element->recordAutoplayMetric(metric); } |
| bool shouldAutoplay() override |
| @@ -412,7 +412,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
| , m_cachedTime(std::numeric_limits<double>::quiet_NaN()) |
| , m_fragmentEndTime(std::numeric_limits<double>::quiet_NaN()) |
| , m_pendingActionFlags(0) |
| - , m_userGestureRequiredForPlay(false) |
| + , m_lockedPendingUserGesture(false) |
| , m_playing(false) |
| , m_shouldDelayLoadEvent(false) |
| , m_haveFiredLoadedData(false) |
| @@ -447,7 +447,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
| // default, otherwise the experiment does nothing. |
| if ((document.settings() && document.settings()->mediaPlaybackRequiresUserGesture()) |
| || m_autoplayHelper->isExperimentEnabled()) { |
| - m_userGestureRequiredForPlay = true; |
| + m_lockedPendingUserGesture = true; |
| } |
| setHasCustomStyleCallbacks(); |
| @@ -1620,7 +1620,7 @@ void HTMLMediaElement::setReadyState(ReadyState state) |
| // then don't require a user gesture. |
| m_autoplayHelper->becameReadyToPlay(); |
| - if (!m_userGestureRequiredForPlay) { |
| + if (!isGestureNeededForPlayback()) { |
| m_paused = false; |
| invalidateCachedTime(); |
| scheduleEvent(EventTypeNames::play); |
| @@ -2043,10 +2043,22 @@ Nullable<ExceptionCode> HTMLMediaElement::play() |
| { |
| WTF_LOG(Media, "HTMLMediaElement::play(%p)", this); |
| - m_autoplayHelper->playMethodCalled(); |
| + m_autoplayHelper->playMethodCalled(!m_paused); |
| if (!UserGestureIndicator::processingUserGesture()) { |
| - if (m_userGestureRequiredForPlay) { |
| + if (isGestureNeededForPlayback()) { |
| + // If playback is deferred, then don't start playback but don't |
| + // fail yet either. |
| + if (m_autoplayHelper->isPlaybackDeferred()) |
|
mlamouri (slow - plz ping)
2016/05/05 13:45:40
I'm a bit confused. What does that mean? When will
liberato (no reviews please)
2016/05/05 17:48:57
if the element needs a user gesture, and is off-sc
|
| + return nullptr; |
| + |
| + // If we're already playing, then this play would do nothing anyway. |
| + // Call playInternal to handle scheduling the promise resolution. |
| + if (!m_paused) { |
| + playInternal(); |
| + return nullptr; |
| + } |
| + |
| recordAutoplayMetric(PlayMethodFailed); |
| String message = ExceptionMessages::failedToExecute("play", "HTMLMediaElement", "API can only be initiated by a user gesture."); |
| document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); |
| @@ -2240,8 +2252,6 @@ void HTMLMediaElement::setMuted(bool muted) |
| m_muted = muted; |
| - m_autoplayHelper->mutedChanged(); |
| - |
| updateVolume(); |
| if (muted) |
| @@ -3650,14 +3660,20 @@ void HTMLMediaElement::selectInitialTracksIfNecessary() |
| videoTracks().anonymousIndexedGetter(0)->setSelected(true); |
| } |
| -bool HTMLMediaElement::isUserGestureRequiredForPlay() const |
| +bool HTMLMediaElement::isLockedPendingUserGesture() const |
| { |
| - return m_userGestureRequiredForPlay; |
| + return m_lockedPendingUserGesture; |
| } |
| void HTMLMediaElement::removeUserGestureRequirement() |
|
mlamouri (slow - plz ping)
2016/05/05 13:45:40
Should this be renamed?
liberato (no reviews please)
2016/05/05 17:48:57
good point, unlockWithUserGesture().
|
| { |
| - m_userGestureRequiredForPlay = false; |
| + m_lockedPendingUserGesture = false; |
| +} |
| + |
| +bool HTMLMediaElement::isGestureNeededForPlayback() const |
| +{ |
| + return m_lockedPendingUserGesture |
| + && !m_autoplayHelper->isGestureRequirementOverridden(); |
| } |
| void HTMLMediaElement::setNetworkState(NetworkState state) |