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

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

Issue 2051253002: Start autoplay muted videos with autoplay attribute when they are visible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 17 matching lines...) Expand all
28 #include "bindings/core/v8/ExceptionState.h" 28 #include "bindings/core/v8/ExceptionState.h"
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "bindings/core/v8/ScriptController.h" 30 #include "bindings/core/v8/ScriptController.h"
31 #include "bindings/core/v8/ScriptEventListener.h" 31 #include "bindings/core/v8/ScriptEventListener.h"
32 #include "bindings/core/v8/ScriptPromiseResolver.h" 32 #include "bindings/core/v8/ScriptPromiseResolver.h"
33 #include "core/HTMLNames.h" 33 #include "core/HTMLNames.h"
34 #include "core/css/MediaList.h" 34 #include "core/css/MediaList.h"
35 #include "core/dom/Attribute.h" 35 #include "core/dom/Attribute.h"
36 #include "core/dom/DOMException.h" 36 #include "core/dom/DOMException.h"
37 #include "core/dom/ElementTraversal.h" 37 #include "core/dom/ElementTraversal.h"
38 #include "core/dom/ElementVisibilityObserver.h"
38 #include "core/dom/Fullscreen.h" 39 #include "core/dom/Fullscreen.h"
39 #include "core/dom/shadow/ShadowRoot.h" 40 #include "core/dom/shadow/ShadowRoot.h"
40 #include "core/events/Event.h" 41 #include "core/events/Event.h"
41 #include "core/frame/FrameView.h" 42 #include "core/frame/FrameView.h"
42 #include "core/frame/LocalFrame.h" 43 #include "core/frame/LocalFrame.h"
43 #include "core/frame/Settings.h" 44 #include "core/frame/Settings.h"
44 #include "core/frame/UseCounter.h" 45 #include "core/frame/UseCounter.h"
45 #include "core/frame/csp/ContentSecurityPolicy.h" 46 #include "core/frame/csp/ContentSecurityPolicy.h"
46 #include "core/html/HTMLMediaSource.h" 47 #include "core/html/HTMLMediaSource.h"
47 #include "core/html/HTMLSourceElement.h" 48 #include "core/html/HTMLSourceElement.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 visitor->trace(m_element); 348 visitor->trace(m_element);
348 Client::trace(visitor); 349 Client::trace(visitor);
349 } 350 }
350 351
351 private: 352 private:
352 AutoplayHelperClientImpl(HTMLMediaElement* element) : m_element(element) {} 353 AutoplayHelperClientImpl(HTMLMediaElement* element) : m_element(element) {}
353 354
354 Member<HTMLMediaElement> m_element; 355 Member<HTMLMediaElement> m_element;
355 }; 356 };
356 357
357
358 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric) 358 void HTMLMediaElement::recordAutoplayMetric(AutoplayMetrics metric)
359 { 359 {
360 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayHistogram, ("Blink.MediaEl ement.Autoplay", NumberOfAutoplayMetrics)); 360 DEFINE_STATIC_LOCAL(EnumerationHistogram, autoplayHistogram, ("Blink.MediaEl ement.Autoplay", NumberOfAutoplayMetrics));
361 autoplayHistogram.count(metric); 361 autoplayHistogram.count(metric);
362 } 362 }
363 363
364 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType) 364 WebMimeRegistry::SupportsType HTMLMediaElement::supportsType(const ContentType& contentType)
365 { 365 {
366 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs")); 366 DEFINE_STATIC_LOCAL(const String, codecs, ("codecs"));
367 367
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) { 1634 if (m_readyState == HAVE_ENOUGH_DATA && oldState < HAVE_ENOUGH_DATA && track sAreReady) {
1635 if (oldState <= HAVE_CURRENT_DATA) { 1635 if (oldState <= HAVE_CURRENT_DATA) {
1636 scheduleEvent(EventTypeNames::canplay); 1636 scheduleEvent(EventTypeNames::canplay);
1637 if (isPotentiallyPlaying) 1637 if (isPotentiallyPlaying)
1638 scheduleNotifyPlaying(); 1638 scheduleNotifyPlaying();
1639 } 1639 }
1640 1640
1641 // Check for autoplay, and record metrics about it if needed. 1641 // Check for autoplay, and record metrics about it if needed.
1642 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) { 1642 if (shouldAutoplay(RecordMetricsBehavior::DoRecord)) {
1643 recordAutoplaySourceMetric(AutoplaySourceAttribute); 1643 recordAutoplaySourceMetric(AutoplaySourceAttribute);
1644 // If the autoplay experiment says that it's okay to play now, 1644
1645 // then don't require a user gesture.
1646 m_autoplayHelper->becameReadyToPlay(); 1645 m_autoplayHelper->becameReadyToPlay();
1647 1646
1648 if (!isGestureNeededForPlayback()) { 1647 if (!isGestureNeededForPlayback()) {
1649 m_paused = false; 1648 if (muted() && RuntimeEnabledFeatures::autoplayMutedVideosEnable d()) {
1650 invalidateCachedTime(); 1649 m_autoplayVisibilityObserver = new ElementVisibilityObserver (this, WTF::bind<bool>(&HTMLMediaElement::visibilityChangedForAutoplay, this));
1651 scheduleEvent(EventTypeNames::play); 1650 m_autoplayVisibilityObserver->start();
1652 scheduleNotifyPlaying(); 1651 } else {
1653 m_autoplaying = false; 1652 m_paused = false;
1653 invalidateCachedTime();
1654 scheduleEvent(EventTypeNames::play);
1655 scheduleNotifyPlaying();
1656 m_autoplaying = false;
1657 }
1654 } 1658 }
1655 } 1659 }
1656 1660
1657 scheduleEvent(EventTypeNames::canplaythrough); 1661 scheduleEvent(EventTypeNames::canplaythrough);
1658 1662
1659 shouldUpdateDisplayState = true; 1663 shouldUpdateDisplayState = true;
1660 } 1664 }
1661 1665
1662 if (shouldUpdateDisplayState) { 1666 if (shouldUpdateDisplayState) {
1663 updateDisplayState(); 1667 updateDisplayState();
(...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after
3634 visitor->trace(m_cueTimeline); 3638 visitor->trace(m_cueTimeline);
3635 visitor->trace(m_textTracks); 3639 visitor->trace(m_textTracks);
3636 visitor->trace(m_textTracksWhenResourceSelectionBegan); 3640 visitor->trace(m_textTracksWhenResourceSelectionBegan);
3637 visitor->trace(m_playPromiseResolvers); 3641 visitor->trace(m_playPromiseResolvers);
3638 visitor->trace(m_playPromiseResolveList); 3642 visitor->trace(m_playPromiseResolveList);
3639 visitor->trace(m_playPromiseRejectList); 3643 visitor->trace(m_playPromiseRejectList);
3640 visitor->trace(m_audioSourceProvider); 3644 visitor->trace(m_audioSourceProvider);
3641 visitor->trace(m_autoplayHelperClient); 3645 visitor->trace(m_autoplayHelperClient);
3642 visitor->trace(m_autoplayHelper); 3646 visitor->trace(m_autoplayHelper);
3643 visitor->trace(m_srcObject); 3647 visitor->trace(m_srcObject);
3648 visitor->trace(m_autoplayVisibilityObserver);
3644 visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::c learWeakMembers>(this); 3649 visitor->template registerWeakMembers<HTMLMediaElement, &HTMLMediaElement::c learWeakMembers>(this);
3645 Supplementable<HTMLMediaElement>::trace(visitor); 3650 Supplementable<HTMLMediaElement>::trace(visitor);
3646 HTMLElement::trace(visitor); 3651 HTMLElement::trace(visitor);
3647 ActiveDOMObject::trace(visitor); 3652 ActiveDOMObject::trace(visitor);
3648 } 3653 }
3649 3654
3650 DEFINE_TRACE_WRAPPERS(HTMLMediaElement) 3655 DEFINE_TRACE_WRAPPERS(HTMLMediaElement)
3651 { 3656 {
3652 visitor->traceWrappers(m_videoTracks); 3657 visitor->traceWrappers(m_videoTracks);
3653 visitor->traceWrappers(m_audioTracks); 3658 visitor->traceWrappers(m_audioTracks);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
3846 3851
3847 if (isHTMLVideoElement()) { 3852 if (isHTMLVideoElement()) {
3848 videoHistogram.count(source); 3853 videoHistogram.count(source);
3849 if (muted()) 3854 if (muted())
3850 mutedVideoHistogram.count(source); 3855 mutedVideoHistogram.count(source);
3851 } else { 3856 } else {
3852 audioHistogram.count(source); 3857 audioHistogram.count(source);
3853 } 3858 }
3854 } 3859 }
3855 3860
3861 void HTMLMediaElement::visibilityChangedForAutoplay(bool visibility) {
3862 if (!visibility)
3863 return;
3864
3865 playInternal();
3866 m_autoplayVisibilityObserver->stop();
3867 m_autoplayVisibilityObserver = nullptr;
3868 }
3869
3856 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3870 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3857 { 3871 {
3858 if (!ThreadHeap::isHeapObjectAlive(m_audioSourceNode)) { 3872 if (!ThreadHeap::isHeapObjectAlive(m_audioSourceNode)) {
3859 getAudioSourceProvider().setClient(nullptr); 3873 getAudioSourceProvider().setClient(nullptr);
3860 m_audioSourceNode = nullptr; 3874 m_audioSourceNode = nullptr;
3861 } 3875 }
3862 } 3876 }
3863 3877
3864 void HTMLMediaElement::AudioSourceProviderImpl::wrap(WebAudioSourceProvider* pro vider) 3878 void HTMLMediaElement::AudioSourceProviderImpl::wrap(WebAudioSourceProvider* pro vider)
3865 { 3879 {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3963 3977
3964 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst 3978 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() co nst
3965 { 3979 {
3966 IntRect result; 3980 IntRect result;
3967 if (LayoutObject* object = m_element->layoutObject()) 3981 if (LayoutObject* object = m_element->layoutObject())
3968 result = object->absoluteBoundingBoxRect(); 3982 result = object->absoluteBoundingBoxRect();
3969 return result; 3983 return result;
3970 } 3984 }
3971 3985
3972 } // namespace blink 3986 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698