Commit 7ba1e57c authored by darin@apple.com's avatar 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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155356 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bad79a9e
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
......@@ -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
......
......@@ -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 {
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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()
......
......@@ -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
......
......@@ -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
......
......@@ -39,14 +39,13 @@
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()
......
......@@ -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;
};
......
......@@ -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)
......
......@@ -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;
......
/*
* 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
......@@ -31,41 +32,37 @@
#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);
}
}
/*
* 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
......@@ -28,49 +29,38 @@
#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*);