Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 1949633002: Don't remove the gesture requirement in the autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed test expectations. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 beaa552e9f848587003ddddedf1e9eed40648ca9..15b0b6a3a4d8464b870101ba7b78ed4310b004a3 100644
--- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp
@@ -298,12 +298,13 @@ public:
double currentTime() const override { return m_element->currentTime(); }
double duration() const override { return m_element->duration(); }
+ bool paused() const override { return m_element->paused(); }
bool ended() const override { return m_element->ended(); }
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(); }
- void removeUserGestureRequirement() override { m_element->removeUserGestureRequirement(); }
+ bool isLockedPendingUserGesture() const override { return m_element->isLockedPendingUserGesture(); }
+ void unlockUserGesture() override { m_element->unlockUserGesture(); }
void recordAutoplayMetric(AutoplayMetrics metric) override { m_element->recordAutoplayMetric(metric); }
bool shouldAutoplay() override
{
@@ -412,7 +413,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 +448,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();
@@ -1013,7 +1014,7 @@ void HTMLMediaElement::loadResource(const WebMediaPlayerSource& source, ContentT
if (isStreamOrBlobUrl) {
bool isMediaStream = source.isMediaStream() || (source.isURL() && isMediaStreamURL(url.getString()));
if (isMediaStream) {
- m_autoplayHelper->removeUserGestureRequirement(GesturelessPlaybackEnabledByStream);
+ m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByStream);
} else {
m_mediaSource = HTMLMediaSource::lookup(url.getString());
@@ -1620,7 +1621,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);
@@ -2046,7 +2047,19 @@ Nullable<ExceptionCode> HTMLMediaElement::play()
m_autoplayHelper->playMethodCalled();
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())
+ 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));
@@ -2057,7 +2070,7 @@ Nullable<ExceptionCode> HTMLMediaElement::play()
// We ask the helper to remove the gesture requirement for us, so that
// it can record the reason.
Platform::current()->recordAction(UserMetricsAction("Media_Play_WithGesture"));
- m_autoplayHelper->removeUserGestureRequirement(GesturelessPlaybackEnabledByPlayMethod);
+ m_autoplayHelper->unlockUserGesture(GesturelessPlaybackEnabledByPlayMethod);
}
if (m_error && m_error->code() == MediaError::MEDIA_ERR_SRC_NOT_SUPPORTED)
@@ -2240,8 +2253,6 @@ void HTMLMediaElement::setMuted(bool muted)
m_muted = muted;
- m_autoplayHelper->mutedChanged();
-
updateVolume();
if (muted)
@@ -3651,14 +3662,20 @@ void HTMLMediaElement::selectInitialTracksIfNecessary()
videoTracks().anonymousIndexedGetter(0)->setSelected(true);
}
-bool HTMLMediaElement::isUserGestureRequiredForPlay() const
+bool HTMLMediaElement::isLockedPendingUserGesture() const
+{
+ return m_lockedPendingUserGesture;
+}
+
+void HTMLMediaElement::unlockUserGesture()
{
- return m_userGestureRequiredForPlay;
+ m_lockedPendingUserGesture = false;
}
-void HTMLMediaElement::removeUserGestureRequirement()
+bool HTMLMediaElement::isGestureNeededForPlayback() const
{
- m_userGestureRequiredForPlay = false;
+ return m_lockedPendingUserGesture
+ && !m_autoplayHelper->isGestureRequirementOverridden();
}
void HTMLMediaElement::setNetworkState(NetworkState state)
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698