Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| index f3c4ad3860e506678b34be4e784a8ada27ae72ed..5d6e8f79cf23bec0f9392d0d569e681ebed554ee 100644 |
| --- a/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/HTMLMediaElement.cpp |
| @@ -337,8 +337,6 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum |
| , m_remoteRoutesAvailable(false) |
| , m_playingRemotely(false) |
| , m_isFinalizing(false) |
| - , m_initialPlayWithoutUserGesture(false) |
| - , m_autoplayMediaCounted(false) |
| , m_inOverlayFullscreenVideo(false) |
| , m_audioTracks(AudioTrackList::create(*this)) |
| , m_videoTracks(VideoTrackList::create(*this)) |
| @@ -669,47 +667,11 @@ String HTMLMediaElement::canPlayType(const String& mimeType, const String& keySy |
| return canPlay; |
| } |
| -void HTMLMediaElement::recordMetricsIfPausing() |
| -{ |
| - // If not playing, then nothing to record. |
| - // TODO(liberato): test metrics. this was m_paused. |
| - if (m_paused) |
| - return; |
| - |
| - const bool bailout = isBailout(); |
| - |
| - // Record that play was paused. We don't care if it was autoplay, |
| - // play(), or the user manually started it. |
| - recordAutoplayMetric(AnyPlaybackPaused); |
| - if (bailout) |
| - recordAutoplayMetric(AnyPlaybackBailout); |
| - |
| - // If this was a gestureless play, then record that separately. |
| - // These cover attr and play() gestureless starts. |
| - if (m_initialPlayWithoutUserGesture) { |
| - m_initialPlayWithoutUserGesture = false; |
| - |
| - recordAutoplayMetric(AutoplayPaused); |
| - |
| - if (bailout) |
| - recordAutoplayMetric(AutoplayBailout); |
| - } |
| -} |
| - |
| void HTMLMediaElement::load() |
| { |
| WTF_LOG(Media, "HTMLMediaElement::load(%p)", this); |
| - recordMetricsIfPausing(); |
| - |
| - if (UserGestureIndicator::processingUserGesture() && m_userGestureRequiredForPlay) { |
| - recordAutoplayMetric(AutoplayEnabledThroughLoad); |
| - m_userGestureRequiredForPlay = false; |
| - // While usergesture-initiated load()s technically count as autoplayed, |
| - // they don't feel like such to the users and hence we don't want to |
| - // count them for the purposes of metrics. |
| - m_autoplayMediaCounted = true; |
| - } |
| + m_autoplayHelper.loadMethodCalled(); |
| prepareForLoad(); |
| loadInternal(); |
| @@ -933,6 +895,8 @@ void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c |
| // The resource fetch algorithm |
| setNetworkState(NETWORK_LOADING); |
| + m_autoplayHelper.loadingStarted(); |
| + |
| // Set m_currentSrc *before* changing to the cache url, the fact that we are loading from the app |
| // cache is an internal detail not exposed through the media element API. |
| m_currentSrc = url; |
| @@ -961,7 +925,7 @@ void HTMLMediaElement::loadResource(const KURL& url, ContentType& contentType, c |
| if (url.protocolIs(mediaSourceBlobProtocol)) { |
| if (isMediaStreamURL(url.string())) { |
| - m_userGestureRequiredForPlay = false; |
| + removeUserGestureRequirement(GesturelessPlaybackEnabledByStream); |
| } else { |
| m_mediaSource = HTMLMediaSource::lookup(url.string()); |
| @@ -1533,20 +1497,22 @@ void HTMLMediaElement::setReadyState(ReadyState state) |
| bool isPotentiallyPlaying = potentiallyPlaying(); |
| if (m_readyState == HAVE_FUTURE_DATA && oldState <= HAVE_CURRENT_DATA && tracksAreReady) { |
| scheduleEvent(EventTypeNames::canplay); |
| - if (isPotentiallyPlaying) |
| + if (isPotentiallyPlaying) { |
|
philipj_slow
2015/12/02 09:01:46
Some extra {} here and elsewhere.
liberato (no reviews please)
2015/12/30 16:58:24
Done.
|
| scheduleEvent(EventTypeNames::playing); |
| + } |
| shouldUpdateDisplayState = true; |
| } |
| if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && tracksAreReady) { |
| if (oldState <= HAVE_CURRENT_DATA) { |
| scheduleEvent(EventTypeNames::canplay); |
| - if (isPotentiallyPlaying) |
| + if (isPotentiallyPlaying) { |
| scheduleEvent(EventTypeNames::playing); |
| + } |
| } |
| // Check for autoplay, and record metrics about it if needed. |
| - if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { |
| + if (shouldAutoplay(RecordMetricsBehavior::RecordOnSandboxFailure)) { |
| // If the autoplay experiment says that it's okay to play now, |
| // then don't require a user gesture. |
| m_autoplayHelper.becameReadyToPlay(); |
| @@ -1687,7 +1653,7 @@ void HTMLMediaElement::seek(double time) |
| // 11 - Set the current playback position to the given new playback position. |
| webMediaPlayer()->seek(time); |
| - m_initialPlayWithoutUserGesture = false; |
| + m_autoplayHelper.initialPlayWithUserGesture(); |
|
philipj_slow
2015/12/02 09:01:46
This is the seek method, can you remind me why `m_
liberato (no reviews please)
2015/12/30 16:58:24
i'm not sure either. i think that was left over i
|
| // 14-17 are handled, if necessary, when the engine signals a readystate change or otherwise |
| // satisfies seek completion and signals a time change. |
| @@ -1870,12 +1836,10 @@ bool HTMLMediaElement::autoplay() const |
| bool HTMLMediaElement::shouldAutoplay(const RecordMetricsBehavior recordMetrics) |
| { |
| if (m_autoplaying && m_paused && autoplay()) { |
| - if (recordMetrics == RecordMetricsBehavior::DoRecord) |
| - autoplayMediaEncountered(); |
| - |
| if (document().isSandboxed(SandboxAutomaticFeatures)) { |
| - if (recordMetrics == RecordMetricsBehavior::DoRecord) |
| - recordAutoplayMetric(AutoplayDisabledBySandbox); |
| + if (recordMetrics == RecordMetricsBehavior::RecordOnSandboxFailure) { |
| + m_autoplayHelper.recordSandboxFailure(); |
| + } |
| return false; |
| } |
| @@ -1953,8 +1917,6 @@ void HTMLMediaElement::play() |
| m_autoplayHelper.playMethodCalled(); |
| if (!UserGestureIndicator::processingUserGesture()) { |
| - autoplayMediaEncountered(); |
| - |
| if (m_userGestureRequiredForPlay) { |
| recordAutoplayMetric(PlayMethodFailed); |
| String message = ExceptionMessages::failedToExecute("play", "HTMLMediaElement", "API can only be initiated by a user gesture."); |
| @@ -1962,9 +1924,7 @@ void HTMLMediaElement::play() |
| return; |
| } |
| } else if (m_userGestureRequiredForPlay) { |
|
philipj_slow
2015/12/02 09:01:46
You could now make this a plain else branch, since
liberato (no reviews please)
2015/12/30 16:58:24
Done.
|
| - if (m_autoplayMediaCounted) |
| - recordAutoplayMetric(AutoplayManualStart); |
| - m_userGestureRequiredForPlay = false; |
| + removeUserGestureRequirement(GesturelessPlaybackEnabledByPlayMethod); |
| } |
| playInternal(); |
| @@ -1994,31 +1954,10 @@ void HTMLMediaElement::playInternal() |
| else if (m_readyState >= HAVE_FUTURE_DATA) |
| scheduleEvent(EventTypeNames::playing); |
| } |
| - m_autoplaying = false; |
|
philipj_slow
2015/12/02 09:01:46
Did this spill over from the other CL, or did you
liberato (no reviews please)
2015/12/30 16:58:24
spilled over, fixed.
|
| updatePlayState(); |
| } |
| -void HTMLMediaElement::autoplayMediaEncountered() |
| -{ |
| - if (!m_autoplayMediaCounted) { |
| - m_autoplayMediaCounted = true; |
| - recordAutoplayMetric(AutoplayMediaFound); |
| - |
| - if (!m_userGestureRequiredForPlay) |
| - m_initialPlayWithoutUserGesture = true; |
| - } |
| -} |
| - |
| -bool HTMLMediaElement::isBailout() const |
| -{ |
| - // We count the user as having bailed-out on the video if they watched |
| - // less than one minute and less than 50% of it. |
| - const double playedTime = currentTime(); |
| - const double progress = playedTime / duration(); |
| - return (playedTime < 60) && (progress < 0.5); |
| -} |
| - |
| void HTMLMediaElement::pause() |
| { |
| WTF_LOG(Media, "HTMLMediaElement::pause(%p)", this); |
| @@ -2031,8 +1970,6 @@ void HTMLMediaElement::pause() |
| m_autoplaying = false; |
| if (!m_paused) { |
| - recordMetricsIfPausing(); |
| - |
| m_paused = true; |
| scheduleTimeupdateEvent(false); |
| scheduleEvent(EventTypeNames::pause); |
| @@ -2724,6 +2661,7 @@ void HTMLMediaElement::timeChanged() |
| // forwards, and paused is false, |
| if (!m_paused) { |
| // changes paused to true and fires a simple event named pause at the media element. |
| + m_autoplayHelper.playbackEnded(); |
| m_paused = true; |
| scheduleEvent(EventTypeNames::pause); |
| } |
| @@ -2732,7 +2670,6 @@ void HTMLMediaElement::timeChanged() |
| m_sentEndEvent = true; |
| scheduleEvent(EventTypeNames::ended); |
| } |
| - recordMetricsIfPausing(); |
| } |
| } else { |
| m_sentEndEvent = false; |
| @@ -2939,17 +2876,18 @@ void HTMLMediaElement::updatePlayState() |
| webMediaPlayer()->setRate(playbackRate()); |
| updateVolume(); |
| webMediaPlayer()->play(); |
| + m_autoplayHelper.playbackStarted(); |
| } |
| if (mediaControls()) |
| mediaControls()->playbackStarted(); |
| startPlaybackProgressTimer(); |
| m_playing = true; |
| - recordAutoplayMetric(AnyPlaybackStarted); |
| } else { // Should not be playing right now |
| if (isPlaying) |
| webMediaPlayer()->pause(); |
| + |
| refreshCachedTime(); |
| m_playbackProgressTimer.stop(); |
| @@ -3065,8 +3003,6 @@ void HTMLMediaElement::stop() |
| { |
| WTF_LOG(Media, "HTMLMediaElement::stop(%p)", this); |
| - recordMetricsIfPausing(); |
| - |
| // Close the async event queue so that no events are enqueued by userCancelledLoad. |
| cancelPendingEventsAndCallbacks(); |
| m_asyncEventQueue->close(); |
| @@ -3575,14 +3511,12 @@ bool HTMLMediaElement::isUserGestureRequiredForPlay() const |
| return m_userGestureRequiredForPlay; |
| } |
| -void HTMLMediaElement::removeUserGestureRequirement() |
| +void HTMLMediaElement::removeUserGestureRequirement(AutoplayMetrics deferredMetric) |
| { |
| - m_userGestureRequiredForPlay = false; |
| -} |
| - |
| -void HTMLMediaElement::setInitialPlayWithoutUserGestures(bool value) |
| -{ |
| - m_initialPlayWithoutUserGesture = value; |
| + if (m_userGestureRequiredForPlay) { |
| + m_userGestureRequiredForPlay = false; |
| + m_autoplayHelper.setGestureRemovalReason(deferredMetric); |
| + } |
| } |
| void HTMLMediaElement::setNetworkState(NetworkState state) |