Title: [206454] trunk/Source/WebCore
Revision
206454
Author
[email protected]
Date
2016-09-27 12:39:45 -0700 (Tue, 27 Sep 2016)

Log Message

Related videos on YouTube (and YouTube playlists) cause media controls to disappear
https://bugs.webkit.org/show_bug.cgi?id=162621
<rdar://problem/28484193>

Reviewed by Jer Noble.

Tweaks the main content media heuristic for better Now Playing behavior on YouTube by making the following
changes:
- Remove the strict requirement for audio to be actively playing for the session to be able to show
  controls for the purpose of Now Playing, making it the same as our policy for the controls manager.
- Make playback requirement restrictions apply only for the controls manager. Videos that do not
  autoplay will still have the correct behavior with respect to Now Playing, since we will bail in the
  hasEverNotifiedAboutPlaying() check.
- Only consider the main content heuristic as preventing media controls from showing up for the purposes
  of the controls manager. Now Playing should instead account for this by preferring elements large
  enough for main content after collecting all of the candidate sessions.

* html/HTMLMediaElement.cpp:
(WebCore::mediaElementSessionInfoForSession):
(WebCore::preferMediaControlsForCandidateSessionOverOtherCandidateSession):
(WebCore::HTMLMediaElement::updatePlayState):
* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::canShowControlsManager):
* platform/audio/mac/MediaSessionManagerMac.mm:
(WebCore::MediaSessionManagerMac::sessionWillBeginPlayback):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206453 => 206454)


--- trunk/Source/WebCore/ChangeLog	2016-09-27 19:35:49 UTC (rev 206453)
+++ trunk/Source/WebCore/ChangeLog	2016-09-27 19:39:45 UTC (rev 206454)
@@ -1,3 +1,31 @@
+2016-09-27  Wenson Hsieh  <[email protected]>
+
+        Related videos on YouTube (and YouTube playlists) cause media controls to disappear
+        https://bugs.webkit.org/show_bug.cgi?id=162621
+        <rdar://problem/28484193>
+
+        Reviewed by Jer Noble.
+
+        Tweaks the main content media heuristic for better Now Playing behavior on YouTube by making the following
+        changes:
+        - Remove the strict requirement for audio to be actively playing for the session to be able to show
+          controls for the purpose of Now Playing, making it the same as our policy for the controls manager.
+        - Make playback requirement restrictions apply only for the controls manager. Videos that do not
+          autoplay will still have the correct behavior with respect to Now Playing, since we will bail in the
+          hasEverNotifiedAboutPlaying() check.
+        - Only consider the main content heuristic as preventing media controls from showing up for the purposes
+          of the controls manager. Now Playing should instead account for this by preferring elements large
+          enough for main content after collecting all of the candidate sessions.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::mediaElementSessionInfoForSession):
+        (WebCore::preferMediaControlsForCandidateSessionOverOtherCandidateSession):
+        (WebCore::HTMLMediaElement::updatePlayState):
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::canShowControlsManager):
+        * platform/audio/mac/MediaSessionManagerMac.mm:
+        (WebCore::MediaSessionManagerMac::sessionWillBeginPlayback):
+
 2016-09-27  Chris Dumez  <[email protected]>
 
         Second parameter to MutationObserver.observe() should be optional

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (206453 => 206454)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2016-09-27 19:35:49 UTC (rev 206453)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2016-09-27 19:39:45 UTC (rev 206454)
@@ -332,6 +332,7 @@
 
 struct MediaElementSessionInfo {
     const MediaElementSession* session;
+    MediaElementSession::PlaybackControlsPurpose purpose;
 
     double timeOfLastUserInteraction;
     bool canShowControlsManager : 1;
@@ -345,6 +346,7 @@
     const HTMLMediaElement& element = session.element();
     return {
         &session,
+        purpose,
         session.mostRecentUserInteractionTime(),
         session.canShowControlsManager(purpose),
         element.isFullscreen() || element.isVisibleInViewport(),
@@ -355,10 +357,17 @@
 
 static bool preferMediaControlsForCandidateSessionOverOtherCandidateSession(const MediaElementSessionInfo& session, const MediaElementSessionInfo& otherSession)
 {
-    // Prioritize visible media over offscreen media.
-    if (session.isVisibleInViewportOrFullscreen != otherSession.isVisibleInViewportOrFullscreen)
+    MediaElementSession::PlaybackControlsPurpose purpose = session.purpose;
+    ASSERT(purpose == otherSession.purpose);
+
+    // For the controls manager, prioritize visible media over offscreen media.
+    if (purpose == MediaElementSession::PlaybackControlsPurpose::ControlsManager && session.isVisibleInViewportOrFullscreen != otherSession.isVisibleInViewportOrFullscreen)
         return session.isVisibleInViewportOrFullscreen;
 
+    // For Now Playing, prioritize elements that would normally satisfy main content.
+    if (purpose == MediaElementSession::PlaybackControlsPurpose::NowPlaying && session.isLargeEnoughForMainContent != otherSession.isLargeEnoughForMainContent)
+        return session.isLargeEnoughForMainContent;
+
     // As a tiebreaker, prioritize elements that the user recently interacted with.
     return session.timeOfLastUserInteraction > otherSession.timeOfLastUserInteraction;
 }
@@ -5013,6 +5022,9 @@
     
     updateMediaController();
     updateRenderer();
+
+    m_hasEverHadAudio |= hasAudio();
+    m_hasEverHadVideo |= hasVideo();
 }
 
 void HTMLMediaElement::setPlaying(bool playing)

Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (206453 => 206454)


--- trunk/Source/WebCore/html/MediaElementSession.cpp	2016-09-27 19:35:49 UTC (rev 206453)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp	2016-09-27 19:39:45 UTC (rev 206454)
@@ -233,8 +233,7 @@
         return false;
     }
 
-    bool meetsAudioTrackRequirements = m_element.hasAudio() || (purpose == PlaybackControlsPurpose::ControlsManager && m_element.hasEverHadAudio());
-    if (!meetsAudioTrackRequirements) {
+    if (!m_element.hasAudio() && !m_element.hasEverHadAudio()) {
         LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: No audio");
         return false;
     }
@@ -259,7 +258,7 @@
         return true;
     }
 
-    if (hasBehaviorRestriction(RequirePlaybackToControlControlsManager) && !m_element.isPlaying()) {
+    if (purpose == PlaybackControlsPurpose::ControlsManager && hasBehaviorRestriction(RequirePlaybackToControlControlsManager) && !m_element.isPlaying()) {
         LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: Needs to be playing");
         return false;
     }
@@ -274,13 +273,14 @@
         return false;
     }
 
-    if (m_element.isVideo()) {
+    // Only allow the main content heuristic to forbid videos from showing up if our purpose is the controls manager.
+    if (purpose == PlaybackControlsPurpose::ControlsManager && m_element.isVideo()) {
         if (!m_element.renderer()) {
             LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: No renderer");
             return false;
         }
 
-        if (purpose == PlaybackControlsPurpose::ControlsManager && !m_element.hasVideo() && !m_element.hasEverHadVideo()) {
+        if (!m_element.hasVideo() && !m_element.hasEverHadVideo()) {
             LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: No video");
             return false;
         }
@@ -291,6 +291,11 @@
         }
     }
 
+    if (purpose == PlaybackControlsPurpose::NowPlaying) {
+        LOG(Media, "MediaElementSession::canShowControlsManager - returning TRUE: Potentially plays audio");
+        return true;
+    }
+
     LOG(Media, "MediaElementSession::canShowControlsManager - returning FALSE: No user gesture");
     return false;
 }

Modified: trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm (206453 => 206454)


--- trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm	2016-09-27 19:35:49 UTC (rev 206453)
+++ trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm	2016-09-27 19:39:45 UTC (rev 206454)
@@ -81,7 +81,7 @@
         return false;
 
     LOG(Media, "MediaSessionManagerMac::sessionWillBeginPlayback");
-    updateNowPlayingInfo();
+    scheduleUpdateNowPlayingInfo();
     return true;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to