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

Unified Diff: third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h

Issue 1370723002: Include viewport visibility checks for autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased. Created 5 years, 1 month 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: third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h
diff --git a/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h b/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h
index c9d015f062bce1126923f2ec3613ad7067c92219..9b66a91142a6decbb85ab56cafa34206f4e0663e 100644
--- a/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h
+++ b/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h
@@ -5,7 +5,6 @@
#ifndef AutoplayExperimentHelper_h
#define AutoplayExperimentHelper_h
-#include "core/html/AutoplayExperimentConfig.h"
#include "core/page/Page.h"
#include "platform/Timer.h"
#include "platform/geometry/IntRect.h"
@@ -77,14 +76,50 @@ public:
void playMethodCalled();
void pauseMethodCalled();
void mutedChanged();
- void positionChanged();
+ void positionChanged(const IntRect&);
+ void updatePositionNotificationRegistration();
+
+ void triggerAutoplayViewportCheckForTesting();
+
+ enum Mode {
+ // Do not enable the autoplay experiment.
+ ExperimentOff = 0,
+ // Enable gestureless autoplay for video elements.
+ ForVideo = 1 << 0,
+ // Enable gestureless autoplay for audio elements.
+ ForAudio = 1 << 1,
+ // Restrict gestureless autoplay to media that is in a visible page.
+ IfPageVisible = 1 << 2,
+ // Restrict gestureless autoplay to media that is visible in
+ // the viewport.
+ IfViewport = 1 << 3,
+ // Restrict gestureless autoplay to audio-less or muted media.
+ IfMuted = 1 << 4,
+ // Restrict gestureless autoplay to sites which contain the
+ // viewport tag.
+ IfMobile = 1 << 5,
+ // If gestureless autoplay is allowed, then mute the media before
+ // starting to play.
+ PlayMuted = 1 << 6,
+ };
private:
+ // Register to receive position updates, if we haven't already. If we
+ // have, then this does nothing.
+ void registerForPositionUpdatesIfNeeded();
+
+ // Un-register for position updates, if we are currently registered.
+ void unregisterForPositionUpdatesIfNeeded();
+
// 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 isEligible() const;
+ // Return false if and only if m_element is not visible, and we care
+ // that it must be visible.
+ bool meetsVisibilityRequirements() const;
+
// Set the muted flag on the media if we're in an experiment mode that
// requires it, else do nothing.
void muteIfNeeded();
@@ -98,26 +133,52 @@ private:
// there are several different cases.
void prepareToPlay(AutoplayMetrics);
+ // Process a timer for checking visibility.
+ void viewportTimerFired(Timer<AutoplayExperimentHelper>*);
+
// Return our media element's document.
Document& document() const;
- inline bool enabled(AutoplayExperimentConfig::Mode mode) const
+ inline bool enabled(Mode mode) const
{
return ((int)m_mode) & ((int)mode);
}
+ Mode fromString(const String& mode);
+
private:
HTMLMediaElement& m_element;
- AutoplayExperimentConfig::Mode m_mode;
+ Mode m_mode;
// Autoplay experiment state.
// True if we've received a play() without a pause().
bool m_playPending : 1;
- friend class Internals;
+ // Are we registered with the view for position updates?
+ bool m_registeredWithLayoutObject : 1;
+
+ // According to our last position update, are we in the viewport?
+ bool m_wasInViewport : 1;
+
+ // According to our last position update, where was our element?
+ IntRect m_lastLocation;
+ IntRect m_lastVisibleRect;
+
+ // When was m_lastLocation set?
+ double m_lastLocationUpdateTime;
+
+ Timer<AutoplayExperimentHelper> m_viewportTimer;
};
+inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode& a,
+ const AutoplayExperimentHelper::Mode& b)
+{
+ a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static_cast<int>(b));
+ return a;
+}
+
+
} // namespace blink
#endif // AutoplayExperimentHelper_h

Powered by Google App Engine
This is Rietveld 408576698