| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef AutoplayExperimentHelper_h | 5 #ifndef AutoplayExperimentHelper_h |
| 6 #define AutoplayExperimentHelper_h | 6 #define AutoplayExperimentHelper_h |
| 7 | 7 |
| 8 #include "core/page/Page.h" | 8 #include "core/page/Page.h" |
| 9 #include "platform/Timer.h" | 9 #include "platform/Timer.h" |
| 10 #include "platform/geometry/IntRect.h" | 10 #include "platform/geometry/IntRect.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 virtual void removeUserGestureRequirement() = 0; | 116 virtual void removeUserGestureRequirement() = 0; |
| 117 virtual void recordAutoplayMetric(AutoplayMetrics) = 0; | 117 virtual void recordAutoplayMetric(AutoplayMetrics) = 0; |
| 118 virtual bool shouldAutoplay() = 0; | 118 virtual bool shouldAutoplay() = 0; |
| 119 virtual bool isHTMLVideoElement() const = 0; | 119 virtual bool isHTMLVideoElement() const = 0; |
| 120 virtual bool isHTMLAudioElement() const = 0; | 120 virtual bool isHTMLAudioElement() const = 0; |
| 121 | 121 |
| 122 // Document | 122 // Document |
| 123 virtual bool isLegacyViewportType() = 0; | 123 virtual bool isLegacyViewportType() = 0; |
| 124 virtual PageVisibilityState pageVisibilityState() const = 0; | 124 virtual PageVisibilityState pageVisibilityState() const = 0; |
| 125 virtual String autoplayExperimentMode() const = 0; | 125 virtual String autoplayExperimentMode() const = 0; |
| 126 virtual LocalFrame* frame() const = 0; |
| 126 | 127 |
| 127 // LayoutObject | 128 // LayoutObject |
| 128 virtual void setRequestPositionUpdates(bool) = 0; | 129 virtual void setRequestPositionUpdates(bool) = 0; |
| 129 virtual IntRect absoluteBoundingBoxRect() const = 0; | 130 virtual IntRect absoluteBoundingBoxRect() const = 0; |
| 130 | 131 |
| 131 DEFINE_INLINE_VIRTUAL_TRACE() { } | 132 DEFINE_INLINE_VIRTUAL_TRACE() { } |
| 132 }; | 133 }; |
| 133 | 134 |
| 134 static AutoplayExperimentHelper* create(Client* client) | 135 static AutoplayExperimentHelper* create(Client* client) |
| 135 { | 136 { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // Restrict gestureless autoplay to media that is in a visible page. | 177 // Restrict gestureless autoplay to media that is in a visible page. |
| 177 IfPageVisible = 1 << 2, | 178 IfPageVisible = 1 << 2, |
| 178 // Restrict gestureless autoplay to media that is visible in | 179 // Restrict gestureless autoplay to media that is visible in |
| 179 // the viewport. | 180 // the viewport. |
| 180 IfViewport = 1 << 3, | 181 IfViewport = 1 << 3, |
| 181 // Restrict gestureless autoplay to audio-less or muted media. | 182 // Restrict gestureless autoplay to audio-less or muted media. |
| 182 IfMuted = 1 << 4, | 183 IfMuted = 1 << 4, |
| 183 // Restrict gestureless autoplay to sites which contain the | 184 // Restrict gestureless autoplay to sites which contain the |
| 184 // viewport tag. | 185 // viewport tag. |
| 185 IfMobile = 1 << 5, | 186 IfMobile = 1 << 5, |
| 187 // Restrict gestureless autoplay to sites which are from the same origin |
| 188 // as the top-level frame. |
| 189 IfSameOrigin = 1 << 6, |
| 190 // When combined with IfSameOrigin, allow muted to override the same |
| 191 // origin check. Else, this does nothing. |
| 192 OrMuted = 1 << 7, |
| 186 // If gestureless autoplay is allowed, then mute the media before | 193 // If gestureless autoplay is allowed, then mute the media before |
| 187 // starting to play. | 194 // starting to play. |
| 188 PlayMuted = 1 << 6, | 195 PlayMuted = 1 << 8, |
| 189 }; | 196 }; |
| 190 | 197 |
| 191 DEFINE_INLINE_TRACE() { visitor->trace(m_client); } | 198 DEFINE_INLINE_TRACE() { visitor->trace(m_client); } |
| 192 | 199 |
| 193 private: | 200 private: |
| 194 explicit AutoplayExperimentHelper(Client*); | 201 explicit AutoplayExperimentHelper(Client*); |
| 195 | 202 |
| 196 // Register to receive position updates, if we haven't already. If we | 203 // Register to receive position updates, if we haven't already. If we |
| 197 // have, then this does nothing. | 204 // have, then this does nothing. |
| 198 void registerForPositionUpdatesIfNeeded(); | 205 void registerForPositionUpdatesIfNeeded(); |
| 199 | 206 |
| 200 // Un-register for position updates, if we are currently registered. | 207 // Un-register for position updates, if we are currently registered. |
| 201 void unregisterForPositionUpdatesIfNeeded(); | 208 void unregisterForPositionUpdatesIfNeeded(); |
| 202 | 209 |
| 210 // Return true if and only if our media element is in the same origin as the |
| 211 // top-level frame. |
| 212 bool isSameOrigin() const; |
| 213 |
| 203 // Return true if any only if this player meets (most) of the eligibility | 214 // Return true if any only if this player meets (most) of the eligibility |
| 204 // requirements for the experiment to override the need for a user | 215 // requirements for the experiment to override the need for a user |
| 205 // gesture. This includes everything except the visibility test. | 216 // gesture. This includes everything except the visibility test. |
| 206 bool isEligible() const; | 217 bool isEligible() const; |
| 207 | 218 |
| 208 // Return false if and only if m_element is not visible, and we care | 219 // Return false if and only if m_element is not visible, and we care |
| 209 // that it must be visible. | 220 // that it must be visible. |
| 210 bool meetsVisibilityRequirements() const; | 221 bool meetsVisibilityRequirements() const; |
| 211 | 222 |
| 212 // Set the muted flag on the media if we're in an experiment mode that | 223 // Set the muted flag on the media if we're in an experiment mode that |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode
& a, | 313 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode
& a, |
| 303 const AutoplayExperimentHelper::Mode& b) | 314 const AutoplayExperimentHelper::Mode& b) |
| 304 { | 315 { |
| 305 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static
_cast<int>(b)); | 316 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static
_cast<int>(b)); |
| 306 return a; | 317 return a; |
| 307 } | 318 } |
| 308 | 319 |
| 309 } // namespace blink | 320 } // namespace blink |
| 310 | 321 |
| 311 #endif // AutoplayExperimentHelper_h | 322 #endif // AutoplayExperimentHelper_h |
| OLD | NEW |