OLD | NEW |
---|---|
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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 , m_initialPlayWithoutUserGesture(false) | 340 , m_initialPlayWithoutUserGesture(false) |
341 , m_autoplayMediaCounted(false) | 341 , m_autoplayMediaCounted(false) |
342 , m_inOverlayFullscreenVideo(false) | 342 , m_inOverlayFullscreenVideo(false) |
343 , m_audioTracks(AudioTrackList::create(*this)) | 343 , m_audioTracks(AudioTrackList::create(*this)) |
344 , m_videoTracks(VideoTrackList::create(*this)) | 344 , m_videoTracks(VideoTrackList::create(*this)) |
345 , m_textTracks(nullptr) | 345 , m_textTracks(nullptr) |
346 #if ENABLE(WEB_AUDIO) | 346 #if ENABLE(WEB_AUDIO) |
347 , m_audioSourceNode(nullptr) | 347 , m_audioSourceNode(nullptr) |
348 #endif | 348 #endif |
349 , m_autoplayHelper(*this) | 349 , m_autoplayHelper(*this) |
350 , m_autoplayDeferredMetric(GesturelessPlaybackUnknownReason) | |
351 , m_recordedElement(false) | |
350 { | 352 { |
351 #if ENABLE(OILPAN) | 353 #if ENABLE(OILPAN) |
352 ThreadState::current()->registerPreFinalizer(this); | 354 ThreadState::current()->registerPreFinalizer(this); |
353 #endif | 355 #endif |
354 ASSERT(RuntimeEnabledFeatures::mediaEnabled()); | 356 ASSERT(RuntimeEnabledFeatures::mediaEnabled()); |
355 | 357 |
356 WTF_LOG(Media, "HTMLMediaElement::HTMLMediaElement(%p)", this); | 358 WTF_LOG(Media, "HTMLMediaElement::HTMLMediaElement(%p)", this); |
357 | 359 |
358 if (document.settings() && document.settings()->mediaPlaybackRequiresUserGes ture()) | 360 if (document.settings() && document.settings()->mediaPlaybackRequiresUserGes ture()) |
359 m_userGestureRequiredForPlay = true; | 361 m_userGestureRequiredForPlay = true; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 case WebMimeRegistry::IsSupported: | 664 case WebMimeRegistry::IsSupported: |
663 canPlay = "probably"; | 665 canPlay = "probably"; |
664 break; | 666 break; |
665 } | 667 } |
666 | 668 |
667 WTF_LOG(Media, "HTMLMediaElement::canPlayType(%p, %s, %s) -> %s", this, mime Type.utf8().data(), keySystem.utf8().data(), canPlay.utf8().data()); | 669 WTF_LOG(Media, "HTMLMediaElement::canPlayType(%p, %s, %s) -> %s", this, mime Type.utf8().data(), keySystem.utf8().data(), canPlay.utf8().data()); |
668 | 670 |
669 return canPlay; | 671 return canPlay; |
670 } | 672 } |
671 | 673 |
672 void HTMLMediaElement::recordMetricsIfPausing() | 674 void HTMLMediaElement::recordMetricsBeforePause() |
673 { | 675 { |
674 // If not playing, then nothing to record. | 676 ASSERT(!m_paused); |
675 // TODO(liberato): test metrics. this was m_paused. | |
676 if (m_paused) | |
677 return; | |
678 | 677 |
679 const bool bailout = isBailout(); | 678 const bool bailout = isBailout(); |
680 | 679 |
681 // Record that play was paused. We don't care if it was autoplay, | 680 // Record that play was paused. We don't care if it was autoplay, |
682 // play(), or the user manually started it. | 681 // play(), or the user manually started it. |
683 recordAutoplayMetric(AnyPlaybackPaused); | 682 recordAutoplayMetric(AnyPlaybackPaused); |
684 if (bailout) | 683 if (bailout) |
685 recordAutoplayMetric(AnyPlaybackBailout); | 684 recordAutoplayMetric(AnyPlaybackBailout); |
686 | 685 |
687 // If this was a gestureless play, then record that separately. | 686 // If this was a gestureless play, then record that separately. |
688 // These cover attr and play() gestureless starts. | 687 // These cover attr and play() gestureless starts. |
689 if (m_initialPlayWithoutUserGesture) { | 688 if (m_initialPlayWithoutUserGesture) { |
690 m_initialPlayWithoutUserGesture = false; | 689 m_initialPlayWithoutUserGesture = false; |
691 | 690 |
692 recordAutoplayMetric(AutoplayPaused); | 691 recordAutoplayMetric(AutoplayPaused); |
693 | 692 |
694 if (bailout) | 693 if (bailout) |
695 recordAutoplayMetric(AutoplayBailout); | 694 recordAutoplayMetric(AutoplayBailout); |
696 } | 695 } |
697 } | 696 } |
698 | 697 |
698 void HTMLMediaElement::recordMetricsAtPlaybackEnd() | |
699 { | |
700 recordAutoplayMetric(AnyPlaybackComplete); | |
701 if (m_initialPlayWithoutUserGesture) { | |
702 m_initialPlayWithoutUserGesture = false; | |
703 recordAutoplayMetric(AutoplayComplete); | |
704 } | |
705 } | |
706 | |
699 void HTMLMediaElement::load() | 707 void HTMLMediaElement::load() |
700 { | 708 { |
701 WTF_LOG(Media, "HTMLMediaElement::load(%p)", this); | 709 WTF_LOG(Media, "HTMLMediaElement::load(%p)", this); |
702 | 710 |
703 recordMetricsIfPausing(); | 711 if (!m_paused) |
712 recordMetricsBeforePause(); | |
704 | 713 |
705 if (UserGestureIndicator::processingUserGesture() && m_userGestureRequiredFo rPlay) { | 714 if (UserGestureIndicator::processingUserGesture() && m_userGestureRequiredFo rPlay) { |
706 recordAutoplayMetric(AutoplayEnabledThroughLoad); | 715 recordAutoplayMetric(AutoplayEnabledThroughLoad); |
707 m_userGestureRequiredForPlay = false; | 716 removeUserGestureRequirement(GesturelessPlaybackEnabledByLoad); |
708 // While usergesture-initiated load()s technically count as autoplayed, | 717 // While usergesture-initiated load()s technically count as autoplayed, |
709 // they don't feel like such to the users and hence we don't want to | 718 // they don't feel like such to the users and hence we don't want to |
710 // count them for the purposes of metrics. | 719 // count them for the purposes of metrics. |
711 m_autoplayMediaCounted = true; | 720 m_autoplayMediaCounted = true; |
712 } | 721 } |
713 | 722 |
714 prepareForLoad(); | 723 prepareForLoad(); |
715 loadInternal(); | 724 loadInternal(); |
716 prepareToPlay(); | 725 prepareToPlay(); |
717 } | 726 } |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 if (fastHasAttribute(mutedAttr)) | 963 if (fastHasAttribute(mutedAttr)) |
955 m_muted = true; | 964 m_muted = true; |
956 updateVolume(); | 965 updateVolume(); |
957 | 966 |
958 ASSERT(!m_mediaSource); | 967 ASSERT(!m_mediaSource); |
959 | 968 |
960 bool attemptLoad = true; | 969 bool attemptLoad = true; |
961 | 970 |
962 if (url.protocolIs(mediaSourceBlobProtocol)) { | 971 if (url.protocolIs(mediaSourceBlobProtocol)) { |
963 if (isMediaStreamURL(url.string())) { | 972 if (isMediaStreamURL(url.string())) { |
964 m_userGestureRequiredForPlay = false; | 973 m_userGestureRequiredForPlay = false; |
philipj_slow
2015/11/26 15:30:56
Drop this line, it looks like it would make remove
liberato (no reviews please)
2015/12/02 00:58:08
Done.
| |
974 removeUserGestureRequirement(GesturelessPlaybackEnabledByStream); | |
965 } else { | 975 } else { |
966 m_mediaSource = HTMLMediaSource::lookup(url.string()); | 976 m_mediaSource = HTMLMediaSource::lookup(url.string()); |
967 | 977 |
968 if (m_mediaSource) { | 978 if (m_mediaSource) { |
969 if (!m_mediaSource->attachToElement(this)) { | 979 if (!m_mediaSource->attachToElement(this)) { |
970 // Forget our reference to the MediaSource, so we leave it a lone | 980 // Forget our reference to the MediaSource, so we leave it a lone |
971 // while processing remainder of load failure. | 981 // while processing remainder of load failure. |
972 m_mediaSource = nullptr; | 982 m_mediaSource = nullptr; |
973 attemptLoad = false; | 983 attemptLoad = false; |
974 } | 984 } |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1526 if (m_readyState >= HAVE_CURRENT_DATA && oldState < HAVE_CURRENT_DATA && !m_ haveFiredLoadedData) { | 1536 if (m_readyState >= HAVE_CURRENT_DATA && oldState < HAVE_CURRENT_DATA && !m_ haveFiredLoadedData) { |
1527 m_haveFiredLoadedData = true; | 1537 m_haveFiredLoadedData = true; |
1528 shouldUpdateDisplayState = true; | 1538 shouldUpdateDisplayState = true; |
1529 scheduleEvent(EventTypeNames::loadeddata); | 1539 scheduleEvent(EventTypeNames::loadeddata); |
1530 setShouldDelayLoadEvent(false); | 1540 setShouldDelayLoadEvent(false); |
1531 } | 1541 } |
1532 | 1542 |
1533 bool isPotentiallyPlaying = potentiallyPlaying(); | 1543 bool isPotentiallyPlaying = potentiallyPlaying(); |
1534 if (m_readyState == HAVE_FUTURE_DATA && oldState <= HAVE_CURRENT_DATA && tra cksAreReady) { | 1544 if (m_readyState == HAVE_FUTURE_DATA && oldState <= HAVE_CURRENT_DATA && tra cksAreReady) { |
1535 scheduleEvent(EventTypeNames::canplay); | 1545 scheduleEvent(EventTypeNames::canplay); |
1536 if (isPotentiallyPlaying) | 1546 if (isPotentiallyPlaying) { |
1537 scheduleEvent(EventTypeNames::playing); | 1547 scheduleEvent(EventTypeNames::playing); |
1548 } | |
1538 shouldUpdateDisplayState = true; | 1549 shouldUpdateDisplayState = true; |
1539 } | 1550 } |
1540 | 1551 |
1541 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) { | 1552 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) { |
1542 if (oldState <= HAVE_CURRENT_DATA) { | 1553 if (oldState <= HAVE_CURRENT_DATA) { |
1543 scheduleEvent(EventTypeNames::canplay); | 1554 scheduleEvent(EventTypeNames::canplay); |
1544 if (isPotentiallyPlaying) | 1555 if (isPotentiallyPlaying) { |
1545 scheduleEvent(EventTypeNames::playing); | 1556 scheduleEvent(EventTypeNames::playing); |
1557 } | |
1546 } | 1558 } |
1547 | 1559 |
1548 // Check for autoplay, and record metrics about it if needed. | 1560 // Check for autoplay, and record metrics about it if needed. |
1549 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { | 1561 if (shouldAutoplay(RecordMetricsBehavior::RecordOnSandboxFailure)) { |
1550 // If the autoplay experiment says that it's okay to play now, | 1562 // If the autoplay experiment says that it's okay to play now, |
1551 // then don't require a user gesture. | 1563 // then don't require a user gesture. |
1552 m_autoplayHelper.becameReadyToPlay(); | 1564 m_autoplayHelper.becameReadyToPlay(); |
1553 | 1565 |
1566 // Record that we have encounted autoplay media. We do this | |
1567 // now, after the experiment has had a chance to override the | |
1568 // user gesture requirement, since it assumes that the media | |
1569 // will play if and only if a user gesture is not required. | |
1570 autoplayMediaEncountered(); | |
1571 | |
1554 if (!m_userGestureRequiredForPlay) { | 1572 if (!m_userGestureRequiredForPlay) { |
1555 m_paused = false; | 1573 m_paused = false; |
1556 invalidateCachedTime(); | 1574 invalidateCachedTime(); |
1557 scheduleEvent(EventTypeNames::play); | 1575 scheduleEvent(EventTypeNames::play); |
1558 scheduleEvent(EventTypeNames::playing); | 1576 scheduleEvent(EventTypeNames::playing); |
1559 } | 1577 } |
1560 } | 1578 } |
1561 | 1579 |
1562 scheduleEvent(EventTypeNames::canplaythrough); | 1580 scheduleEvent(EventTypeNames::canplaythrough); |
1563 | 1581 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1863 } | 1881 } |
1864 | 1882 |
1865 bool HTMLMediaElement::autoplay() const | 1883 bool HTMLMediaElement::autoplay() const |
1866 { | 1884 { |
1867 return fastHasAttribute(autoplayAttr); | 1885 return fastHasAttribute(autoplayAttr); |
1868 } | 1886 } |
1869 | 1887 |
1870 bool HTMLMediaElement::shouldAutoplay(const RecordMetricsBehavior recordMetrics) | 1888 bool HTMLMediaElement::shouldAutoplay(const RecordMetricsBehavior recordMetrics) |
1871 { | 1889 { |
1872 if (m_autoplaying && m_paused && autoplay()) { | 1890 if (m_autoplaying && m_paused && autoplay()) { |
1873 if (recordMetrics == RecordMetricsBehavior::DoRecord) | |
1874 autoplayMediaEncountered(); | |
1875 | |
1876 if (document().isSandboxed(SandboxAutomaticFeatures)) { | 1891 if (document().isSandboxed(SandboxAutomaticFeatures)) { |
1877 if (recordMetrics == RecordMetricsBehavior::DoRecord) | 1892 if (recordMetrics == RecordMetricsBehavior::RecordOnSandboxFailure) { |
1893 // We record autoplayMediaEncountered here because we know | |
1894 // that the autoplay attempt will fail. | |
1895 autoplayMediaEncountered(); | |
1878 recordAutoplayMetric(AutoplayDisabledBySandbox); | 1896 recordAutoplayMetric(AutoplayDisabledBySandbox); |
1897 } | |
1879 return false; | 1898 return false; |
1880 } | 1899 } |
1881 | 1900 |
1882 return true; | 1901 return true; |
1883 } | 1902 } |
1884 | 1903 |
1885 return false; | 1904 return false; |
1886 } | 1905 } |
1887 | 1906 |
1888 String HTMLMediaElement::preload() const | 1907 String HTMLMediaElement::preload() const |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1957 | 1976 |
1958 if (m_userGestureRequiredForPlay) { | 1977 if (m_userGestureRequiredForPlay) { |
1959 recordAutoplayMetric(PlayMethodFailed); | 1978 recordAutoplayMetric(PlayMethodFailed); |
1960 String message = ExceptionMessages::failedToExecute("play", "HTMLMed iaElement", "API can only be initiated by a user gesture."); | 1979 String message = ExceptionMessages::failedToExecute("play", "HTMLMed iaElement", "API can only be initiated by a user gesture."); |
1961 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); | 1980 document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); |
1962 return; | 1981 return; |
1963 } | 1982 } |
1964 } else if (m_userGestureRequiredForPlay) { | 1983 } else if (m_userGestureRequiredForPlay) { |
1965 if (m_autoplayMediaCounted) | 1984 if (m_autoplayMediaCounted) |
1966 recordAutoplayMetric(AutoplayManualStart); | 1985 recordAutoplayMetric(AutoplayManualStart); |
1986 // Don't let future gestureless playbacks affect metrics. This is | |
1987 // also why we don't have to go through removeUserGestureRequirement. | |
1988 m_autoplayMediaCounted = true; | |
1989 | |
1967 m_userGestureRequiredForPlay = false; | 1990 m_userGestureRequiredForPlay = false; |
philipj_slow
2015/11/26 15:30:56
Call recordAutoplayMetric(GesturelessPlaybackEnabl
liberato (no reviews please)
2015/12/02 00:58:09
updated to removeUserGestureRequirement. if gestu
| |
1968 } | 1991 } |
1969 | 1992 |
1970 playInternal(); | 1993 playInternal(); |
1971 } | 1994 } |
1972 | 1995 |
1973 void HTMLMediaElement::playInternal() | 1996 void HTMLMediaElement::playInternal() |
1974 { | 1997 { |
1975 WTF_LOG(Media, "HTMLMediaElement::playInternal(%p)", this); | 1998 WTF_LOG(Media, "HTMLMediaElement::playInternal(%p)", this); |
1976 | 1999 |
1977 // 4.8.10.9. Playing the media resource | 2000 // 4.8.10.9. Playing the media resource |
1978 if (m_networkState == NETWORK_EMPTY) | 2001 if (m_networkState == NETWORK_EMPTY) |
1979 scheduleDelayedAction(LoadMediaResource); | 2002 scheduleDelayedAction(LoadMediaResource); |
1980 | 2003 |
1981 // Generally "ended" and "looping" are exclusive. Here, the loop attribute | 2004 // Generally "ended" and "looping" are exclusive. Here, the loop attribute |
1982 // is ignored to seek back to start in case loop was set after playback | 2005 // is ignored to seek back to start in case loop was set after playback |
1983 // ended. See http://crbug.com/364442 | 2006 // ended. See http://crbug.com/364442 |
1984 if (endedPlayback(LoopCondition::Ignored)) | 2007 if (endedPlayback(LoopCondition::Ignored)) |
1985 seek(0); | 2008 seek(0); |
1986 | 2009 |
1987 if (m_paused) { | 2010 if (m_paused) { |
1988 m_paused = false; | 2011 m_paused = false; |
1989 invalidateCachedTime(); | 2012 invalidateCachedTime(); |
1990 scheduleEvent(EventTypeNames::play); | 2013 scheduleEvent(EventTypeNames::play); |
1991 | 2014 |
1992 if (m_readyState <= HAVE_CURRENT_DATA) | 2015 if (m_readyState <= HAVE_CURRENT_DATA) { |
philipj_slow
2015/11/26 15:30:56
Drop the added braces here and elsewhere: git chec
liberato (no reviews please)
2015/12/02 00:58:08
Done.
| |
1993 scheduleEvent(EventTypeNames::waiting); | 2016 scheduleEvent(EventTypeNames::waiting); |
1994 else if (m_readyState >= HAVE_FUTURE_DATA) | 2017 } else if (m_readyState >= HAVE_FUTURE_DATA) { |
1995 scheduleEvent(EventTypeNames::playing); | 2018 scheduleEvent(EventTypeNames::playing); |
2019 } | |
1996 } | 2020 } |
1997 m_autoplaying = false; | |
1998 | 2021 |
1999 updatePlayState(); | 2022 updatePlayState(); |
2000 } | 2023 } |
2001 | 2024 |
2002 void HTMLMediaElement::autoplayMediaEncountered() | 2025 void HTMLMediaElement::autoplayMediaEncountered() |
2003 { | 2026 { |
2004 if (!m_autoplayMediaCounted) { | 2027 if (!m_autoplayMediaCounted) { |
2005 m_autoplayMediaCounted = true; | 2028 m_autoplayMediaCounted = true; |
2006 recordAutoplayMetric(AutoplayMediaFound); | 2029 recordAutoplayMetric(AutoplayMediaFound); |
2007 | 2030 |
2008 if (!m_userGestureRequiredForPlay) | 2031 // If no user gesture was required, then assume that playback will |
2032 // actually start. | |
2033 if (!m_userGestureRequiredForPlay) { | |
2009 m_initialPlayWithoutUserGesture = true; | 2034 m_initialPlayWithoutUserGesture = true; |
2035 recordAutoplayMetric(m_autoplayDeferredMetric); | |
philipj_slow
2015/11/26 15:30:56
I'm still finding this a bit hard to follow. In ge
liberato (no reviews please)
2015/12/02 00:58:08
oh, i didn't realize that you were suggesting to r
| |
2036 } | |
2010 } | 2037 } |
2011 } | 2038 } |
2012 | 2039 |
2013 bool HTMLMediaElement::isBailout() const | 2040 bool HTMLMediaElement::isBailout() const |
2014 { | 2041 { |
2015 // We count the user as having bailed-out on the video if they watched | 2042 // We count the user as having bailed-out on the video if they watched |
2016 // less than one minute and less than 50% of it. | 2043 // less than one minute and less than 50% of it. |
2017 const double playedTime = currentTime(); | 2044 const double playedTime = currentTime(); |
2018 const double progress = playedTime / duration(); | 2045 const double progress = playedTime / duration(); |
2019 return (playedTime < 60) && (progress < 0.5); | 2046 return (playedTime < 60) && (progress < 0.5); |
2020 } | 2047 } |
2021 | 2048 |
2022 void HTMLMediaElement::pause() | 2049 void HTMLMediaElement::pause() |
2023 { | 2050 { |
2024 WTF_LOG(Media, "HTMLMediaElement::pause(%p)", this); | 2051 WTF_LOG(Media, "HTMLMediaElement::pause(%p)", this); |
2025 | 2052 |
2026 if (m_networkState == NETWORK_EMPTY) | 2053 if (m_networkState == NETWORK_EMPTY) |
2027 scheduleDelayedAction(LoadMediaResource); | 2054 scheduleDelayedAction(LoadMediaResource); |
2028 | 2055 |
2029 m_autoplayHelper.pauseMethodCalled(); | 2056 m_autoplayHelper.pauseMethodCalled(); |
2030 | 2057 |
2031 m_autoplaying = false; | 2058 m_autoplaying = false; |
2032 | 2059 |
2033 if (!m_paused) { | 2060 if (!m_paused) { |
2034 recordMetricsIfPausing(); | 2061 recordMetricsBeforePause(); |
2035 | 2062 |
2036 m_paused = true; | 2063 m_paused = true; |
2037 scheduleTimeupdateEvent(false); | 2064 scheduleTimeupdateEvent(false); |
2038 scheduleEvent(EventTypeNames::pause); | 2065 scheduleEvent(EventTypeNames::pause); |
2039 } | 2066 } |
2040 | 2067 |
2041 updatePlayState(); | 2068 updatePlayState(); |
2042 } | 2069 } |
2043 | 2070 |
2044 void HTMLMediaElement::requestRemotePlayback() | 2071 void HTMLMediaElement::requestRemotePlayback() |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2717 // If the media element has a loop attribute specified | 2744 // If the media element has a loop attribute specified |
2718 if (loop()) { | 2745 if (loop()) { |
2719 m_sentEndEvent = false; | 2746 m_sentEndEvent = false; |
2720 // then seek to the earliest possible position of the media resourc e and abort these steps. | 2747 // then seek to the earliest possible position of the media resourc e and abort these steps. |
2721 seek(0); | 2748 seek(0); |
2722 } else { | 2749 } else { |
2723 // If the media element has still ended playback, and the direction of playback is still | 2750 // If the media element has still ended playback, and the direction of playback is still |
2724 // forwards, and paused is false, | 2751 // forwards, and paused is false, |
2725 if (!m_paused) { | 2752 if (!m_paused) { |
2726 // changes paused to true and fires a simple event named pause a t the media element. | 2753 // changes paused to true and fires a simple event named pause a t the media element. |
2754 recordMetricsAtPlaybackEnd(); | |
2727 m_paused = true; | 2755 m_paused = true; |
2728 scheduleEvent(EventTypeNames::pause); | 2756 scheduleEvent(EventTypeNames::pause); |
2729 } | 2757 } |
2730 // Queue a task to fire a simple event named ended at the media elem ent. | 2758 // Queue a task to fire a simple event named ended at the media elem ent. |
2731 if (!m_sentEndEvent) { | 2759 if (!m_sentEndEvent) { |
2732 m_sentEndEvent = true; | 2760 m_sentEndEvent = true; |
2733 scheduleEvent(EventTypeNames::ended); | 2761 scheduleEvent(EventTypeNames::ended); |
2734 } | 2762 } |
2735 recordMetricsIfPausing(); | |
2736 } | 2763 } |
2737 } else { | 2764 } else { |
2738 m_sentEndEvent = false; | 2765 m_sentEndEvent = false; |
2739 } | 2766 } |
2740 | 2767 |
2741 updatePlayState(); | 2768 updatePlayState(); |
2742 } | 2769 } |
2743 | 2770 |
2744 void HTMLMediaElement::durationChanged() | 2771 void HTMLMediaElement::durationChanged() |
2745 { | 2772 { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2932 if (shouldBePlaying) { | 2959 if (shouldBePlaying) { |
2933 setDisplayMode(Video); | 2960 setDisplayMode(Video); |
2934 invalidateCachedTime(); | 2961 invalidateCachedTime(); |
2935 | 2962 |
2936 if (!isPlaying) { | 2963 if (!isPlaying) { |
2937 // Set rate, muted before calling play in case they were set before the media engine was setup. | 2964 // Set rate, muted before calling play in case they were set before the media engine was setup. |
2938 // The media engine should just stash the rate and muted values sinc e it isn't already playing. | 2965 // The media engine should just stash the rate and muted values sinc e it isn't already playing. |
2939 webMediaPlayer()->setRate(playbackRate()); | 2966 webMediaPlayer()->setRate(playbackRate()); |
2940 updateVolume(); | 2967 updateVolume(); |
2941 webMediaPlayer()->play(); | 2968 webMediaPlayer()->play(); |
2969 recordAutoplayMetric(AnyPlaybackStarted); | |
2942 } | 2970 } |
2943 | 2971 |
2944 if (mediaControls()) | 2972 if (mediaControls()) |
2945 mediaControls()->playbackStarted(); | 2973 mediaControls()->playbackStarted(); |
2946 startPlaybackProgressTimer(); | 2974 startPlaybackProgressTimer(); |
2947 m_playing = true; | 2975 m_playing = true; |
2948 recordAutoplayMetric(AnyPlaybackStarted); | 2976 m_autoplaying = false; |
liberato (no reviews please)
2015/11/25 18:58:54
i moved this from playInternal(). not sure that t
philipj_slow
2015/11/26 15:30:56
Nice catch! Fixed in https://github.com/whatwg/htm
liberato (no reviews please)
2015/12/02 00:58:09
https://codereview.chromium.org/1482393003/
| |
2949 | 2977 |
2950 } else { // Should not be playing right now | 2978 } else { // Should not be playing right now |
2951 if (isPlaying) | 2979 if (isPlaying) |
2952 webMediaPlayer()->pause(); | 2980 webMediaPlayer()->pause(); |
2981 | |
2953 refreshCachedTime(); | 2982 refreshCachedTime(); |
2954 | 2983 |
2955 m_playbackProgressTimer.stop(); | 2984 m_playbackProgressTimer.stop(); |
2956 m_playing = false; | 2985 m_playing = false; |
2957 double time = currentTime(); | 2986 double time = currentTime(); |
2958 if (time > m_lastSeekTime) | 2987 if (time > m_lastSeekTime) |
2959 addPlayedRange(m_lastSeekTime, time); | 2988 addPlayedRange(m_lastSeekTime, time); |
2960 | 2989 |
2961 if (couldPlayIfEnoughData()) | 2990 if (couldPlayIfEnoughData()) |
2962 prepareToPlay(); | 2991 prepareToPlay(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3058 mediaControls()->refreshCastButtonVisibilityWithoutUpdate(); | 3087 mediaControls()->refreshCastButtonVisibilityWithoutUpdate(); |
3059 | 3088 |
3060 if (layoutObject()) | 3089 if (layoutObject()) |
3061 layoutObject()->setShouldDoFullPaintInvalidation(); | 3090 layoutObject()->setShouldDoFullPaintInvalidation(); |
3062 } | 3091 } |
3063 | 3092 |
3064 void HTMLMediaElement::stop() | 3093 void HTMLMediaElement::stop() |
3065 { | 3094 { |
3066 WTF_LOG(Media, "HTMLMediaElement::stop(%p)", this); | 3095 WTF_LOG(Media, "HTMLMediaElement::stop(%p)", this); |
3067 | 3096 |
3068 recordMetricsIfPausing(); | 3097 if (!m_paused) |
3098 recordMetricsBeforePause(); | |
philipj_slow
2015/11/26 15:30:56
As I think I pointed out in an earlier review, thi
liberato (no reviews please)
2015/12/02 00:58:08
Done.
| |
3069 | 3099 |
3070 // Close the async event queue so that no events are enqueued by userCancell edLoad. | 3100 // Close the async event queue so that no events are enqueued by userCancell edLoad. |
3071 cancelPendingEventsAndCallbacks(); | 3101 cancelPendingEventsAndCallbacks(); |
3072 m_asyncEventQueue->close(); | 3102 m_asyncEventQueue->close(); |
3073 | 3103 |
3074 userCancelledLoad(); | 3104 userCancelledLoad(); |
3075 | 3105 |
3076 // Stop the playback without generating events | 3106 // Stop the playback without generating events |
3077 m_playing = false; | 3107 m_playing = false; |
3078 m_paused = true; | 3108 m_paused = true; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3568 // Select the first video track if a video track hasn't been selected yet. | 3598 // Select the first video track if a video track hasn't been selected yet. |
3569 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1) | 3599 if (videoTracks().length() > 0 && videoTracks().selectedIndex() == -1) |
3570 videoTracks().anonymousIndexedGetter(0)->setSelected(true); | 3600 videoTracks().anonymousIndexedGetter(0)->setSelected(true); |
3571 } | 3601 } |
3572 | 3602 |
3573 bool HTMLMediaElement::isUserGestureRequiredForPlay() const | 3603 bool HTMLMediaElement::isUserGestureRequiredForPlay() const |
3574 { | 3604 { |
3575 return m_userGestureRequiredForPlay; | 3605 return m_userGestureRequiredForPlay; |
3576 } | 3606 } |
3577 | 3607 |
3578 void HTMLMediaElement::removeUserGestureRequirement() | 3608 void HTMLMediaElement::removeUserGestureRequirement(AutoplayMetrics deferredMetr ic) |
3579 { | 3609 { |
3580 m_userGestureRequiredForPlay = false; | 3610 if (m_userGestureRequiredForPlay) { |
3581 } | 3611 m_userGestureRequiredForPlay = false; |
3582 | 3612 m_autoplayDeferredMetric = deferredMetric; |
3583 void HTMLMediaElement::setInitialPlayWithoutUserGestures(bool value) | 3613 } |
3584 { | |
3585 m_initialPlayWithoutUserGesture = value; | |
3586 } | 3614 } |
3587 | 3615 |
3588 void HTMLMediaElement::setNetworkState(NetworkState state) | 3616 void HTMLMediaElement::setNetworkState(NetworkState state) |
3589 { | 3617 { |
3590 if (m_networkState != state) { | 3618 if (m_networkState != state) { |
3591 m_networkState = state; | 3619 m_networkState = state; |
3592 if (MediaControls* controls = mediaControls()) | 3620 if (MediaControls* controls = mediaControls()) |
3593 controls->networkStateChanged(); | 3621 controls->networkStateChanged(); |
3622 | |
3623 if (m_networkState == NETWORK_LOADING && !m_recordedElement) { | |
philipj_slow
2015/11/26 15:30:56
Why here instead of in HTMLMediaElement::loadResou
liberato (no reviews please)
2015/12/02 00:58:09
Done.
| |
3624 m_recordedElement = true; | |
3625 recordAutoplayMetric(isHTMLVideoElement() | |
3626 ? AnyVideoElement : AnyAudioElement); | |
3627 } | |
3594 } | 3628 } |
3595 } | 3629 } |
3596 | 3630 |
3597 void HTMLMediaElement::notifyPositionMayHaveChanged(const IntRect& visibleRect) | 3631 void HTMLMediaElement::notifyPositionMayHaveChanged(const IntRect& visibleRect) |
3598 { | 3632 { |
3599 m_autoplayHelper.positionChanged(visibleRect); | 3633 m_autoplayHelper.positionChanged(visibleRect); |
3600 } | 3634 } |
3601 | 3635 |
3602 void HTMLMediaElement::updatePositionNotificationRegistration() | 3636 void HTMLMediaElement::updatePositionNotificationRegistration() |
3603 { | 3637 { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3672 visitor->trace(m_client); | 3706 visitor->trace(m_client); |
3673 } | 3707 } |
3674 | 3708 |
3675 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) | 3709 DEFINE_TRACE(HTMLMediaElement::AudioSourceProviderImpl) |
3676 { | 3710 { |
3677 visitor->trace(m_client); | 3711 visitor->trace(m_client); |
3678 } | 3712 } |
3679 #endif | 3713 #endif |
3680 | 3714 |
3681 } | 3715 } |
OLD | NEW |