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

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

Issue 2108403003: Measure whether muted videos that started playing with play() become visible at some point (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: this one is ready Created 4 years, 5 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 26 matching lines...) Expand all
37 #include "core/dom/ElementTraversal.h" 37 #include "core/dom/ElementTraversal.h"
38 #include "core/dom/ElementVisibilityObserver.h" 38 #include "core/dom/ElementVisibilityObserver.h"
39 #include "core/dom/Fullscreen.h" 39 #include "core/dom/Fullscreen.h"
40 #include "core/dom/shadow/ShadowRoot.h" 40 #include "core/dom/shadow/ShadowRoot.h"
41 #include "core/events/Event.h" 41 #include "core/events/Event.h"
42 #include "core/frame/FrameView.h" 42 #include "core/frame/FrameView.h"
43 #include "core/frame/LocalFrame.h" 43 #include "core/frame/LocalFrame.h"
44 #include "core/frame/Settings.h" 44 #include "core/frame/Settings.h"
45 #include "core/frame/UseCounter.h" 45 #include "core/frame/UseCounter.h"
46 #include "core/frame/csp/ContentSecurityPolicy.h" 46 #include "core/frame/csp/ContentSecurityPolicy.h"
47 #include "core/html/AutoplayUmaHelper.h"
47 #include "core/html/HTMLMediaSource.h" 48 #include "core/html/HTMLMediaSource.h"
48 #include "core/html/HTMLSourceElement.h" 49 #include "core/html/HTMLSourceElement.h"
49 #include "core/html/HTMLTrackElement.h" 50 #include "core/html/HTMLTrackElement.h"
50 #include "core/html/MediaError.h" 51 #include "core/html/MediaError.h"
51 #include "core/html/MediaFragmentURIParser.h" 52 #include "core/html/MediaFragmentURIParser.h"
52 #include "core/html/TimeRanges.h" 53 #include "core/html/TimeRanges.h"
53 #include "core/html/shadow/MediaControls.h" 54 #include "core/html/shadow/MediaControls.h"
54 #include "core/html/track/AudioTrack.h" 55 #include "core/html/track/AudioTrack.h"
55 #include "core/html/track/AudioTrackList.h" 56 #include "core/html/track/AudioTrackList.h"
56 #include "core/html/track/AutomaticTrackSelection.h" 57 #include "core/html/track/AutomaticTrackSelection.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 case WebMediaPlayer::PreloadMetaData: 274 case WebMediaPlayer::PreloadMetaData:
274 return "metadata"; 275 return "metadata";
275 case WebMediaPlayer::PreloadAuto: 276 case WebMediaPlayer::PreloadAuto:
276 return "auto"; 277 return "auto";
277 } 278 }
278 279
279 NOTREACHED(); 280 NOTREACHED();
280 return String(); 281 return String();
281 } 282 }
282 283
283 // These values are used for histograms. Do not reorder.
284 enum AutoplaySource {
285 // Autoplay comes from HTMLMediaElement `autoplay` attribute.
286 AutoplaySourceAttribute = 0,
287 // Autoplay comes from `play()` method.
288 AutoplaySourceMethod = 1,
289 // This enum value must be last.
290 NumberOfAutoplaySources = 2,
291 };
292
293 } // anonymous namespace 284 } // anonymous namespace
294 285
295 class HTMLMediaElement::AutoplayHelperClientImpl : 286 class HTMLMediaElement::AutoplayHelperClientImpl :
296 public AutoplayExperimentHelper::Client { 287 public AutoplayExperimentHelper::Client {
297 288
298 public: 289 public:
299 static AutoplayHelperClientImpl* create(HTMLMediaElement* element) 290 static AutoplayHelperClientImpl* create(HTMLMediaElement* element)
300 { 291 {
301 return new AutoplayHelperClientImpl(element); 292 return new AutoplayHelperClientImpl(element);
302 } 293 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 , m_playingRemotely(false) 431 , m_playingRemotely(false)
441 , m_inOverlayFullscreenVideo(false) 432 , m_inOverlayFullscreenVideo(false)
442 , m_audioTracks(AudioTrackList::create(*this)) 433 , m_audioTracks(AudioTrackList::create(*this))
443 , m_videoTracks(VideoTrackList::create(*this)) 434 , m_videoTracks(VideoTrackList::create(*this))
444 , m_textTracks(nullptr) 435 , m_textTracks(nullptr)
445 , m_playPromiseResolveTask(CancellableTaskFactory::create(this, &HTMLMediaEl ement::resolveScheduledPlayPromises)) 436 , m_playPromiseResolveTask(CancellableTaskFactory::create(this, &HTMLMediaEl ement::resolveScheduledPlayPromises))
446 , m_playPromiseRejectTask(CancellableTaskFactory::create(this, &HTMLMediaEle ment::rejectScheduledPlayPromises)) 437 , m_playPromiseRejectTask(CancellableTaskFactory::create(this, &HTMLMediaEle ment::rejectScheduledPlayPromises))
447 , m_audioSourceNode(nullptr) 438 , m_audioSourceNode(nullptr)
448 , m_autoplayHelperClient(AutoplayHelperClientImpl::create(this)) 439 , m_autoplayHelperClient(AutoplayHelperClientImpl::create(this))
449 , m_autoplayHelper(AutoplayExperimentHelper::create(m_autoplayHelperClient.g et())) 440 , m_autoplayHelper(AutoplayExperimentHelper::create(m_autoplayHelperClient.g et()))
441 , m_autoplayUmaHelper(AutoplayUmaHelper::create(this))
450 , m_remotePlaybackClient(nullptr) 442 , m_remotePlaybackClient(nullptr)
451 , m_autoplayVisibilityObserver(nullptr) 443 , m_autoplayVisibilityObserver(nullptr)
452 { 444 {
453 ThreadState::current()->registerPreFinalizer(this); 445 ThreadState::current()->registerPreFinalizer(this);
454 446
455 MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")"; 447 MEDIA_LOG << "HTMLMediaElement(" << (void*)this << ")";
456 448
457 // If any experiment is enabled, then we want to enable a user gesture by 449 // If any experiment is enabled, then we want to enable a user gesture by
458 // default, otherwise the experiment does nothing. 450 // default, otherwise the experiment does nothing.
459 if ((document.settings() && document.settings()->mediaPlaybackRequiresUserGe sture()) 451 if ((document.settings() && document.settings()->mediaPlaybackRequiresUserGe sture())
(...skipping 23 matching lines...) Expand all
483 closeMediaSource(); 475 closeMediaSource();
484 476
485 // Destroying the player may cause a resource load to be canceled, 477 // Destroying the player may cause a resource load to be canceled,
486 // which could result in LocalDOMWindow::dispatchWindowLoadEvent() being 478 // which could result in LocalDOMWindow::dispatchWindowLoadEvent() being
487 // called via ResourceFetch::didLoadResource(), then 479 // called via ResourceFetch::didLoadResource(), then
488 // FrameLoader::checkCompleted(). But it's guaranteed that the load event 480 // FrameLoader::checkCompleted(). But it's guaranteed that the load event
489 // doesn't get dispatched during the object destruction. 481 // doesn't get dispatched during the object destruction.
490 // See Document::isDelayingLoadEvent(). 482 // See Document::isDelayingLoadEvent().
491 // Also see http://crbug.com/275223 for more details. 483 // Also see http://crbug.com/275223 for more details.
492 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking(); 484 clearMediaPlayerAndAudioSourceProviderClientWithoutLocking();
485
486 m_autoplayUmaHelper->onElementDestroyed();
493 } 487 }
494 488
495 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument) 489 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument)
496 { 490 {
497 MEDIA_LOG << "didMoveToNewDocument(" << (void*)this << ")"; 491 MEDIA_LOG << "didMoveToNewDocument(" << (void*)this << ")";
498 492
499 // If any experiment is enabled, then we want to enable a user gesture by 493 // If any experiment is enabled, then we want to enable a user gesture by
500 // default, otherwise the experiment does nothing. 494 // default, otherwise the experiment does nothing.
501 bool oldDocumentRequiresUserGesture = (oldDocument.settings() && oldDocument .settings()->mediaPlaybackRequiresUserGesture()) 495 bool oldDocumentRequiresUserGesture = (oldDocument.settings() && oldDocument .settings()->mediaPlaybackRequiresUserGesture())
502 || m_autoplayHelper->isExperimentEnabled(); 496 || m_autoplayHelper->isExperimentEnabled();
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 1613
1620 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) { 1614 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) {
1621 if (oldState <= HAVE_CURRENT_DATA) { 1615 if (oldState <= HAVE_CURRENT_DATA) {
1622 scheduleEvent(EventTypeNames::canplay); 1616 scheduleEvent(EventTypeNames::canplay);
1623 if (isPotentiallyPlaying) 1617 if (isPotentiallyPlaying)
1624 scheduleNotifyPlaying(); 1618 scheduleNotifyPlaying();
1625 } 1619 }
1626 1620
1627 // Check for autoplay, and record metrics about it if needed. 1621 // Check for autoplay, and record metrics about it if needed.
1628 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { 1622 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) {
1629 recordAutoplaySourceMetric(AutoplaySourceAttribute); 1623 recordAutoplaySourceMetric(AutoplaySource::Attribute);
1624 m_autoplayUmaHelper->onAutoplayInitiated(AutoplaySource::Attribute);
1630 1625
1631 // If the autoplay experiment says that it's okay to play now, 1626 // If the autoplay experiment says that it's okay to play now,
1632 // then don't require a user gesture. 1627 // then don't require a user gesture.
1633 m_autoplayHelper->becameReadyToPlay(); 1628 m_autoplayHelper->becameReadyToPlay();
1634 1629
1635 if (!isGestureNeededForPlayback()) { 1630 if (!isGestureNeededForPlayback()) {
1636 if (isHTMLVideoElement() && muted() && RuntimeEnabledFeatures::a utoplayMutedVideosEnabled()) { 1631 if (isHTMLVideoElement() && muted() && RuntimeEnabledFeatures::a utoplayMutedVideosEnabled()) {
1637 m_autoplayVisibilityObserver = new ElementVisibilityObserver (this, WTF::bind(&HTMLMediaElement::onVisibilityChangedForAutoplay, wrapPersiste nt(this))); 1632 m_autoplayVisibilityObserver = new ElementVisibilityObserver (this, WTF::bind(&HTMLMediaElement::onVisibilityChangedForAutoplay, wrapPersiste nt(this)));
1638 m_autoplayVisibilityObserver->start(); 1633 m_autoplayVisibilityObserver->start();
1639 } else { 1634 } else {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 return promise; 2064 return promise;
2070 } 2065 }
2071 2066
2072 Nullable<ExceptionCode> HTMLMediaElement::play() 2067 Nullable<ExceptionCode> HTMLMediaElement::play()
2073 { 2068 {
2074 MEDIA_LOG << "play(" << (void*)this << ")"; 2069 MEDIA_LOG << "play(" << (void*)this << ")";
2075 2070
2076 m_autoplayHelper->playMethodCalled(); 2071 m_autoplayHelper->playMethodCalled();
2077 2072
2078 if (!UserGestureIndicator::processingUserGesture()) { 2073 if (!UserGestureIndicator::processingUserGesture()) {
2079 recordAutoplaySourceMetric(AutoplaySourceMethod); 2074 recordAutoplaySourceMetric(AutoplaySource::Method);
2075 m_autoplayUmaHelper->onAutoplayInitiated(AutoplaySource::Method);
2080 if (isGestureNeededForPlayback()) { 2076 if (isGestureNeededForPlayback()) {
2081 // If playback is deferred, then don't start playback but don't 2077 // If playback is deferred, then don't start playback but don't
2082 // fail yet either. 2078 // fail yet either.
2083 if (m_autoplayHelper->isPlaybackDeferred()) 2079 if (m_autoplayHelper->isPlaybackDeferred())
2084 return nullptr; 2080 return nullptr;
2085 2081
2086 // If we're already playing, then this play would do nothing anyway. 2082 // If we're already playing, then this play would do nothing anyway.
2087 // Call playInternal to handle scheduling the promise resolution. 2083 // Call playInternal to handle scheduling the promise resolution.
2088 if (!m_paused) { 2084 if (!m_paused) {
2089 playInternal(); 2085 playInternal();
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
3654 visitor->trace(m_videoTracks); 3650 visitor->trace(m_videoTracks);
3655 visitor->trace(m_cueTimeline); 3651 visitor->trace(m_cueTimeline);
3656 visitor->trace(m_textTracks); 3652 visitor->trace(m_textTracks);
3657 visitor->trace(m_textTracksWhenResourceSelectionBegan); 3653 visitor->trace(m_textTracksWhenResourceSelectionBegan);
3658 visitor->trace(m_playPromiseResolvers); 3654 visitor->trace(m_playPromiseResolvers);
3659 visitor->trace(m_playPromiseResolveList); 3655 visitor->trace(m_playPromiseResolveList);
3660 visitor->trace(m_playPromiseRejectList); 3656 visitor->trace(m_playPromiseRejectList);
3661 visitor->trace(m_audioSourceProvider); 3657 visitor->trace(m_audioSourceProvider);
3662 visitor->trace(m_autoplayHelperClient); 3658 visitor->trace(m_autoplayHelperClient);
3663 visitor->trace(m_autoplayHelper); 3659 visitor->trace(m_autoplayHelper);
3660 visitor->trace(m_autoplayUmaHelper);
3664 visitor->trace(m_srcObject); 3661 visitor->trace(m_srcObject);
3665 visitor->trace(m_autoplayVisibilityObserver); 3662 visitor->trace(m_autoplayVisibilityObserver);
3666 visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::c learWeakMembers>(this); 3663 visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::c learWeakMembers>(this);
3667 Supplementable<HTMLMediaElement>::trace(visitor); 3664 Supplementable<HTMLMediaElement>::trace(visitor);
3668 HTMLElement::trace(visitor); 3665 HTMLElement::trace(visitor);
3669 ActiveDOMObject::trace(visitor); 3666 ActiveDOMObject::trace(visitor);
3670 } 3667 }
3671 3668
3672 DEFINE_TRACE_WRAPPERS(HTMLMediaElement) 3669 DEFINE_TRACE_WRAPPERS(HTMLMediaElement)
3673 { 3670 {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3874 { 3871 {
3875 if (isHTMLVideoElement()) { 3872 if (isHTMLVideoElement()) {
3876 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("Media.Controls.Sh ow.Video", MediaControlsShowMax)); 3873 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("Media.Controls.Sh ow.Video", MediaControlsShowMax));
3877 return histogram; 3874 return histogram;
3878 } 3875 }
3879 3876
3880 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("Media.Controls.Show.A udio", MediaControlsShowMax)); 3877 DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, ("Media.Controls.Show.A udio", MediaControlsShowMax));
3881 return histogram; 3878 return histogram;
3882 } 3879 }
3883 3880
3884 void HTMLMediaElement::recordAutoplaySourceMetric(int source) 3881 void HTMLMediaElement::recordAutoplaySourceMetric(AutoplaySource source)
3885 { 3882 {
3886 DEFINE_STATIC_LOCAL(EnumerationHistogram, videoHistogram, ("Media.Video.Auto play", NumberOfAutoplaySources)); 3883 DEFINE_STATIC_LOCAL(EnumerationHistogram, videoHistogram, ("Media.Video.Auto play", static_cast<int>(AutoplaySource::NumberOfSources)));
3887 DEFINE_STATIC_LOCAL(EnumerationHistogram, mutedVideoHistogram, ("Media.Video .Autoplay.Muted", NumberOfAutoplaySources)); 3884 DEFINE_STATIC_LOCAL(EnumerationHistogram, mutedVideoHistogram, ("Media.Video .Autoplay.Muted", static_cast<int>(AutoplaySource::NumberOfSources)));
3888 DEFINE_STATIC_LOCAL(EnumerationHistogram, audioHistogram, ("Media.Audio.Auto play", NumberOfAutoplaySources)); 3885 DEFINE_STATIC_LOCAL(EnumerationHistogram, audioHistogram, ("Media.Audio.Auto play", static_cast<int>(AutoplaySource::NumberOfSources)));
3889 3886
3890 if (isHTMLVideoElement()) { 3887 if (isHTMLVideoElement()) {
3891 videoHistogram.count(source); 3888 videoHistogram.count(static_cast<int>(source));
3892 if (muted()) 3889 if (muted())
3893 mutedVideoHistogram.count(source); 3890 mutedVideoHistogram.count(static_cast<int>(source));
3894 } else { 3891 } else {
3895 audioHistogram.count(source); 3892 audioHistogram.count(static_cast<int>(source));
3896 } 3893 }
3897 } 3894 }
3898 3895
3899 void HTMLMediaElement::recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus sta tus) 3896 void HTMLMediaElement::recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus sta tus)
3900 { 3897 {
3901 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayUnmuteHistogram, ("Media.V ideo.Autoplay.Muted.UnmuteAction", AutoplayUnmuteActionMax)); 3898 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayUnmuteHistogram, ("Media.V ideo.Autoplay.Muted.UnmuteAction", AutoplayUnmuteActionMax));
3902 3899
3903 autoplayUnmuteHistogram.count(status); 3900 autoplayUnmuteHistogram.count(status);
3904 } 3901 }
3905 3902
3906 void HTMLMediaElement::onVisibilityChangedForAutoplay(bool isVisible) 3903 void HTMLMediaElement::onVisibilityChangedForAutoplay(bool isVisible)
3907 { 3904 {
3908 if (!isVisible) 3905 if (!isVisible)
3909 return; 3906 return;
3910 3907
3911 if (shouldAutoplay()) { 3908 if (shouldAutoplay()) {
3912 m_paused = false; 3909 m_paused = false;
3913 invalidateCachedTime(); 3910 invalidateCachedTime();
3914 scheduleEvent(EventTypeNames::play); 3911 scheduleEvent(EventTypeNames::play);
3915 scheduleNotifyPlaying(); 3912 scheduleNotifyPlaying();
3916 m_autoplaying = false; 3913 m_autoplaying = false;
3917 3914
3918 updatePlayState(); 3915 updatePlayState();
3916 m_autoplayUmaHelper->onAutoplayStarted();
3919 } 3917 }
3920 3918
3921 m_autoplayVisibilityObserver->stop(); 3919 m_autoplayVisibilityObserver->stop();
3922 m_autoplayVisibilityObserver = nullptr; 3920 m_autoplayVisibilityObserver = nullptr;
3923 } 3921 }
3924 3922
3925 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3923 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3926 { 3924 {
3927 if (!ThreadHeap::isHeapObjectAlive(m_audioSourceNode)) { 3925 if (!ThreadHeap::isHeapObjectAlive(m_audioSourceNode)) {
3928 getAudioSourceProvider().setClient(nullptr); 3926 getAudioSourceProvider().setClient(nullptr);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
4028 4026
4029 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst 4027 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst
4030 { 4028 {
4031 IntRect result; 4029 IntRect result;
4032 if (LayoutObject* object = m_element->layoutObject()) 4030 if (LayoutObject* object = m_element->layoutObject())
4033 result = object->absoluteBoundingBoxRect(); 4031 result = object->absoluteBoundingBoxRect();
4034 return result; 4032 return result;
4035 } 4033 }
4036 4034
4037 } // namespace blink 4035 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698