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

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

Issue 1329853004: Include viewport visibility checks for autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@autoplay_step1
Patch Set: Created 5 years, 3 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/AutoplayExperimentHelper.h
diff --git a/Source/core/html/AutoplayExperimentHelper.h b/Source/core/html/AutoplayExperimentHelper.h
index c9d015f062bce1126923f2ec3613ad7067c92219..f3388280a9407f273554ada91d54e01cc891a9a2 100644
--- a/Source/core/html/AutoplayExperimentHelper.h
+++ b/Source/core/html/AutoplayExperimentHelper.h
@@ -79,12 +79,51 @@ public:
void mutedChanged();
void positionChanged();
+ // For testing.
+ void triggerAutoplayViewportCheck();
+
private:
+ // The location and size of our element, and the viewport. Also supports
+ // "not valid", in case some of the information isn't available.
+ class LocationState {
+ public:
+ LocationState() : m_valid(false) {}
+ LocationState(Element&);
+
+ bool valid() const { return m_valid; }
+ PageVisibilityState visibilityState() const { return m_visibilityState; }
+ const IntRect& element() const { return m_element; }
+ const IntRect& screen() const { return m_screen; }
+
+ bool operator==(const LocationState&) const;
+ bool operator!=(const LocationState&) const;
+
+ // Return true if and only if the player is visible.
+ bool isInViewport();
+
+ private:
+ bool m_valid;
+ PageVisibilityState m_visibilityState;
+ IntRect m_element;
+ IntRect m_screen;
+ };
+
+ // 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 the player is not visible, and we care
+ // that it must be visible.
+ bool isInViewportIfNeeded();
+
// Set the muted flag on the media if we're in an experiment mode that
// requires it, else do nothing.
void muteIfNeeded();
@@ -98,6 +137,9 @@ 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;
@@ -115,6 +157,14 @@ private:
// True if we've received a play() without a pause().
bool m_playPending : 1;
+ // Are we registered with the view for position updates?
+ bool m_registeredWithView : 1;
+
+ // According to our last position update, are we in the viewport?
+ bool m_wasInViewport : 1;
+
+ Timer<AutoplayExperimentHelper> m_viewportTimer;
+
friend class Internals;
};

Powered by Google App Engine
This is Rietveld 408576698