Skip to content
Permalink
Browse files
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):


Canonical link: https://commits.webkit.org/194956@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223960 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jernoble committed Oct 25, 2017
1 parent 8f37b7c commit 7ff4b887ddf4ee5102ef73687046914c27330cb8
Showing 5 changed files with 38 additions and 1 deletion.
@@ -1,3 +1,32 @@
2017-10-25 Jer Noble <jer.noble@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 <jfernandez@igalia.com>

[css-grid] Avoid clearing the overrideContainingBlockWidth if possible
@@ -44,6 +44,7 @@ inline HTMLAudioElement::HTMLAudioElement(const QualifiedName& tagName, Document
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;
}
@@ -457,7 +457,6 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
, 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,6 +467,11 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
ALWAYS_LOG(LOGIDENTIFIER);

setHasCustomStyleResolveCallbacks();
}

void HTMLMediaElement::finishInitialization()
{
m_mediaSession = std::make_unique<MediaElementSession>(*this);

m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureForFullscreen);
m_mediaSession->addBehaviorRestriction(MediaElementSession::RequirePageConsentToLoadMedia);
@@ -477,6 +481,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document& docum
m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureToControlControlsManager);
m_mediaSession->addBehaviorRestriction(MediaElementSession::RequirePlaybackToControlControlsManager);

auto& document = this->document();
auto* page = document.page();

if (document.settings().invisibleAutoplayNotPermitted())
@@ -545,6 +545,7 @@ class HTMLMediaElement

protected:
HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
virtual void finishInitialization();
virtual ~HTMLMediaElement();

void parseAttribute(const QualifiedName&, const AtomicString&) override;
@@ -64,6 +64,7 @@ inline HTMLVideoElement::HTMLVideoElement(const QualifiedName& tagName, Document
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;
}

0 comments on commit 7ff4b88

Please sign in to comment.