Chromium Code Reviews| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 public: | 105 public: |
| 106 virtual ~Client() {} | 106 virtual ~Client() {} |
| 107 | 107 |
| 108 // HTMLMediaElement | 108 // HTMLMediaElement |
| 109 virtual double currentTime() const = 0; | 109 virtual double currentTime() const = 0; |
| 110 virtual double duration() const = 0; | 110 virtual double duration() const = 0; |
| 111 virtual bool ended() const = 0; | 111 virtual bool ended() const = 0; |
| 112 virtual bool muted() const = 0; | 112 virtual bool muted() const = 0; |
| 113 virtual void setMuted(bool) = 0; | 113 virtual void setMuted(bool) = 0; |
| 114 virtual void playInternal() = 0; | 114 virtual void playInternal() = 0; |
| 115 virtual bool isUserGestureRequiredForPlay() const = 0; | 115 virtual bool isLockedPendingUserGesture() const = 0; |
| 116 virtual void removeUserGestureRequirement() = 0; | 116 virtual void unlockUserGesture() = 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 | 126 |
| 127 // Frame | 127 // Frame |
| 128 virtual bool isCrossOrigin() const = 0; | 128 virtual bool isCrossOrigin() const = 0; |
| 129 virtual bool isAutoplayAllowedPerSettings() const = 0; | 129 virtual bool isAutoplayAllowedPerSettings() const = 0; |
| 130 | 130 |
| 131 // LayoutObject | 131 // LayoutObject |
| 132 virtual void setRequestPositionUpdates(bool) = 0; | 132 virtual void setRequestPositionUpdates(bool) = 0; |
| 133 virtual IntRect absoluteBoundingBoxRect() const = 0; | 133 virtual IntRect absoluteBoundingBoxRect() const = 0; |
| 134 | 134 |
| 135 DEFINE_INLINE_VIRTUAL_TRACE() { } | 135 DEFINE_INLINE_VIRTUAL_TRACE() { } |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 static AutoplayExperimentHelper* create(Client* client) | 138 static AutoplayExperimentHelper* create(Client* client) |
| 139 { | 139 { |
| 140 return new AutoplayExperimentHelper(client); | 140 return new AutoplayExperimentHelper(client); |
| 141 } | 141 } |
| 142 | 142 |
| 143 ~AutoplayExperimentHelper(); | 143 ~AutoplayExperimentHelper(); |
| 144 | 144 |
| 145 void becameReadyToPlay(); | 145 void becameReadyToPlay(); |
| 146 void playMethodCalled(); | 146 void playMethodCalled(bool playing); |
|
mlamouri (slow - plz ping)
2016/05/06 15:05:47
Could you add a `virtual bool paused() const = 0;`
liberato (no reviews please)
2016/05/17 21:24:33
Done.
| |
| 147 void pauseMethodCalled(); | 147 void pauseMethodCalled(); |
| 148 void loadMethodCalled(); | 148 void loadMethodCalled(); |
| 149 void mutedChanged(); | |
| 150 void positionChanged(const IntRect&); | 149 void positionChanged(const IntRect&); |
| 151 void updatePositionNotificationRegistration(); | 150 void updatePositionNotificationRegistration(); |
| 152 void recordSandboxFailure(); | 151 void recordSandboxFailure(); |
| 153 void loadingStarted(); | 152 void loadingStarted(); |
| 154 void playbackStarted(); | 153 void playbackStarted(); |
| 155 void playbackStopped(); | 154 void playbackStopped(); |
| 156 void initialPlayWithUserGesture(); | 155 void initialPlayWithUserGesture(); |
| 157 | 156 |
| 158 // Returns true if and only if any experiment is enabled (i.e., |m_mode| | 157 // Returns true if and only if any experiment is enabled (i.e., |m_mode| |
| 159 // is not ExperimentOff). | 158 // is not ExperimentOff). |
| 160 bool isExperimentEnabled(); | 159 bool isExperimentEnabled(); |
| 161 | 160 |
| 162 // Clean up. For Oilpan, this means "early in HTMLMediaElement's dispose". | 161 // Clean up. For Oilpan, this means "early in HTMLMediaElement's dispose". |
| 163 // For non-Oilpan, just delete the object. | 162 // For non-Oilpan, just delete the object. |
| 164 void dispose(); | 163 void dispose(); |
| 165 | 164 |
| 166 // Remove the user gesture requirement, and record why. If there is no | 165 // Remove the user gesture requirement, and record why. If there is no |
| 167 // gesture requirement, then this does nothing. | 166 // gesture requirement, then this does nothing. |
| 168 void removeUserGestureRequirement(AutoplayMetrics); | 167 void unlockUserGesture(AutoplayMetrics); |
| 168 | |
| 169 // Set the reason that we're overridding the user gesture. If there is no | |
| 170 // gesture requirement, then this does nothing. | |
| 171 void setDeferredOverrideReason(AutoplayMetrics); | |
| 172 | |
| 173 // Return true if and only if the user gesture requirement is currently | |
| 174 // overridden by the experiment, permitting playback. | |
| 175 bool isGestureRequirementOverridden() const; | |
| 176 | |
| 177 // Return true if and only if playback is queued but hasn't started yet, | |
| 178 // such as if the element doesn't meet visibility requirements. | |
| 179 bool isPlaybackDeferred() const; | |
| 169 | 180 |
| 170 // Set the position to the current view's position, and | 181 // Set the position to the current view's position, and |
| 171 void triggerAutoplayViewportCheckForTesting(); | 182 void triggerAutoplayViewportCheckForTesting(); |
| 172 | 183 |
| 173 enum Mode { | 184 enum Mode { |
| 174 // Do not enable the autoplay experiment. | 185 // Do not enable the autoplay experiment. |
| 175 ExperimentOff = 0, | 186 ExperimentOff = 0, |
| 176 // Enable gestureless autoplay for video elements. | 187 // Enable gestureless autoplay for video elements. |
| 177 ForVideo = 1 << 0, | 188 ForVideo = 1 << 0, |
| 178 // Enable gestureless autoplay for audio elements. | 189 // Enable gestureless autoplay for audio elements. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 203 private: | 214 private: |
| 204 explicit AutoplayExperimentHelper(Client*); | 215 explicit AutoplayExperimentHelper(Client*); |
| 205 | 216 |
| 206 // Register to receive position updates, if we haven't already. If we | 217 // Register to receive position updates, if we haven't already. If we |
| 207 // have, then this does nothing. | 218 // have, then this does nothing. |
| 208 void registerForPositionUpdatesIfNeeded(); | 219 void registerForPositionUpdatesIfNeeded(); |
| 209 | 220 |
| 210 // Un-register for position updates, if we are currently registered. | 221 // Un-register for position updates, if we are currently registered. |
| 211 void unregisterForPositionUpdatesIfNeeded(); | 222 void unregisterForPositionUpdatesIfNeeded(); |
| 212 | 223 |
| 224 // Modifiers for checking isEligible(). | |
| 225 enum EligibilityMode { | |
| 226 // Perform all normal eligibility checks. | |
| 227 Normal = 0, | |
| 228 | |
| 229 // Perform normal eligibility checks, but skip checking if autoplay has | |
| 230 // actually been requested. In other words, don't fail just becase | |
| 231 // nobody has called play() and/or set the autoplay attribute. | |
| 232 IgnorePendingPlayback = 1 | |
| 233 }; | |
| 234 | |
| 213 // Return true if any only if this player meets (most) of the eligibility | 235 // Return true if any only if this player meets (most) of the eligibility |
| 214 // requirements for the experiment to override the need for a user | 236 // requirements for the experiment to override the need for a user |
| 215 // gesture. This includes everything except the visibility test. | 237 // gesture. This includes everything except the visibility test. |
| 216 bool isEligible() const; | 238 // |mode| modifies the eligibility check, as described above. |
| 239 bool isEligible(EligibilityMode = Normal) const; | |
| 217 | 240 |
| 218 // Return false if and only if m_element is not visible, and we care | 241 // Return false if and only if m_element is not visible, and we care |
| 219 // that it must be visible. | 242 // that it must be visible. |
| 220 bool meetsVisibilityRequirements() const; | 243 bool meetsVisibilityRequirements() const; |
| 221 | 244 |
| 222 // Set the muted flag on the media if we're in an experiment mode that | 245 // Set the muted flag on the media if we're in an experiment mode that |
| 223 // requires it, else do nothing. | 246 // requires it, else do nothing. |
| 224 void muteIfNeeded(); | 247 void muteIfNeeded(); |
| 225 | 248 |
| 226 // Maybe override the requirement for a user gesture, and start playing | 249 // Maybe override the requirement for a user gesture, and start playing |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 242 void recordMetricsBeforePause(); | 265 void recordMetricsBeforePause(); |
| 243 | 266 |
| 244 // Process a timer for checking visibility. | 267 // Process a timer for checking visibility. |
| 245 void viewportTimerFired(Timer<AutoplayExperimentHelper>*); | 268 void viewportTimerFired(Timer<AutoplayExperimentHelper>*); |
| 246 | 269 |
| 247 // Return our media element's document. | 270 // Return our media element's document. |
| 248 Document& document() const; | 271 Document& document() const; |
| 249 | 272 |
| 250 Client& client() const; | 273 Client& client() const; |
| 251 | 274 |
| 252 bool isUserGestureRequiredForPlay() const; | 275 bool isLockedPendingUserGesture() const; |
| 253 | 276 |
| 254 inline bool enabled(Mode mode) const | 277 inline bool enabled(Mode mode) const |
| 255 { | 278 { |
| 256 return ((int)m_mode) & ((int)mode); | 279 return ((int)m_mode) & ((int)mode); |
| 257 } | 280 } |
| 258 | 281 |
| 259 Mode fromString(const String& mode); | 282 Mode fromString(const String& mode); |
| 260 | 283 |
| 261 void recordAutoplayMetric(AutoplayMetrics); | 284 void recordAutoplayMetric(AutoplayMetrics); |
| 262 | 285 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode & a, | 339 inline AutoplayExperimentHelper::Mode& operator|=(AutoplayExperimentHelper::Mode & a, |
| 317 const AutoplayExperimentHelper::Mode& b) | 340 const AutoplayExperimentHelper::Mode& b) |
| 318 { | 341 { |
| 319 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static _cast<int>(b)); | 342 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static _cast<int>(b)); |
| 320 return a; | 343 return a; |
| 321 } | 344 } |
| 322 | 345 |
| 323 } // namespace blink | 346 } // namespace blink |
| 324 | 347 |
| 325 #endif // AutoplayExperimentHelper_h | 348 #endif // AutoplayExperimentHelper_h |
| OLD | NEW |