| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 AnyPlaybackStarted = 11, | 60 AnyPlaybackStarted = 11, |
| 61 // Some play, whether user initiated or not, paused. | 61 // Some play, whether user initiated or not, paused. |
| 62 AnyPlaybackPaused = 12, | 62 AnyPlaybackPaused = 12, |
| 63 // Some playback, whether user initiated or not, bailed out early. | 63 // Some playback, whether user initiated or not, bailed out early. |
| 64 AnyPlaybackBailout = 13, | 64 AnyPlaybackBailout = 13, |
| 65 | 65 |
| 66 // This enum value must be last. | 66 // This enum value must be last. |
| 67 NumberOfAutoplayMetrics, | 67 NumberOfAutoplayMetrics, |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 class AutoplayExperimentHelper { | 70 class AutoplayExperimentHelper final { |
| 71 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 71 public: | 72 public: |
| 72 AutoplayExperimentHelper(HTMLMediaElement&); | 73 explicit AutoplayExperimentHelper(HTMLMediaElement&); |
| 73 ~AutoplayExperimentHelper(); | 74 ~AutoplayExperimentHelper(); |
| 74 | 75 |
| 75 void becameReadyToPlay(); | 76 void becameReadyToPlay(); |
| 76 void playMethodCalled(); | 77 void playMethodCalled(); |
| 77 void pauseMethodCalled(); | 78 void pauseMethodCalled(); |
| 78 void mutedChanged(); | 79 void mutedChanged(); |
| 79 void positionChanged(const IntRect&); | 80 void positionChanged(const IntRect&); |
| 80 void updatePositionNotificationRegistration(); | 81 void updatePositionNotificationRegistration(); |
| 81 | 82 |
| 82 void triggerAutoplayViewportCheckForTesting(); | 83 void triggerAutoplayViewportCheckForTesting(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 96 // Restrict gestureless autoplay to audio-less or muted media. | 97 // Restrict gestureless autoplay to audio-less or muted media. |
| 97 IfMuted = 1 << 4, | 98 IfMuted = 1 << 4, |
| 98 // Restrict gestureless autoplay to sites which contain the | 99 // Restrict gestureless autoplay to sites which contain the |
| 99 // viewport tag. | 100 // viewport tag. |
| 100 IfMobile = 1 << 5, | 101 IfMobile = 1 << 5, |
| 101 // If gestureless autoplay is allowed, then mute the media before | 102 // If gestureless autoplay is allowed, then mute the media before |
| 102 // starting to play. | 103 // starting to play. |
| 103 PlayMuted = 1 << 6, | 104 PlayMuted = 1 << 6, |
| 104 }; | 105 }; |
| 105 | 106 |
| 107 DEFINE_INLINE_TRACE() |
| 108 { |
| 109 visitor->trace(m_element); |
| 110 } |
| 111 |
| 106 private: | 112 private: |
| 107 // Register to receive position updates, if we haven't already. If we | 113 // Register to receive position updates, if we haven't already. If we |
| 108 // have, then this does nothing. | 114 // have, then this does nothing. |
| 109 void registerForPositionUpdatesIfNeeded(); | 115 void registerForPositionUpdatesIfNeeded(); |
| 110 | 116 |
| 111 // Un-register for position updates, if we are currently registered. | 117 // Un-register for position updates, if we are currently registered. |
| 112 void unregisterForPositionUpdatesIfNeeded(); | 118 void unregisterForPositionUpdatesIfNeeded(); |
| 113 | 119 |
| 114 // Return true if any only if this player meets (most) of the eligibility | 120 // Return true if any only if this player meets (most) of the eligibility |
| 115 // requirements for the experiment to override the need for a user | 121 // requirements for the experiment to override the need for a user |
| (...skipping 16 matching lines...) Expand all Loading... |
| 132 // going to start playback. This doesn't actually start playback, since | 138 // going to start playback. This doesn't actually start playback, since |
| 133 // there are several different cases. | 139 // there are several different cases. |
| 134 void prepareToPlay(AutoplayMetrics); | 140 void prepareToPlay(AutoplayMetrics); |
| 135 | 141 |
| 136 // Process a timer for checking visibility. | 142 // Process a timer for checking visibility. |
| 137 void viewportTimerFired(Timer<AutoplayExperimentHelper>*); | 143 void viewportTimerFired(Timer<AutoplayExperimentHelper>*); |
| 138 | 144 |
| 139 // Return our media element's document. | 145 // Return our media element's document. |
| 140 Document& document() const; | 146 Document& document() const; |
| 141 | 147 |
| 148 HTMLMediaElement& element() const; |
| 149 |
| 142 inline bool enabled(Mode mode) const | 150 inline bool enabled(Mode mode) const |
| 143 { | 151 { |
| 144 return ((int)m_mode) & ((int)mode); | 152 return ((int)m_mode) & ((int)mode); |
| 145 } | 153 } |
| 146 | 154 |
| 147 Mode fromString(const String& mode); | 155 Mode fromString(const String& mode); |
| 148 | 156 |
| 149 private: | 157 RawPtrWillBeMember<HTMLMediaElement> m_element; |
| 150 HTMLMediaElement& m_element; | |
| 151 | 158 |
| 152 Mode m_mode; | 159 Mode m_mode; |
| 153 | 160 |
| 154 // Autoplay experiment state. | 161 // Autoplay experiment state. |
| 155 // True if we've received a play() without a pause(). | 162 // True if we've received a play() without a pause(). |
| 156 bool m_playPending : 1; | 163 bool m_playPending : 1; |
| 157 | 164 |
| 158 // Are we registered with the view for position updates? | 165 // Are we registered with the view for position updates? |
| 159 bool m_registeredWithLayoutObject : 1; | 166 bool m_registeredWithLayoutObject : 1; |
| 160 | 167 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 175 const AutoplayExperimentHelper::Mode& b) | 182 const AutoplayExperimentHelper::Mode& b) |
| 176 { | 183 { |
| 177 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static
_cast<int>(b)); | 184 a = static_cast<AutoplayExperimentHelper::Mode>(static_cast<int>(a) | static
_cast<int>(b)); |
| 178 return a; | 185 return a; |
| 179 } | 186 } |
| 180 | 187 |
| 181 | 188 |
| 182 } // namespace blink | 189 } // namespace blink |
| 183 | 190 |
| 184 #endif // AutoplayExperimentHelper_h | 191 #endif // AutoplayExperimentHelper_h |
| OLD | NEW |