Changeset 188030 in webkit


Ignore:
Timestamp:
Aug 6, 2015 12:13:55 AM (9 years ago)
Author:
mrajca@apple.com
Message:

Media Session: push paused state to the media session focus manager instead of polling
https://bugs.webkit.org/show_bug.cgi?id=147633

Reviewed by Simon Fraser.

WebCore:

  • dom/Document.cpp:

(WebCore::Document::updateIsPlayingMedia): If a valid source element ID is passed in, set the 'IsSourcePlaying'

flag accordingly.

  • dom/Document.h:
  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::elementWithID):
(WebCore::HTMLMediaElement::setMuted): Pass along the element ID.
(WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged): Ditto.
(WebCore::HTMLMediaElement::setPlaying): Ditto.

  • html/HTMLMediaElement.h:
  • page/ChromeClient.h:
  • page/MediaProducer.h:
  • page/Page.cpp:

(WebCore::Page::updateIsPlayingMedia): Pass along the source element ID.
(WebCore::Page::isMediaElementPaused): Deleted. We now push media playback state changes instead of polling.

  • page/Page.h:

WebKit2:

  • UIProcess/WebMediaSessionFocusManager.cpp:

(WebKit::WebMediaSessionFocusManager::isFocusedContentMediaElementPaused): Report whether the focused media

element is currently playing. The callback is no longer necessary and will be removed in a future patch in
favor of returning a value directly.

(WebKit::WebMediaSessionFocusManager::mediaElementIsPlayingDidChange): Keep track of whether the focused media

element is currently playing.

  • UIProcess/WebMediaSessionFocusManager.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::isPlayingMediaDidChange): If the focused media element begins/ends playing, keep track

of its playing state.

(WebKit::WebPageProxy::isMediaElementPaused): Deleted. We now push media playback state changes instead of

polling.

  • UIProcess/WebPageProxy.h: isPlayingMediaDidChange is now passed the ID of the media element that triggered the 'playing' state change. This can be used in conjunction with the IsSourcePlaying media flag to identify whether the source element begin/ended playing.
  • UIProcess/WebPageProxy.messages.in: Ditto.
  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::setPluginIsPlayingAudio): Since a media element did not trigger this, pass in 0 for the

source media element.

  • WebProcess/WebCoreSupport/WebChromeClient.cpp:

(WebKit::WebChromeClient::isPlayingMediaDidChange): isPlayingMediaDidChange is now passed the ID of the media

element that triggered the 'playing' state change.

  • WebProcess/WebCoreSupport/WebChromeClient.h: Ditto.
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::isMediaElementPaused): Deleted. We now push media playback state changes instead of polling.

  • WebProcess/WebPage/WebPage.h: Ditto.
  • WebProcess/WebPage/WebPage.messages.in: Ditto.
Location:
trunk/Source
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r188025 r188030  
     12015-08-04  Matt Rajca  <mrajca@apple.com>
     2
     3        Media Session: push paused state to the media session focus manager instead of polling
     4        https://bugs.webkit.org/show_bug.cgi?id=147633
     5
     6        Reviewed by Simon Fraser.
     7
     8        * dom/Document.cpp:
     9        (WebCore::Document::updateIsPlayingMedia): If a valid source element ID is passed in, set the 'IsSourcePlaying'
     10         flag accordingly.
     11        * dom/Document.h:
     12        * html/HTMLMediaElement.cpp:
     13        (WebCore::HTMLMediaElement::elementWithID):
     14        (WebCore::HTMLMediaElement::setMuted): Pass along the element ID.
     15        (WebCore::HTMLMediaElement::mediaPlayerCharacteristicChanged): Ditto.
     16        (WebCore::HTMLMediaElement::setPlaying): Ditto.
     17        * html/HTMLMediaElement.h:
     18        * page/ChromeClient.h:
     19        * page/MediaProducer.h:
     20        * page/Page.cpp:
     21        (WebCore::Page::updateIsPlayingMedia): Pass along the source element ID.
     22        (WebCore::Page::isMediaElementPaused): Deleted. We now push media playback state changes instead of polling.
     23        * page/Page.h:
     24
    1252015-08-05  Myles C. Maxfield  <mmaxfield@apple.com>
    226
  • trunk/Source/WebCore/dom/Document.cpp

    r187706 r188030  
    35073507}
    35083508
    3509 void Document::updateIsPlayingMedia()
     3509void Document::updateIsPlayingMedia(uint64_t sourceElementID)
    35103510{
    35113511    MediaProducer::MediaStateFlags state = MediaProducer::IsNotPlaying;
     
    35133513        state |= audioProducer->mediaState();
    35143514
     3515#if ENABLE(MEDIA_SESSION)
     3516    if (HTMLMediaElement* sourceElement = HTMLMediaElement::elementWithID(sourceElementID)) {
     3517        if (sourceElement->isPlaying())
     3518            state |= MediaProducer::IsSourceElementPlaying;
     3519    }
     3520#endif
     3521
    35153522    if (state == m_mediaState)
    35163523        return;
     
    35193526
    35203527    if (page())
    3521         page()->updateIsPlayingMedia();
     3528        page()->updateIsPlayingMedia(sourceElementID);
    35223529}
    35233530
  • trunk/Source/WebCore/dom/Document.h

    r187706 r188030  
    227227#endif
    228228
     229WEBCORE_EXPORT extern const uint64_t HTMLMediaElementInvalidID;
     230
    229231enum PageshowEventPersistence {
    230232    PageshowEventNotPersisted = 0,
     
    12611263    WEBCORE_EXPORT void removeAudioProducer(MediaProducer*);
    12621264    MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
    1263     WEBCORE_EXPORT void updateIsPlayingMedia();
     1265    WEBCORE_EXPORT void updateIsPlayingMedia(uint64_t = HTMLMediaElementInvalidID);
    12641266    void pageMutedStateDidChange();
    12651267    WeakPtr<Document> createWeakPtr() { return m_weakFactory.createWeakPtr(); }
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r187892 r188030  
    203203#endif
    204204
     205const uint64_t HTMLMediaElementInvalidID = 0;
     206
    205207using namespace HTMLNames;
    206208
     
    300302HTMLMediaElement* HTMLMediaElement::elementWithID(uint64_t id)
    301303{
     304    if (id == HTMLMediaElementInvalidID)
     305        return nullptr;
     306   
    302307    return elementIDsToElements().get(id);
    303308}
     
    31653170        }
    31663171        scheduleEvent(eventNames().volumechangeEvent);
     3172
     3173#if ENABLE(MEDIA_SESSION)
     3174        document().updateIsPlayingMedia(m_elementID);
     3175#else
    31673176        document().updateIsPlayingMedia();
     3177#endif
    31683178
    31693179#if ENABLE(WIRELESS_PLAYBACK_TARGET)
     
    45294539        pauseInternal();
    45304540
     4541#if ENABLE(MEDIA_SESSION)
     4542    document().updateIsPlayingMedia(m_elementID);
     4543#else
    45314544    document().updateIsPlayingMedia();
     4545#endif
    45324546
    45334547    endProcessingMediaPlayerCallback();
     
    47894803
    47904804    m_playing = playing;
     4805
     4806#if ENABLE(MEDIA_SESSION)
     4807    document().updateIsPlayingMedia(m_elementID);
     4808#else
    47914809    document().updateIsPlayingMedia();
     4810#endif
    47924811
    47934812#if ENABLE(WIRELESS_PLAYBACK_TARGET)
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r187712 r188030  
    9999#endif
    100100
     101extern const uint64_t HTMLMediaElementInvalidID;
     102
    101103class HTMLMediaElement
    102104    : public HTMLElement
  • trunk/Source/WebCore/page/ChromeClient.h

    r187713 r188030  
    421421    virtual bool shouldUseTiledBackingForFrameView(const FrameView*) const { return false; }
    422422
    423     virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags) { }
     423    virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
    424424
    425425#if ENABLE(MEDIA_SESSION)
  • trunk/Source/WebCore/page/MediaProducer.h

    r186361 r188030  
    3939        ExternalDeviceAutoPlayCandidate = 1 << 4,
    4040        DidPlayToEnd = 1 << 5,
     41        IsSourceElementPlaying = 1 << 6,
    4142    };
    4243    typedef unsigned MediaStateFlags;
  • trunk/Source/WebCore/page/Page.cpp

    r187790 r188030  
    11841184}
    11851185
    1186 void Page::updateIsPlayingMedia()
     1186void Page::updateIsPlayingMedia(uint64_t sourceElementID)
    11871187{
    11881188    MediaProducer::MediaStateFlags state = MediaProducer::IsNotPlaying;
     
    11961196    m_mediaState = state;
    11971197
    1198     chrome().client().isPlayingMediaDidChange(state);
     1198    chrome().client().isPlayingMediaDidChange(state, sourceElementID);
    11991199}
    12001200
     
    12251225    }
    12261226}
    1227 
    1228 bool Page::isMediaElementPaused(uint64_t elementID)
    1229 {
    1230     if (HTMLMediaElement* element = HTMLMediaElement::elementWithID(elementID))
    1231         return element->paused();
    1232 
    1233     ASSERT_NOT_REACHED();
    1234     return true;
    1235 }
    12361227#endif
    12371228
  • trunk/Source/WebCore/page/Page.h

    r187790 r188030  
    437437
    438438    MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
    439     void updateIsPlayingMedia();
     439    void updateIsPlayingMedia(uint64_t);
    440440    bool isMuted() const { return m_muted; }
    441441    WEBCORE_EXPORT void setMuted(bool);
     
    443443#if ENABLE(MEDIA_SESSION)
    444444    WEBCORE_EXPORT void handleMediaEvent(MediaEventType);
    445     WEBCORE_EXPORT bool isMediaElementPaused(uint64_t);
    446445#endif
    447446
  • trunk/Source/WebKit2/ChangeLog

    r188011 r188030  
     12015-08-04  Matt Rajca  <mrajca@apple.com>
     2
     3        Media Session: push paused state to the media session focus manager instead of polling
     4        https://bugs.webkit.org/show_bug.cgi?id=147633
     5
     6        Reviewed by Simon Fraser.
     7
     8        * UIProcess/WebMediaSessionFocusManager.cpp:
     9        (WebKit::WebMediaSessionFocusManager::isFocusedContentMediaElementPaused): Report whether the focused media
     10         element is currently playing. The callback is no longer necessary and will be removed in a future patch in
     11         favor of returning a value directly.
     12        (WebKit::WebMediaSessionFocusManager::mediaElementIsPlayingDidChange): Keep track of whether the focused media
     13         element is currently playing.
     14        * UIProcess/WebMediaSessionFocusManager.h:
     15        * UIProcess/WebPageProxy.cpp:
     16        (WebKit::WebPageProxy::isPlayingMediaDidChange): If the focused media element begins/ends playing, keep track
     17         of its playing state.
     18        (WebKit::WebPageProxy::isMediaElementPaused): Deleted. We now push media playback state changes instead of
     19         polling.
     20        * UIProcess/WebPageProxy.h: isPlayingMediaDidChange is now passed the ID of the media element that triggered
     21         the 'playing' state change. This can be used in conjunction with the IsSourcePlaying media flag to identify
     22         whether the source element begin/ended playing.
     23        * UIProcess/WebPageProxy.messages.in: Ditto.
     24        * WebProcess/Plugins/PluginView.cpp:
     25        (WebKit::PluginView::setPluginIsPlayingAudio): Since a media element did not trigger this, pass in 0 for the
     26         source media element.
     27        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
     28        (WebKit::WebChromeClient::isPlayingMediaDidChange): isPlayingMediaDidChange is now passed the ID of the media
     29         element that triggered the 'playing' state change.
     30        * WebProcess/WebCoreSupport/WebChromeClient.h: Ditto.
     31        * WebProcess/WebPage/WebPage.cpp:
     32        (WebKit::WebPage::isMediaElementPaused): Deleted. We now push media playback state changes instead of polling.
     33        * WebProcess/WebPage/WebPage.h: Ditto.
     34        * WebProcess/WebPage/WebPage.messages.in: Ditto.
     35
    1362015-08-05  Tim Horton  <timothy_horton@apple.com>
    237
  • trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.cpp

    r187917 r188030  
    6363        return;
    6464
    65     RefPtr<UnsignedCallback> callback = UnsignedCallback::create(callbackFunction);
    66     WebPageProxy* proxy = m_focusedMediaElement->first;
    67     uint64_t elementID = m_focusedMediaElement->second;
    68     proxy->isMediaElementPaused(elementID, callback);
     65    callbackFunction(!m_focusedMediaElementIsPlaying, CallbackBase::Error::None);
     66}
     67
     68void WebMediaSessionFocusManager::mediaElementIsPlayingDidChange(WebPageProxy* proxy, uint64_t elementID, bool isPlaying)
     69{
     70    if (m_focusedMediaElement) {
     71        if (proxy == m_focusedMediaElement->first && elementID == m_focusedMediaElement->second)
     72            m_focusedMediaElementIsPlaying = isPlaying;
     73    }
    6974}
    7075
  • trunk/Source/WebKit2/UIProcess/WebMediaSessionFocusManager.h

    r187917 r188030  
    4545
    4646    void isFocusedContentMediaElementPaused(std::function<void(bool, CallbackBase::Error)>);
     47    void mediaElementIsPlayingDidChange(WebPageProxy*, uint64_t, bool);
    4748
    4849    void setFocusedMediaElement(WebPageProxy&, uint64_t);
     
    6061
    6162    std::unique_ptr<FocusedMediaElement> m_focusedMediaElement;
     63    bool m_focusedMediaElementIsPlaying { false };
    6264};
    6365
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r188011 r188030  
    38833883    m_process->send(Messages::WebPage::HandleMediaEvent(eventType), m_pageID);
    38843884}
    3885 
    3886 void WebPageProxy::isMediaElementPaused(uint64_t elementID, RefPtr<UnsignedCallback> callback)
    3887 {
    3888     if (!isValid()) {
    3889         callback->invalidate();
    3890         return;
    3891     }
    3892 
    3893     uint64_t callbackID = callback->callbackID();
    3894     m_callbacks.put(callback);
    3895 
    3896     m_process->send(Messages::WebPage::IsMediaElementPaused(elementID, callbackID), m_pageID);
    3897 }
    38983885#endif
    38993886
     
    59515938}
    59525939
    5953 void WebPageProxy::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state)
    5954 {
     5940void WebPageProxy::isPlayingMediaDidChange(MediaProducer::MediaStateFlags state, uint64_t sourceElementID)
     5941{
     5942#if ENABLE(MEDIA_SESSION)
     5943    WebMediaSessionFocusManager* focusManager = process().processPool().supplement<WebMediaSessionFocusManager>();
     5944    ASSERT(focusManager);
     5945    focusManager->mediaElementIsPlayingDidChange(this, sourceElementID, state & MediaProducer::IsSourceElementPlaying);
     5946#endif
     5947
    59555948    if (state == m_mediaState)
    59565949        return;
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r188011 r188030  
    944944    bool hasMediaSessionWithActiveMediaElements() const { return m_hasMediaSessionWithActiveMediaElements; }
    945945    void handleMediaEvent(WebCore::MediaEventType);
    946     void isMediaElementPaused(uint64_t, RefPtr<UnsignedCallback>);
    947946#endif
    948947
     
    10261025
    10271026    bool isPlayingAudio() const { return !!(m_mediaState & WebCore::MediaProducer::IsPlayingAudio); }
    1028     void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags);
     1027    void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t);
    10291028
    10301029#if ENABLE(MEDIA_SESSION)
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r188011 r188030  
    423423#endif
    424424
    425     IsPlayingMediaDidChange(unsigned state)
     425    IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID)
    426426
    427427#if ENABLE(MEDIA_SESSION)
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r187713 r188030  
    10581058}
    10591059
    1060 void WebChromeClient::isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags state)
    1061 {
    1062     m_page->send(Messages::WebPageProxy::IsPlayingMediaDidChange(state));
     1060void WebChromeClient::isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags state, uint64_t sourceElementID)
     1061{
     1062    m_page->send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
    10631063}
    10641064
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

    r187713 r188030  
    292292    virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) const override;
    293293
    294     virtual void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags) override;
     294    virtual void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) override;
    295295    virtual void setPageActivityState(WebCore::PageActivityState::Flags) override;
    296296
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r188011 r188030  
    40774077    m_page->handleMediaEvent(static_cast<MediaEventType>(eventType));
    40784078}
    4079 
    4080 void WebPage::isMediaElementPaused(uint64_t elementID, uint64_t callbackID)
    4081 {
    4082     bool paused = m_page->isMediaElementPaused(elementID);
    4083     send(Messages::WebPageProxy::UnsignedCallback(paused, callbackID));
    4084 }
    40854079#endif
    40864080
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r187795 r188030  
    751751#if ENABLE(MEDIA_SESSION)
    752752    void handleMediaEvent(uint32_t /* WebCore::MediaEventType */);
    753     void isMediaElementPaused(uint64_t, uint64_t);
    754753#endif
    755754
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r187790 r188030  
    317317#if ENABLE(MEDIA_SESSION)
    318318    HandleMediaEvent(uint32_t eventType)
    319     IsMediaElementPaused(uint64_t elementID, uint64_t callbackID)
    320319#endif
    321320
Note: See TracChangeset for help on using the changeset viewer.