Implement Page::isPlayingAudio().
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Oct 2014 18:22:27 +0000 (18:22 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Oct 2014 18:22:27 +0000 (18:22 +0000)
commitbbdcd443eed704758fca5a7edfa21579a125a2ba
tree699e267e69fb6a84d3af92f61ebfaaa21d13f243
parentff875d7b713494bb89ea8a407e326ad058f93d41
Implement Page::isPlayingAudio().
https://bugs.webkit.org/show_bug.cgi?id=137218

Reviewed by Eric Carlson.

- Add a hasMediaCharacteristics() method to MediaSession. There are three characteristics:
audible, visual, and legible. MediaSession gets the media characteristics information from
its MediaSessionClient.
- Add a mediaStateDidChange() method to MediaSessionClient that MediaSession can call when its
state changes.
- Each Document keeps a set of MediaSessions it contains. When that set changes, or when a MediaSession
changes state, or when its characteristics change, Document::updateIsPlayingAudio() is called. That method
iterates through all its MediaSessions to check if the overall isPlayingAudio state has changed in the Document.
- Each Page caches its overall isPlayingAudio state. Whenever a Document's isPlayingAudio state changes,
it calls Page::updateIsPlayingAudio() which iterates through its frames' documents to calculate its
overall isPlayingAudio state.

No new tests, no behavior change.

* dom/Document.cpp:
(WebCore::Document::Document):
Initialize m_isPlayingAudio.
(WebCore::Document::registerMediaSession):
Add the MediaSession to m_mediaSessions. Call updateIsPlayingAudio().
(WebCore::Document::unregisterMediaSession):
Remove the MediaSession from m_mediaSessions. Call updateIsPlayingAudio().
(WebCore::Document::updateIsPlayingAudio):
Go through all the MediaSessions in this Document and check if any has the Audible characteristic
and is playing. If the overall isPlayingAudio state changes, call Page::updateIsPlayingAudio().
* dom/Document.h:
(WebCore::Document::isPlayingAudio):

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::registerWithDocument):
Call Document::registerMediaSession().
(WebCore::HTMLMediaElement::unregisterWithDocument):
Call Document::unregisterMediaSession().
(WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged):
Call Document::updateIsPlayingAudio().
(WebCore::HTMLMediaElement::stop):
Call MediaSession::clientWillPausePlayback() so the MediaSession's state can be set back to Paused.
(WebCore::HTMLMediaElement::hasMediaCharacteristics):
Call hasAudio() to check if the HTMLMediaElement has the Audible characteristic. Call hasVideo()
to check if it has the Visual characteristic. Call hasClosedCaptions() to check if it has the
Legible characteristic.
(WebCore::HTMLMediaElement::mediaStateDidChange):
Call Document::updateIsPlayingAudio().
* html/HTMLMediaElement.h:

* page/Page.cpp:
(WebCore::Page::Page):
Initialize m_isPlayingAudio.
(WebCore::Page::updateIsPlayingAudio):
Iterate through all its frames' documents to check if any has audio playing. If the overall isPlayingAudio
state has changed, update m_isPlayingAudio.
* page/Page.h:
(WebCore::Page::isPlayingAudio):

* platform/audio/MediaSession.cpp:
(WebCore::MediaSession::setState):
If the MediaSession's state has changed, call Document::updateIsPlayingAudio().
(WebCore::MediaSession::hasMediaCharacteristics):
Call MediaSessionClient::hasMediaCharacteristics().
* platform/audio/MediaSession.h:
(WebCore::MediaSessionClient::mediaStateDidChange):

* platform/audio/mac/AudioDestinationMac.h:
AudioDestination only has the Audible characteristic.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174353 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebCore/platform/audio/MediaSession.cpp
Source/WebCore/platform/audio/MediaSession.h
Source/WebCore/platform/audio/mac/AudioDestinationMac.h