Title: [250542] trunk/Source/WebCore
Revision
250542
Author
cdu...@apple.com
Date
2019-09-30 20:36:01 -0700 (Mon, 30 Sep 2019)

Log Message

Make GenericEventQueue an ActiveDOMObject
https://bugs.webkit.org/show_bug.cgi?id=202373

Reviewed by Eric Carlson.

Make GenericEventQueue an ActiveDOMObject so that it is guaranteed to never fire any events while
suspended without requiring the client to explicitly suspend/resume the event queue.

* Modules/encryptedmedia/MediaKeySession.cpp:
(WebCore::MediaKeySession::MediaKeySession):
(WebCore::MediaKeySession::enqueueMessage):
(WebCore::MediaKeySession::updateKeyStatuses):
* Modules/encryptedmedia/MediaKeySession.h:
* Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp:
(WebCore::WebKitMediaKeySession::WebKitMediaKeySession):
(WebCore::WebKitMediaKeySession::~WebKitMediaKeySession):
(WebCore::WebKitMediaKeySession::addKeyTimerFired):
(WebCore::WebKitMediaKeySession::sendMessage):
(WebCore::WebKitMediaKeySession::sendError):
(WebCore::WebKitMediaKeySession::hasPendingActivity const):
(WebCore::WebKitMediaKeySession::stop):
* Modules/encryptedmedia/legacy/WebKitMediaKeySession.h:
* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::MediaSource):
(WebCore::MediaSource::hasPendingActivity const):
(WebCore::MediaSource::stop):
(WebCore::MediaSource::canSuspendForDocumentSuspension const):
(WebCore::MediaSource::scheduleEvent):
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::SourceBuffer):
(WebCore::SourceBuffer::hasPendingActivity const):
(WebCore::SourceBuffer::stop):
(WebCore::SourceBuffer::scheduleEvent):
* Modules/mediasource/SourceBuffer.h:
* Modules/mediasource/SourceBufferList.cpp:
(WebCore::SourceBufferList::SourceBufferList):
(WebCore::SourceBufferList::scheduleEvent):
(WebCore::SourceBufferList::canSuspendForDocumentSuspension const):
* Modules/mediasource/SourceBufferList.h:
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::AudioContext):
(WebCore::AudioContext::stop):
* Modules/webaudio/AudioContext.h:
* animation/DeclarativeAnimation.cpp:
(WebCore::DeclarativeAnimation::DeclarativeAnimation):
(WebCore::DeclarativeAnimation::tick):
(WebCore::DeclarativeAnimation::needsTick const):
(WebCore::DeclarativeAnimation::remove):
(WebCore::DeclarativeAnimation::enqueueDOMEvent):
(WebCore::DeclarativeAnimation::stop):
(WebCore::DeclarativeAnimation::suspend):
(WebCore::DeclarativeAnimation::resume):
* animation/DeclarativeAnimation.h:
* dom/GenericEventQueue.cpp:
(WebCore::GenericEventQueueBase<T>::GenericEventQueueBase):
(WebCore::GenericEventQueueBase<T>::setPaused):
(WebCore::GenericEventQueueBase<T>::canSuspendForDocumentSuspension const):
(WebCore::GenericEventQueueBase<T>::suspend):
(WebCore::GenericEventQueueBase<T>::resume):
(WebCore::GenericEventQueueBase<T>::rescheduleAllEventsIfNeeded):
(WebCore::GenericEventQueueBase<T>::stop):
(WebCore::GenericEventQueueBase<T>::activeDOMObjectName const):
(WebCore::GenericEventQueue::create):
(WebCore::MainThreadGenericEventQueue::create):
* dom/GenericEventQueue.h:
* dom/MessagePort.cpp:
(WebCore::MessagePort::MessagePort):
(WebCore::MessagePort::close):
(WebCore::MessagePort::dispatchMessages):
* dom/MessagePort.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement):
(WebCore::HTMLMediaElement::~HTMLMediaElement):
(WebCore::HTMLMediaElement::scheduleEvent):
(WebCore::HTMLMediaElement::updateActiveTextTrackCues):
(WebCore::HTMLMediaElement::cancelPendingEventsAndCallbacks):
(WebCore::HTMLMediaElement::mediaPlayerKeyNeeded):
(WebCore::HTMLMediaElement::mediaPlayerInitializationDataEncountered):
(WebCore::HTMLMediaElement::closeTaskQueues):
(WebCore::HTMLMediaElement::suspend):
(WebCore::HTMLMediaElement::resume):
(WebCore::HTMLMediaElement::hasPendingActivity const):
(WebCore::HTMLMediaElement::enqueuePlaybackTargetAvailabilityChangedEvent):
* html/HTMLMediaElement.h:
* html/track/TrackListBase.cpp:
(WebCore::TrackListBase::TrackListBase):
(WebCore::TrackListBase::scheduleTrackEvent):
(WebCore::TrackListBase::scheduleChangeEvent):
(WebCore::TrackListBase::isChangeEventScheduled const):
(WebCore::TrackListBase::canSuspendForDocumentSuspension const):
* html/track/TrackListBase.h:
* workers/Worker.cpp:
(WebCore::Worker::Worker):
(WebCore::Worker::terminate):
(WebCore::Worker::stop):
(WebCore::Worker::hasPendingActivity const):
(WebCore::Worker::enqueueEvent):
(WebCore::Worker::dispatchEvent):
* workers/Worker.h:
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::ServiceWorkerContainer):
(WebCore::ServiceWorkerContainer::startMessages):
(WebCore::ServiceWorkerContainer::postMessage):
(WebCore::ServiceWorkerContainer::stop):
* workers/service/ServiceWorkerContainer.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (250541 => 250542)


--- trunk/Source/WebCore/ChangeLog	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/ChangeLog	2019-10-01 03:36:01 UTC (rev 250542)
@@ -1,5 +1,114 @@
 2019-09-30  Chris Dumez  <cdu...@apple.com>
 
+        Make GenericEventQueue an ActiveDOMObject
+        https://bugs.webkit.org/show_bug.cgi?id=202373
+
+        Reviewed by Eric Carlson.
+
+        Make GenericEventQueue an ActiveDOMObject so that it is guaranteed to never fire any events while
+        suspended without requiring the client to explicitly suspend/resume the event queue.
+
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        (WebCore::MediaKeySession::MediaKeySession):
+        (WebCore::MediaKeySession::enqueueMessage):
+        (WebCore::MediaKeySession::updateKeyStatuses):
+        * Modules/encryptedmedia/MediaKeySession.h:
+        * Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp:
+        (WebCore::WebKitMediaKeySession::WebKitMediaKeySession):
+        (WebCore::WebKitMediaKeySession::~WebKitMediaKeySession):
+        (WebCore::WebKitMediaKeySession::addKeyTimerFired):
+        (WebCore::WebKitMediaKeySession::sendMessage):
+        (WebCore::WebKitMediaKeySession::sendError):
+        (WebCore::WebKitMediaKeySession::hasPendingActivity const):
+        (WebCore::WebKitMediaKeySession::stop):
+        * Modules/encryptedmedia/legacy/WebKitMediaKeySession.h:
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::MediaSource):
+        (WebCore::MediaSource::hasPendingActivity const):
+        (WebCore::MediaSource::stop):
+        (WebCore::MediaSource::canSuspendForDocumentSuspension const):
+        (WebCore::MediaSource::scheduleEvent):
+        * Modules/mediasource/MediaSource.h:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::SourceBuffer):
+        (WebCore::SourceBuffer::hasPendingActivity const):
+        (WebCore::SourceBuffer::stop):
+        (WebCore::SourceBuffer::scheduleEvent):
+        * Modules/mediasource/SourceBuffer.h:
+        * Modules/mediasource/SourceBufferList.cpp:
+        (WebCore::SourceBufferList::SourceBufferList):
+        (WebCore::SourceBufferList::scheduleEvent):
+        (WebCore::SourceBufferList::canSuspendForDocumentSuspension const):
+        * Modules/mediasource/SourceBufferList.h:
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::AudioContext):
+        (WebCore::AudioContext::stop):
+        * Modules/webaudio/AudioContext.h:
+        * animation/DeclarativeAnimation.cpp:
+        (WebCore::DeclarativeAnimation::DeclarativeAnimation):
+        (WebCore::DeclarativeAnimation::tick):
+        (WebCore::DeclarativeAnimation::needsTick const):
+        (WebCore::DeclarativeAnimation::remove):
+        (WebCore::DeclarativeAnimation::enqueueDOMEvent):
+        (WebCore::DeclarativeAnimation::stop):
+        (WebCore::DeclarativeAnimation::suspend):
+        (WebCore::DeclarativeAnimation::resume):
+        * animation/DeclarativeAnimation.h:
+        * dom/GenericEventQueue.cpp:
+        (WebCore::GenericEventQueueBase<T>::GenericEventQueueBase):
+        (WebCore::GenericEventQueueBase<T>::setPaused):
+        (WebCore::GenericEventQueueBase<T>::canSuspendForDocumentSuspension const):
+        (WebCore::GenericEventQueueBase<T>::suspend):
+        (WebCore::GenericEventQueueBase<T>::resume):
+        (WebCore::GenericEventQueueBase<T>::rescheduleAllEventsIfNeeded):
+        (WebCore::GenericEventQueueBase<T>::stop):
+        (WebCore::GenericEventQueueBase<T>::activeDOMObjectName const):
+        (WebCore::GenericEventQueue::create):
+        (WebCore::MainThreadGenericEventQueue::create):
+        * dom/GenericEventQueue.h:
+        * dom/MessagePort.cpp:
+        (WebCore::MessagePort::MessagePort):
+        (WebCore::MessagePort::close):
+        (WebCore::MessagePort::dispatchMessages):
+        * dom/MessagePort.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement):
+        (WebCore::HTMLMediaElement::~HTMLMediaElement):
+        (WebCore::HTMLMediaElement::scheduleEvent):
+        (WebCore::HTMLMediaElement::updateActiveTextTrackCues):
+        (WebCore::HTMLMediaElement::cancelPendingEventsAndCallbacks):
+        (WebCore::HTMLMediaElement::mediaPlayerKeyNeeded):
+        (WebCore::HTMLMediaElement::mediaPlayerInitializationDataEncountered):
+        (WebCore::HTMLMediaElement::closeTaskQueues):
+        (WebCore::HTMLMediaElement::suspend):
+        (WebCore::HTMLMediaElement::resume):
+        (WebCore::HTMLMediaElement::hasPendingActivity const):
+        (WebCore::HTMLMediaElement::enqueuePlaybackTargetAvailabilityChangedEvent):
+        * html/HTMLMediaElement.h:
+        * html/track/TrackListBase.cpp:
+        (WebCore::TrackListBase::TrackListBase):
+        (WebCore::TrackListBase::scheduleTrackEvent):
+        (WebCore::TrackListBase::scheduleChangeEvent):
+        (WebCore::TrackListBase::isChangeEventScheduled const):
+        (WebCore::TrackListBase::canSuspendForDocumentSuspension const):
+        * html/track/TrackListBase.h:
+        * workers/Worker.cpp:
+        (WebCore::Worker::Worker):
+        (WebCore::Worker::terminate):
+        (WebCore::Worker::stop):
+        (WebCore::Worker::hasPendingActivity const):
+        (WebCore::Worker::enqueueEvent):
+        (WebCore::Worker::dispatchEvent):
+        * workers/Worker.h:
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::ServiceWorkerContainer):
+        (WebCore::ServiceWorkerContainer::startMessages):
+        (WebCore::ServiceWorkerContainer::postMessage):
+        (WebCore::ServiceWorkerContainer::stop):
+        * workers/service/ServiceWorkerContainer.h:
+
+2019-09-30  Chris Dumez  <cdu...@apple.com>
+
         IDBTransaction / IDBObjectStore should not prevent a page from entering the back / forward cache
         https://bugs.webkit.org/show_bug.cgi?id=202291
         <rdar://problem/55760106>

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp (250541 => 250542)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -68,7 +68,7 @@
     , m_sessionType(sessionType)
     , m_implementation(WTFMove(implementation))
     , m_instanceSession(WTFMove(instanceSession))
-    , m_eventQueue(*this)
+    , m_eventQueue(MainThreadGenericEventQueue::create(*this))
 {
     // https://w3c.github.io/encrypted-media/#dom-mediakeys-createsession
     // W3C Editor's Draft 09 November 2016
@@ -614,7 +614,7 @@
     //    interface with its type attribute set to message and its isTrusted attribute initialized to true, and dispatch it at the
     //    session.
     auto messageEvent = MediaKeyMessageEvent::create(eventNames().messageEvent, {messageType, message.tryCreateArrayBuffer()}, Event::IsTrusted::Yes);
-    m_eventQueue.enqueueEvent(WTFMove(messageEvent));
+    m_eventQueue->enqueueEvent(WTFMove(messageEvent));
 }
 
 void MediaKeySession::updateKeyStatuses(CDMInstanceSession::KeyStatusVector&& inputStatuses)
@@ -659,7 +659,7 @@
         m_statuses.uncheckedAppend({ WTFMove(status.first), toMediaKeyStatus(status.second) });
 
     // 5. Queue a task to fire a simple event named keystatuseschange at the session.
-    m_eventQueue.enqueueEvent(Event::create(eventNames().keystatuseschangeEvent, Event::CanBubble::No, Event::IsCancelable::No));
+    m_eventQueue->enqueueEvent(Event::create(eventNames().keystatuseschangeEvent, Event::CanBubble::No, Event::IsCancelable::No));
 
     // 6. Queue a task to run the Attempt to Resume Playback If Necessary algorithm on each of the media element(s) whose mediaKeys attribute is the MediaKeys object that created the session.
     m_taskQueue.enqueueTask(

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h (250541 => 250542)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -114,7 +114,7 @@
     MediaKeySessionType m_sessionType;
     Ref<CDM> m_implementation;
     Ref<CDMInstanceSession> m_instanceSession;
-    MainThreadGenericEventQueue m_eventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_eventQueue;
     GenericTaskQueue<Timer> m_taskQueue;
     Vector<Ref<SharedBuffer>> m_recordOfKeyUsage;
     double m_firstDecryptTime { 0 };

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp (250541 => 250542)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -54,7 +54,7 @@
     : ActiveDOMObject(&context)
     , m_keys(&keys)
     , m_keySystem(keySystem)
-    , m_asyncEventQueue(*this)
+    , m_asyncEventQueue(MainThreadGenericEventQueue::create(*this))
     , m_session(keys.cdm().createSession(*this))
     , m_keyRequestTimer(*this, &WebKitMediaKeySession::keyRequestTimerFired)
     , m_addKeyTimer(*this, &WebKitMediaKeySession::addKeyTimerFired)
@@ -68,7 +68,7 @@
     if (m_session)
         m_session->setClient(nullptr);
 
-    m_asyncEventQueue.cancelAllEvents();
+    m_asyncEventQueue->cancelAllEvents();
 }
 
 void WebKitMediaKeySession::close()
@@ -183,7 +183,7 @@
         if (didStoreKey) {
             auto keyaddedEvent = Event::create(eventNames().webkitkeyaddedEvent, Event::CanBubble::No, Event::IsCancelable::No);
             keyaddedEvent->setTarget(this);
-            m_asyncEventQueue.enqueueEvent(WTFMove(keyaddedEvent));
+            m_asyncEventQueue->enqueueEvent(WTFMove(keyaddedEvent));
 
             ASSERT(m_keys);
             m_keys->keyAdded();
@@ -207,7 +207,7 @@
 {
     auto event = WebKitMediaKeyMessageEvent::create(eventNames().webkitkeymessageEvent, message, destinationURL);
     event->setTarget(this);
-    m_asyncEventQueue.enqueueEvent(WTFMove(event));
+    m_asyncEventQueue->enqueueEvent(WTFMove(event));
 }
 
 void WebKitMediaKeySession::sendError(MediaKeyErrorCode errorCode, uint32_t systemCode)
@@ -216,7 +216,7 @@
 
     auto keyerrorEvent = Event::create(eventNames().webkitkeyerrorEvent, Event::CanBubble::No, Event::IsCancelable::No);
     keyerrorEvent->setTarget(this);
-    m_asyncEventQueue.enqueueEvent(WTFMove(keyerrorEvent));
+    m_asyncEventQueue->enqueueEvent(WTFMove(keyerrorEvent));
 }
 
 String WebKitMediaKeySession::mediaKeysStorageDirectory() const
@@ -238,22 +238,11 @@
 
 bool WebKitMediaKeySession::hasPendingActivity() const
 {
-    return (m_keys && m_session) || m_asyncEventQueue.hasPendingEvents();
+    return (m_keys && m_session) || m_asyncEventQueue->hasPendingEvents();
 }
 
-void WebKitMediaKeySession::suspend(ReasonForSuspension)
-{
-    ASSERT_NOT_REACHED();
-}
-
-void WebKitMediaKeySession::resume()
-{
-    ASSERT_NOT_REACHED();
-}
-
 void WebKitMediaKeySession::stop()
 {
-    m_asyncEventQueue.close();
     close();
 }
 

Modified: trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h (250541 => 250542)


--- trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -77,8 +77,6 @@
     void refEventTarget() final { ref(); }
     void derefEventTarget() final { deref(); }
 
-    void suspend(ReasonForSuspension) final;
-    void resume() final;
     void stop() final;
     bool canSuspendForDocumentSuspension() const final;
     const char* activeDOMObjectName() const final;
@@ -90,7 +88,7 @@
     String m_keySystem;
     String m_sessionId;
     RefPtr<WebKitMediaKeyError> m_error;
-    MainThreadGenericEventQueue m_asyncEventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_asyncEventQueue;
     std::unique_ptr<LegacyCDMSession> m_session;
 
     struct PendingKeyRequest {

Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (250541 => 250542)


--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -101,7 +101,7 @@
     : ActiveDOMObject(&context)
     , m_duration(MediaTime::invalidTime())
     , m_pendingSeekTime(MediaTime::invalidTime())
-    , m_asyncEventQueue(*this)
+    , m_asyncEventQueue(MainThreadGenericEventQueue::create(*this))
 #if !RELEASE_LOG_DISABLED
     , m_logger(downcast<Document>(context).logger())
 #endif
@@ -973,38 +973,14 @@
 
 bool MediaSource::hasPendingActivity() const
 {
-    return m_private || m_asyncEventQueue.hasPendingEvents()
+    return m_private || m_asyncEventQueue->hasPendingEvents()
         || ActiveDOMObject::hasPendingActivity();
 }
 
-void MediaSource::suspend(ReasonForSuspension reason)
-{
-    ALWAYS_LOG(LOGIDENTIFIER, static_cast<int>(reason));
-
-    switch (reason) {
-    case ReasonForSuspension::PageCache:
-    case ReasonForSuspension::PageWillBeSuspended:
-        m_asyncEventQueue.suspend();
-        break;
-    case ReasonForSuspension::_javascript_DebuggerPaused:
-    case ReasonForSuspension::WillDeferLoading:
-        // Do nothing, we don't pause media playback in these cases.
-        break;
-    }
-}
-
-void MediaSource::resume()
-{
-    ALWAYS_LOG(LOGIDENTIFIER);
-
-    m_asyncEventQueue.resume();
-}
-
 void MediaSource::stop()
 {
     ALWAYS_LOG(LOGIDENTIFIER);
 
-    m_asyncEventQueue.close();
     if (m_mediaElement)
         m_mediaElement->detachMediaSource();
     m_readyState = ReadyState::Closed;
@@ -1013,7 +989,8 @@
 
 bool MediaSource::canSuspendForDocumentSuspension() const
 {
-    return isClosed() && !m_asyncEventQueue.hasPendingEvents();
+    // FIXME: Do better.
+    return isClosed();
 }
 
 const char* MediaSource::activeDOMObjectName() const
@@ -1080,7 +1057,7 @@
     auto event = Event::create(eventName, Event::CanBubble::No, Event::IsCancelable::No);
     event->setTarget(this);
 
-    m_asyncEventQueue.enqueueEvent(WTFMove(event));
+    m_asyncEventQueue->enqueueEvent(WTFMove(event));
 }
 
 ScriptExecutionContext* MediaSource::scriptExecutionContext() const

Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.h (250541 => 250542)


--- trunk/Source/WebCore/Modules/mediasource/MediaSource.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -126,8 +126,6 @@
 private:
     explicit MediaSource(ScriptExecutionContext&);
 
-    void suspend(ReasonForSuspension) final;
-    void resume() final;
     void stop() final;
     bool canSuspendForDocumentSuspension() const final;
     const char* activeDOMObjectName() const final;
@@ -168,7 +166,7 @@
     MediaTime m_duration;
     MediaTime m_pendingSeekTime;
     ReadyState m_readyState { ReadyState::Closed };
-    MainThreadGenericEventQueue m_asyncEventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_asyncEventQueue;
 #if !RELEASE_LOG_DISABLED
     Ref<const Logger> m_logger;
     const void* m_logIdentifier { nullptr };

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (250541 => 250542)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -107,7 +107,7 @@
     : ActiveDOMObject(source->scriptExecutionContext())
     , m_private(WTFMove(sourceBufferPrivate))
     , m_source(source)
-    , m_asyncEventQueue(*this)
+    , m_asyncEventQueue(MainThreadGenericEventQueue::create(*this))
     , m_appendBufferTimer(*this, &SourceBuffer::appendBufferTimerFired)
     , m_appendWindowStart(MediaTime::zeroTime())
     , m_appendWindowEnd(MediaTime::positiveInfiniteTime())
@@ -528,31 +528,11 @@
 
 bool SourceBuffer::hasPendingActivity() const
 {
-    return m_source || m_asyncEventQueue.hasPendingEvents();
+    return m_source || m_asyncEventQueue->hasPendingEvents();
 }
 
-void SourceBuffer::suspend(ReasonForSuspension reason)
-{
-    switch (reason) {
-    case ReasonForSuspension::PageCache:
-    case ReasonForSuspension::PageWillBeSuspended:
-        m_asyncEventQueue.suspend();
-        break;
-    case ReasonForSuspension::_javascript_DebuggerPaused:
-    case ReasonForSuspension::WillDeferLoading:
-        // Do nothing, we don't pause media playback in these cases.
-        break;
-    }
-}
-
-void SourceBuffer::resume()
-{
-    m_asyncEventQueue.resume();
-}
-
 void SourceBuffer::stop()
 {
-    m_asyncEventQueue.close();
     m_appendBufferTimer.stop();
     m_removeTimer.stop();
 }
@@ -577,7 +557,7 @@
     auto event = Event::create(eventName, Event::CanBubble::No, Event::IsCancelable::No);
     event->setTarget(this);
 
-    m_asyncEventQueue.enqueueEvent(WTFMove(event));
+    m_asyncEventQueue->enqueueEvent(WTFMove(event));
 }
 
 ExceptionOr<void> SourceBuffer::appendBufferInternal(const unsigned char* data, unsigned size)

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h (250541 => 250542)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -144,8 +144,6 @@
     void refEventTarget() final { ref(); }
     void derefEventTarget() final { deref(); }
 
-    void suspend(ReasonForSuspension) final;
-    void resume() final;
     void stop() final;
     const char* activeDOMObjectName() const final;
     bool canSuspendForDocumentSuspension() const final;
@@ -217,7 +215,7 @@
 
     Ref<SourceBufferPrivate> m_private;
     MediaSource* m_source;
-    MainThreadGenericEventQueue m_asyncEventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_asyncEventQueue;
     AppendMode m_mode { AppendMode::Segments };
 
     Vector<unsigned char> m_pendingAppendData;

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp (250541 => 250542)


--- trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -44,7 +44,7 @@
 
 SourceBufferList::SourceBufferList(ScriptExecutionContext* context)
     : ActiveDOMObject(context)
-    , m_asyncEventQueue(*this)
+    , m_asyncEventQueue(MainThreadGenericEventQueue::create(*this))
 {
     suspendIfNeeded();
 }
@@ -98,38 +98,14 @@
     auto event = Event::create(eventName, Event::CanBubble::No, Event::IsCancelable::No);
     event->setTarget(this);
 
-    m_asyncEventQueue.enqueueEvent(WTFMove(event));
+    m_asyncEventQueue->enqueueEvent(WTFMove(event));
 }
 
 bool SourceBufferList::canSuspendForDocumentSuspension() const
 {
-    return !m_asyncEventQueue.hasPendingEvents();
+    return !m_asyncEventQueue->hasPendingEvents();
 }
 
-void SourceBufferList::suspend(ReasonForSuspension reason)
-{
-    switch (reason) {
-    case ReasonForSuspension::PageCache:
-    case ReasonForSuspension::PageWillBeSuspended:
-        m_asyncEventQueue.suspend();
-        break;
-    case ReasonForSuspension::_javascript_DebuggerPaused:
-    case ReasonForSuspension::WillDeferLoading:
-        // Do nothing, we don't pause media playback in these cases.
-        break;
-    }
-}
-
-void SourceBufferList::resume()
-{
-    m_asyncEventQueue.resume();
-}
-
-void SourceBufferList::stop()
-{
-    m_asyncEventQueue.close();
-}
-
 const char* SourceBufferList::activeDOMObjectName() const
 {
     return "SourceBufferList";

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h (250541 => 250542)


--- trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -79,12 +79,9 @@
     void derefEventTarget() override { deref(); }
 
     bool canSuspendForDocumentSuspension() const final;
-    void suspend(ReasonForSuspension) final;
-    void resume() final;
-    void stop() final;
     const char* activeDOMObjectName() const final;
 
-    MainThreadGenericEventQueue m_asyncEventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_asyncEventQueue;
 
     Vector<RefPtr<SourceBuffer>> m_list;
 };

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (250541 => 250542)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -140,7 +140,7 @@
     , m_logIdentifier(uniqueLogIdentifier())
 #endif
     , m_mediaSession(PlatformMediaSession::create(*this))
-    , m_eventQueue(makeUnique<MainThreadGenericEventQueue>(*this))
+    , m_eventQueue(MainThreadGenericEventQueue::create(*this))
 {
     // According to spec AudioContext must die only after page navigate.
     // Lets mark it as ActiveDOMObject with pending activity and unmark it in clear method.
@@ -166,7 +166,7 @@
 #endif
     , m_isOfflineContext(true)
     , m_mediaSession(PlatformMediaSession::create(*this))
-    , m_eventQueue(makeUnique<MainThreadGenericEventQueue>(*this))
+    , m_eventQueue(MainThreadGenericEventQueue::create(*this))
 {
     constructCommon();
 
@@ -336,8 +336,6 @@
     ASSERT(document());
     document()->updateIsPlayingMedia();
 
-    m_eventQueue->close();
-
     uninitialize();
     clear();
 }

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (250541 => 250542)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -45,6 +45,7 @@
 #include <wtf/RefPtr.h>
 #include <wtf/ThreadSafeRefCounted.h>
 #include <wtf/Threading.h>
+#include <wtf/UniqueRef.h>
 #include <wtf/Vector.h>
 #include <wtf/text/AtomStringHash.h>
 
@@ -417,7 +418,7 @@
     Vector<Vector<DOMPromiseDeferred<void>>> m_stateReactions;
 
     std::unique_ptr<PlatformMediaSession> m_mediaSession;
-    std::unique_ptr<MainThreadGenericEventQueue> m_eventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_eventQueue;
 
     RefPtr<AudioBuffer> m_renderTarget;
     RefPtr<AudioDestinationNode> m_destinationNode;

Modified: trunk/Source/WebCore/animation/DeclarativeAnimation.cpp (250541 => 250542)


--- trunk/Source/WebCore/animation/DeclarativeAnimation.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/animation/DeclarativeAnimation.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -44,7 +44,7 @@
 
 DeclarativeAnimation::DeclarativeAnimation(Element& owningElement, const Animation& backingAnimation)
     : WebAnimation(owningElement.document())
-    , m_eventQueue(owningElement)
+    , m_eventQueue(MainThreadGenericEventQueue::create(owningElement))
     , m_owningElement(&owningElement)
     , m_backingAnimation(const_cast<Animation&>(backingAnimation))
 {
@@ -67,7 +67,7 @@
     // maps containing running CSS Transitions and CSS Animations for a given element.
     if (wasRelevant && playState() == WebAnimation::PlayState::Idle) {
         disassociateFromOwningElement();
-        m_eventQueue.close();
+        m_eventQueue->close();
     }
 }
 
@@ -83,12 +83,12 @@
 
 bool DeclarativeAnimation::needsTick() const
 {
-    return WebAnimation::needsTick() || m_eventQueue.hasPendingEvents();
+    return WebAnimation::needsTick() || m_eventQueue->hasPendingEvents();
 }
 
 void DeclarativeAnimation::remove()
 {
-    m_eventQueue.close();
+    m_eventQueue->close();
     WebAnimation::remove();
 }
 
@@ -335,26 +335,23 @@
     ASSERT(m_owningElement);
     auto time = secondsToWebAnimationsAPITime(elapsedTime) / 1000;
     if (is<CSSAnimation>(this))
-        m_eventQueue.enqueueEvent(AnimationEvent::create(eventType, downcast<CSSAnimation>(this)->animationName(), time));
+        m_eventQueue->enqueueEvent(AnimationEvent::create(eventType, downcast<CSSAnimation>(this)->animationName(), time));
     else if (is<CSSTransition>(this))
-        m_eventQueue.enqueueEvent(TransitionEvent::create(eventType, downcast<CSSTransition>(this)->transitionProperty(), time, PseudoElement::pseudoElementNameForEvents(m_owningElement->pseudoId())));
+        m_eventQueue->enqueueEvent(TransitionEvent::create(eventType, downcast<CSSTransition>(this)->transitionProperty(), time, PseudoElement::pseudoElementNameForEvents(m_owningElement->pseudoId())));
 }
 
 void DeclarativeAnimation::stop()
 {
-    m_eventQueue.close();
     WebAnimation::stop();
 }
 
 void DeclarativeAnimation::suspend(ReasonForSuspension reason)
 {
-    m_eventQueue.suspend();
     WebAnimation::suspend(reason);
 }
 
 void DeclarativeAnimation::resume()
 {
-    m_eventQueue.resume();
     WebAnimation::resume();
 }
 

Modified: trunk/Source/WebCore/animation/DeclarativeAnimation.h (250541 => 250542)


--- trunk/Source/WebCore/animation/DeclarativeAnimation.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/animation/DeclarativeAnimation.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -88,7 +88,7 @@
     bool m_wasPending { false };
     AnimationEffectPhase m_previousPhase { AnimationEffectPhase::Idle };
 
-    MainThreadGenericEventQueue m_eventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_eventQueue;
 
     Element* m_owningElement;
     Ref<Animation> m_backingAnimation;

Modified: trunk/Source/WebCore/dom/GenericEventQueue.cpp (250541 => 250542)


--- trunk/Source/WebCore/dom/GenericEventQueue.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/dom/GenericEventQueue.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -46,7 +46,8 @@
 
 template<typename T>
 GenericEventQueueBase<T>::GenericEventQueueBase(EventTarget& owner)
-    : m_owner(owner)
+    : ActiveDOMObject(owner.scriptExecutionContext())
+    , m_owner(owner)
     , m_taskQueue(TaskQueueConstructor<T>::construct(owner.scriptExecutionContext()))
 {
 }
@@ -65,7 +66,7 @@
 
     m_pendingEvents.append(WTFMove(event));
 
-    if (m_isSuspended)
+    if (isSuspendedOrPausedByClient())
         return;
 
     m_taskQueue.enqueueTask(std::bind(&GenericEventQueueBase::dispatchOneEvent, this));
@@ -119,9 +120,30 @@
 }
 
 template<typename T>
-void GenericEventQueueBase<T>::suspend()
+void GenericEventQueueBase<T>::setPaused(bool shouldPause)
 {
-    ASSERT(!m_isSuspended);
+    if (m_isPausedByClient == shouldPause)
+        return;
+
+    m_isPausedByClient = shouldPause;
+    if (shouldPause)
+        m_taskQueue.cancelAllTasks();
+    else
+        rescheduleAllEventsIfNeeded();
+}
+
+template<typename T>
+bool GenericEventQueueBase<T>::canSuspendForDocumentSuspension() const
+{
+    return true;
+}
+
+template<typename T>
+void GenericEventQueueBase<T>::suspend(ReasonForSuspension)
+{
+    if (m_isSuspended)
+        return;
+
     m_isSuspended = true;
     m_taskQueue.cancelAllTasks();
 }
@@ -133,12 +155,46 @@
         return;
 
     m_isSuspended = false;
+    rescheduleAllEventsIfNeeded();
+}
 
+template<typename T>
+void GenericEventQueueBase<T>::rescheduleAllEventsIfNeeded()
+{
+    if (isSuspendedOrPausedByClient())
+        return;
+
     for (unsigned i = 0; i < m_pendingEvents.size(); ++i)
         m_taskQueue.enqueueTask(std::bind(&GenericEventQueueBase::dispatchOneEvent, this));
 }
 
+template<typename T>
+void GenericEventQueueBase<T>::stop()
+{
+    close();
+}
+
+template<typename T>
+const char* GenericEventQueueBase<T>::activeDOMObjectName() const
+{
+    return "GenericEventQueueBase";
+}
+
 template class GenericEventQueueBase<Timer>;
 template class GenericEventQueueBase<ScriptExecutionContext>;
 
+UniqueRef<GenericEventQueue> GenericEventQueue::create(EventTarget& eventTarget)
+{
+    auto eventQueue = makeUniqueRef<GenericEventQueue>(eventTarget);
+    eventQueue->suspendIfNeeded();
+    return eventQueue;
 }
+
+UniqueRef<MainThreadGenericEventQueue> MainThreadGenericEventQueue::create(EventTarget& eventTarget)
+{
+    auto eventQueue = makeUniqueRef<MainThreadGenericEventQueue>(eventTarget);
+    eventQueue->suspendIfNeeded();
+    return eventQueue;
+}
+
+}

Modified: trunk/Source/WebCore/dom/GenericEventQueue.h (250541 => 250542)


--- trunk/Source/WebCore/dom/GenericEventQueue.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/dom/GenericEventQueue.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -25,10 +25,12 @@
 
 #pragma once
 
+#include "ActiveDOMObject.h"
 #include "GenericTaskQueue.h"
 #include <wtf/Deque.h>
 #include <wtf/Forward.h>
 #include <wtf/RefPtr.h>
+#include <wtf/UniqueRef.h>
 
 namespace WebCore {
 
@@ -38,7 +40,7 @@
 class ScriptExecutionContext;
 
 template<typename T>
-class GenericEventQueueBase {
+class GenericEventQueueBase : public ActiveDOMObject {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     explicit GenericEventQueueBase(EventTarget&);
@@ -51,8 +53,7 @@
     bool hasPendingEvents() const;
     bool hasPendingEventsOfType(const AtomString&) const;
 
-    void suspend();
-    void resume();
+    void setPaused(bool);
 
     bool isSuspended() const { return m_isSuspended; }
 
@@ -59,10 +60,20 @@
 private:
     void dispatchOneEvent();
 
+    const char* activeDOMObjectName() const final;
+    bool canSuspendForDocumentSuspension() const final;
+    void stop() final;
+    void suspend(ReasonForSuspension) final;
+    void resume() final;
+
+    void rescheduleAllEventsIfNeeded();
+    bool isSuspendedOrPausedByClient() const { return m_isSuspended || m_isPausedByClient; }
+
     EventTarget& m_owner;
     GenericTaskQueue<T> m_taskQueue;
     Deque<RefPtr<Event>> m_pendingEvents;
     bool m_isClosed { false };
+    bool m_isPausedByClient { false };
     bool m_isSuspended { false };
 };
 
@@ -69,6 +80,10 @@
 // All instances of MainThreadGenericEventQueue use a shared Timer for dispatching events.
 class MainThreadGenericEventQueue : public GenericEventQueueBase<Timer> {
 public:
+    static UniqueRef<MainThreadGenericEventQueue> create(EventTarget&);
+
+private:
+    friend UniqueRef<MainThreadGenericEventQueue> WTF::makeUniqueRefWithoutFastMallocCheck<MainThreadGenericEventQueue, WebCore::EventTarget&>(WebCore::EventTarget&);
     explicit MainThreadGenericEventQueue(EventTarget& eventTarget)
         : GenericEventQueueBase<Timer>(eventTarget)
     {
@@ -78,6 +93,10 @@
 class GenericEventQueue : public GenericEventQueueBase<ScriptExecutionContext> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
+    static UniqueRef<GenericEventQueue> create(EventTarget&);
+
+private:
+    friend UniqueRef<GenericEventQueue> WTF::makeUniqueRefWithoutFastMallocCheck<GenericEventQueue, WebCore::EventTarget&>(WebCore::EventTarget&);
     explicit GenericEventQueue(EventTarget& eventTarget)
         : GenericEventQueueBase<ScriptExecutionContext>(eventTarget)
     {

Modified: trunk/Source/WebCore/dom/MessagePort.cpp (250541 => 250542)


--- trunk/Source/WebCore/dom/MessagePort.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/dom/MessagePort.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -98,7 +98,7 @@
     : ActiveDOMObject(&scriptExecutionContext)
     , m_identifier(local)
     , m_remoteIdentifier(remote)
-    , m_eventQueue(*this)
+    , m_eventQueue(GenericEventQueue::create(*this))
 {
     LOG(MessagePorts, "Created MessagePort %s (%p) in process %" PRIu64, m_identifier.logString().utf8().data(), this, Process::identifier().toUInt64());
 
@@ -228,19 +228,9 @@
 
     MessagePortChannelProvider::fromContext(*m_scriptExecutionContext).messagePortClosed(m_identifier);
     removeAllEventListeners();
-    m_eventQueue.close();
+    m_eventQueue->close();
 }
 
-void MessagePort::suspend(ReasonForSuspension)
-{
-    m_eventQueue.suspend();
-}
-
-void MessagePort::resume()
-{
-    m_eventQueue.resume();
-}
-
 void MessagePort::contextDestroyed()
 {
     ASSERT(m_scriptExecutionContext);
@@ -280,7 +270,7 @@
             if (contextIsWorker && downcast<WorkerGlobalScope>(*m_scriptExecutionContext).isClosing())
                 return;
             auto ports = MessagePort::entanglePorts(*m_scriptExecutionContext, WTFMove(message.transferredPorts));
-            m_eventQueue.enqueueEvent(MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
+            m_eventQueue->enqueueEvent(MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
         }
     };
 

Modified: trunk/Source/WebCore/dom/MessagePort.h (250541 => 250542)


--- trunk/Source/WebCore/dom/MessagePort.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/dom/MessagePort.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -85,8 +85,6 @@
     // ActiveDOMObject
     const char* activeDOMObjectName() const final;
     bool canSuspendForDocumentSuspension() const final;
-    void suspend(ReasonForSuspension) final;
-    void resume() final;
     void contextDestroyed() final;
     void stop() final { close(); }
     bool hasPendingActivity() const final;
@@ -129,7 +127,7 @@
     MessagePortIdentifier m_remoteIdentifier;
 
     mutable std::atomic<unsigned> m_refCount { 1 };
-    GenericEventQueue m_eventQueue;
+    UniqueRef<GenericEventQueue> m_eventQueue;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (250541 => 250542)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -426,7 +426,7 @@
     , m_scanTimer(*this, &HTMLMediaElement::scanTimerFired)
     , m_playbackControlsManagerBehaviorRestrictionsTimer(*this, &HTMLMediaElement::playbackControlsManagerBehaviorRestrictionsTimerFired)
     , m_seekToPlaybackPositionEndedTimer(*this, &HTMLMediaElement::seekToPlaybackPositionEndedTimerFired)
-    , m_asyncEventQueue(*this)
+    , m_asyncEventQueue(MainThreadGenericEventQueue::create(*this))
     , m_lastTimeUpdateEventMovieTime(MediaTime::positiveInfiniteTime())
     , m_firstTimePlaying(true)
     , m_playing(false)
@@ -572,7 +572,7 @@
     beginIgnoringTrackDisplayUpdateRequests();
     allMediaElements().remove(this);
 
-    m_asyncEventQueue.close();
+    m_asyncEventQueue->close();
 
     setShouldDelayLoadEvent(false);
     unregisterWithDocument(document());
@@ -1021,7 +1021,7 @@
     // Don't set the event target, the event queue will set it in GenericEventQueue::timerFired and setting it here
     // will trigger an ASSERT if this element has been marked for deletion.
 
-    m_asyncEventQueue.enqueueEvent(WTFMove(event));
+    m_asyncEventQueue->enqueueEvent(WTFMove(event));
 }
 
 void HTMLMediaElement::scheduleResolvePendingPlayPromises()
@@ -1849,11 +1849,11 @@
         if (eventTask.second->startTime() >= eventTask.second->endTime()) {
             auto enterEvent = Event::create(eventNames().enterEvent, Event::CanBubble::No, Event::IsCancelable::No);
             enterEvent->setTarget(eventTask.second);
-            m_asyncEventQueue.enqueueEvent(WTFMove(enterEvent));
+            m_asyncEventQueue->enqueueEvent(WTFMove(enterEvent));
 
             auto exitEvent = Event::create(eventNames().exitEvent, Event::CanBubble::No, Event::IsCancelable::No);
             exitEvent->setTarget(eventTask.second);
-            m_asyncEventQueue.enqueueEvent(WTFMove(exitEvent));
+            m_asyncEventQueue->enqueueEvent(WTFMove(exitEvent));
         } else {
             RefPtr<Event> event;
             if (eventTask.first == eventTask.second->startMediaTime())
@@ -1861,7 +1861,7 @@
             else
                 event = Event::create(eventNames().exitEvent, Event::CanBubble::No, Event::IsCancelable::No);
             event->setTarget(eventTask.second);
-            m_asyncEventQueue.enqueueEvent(WTFMove(event));
+            m_asyncEventQueue->enqueueEvent(WTFMove(event));
         }
     }
 
@@ -1874,7 +1874,7 @@
     for (auto& affectedTrack : affectedTracks) {
         auto event = Event::create(eventNames().cuechangeEvent, Event::CanBubble::No, Event::IsCancelable::No);
         event->setTarget(affectedTrack);
-        m_asyncEventQueue.enqueueEvent(WTFMove(event));
+        m_asyncEventQueue->enqueueEvent(WTFMove(event));
 
         // ... if the text track has a corresponding track element, to then fire a
         // simple event named cuechange at the track element as well.
@@ -1883,7 +1883,7 @@
             auto trackElement = makeRefPtr(downcast<LoadableTextTrack>(*affectedTrack).trackElement());
             ASSERT(trackElement);
             event->setTarget(trackElement);
-            m_asyncEventQueue.enqueueEvent(WTFMove(event));
+            m_asyncEventQueue->enqueueEvent(WTFMove(event));
         }
     }
 
@@ -2223,7 +2223,7 @@
 void HTMLMediaElement::cancelPendingEventsAndCallbacks()
 {
     INFO_LOG(LOGIDENTIFIER);
-    m_asyncEventQueue.cancelAllEvents();
+    m_asyncEventQueue->cancelAllEvents();
 
     for (auto& source : childrenOfType<HTMLSourceElement>(*this))
         source.cancelPendingErrorEvent();
@@ -2614,7 +2614,7 @@
 
     auto event = WebKitMediaKeyNeededEvent::create(eventNames().webkitneedkeyEvent, initData);
     event->setTarget(this);
-    m_asyncEventQueue.enqueueEvent(WTFMove(event));
+    m_asyncEventQueue->enqueueEvent(WTFMove(event));
 
     return true;
 }
@@ -2761,7 +2761,7 @@
     //      initDataType = initDataType
     //      initData = initData
     MediaEncryptedEventInit initializer { initDataType, WTFMove(initData) };
-    m_asyncEventQueue.enqueueEvent(MediaEncryptedEvent::create(eventNames().encryptedEvent, initializer, Event::IsTrusted::Yes));
+    m_asyncEventQueue->enqueueEvent(MediaEncryptedEvent::create(eventNames().encryptedEvent, initializer, Event::IsTrusted::Yes));
 }
 
 void HTMLMediaElement::mediaPlayerWaitingForKeyChanged()
@@ -5720,7 +5720,7 @@
 #if ENABLE(ENCRYPTED_MEDIA)
     m_encryptedMediaQueue.close();
 #endif
-    m_asyncEventQueue.close();
+    m_asyncEventQueue->close();
 #if PLATFORM(IOS_FAMILY)
     m_volumeRevertTaskQueue.close();
 #endif
@@ -5761,7 +5761,6 @@
     switch (reason) {
     case ReasonForSuspension::PageCache:
         stopWithoutDestroyingMediaPlayer();
-        m_asyncEventQueue.suspend();
         setBufferingPolicy(BufferingPolicy::MakeResourcesPurgeable);
         m_mediaSession->addBehaviorRestriction(MediaElementSession::RequirePageConsentToResumeMedia);
         break;
@@ -5779,8 +5778,6 @@
 
     setInActiveDocument(true);
 
-    m_asyncEventQueue.resume();
-
     if (!m_mediaSession->pageAllowsPlaybackAfterResuming())
         document().addMediaCanStartListener(*this);
     else
@@ -5803,7 +5800,7 @@
 
 bool HTMLMediaElement::hasPendingActivity() const
 {
-    return (hasAudio() && isPlaying()) || m_asyncEventQueue.hasPendingEvents() || m_creatingControls;
+    return (hasAudio() && isPlaying()) || m_asyncEventQueue->hasPendingEvents() || m_creatingControls;
 }
 
 void HTMLMediaElement::mediaVolumeDidChange()
@@ -5952,7 +5949,7 @@
     INFO_LOG(LOGIDENTIFIER, "hasTargets = ", hasTargets);
     auto event = WebKitPlaybackTargetAvailabilityEvent::create(eventNames().webkitplaybacktargetavailabilitychangedEvent, hasTargets);
     event->setTarget(this);
-    m_asyncEventQueue.enqueueEvent(WTFMove(event));
+    m_asyncEventQueue->enqueueEvent(WTFMove(event));
     scheduleUpdateMediaState();
 }
 

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (250541 => 250542)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -972,7 +972,7 @@
     GenericTaskQueue<Timer> m_fullscreenTaskQueue;
     GenericTaskQueue<Timer> m_playbackTargetIsWirelessQueue;
     RefPtr<TimeRanges> m_playedTimeRanges;
-    MainThreadGenericEventQueue m_asyncEventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_asyncEventQueue;
 #if PLATFORM(IOS_FAMILY)
     DeferrableTask<Timer> m_volumeRevertTaskQueue;
 #endif

Modified: trunk/Source/WebCore/html/track/TrackListBase.cpp (250541 => 250542)


--- trunk/Source/WebCore/html/track/TrackListBase.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/html/track/TrackListBase.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -42,7 +42,7 @@
 TrackListBase::TrackListBase(HTMLMediaElement* element, ScriptExecutionContext* context)
     : ActiveDOMObject(context)
     , m_element(element)
-    , m_asyncEventQueue(*this)
+    , m_asyncEventQueue(MainThreadGenericEventQueue::create(*this))
 {
     ASSERT(!context || is<Document>(context));
     suspendIfNeeded();
@@ -98,7 +98,7 @@
 
 void TrackListBase::scheduleTrackEvent(const AtomString& eventName, Ref<TrackBase>&& track)
 {
-    m_asyncEventQueue.enqueueEvent(TrackEvent::create(eventName, Event::CanBubble::No, Event::IsCancelable::No, WTFMove(track)));
+    m_asyncEventQueue->enqueueEvent(TrackEvent::create(eventName, Event::CanBubble::No, Event::IsCancelable::No, WTFMove(track)));
 }
 
 void TrackListBase::scheduleAddTrackEvent(Ref<TrackBase>&& track)
@@ -161,12 +161,12 @@
     // Whenever a track in a VideoTrackList that was previously not selected is
     // selected, the user agent must queue a task to fire a simple event named
     // change at the VideoTrackList object.
-    m_asyncEventQueue.enqueueEvent(Event::create(eventNames().changeEvent, Event::CanBubble::No, Event::IsCancelable::No));
+    m_asyncEventQueue->enqueueEvent(Event::create(eventNames().changeEvent, Event::CanBubble::No, Event::IsCancelable::No));
 }
 
 bool TrackListBase::isChangeEventScheduled() const
 {
-    return m_asyncEventQueue.hasPendingEventsOfType(eventNames().changeEvent);
+    return m_asyncEventQueue->hasPendingEventsOfType(eventNames().changeEvent);
 }
 
 bool TrackListBase::isAnyTrackEnabled() const
@@ -180,33 +180,9 @@
 
 bool TrackListBase::canSuspendForDocumentSuspension() const
 {
-    return !m_asyncEventQueue.hasPendingEvents();
+    return true;
 }
 
-void TrackListBase::suspend(ReasonForSuspension reason)
-{
-    switch (reason) {
-    case ReasonForSuspension::PageCache:
-    case ReasonForSuspension::PageWillBeSuspended:
-        m_asyncEventQueue.suspend();
-        break;
-    case ReasonForSuspension::_javascript_DebuggerPaused:
-    case ReasonForSuspension::WillDeferLoading:
-        // Do nothing, we don't pause media playback in these cases.
-        break;
-    }
-}
-
-void TrackListBase::resume()
-{
-    m_asyncEventQueue.resume();
-}
-
-void TrackListBase::stop()
-{
-    m_asyncEventQueue.close();
-}
-
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/html/track/TrackListBase.h (250541 => 250542)


--- trunk/Source/WebCore/html/track/TrackListBase.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/html/track/TrackListBase.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -76,9 +76,6 @@
     void scheduleTrackEvent(const AtomString& eventName, Ref<TrackBase>&&);
 
     bool canSuspendForDocumentSuspension() const final;
-    void suspend(ReasonForSuspension) final;
-    void resume() final;
-    void stop() final;
 
     // EventTarget
     void refEventTarget() final { ref(); }
@@ -86,7 +83,7 @@
 
     HTMLMediaElement* m_element;
 
-    MainThreadGenericEventQueue m_asyncEventQueue;
+    UniqueRef<MainThreadGenericEventQueue> m_asyncEventQueue;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/Worker.cpp (250541 => 250542)


--- trunk/Source/WebCore/workers/Worker.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/workers/Worker.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -68,7 +68,7 @@
     , m_identifier("worker:" + Inspector::IdentifiersFactory::createIdentifier())
     , m_contextProxy(WorkerGlobalScopeProxy::create(*this))
     , m_runtimeFlags(runtimeFlags)
-    , m_eventQueue(*this)
+    , m_eventQueue(GenericEventQueue::create(*this))
 {
     static bool addedListener;
     if (!addedListener) {
@@ -146,7 +146,7 @@
 void Worker::terminate()
 {
     m_contextProxy.terminateWorkerGlobalScope();
-    m_eventQueue.cancelAllEvents();
+    m_eventQueue->cancelAllEvents();
 }
 
 bool Worker::canSuspendForDocumentSuspension() const
@@ -154,16 +154,6 @@
     return true;
 }
 
-void Worker::suspend(ReasonForSuspension)
-{
-    m_eventQueue.suspend();
-}
-
-void Worker::resume()
-{
-    m_eventQueue.resume();
-}
-
 const char* Worker::activeDOMObjectName() const
 {
     return "Worker";
@@ -172,12 +162,11 @@
 void Worker::stop()
 {
     terminate();
-    m_eventQueue.close();
 }
 
 bool Worker::hasPendingActivity() const
 {
-    return m_contextProxy.hasPendingActivity() || ActiveDOMObject::hasPendingActivity() || m_eventQueue.hasPendingEvents();
+    return m_contextProxy.hasPendingActivity() || ActiveDOMObject::hasPendingActivity() || m_eventQueue->hasPendingEvents();
 }
 
 void Worker::notifyNetworkStateChange(bool isOnLine)
@@ -217,12 +206,12 @@
 
 void Worker::enqueueEvent(Ref<Event>&& event)
 {
-    m_eventQueue.enqueueEvent(WTFMove(event));
+    m_eventQueue->enqueueEvent(WTFMove(event));
 }
 
 void Worker::dispatchEvent(Event& event)
 {
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!m_eventQueue.isSuspended());
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!m_eventQueue->isSuspended());
 
     AbstractWorker::dispatchEvent(event);
     if (is<ErrorEvent>(event) && !event.defaultPrevented() && event.isTrusted() && scriptExecutionContext()) {

Modified: trunk/Source/WebCore/workers/Worker.h (250541 => 250542)


--- trunk/Source/WebCore/workers/Worker.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/workers/Worker.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -83,8 +83,6 @@
     void notifyFinished() final;
 
     bool canSuspendForDocumentSuspension() const final;
-    void suspend(ReasonForSuspension) final;
-    void resume() final;
     void stop() final;
     const char* activeDOMObjectName() const final;
 
@@ -98,7 +96,7 @@
     MonotonicTime m_workerCreationTime;
     bool m_shouldBypassMainWorldContentSecurityPolicy { false };
     JSC::RuntimeFlags m_runtimeFlags;
-    GenericEventQueue m_eventQueue;
+    UniqueRef<GenericEventQueue> m_eventQueue;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (250541 => 250542)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2019-10-01 03:36:01 UTC (rev 250542)
@@ -70,13 +70,13 @@
 ServiceWorkerContainer::ServiceWorkerContainer(ScriptExecutionContext* context, NavigatorBase& navigator)
     : ActiveDOMObject(context)
     , m_navigator(navigator)
-    , m_messageQueue(*this)
+    , m_messageQueue(GenericEventQueue::create(*this))
 {
     suspendIfNeeded();
     
     // We should queue messages until the DOMContentLoaded event has fired or startMessages() has been called.
     if (is<Document>(context) && downcast<Document>(*context).parsing())
-        m_messageQueue.suspend();
+        m_messageQueue->setPaused(true);
 }
 
 ServiceWorkerContainer::~ServiceWorkerContainer()
@@ -314,7 +314,7 @@
 
 void ServiceWorkerContainer::startMessages()
 {
-    m_messageQueue.resume();
+    m_messageQueue->setPaused(false);
 }
 
 void ServiceWorkerContainer::jobFailedWithException(ServiceWorkerJob& job, const Exception& exception)
@@ -413,7 +413,7 @@
 
     auto messageEvent = MessageEvent::create(MessagePort::entanglePorts(context, WTFMove(message.transferredPorts)), message.message.releaseNonNull(), sourceOrigin, { }, WTFMove(source));
     
-    m_messageQueue.enqueueEvent(WTFMove(messageEvent));
+    m_messageQueue->enqueueEvent(WTFMove(messageEvent));
 }
 
 void ServiceWorkerContainer::notifyRegistrationIsSettled(const ServiceWorkerRegistrationKey& registrationKey)
@@ -523,16 +523,6 @@
     return !hasPendingActivity();
 }
 
-void ServiceWorkerContainer::suspend(ReasonForSuspension)
-{
-    m_messageQueue.suspend();
-}
-
-void ServiceWorkerContainer::resume()
-{
-    m_messageQueue.resume();
-}
-
 SWClientConnection& ServiceWorkerContainer::ensureSWClientConnection()
 {
     ASSERT(scriptExecutionContext());
@@ -583,7 +573,6 @@
     m_isStopped = true;
     removeAllEventListeners();
     m_readyPromise = nullptr;
-    m_messageQueue.close();
     auto jobMap = WTFMove(m_jobMap);
     for (auto& ongoingJob : jobMap.values()) {
         if (ongoingJob.job->cancelPendingLoad())

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (250541 => 250542)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2019-10-01 03:23:58 UTC (rev 250541)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2019-10-01 03:36:01 UTC (rev 250542)
@@ -111,8 +111,6 @@
     // ActiveDOMObject.
     const char* activeDOMObjectName() const final;
     bool canSuspendForDocumentSuspension() const final;
-    void suspend(ReasonForSuspension) final;
-    void resume() final;
     
     ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
     EventTargetInterface eventTargetInterface() const final { return ServiceWorkerContainerEventTargetInterfaceType; }
@@ -143,8 +141,7 @@
 
     uint64_t m_lastOngoingSettledRegistrationIdentifier { 0 };
     HashMap<uint64_t, ServiceWorkerRegistrationKey> m_ongoingSettledRegistrations;
-    GenericEventQueue m_messageQueue;
-
+    UniqueRef<GenericEventQueue> m_messageQueue;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to