OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "core/html/AutoplayExperimentHelper.h" | 5 #include "core/html/AutoplayExperimentHelper.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
9 #include "core/html/HTMLMediaElement.h" | 9 #include "core/html/HTMLMediaElement.h" |
10 #include "core/layout/LayoutBox.h" | 10 #include "core/layout/LayoutBox.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void AutoplayExperimentHelper::playMethodCalled() | 79 void AutoplayExperimentHelper::playMethodCalled() |
80 { | 80 { |
81 // Set the pending state, even if the play isn't going to be pending. | 81 // Set the pending state, even if the play isn't going to be pending. |
82 // Eligibility can change if, for example, the mute status changes. | 82 // Eligibility can change if, for example, the mute status changes. |
83 // Having this set is okay. | 83 // Having this set is okay. |
84 m_playPending = true; | 84 m_playPending = true; |
85 | 85 |
86 if (!UserGestureIndicator::processingUserGesture()) { | 86 if (!UserGestureIndicator::utilizeUserGesture()) { |
87 autoplayMediaEncountered(); | 87 autoplayMediaEncountered(); |
88 | 88 |
89 if (isEligible()) { | 89 if (isEligible()) { |
90 // Remember that userGestureRequiredForPlay is required for | 90 // Remember that userGestureRequiredForPlay is required for |
91 // us to be eligible for the experiment. | 91 // us to be eligible for the experiment. |
92 // If we are able to override the gesture requirement now, then | 92 // If we are able to override the gesture requirement now, then |
93 // do so. Otherwise, install an event listener if we need one. | 93 // do so. Otherwise, install an event listener if we need one. |
94 if (meetsVisibilityRequirements()) { | 94 if (meetsVisibilityRequirements()) { |
95 // Override the gesture and assume that play() will succeed. | 95 // Override the gesture and assume that play() will succeed. |
96 prepareToAutoplay(GesturelessPlaybackStartedByPlayMethodImmediat
ely); | 96 prepareToAutoplay(GesturelessPlaybackStartedByPlayMethodImmediat
ely); |
(...skipping 17 matching lines...) Expand all Loading... |
114 | 114 |
115 void AutoplayExperimentHelper::pauseMethodCalled() | 115 void AutoplayExperimentHelper::pauseMethodCalled() |
116 { | 116 { |
117 // Don't try to autoplay, if we would have. | 117 // Don't try to autoplay, if we would have. |
118 m_playPending = false; | 118 m_playPending = false; |
119 unregisterForPositionUpdatesIfNeeded(); | 119 unregisterForPositionUpdatesIfNeeded(); |
120 } | 120 } |
121 | 121 |
122 void AutoplayExperimentHelper::loadMethodCalled() | 122 void AutoplayExperimentHelper::loadMethodCalled() |
123 { | 123 { |
124 if (UserGestureIndicator::processingUserGesture() && isUserGestureRequiredFo
rPlay()) { | 124 if (isUserGestureRequiredForPlay() && UserGestureIndicator::utilizeUserGestu
re()) { |
125 recordAutoplayMetric(AutoplayEnabledThroughLoad); | 125 recordAutoplayMetric(AutoplayEnabledThroughLoad); |
126 removeUserGestureRequirement(GesturelessPlaybackEnabledByLoad); | 126 removeUserGestureRequirement(GesturelessPlaybackEnabledByLoad); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 void AutoplayExperimentHelper::mutedChanged() | 130 void AutoplayExperimentHelper::mutedChanged() |
131 { | 131 { |
132 // If we are no longer eligible for the autoplay experiment, then also | 132 // If we are no longer eligible for the autoplay experiment, then also |
133 // quit listening for events. If we are eligible, and if we should be | 133 // quit listening for events. If we are eligible, and if we should be |
134 // playing, then start playing. In other words, start playing if | 134 // playing, then start playing. In other words, start playing if |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 if (m_recordedElement) | 476 if (m_recordedElement) |
477 return; | 477 return; |
478 | 478 |
479 m_recordedElement = true; | 479 m_recordedElement = true; |
480 recordAutoplayMetric(client().isHTMLVideoElement() | 480 recordAutoplayMetric(client().isHTMLVideoElement() |
481 ? AnyVideoElement | 481 ? AnyVideoElement |
482 : AnyAudioElement); | 482 : AnyAudioElement); |
483 } | 483 } |
484 | 484 |
485 } // namespace blink | 485 } // namespace blink |
OLD | NEW |