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

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: identical to PS4 on 1329853004 (probably rebased) 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: 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..ed3d75d178bc257d683449390db4ffbc3e5abf59 100644
--- a/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h
+++ b/third_party/WebKit/Source/core/html/AutoplayExperimentHelper.h
@@ -79,12 +79,56 @@ public:
void mutedChanged();
void positionChanged();
+ // For testing.
+ void triggerAutoplayViewportCheck();
+
private:
+ // The location and size of our element, and the viewport.
+ class LocationState {
+ public:
+ LocationState() {}
+ LocationState(Element&);
esprehn 2015/10/01 07:04:14 const Element& ?
liberato (no reviews please) 2015/10/01 22:49:02 locationstate removed.
+
+ PageVisibilityState visibilityState() const { return m_visibilityState; }
+ const IntRect& element() const { return m_element; }
esprehn 2015/10/01 07:04:14 elementRect() ? element is confusing
liberato (no reviews please) 2015/10/01 22:49:02 locationstate removed.
+ const IntRect& screen() const { return m_screen; }
esprehn 2015/10/01 07:04:14 screenRect
liberato (no reviews please) 2015/10/01 22:49:02 ditto.
+
+ bool operator==(const LocationState&) const;
+ bool operator!=(const LocationState&) const;
+
+ // Return true if and only if the element is visible.
+ bool isElementVisible() const;
+
+ // Return true if and only if the element's page is visible.
+ bool isPageVisible() const;
+
+ private:
+ 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 element described by LocationState is
+ // not visible, and we care that it must be visible.
+ bool meetsVisibilityRequirements(const LocationState&) const;
+
+ // Return false if and only if m_element is not visible, and we care
+ // that it must be visible. This is equivalent to calling
+ // meetsVisibilityRequirements(LocationState(m_element))
+ 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,6 +142,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 +162,20 @@ 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_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?
+ LocationState m_lastLocation;
+
+ // When was m_lastLocation set?
+ double m_lastLocationUpdateTime;
+
+ Timer<AutoplayExperimentHelper> m_viewportTimer;
+
friend class Internals;
esprehn 2015/10/01 07:04:14 We don't generally do friends like this, we just a
liberato (no reviews please) 2015/10/01 22:49:02 Done.
};

Powered by Google App Engine
This is Rietveld 408576698