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

Unified Diff: Source/core/html/HTMLMediaElement.h

Issue 1179223002: Implement autoplay gesture override experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased. Created 5 years, 5 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
Index: Source/core/html/HTMLMediaElement.h
diff --git a/Source/core/html/HTMLMediaElement.h b/Source/core/html/HTMLMediaElement.h
index 2bb0dd6888960b964924babfdecd28d794934ca2..edfc9d8701301a22bccbbc9785a1b4f866c9318c 100644
--- a/Source/core/html/HTMLMediaElement.h
+++ b/Source/core/html/HTMLMediaElement.h
@@ -287,6 +287,35 @@ protected:
void setControllerInternal(MediaController*);
private:
+ // These values are used for a histogram. Do not reorder.
+ enum AutoplayMetrics {
+ // Media element with autoplay seen.
+ AutoplayMediaFound = 0,
+ // Autoplay enabled and user stopped media play at any point.
+ AutoplayStopped = 1,
+ // Autoplay enabled but user bailed out on media play early.
+ AutoplayBailout = 2,
+ // Autoplay disabled but user manually started media.
+ AutoplayManualStart = 3,
+ // Autoplay was (re)enabled through a user-gesture triggered load()
+ AutoplayEnabledThroughLoad = 4,
+ // Autoplay disabled by sandbox flags.
+ AutoplayDisabledBySandbox = 5,
+ // AutoplayStopped for a media play that was started by the experiment.
+ AutoplayExperimentStopped = 6,
+ // AutoplayBailout for media a play that was started by the experiment.
+ AutoplayExperimentBailout = 7,
+ // Autoplay started by experiment when media scrolled into view. We don't
+ // record whether it was a javascript or attribute autoplay request.
+ AutoplayExperimentStartedByScroll = 8,
+ // Autoplay started by experiment during initial load.
+ AutoplayExperimentStartedByLoad = 9,
+ // Autoplay started by experiment in play() call.
+ AutoplayExperimentStartedByPlay = 10,
+ // This enum value must be last.
+ NumberOfAutoplayMetrics,
+ };
+
void resetMediaPlayerAndMediaSource();
bool alwaysCreateUserAgentShadowRoot() const final { return true; }
@@ -427,6 +456,47 @@ private:
bool isBlockedOnMediaController() const;
bool isAutoplaying() const { return m_autoplaying; }
+ void recordAutoplayMetric(AutoplayMetrics);
+
+ // vvvv Helpers for clank autoplay investigation vvvv
+
+ // Install an event listener to check for changes in visibility. If a
+ // listener is already installed, then this does nothing.
+ void autoplayExperimentInstallEventListenerIfNeeded();
+
+ // Remove any event listener. It's okay to call this if one isn't
+ // installed already.
+ void autoplayExperimentClearEventListenerIfNeeded();
+
+ // Return true if any only if this player meets (most) of the eligibility
+ // requirements for the experiment to override the need for a user
+ // gesture. This includes everything except the visibility test.
+ bool autoplayExperimentIsEligible() const;
+
+ // Return true if and only if the player is visible.
+ bool autoplayExperimentIsVisible();
+
+ // Set the mute flag on the media if we're in an experiment mode that
+ // requires it, else do nothing.
+ void autoplayExperimentMuteIfNeeded();
+
+ // Maybe override the requirement for a user gesture, and start playing
+ // autoplay media. Returns true if only if it starts playback.
+ bool autoplayExperimentMaybeStartPlaying();
+
+ // Configure internal state to record that the autoplay experiment is
+ // going to start playback. This doesn't actually start playback, since
+ // there are several different cases.
+ void autoplayExperimentPrepareToPlay(AutoplayMetrics);
+
+ // Begin (or start over) a periodic check for visibility. We will poll
+ // during this check to see if the video is in view.
+ void beginPeriodicVisibilityCheck();
+
+ // Process a timer for checking visibility.
+ void visibilityTimerFired(Timer<HTMLMediaElement>*);
+ // ^^^^ Helpers for clank autoplay investigation ^^^^
+
WebMediaPlayer::CORSMode corsMode() const;
// Returns the "direction of playback" value as specified in the HTML5 spec.
@@ -550,6 +620,29 @@ private:
bool m_initialPlayWithoutUserGestures : 1;
bool m_autoplayMediaCounted : 1;
+ // Autoplay experiment state.
+ // True if we've received a play() without a pause().
+ bool m_autoplayExperimentPlayPending : 1;
+
+ // Autoplay experiment state.
+ // True if and only if we initiated playback because of the autoplay
+ // experiment. Once set, this is never unset.
+ bool m_autoplayExperimentStartedByExperiment : 1;
+
+ // Autoplay experiment state.
+ // Touch listener for the autoplay experiment.
+ class AutoplayExperimentTouchListener;
+ friend class AutoplayExperimentTouchListener;
+ RefPtrWillBeMember<EventListener> m_autoplayExperimentTouchListener;
+
+ enum AutoplayExperimentMode {
+ ExperimentOff,
+ ExperimentAlways,
+ ExperimentIfMuted,
+ ExperimentPlayMuted
+ };
+ AutoplayExperimentMode m_autoplayExperimentMode;
+
RefPtrWillBeMember<AudioTrackList> m_audioTracks;
RefPtrWillBeMember<VideoTrackList> m_videoTracks;
RefPtrWillBeMember<TextTrackList> m_textTracks;
@@ -613,6 +706,11 @@ private:
AudioSourceProviderImpl m_audioSourceProvider;
#endif
+ Timer<HTMLMediaElement> m_autoplayVisibilityTimer;
+ double m_autoplayLastScrollX;
+ double m_autoplayLastScrollY;
+ double m_autoplayVisibilityTimerSpan;
+
friend class MediaController;
PersistentWillBeMember<MediaController> m_mediaController;

Powered by Google App Engine
This is Rietveld 408576698