Add support for an autoplay play-pause events quirk.
authormrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Mar 2017 18:48:29 +0000 (18:48 +0000)
committermrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Mar 2017 18:48:29 +0000 (18:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169235

Reviewed by Jer Noble.

For sites that assume media starts off playing, send a playing and pause event to trigger
custom media controls to update.

* html/HTMLMediaElement.cpp:
(WebCore::needsAutoplayPlayPauseEventsQuirk):
(WebCore::HTMLMediaElement::dispatchPlayPauseEventsIfNeedsQuirks):
(WebCore::HTMLMediaElement::setReadyState):
(WebCore::HTMLMediaElement::play):
* html/HTMLMediaElement.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213585 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h

index 1e9a757..88dbc16 100644 (file)
@@ -1,3 +1,20 @@
+2017-03-06  Matt Rajca  <mrajca@apple.com>
+
+        Add support for an autoplay play-pause events quirk.
+        https://bugs.webkit.org/show_bug.cgi?id=169235
+
+        Reviewed by Jer Noble.
+
+        For sites that assume media starts off playing, send a playing and pause event to trigger
+        custom media controls to update.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::needsAutoplayPlayPauseEventsQuirk):
+        (WebCore::HTMLMediaElement::dispatchPlayPauseEventsIfNeedsQuirks):
+        (WebCore::HTMLMediaElement::setReadyState):
+        (WebCore::HTMLMediaElement::play):
+        * html/HTMLMediaElement.h:
+
 2017-03-08  Zan Dobersek  <zdobersek@igalia.com>
 
         MediaPlayerPrivateGStreamerBase::volume() should override the MediaPlayerPrivate method
index e62f147..5eb207a 100644 (file)
@@ -585,6 +585,16 @@ HTMLMediaElement::~HTMLMediaElement()
     updatePlaybackControlsManager();
 }
 
+static bool needsAutoplayPlayPauseEventsQuirk(const Document& document)
+{
+    auto* page = document.page();
+    if (!page || !page->settings().needsSiteSpecificQuirks())
+        return false;
+
+    String host = document.url().host();
+    return equalLettersIgnoringASCIICase(host, "yahoo.com") || host.endsWithIgnoringASCIICase(".yahoo.com");
+}
+
 static bool needsPlaybackControlsManagerQuirk(Page& page)
 {
     if (!page.settings().needsSiteSpecificQuirks())
@@ -2306,6 +2316,15 @@ SuccessOr<MediaPlaybackDenialReason> HTMLMediaElement::canTransitionFromAutoplay
     return MediaPlaybackDenialReason::PageConsentRequired;
 }
 
+void HTMLMediaElement::dispatchPlayPauseEventsIfNeedsQuirks()
+{
+    if (!needsAutoplayPlayPauseEventsQuirk(document().topDocument()))
+        return;
+
+    scheduleEvent(eventNames().playingEvent);
+    scheduleEvent(eventNames().pauseEvent);
+}
+
 void HTMLMediaElement::setReadyState(MediaPlayer::ReadyState state)
 {
     LOG(Media, "HTMLMediaElement::setReadyState(%p) - new state = %d, current state = %d,", this, static_cast<int>(state), static_cast<int>(m_readyState));
@@ -2427,6 +2446,7 @@ void HTMLMediaElement::setReadyState(MediaPlayer::ReadyState state)
             scheduleNotifyAboutPlaying();
         } else if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
             m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::Prevented;
+            dispatchPlayPauseEventsIfNeedsQuirks();
 
             if (Page* page = document().page())
                 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
@@ -3111,6 +3131,7 @@ void HTMLMediaElement::play(DOMPromise<void>&& promise)
     if (!success) {
         if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
             m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::Prevented;
+            dispatchPlayPauseEventsIfNeedsQuirks();
 
             if (Page* page = document().page())
                 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
@@ -3143,6 +3164,7 @@ void HTMLMediaElement::play()
     if (!success) {
         if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
             m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::Prevented;
+            dispatchPlayPauseEventsIfNeedsQuirks();
 
             if (Page* page = document().page())
                 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
index e378bc3..548e941 100644 (file)
@@ -730,6 +730,7 @@ private:
     bool stoppedDueToErrors() const;
     bool pausedForUserInteraction() const;
     bool couldPlayIfEnoughData() const;
+    void dispatchPlayPauseEventsIfNeedsQuirks();
     SuccessOr<MediaPlaybackDenialReason> canTransitionFromAutoplayToPlay() const;
 
     MediaTime minTimeSeekable() const;