| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 #include "core/events/DOMWindowEventQueue.h" | 27 #include "core/events/DOMWindowEventQueue.h" |
| 28 | 28 |
| 29 #include "core/events/Event.h" | 29 #include "core/events/Event.h" |
| 30 #include "core/frame/LocalDOMWindow.h" | 30 #include "core/frame/LocalDOMWindow.h" |
| 31 #include "core/frame/SuspendableTimer.h" | 31 #include "core/frame/SuspendableTimer.h" |
| 32 #include "core/inspector/InspectorInstrumentation.h" | 32 #include "core/inspector/InspectorInstrumentation.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 class DOMWindowEventQueueTimer final : public NoBaseWillBeGarbageCollectedFinali
zed<DOMWindowEventQueueTimer>, public SuspendableTimer { | 36 class DOMWindowEventQueueTimer final : public GarbageCollectedFinalized<DOMWindo
wEventQueueTimer>, public SuspendableTimer { |
| 37 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(DOMWindowEventQueueTimer); | 37 USING_GARBAGE_COLLECTED_MIXIN(DOMWindowEventQueueTimer); |
| 38 WTF_MAKE_NONCOPYABLE(DOMWindowEventQueueTimer); | 38 WTF_MAKE_NONCOPYABLE(DOMWindowEventQueueTimer); |
| 39 public: | 39 public: |
| 40 DOMWindowEventQueueTimer(DOMWindowEventQueue* eventQueue, ExecutionContext*
context) | 40 DOMWindowEventQueueTimer(DOMWindowEventQueue* eventQueue, ExecutionContext*
context) |
| 41 : SuspendableTimer(context) | 41 : SuspendableTimer(context) |
| 42 , m_eventQueue(eventQueue) | 42 , m_eventQueue(eventQueue) |
| 43 { | 43 { |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Eager finalization is needed to promptly stop this timer object. | 46 // Eager finalization is needed to promptly stop this timer object. |
| 47 // (see DOMTimer comment for more.) | 47 // (see DOMTimer comment for more.) |
| 48 EAGERLY_FINALIZE(); | 48 EAGERLY_FINALIZE(); |
| 49 DEFINE_INLINE_VIRTUAL_TRACE() | 49 DEFINE_INLINE_VIRTUAL_TRACE() |
| 50 { | 50 { |
| 51 visitor->trace(m_eventQueue); | 51 visitor->trace(m_eventQueue); |
| 52 SuspendableTimer::trace(visitor); | 52 SuspendableTimer::trace(visitor); |
| 53 } | 53 } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 virtual void fired() { m_eventQueue->pendingEventTimerFired(); } | 56 virtual void fired() { m_eventQueue->pendingEventTimerFired(); } |
| 57 | 57 |
| 58 RawPtrWillBeMember<DOMWindowEventQueue> m_eventQueue; | 58 Member<DOMWindowEventQueue> m_eventQueue; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 PassRefPtrWillBeRawPtr<DOMWindowEventQueue> DOMWindowEventQueue::create(Executio
nContext* context) | 61 RawPtr<DOMWindowEventQueue> DOMWindowEventQueue::create(ExecutionContext* contex
t) |
| 62 { | 62 { |
| 63 return adoptRefWillBeNoop(new DOMWindowEventQueue(context)); | 63 return new DOMWindowEventQueue(context); |
| 64 } | 64 } |
| 65 | 65 |
| 66 DOMWindowEventQueue::DOMWindowEventQueue(ExecutionContext* context) | 66 DOMWindowEventQueue::DOMWindowEventQueue(ExecutionContext* context) |
| 67 : m_pendingEventTimer(adoptPtrWillBeNoop(new DOMWindowEventQueueTimer(this,
context))) | 67 : m_pendingEventTimer(new DOMWindowEventQueueTimer(this, context)) |
| 68 , m_isClosed(false) | 68 , m_isClosed(false) |
| 69 { | 69 { |
| 70 m_pendingEventTimer->suspendIfNeeded(); | 70 m_pendingEventTimer->suspendIfNeeded(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 DOMWindowEventQueue::~DOMWindowEventQueue() | 73 DOMWindowEventQueue::~DOMWindowEventQueue() |
| 74 { | 74 { |
| 75 } | 75 } |
| 76 | 76 |
| 77 DEFINE_TRACE(DOMWindowEventQueue) | 77 DEFINE_TRACE(DOMWindowEventQueue) |
| 78 { | 78 { |
| 79 #if ENABLE(OILPAN) | 79 #if ENABLE(OILPAN) |
| 80 visitor->trace(m_pendingEventTimer); | 80 visitor->trace(m_pendingEventTimer); |
| 81 visitor->trace(m_queuedEvents); | 81 visitor->trace(m_queuedEvents); |
| 82 #endif | 82 #endif |
| 83 EventQueue::trace(visitor); | 83 EventQueue::trace(visitor); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool DOMWindowEventQueue::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) | 86 bool DOMWindowEventQueue::enqueueEvent(RawPtr<Event> event) |
| 87 { | 87 { |
| 88 if (m_isClosed) | 88 if (m_isClosed) |
| 89 return false; | 89 return false; |
| 90 | 90 |
| 91 ASSERT(event->target()); | 91 ASSERT(event->target()); |
| 92 InspectorInstrumentation::didEnqueueEvent(event->target(), event.get()); | 92 InspectorInstrumentation::didEnqueueEvent(event->target(), event.get()); |
| 93 | 93 |
| 94 bool wasAdded = m_queuedEvents.add(event).isNewEntry; | 94 bool wasAdded = m_queuedEvents.add(event).isNewEntry; |
| 95 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. | 95 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. |
| 96 | 96 |
| 97 if (!m_pendingEventTimer->isActive()) | 97 if (!m_pendingEventTimer->isActive()) |
| 98 m_pendingEventTimer->startOneShot(0, BLINK_FROM_HERE); | 98 m_pendingEventTimer->startOneShot(0, BLINK_FROM_HERE); |
| 99 | 99 |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool DOMWindowEventQueue::cancelEvent(Event* event) | 103 bool DOMWindowEventQueue::cancelEvent(Event* event) |
| 104 { | 104 { |
| 105 WillBeHeapListHashSet<RefPtrWillBeMember<Event>, 16>::iterator it = m_queued
Events.find(event); | 105 HeapListHashSet<Member<Event>, 16>::iterator it = m_queuedEvents.find(event)
; |
| 106 bool found = it != m_queuedEvents.end(); | 106 bool found = it != m_queuedEvents.end(); |
| 107 if (found) { | 107 if (found) { |
| 108 InspectorInstrumentation::didRemoveEvent(event->target(), event); | 108 InspectorInstrumentation::didRemoveEvent(event->target(), event); |
| 109 m_queuedEvents.remove(it); | 109 m_queuedEvents.remove(it); |
| 110 } | 110 } |
| 111 if (m_queuedEvents.isEmpty()) | 111 if (m_queuedEvents.isEmpty()) |
| 112 m_pendingEventTimer->stop(); | 112 m_pendingEventTimer->stop(); |
| 113 return found; | 113 return found; |
| 114 } | 114 } |
| 115 | 115 |
| 116 void DOMWindowEventQueue::close() | 116 void DOMWindowEventQueue::close() |
| 117 { | 117 { |
| 118 m_isClosed = true; | 118 m_isClosed = true; |
| 119 m_pendingEventTimer->stop(); | 119 m_pendingEventTimer->stop(); |
| 120 if (InspectorInstrumentation::hasFrontends()) { | 120 if (InspectorInstrumentation::hasFrontends()) { |
| 121 for (const auto& queuedEvent : m_queuedEvents) { | 121 for (const auto& queuedEvent : m_queuedEvents) { |
| 122 RefPtrWillBeRawPtr<Event> event = queuedEvent; | 122 RawPtr<Event> event = queuedEvent; |
| 123 if (event) | 123 if (event) |
| 124 InspectorInstrumentation::didRemoveEvent(event->target(), event.
get()); | 124 InspectorInstrumentation::didRemoveEvent(event->target(), event.
get()); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 m_queuedEvents.clear(); | 127 m_queuedEvents.clear(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void DOMWindowEventQueue::pendingEventTimerFired() | 130 void DOMWindowEventQueue::pendingEventTimerFired() |
| 131 { | 131 { |
| 132 ASSERT(!m_pendingEventTimer->isActive()); | 132 ASSERT(!m_pendingEventTimer->isActive()); |
| 133 ASSERT(!m_queuedEvents.isEmpty()); | 133 ASSERT(!m_queuedEvents.isEmpty()); |
| 134 | 134 |
| 135 // Insert a marker for where we should stop. | 135 // Insert a marker for where we should stop. |
| 136 ASSERT(!m_queuedEvents.contains(nullptr)); | 136 ASSERT(!m_queuedEvents.contains(nullptr)); |
| 137 bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry; | 137 bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry; |
| 138 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. | 138 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. |
| 139 | 139 |
| 140 RefPtrWillBeRawPtr<DOMWindowEventQueue> protector(this); | 140 RawPtr<DOMWindowEventQueue> protector(this); |
| 141 | 141 |
| 142 while (!m_queuedEvents.isEmpty()) { | 142 while (!m_queuedEvents.isEmpty()) { |
| 143 WillBeHeapListHashSet<RefPtrWillBeMember<Event>, 16>::iterator iter = m_
queuedEvents.begin(); | 143 HeapListHashSet<Member<Event>, 16>::iterator iter = m_queuedEvents.begin
(); |
| 144 RefPtrWillBeRawPtr<Event> event = *iter; | 144 RawPtr<Event> event = *iter; |
| 145 m_queuedEvents.remove(iter); | 145 m_queuedEvents.remove(iter); |
| 146 if (!event) | 146 if (!event) |
| 147 break; | 147 break; |
| 148 dispatchEvent(event.get()); | 148 dispatchEvent(event.get()); |
| 149 InspectorInstrumentation::didRemoveEvent(event->target(), event.get()); | 149 InspectorInstrumentation::didRemoveEvent(event->target(), event.get()); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 void DOMWindowEventQueue::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event) | 153 void DOMWindowEventQueue::dispatchEvent(RawPtr<Event> event) |
| 154 { | 154 { |
| 155 EventTarget* eventTarget = event->target(); | 155 EventTarget* eventTarget = event->target(); |
| 156 if (eventTarget->toDOMWindow()) | 156 if (eventTarget->toDOMWindow()) |
| 157 eventTarget->toDOMWindow()->dispatchEvent(event, nullptr); | 157 eventTarget->toDOMWindow()->dispatchEvent(event, nullptr); |
| 158 else | 158 else |
| 159 eventTarget->dispatchEvent(event); | 159 eventTarget->dispatchEvent(event); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |