MediaSessionManagerMac::nowPlayingEligibleSession() needs to honor the main content...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Sep 2016 18:45:53 +0000 (18:45 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Sep 2016 18:45:53 +0000 (18:45 +0000)
commit4373020741ef83fa7ed0ed08e259eefacc048273
treeb6a1c266d6aaf37b00d71effcd4161251e8dc053
parente277cbddb8f16cf62a89bef76f5b42f7ed5c08ba
MediaSessionManagerMac::nowPlayingEligibleSession() needs to honor the main content heuristic
https://bugs.webkit.org/show_bug.cgi?id=162480
<rdar://problem/28430615>

Reviewed by Jer Noble.

Changes the implementation of nowPlayingEligibleSession to use bestMediaElementForShowingPlaybackControlsManager
and also early return nullptr if the current tab the web process is hosted in is the active tab, and the window
it is hosted in is the main window. This information is derived from the viewState flags in the Page of each
tab -- whenever the (visible && active) state changes, the Page tells the global media session manager to update
its Now Playing info. Then, when each MediaElementSession tries to determine whether it can show playback
controls for the purposes of Now Playing, each session consults its page's visible and active state. If a page
is both visible and active, no Now Playing controls are allowed for that media session.

Also adds some slight adjustments to MediaSessionManagerMac::updateNowPlayingInfo, so we reset the title, rate
and duration of the current active session when clearing out the now playing info. Likewise, when vending an
active video, if the video information matches that of the current session, we mark m_nowPlayingActive anyways.
These tweaks prevent us from getting in a bad state when switching between a tab with media and one without.

Unit tests to come in a future patch.

* html/HTMLMediaElement.cpp:
(WebCore::mediaElementSessionInfoForSession):
(WebCore::mediaSessionMayBeConfusedWithMainContent):
(WebCore::HTMLMediaElement::bestMediaElementForShowingPlaybackControlsManager):
(WebCore::HTMLMediaElement::updatePlaybackControlsManager):
(WebCore::bestMediaSessionForShowingPlaybackControlsManager): Deleted.
* html/HTMLMediaElement.h:
* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::canShowControlsManager):
(WebCore::MediaElementSession::pageAllowsNowPlayingControls):
* html/MediaElementSession.h:
* page/Page.cpp:
(WebCore::Page::setViewState):
(WebCore::Page::isVisibleAndActive):
* page/Page.h:
* platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary):
* platform/audio/PlatformMediaSessionManager.h:
* platform/audio/mac/MediaSessionManagerMac.mm:
(WebCore::PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary):
(WebCore::MediaSessionManagerMac::nowPlayingEligibleSession):
(WebCore::MediaSessionManagerMac::updateNowPlayingInfo):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206315 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/MediaElementSession.cpp
Source/WebCore/html/MediaElementSession.h
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
Source/WebCore/platform/audio/PlatformMediaSessionManager.h
Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm