Changeset 223960 in webkit


Ignore:
Timestamp:
Oct 25, 2017 10:39:47 AM (6 years ago)
Author:
jer.noble@apple.com
Message:

Autoplay muted videos still stop playback of other streaming apps in the background
https://bugs.webkit.org/show_bug.cgi?id=177920

Reviewed by Eric Carlson.

When creating a new <video> or <audio> element, the global AudioSession can sometimes have
its sessionCategory() set to "MediaPlayback", even if the element does not yet have a
source. This is because the constructor for the MediaElementSession is called before
m_isPlayingToWirelessTarget is initialized, and so in the MediaElementSession constructor,
the media element's m_isPlayingToWirelessTarget ivar is sometimes (uninitialized) true.

We could move the MediaElementSession ivar to the very end of the header, so it's
initialized last, but that still leaves the possibility of the MediaElementSession et. all
calling into the HTMLMediaElement before it's subclass's constructors have a chance to
initialize their own ivars (much less their vtables). So instead, we'll create and set the
MediaElementSession in a finishInitialization() method called from the HTMLVideoElement and
HTMLAudioElement's create() factory methods.

  • html/HTMLAudioElement.cpp:

(WebCore::HTMLAudioElement::create):

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::HTMLMediaElement):
(WebCore::HTMLMediaElement::finishInitialization):

  • html/HTMLMediaElement.h:
  • html/HTMLVideoElement.cpp:

(WebCore::HTMLVideoElement::create):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r223955 r223960  
     12017-10-25  Jer Noble  <jer.noble@apple.com>
     2
     3        Autoplay muted videos still stop playback of other streaming apps in the background
     4        https://bugs.webkit.org/show_bug.cgi?id=177920
     5
     6        Reviewed by Eric Carlson.
     7
     8        When creating a new <video> or <audio> element, the global AudioSession can sometimes have
     9        its sessionCategory() set to "MediaPlayback", even if the element does not yet have a
     10        source. This is because the constructor for the MediaElementSession is called before
     11        m_isPlayingToWirelessTarget is initialized, and so in the MediaElementSession constructor,
     12        the media element's m_isPlayingToWirelessTarget ivar is sometimes (uninitialized) true.
     13
     14        We could move the MediaElementSession ivar to the very end of the header, so it's
     15        initialized last, but that still leaves the possibility of the MediaElementSession et. all
     16        calling into the HTMLMediaElement before it's subclass's constructors have a chance to
     17        initialize their own ivars (much less their vtables). So instead, we'll create and set the
     18        MediaElementSession in a finishInitialization() method called from the HTMLVideoElement and
     19        HTMLAudioElement's create() factory methods.
     20
     21        * html/HTMLAudioElement.cpp:
     22        (WebCore::HTMLAudioElement::create):
     23        * html/HTMLMediaElement.cpp:
     24        (WebCore::HTMLMediaElement::HTMLMediaElement):
     25        (WebCore::HTMLMediaElement::finishInitialization):
     26        * html/HTMLMediaElement.h:
     27        * html/HTMLVideoElement.cpp:
     28        (WebCore::HTMLVideoElement::create):
     29
    1302017-10-25  Javier Fernandez  <jfernandez@igalia.com>
    231
  • trunk/Source/WebCore/html/HTMLAudioElement.cpp

    r217774 r223960  
    4545{
    4646    auto element = adoptRef(*new HTMLAudioElement(tagName, document, createdByParser));
     47    element->finishInitialization();
    4748    element->suspendIfNeeded();
    4849    return element;
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r223906 r223960  
    458458    , m_processingPreferenceChange(false)
    459459#endif
    460     , m_mediaSession(std::make_unique<MediaElementSession>(*this))
    461460#if !RELEASE_LOG_DISABLED
    462461    , m_logger(&document.logger())
     
    469468
    470469    setHasCustomStyleResolveCallbacks();
     470}
     471
     472void HTMLMediaElement::finishInitialization()
     473{
     474    m_mediaSession = std::make_unique<MediaElementSession>(*this);
    471475
    472476    m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureForFullscreen);
     
    478482    m_mediaSession->addBehaviorRestriction(MediaElementSession::RequirePlaybackToControlControlsManager);
    479483
     484    auto& document = this->document();
    480485    auto* page = document.page();
    481486
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r223802 r223960  
    546546protected:
    547547    HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
     548    virtual void finishInitialization();
    548549    virtual ~HTMLMediaElement();
    549550
  • trunk/Source/WebCore/html/HTMLVideoElement.cpp

    r223644 r223960  
    6565{
    6666    auto videoElement = adoptRef(*new HTMLVideoElement(tagName, document, createdByParser));
     67    videoElement->finishInitialization();
    6768    videoElement->suspendIfNeeded();
    6869    return videoElement;
Note: See TracChangeset for help on using the changeset viewer.