| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 // Remove the user gesture requirement, and record why. If there is no | 158 // Remove the user gesture requirement, and record why. If there is no |
| 159 // gesture requirement, then this does nothing. | 159 // gesture requirement, then this does nothing. |
| 160 void removeUserGestureRequirement(AutoplayMetrics); | 160 void removeUserGestureRequirement(AutoplayMetrics); |
| 161 | 161 |
| 162 // Set the position to the current view's position, and | 162 // Set the position to the current view's position, and |
| 163 void triggerAutoplayViewportCheckForTesting(); | 163 void triggerAutoplayViewportCheckForTesting(); |
| 164 | 164 |
| 165 enum Mode { | 165 enum Mode { |
| 166 // Do not enable the autoplay experiment. | 166 // Do not enable the autoplay experiment. |
| 167 ExperimentOff = 0, | 167 ExperimentOff = 0, |
| 168 // Enable gestureless autoplay for video elements. | 168 // Enable gestureless autoplay for video elements. |
| 169 ForVideo = 1 << 0, | 169 ForVideo = 1 << 0, |
| 170 // Enable gestureless autoplay for audio elements. | 170 // Enable gestureless autoplay for audio elements. |
| 171 ForAudio = 1 << 1, | 171 ForAudio = 1 << 1, |
| 172 // Restrict gestureless autoplay to media that is in a visible page. | 172 // Restrict gestureless autoplay to media that is in a visible page. |
| 173 IfPageVisible = 1 << 2, | 173 IfPageVisible = 1 << 2, |
| 174 // Restrict gestureless autoplay to media that is visible in | 174 // Restrict gestureless autoplay to media that is entirely visible in |
| 175 // the viewport. | 175 // the viewport. |
| 176 IfViewport = 1 << 3, | 176 IfViewport = 1 << 3, |
| 177 // Restrict gestureless autoplay to media that is partially visible in |
| 178 // the viewport. |
| 179 IfPartialViewport = 1 << 4, |
| 177 // Restrict gestureless autoplay to audio-less or muted media. | 180 // Restrict gestureless autoplay to audio-less or muted media. |
| 178 IfMuted = 1 << 4, | 181 IfMuted = 1 << 5, |
| 179 // Restrict gestureless autoplay to sites which contain the | 182 // Restrict gestureless autoplay to sites which contain the |
| 180 // viewport tag. | 183 // viewport tag. |
| 181 IfMobile = 1 << 5, | 184 IfMobile = 1 << 6, |
| 182 // If gestureless autoplay is allowed, then mute the media before | 185 // If gestureless autoplay is allowed, then mute the media before |
| 183 // starting to play. | 186 // starting to play. |
| 184 PlayMuted = 1 << 6, | 187 PlayMuted = 1 << 7, |
| 185 }; | 188 }; |
| 186 | 189 |
| 187 DEFINE_INLINE_TRACE() { visitor->trace(m_client); } | 190 DEFINE_INLINE_TRACE() { visitor->trace(m_client); } |
| 188 | 191 |
| 189 private: | 192 private: |
| 190 explicit AutoplayExperimentHelper(Client*); | 193 explicit AutoplayExperimentHelper(Client*); |
| 191 | 194 |
| 192 // Register to receive position updates, if we haven't already. If we | 195 // Register to receive position updates, if we haven't already. If we |
| 193 // have, then this does nothing. | 196 // have, then this does nothing. |
| 194 void registerForPositionUpdatesIfNeeded(); | 197 void registerForPositionUpdatesIfNeeded(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 246 } |
| 244 | 247 |
| 245 Mode fromString(const String& mode); | 248 Mode fromString(const String& mode); |
| 246 | 249 |
| 247 void recordAutoplayMetric(AutoplayMetrics); | 250 void recordAutoplayMetric(AutoplayMetrics); |
| 248 | 251 |
| 249 // Could stopping at this point be considered a bailout of playback? | 252 // Could stopping at this point be considered a bailout of playback? |
| 250 // (as in, "The user really didn't want to play this"). | 253 // (as in, "The user really didn't want to play this"). |
| 251 bool isBailout() const; | 254 bool isBailout() const; |
| 252 | 255 |
| 256 // Returns true if and only if the experiment requires some sort of viewport |
| 257 // visibility check for autoplay. |
| 258 bool requiresViewportVisibility() const; |
| 259 |
| 253 Member<Client> m_client; | 260 Member<Client> m_client; |
| 254 | 261 |
| 255 Mode m_mode; | 262 Mode m_mode; |
| 256 | 263 |
| 257 // Autoplay experiment state. | 264 // Autoplay experiment state. |
| 258 // True if we've received a play() without a pause(). | 265 // True if we've received a play() without a pause(). |
| 259 bool m_playPending : 1; | 266 bool m_playPending : 1; |
| 260 | 267 |
| 261 // Are we registered with the view for position updates? | 268 // Are we registered with the view for position updates? |
| 262 bool m_registeredWithLayoutObject : 1; | 269 bool m_registeredWithLayoutObject : 1; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode
& a, | 305 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode
& a, |
| 299 const AutoplayExperimentHelper::Mode& b) | 306 const AutoplayExperimentHelper::Mode& b) |
| 300 { | 307 { |
| 301 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static
_cast<int>(b)); | 308 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static
_cast<int>(b)); |
| 302 return a; | 309 return a; |
| 303 } | 310 } |
| 304 | 311 |
| 305 } // namespace blink | 312 } // namespace blink |
| 306 | 313 |
| 307 #endif // AutoplayExperimentHelper_h | 314 #endif // AutoplayExperimentHelper_h |
| OLD | NEW |