2 * Copyright (C) 2012 Victor Carbune (victor@rosedu.org)
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "ActiveDOMObject.h"
29 #include "GenericTaskQueue.h"
30 #include <wtf/Deque.h>
31 #include <wtf/Forward.h>
32 #include <wtf/RefPtr.h>
33 #include <wtf/UniqueRef.h>
40 class ScriptExecutionContext;
43 class GenericEventQueueBase : public ActiveDOMObject {
44 WTF_MAKE_FAST_ALLOCATED;
46 explicit GenericEventQueueBase(EventTarget&);
47 ~GenericEventQueueBase();
49 void enqueueEvent(RefPtr<Event>&&);
52 void cancelAllEvents();
53 bool hasPendingEvents() const;
54 bool hasPendingEventsOfType(const AtomString&) const;
58 bool isSuspended() const { return m_isSuspended; }
61 void dispatchOneEvent();
63 const char* activeDOMObjectName() const final;
65 void suspend(ReasonForSuspension) final;
68 void rescheduleAllEventsIfNeeded();
69 bool isSuspendedOrPausedByClient() const { return m_isSuspended || m_isPausedByClient; }
72 UniqueRef<GenericTaskQueue<T>> m_taskQueue;
73 Deque<RefPtr<Event>> m_pendingEvents;
74 bool m_isClosed { false };
75 bool m_isPausedByClient { false };
76 bool m_isSuspended { false };
79 // All instances of MainThreadGenericEventQueue use a shared Timer for dispatching events.
80 class MainThreadGenericEventQueue : public GenericEventQueueBase<Timer> {
82 static UniqueRef<MainThreadGenericEventQueue> create(EventTarget&);
85 friend UniqueRef<MainThreadGenericEventQueue> WTF::makeUniqueRefWithoutFastMallocCheck<MainThreadGenericEventQueue, WebCore::EventTarget&>(WebCore::EventTarget&);
86 explicit MainThreadGenericEventQueue(EventTarget& eventTarget)
87 : GenericEventQueueBase<Timer>(eventTarget)
92 class GenericEventQueue : public GenericEventQueueBase<ScriptExecutionContext> {
93 WTF_MAKE_FAST_ALLOCATED;
95 static UniqueRef<GenericEventQueue> create(EventTarget&);
98 friend UniqueRef<GenericEventQueue> WTF::makeUniqueRefWithoutFastMallocCheck<GenericEventQueue, WebCore::EventTarget&>(WebCore::EventTarget&);
99 explicit GenericEventQueue(EventTarget& eventTarget)
100 : GenericEventQueueBase<ScriptExecutionContext>(eventTarget)
105 } // namespace WebCore