OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "core/dom/custom/CustomElementLifecycleCallbacks.h" | 38 #include "core/dom/custom/CustomElementLifecycleCallbacks.h" |
39 #include "core/dom/custom/CustomElementMicrotaskDispatcher.h" | 39 #include "core/dom/custom/CustomElementMicrotaskDispatcher.h" |
40 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" | 40 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" |
41 #include "core/dom/custom/CustomElementMicrotaskQueue.h" | 41 #include "core/dom/custom/CustomElementMicrotaskQueue.h" |
42 #include "core/dom/custom/CustomElementMicrotaskResolutionStep.h" | 42 #include "core/dom/custom/CustomElementMicrotaskResolutionStep.h" |
43 #include "core/dom/custom/CustomElementRegistrationContext.h" | 43 #include "core/dom/custom/CustomElementRegistrationContext.h" |
44 #include "core/html/imports/HTMLImportChild.h" | 44 #include "core/html/imports/HTMLImportChild.h" |
45 | 45 |
46 namespace WebCore { | 46 namespace WebCore { |
47 | 47 |
48 class HTMLImport; | 48 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CustomElementScheduler) |
49 | 49 |
50 void CustomElementScheduler::scheduleCallback(PassRefPtr<CustomElementLifecycleC
allbacks> callbacks, PassRefPtr<Element> element, CustomElementLifecycleCallback
s::CallbackType type) | 50 void CustomElementScheduler::scheduleCallback(PassRefPtr<CustomElementLifecycleC
allbacks> callbacks, PassRefPtrWillBeRawPtr<Element> element, CustomElementLifec
ycleCallbacks::CallbackType type) |
51 { | 51 { |
52 ASSERT(type != CustomElementLifecycleCallbacks::AttributeChanged); | 52 ASSERT(type != CustomElementLifecycleCallbacks::AttributeChanged); |
53 | 53 |
54 if (!callbacks->hasCallback(type)) | 54 if (!callbacks->hasCallback(type)) |
55 return; | 55 return; |
56 | 56 |
57 CustomElementCallbackQueue& queue = instance().schedule(element); | 57 CustomElementCallbackQueue& queue = instance().schedule(element); |
58 queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, ty
pe)); | 58 queue.append(CustomElementCallbackInvocation::createInvocation(callbacks, ty
pe)); |
59 } | 59 } |
60 | 60 |
61 void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE
lementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicSt
ring& name, const AtomicString& oldValue, const AtomicString& newValue) | 61 void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE
lementLifecycleCallbacks> callbacks, PassRefPtrWillBeRawPtr<Element> element, co
nst AtomicString& name, const AtomicString& oldValue, const AtomicString& newVal
ue) |
62 { | 62 { |
63 if (!callbacks->hasCallback(CustomElementLifecycleCallbacks::AttributeChange
d)) | 63 if (!callbacks->hasCallback(CustomElementLifecycleCallbacks::AttributeChange
d)) |
64 return; | 64 return; |
65 | 65 |
66 CustomElementCallbackQueue& queue = instance().schedule(element); | 66 CustomElementCallbackQueue& queue = instance().schedule(element); |
67 queue.append(CustomElementCallbackInvocation::createAttributeChangedInvocati
on(callbacks, name, oldValue, newValue)); | 67 queue.append(CustomElementCallbackInvocation::createAttributeChangedInvocati
on(callbacks, name, oldValue, newValue)); |
68 } | 68 } |
69 | 69 |
70 void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtr<CustomElemen
tRegistrationContext> context, PassRefPtr<Element> element, const CustomElementD
escriptor& descriptor) | 70 void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtrWillBeRawPtr<
CustomElementRegistrationContext> context, PassRefPtrWillBeRawPtr<Element> eleme
nt, const CustomElementDescriptor& descriptor) |
71 { | 71 { |
72 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { | 72 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { |
73 context->resolve(element.get(), descriptor); | 73 context->resolve(element.get(), descriptor); |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 HTMLImportLoader* loader = element->document().importLoader(); | 77 HTMLImportLoader* loader = element->document().importLoader(); |
78 OwnPtr<CustomElementMicrotaskResolutionStep> step = CustomElementMicrotaskRe
solutionStep::create(context, element, descriptor); | 78 OwnPtrWillBeRawPtr<CustomElementMicrotaskResolutionStep> step = CustomElemen
tMicrotaskResolutionStep::create(context, element, descriptor); |
79 CustomElementMicrotaskDispatcher::instance().enqueue(loader, step.release())
; | 79 CustomElementMicrotaskDispatcher::instance().enqueue(loader, step.release())
; |
80 } | 80 } |
81 | 81 |
82 CustomElementMicrotaskImportStep* CustomElementScheduler::scheduleImport(HTMLImp
ortChild* import) | 82 CustomElementMicrotaskImportStep* CustomElementScheduler::scheduleImport(HTMLImp
ortChild* import) |
83 { | 83 { |
84 ASSERT(!import->isDone()); | 84 ASSERT(!import->isDone()); |
85 ASSERT(import->parent()); | 85 ASSERT(import->parent()); |
86 | 86 |
87 OwnPtr<CustomElementMicrotaskImportStep> step = CustomElementMicrotaskImport
Step::create(import); | 87 OwnPtrWillBeRawPtr<CustomElementMicrotaskImportStep> step = CustomElementMic
rotaskImportStep::create(import); |
88 CustomElementMicrotaskImportStep* rawStep = step.get(); | 88 CustomElementMicrotaskImportStep* rawStep = step.get(); |
89 | 89 |
90 // Ownership of the new step is transferred to the parent | 90 // Ownership of the new step is transferred to the parent |
91 // processing step, or the base queue. | 91 // processing step, or the base queue. |
92 CustomElementMicrotaskDispatcher::instance().enqueue(import->parent()->loade
r(), step.release()); | 92 CustomElementMicrotaskDispatcher::instance().enqueue(import->parent()->loade
r(), step.release()); |
93 | 93 |
94 return rawStep; | 94 return rawStep; |
95 } | 95 } |
96 | 96 |
97 CustomElementScheduler& CustomElementScheduler::instance() | 97 CustomElementScheduler& CustomElementScheduler::instance() |
98 { | 98 { |
99 DEFINE_STATIC_LOCAL(CustomElementScheduler, instance, ()); | 99 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CustomElementScheduler>, instance
, (adoptPtrWillBeNoop (new CustomElementScheduler()))); |
100 return instance; | 100 return *instance; |
101 } | 101 } |
102 | 102 |
103 CustomElementCallbackQueue& CustomElementScheduler::ensureCallbackQueue(PassRefP
tr<Element> element) | 103 CustomElementCallbackQueue& CustomElementScheduler::ensureCallbackQueue(PassRefP
trWillBeRawPtr<Element> element) |
104 { | 104 { |
105 ElementCallbackQueueMap::ValueType* it = m_elementCallbackQueueMap.add(eleme
nt.get(), nullptr).storedValue; | 105 ElementCallbackQueueMap::ValueType* it = m_elementCallbackQueueMap.add(eleme
nt.get(), nullptr).storedValue; |
106 if (!it->value) | 106 if (!it->value) |
107 it->value = CustomElementCallbackQueue::create(element); | 107 it->value = CustomElementCallbackQueue::create(element); |
108 return *it->value.get(); | 108 return *it->value.get(); |
109 } | 109 } |
110 | 110 |
111 void CustomElementScheduler::callbackDispatcherDidFinish() | 111 void CustomElementScheduler::callbackDispatcherDidFinish() |
112 { | 112 { |
113 if (CustomElementMicrotaskDispatcher::instance().elementQueueIsEmpty()) | 113 if (CustomElementMicrotaskDispatcher::instance().elementQueueIsEmpty()) |
114 instance().clearElementCallbackQueueMap(); | 114 instance().clearElementCallbackQueueMap(); |
115 } | 115 } |
116 | 116 |
117 void CustomElementScheduler::microtaskDispatcherDidFinish() | 117 void CustomElementScheduler::microtaskDispatcherDidFinish() |
118 { | 118 { |
119 ASSERT(!CustomElementCallbackDispatcher::inCallbackDeliveryScope()); | 119 ASSERT(!CustomElementCallbackDispatcher::inCallbackDeliveryScope()); |
120 instance().clearElementCallbackQueueMap(); | 120 instance().clearElementCallbackQueueMap(); |
121 } | 121 } |
122 | 122 |
123 void CustomElementScheduler::clearElementCallbackQueueMap() | 123 void CustomElementScheduler::clearElementCallbackQueueMap() |
124 { | 124 { |
125 ElementCallbackQueueMap emptyMap; | 125 ElementCallbackQueueMap emptyMap; |
126 m_elementCallbackQueueMap.swap(emptyMap); | 126 m_elementCallbackQueueMap.swap(emptyMap); |
127 } | 127 } |
128 | 128 |
129 // Finds or creates the callback queue for element. | 129 // Finds or creates the callback queue for element. |
130 CustomElementCallbackQueue& CustomElementScheduler::schedule(PassRefPtr<Element>
passElement) | 130 CustomElementCallbackQueue& CustomElementScheduler::schedule(PassRefPtrWillBeRaw
Ptr<Element> passElement) |
131 { | 131 { |
132 RefPtr<Element> element(passElement); | 132 RefPtrWillBeRawPtr<Element> element(passElement); |
133 | 133 |
134 CustomElementCallbackQueue& callbackQueue = ensureCallbackQueue(element); | 134 CustomElementCallbackQueue& callbackQueue = ensureCallbackQueue(element); |
135 if (callbackQueue.inCreatedCallback()) { | 135 if (callbackQueue.inCreatedCallback()) { |
136 // Don't move it. Authors use the createdCallback like a | 136 // Don't move it. Authors use the createdCallback like a |
137 // constructor. By not moving it, the createdCallback | 137 // constructor. By not moving it, the createdCallback |
138 // completes before any other callbacks are entered for this | 138 // completes before any other callbacks are entered for this |
139 // element. | 139 // element. |
140 return callbackQueue; | 140 return callbackQueue; |
141 } | 141 } |
142 | 142 |
143 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { | 143 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { |
144 // The processing stack is active. | 144 // The processing stack is active. |
145 CustomElementCallbackDispatcher::instance().enqueue(&callbackQueue); | 145 CustomElementCallbackDispatcher::instance().enqueue(&callbackQueue); |
146 return callbackQueue; | 146 return callbackQueue; |
147 } | 147 } |
148 | 148 |
149 CustomElementMicrotaskDispatcher::instance().enqueue(&callbackQueue); | 149 CustomElementMicrotaskDispatcher::instance().enqueue(&callbackQueue); |
150 return callbackQueue; | 150 return callbackQueue; |
151 } | 151 } |
152 | 152 |
| 153 void CustomElementScheduler::trace(Visitor* visitor) |
| 154 { |
| 155 visitor->trace(m_elementCallbackQueueMap); |
| 156 } |
| 157 |
153 } // namespace WebCore | 158 } // namespace WebCore |
OLD | NEW |