Title: [223960] trunk/Source/WebCore
Revision
223960
Author
jer.no...@apple.com
Date
2017-10-25 10:39:47 -0700 (Wed, 25 Oct 2017)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (223959 => 223960)


--- trunk/Source/WebCore/ChangeLog	2017-10-25 17:27:24 UTC (rev 223959)
+++ trunk/Source/WebCore/ChangeLog	2017-10-25 17:39:47 UTC (rev 223960)
@@ -1,3 +1,32 @@
+2017-10-25  Jer Noble  <jer.no...@apple.com>
+
+        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):
+
 2017-10-25  Javier Fernandez  <jfernan...@igalia.com>
 
         [css-grid] Avoid clearing the overrideContainingBlockWidth if possible

Modified: trunk/Source/WebCore/html/HTMLAudioElement.cpp (223959 => 223960)


--- trunk/Source/WebCore/html/HTMLAudioElement.cpp	2017-10-25 17:27:24 UTC (rev 223959)
+++ trunk/Source/WebCore/html/HTMLAudioElement.cpp	2017-10-25 17:39:47 UTC (rev 223960)
@@ -44,6 +44,7 @@
 Ref<HTMLAudioElement> HTMLAudioElement::create(const QualifiedName& tagName, Document& document, bool createdByParser)
 {
     auto element = adoptRef(*new HTMLAudioElement(tagName, document, createdByParser));
+    element->finishInitialization();
     element->suspendIfNeeded();
     return element;
 }

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (223959 => 223960)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-10-25 17:27:24 UTC (rev 223959)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-10-25 17:39:47 UTC (rev 223960)
@@ -457,7 +457,6 @@
     , m_haveVisibleTextTrack(false)
     , m_processingPreferenceChange(false)
 #endif
-    , m_mediaSession(std::make_unique<MediaElementSession>(*this))
 #if !RELEASE_LOG_DISABLED
     , m_logger(&document.logger())
     , m_logIdentifier(nextLogIdentifier())
@@ -468,7 +467,12 @@
     ALWAYS_LOG(LOGIDENTIFIER);
 
     setHasCustomStyleResolveCallbacks();
+}
 
+void HTMLMediaElement::finishInitialization()
+{
+    m_mediaSession = std::make_unique<MediaElementSession>(*this);
+
     m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureForFullscreen);
     m_mediaSession->addBehaviorRestriction(MediaElementSession::RequirePageConsentToLoadMedia);
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
@@ -477,6 +481,7 @@
     m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureToControlControlsManager);
     m_mediaSession->addBehaviorRestriction(MediaElementSession::RequirePlaybackToControlControlsManager);
 
+    auto& document = this->document();
     auto* page = document.page();
 
     if (document.settings().invisibleAutoplayNotPermitted())

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (223959 => 223960)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2017-10-25 17:27:24 UTC (rev 223959)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2017-10-25 17:39:47 UTC (rev 223960)
@@ -545,6 +545,7 @@
 
 protected:
     HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
+    virtual void finishInitialization();
     virtual ~HTMLMediaElement();
 
     void parseAttribute(const QualifiedName&, const AtomicString&) override;

Modified: trunk/Source/WebCore/html/HTMLVideoElement.cpp (223959 => 223960)


--- trunk/Source/WebCore/html/HTMLVideoElement.cpp	2017-10-25 17:27:24 UTC (rev 223959)
+++ trunk/Source/WebCore/html/HTMLVideoElement.cpp	2017-10-25 17:39:47 UTC (rev 223960)
@@ -64,6 +64,7 @@
 Ref<HTMLVideoElement> HTMLVideoElement::create(const QualifiedName& tagName, Document& document, bool createdByParser)
 {
     auto videoElement = adoptRef(*new HTMLVideoElement(tagName, document, createdByParser));
+    videoElement->finishInitialization();
     videoElement->suspendIfNeeded();
     return videoElement;
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to