OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2015 Google Inc. All rights reserved. | |
philipj_slow
2015/08/13 10:15:40
This is new code, so I think you can use the short
liberato (no reviews please)
2015/09/01 06:54:20
thanks, forgot about the short one.
| |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef AutoplayExperimentHelper_h | |
32 #define AutoplayExperimentHelper_h | |
33 | |
34 #include "platform/Timer.h" | |
35 | |
36 namespace blink { | |
philipj_slow
2015/08/13 10:15:40
Hmm, merge this into the below namespace blink blo
liberato (no reviews please)
2015/09/01 06:54:20
done.
| |
37 class Document; | |
38 class HTMLMediaElement; | |
39 class EventListener; | |
40 } // namespace blink | |
41 | |
42 namespace blink { | |
43 | |
44 // These values are used for a histogram. Do not reorder. | |
45 enum AutoplayMetrics { | |
46 // Media element with autoplay seen. | |
47 AutoplayMediaFound = 0, | |
48 // Autoplay enabled and user stopped media play at any point. | |
49 AutoplayStopped = 1, | |
50 // Autoplay enabled but user bailed out on media play early. | |
51 AutoplayBailout = 2, | |
52 // Autoplay disabled but user manually started media. | |
53 AutoplayManualStart = 3, | |
54 // Autoplay was (re)enabled through a user-gesture triggered load() | |
55 AutoplayEnabledThroughLoad = 4, | |
56 // Autoplay disabled by sandbox flags. | |
57 AutoplayDisabledBySandbox = 5, | |
58 | |
59 // These metrics indicate "no gesture but gesture requirement was | |
60 // overridden by experiment". They do not include cases where no | |
61 // user gesture is required (!m_userGestureRequiredForPlay). | |
62 // Gestureless playback when media scrolled into view. We don't | |
philipj_slow
2015/08/13 10:15:40
I can't parse "Gestureless playback when media scr
liberato (no reviews please)
2015/09/01 06:54:20
Done.
| |
63 // record whether it was a javascript or attribute autoplay request. | |
64 GesturelessPlaybackStartedByScroll = 6, | |
65 // Autoplay started by experiment override during initial load. | |
philipj_slow
2015/08/13 10:15:40
If I'm reading this right, GesturelessPlaybackStar
liberato (no reviews please)
2015/09/01 06:54:20
i renamed these. i also separated GesturelessPlay
| |
66 GesturelessPlaybackStartedByLoad = 7, | |
67 // Autoplay started by experiment override in play() call. | |
68 GesturelessPlaybackStartedByPlayMethod = 8, | |
69 | |
70 // play() failed to play due to gesture requirement. | |
71 PlayMethodFailed = 9, | |
72 | |
73 // Some play, whether user initiated or not, started. | |
74 AnyPlaybackStarted = 10, | |
75 // Some play, whether user initiated or not, stopped. | |
76 AnyPlaybackStopped = 11, | |
77 // Some playback, whether user initiated or not, bailed out early. | |
78 AnyPlaybackBailout = 12, | |
79 | |
80 // This enum value must be last. | |
81 NumberOfAutoplayMetrics, | |
82 }; | |
83 | |
84 class AutoplayExperimentHelper { | |
85 public: | |
86 AutoplayExperimentHelper(HTMLMediaElement&); | |
87 ~AutoplayExperimentHelper(); | |
88 | |
89 void onReadyToPlay(); | |
philipj_slow
2015/08/13 10:15:40
The name had me thinking it was a callback based o
liberato (no reviews please)
2015/09/01 06:54:20
Done.
| |
90 void onPlayMethodCalled(); | |
91 void onPauseMethodCalled(); | |
92 void onMuteChanged(); | |
93 | |
94 private: | |
95 // Install an event listener to check for changes in visibility. If a | |
96 // listener is already installed, then this does nothing. | |
97 void installEventListenerIfNeeded(); | |
98 | |
99 // Remove any event listener. It's okay to call this if one isn't | |
100 // installed already. | |
101 void clearEventListenerIfNeeded(); | |
102 | |
103 // Return true if any only if this player meets (most) of the eligibility | |
104 // requirements for the experiment to override the need for a user | |
105 // gesture. This includes everything except the visibility test. | |
106 bool isEligible() const; | |
107 | |
108 // Return true if and only if the player is visible. | |
109 bool isInViewportIfNeeded(); | |
110 | |
111 // Set the mute flag on the media if we're in an experiment mode that | |
philipj_slow
2015/08/13 10:15:40
s/mute/muted/
liberato (no reviews please)
2015/09/01 06:54:20
Done.
| |
112 // requires it, else do nothing. | |
113 void muteIfNeeded(); | |
114 | |
115 // Maybe override the requirement for a user gesture, and start playing | |
116 // autoplay media. Returns true if only if it starts playback. | |
117 bool maybeStartPlaying(); | |
118 | |
119 // Configure internal state to record that the autoplay experiment is | |
120 // going to start playback. This doesn't actually start playback, since | |
121 // there are several different cases. | |
122 void prepareToPlay(AutoplayMetrics); | |
123 | |
124 // Begin (or start over) a periodic check for visibility. We will poll | |
125 // during this check to see if the video is in the viewport. | |
126 void notifyScrolled(); | |
127 | |
128 // Process a timer for checking visibility. | |
129 void viewportTimerFired(Timer<AutoplayExperimentHelper>*); | |
130 | |
131 // Return our media player's document. | |
philipj_slow
2015/08/13 10:15:40
s/player/element/
liberato (no reviews please)
2015/09/01 06:54:20
Done.
| |
132 Document& document() const; | |
133 | |
134 private: | |
135 HTMLMediaElement& m_element; | |
136 | |
137 enum AutoplayExperimentMode { | |
138 ExperimentOff = 0, | |
139 ExperimentEnabled = 1 << 0, | |
140 ExperimentIfViewport = 1 << 1, | |
141 ExperimentIfMuted = 1 << 2, | |
142 ExperimentIfMobile = 1 << 3, | |
143 ExperimentPlayMuted = 1 << 4 | |
144 }; | |
145 int m_mode; // Bitwise-or of AutoplayExperimentMode | |
146 | |
147 // Autoplay experiment state. | |
148 // True if we've received a play() without a pause(). | |
149 bool m_playPending : 1; | |
150 | |
151 // Scroll listener for the autoplay experiment, to help us determine when | |
152 // the user has scrolled the player into the viewport. | |
philipj_slow
2015/08/13 10:15:40
To be pedantic, it could also be scripts driving t
liberato (no reviews please)
2015/09/01 06:54:20
listener was removed, as part of Ojan's suggested
| |
153 class ScrollListener; | |
154 friend class AutoplayExperimentScrollListener; | |
155 RefPtrWillBeMember<EventListener> m_scrollListener; | |
156 Timer<AutoplayExperimentHelper> m_viewportTimer; | |
157 }; | |
158 | |
159 } // namespace blink | |
160 | |
161 #endif // AutoplayExperimentHelper_h | |
OLD | NEW |