| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/dom/custom/CustomElementMicrotaskDispatcher.h" | 6 #include "core/dom/custom/CustomElementMicrotaskDispatcher.h" |
| 7 | 7 |
| 8 #include "core/dom/Microtask.h" | 8 #include "core/dom/Microtask.h" |
| 9 #include "core/dom/custom/CustomElementCallbackDispatcher.h" | 9 #include "core/dom/custom/CustomElementCallbackDispatcher.h" |
| 10 #include "core/dom/custom/CustomElementCallbackQueue.h" | 10 #include "core/dom/custom/CustomElementCallbackQueue.h" |
| 11 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" | 11 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" |
| 12 #include "core/dom/custom/CustomElementMicrotaskQueue.h" | 12 #include "core/dom/custom/CustomElementMicrotaskQueue.h" |
| 13 #include "core/dom/custom/CustomElementScheduler.h" | 13 #include "core/dom/custom/CustomElementScheduler.h" |
| 14 #include "core/html/imports/HTMLImportLoader.h" | 14 #include "core/html/imports/HTMLImportLoader.h" |
| 15 #include "wtf/MainThread.h" | 15 #include "wtf/MainThread.h" |
| 16 | 16 |
| 17 namespace WebCore { | 17 namespace WebCore { |
| 18 | 18 |
| 19 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; | 19 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; |
| 20 | 20 |
| 21 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() | 21 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() |
| 22 : m_hasScheduledMicrotask(false) | 22 : m_hasScheduledMicrotask(false) |
| 23 , m_phase(Quiescent) | 23 , m_phase(Quiescent) |
| 24 , m_resolutionAndImports(CustomElementMicrotaskQueue::create()) | 24 , m_resolutionAndImports(CustomElementMicrotaskQueue::create()) |
| 25 { | 25 { |
| 26 } | 26 } |
| 27 | 27 |
| 28 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CustomElementMicrotaskDispatcher) |
| 29 |
| 28 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() | 30 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() |
| 29 { | 31 { |
| 30 DEFINE_STATIC_LOCAL(CustomElementMicrotaskDispatcher, instance, ()); | 32 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CustomElementMicrotaskDispatcher>
, instance, (adoptPtrWillBeNoop(new CustomElementMicrotaskDispatcher()))); |
| 31 return instance; | 33 return *instance; |
| 32 } | 34 } |
| 33 | 35 |
| 34 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* importLoader, P
assOwnPtr<CustomElementMicrotaskStep> step) | 36 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* importLoader, P
assOwnPtrWillBeRawPtr<CustomElementMicrotaskStep> step) |
| 35 { | 37 { |
| 36 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); | 38 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); |
| 37 ensureMicrotaskScheduled(); | 39 ensureMicrotaskScheduled(); |
| 38 if (importLoader) | 40 if (importLoader) |
| 39 importLoader->microtaskQueue()->enqueue(step); | 41 importLoader->microtaskQueue()->enqueue(step); |
| 40 else | 42 else |
| 41 m_resolutionAndImports->enqueue(step); | 43 m_resolutionAndImports->enqueue(step); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue
) | 46 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue
) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 79 |
| 78 // Finishing microtask work deletes all | 80 // Finishing microtask work deletes all |
| 79 // CustomElementCallbackQueues. Being in a callback delivery scope | 81 // CustomElementCallbackQueues. Being in a callback delivery scope |
| 80 // implies those queues could still be in use. | 82 // implies those queues could still be in use. |
| 81 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac
kDeliveryScope()); | 83 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac
kDeliveryScope()); |
| 82 | 84 |
| 83 m_phase = Resolving; | 85 m_phase = Resolving; |
| 84 m_resolutionAndImports->dispatch(); | 86 m_resolutionAndImports->dispatch(); |
| 85 | 87 |
| 86 m_phase = DispatchingCallbacks; | 88 m_phase = DispatchingCallbacks; |
| 87 for (Vector<CustomElementCallbackQueue*>::iterator it = m_elements.begin();i
t != m_elements.end(); ++it) { | 89 for (WillBeHeapVector<RawPtrWillBeMember<CustomElementCallbackQueue> >::iter
ator it = m_elements.begin(); it != m_elements.end(); ++it) { |
| 88 // Created callback may enqueue an attached callback. | 90 // Created callback may enqueue an attached callback. |
| 89 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; | 91 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; |
| 90 (*it)->processInElementQueue(kMicrotaskQueueId); | 92 (*it)->processInElementQueue(kMicrotaskQueueId); |
| 91 } | 93 } |
| 92 | 94 |
| 93 m_elements.clear(); | 95 m_elements.clear(); |
| 94 CustomElementScheduler::microtaskDispatcherDidFinish(); | 96 CustomElementScheduler::microtaskDispatcherDidFinish(); |
| 95 m_phase = Quiescent; | 97 m_phase = Quiescent; |
| 96 } | 98 } |
| 97 | 99 |
| 100 void CustomElementMicrotaskDispatcher::trace(Visitor* visitor) |
| 101 { |
| 102 visitor->trace(m_resolutionAndImports); |
| 103 #if ENABLE(OILPAN) |
| 104 visitor->trace(m_elements); |
| 105 #endif |
| 106 } |
| 107 |
| 98 #if !defined(NDEBUG) | 108 #if !defined(NDEBUG) |
| 99 void CustomElementMicrotaskDispatcher::show() | 109 void CustomElementMicrotaskDispatcher::show() |
| 100 { | 110 { |
| 101 fprintf(stderr, "Dispatcher:\n"); | 111 fprintf(stderr, "Dispatcher:\n"); |
| 102 m_resolutionAndImports->show(1); | 112 m_resolutionAndImports->show(1); |
| 103 } | 113 } |
| 104 #endif | 114 #endif |
| 105 | 115 |
| 106 } // namespace WebCore | 116 } // namespace WebCore |
| 107 | 117 |
| 108 #if !defined(NDEBUG) | 118 #if !defined(NDEBUG) |
| 109 void showCEMD() | 119 void showCEMD() |
| 110 { | 120 { |
| 111 WebCore::CustomElementMicrotaskDispatcher::instance().show(); | 121 WebCore::CustomElementMicrotaskDispatcher::instance().show(); |
| 112 } | 122 } |
| 113 #endif | 123 #endif |
| OLD | NEW |