Diff
Modified: branches/safari-602-branch/Source/WebCore/ChangeLog (206455 => 206456)
--- branches/safari-602-branch/Source/WebCore/ChangeLog 2016-09-27 19:49:33 UTC (rev 206455)
+++ branches/safari-602-branch/Source/WebCore/ChangeLog 2016-09-27 19:49:38 UTC (rev 206456)
@@ -1,5 +1,37 @@
2016-09-27 Babak Shafiei <bshaf...@apple.com>
+ Merge r206454. rdar://problem/28484193
+
+ 2016-09-27 Wenson Hsieh <wenson_hs...@apple.com>
+
+ 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 Babak Shafiei <bshaf...@apple.com>
+
Merge r206444. rdar://problem/28496755
2016-09-27 Wenson Hsieh <wenson_hs...@apple.com>
Modified: branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.cpp (206455 => 206456)
--- branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.cpp 2016-09-27 19:49:33 UTC (rev 206455)
+++ branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.cpp 2016-09-27 19:49:38 UTC (rev 206456)
@@ -350,6 +350,7 @@
struct MediaElementSessionInfo {
const MediaElementSession* session;
+ MediaElementSession::PlaybackControlsPurpose purpose;
double timeOfLastUserInteraction;
bool canShowControlsManager : 1;
@@ -363,6 +364,7 @@
const HTMLMediaElement& element = session.element();
return {
&session,
+ purpose,
session.mostRecentUserInteractionTime(),
session.canShowControlsManager(purpose),
element.isFullscreen() || element.isVisibleInViewport(),
@@ -373,10 +375,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;
}
@@ -5085,6 +5094,9 @@
updateMediaController();
updateRenderer();
+
+ m_hasEverHadAudio |= hasAudio();
+ m_hasEverHadVideo |= hasVideo();
}
void HTMLMediaElement::setPlaying(bool playing)
Modified: branches/safari-602-branch/Source/WebCore/html/MediaElementSession.cpp (206455 => 206456)
--- branches/safari-602-branch/Source/WebCore/html/MediaElementSession.cpp 2016-09-27 19:49:33 UTC (rev 206455)
+++ branches/safari-602-branch/Source/WebCore/html/MediaElementSession.cpp 2016-09-27 19:49:38 UTC (rev 206456)
@@ -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: branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm (206455 => 206456)
--- branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm 2016-09-27 19:49:33 UTC (rev 206455)
+++ branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm 2016-09-27 19:49:38 UTC (rev 206456)
@@ -81,7 +81,7 @@
return false;
LOG(Media, "MediaSessionManagerMac::sessionWillBeginPlayback");
- updateNowPlayingInfo();
+ scheduleUpdateNowPlayingInfo();
return true;
}