Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: Source/core/html/HTMLMediaElement.cpp

Issue 1179223002: Implement autoplay gesture override experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: linker errors on win/mac... Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows 240 // when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows
241 // it cannot render. 241 // it cannot render.
242 if (contentMIMEType != "application/octet-stream" || contentTypeCodecs.isEmp ty()) { 242 if (contentMIMEType != "application/octet-stream" || contentTypeCodecs.isEmp ty()) {
243 WebMimeRegistry::SupportsType supported = Platform::current()->mimeRegis try()->supportsMediaMIMEType(contentMIMEType, contentTypeCodecs, keySystem.lower ()); 243 WebMimeRegistry::SupportsType supported = Platform::current()->mimeRegis try()->supportsMediaMIMEType(contentMIMEType, contentTypeCodecs, keySystem.lower ());
244 return supported > WebMimeRegistry::IsNotSupported; 244 return supported > WebMimeRegistry::IsNotSupported;
245 } 245 }
246 246
247 return false; 247 return false;
248 } 248 }
249 249
250 // These values are used for a histogram. Do not reorder. 250 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric)
251 enum AutoplayMetrics {
252 // Media element with autoplay seen.
253 AutoplayMediaFound = 0,
254 // Autoplay enabled and user stopped media play at any point.
255 AutoplayStopped = 1,
256 // Autoplay enabled but user bailed out on media play early.
257 AutoplayBailout = 2,
258 // Autoplay disabled but user manually started media.
259 AutoplayManualStart = 3,
260 // Autoplay was (re)enabled through a user-gesture triggered load()
261 AutoplayEnabledThroughLoad = 4,
262 // Autoplay disabled by sandbox flags.
263 AutoplayDisabledBySandbox = 5,
264 // This enum value must be last.
265 NumberOfAutoplayMetrics,
266 };
267
268 static void recordAutoplayMetric(AutoplayMetrics metric)
269 { 251 {
270 Platform::current()->histogramEnumeration("Blink.MediaElement.Autoplay", met ric, NumberOfAutoplayMetrics); 252 Platform::current()->histogramEnumeration("Blink.MediaElement.Autoplay", met ric, NumberOfAutoplayMetrics);
271 } 253 }
272 254
273 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType, const String& keySystem) 255 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType, const String& keySystem)
274 { 256 {
275 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs")); 257 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs"));
276 258
277 if (!RuntimeEnabledFeatures::mediaEnabled()) 259 if (!RuntimeEnabledFeatures::mediaEnabled())
278 return WebMimeRegistry::IsNotSupported; 260 return WebMimeRegistry::IsNotSupported;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 , m_sentEndEvent(false) 330 , m_sentEndEvent(false)
349 , m_closedCaptionsVisible(false) 331 , m_closedCaptionsVisible(false)
350 , m_completelyLoaded(false) 332 , m_completelyLoaded(false)
351 , m_havePreparedToPlay(false) 333 , m_havePreparedToPlay(false)
352 , m_tracksAreReady(true) 334 , m_tracksAreReady(true)
353 , m_haveVisibleTextTrack(false) 335 , m_haveVisibleTextTrack(false)
354 , m_processingPreferenceChange(false) 336 , m_processingPreferenceChange(false)
355 , m_remoteRoutesAvailable(false) 337 , m_remoteRoutesAvailable(false)
356 , m_playingRemotely(false) 338 , m_playingRemotely(false)
357 , m_isFinalizing(false) 339 , m_isFinalizing(false)
358 , m_initialPlayWithoutUserGestures(false) 340 , m_initialPlayWithoutUserGesture(false)
359 , m_autoplayMediaCounted(false) 341 , m_autoplayMediaCounted(false)
360 , m_inOverlayFullscreenVideo(false) 342 , m_inOverlayFullscreenVideo(false)
361 , m_audioTracks(AudioTrackList::create(*this)) 343 , m_audioTracks(AudioTrackList::create(*this))
362 , m_videoTracks(VideoTrackList::create(*this)) 344 , m_videoTracks(VideoTrackList::create(*this))
363 , m_textTracks(nullptr) 345 , m_textTracks(nullptr)
364 #if ENABLE(WEB_AUDIO) 346 #if ENABLE(WEB_AUDIO)
365 , m_audioSourceNode(nullptr) 347 , m_audioSourceNode(nullptr)
366 #endif 348 #endif
349 , m_autoplayHelper(*this)
367 { 350 {
368 #if ENABLE(OILPAN) 351 #if ENABLE(OILPAN)
369 ThreadState::current()->registerPreFinalizer(this); 352 ThreadState::current()->registerPreFinalizer(this);
370 #endif 353 #endif
371 ASSERT(RuntimeEnabledFeatures::mediaEnabled()); 354 ASSERT(RuntimeEnabledFeatures::mediaEnabled());
372 355
373 WTF_LOG(Media, "HTMLMediaElement::HTMLMediaElement(%p)", this); 356 WTF_LOG(Media, "HTMLMediaElement::HTMLMediaElement(%p)", this);
374 357
375 if (document.settings() && document.settings()->mediaPlaybackRequiresUserGes ture()) 358 if (document.settings() && document.settings()->mediaPlaybackRequiresUserGes ture())
376 m_userGestureRequiredForPlay = true; 359 m_userGestureRequiredForPlay = true;
377 360
378 setHasCustomStyleCallbacks(); 361 setHasCustomStyleCallbacks();
379 addElementToDocumentMap(this, &document); 362 addElementToDocumentMap(this, &document);
380 } 363 }
381 364
382 HTMLMediaElement::~HTMLMediaElement() 365 HTMLMediaElement::~HTMLMediaElement()
383 { 366 {
384 WTF_LOG(Media, "HTMLMediaElement::~HTMLMediaElement(%p)", this); 367 WTF_LOG(Media, "HTMLMediaElement::~HTMLMediaElement(%p)", this);
368
385 #if !ENABLE(OILPAN) 369 #if !ENABLE(OILPAN)
386 // HTMLMediaElement and m_asyncEventQueue always become unreachable 370 // HTMLMediaElement and m_asyncEventQueue always become unreachable
387 // together. So HTMLMediaElement and m_asyncEventQueue are destructed in 371 // together. So HTMLMediaElement and m_asyncEventQueue are destructed in
388 // the same GC. We don't need to close it explicitly in Oilpan. 372 // the same GC. We don't need to close it explicitly in Oilpan.
389 m_asyncEventQueue->close(); 373 m_asyncEventQueue->close();
390 374
391 setShouldDelayLoadEvent(false); 375 setShouldDelayLoadEvent(false);
392 376
393 if (m_textTracks) 377 if (m_textTracks)
394 m_textTracks->clearOwner(); 378 m_textTracks->clearOwner();
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 case WebMimeRegistry::IsSupported: 668 case WebMimeRegistry::IsSupported:
685 canPlay = "probably"; 669 canPlay = "probably";
686 break; 670 break;
687 } 671 }
688 672
689 WTF_LOG(Media, "HTMLMediaElement::canPlayType(%p, %s, %s) -> %s", this, mime Type.utf8().data(), keySystem.utf8().data(), canPlay.utf8().data()); 673 WTF_LOG(Media, "HTMLMediaElement::canPlayType(%p, %s, %s) -> %s", this, mime Type.utf8().data(), keySystem.utf8().data(), canPlay.utf8().data());
690 674
691 return canPlay; 675 return canPlay;
692 } 676 }
693 677
678 void HTMLMediaElement::recordMetricsIfPausing()
679 {
680 // If not playing, then nothing to record.
681 if (!m_playing)
philipj_slow 2015/09/02 09:24:12 Use m_paused here unless there's a reason to use m
liberato (no reviews please) 2015/09/04 06:49:46 i think i used m_paused originally, but switched a
philipj_slow 2015/09/04 08:42:29 OK, whatever you find out please let me know, what
682 return;
683
684 const bool bailout = isBailout();
685
686 // Record that play was paused. We don't care if it was autoplay,
687 // play(), or the user manually started it.
688 recordAutoplayMetric(AnyPlaybackPaused);
689 if (bailout)
690 recordAutoplayMetric(AnyPlaybackBailout);
691
692 // If this was a gestureless play, then record that separately.
693 // These cover attr and play() gestureless starts.
694 if (m_initialPlayWithoutUserGesture) {
695 m_initialPlayWithoutUserGesture = false;
696
697 recordAutoplayMetric(AutoplayPaused);
698
699 if (bailout)
700 recordAutoplayMetric(AutoplayBailout);
701 }
702 }
703
694 void HTMLMediaElement::load() 704 void HTMLMediaElement::load()
695 { 705 {
696 WTF_LOG(Media, "HTMLMediaElement::load(%p)", this); 706 WTF_LOG(Media, "HTMLMediaElement::load(%p)", this);
697 707
698 if (m_initialPlayWithoutUserGestures && m_playing) 708 recordMetricsIfPausing();
699 gesturelessInitialPlayHalted();
700 709
701 if (UserGestureIndicator::processingUserGesture() && m_userGestureRequiredFo rPlay) { 710 if (UserGestureIndicator::processingUserGesture() && m_userGestureRequiredFo rPlay) {
702 recordAutoplayMetric(AutoplayEnabledThroughLoad); 711 recordAutoplayMetric(AutoplayEnabledThroughLoad);
703 m_userGestureRequiredForPlay = false; 712 m_userGestureRequiredForPlay = false;
704 // While usergesture-initiated load()s technically count as autoplayed, 713 // While usergesture-initiated load()s technically count as autoplayed,
705 // they don't feel like such to the users and hence we don't want to 714 // they don't feel like such to the users and hence we don't want to
706 // count them for the purposes of metrics. 715 // count them for the purposes of metrics.
707 m_autoplayMediaCounted = true; 716 m_autoplayMediaCounted = true;
708 } 717 }
709 718
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 shouldUpdateDisplayState = true; 1552 shouldUpdateDisplayState = true;
1544 } 1553 }
1545 1554
1546 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) { 1555 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) {
1547 if (oldState <= HAVE_CURRENT_DATA) { 1556 if (oldState <= HAVE_CURRENT_DATA) {
1548 scheduleEvent(EventTypeNames::canplay); 1557 scheduleEvent(EventTypeNames::canplay);
1549 if (isPotentiallyPlaying) 1558 if (isPotentiallyPlaying)
1550 scheduleEvent(EventTypeNames::playing); 1559 scheduleEvent(EventTypeNames::playing);
1551 } 1560 }
1552 1561
1553 if (m_autoplaying && m_paused && autoplay()) { 1562 if (m_autoplaying && m_paused && autoplay()) {
philipj_slow 2015/09/02 09:24:12 Maybe factor this into a shouldAutoplay() that can
liberato (no reviews please) 2015/09/04 06:49:46 Done.
1554 autoplayMediaEncountered(); 1563 autoplayMediaEncountered();
1555 1564
1556 if (document().isSandboxed(SandboxAutomaticFeatures)) { 1565 if (document().isSandboxed(SandboxAutomaticFeatures)) {
1557 recordAutoplayMetric(AutoplayDisabledBySandbox); 1566 recordAutoplayMetric(AutoplayDisabledBySandbox);
1558 } else if (!m_userGestureRequiredForPlay) { 1567 } else {
1559 m_paused = false; 1568 // If the autoplay experiment says that it's okay to play now,
1560 invalidateCachedTime(); 1569 // then don't require a user gesture.
1561 scheduleEvent(EventTypeNames::play); 1570 m_autoplayHelper.becameReadyToPlay();
1562 scheduleEvent(EventTypeNames::playing); 1571
1572 if (!m_userGestureRequiredForPlay) {
1573 m_paused = false;
1574 invalidateCachedTime();
1575 scheduleEvent(EventTypeNames::play);
1576 scheduleEvent(EventTypeNames::playing);
1577 }
1563 } 1578 }
1564 } 1579 }
1565 1580
1566 scheduleEvent(EventTypeNames::canplaythrough); 1581 scheduleEvent(EventTypeNames::canplaythrough);
1567 1582
1568 shouldUpdateDisplayState = true; 1583 shouldUpdateDisplayState = true;
1569 } 1584 }
1570 1585
1571 if (shouldUpdateDisplayState) { 1586 if (shouldUpdateDisplayState) {
1572 updateDisplayState(); 1587 updateDisplayState();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 1700
1686 m_lastSeekTime = time; 1701 m_lastSeekTime = time;
1687 m_sentEndEvent = false; 1702 m_sentEndEvent = false;
1688 1703
1689 // 10 - Queue a task to fire a simple event named seeking at the element. 1704 // 10 - Queue a task to fire a simple event named seeking at the element.
1690 scheduleEvent(EventTypeNames::seeking); 1705 scheduleEvent(EventTypeNames::seeking);
1691 1706
1692 // 11 - Set the current playback position to the given new playback position . 1707 // 11 - Set the current playback position to the given new playback position .
1693 webMediaPlayer()->seek(time); 1708 webMediaPlayer()->seek(time);
1694 1709
1695 m_initialPlayWithoutUserGestures = false; 1710 m_initialPlayWithoutUserGesture = false;
1696 1711
1697 // 14-17 are handled, if necessary, when the engine signals a readystate cha nge or otherwise 1712 // 14-17 are handled, if necessary, when the engine signals a readystate cha nge or otherwise
1698 // satisfies seek completion and signals a time change. 1713 // satisfies seek completion and signals a time change.
1699 } 1714 }
1700 1715
1701 void HTMLMediaElement::finishSeek() 1716 void HTMLMediaElement::finishSeek()
1702 { 1717 {
1703 WTF_LOG(Media, "HTMLMediaElement::finishSeek(%p)", this); 1718 WTF_LOG(Media, "HTMLMediaElement::finishSeek(%p)", this);
1704 1719
1705 // 14 - Set the seeking IDL attribute to false. 1720 // 14 - Set the seeking IDL attribute to false.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 1950
1936 WebMediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const 1951 WebMediaPlayer::Preload HTMLMediaElement::effectivePreloadType() const
1937 { 1952 {
1938 return autoplay() ? WebMediaPlayer::PreloadAuto : preloadType(); 1953 return autoplay() ? WebMediaPlayer::PreloadAuto : preloadType();
1939 } 1954 }
1940 1955
1941 void HTMLMediaElement::play() 1956 void HTMLMediaElement::play()
1942 { 1957 {
1943 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this); 1958 WTF_LOG(Media, "HTMLMediaElement::play(%p)", this);
1944 1959
1960 m_autoplayHelper.playMethodCalled();
1961
1945 if (!UserGestureIndicator::processingUserGesture()) { 1962 if (!UserGestureIndicator::processingUserGesture()) {
1946 autoplayMediaEncountered(); 1963 autoplayMediaEncountered();
1964
1947 if (m_userGestureRequiredForPlay) { 1965 if (m_userGestureRequiredForPlay) {
1966 recordAutoplayMetric(PlayMethodFailed);
1948 String message = ExceptionMessages::failedToExecute("play", "HTMLMed iaElement", "API can only be initiated by a user gesture."); 1967 String message = ExceptionMessages::failedToExecute("play", "HTMLMed iaElement", "API can only be initiated by a user gesture.");
1949 document().executionContext()->addConsoleMessage(ConsoleMessage::cre ate(JSMessageSource, WarningMessageLevel, message)); 1968 document().executionContext()->addConsoleMessage(ConsoleMessage::cre ate(JSMessageSource, WarningMessageLevel, message));
1950 return; 1969 return;
1951 } 1970 }
1952 } else if (m_userGestureRequiredForPlay) { 1971 } else if (m_userGestureRequiredForPlay) {
1953 if (m_autoplayMediaCounted) 1972 if (m_autoplayMediaCounted)
1954 recordAutoplayMetric(AutoplayManualStart); 1973 recordAutoplayMetric(AutoplayManualStart);
1955 m_userGestureRequiredForPlay = false; 1974 m_userGestureRequiredForPlay = false;
1956 } 1975 }
1957 1976
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 updateMediaController(); 2010 updateMediaController();
1992 } 2011 }
1993 2012
1994 void HTMLMediaElement::autoplayMediaEncountered() 2013 void HTMLMediaElement::autoplayMediaEncountered()
1995 { 2014 {
1996 if (!m_autoplayMediaCounted) { 2015 if (!m_autoplayMediaCounted) {
1997 m_autoplayMediaCounted = true; 2016 m_autoplayMediaCounted = true;
1998 recordAutoplayMetric(AutoplayMediaFound); 2017 recordAutoplayMetric(AutoplayMediaFound);
1999 2018
2000 if (!m_userGestureRequiredForPlay) 2019 if (!m_userGestureRequiredForPlay)
2001 m_initialPlayWithoutUserGestures = true; 2020 m_initialPlayWithoutUserGesture = true;
2002 } 2021 }
2003 } 2022 }
2004 2023
2005 void HTMLMediaElement::gesturelessInitialPlayHalted() 2024 bool HTMLMediaElement::isBailout() const
2006 { 2025 {
2007 ASSERT(m_initialPlayWithoutUserGestures);
2008 m_initialPlayWithoutUserGestures = false;
2009
2010 recordAutoplayMetric(AutoplayStopped);
2011
2012 // We count the user as having bailed-out on the video if they watched 2026 // We count the user as having bailed-out on the video if they watched
2013 // less than one minute and less than 50% of it. 2027 // less than one minute and less than 50% of it.
2014 double playedTime = currentTime(); 2028 const double playedTime = currentTime();
2015 if (playedTime < 60) { 2029 const double progress = playedTime / duration();
2016 double progress = playedTime / duration(); 2030 return (playedTime < 60) && (progress < 0.5);
2017 if (progress < 0.5)
2018 recordAutoplayMetric(AutoplayBailout);
2019 }
2020 } 2031 }
2021 2032
2022 void HTMLMediaElement::pause() 2033 void HTMLMediaElement::pause()
2023 { 2034 {
2024 WTF_LOG(Media, "HTMLMediaElement::pause(%p)", this); 2035 WTF_LOG(Media, "HTMLMediaElement::pause(%p)", this);
2025 2036
2026 if (m_networkState == NETWORK_EMPTY) 2037 if (m_networkState == NETWORK_EMPTY)
2027 scheduleDelayedAction(LoadMediaResource); 2038 scheduleDelayedAction(LoadMediaResource);
2028 2039
2040 m_autoplayHelper.pauseMethodCalled();
2041
2029 m_autoplaying = false; 2042 m_autoplaying = false;
2030 2043
2031 if (!m_paused) { 2044 if (!m_paused) {
2032 if (m_initialPlayWithoutUserGestures) 2045 recordMetricsIfPausing();
2033 gesturelessInitialPlayHalted();
2034 2046
2035 m_paused = true; 2047 m_paused = true;
2036 scheduleTimeupdateEvent(false); 2048 scheduleTimeupdateEvent(false);
2037 scheduleEvent(EventTypeNames::pause); 2049 scheduleEvent(EventTypeNames::pause);
2038 } 2050 }
2039 2051
2040 updatePlayState(); 2052 updatePlayState();
2041 } 2053 }
2042 2054
2043 void HTMLMediaElement::requestRemotePlayback() 2055 void HTMLMediaElement::requestRemotePlayback()
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 2128
2117 void HTMLMediaElement::setMuted(bool muted) 2129 void HTMLMediaElement::setMuted(bool muted)
2118 { 2130 {
2119 WTF_LOG(Media, "HTMLMediaElement::setMuted(%p, %s)", this, boolString(muted) ); 2131 WTF_LOG(Media, "HTMLMediaElement::setMuted(%p, %s)", this, boolString(muted) );
2120 2132
2121 if (m_muted == muted) 2133 if (m_muted == muted)
2122 return; 2134 return;
2123 2135
2124 m_muted = muted; 2136 m_muted = muted;
2125 2137
2138 m_autoplayHelper.mutedChanged();
2139
2126 updateVolume(); 2140 updateVolume();
2127 2141
2128 scheduleEvent(EventTypeNames::volumechange); 2142 scheduleEvent(EventTypeNames::volumechange);
2129 } 2143 }
2130 2144
2131 void HTMLMediaElement::updateVolume() 2145 void HTMLMediaElement::updateVolume()
2132 { 2146 {
2133 if (webMediaPlayer()) 2147 if (webMediaPlayer())
2134 webMediaPlayer()->setVolume(effectiveMediaVolume()); 2148 webMediaPlayer()->setVolume(effectiveMediaVolume());
2135 2149
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
2747 if (!m_mediaController && !m_paused) { 2761 if (!m_mediaController && !m_paused) {
2748 // changes paused to true and fires a simple event named pause a t the media element. 2762 // changes paused to true and fires a simple event named pause a t the media element.
2749 m_paused = true; 2763 m_paused = true;
2750 scheduleEvent(EventTypeNames::pause); 2764 scheduleEvent(EventTypeNames::pause);
2751 } 2765 }
2752 // Queue a task to fire a simple event named ended at the media elem ent. 2766 // Queue a task to fire a simple event named ended at the media elem ent.
2753 if (!m_sentEndEvent) { 2767 if (!m_sentEndEvent) {
2754 m_sentEndEvent = true; 2768 m_sentEndEvent = true;
2755 scheduleEvent(EventTypeNames::ended); 2769 scheduleEvent(EventTypeNames::ended);
2756 } 2770 }
2771 recordMetricsIfPausing();
2757 // If the media element has a current media controller, then report the controller state 2772 // If the media element has a current media controller, then report the controller state
2758 // for the media element's current media controller. 2773 // for the media element's current media controller.
2759 updateMediaController(); 2774 updateMediaController();
2760 } 2775 }
2761 } else { 2776 } else {
2762 m_sentEndEvent = false; 2777 m_sentEndEvent = false;
2763 } 2778 }
2764 2779
2765 updatePlayState(); 2780 updatePlayState();
2766 } 2781 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2967 // The media engine should just stash the rate and muted values sinc e it isn't already playing. 2982 // The media engine should just stash the rate and muted values sinc e it isn't already playing.
2968 webMediaPlayer()->setRate(effectivePlaybackRate()); 2983 webMediaPlayer()->setRate(effectivePlaybackRate());
2969 updateVolume(); 2984 updateVolume();
2970 webMediaPlayer()->play(); 2985 webMediaPlayer()->play();
2971 } 2986 }
2972 2987
2973 if (mediaControls()) 2988 if (mediaControls())
2974 mediaControls()->playbackStarted(); 2989 mediaControls()->playbackStarted();
2975 startPlaybackProgressTimer(); 2990 startPlaybackProgressTimer();
2976 m_playing = true; 2991 m_playing = true;
2992 recordAutoplayMetric(AnyPlaybackStarted);
2977 2993
2978 } else { // Should not be playing right now 2994 } else { // Should not be playing right now
2979 if (isPlaying) 2995 if (isPlaying)
2980 webMediaPlayer()->pause(); 2996 webMediaPlayer()->pause();
2981 refreshCachedTime(); 2997 refreshCachedTime();
2982 2998
2983 m_playbackProgressTimer.stop(); 2999 m_playbackProgressTimer.stop();
2984 m_playing = false; 3000 m_playing = false;
2985 double time = currentTime(); 3001 double time = currentTime();
2986 if (time > m_lastSeekTime) 3002 if (time > m_lastSeekTime)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3086 mediaControls()->refreshCastButtonVisibilityWithoutUpdate(); 3102 mediaControls()->refreshCastButtonVisibilityWithoutUpdate();
3087 3103
3088 if (layoutObject()) 3104 if (layoutObject())
3089 layoutObject()->setShouldDoFullPaintInvalidation(); 3105 layoutObject()->setShouldDoFullPaintInvalidation();
3090 } 3106 }
3091 3107
3092 void HTMLMediaElement::stop() 3108 void HTMLMediaElement::stop()
3093 { 3109 {
3094 WTF_LOG(Media, "HTMLMediaElement::stop(%p)", this); 3110 WTF_LOG(Media, "HTMLMediaElement::stop(%p)", this);
3095 3111
3096 if (m_playing && m_initialPlayWithoutUserGestures) 3112 recordMetricsIfPausing();
3097 gesturelessInitialPlayHalted();
3098 3113
3099 // Close the async event queue so that no events are enqueued by userCancell edLoad. 3114 // Close the async event queue so that no events are enqueued by userCancell edLoad.
3100 cancelPendingEventsAndCallbacks(); 3115 cancelPendingEventsAndCallbacks();
3101 m_asyncEventQueue->close(); 3116 m_asyncEventQueue->close();
3102 3117
3103 userCancelledLoad(); 3118 userCancelledLoad();
3104 3119
3105 // Stop the playback without generating events 3120 // Stop the playback without generating events
3106 m_playing = false; 3121 m_playing = false;
3107 m_paused = true; 3122 m_paused = true;
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
3701 3716
3702 // Enable the first audio track if an audio track hasn't been enabled yet. 3717 // Enable the first audio track if an audio track hasn't been enabled yet.
3703 if (audioTracks().length() > 0 && !audioTracks().hasEnabledTrack()) 3718 if (audioTracks().length() > 0 && !audioTracks().hasEnabledTrack())
3704 audioTracks().anonymousIndexedGetter(0)->setEnabled(true); 3719 audioTracks().anonymousIndexedGetter(0)->setEnabled(true);
3705 3720
3706 // Select the first video track if a video track hasn't been selected yet. 3721 // Select the first video track if a video track hasn't been selected yet.
3707 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1) 3722 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1)
3708 videoTracks().anonymousIndexedGetter(0)->setSelected(true); 3723 videoTracks().anonymousIndexedGetter(0)->setSelected(true);
3709 } 3724 }
3710 3725
3726 bool HTMLMediaElement::isUserGestureRequiredForPlay() const
3727 {
3728 return m_userGestureRequiredForPlay;
3729 }
3730
3731 void HTMLMediaElement::removeUserGestureRequirement()
3732 {
3733 m_userGestureRequiredForPlay = false;
3734 }
3735
3736 void HTMLMediaElement::setInitialPlayWithoutUserGestures(bool value)
3737 {
3738 m_initialPlayWithoutUserGesture = value;
3739 }
3740
3741 void HTMLMediaElement::notifyPositionMayHaveChanged()
3742 {
3743 m_autoplayHelper.positionChanged();
3744 }
3745
3746 void HTMLMediaElement::triggerAutoplayViewportCheck()
3747 {
3748 m_autoplayHelper.triggerAutoplayViewportCheck();
3749 }
3750
3711 #if ENABLE(WEB_AUDIO) 3751 #if ENABLE(WEB_AUDIO)
3712 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3752 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3713 { 3753 {
3714 if (!Heap::isHeapObjectAlive(m_audioSourceNode)) 3754 if (!Heap::isHeapObjectAlive(m_audioSourceNode))
3715 audioSourceProvider().setClient(nullptr); 3755 audioSourceProvider().setClient(nullptr);
3716 } 3756 }
3717 3757
3718 void HTMLMediaElement::AudioSourceProviderImpl::wrap(WebAudioSourceProvider* pro vider) 3758 void HTMLMediaElement::AudioSourceProviderImpl::wrap(WebAudioSourceProvider* pro vider)
3719 { 3759 {
3720 MutexLocker locker(provideInputLock); 3760 MutexLocker locker(provideInputLock);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3770 visitor->trace(m_client); 3810 visitor->trace(m_client);
3771 } 3811 }
3772 3812
3773 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) 3813 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl)
3774 { 3814 {
3775 visitor->trace(m_client); 3815 visitor->trace(m_client);
3776 } 3816 }
3777 #endif 3817 #endif
3778 3818
3779 } 3819 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698