Tighten up EventQueue classes a bit, less indirection and memory allocation
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Sep 2013 16:58:20 +0000 (16:58 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Sep 2013 16:58:20 +0000 (16:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121016

Reviewed by Andreas Kling.

* Modules/encryptedmedia/MediaKeySession.cpp:
(WebCore::MediaKeySession::MediaKeySession): Updated since event queue is now
a member rather than an OwnPtr.
(WebCore::MediaKeySession::close): Ditto.
(WebCore::MediaKeySession::keyRequestTimerFired): Ditto.
(WebCore::MediaKeySession::addKeyTimerFired): Ditto.
* Modules/encryptedmedia/MediaKeySession.h: Ditto.

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::closeConnection): Updated since ScriptExecutionContext's
eventQueue function now returns a reference rather than a pointer. Also, the
cancelEvent function takes a reference instead of a pointer.
(WebCore::IDBDatabase::enqueueEvent): Ditto.
* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::abort): Ditto.
(WebCore::IDBRequest::enqueueEvent): Ditto.
* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::enqueueEvent): Ditto.

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::MediaSource): Updated since event queue is now a
member rather than an OwnPtr. Also use initialization instead of assignment
to set up source buffers.
(WebCore::MediaSource::hasPendingActivity): Ditto.
(WebCore::MediaSource::stop): Ditto.
(WebCore::MediaSource::scheduleEvent): Ditto.
* Modules/mediasource/MediaSource.h: Ditto.

* Modules/mediasource/SourceBufferList.cpp:
(WebCore::SourceBufferList::SourceBufferList): Take references instead of
pointers.
(WebCore::SourceBufferList::length): Changed type to unsigned instead of
unsigned long. This is an IDL "unsigned long", which corresponds to "unsigned"
in our C++ DOM implementation.
(WebCore::SourceBufferList::createAndFireEvent): Updated since event queue is
now a reference.
(WebCore::SourceBufferList::scriptExecutionContext): Updated since script
execution context is now a reference.
* Modules/mediasource/SourceBufferList.h: Ditto.

* dom/Document.cpp:
(WebCore::Document::Document): Updated since event queue is now a member rather
than a RefPtr.
(WebCore::Document::detach): Ditto.
(WebCore::Document::enqueueWindowEvent): Ditto.
(WebCore::Document::enqueueDocumentEvent): Ditto.
* dom/Document.h: Ditto.

* dom/DocumentEventQueue.cpp: Renamed DocumentEventQueueTimer to just Timer and
made it a class member of DocumentEventQueue. Also changed it to use references
instead of pointers and removed unneeded ScriptExecutionContext argument.
(WebCore::DocumentEventQueue::DocumentEventQueue): Updated to take a document
reference instead of a script execution context pointer.
(WebCore::DocumentEventQueue::enqueueEvent): Wrote the assertions in a clearer
style and do the assertions even when the queue is closed.
(WebCore::DocumentEventQueue::enqueueOrDispatchScrollEvent): Removed the unneeded
ScrollEventTargetType argument, since the policy is specific to the document node.
Made the argument a reference instead of a PassRefPtr, and rewrote the function
to be more straightforward and readable.
(WebCore::DocumentEventQueue::cancelEvent): Use the return value recently added to
the remove function to avoid the need for use of iterators and a find/remove pair.
(WebCore::DocumentEventQueue::pendingEventTimerFired): Rewrote this to use the
recently added ListHashSet takeFirst function. Also protect the document instead
of protecting just this object during the dispatch. Can't really protect the
event queue since it's no longer separately reference counted.
(WebCore::DocumentEventQueue::dispatchEvent): Changed this to take a reference and
added a FIXME about some curious code in here that needs a "why" comment.
* dom/DocumentEventQueue.h: Removed many unneeded includes, some unneeded forward
declarations, marked the class final, made it no longer derive from RefCounted,
removed ScrollEventTargetType and create, and did the other changes mentioned above.

* dom/EventQueue.h: Got rid of many uneeded includes, changed the argument type
of cancelEvent to Event& and rewrote the comment for close.

* dom/GenericEventQueue.cpp:
(WebCore::GenericEventQueue::GenericEventQueue): Updated to take a reference.
(WebCore::GenericEventQueue::enqueueEvent): Ditto.
(WebCore::GenericEventQueue::timerFired): Ditto.
* dom/GenericEventQueue.h: Changed this class to no longer derive from EventQueue
since there was no value coming from that polymorphism. Removed all the virtual
keywords from the class. Switched from pointers to references. Removed the unused
cancelEvent function. Removed the create function since this is always used as a
data member, not a pointer on the heap.

* dom/ScriptExecutionContext.h: Changed the return type of eventQueue to a reference.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Updated since event queue is now a
member rather than an OwnPtr.
(WebCore::HTMLMediaElement::~HTMLMediaElement): Ditto.
(WebCore::HTMLMediaElement::scheduleEvent): Ditto.
(WebCore::HTMLMediaElement::updateActiveTextTrackCues): Ditto.
(WebCore::HTMLMediaElement::cancelPendingEventsAndCallbacks): Ditto.
(WebCore::HTMLMediaElement::mediaPlayerKeyAdded): Ditto.
(WebCore::HTMLMediaElement::mediaPlayerKeyError): Ditto.
(WebCore::HTMLMediaElement::mediaPlayerKeyMessage): Ditto.
(WebCore::HTMLMediaElement::mediaPlayerKeyNeeded): Ditto.
(WebCore::HTMLMediaElement::stop): Ditto.
(WebCore::HTMLMediaElement::hasPendingActivity): Ditto.
* html/HTMLMediaElement.h: Ditto.

* page/EventHandler.cpp:
(WebCore::EventHandler::sendScrollEvent): Updated to remove the now-uneeded
ScrollEventTargetType argument, and also to use references instead of pointers.
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollTo): Ditto.
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::scrollTo): Ditto.

* workers/WorkerEventQueue.cpp:
(WebCore::WorkerEventQueue::WorkerEventQueue): Updated to work with references
instead of pointers.
(WebCore::WorkerEventQueue::enqueueEvent): Ditto.
(WebCore::WorkerEventQueue::cancelEvent): Use the take function instead of a
get/remove pair, to eliminate double hashing.
* workers/WorkerEventQueue.h: Removed unneeded includes, forward declarations,
the create function, and the private removeEvent function. Marked class final.

* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::WorkerGlobalScope): Updated since eventQueue is
now a data member.
(WebCore::WorkerGlobalScope::eventQueue): Ditto.
* workers/WorkerGlobalScope.h: Made m_eventQueue a queue instead of a pointer
to a queue. Also made the eventQueue function private and final.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155356 268f45cc-cd09-0410-ab3c-d52691b4dbfc

27 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeySession.h
Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Source/WebCore/Modules/indexeddb/IDBRequest.cpp
Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
Source/WebCore/Modules/mediasource/MediaSource.cpp
Source/WebCore/Modules/mediasource/MediaSource.h
Source/WebCore/Modules/mediasource/SourceBufferList.cpp
Source/WebCore/Modules/mediasource/SourceBufferList.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/DocumentEventQueue.cpp
Source/WebCore/dom/DocumentEventQueue.h
Source/WebCore/dom/EventQueue.h
Source/WebCore/dom/GenericEventQueue.cpp
Source/WebCore/dom/GenericEventQueue.h
Source/WebCore/dom/ScriptExecutionContext.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/page/EventHandler.cpp
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderListBox.cpp
Source/WebCore/workers/WorkerEventQueue.cpp
Source/WebCore/workers/WorkerEventQueue.h
Source/WebCore/workers/WorkerGlobalScope.cpp
Source/WebCore/workers/WorkerGlobalScope.h

index f9fc037..17c12fe 100644 (file)
@@ -1,3 +1,135 @@
+2013-09-08  Darin Adler  <darin@apple.com>
+
+        Tighten up EventQueue classes a bit, less indirection and memory allocation
+        https://bugs.webkit.org/show_bug.cgi?id=121016
+
+        Reviewed by Andreas Kling.
+
+        * Modules/encryptedmedia/MediaKeySession.cpp:
+        (WebCore::MediaKeySession::MediaKeySession): Updated since event queue is now
+        a member rather than an OwnPtr.
+        (WebCore::MediaKeySession::close): Ditto.
+        (WebCore::MediaKeySession::keyRequestTimerFired): Ditto.
+        (WebCore::MediaKeySession::addKeyTimerFired): Ditto.
+        * Modules/encryptedmedia/MediaKeySession.h: Ditto.
+
+        * Modules/indexeddb/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::closeConnection): Updated since ScriptExecutionContext's
+        eventQueue function now returns a reference rather than a pointer. Also, the
+        cancelEvent function takes a reference instead of a pointer.
+        (WebCore::IDBDatabase::enqueueEvent): Ditto.
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore::IDBRequest::abort): Ditto.
+        (WebCore::IDBRequest::enqueueEvent): Ditto.
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::enqueueEvent): Ditto.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::MediaSource): Updated since event queue is now a
+        member rather than an OwnPtr. Also use initialization instead of assignment
+        to set up source buffers.
+        (WebCore::MediaSource::hasPendingActivity): Ditto.
+        (WebCore::MediaSource::stop): Ditto.
+        (WebCore::MediaSource::scheduleEvent): Ditto.
+        * Modules/mediasource/MediaSource.h: Ditto.
+
+        * Modules/mediasource/SourceBufferList.cpp:
+        (WebCore::SourceBufferList::SourceBufferList): Take references instead of
+        pointers.
+        (WebCore::SourceBufferList::length): Changed type to unsigned instead of
+        unsigned long. This is an IDL "unsigned long", which corresponds to "unsigned"
+        in our C++ DOM implementation.
+        (WebCore::SourceBufferList::createAndFireEvent): Updated since event queue is
+        now a reference.
+        (WebCore::SourceBufferList::scriptExecutionContext): Updated since script
+        execution context is now a reference.
+        * Modules/mediasource/SourceBufferList.h: Ditto.
+
+        * dom/Document.cpp:
+        (WebCore::Document::Document): Updated since event queue is now a member rather
+        than a RefPtr.
+        (WebCore::Document::detach): Ditto.
+        (WebCore::Document::enqueueWindowEvent): Ditto.
+        (WebCore::Document::enqueueDocumentEvent): Ditto.
+        * dom/Document.h: Ditto.
+
+        * dom/DocumentEventQueue.cpp: Renamed DocumentEventQueueTimer to just Timer and
+        made it a class member of DocumentEventQueue. Also changed it to use references
+        instead of pointers and removed unneeded ScriptExecutionContext argument.
+        (WebCore::DocumentEventQueue::DocumentEventQueue): Updated to take a document
+        reference instead of a script execution context pointer.
+        (WebCore::DocumentEventQueue::enqueueEvent): Wrote the assertions in a clearer
+        style and do the assertions even when the queue is closed.
+        (WebCore::DocumentEventQueue::enqueueOrDispatchScrollEvent): Removed the unneeded
+        ScrollEventTargetType argument, since the policy is specific to the document node.
+        Made the argument a reference instead of a PassRefPtr, and rewrote the function
+        to be more straightforward and readable.
+        (WebCore::DocumentEventQueue::cancelEvent): Use the return value recently added to
+        the remove function to avoid the need for use of iterators and a find/remove pair.
+        (WebCore::DocumentEventQueue::pendingEventTimerFired): Rewrote this to use the
+        recently added ListHashSet takeFirst function. Also protect the document instead
+        of protecting just this object during the dispatch. Can't really protect the
+        event queue since it's no longer separately reference counted.
+        (WebCore::DocumentEventQueue::dispatchEvent): Changed this to take a reference and
+        added a FIXME about some curious code in here that needs a "why" comment.
+        * dom/DocumentEventQueue.h: Removed many unneeded includes, some unneeded forward
+        declarations, marked the class final, made it no longer derive from RefCounted,
+        removed ScrollEventTargetType and create, and did the other changes mentioned above.
+
+        * dom/EventQueue.h: Got rid of many uneeded includes, changed the argument type
+        of cancelEvent to Event& and rewrote the comment for close.
+
+        * dom/GenericEventQueue.cpp:
+        (WebCore::GenericEventQueue::GenericEventQueue): Updated to take a reference.
+        (WebCore::GenericEventQueue::enqueueEvent): Ditto.
+        (WebCore::GenericEventQueue::timerFired): Ditto.
+        * dom/GenericEventQueue.h: Changed this class to no longer derive from EventQueue
+        since there was no value coming from that polymorphism. Removed all the virtual
+        keywords from the class. Switched from pointers to references. Removed the unused
+        cancelEvent function. Removed the create function since this is always used as a
+        data member, not a pointer on the heap.
+
+        * dom/ScriptExecutionContext.h: Changed the return type of eventQueue to a reference.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement): Updated since event queue is now a
+        member rather than an OwnPtr.
+        (WebCore::HTMLMediaElement::~HTMLMediaElement): Ditto.
+        (WebCore::HTMLMediaElement::scheduleEvent): Ditto.
+        (WebCore::HTMLMediaElement::updateActiveTextTrackCues): Ditto.
+        (WebCore::HTMLMediaElement::cancelPendingEventsAndCallbacks): Ditto.
+        (WebCore::HTMLMediaElement::mediaPlayerKeyAdded): Ditto.
+        (WebCore::HTMLMediaElement::mediaPlayerKeyError): Ditto.
+        (WebCore::HTMLMediaElement::mediaPlayerKeyMessage): Ditto.
+        (WebCore::HTMLMediaElement::mediaPlayerKeyNeeded): Ditto.
+        (WebCore::HTMLMediaElement::stop): Ditto.
+        (WebCore::HTMLMediaElement::hasPendingActivity): Ditto.
+        * html/HTMLMediaElement.h: Ditto.
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::sendScrollEvent): Updated to remove the now-uneeded
+        ScrollEventTargetType argument, and also to use references instead of pointers.
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::scrollTo): Ditto.
+        * rendering/RenderListBox.cpp:
+        (WebCore::RenderListBox::scrollTo): Ditto.
+
+        * workers/WorkerEventQueue.cpp:
+        (WebCore::WorkerEventQueue::WorkerEventQueue): Updated to work with references
+        instead of pointers.
+        (WebCore::WorkerEventQueue::enqueueEvent): Ditto.
+        (WebCore::WorkerEventQueue::cancelEvent): Use the take function instead of a
+        get/remove pair, to eliminate double hashing.
+        * workers/WorkerEventQueue.h: Removed unneeded includes, forward declarations,
+        the create function, and the private removeEvent function. Marked class final.
+
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::WorkerGlobalScope): Updated since eventQueue is
+        now a data member.
+        (WebCore::WorkerGlobalScope::eventQueue): Ditto.
+        * workers/WorkerGlobalScope.h: Made m_eventQueue a queue instead of a pointer
+        to a queue. Also made the eventQueue function private and final.
+
 2013-09-09  Hans Muller  <hmuller@adobe.com>
 
         [CSS Shapes] Heap-buffer-overflow in WebCore::ShapeInterval<float>::subtractShapeIntervals
index 6aaf825..33fd72c 100644 (file)
@@ -46,7 +46,7 @@ MediaKeySession::MediaKeySession(ScriptExecutionContext* context, MediaKeys* key
     : ContextDestructionObserver(context)
     , m_keys(keys)
     , m_keySystem(keySystem)
-    , m_asyncEventQueue(GenericEventQueue::create(this))
+    , m_asyncEventQueue(*this)
     , m_session(keys->cdm()->createSession())
     , m_keyRequestTimer(this, &MediaKeySession::keyRequestTimerFired)
     , m_addKeyTimer(this, &MediaKeySession::addKeyTimerFired)
@@ -68,7 +68,7 @@ void MediaKeySession::close()
     if (m_session)
         m_session->releaseKeys();
     m_session = 0;
-    m_asyncEventQueue->cancelAllEvents();
+    m_asyncEventQueue.cancelAllEvents();
 }
 
 const String& MediaKeySession::sessionId() const
@@ -117,7 +117,7 @@ void MediaKeySession::keyRequestTimerFired(Timer<MediaKeySession>*)
             // 3.3. queue a task to fire a simple event named keyerror at the MediaKeySession object.
             RefPtr<Event> event = Event::create(eventNames().webkitkeyerrorEvent, false, false);
             event->setTarget(this);
-            m_asyncEventQueue->enqueueEvent(event.release());
+            m_asyncEventQueue.enqueueEvent(event.release());
 
             // 3.4. Abort the task.
             continue;
@@ -134,7 +134,7 @@ void MediaKeySession::keyRequestTimerFired(Timer<MediaKeySession>*)
         init.destinationURL = destinationURL;
         RefPtr<MediaKeyMessageEvent> event = MediaKeyMessageEvent::create(eventNames().webkitkeymessageEvent, init);
         event->setTarget(this);
-        m_asyncEventQueue->enqueueEvent(event);
+        m_asyncEventQueue.enqueueEvent(event.release());
     }
 }
 
@@ -188,14 +188,14 @@ void MediaKeySession::addKeyTimerFired(Timer<MediaKeySession>*)
             init.message = nextMessage;
             RefPtr<MediaKeyMessageEvent> event = MediaKeyMessageEvent::create(eventNames().webkitkeymessageEvent, init);
             event->setTarget(this);
-            m_asyncEventQueue->enqueueEvent(event);
+            m_asyncEventQueue.enqueueEvent(event.release());
         }
 
         // 2.7. If did store key is true, queue a task to fire a simple event named keyadded at the MediaKeySession object.
         if (didStoreKey) {
             RefPtr<Event> keyaddedEvent = Event::create(eventNames().webkitkeyaddedEvent, false, false);
             keyaddedEvent->setTarget(this);
-            m_asyncEventQueue->enqueueEvent(keyaddedEvent);
+            m_asyncEventQueue.enqueueEvent(keyaddedEvent.release());
         }
 
         // 2.8. If any of the preceding steps in the task failed
@@ -211,7 +211,7 @@ void MediaKeySession::addKeyTimerFired(Timer<MediaKeySession>*)
             // 2.8.3. queue a task to fire a simple event named keyerror at the MediaKeySession object.
             RefPtr<Event> keyerrorEvent = Event::create(eventNames().webkitkeyerrorEvent, false, false);
             keyerrorEvent->setTarget(this);
-            m_asyncEventQueue->enqueueEvent(keyerrorEvent.release());
+            m_asyncEventQueue.enqueueEvent(keyerrorEvent.release());
             
             // 2.8.4. Abort the task.
             // NOTE: no-op
index 8470634..0c86244 100644 (file)
@@ -84,7 +84,7 @@ protected:
     String m_keySystem;
     String m_sessionId;
     RefPtr<MediaKeyError> m_error;
-    OwnPtr<GenericEventQueue> m_asyncEventQueue;
+    GenericEventQueue m_asyncEventQueue;
     OwnPtr<CDMSession> m_session;
 
     struct PendingKeyRequest {
index 8de0239..92ae8d8 100644 (file)
@@ -292,13 +292,13 @@ void IDBDatabase::closeConnection()
     if (m_contextStopped || !scriptExecutionContext())
         return;
 
-    EventQueue* eventQueue = scriptExecutionContext()->eventQueue();
+    EventQueue& eventQueue = scriptExecutionContext()->eventQueue();
     // Remove any pending versionchange events scheduled to fire on this
     // connection. They would have been scheduled by the backend when another
     // connection called setVersion, but the frontend connection is being
     // closed before they could fire.
     for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
-        bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get());
+        bool removed = eventQueue.cancelEvent(*m_enqueuedEvents[i]);
         ASSERT_UNUSED(removed, removed);
     }
 }
@@ -320,9 +320,8 @@ void IDBDatabase::enqueueEvent(PassRefPtr<Event> event)
 {
     ASSERT(!m_contextStopped);
     ASSERT(scriptExecutionContext());
-    EventQueue* eventQueue = scriptExecutionContext()->eventQueue();
     event->setTarget(this);
-    eventQueue->enqueueEvent(event.get());
+    scriptExecutionContext()->eventQueue().enqueueEvent(event.get());
     m_enqueuedEvents.append(event);
 }
 
index 88cd559..2d05fa9 100644 (file)
@@ -171,9 +171,9 @@ void IDBRequest::abort()
     // Enqueued events may be the only reference to this object.
     RefPtr<IDBRequest> self(this);
 
-    EventQueue* eventQueue = scriptExecutionContext()->eventQueue();
+    EventQueue& eventQueue = scriptExecutionContext()->eventQueue();
     for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
-        bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get());
+        bool removed = eventQueue.cancelEvent(*m_enqueuedEvents[i]);
         ASSERT_UNUSED(removed, removed);
     }
     m_enqueuedEvents.clear();
@@ -552,10 +552,9 @@ void IDBRequest::enqueueEvent(PassRefPtr<Event> event)
 
     ASSERT_WITH_MESSAGE(m_readyState == PENDING || m_didFireUpgradeNeededEvent, "When queueing event %s, m_readyState was %d", event->type().string().utf8().data(), m_readyState);
 
-    EventQueue* eventQueue = scriptExecutionContext()->eventQueue();
     event->setTarget(this);
 
-    if (eventQueue->enqueueEvent(event.get()))
+    if (scriptExecutionContext()->eventQueue().enqueueEvent(event.get()))
         m_enqueuedEvents.append(event);
 }
 
index 6b6c358..f7e91d1 100644 (file)
@@ -432,9 +432,8 @@ void IDBTransaction::enqueueEvent(PassRefPtr<Event> event)
     if (m_contextStopped || !scriptExecutionContext())
         return;
 
-    EventQueue* eventQueue = scriptExecutionContext()->eventQueue();
     event->setTarget(this);
-    eventQueue->enqueueEvent(event);
+    scriptExecutionContext()->eventQueue().enqueueEvent(event);
 }
 
 EventTargetData* IDBTransaction::eventTargetData()
index 433bda5..816d075 100644 (file)
@@ -52,10 +52,10 @@ PassRefPtr<MediaSource> MediaSource::create(ScriptExecutionContext* context)
 MediaSource::MediaSource(ScriptExecutionContext* context)
     : ActiveDOMObject(context)
     , m_readyState(closedKeyword())
-    , m_asyncEventQueue(GenericEventQueue::create(this))
+    , m_asyncEventQueue(*this)
+    , m_sourceBuffers(SourceBufferList::create(scriptExecutionContext(), m_asyncEventQueue))
+    , m_activeSourceBuffers(SourceBufferList::create(scriptExecutionContext(), m_asyncEventQueue))
 {
-    m_sourceBuffers = SourceBufferList::create(scriptExecutionContext(), m_asyncEventQueue.get());
-    m_activeSourceBuffers = SourceBufferList::create(scriptExecutionContext(), m_asyncEventQueue.get());
 }
 
 const String& MediaSource::openKeyword()
@@ -302,14 +302,13 @@ ScriptExecutionContext* MediaSource::scriptExecutionContext() const
 
 bool MediaSource::hasPendingActivity() const
 {
-    return m_private || m_asyncEventQueue->hasPendingEvents()
-        || ActiveDOMObject::hasPendingActivity();
+    return m_private || m_asyncEventQueue.hasPendingEvents() || ActiveDOMObject::hasPendingActivity();
 }
 
 void MediaSource::stop()
 {
     m_private.clear();
-    m_asyncEventQueue->cancelAllEvents();
+    m_asyncEventQueue.cancelAllEvents();
 }
 
 EventTargetData* MediaSource::eventTargetData()
@@ -324,12 +323,9 @@ EventTargetData& MediaSource::ensureEventTargetData()
 
 void MediaSource::scheduleEvent(const AtomicString& eventName)
 {
-    ASSERT(m_asyncEventQueue);
-
     RefPtr<Event> event = Event::create(eventName, false, false);
     event->setTarget(this);
-
-    m_asyncEventQueue->enqueueEvent(event.release());
+    m_asyncEventQueue.enqueueEvent(event.release());
 }
 
 } // namespace WebCore
index cc7cf47..ea5bc6d 100644 (file)
@@ -94,9 +94,9 @@ private:
     String m_readyState;
     OwnPtr<MediaSourcePrivate> m_private;
 
+    GenericEventQueue m_asyncEventQueue;
     RefPtr<SourceBufferList> m_sourceBuffers;
     RefPtr<SourceBufferList> m_activeSourceBuffers;
-    OwnPtr<GenericEventQueue> m_asyncEventQueue;
 };
 
 } // namespace WebCore
index b21482d..ea58006 100644 (file)
 
 namespace WebCore {
 
-SourceBufferList::SourceBufferList(ScriptExecutionContext* context,
-                                   GenericEventQueue* asyncEventQueue)
+SourceBufferList::SourceBufferList(ScriptExecutionContext& context, GenericEventQueue& asyncEventQueue)
     : m_scriptExecutionContext(context)
     , m_asyncEventQueue(asyncEventQueue)
 {
 }
 
-unsigned long SourceBufferList::length() const
+unsigned SourceBufferList::length() const
 {
     return m_list.size();
 }
@@ -86,12 +85,9 @@ void SourceBufferList::clear()
 
 void SourceBufferList::createAndFireEvent(const AtomicString& eventName)
 {
-    ASSERT(m_asyncEventQueue);
-
     RefPtr<Event> event = Event::create(eventName, false, false);
     event->setTarget(this);
-
-    m_asyncEventQueue->enqueueEvent(event.release());
+    m_asyncEventQueue.enqueueEvent(event.release());
 }
 
 const AtomicString& SourceBufferList::interfaceName() const
@@ -101,7 +97,7 @@ const AtomicString& SourceBufferList::interfaceName() const
 
 ScriptExecutionContext* SourceBufferList::scriptExecutionContext() const
 {
-    return m_scriptExecutionContext;
+    return &m_scriptExecutionContext;
 }
 
 EventTargetData* SourceBufferList::eventTargetData()
index d380c10..0df29c3 100644 (file)
@@ -44,13 +44,13 @@ class GenericEventQueue;
 
 class SourceBufferList : public RefCounted<SourceBufferList>, public EventTarget {
 public:
-    static PassRefPtr<SourceBufferList> create(ScriptExecutionContext* context, GenericEventQueue* asyncEventQueue)
+    static PassRefPtr<SourceBufferList> create(ScriptExecutionContext& context, GenericEventQueue& asyncEventQueue)
     {
         return adoptRef(new SourceBufferList(context, asyncEventQueue));
     }
     virtual ~SourceBufferList() { }
 
-    unsigned long length() const;
+    unsigned length() const;
     SourceBuffer* item(unsigned index) const;
 
     void add(PassRefPtr<SourceBuffer>);
@@ -77,8 +77,8 @@ private:
     virtual void derefEventTarget() OVERRIDE { deref(); }
 
     EventTargetData m_eventTargetData;
-    ScriptExecutionContext* m_scriptExecutionContext;
-    GenericEventQueue* m_asyncEventQueue;
+    ScriptExecutionContext& m_scriptExecutionContext;
+    GenericEventQueue& m_asyncEventQueue;
 
     Vector<RefPtr<SourceBuffer> > m_list;
 };
index 8f212fe..4062825 100644 (file)
@@ -448,7 +448,7 @@ Document::Document(Frame* frame, const KURL& url, unsigned documentClasses)
     , m_sawElementsInKnownNamespaces(false)
     , m_isSrcdocDocument(false)
     , m_renderView(0)
-    , m_eventQueue(DocumentEventQueue::create(this))
+    , m_eventQueue(*this)
     , m_weakFactory(this)
     , m_idAttributeName(idAttr)
 #if ENABLE(FULLSCREEN_API)
@@ -2057,7 +2057,7 @@ void Document::detach()
         clearAXObjectCache();
 
     stopActiveDOMObjects();
-    m_eventQueue->close();
+    m_eventQueue.close();
 #if ENABLE(FULLSCREEN_API)
     m_fullScreenChangeEventTargetQueue.clear();
     m_fullScreenErrorEventTargetQueue.clear();
@@ -3630,13 +3630,13 @@ void Document::dispatchWindowLoadEvent()
 void Document::enqueueWindowEvent(PassRefPtr<Event> event)
 {
     event->setTarget(domWindow());
-    m_eventQueue->enqueueEvent(event);
+    m_eventQueue.enqueueEvent(event);
 }
 
 void Document::enqueueDocumentEvent(PassRefPtr<Event> event)
 {
     event->setTarget(this);
-    m_eventQueue->enqueueEvent(event);
+    m_eventQueue.enqueueEvent(event);
 }
 
 PassRefPtr<Event> Document::createEvent(const String& eventType, ExceptionCode& ec)
index 60f9220..2de8913 100644 (file)
@@ -1010,7 +1010,7 @@ public:
     void enqueuePageshowEvent(PageshowEventPersistence);
     void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
     void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject);
-    virtual DocumentEventQueue* eventQueue() const { return m_eventQueue.get(); }
+    DocumentEventQueue& eventQueue() const { return m_eventQueue; }
 
     void addMediaCanStartListener(MediaCanStartListener*);
     void removeMediaCanStartListener(MediaCanStartListener*);
@@ -1447,7 +1447,7 @@ private:
     bool m_isSrcdocDocument;
 
     RenderView* m_renderView;
-    RefPtr<DocumentEventQueue> m_eventQueue;
+    mutable DocumentEventQueue m_eventQueue;
 
     WeakPtrFactory<Document> m_weakFactory;
 
index 35a7b32..f01aee7 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Google Inc. All Rights Reserved.
+ * Copyright (C) 2013 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "Document.h"
 #include "Event.h"
 #include "EventNames.h"
-#include "RuntimeApplicationChecks.h"
-#include "ScriptExecutionContext.h"
 #include "SuspendableTimer.h"
 #include <wtf/Ref.h>
 
 namespace WebCore {
     
-class DocumentEventQueueTimer FINAL : public SuspendableTimer {
+class DocumentEventQueue::Timer FINAL : public SuspendableTimer {
 public:
-    static PassOwnPtr<DocumentEventQueueTimer> create(DocumentEventQueue* eventQueue, ScriptExecutionContext* context)
+    static PassOwnPtr<Timer> create(DocumentEventQueue& eventQueue)
     {
-        return adoptPtr(new DocumentEventQueueTimer(eventQueue, context));
+        return adoptPtr(new Timer(eventQueue));
     }
 
 private:
-    DocumentEventQueueTimer(DocumentEventQueue* eventQueue, ScriptExecutionContext* context)
-        : SuspendableTimer(context)
-        , m_eventQueue(eventQueue) { }
+    Timer(DocumentEventQueue& eventQueue)
+        : SuspendableTimer(&eventQueue.m_document)
+        , m_eventQueue(eventQueue)
+    {
+    }
 
     virtual void fired() OVERRIDE
     {
         ASSERT(!isSuspended());
-        m_eventQueue->pendingEventTimerFired();
+        m_eventQueue.pendingEventTimerFired();
     }
 
-    DocumentEventQueue* m_eventQueue;
+    DocumentEventQueue& m_eventQueue;
 };
 
-PassRefPtr<DocumentEventQueue> DocumentEventQueue::create(ScriptExecutionContext* context)
-{
-    return adoptRef(new DocumentEventQueue(context));
-}
-
-DocumentEventQueue::DocumentEventQueue(ScriptExecutionContext* context)
-    : m_pendingEventTimer(DocumentEventQueueTimer::create(this, context))
+DocumentEventQueue::DocumentEventQueue(Document& document)
+    : m_document(document)
+    , m_pendingEventTimer(Timer::create(*this))
     , m_isClosed(false)
 {
     m_pendingEventTimer->suspendIfNeeded();
@@ -77,41 +74,43 @@ DocumentEventQueue::~DocumentEventQueue()
 
 bool DocumentEventQueue::enqueueEvent(PassRefPtr<Event> event)
 {
+    ASSERT(event->target());
+    ASSERT(!m_queuedEvents.contains(event.get()));
+
     if (m_isClosed)
         return false;
 
-    ASSERT(event->target());
-    bool wasAdded = m_queuedEvents.add(event).isNewEntry;
-    ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the list.
-    
+    m_queuedEvents.add(event);
     if (!m_pendingEventTimer->isActive())
         m_pendingEventTimer->startOneShot(0);
-
     return true;
 }
 
-void DocumentEventQueue::enqueueOrDispatchScrollEvent(PassRefPtr<Node> target, ScrollEventTargetType targetType)
+void DocumentEventQueue::enqueueOrDispatchScrollEvent(Node& target)
 {
-    if (!target->document().hasListenerType(Document::SCROLL_LISTENER))
+    ASSERT(&target.document() == &m_document);
+
+    if (m_isClosed)
         return;
 
-    // Per the W3C CSSOM View Module, scroll events fired at the document should bubble, others should not.
-    bool canBubble = targetType == ScrollEventDocumentTarget;
-    RefPtr<Event> scrollEvent = Event::create(eventNames().scrollEvent, canBubble, false /* non cancelleable */);
-     
-    if (!m_nodesWithQueuedScrollEvents.add(target.get()).isNewEntry)
+    if (!m_document.hasListenerType(Document::SCROLL_LISTENER))
         return;
 
-    scrollEvent->setTarget(target);
+    if (!m_nodesWithQueuedScrollEvents.add(&target).isNewEntry)
+        return;
+
+    // Per the W3C CSSOM View Module, scroll events fired at the document should bubble, others should not.
+    bool bubbles = target.isDocumentNode();
+    bool cancelable = false;
+
+    RefPtr<Event> scrollEvent = Event::create(eventNames().scrollEvent, bubbles, cancelable);
+    scrollEvent->setTarget(&target);
     enqueueEvent(scrollEvent.release());
 }
 
-bool DocumentEventQueue::cancelEvent(Event* event)
+bool DocumentEventQueue::cancelEvent(Event& event)
 {
-    ListHashSet<RefPtr<Event>, 16>::iterator it = m_queuedEvents.find(event);
-    bool found = it != m_queuedEvents.end();
-    if (found)
-        m_queuedEvents.remove(it);
+    bool found = m_queuedEvents.remove(&event);
     if (m_queuedEvents.isEmpty())
         m_pendingEventTimer->cancel();
     return found;
@@ -132,29 +131,28 @@ void DocumentEventQueue::pendingEventTimerFired()
     m_nodesWithQueuedScrollEvents.clear();
 
     // Insert a marker for where we should stop.
-    ASSERT(!m_queuedEvents.contains(0));
-    bool wasAdded = m_queuedEvents.add(0).isNewEntry;
-    ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the list.
+    ASSERT(!m_queuedEvents.contains(nullptr));
+    m_queuedEvents.add(nullptr);
 
-    Ref<DocumentEventQueue> protect(*this);
+    Ref<Document> protect(m_document);
 
     while (!m_queuedEvents.isEmpty()) {
-        ListHashSet<RefPtr<Event>, 16>::iterator iter = m_queuedEvents.begin();
-        RefPtr<Event> event = *iter;
-        m_queuedEvents.remove(iter);
+        RefPtr<Event> event = m_queuedEvents.takeFirst();
         if (!event)
             break;
-        dispatchEvent(event.get());
+        dispatchEvent(*event);
     }
 }
 
-void DocumentEventQueue::dispatchEvent(PassRefPtr<Event> event)
+void DocumentEventQueue::dispatchEvent(Event& event)
 {
-    EventTarget* eventTarget = event->target();
-    if (eventTarget->toDOMWindow())
-        eventTarget->toDOMWindow()->dispatchEvent(event, 0);
+    // FIXME: Where did this special case for the DOM window come from?
+    // Why do we have this special case here instead of a virtual function on EventTarget?
+    EventTarget& eventTarget = *event.target();
+    if (DOMWindow* window = eventTarget.toDOMWindow())
+        window->dispatchEvent(&event, 0);
     else
-        eventTarget->dispatchEvent(event);
+        eventTarget.dispatchEvent(&event);
 }
 
 }
index 71885fe..b88f1e1 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Google Inc. All Rights Reserved.
+ * Copyright (C) 2013 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #define DocumentEventQueue_h
 
 #include "EventQueue.h"
-#include <wtf/Forward.h>
 #include <wtf/HashSet.h>
 #include <wtf/ListHashSet.h>
 #include <wtf/OwnPtr.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
+class Document;
 class Event;
-class DocumentEventQueueTimer;
 class Node;
-class ScriptExecutionContext;
 
-class DocumentEventQueue : public RefCounted<DocumentEventQueue>, public EventQueue {
+class DocumentEventQueue FINAL : public EventQueue {
 public:
-    enum ScrollEventTargetType {
-        ScrollEventDocumentTarget,
-        ScrollEventElementTarget
-    };
+    explicit DocumentEventQueue(Document&);
+    ~DocumentEventQueue();
 
-    static PassRefPtr<DocumentEventQueue> create(ScriptExecutionContext*);
-    virtual ~DocumentEventQueue();
-
-    // EventQueue
     virtual bool enqueueEvent(PassRefPtr<Event>) OVERRIDE;
-    virtual bool cancelEvent(Event*) OVERRIDE;
+    virtual bool cancelEvent(Event&) OVERRIDE;
     virtual void close() OVERRIDE;
 
-    void enqueueOrDispatchScrollEvent(PassRefPtr<Node>, ScrollEventTargetType);
+    void enqueueOrDispatchScrollEvent(Node&);
 
 private:
-    explicit DocumentEventQueue(ScriptExecutionContext*);
-
     void pendingEventTimerFired();
-    void dispatchEvent(PassRefPtr<Event>);
+    void dispatchEvent(Event&);
 
-    OwnPtr<DocumentEventQueueTimer> m_pendingEventTimer;
+    class Timer;
+
+    Document& m_document;
+    OwnPtr<Timer> m_pendingEventTimer;
     ListHashSet<RefPtr<Event>, 16> m_queuedEvents;
     HashSet<Node*> m_nodesWithQueuedScrollEvents;
     bool m_isClosed;
-
-    friend class DocumentEventQueueTimer;    
 };
 
 }
index 56ce153..2906f80 100644 (file)
@@ -27,9 +27,7 @@
 #ifndef EventQueue_h
 #define EventQueue_h
 
-#include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
-#include <wtf/PassOwnPtr.h>
+#include <wtf/Forward.h>
 
 namespace WebCore {
 
@@ -39,9 +37,8 @@ class EventQueue {
 public:
     virtual ~EventQueue() { }
     virtual bool enqueueEvent(PassRefPtr<Event>) = 0;
-    virtual bool cancelEvent(Event*) = 0;
-    // The accumulated and all the future events will be discarded, no events will be dispatched anymore.
-    virtual void close() = 0;
+    virtual bool cancelEvent(Event&) = 0;
+    virtual void close() = 0; // Discard accumulated events and all future events. No events will be dispatched after this.
 };
 
 }
index a04e489..3dd3483 100644 (file)
  */
 
 #include "config.h"
-
 #include "GenericEventQueue.h"
 
 #include "Event.h"
+#include "EventTarget.h"
 
 namespace WebCore {
 
-PassOwnPtr<GenericEventQueue> GenericEventQueue::create(EventTarget* owner)
-{
-    return adoptPtr(new GenericEventQueue(owner));
-}
-
-GenericEventQueue::GenericEventQueue(EventTarget* owner)
+GenericEventQueue::GenericEventQueue(EventTarget& owner)
     : m_owner(owner)
     , m_timer(this, &GenericEventQueue::timerFired)
     , m_isClosed(false)
@@ -52,7 +47,7 @@ bool GenericEventQueue::enqueueEvent(PassRefPtr<Event> event)
     if (m_isClosed)
         return false;
 
-    if (event->target() == m_owner)
+    if (event->target() == &m_owner)
         event->setTarget(0);
 
     m_pendingEvents.append(event);
@@ -63,31 +58,18 @@ bool GenericEventQueue::enqueueEvent(PassRefPtr<Event> event)
     return true;
 }
 
-bool GenericEventQueue::cancelEvent(Event* event)
-{
-    bool found = m_pendingEvents.contains(event);
-
-    if (found)
-        m_pendingEvents.remove(m_pendingEvents.find(event));
-
-    if (m_pendingEvents.isEmpty())
-        m_timer.stop();
-
-    return found;
-}
-
 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*)
 {
     ASSERT(!m_timer.isActive());
     ASSERT(!m_pendingEvents.isEmpty());
 
-    Vector<RefPtr<Event> > pendingEvents;
+    Vector<RefPtr<Event>> pendingEvents;
     m_pendingEvents.swap(pendingEvents);
 
-    RefPtr<EventTarget> protect(m_owner);
+    RefPtr<EventTarget> protect(&m_owner);
     for (unsigned i = 0; i < pendingEvents.size(); ++i) {
-        EventTarget* target = pendingEvents[i]->target() ? pendingEvents[i]->target() : m_owner;
-        target->dispatchEvent(pendingEvents[i].release());
+        EventTarget& target = pendingEvents[i]->target() ? *pendingEvents[i]->target() : m_owner;
+        target.dispatchEvent(pendingEvents[i].release());
     }
 }
 
index 30430c6..ad76f02 100644 (file)
 #ifndef GenericEventQueue_h
 #define GenericEventQueue_h
 
-#include "EventQueue.h"
-#include "EventTarget.h"
 #include "Timer.h"
-#include <wtf/PassOwnPtr.h>
+#include <wtf/Forward.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
-class GenericEventQueue : public EventQueue {
-    WTF_MAKE_FAST_ALLOCATED;
+class Event;
+class EventTarget;
+
+class GenericEventQueue {
 public:
-    explicit GenericEventQueue(EventTarget*);
-    static PassOwnPtr<GenericEventQueue> create(EventTarget*);
-    virtual ~GenericEventQueue();
+    explicit GenericEventQueue(EventTarget&);
+    ~GenericEventQueue();
 
-    // EventQueue
-    virtual bool enqueueEvent(PassRefPtr<Event>) OVERRIDE;
-    virtual bool cancelEvent(Event*) OVERRIDE;
-    virtual void close() OVERRIDE;
+    bool enqueueEvent(PassRefPtr<Event>);
+    void close();
 
     void cancelAllEvents();
     bool hasPendingEvents() const;
@@ -53,10 +50,9 @@ public:
 private:
     void timerFired(Timer<GenericEventQueue>*);
 
-    EventTarget* m_owner;
-    Vector<RefPtr<Event> > m_pendingEvents;
+    EventTarget& m_owner;
+    Vector<RefPtr<Event>> m_pendingEvents;
     Timer<GenericEventQueue> m_timer;
-
     bool m_isClosed;
 };
 
index 3ff6a3c..6f4452e 100644 (file)
@@ -150,7 +150,7 @@ public:
     void didChangeTimerAlignmentInterval();
     virtual double timerAlignmentInterval() const;
 
-    virtual EventQueue* eventQueue() const = 0;
+    virtual EventQueue& eventQueue() const = 0;
 
 #if ENABLE(SQL_DATABASE)
     void setDatabaseContext(DatabaseContext*);
index a13fb85..a5a9932 100644 (file)
@@ -258,7 +258,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
     , m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired)
     , m_playbackProgressTimer(this, &HTMLMediaElement::playbackProgressTimerFired)
     , m_playedTimeRanges()
-    , m_asyncEventQueue(GenericEventQueue::create(this))
+    , m_asyncEventQueue(*this)
     , m_playbackRate(1.0f)
     , m_defaultPlaybackRate(1.0f)
     , m_webkitPreservesPitch(true)
@@ -352,7 +352,7 @@ HTMLMediaElement::~HTMLMediaElement()
 {
     LOG(Media, "HTMLMediaElement::~HTMLMediaElement");
 
-    m_asyncEventQueue->close();
+    m_asyncEventQueue.close();
 
     if (m_isWaitingUntilMediaCanStart)
         document().removeMediaCanStartListener(this);
@@ -704,7 +704,7 @@ void HTMLMediaElement::scheduleEvent(const AtomicString& eventName)
     // 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(event.release());
+    m_asyncEventQueue.enqueueEvent(event.release());
 }
 
 void HTMLMediaElement::loadTimerFired(Timer<HTMLMediaElement>*)
@@ -1325,11 +1325,11 @@ void HTMLMediaElement::updateActiveTextTrackCues(double movieTime)
         if (eventTasks[i].second->startTime() >= eventTasks[i].second->endTime()) {
             event = Event::create(eventNames().enterEvent, false, false);
             event->setTarget(eventTasks[i].second);
-            m_asyncEventQueue->enqueueEvent(event.release());
+            m_asyncEventQueue.enqueueEvent(event.release());
 
             event = Event::create(eventNames().exitEvent, false, false);
             event->setTarget(eventTasks[i].second);
-            m_asyncEventQueue->enqueueEvent(event.release());
+            m_asyncEventQueue.enqueueEvent(event.release());
         } else {
             if (eventTasks[i].first == eventTasks[i].second->startTime())
                 event = Event::create(eventNames().enterEvent, false, false);
@@ -1337,7 +1337,7 @@ void HTMLMediaElement::updateActiveTextTrackCues(double movieTime)
                 event = Event::create(eventNames().exitEvent, false, false);
 
             event->setTarget(eventTasks[i].second);
-            m_asyncEventQueue->enqueueEvent(event.release());
+            m_asyncEventQueue.enqueueEvent(event.release());
         }
     }
 
@@ -1351,7 +1351,7 @@ void HTMLMediaElement::updateActiveTextTrackCues(double movieTime)
         RefPtr<Event> event = Event::create(eventNames().cuechangeEvent, false, false);
         event->setTarget(affectedTracks[i]);
 
-        m_asyncEventQueue->enqueueEvent(event.release());
+        m_asyncEventQueue.enqueueEvent(event.release());
 
         // ... if the text track has a corresponding track element, to then fire a
         // simple event named cuechange at the track element as well.
@@ -1361,7 +1361,7 @@ void HTMLMediaElement::updateActiveTextTrackCues(double movieTime)
             ASSERT(trackElement);
             event->setTarget(trackElement);
             
-            m_asyncEventQueue->enqueueEvent(event.release());
+            m_asyncEventQueue.enqueueEvent(event.release());
         }
     }
 
@@ -1653,7 +1653,7 @@ void HTMLMediaElement::mediaEngineError(PassRefPtr<MediaError> err)
 void HTMLMediaElement::cancelPendingEventsAndCallbacks()
 {
     LOG(Media, "HTMLMediaElement::cancelPendingEventsAndCallbacks");
-    m_asyncEventQueue->cancelAllEvents();
+    m_asyncEventQueue.cancelAllEvents();
 
     auto sourceChildren = childrenOfType<HTMLSourceElement>(this);
     for (auto source = sourceChildren.begin(), end = sourceChildren.end(); source != end; ++source)
@@ -1943,7 +1943,7 @@ void HTMLMediaElement::mediaPlayerKeyAdded(MediaPlayer*, const String& keySystem
 
     RefPtr<Event> event = MediaKeyEvent::create(eventNames().webkitkeyaddedEvent, initializer);
     event->setTarget(this);
-    m_asyncEventQueue->enqueueEvent(event.release());
+    m_asyncEventQueue.enqueueEvent(event.release());
 }
 
 void HTMLMediaElement::mediaPlayerKeyError(MediaPlayer*, const String& keySystem, const String& sessionId, MediaPlayerClient::MediaKeyErrorCode errorCode, unsigned short systemCode)
@@ -1980,7 +1980,7 @@ void HTMLMediaElement::mediaPlayerKeyError(MediaPlayer*, const String& keySystem
 
     RefPtr<Event> event = MediaKeyEvent::create(eventNames().webkitkeyerrorEvent, initializer);
     event->setTarget(this);
-    m_asyncEventQueue->enqueueEvent(event.release());
+    m_asyncEventQueue.enqueueEvent(event.release());
 }
 
 void HTMLMediaElement::mediaPlayerKeyMessage(MediaPlayer*, const String& keySystem, const String& sessionId, const unsigned char* message, unsigned messageLength, const KURL& defaultURL)
@@ -1995,7 +1995,7 @@ void HTMLMediaElement::mediaPlayerKeyMessage(MediaPlayer*, const String& keySyst
 
     RefPtr<Event> event = MediaKeyEvent::create(eventNames().webkitkeymessageEvent, initializer);
     event->setTarget(this);
-    m_asyncEventQueue->enqueueEvent(event.release());
+    m_asyncEventQueue.enqueueEvent(event.release());
 }
 
 bool HTMLMediaElement::mediaPlayerKeyNeeded(MediaPlayer*, const String& keySystem, const String& sessionId, const unsigned char* initData, unsigned initDataLength)
@@ -2015,7 +2015,7 @@ bool HTMLMediaElement::mediaPlayerKeyNeeded(MediaPlayer*, const String& keySyste
 
     RefPtr<Event> event = MediaKeyEvent::create(eventNames().webkitneedkeyEvent, initializer);
     event->setTarget(this);
-    m_asyncEventQueue->enqueueEvent(event.release());
+    m_asyncEventQueue.enqueueEvent(event.release());
     return true;
 }
 #endif
@@ -2036,7 +2036,7 @@ bool HTMLMediaElement::mediaPlayerKeyNeeded(MediaPlayer*, Uint8Array* initData)
 
     RefPtr<Event> event = MediaKeyNeededEvent::create(eventNames().webkitneedkeyEvent, initializer);
     event->setTarget(this);
-    m_asyncEventQueue->enqueueEvent(event.release());
+    m_asyncEventQueue.enqueueEvent(event.release());
 
     return true;
 }
@@ -4179,7 +4179,7 @@ void HTMLMediaElement::stop()
     stopPeriodicTimers();
     cancelPendingEventsAndCallbacks();
 
-    m_asyncEventQueue->close();
+    m_asyncEventQueue.close();
 
     // Once an active DOM object has been stopped it can not be restarted, so we can deallocate
     // the media player now. Note that userCancelledLoad will already have cleared the player
@@ -4238,7 +4238,7 @@ void HTMLMediaElement::resume()
 
 bool HTMLMediaElement::hasPendingActivity() const
 {
-    return (hasAudio() && isPlaying()) || m_asyncEventQueue->hasPendingEvents();
+    return (hasAudio() && isPlaying()) || m_asyncEventQueue.hasPendingEvents();
 }
 
 void HTMLMediaElement::mediaVolumeDidChange()
index 0617e4e..e778e85 100644 (file)
@@ -626,7 +626,7 @@ private:
     Timer<HTMLMediaElement> m_progressEventTimer;
     Timer<HTMLMediaElement> m_playbackProgressTimer;
     RefPtr<TimeRanges> m_playedTimeRanges;
-    OwnPtr<GenericEventQueue> m_asyncEventQueue;
+    GenericEventQueue m_asyncEventQueue;
 
     double m_playbackRate;
     double m_defaultPlaybackRate;
index 1f22749..89a8eb8 100644 (file)
@@ -3866,7 +3866,7 @@ void EventHandler::sendScrollEvent()
 {
     setFrameWasScrolledByUser();
     if (m_frame.view() && m_frame.document())
-        m_frame.document()->eventQueue()->enqueueOrDispatchScrollEvent(m_frame.document(), DocumentEventQueue::ScrollEventDocumentTarget);
+        m_frame.document()->eventQueue().enqueueOrDispatchScrollEvent(*m_frame.document());
 }
 
 void EventHandler::setFrameWasScrolledByUser()
index 1fd0d2f..2b77b60 100644 (file)
@@ -2263,7 +2263,7 @@ void RenderLayer::scrollTo(int x, int y)
 
     // Schedule the scroll DOM event.
     if (Node* node = renderer().node())
-        node->document().eventQueue()->enqueueOrDispatchScrollEvent(renderer().node(), DocumentEventQueue::ScrollEventElementTarget);
+        node->document().eventQueue().enqueueOrDispatchScrollEvent(*node);
 
     InspectorInstrumentation::didScrollLayer(&frame);
     if (scrollsOverflow())
index 30691f6..fc05cf0 100644 (file)
@@ -645,7 +645,7 @@ void RenderListBox::scrollTo(int newOffset)
 
     m_indexOffset = newOffset;
     repaint();
-    node()->document().eventQueue()->enqueueOrDispatchScrollEvent(node(), DocumentEventQueue::ScrollEventElementTarget);
+    node()->document().eventQueue().enqueueOrDispatchScrollEvent(*node());
 }
 
 LayoutUnit RenderListBox::itemHeight() const
index 235529f..0cc4789 100644 (file)
 
 namespace WebCore {
 
-PassOwnPtr<WorkerEventQueue> WorkerEventQueue::create(ScriptExecutionContext* context)
-{
-    return adoptPtr(new WorkerEventQueue(context));
-}
-
-WorkerEventQueue::WorkerEventQueue(ScriptExecutionContext* context)
+WorkerEventQueue::WorkerEventQueue(ScriptExecutionContext& context)
     : m_scriptExecutionContext(context)
     , m_isClosed(false)
 {
@@ -51,9 +46,9 @@ WorkerEventQueue::~WorkerEventQueue()
     close();
 }
 
-class WorkerEventQueue::EventDispatcherTask : public ScriptExecutionContext::Task {
+class WorkerEventQueue::EventDispatcherTask FINAL : public ScriptExecutionContext::Task {
 public:
-    static PassOwnPtr<EventDispatcherTask> create(PassRefPtr<Event> event, WorkerEventQueue* eventQueue)
+    static PassOwnPtr<EventDispatcherTask> create(PassRefPtr<Event> event, WorkerEventQueue& eventQueue)
     {
         return adoptPtr(new EventDispatcherTask(event, eventQueue));
     }
@@ -61,7 +56,7 @@ public:
     virtual ~EventDispatcherTask()
     {
         if (m_event)
-            m_eventQueue->removeEvent(m_event.get());
+            m_eventQueue.m_eventTaskMap.remove(m_event.get());
     }
 
     void dispatchEvent(ScriptExecutionContext*, PassRefPtr<Event> event)
@@ -69,11 +64,11 @@ public:
         event->target()->dispatchEvent(event);
     }
 
-    virtual void performTask(ScriptExecutionContext* context)
+    virtual void performTask(ScriptExecutionContext* context) OVERRIDE
     {
         if (m_isCancelled)
             return;
-        m_eventQueue->removeEvent(m_event.get());
+        m_eventQueue.m_eventTaskMap.remove(m_event.get());
         dispatchEvent(context, m_event);
         m_event.clear();
     }
@@ -85,7 +80,7 @@ public:
     }
 
 private:
-    EventDispatcherTask(PassRefPtr<Event> event, WorkerEventQueue* eventQueue)
+    EventDispatcherTask(PassRefPtr<Event> event, WorkerEventQueue& eventQueue)
         : m_event(event)
         , m_eventQueue(eventQueue)
         , m_isCancelled(false)
@@ -93,33 +88,27 @@ private:
     }
 
     RefPtr<Event> m_event;
-    WorkerEventQueue* m_eventQueue;
+    WorkerEventQueue& m_eventQueue;
     bool m_isCancelled;
 };
 
-void WorkerEventQueue::removeEvent(Event* event)
-{
-    m_eventTaskMap.remove(event);
-}
-
 bool WorkerEventQueue::enqueueEvent(PassRefPtr<Event> prpEvent)
 {
     if (m_isClosed)
         return false;
     RefPtr<Event> event = prpEvent;
-    OwnPtr<EventDispatcherTask> task = EventDispatcherTask::create(event, this);
+    OwnPtr<EventDispatcherTask> task = EventDispatcherTask::create(event, *this);
     m_eventTaskMap.add(event.release(), task.get());
-    m_scriptExecutionContext->postTask(task.release());
+    m_scriptExecutionContext.postTask(task.release());
     return true;
 }
 
-bool WorkerEventQueue::cancelEvent(Event* event)
+bool WorkerEventQueue::cancelEvent(Event& event)
 {
-    EventDispatcherTask* task = m_eventTaskMap.get(event);
+    EventDispatcherTask* task = m_eventTaskMap.take(&event);
     if (!task)
         return false;
     task->cancel();
-    removeEvent(event);
     return true;
 }
 
index 4661dfa..e0341fa 100644 (file)
 
 #include "EventQueue.h"
 #include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
 #include <wtf/PassOwnPtr.h>
-#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
-class Event;
-class Node;
 class ScriptExecutionContext;
 
-class WorkerEventQueue : public EventQueue {
-    WTF_MAKE_FAST_ALLOCATED;
+class WorkerEventQueue FINAL : public EventQueue {
 public:
-
-    static PassOwnPtr<WorkerEventQueue> create(ScriptExecutionContext*);
+    explicit WorkerEventQueue(ScriptExecutionContext&);
     virtual ~WorkerEventQueue();
 
-    // EventQueue
     virtual bool enqueueEvent(PassRefPtr<Event>) OVERRIDE;
-    virtual bool cancelEvent(Event*) OVERRIDE;
+    virtual bool cancelEvent(Event&) OVERRIDE;
     virtual void close() OVERRIDE;
 
 private:
-    explicit WorkerEventQueue(ScriptExecutionContext*);
-    void removeEvent(Event*);
-
-    ScriptExecutionContext* m_scriptExecutionContext;
+    ScriptExecutionContext& m_scriptExecutionContext;
     bool m_isClosed;
 
     class EventDispatcherTask;
index 45807bb..f8972e5 100644 (file)
@@ -94,7 +94,7 @@ WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, P
     , m_workerInspectorController(adoptPtr(new WorkerInspectorController(this)))
 #endif
     , m_closing(false)
-    , m_eventQueue(WorkerEventQueue::create(this))
+    , m_eventQueue(*this)
     , m_topOrigin(topOrigin)
 {
     setSecurityOrigin(SecurityOrigin::create(url));
@@ -365,9 +365,9 @@ void WorkerGlobalScope::notifyObserversOfStop()
     }
 }
 
-WorkerEventQueue* WorkerGlobalScope::eventQueue() const
+WorkerEventQueue& WorkerGlobalScope::eventQueue() const
 {
-    return m_eventQueue.get();
+    return m_eventQueue;
 }
 
 } // namespace WebCore
index f629c72..129f10e 100644 (file)
@@ -104,9 +104,6 @@ namespace WebCore {
         int setInterval(PassOwnPtr<ScheduledAction>, int timeout);
         void clearInterval(int timeoutId);
 
-        // ScriptExecutionContext
-        virtual WorkerEventQueue* eventQueue() const OVERRIDE;
-
         virtual bool isContextThread() const OVERRIDE;
         virtual bool isJSExecutionForbidden() const OVERRIDE;
 
@@ -162,6 +159,8 @@ namespace WebCore {
 
         virtual EventTarget* errorEventTarget() OVERRIDE;
 
+        virtual WorkerEventQueue& eventQueue() const OVERRIDE FINAL;
+
         KURL m_url;
         String m_userAgent;
         OwnPtr<GroupSettings> m_groupSettings;
@@ -180,7 +179,7 @@ namespace WebCore {
 
         HashSet<Observer*> m_workerObservers;
 
-        OwnPtr<WorkerEventQueue> m_eventQueue;
+        mutable WorkerEventQueue m_eventQueue;
 
         RefPtr<SecurityOrigin> m_topOrigin;
     };