OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/dom/custom/V0CustomElementMicrotaskDispatcher.h" |
| 6 |
| 7 #include "bindings/core/v8/Microtask.h" |
| 8 #include "core/dom/custom/V0CustomElementCallbackQueue.h" |
| 9 #include "core/dom/custom/V0CustomElementMicrotaskImportStep.h" |
| 10 #include "core/dom/custom/V0CustomElementProcessingStack.h" |
| 11 #include "core/dom/custom/V0CustomElementScheduler.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 static const V0CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; |
| 16 |
| 17 V0CustomElementMicrotaskDispatcher::V0CustomElementMicrotaskDispatcher() |
| 18 : m_hasScheduledMicrotask(false) |
| 19 , m_phase(Quiescent) |
| 20 { |
| 21 } |
| 22 |
| 23 V0CustomElementMicrotaskDispatcher& V0CustomElementMicrotaskDispatcher::instance
() |
| 24 { |
| 25 DEFINE_STATIC_LOCAL(V0CustomElementMicrotaskDispatcher, instance, (new V0Cus
tomElementMicrotaskDispatcher)); |
| 26 return instance; |
| 27 } |
| 28 |
| 29 void V0CustomElementMicrotaskDispatcher::enqueue(V0CustomElementCallbackQueue* q
ueue) |
| 30 { |
| 31 ensureMicrotaskScheduledForElementQueue(); |
| 32 queue->setOwner(kMicrotaskQueueId); |
| 33 m_elements.append(queue); |
| 34 } |
| 35 |
| 36 void V0CustomElementMicrotaskDispatcher::ensureMicrotaskScheduledForElementQueue
() |
| 37 { |
| 38 DCHECK(m_phase == Quiescent || m_phase == Resolving); |
| 39 ensureMicrotaskScheduled(); |
| 40 } |
| 41 |
| 42 void V0CustomElementMicrotaskDispatcher::ensureMicrotaskScheduled() |
| 43 { |
| 44 if (!m_hasScheduledMicrotask) { |
| 45 Microtask::enqueueMicrotask(WTF::bind(&dispatch)); |
| 46 m_hasScheduledMicrotask = true; |
| 47 } |
| 48 } |
| 49 |
| 50 void V0CustomElementMicrotaskDispatcher::dispatch() |
| 51 { |
| 52 instance().doDispatch(); |
| 53 } |
| 54 |
| 55 void V0CustomElementMicrotaskDispatcher::doDispatch() |
| 56 { |
| 57 DCHECK(isMainThread()); |
| 58 |
| 59 DCHECK(m_phase == Quiescent); |
| 60 DCHECK(m_hasScheduledMicrotask); |
| 61 m_hasScheduledMicrotask = false; |
| 62 |
| 63 // Finishing microtask work deletes all |
| 64 // V0CustomElementCallbackQueues. Being in a callback delivery scope |
| 65 // implies those queues could still be in use. |
| 66 ASSERT_WITH_SECURITY_IMPLICATION(!V0CustomElementProcessingStack::inCallback
DeliveryScope()); |
| 67 |
| 68 m_phase = Resolving; |
| 69 |
| 70 m_phase = DispatchingCallbacks; |
| 71 for (const auto& element : m_elements) { |
| 72 // Created callback may enqueue an attached callback. |
| 73 V0CustomElementProcessingStack::CallbackDeliveryScope scope; |
| 74 element->processInElementQueue(kMicrotaskQueueId); |
| 75 } |
| 76 |
| 77 m_elements.clear(); |
| 78 V0CustomElementScheduler::microtaskDispatcherDidFinish(); |
| 79 m_phase = Quiescent; |
| 80 } |
| 81 |
| 82 DEFINE_TRACE(V0CustomElementMicrotaskDispatcher) |
| 83 { |
| 84 visitor->trace(m_elements); |
| 85 } |
| 86 |
| 87 } // namespace blink |
OLD | NEW |