| 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/CustomElementScheduler.h" | 13 #include "core/dom/custom/CustomElementScheduler.h" |
| 13 #include "core/html/imports/HTMLImport.h" | 14 #include "core/html/imports/HTMLImportLoader.h" |
| 14 #include "wtf/MainThread.h" | 15 #include "wtf/MainThread.h" |
| 15 | 16 |
| 16 namespace WebCore { | 17 namespace WebCore { |
| 17 | 18 |
| 18 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; | 19 static const CustomElementCallbackQueue::ElementQueueId kMicrotaskQueueId = 0; |
| 19 | 20 |
| 20 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() | 21 CustomElementMicrotaskDispatcher::CustomElementMicrotaskDispatcher() |
| 21 : m_hasScheduledMicrotask(false) | 22 : m_hasScheduledMicrotask(false) |
| 22 , m_phase(Quiescent) | 23 , m_phase(Quiescent) |
| 24 , m_resolutionAndImports(CustomElementMicrotaskQueue::create()) |
| 23 { | 25 { |
| 24 } | 26 } |
| 25 | 27 |
| 26 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() | 28 CustomElementMicrotaskDispatcher& CustomElementMicrotaskDispatcher::instance() |
| 27 { | 29 { |
| 28 DEFINE_STATIC_LOCAL(CustomElementMicrotaskDispatcher, instance, ()); | 30 DEFINE_STATIC_LOCAL(CustomElementMicrotaskDispatcher, instance, ()); |
| 29 return instance; | 31 return instance; |
| 30 } | 32 } |
| 31 | 33 |
| 32 void CustomElementMicrotaskDispatcher::enqueue(HTMLImport* import, PassOwnPtr<Cu
stomElementMicrotaskStep> step) | 34 void CustomElementMicrotaskDispatcher::enqueue(HTMLImportLoader* importLoader, P
assOwnPtr<CustomElementMicrotaskStep> step) |
| 33 { | 35 { |
| 34 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); | 36 ASSERT(m_phase == Quiescent || m_phase == DispatchingCallbacks); |
| 35 ensureMicrotaskScheduled(); | 37 ensureMicrotaskScheduled(); |
| 36 if (import && import->customElementMicrotaskStep()) | 38 if (importLoader) |
| 37 import->customElementMicrotaskStep()->enqueue(step); | 39 importLoader->microtaskQueue()->enqueue(step); |
| 38 else | 40 else |
| 39 m_resolutionAndImports.enqueue(step); | 41 m_resolutionAndImports->enqueue(step); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue
) | 44 void CustomElementMicrotaskDispatcher::enqueue(CustomElementCallbackQueue* queue
) |
| 43 { | 45 { |
| 44 ASSERT(m_phase == Quiescent || m_phase == Resolving); | 46 ASSERT(m_phase == Quiescent || m_phase == Resolving); |
| 45 ensureMicrotaskScheduled(); | 47 ensureMicrotaskScheduled(); |
| 46 queue->setOwner(kMicrotaskQueueId); | 48 queue->setOwner(kMicrotaskQueueId); |
| 47 m_elements.append(queue); | 49 m_elements.append(queue); |
| 48 } | 50 } |
| 49 | 51 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 72 | 74 |
| 73 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); | 75 ASSERT(m_phase == Quiescent && m_hasScheduledMicrotask); |
| 74 m_hasScheduledMicrotask = false; | 76 m_hasScheduledMicrotask = false; |
| 75 | 77 |
| 76 // Finishing microtask work deletes all | 78 // Finishing microtask work deletes all |
| 77 // CustomElementCallbackQueues. Being in a callback delivery scope | 79 // CustomElementCallbackQueues. Being in a callback delivery scope |
| 78 // implies those queues could still be in use. | 80 // implies those queues could still be in use. |
| 79 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac
kDeliveryScope()); | 81 ASSERT_WITH_SECURITY_IMPLICATION(!CustomElementCallbackDispatcher::inCallbac
kDeliveryScope()); |
| 80 | 82 |
| 81 m_phase = Resolving; | 83 m_phase = Resolving; |
| 82 m_resolutionAndImports.dispatch(); | 84 m_resolutionAndImports->dispatch(); |
| 83 | 85 |
| 84 m_phase = DispatchingCallbacks; | 86 m_phase = DispatchingCallbacks; |
| 85 for (Vector<CustomElementCallbackQueue*>::iterator it = m_elements.begin();i
t != m_elements.end(); ++it) { | 87 for (Vector<CustomElementCallbackQueue*>::iterator it = m_elements.begin();i
t != m_elements.end(); ++it) { |
| 86 // Created callback may enqueue an attached callback. | 88 // Created callback may enqueue an attached callback. |
| 87 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; | 89 CustomElementCallbackDispatcher::CallbackDeliveryScope scope; |
| 88 (*it)->processInElementQueue(kMicrotaskQueueId); | 90 (*it)->processInElementQueue(kMicrotaskQueueId); |
| 89 } | 91 } |
| 90 | 92 |
| 91 m_elements.clear(); | 93 m_elements.clear(); |
| 92 CustomElementScheduler::microtaskDispatcherDidFinish(); | 94 CustomElementScheduler::microtaskDispatcherDidFinish(); |
| 93 m_phase = Quiescent; | 95 m_phase = Quiescent; |
| 94 } | 96 } |
| 95 | 97 |
| 96 } // namespace WebCore | 98 } // namespace WebCore |
| OLD | NEW |