Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: Source/core/dom/custom/CustomElementScheduler.cpp

Issue 144023016: Separate Custom Element resolution and upgrade/createdCallback. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/custom/CustomElementScheduler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/dom/custom/CustomElementScheduler.h" 32 #include "core/dom/custom/CustomElementScheduler.h"
33 33
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/Element.h" 35 #include "core/dom/Element.h"
36 #include "core/dom/custom/CustomElementCallbackDispatcher.h" 36 #include "core/dom/custom/CustomElementCallbackDispatcher.h"
37 #include "core/dom/custom/CustomElementCallbackInvocation.h" 37 #include "core/dom/custom/CustomElementCallbackInvocation.h"
38 #include "core/dom/custom/CustomElementLifecycleCallbacks.h" 38 #include "core/dom/custom/CustomElementLifecycleCallbacks.h"
39 #include "core/dom/custom/CustomElementMicrotaskElementStep.h"
40 #include "core/dom/custom/CustomElementMicrotaskImportStep.h" 39 #include "core/dom/custom/CustomElementMicrotaskImportStep.h"
40 #include "core/dom/custom/CustomElementMicrotaskResolutionStep.h"
41 #include "core/dom/custom/CustomElementRegistrationContext.h" 41 #include "core/dom/custom/CustomElementRegistrationContext.h"
42 #include "core/dom/custom/CustomElementResolutionStep.h"
43 #include "core/html/HTMLImport.h"
44 #include "core/html/HTMLImportChild.h" 42 #include "core/html/HTMLImportChild.h"
45 #include "wtf/MainThread.h" 43 #include "wtf/MainThread.h"
46 44
47 namespace WebCore { 45 namespace WebCore {
48 46
47 class HTMLImport;
48
49 void CustomElementScheduler::scheduleCreatedCallback(PassRefPtr<CustomElementLif ecycleCallbacks> callbacks, PassRefPtr<Element> element)
50 {
51 CustomElementCallbackQueue* queue = instance().schedule(element);
52 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C ustomElementLifecycleCallbacks::Created));
53 }
54
49 void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE lementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicSt ring& name, const AtomicString& oldValue, const AtomicString& newValue) 55 void CustomElementScheduler::scheduleAttributeChangedCallback(PassRefPtr<CustomE lementLifecycleCallbacks> callbacks, PassRefPtr<Element> element, const AtomicSt ring& name, const AtomicString& oldValue, const AtomicString& newValue)
50 { 56 {
51 if (!callbacks->hasAttributeChangedCallback()) 57 if (!callbacks->hasAttributeChangedCallback())
52 return; 58 return;
53 59
54 CustomElementCallbackQueue* queue = instance().schedule(element); 60 CustomElementCallbackQueue* queue = instance().schedule(element);
55 queue->append(CustomElementCallbackInvocation::createAttributeChangedInvocat ion(callbacks, name, oldValue, newValue)); 61 queue->append(CustomElementCallbackInvocation::createAttributeChangedInvocat ion(callbacks, name, oldValue, newValue));
56 } 62 }
57 63
58 void CustomElementScheduler::scheduleAttachedCallback(PassRefPtr<CustomElementLi fecycleCallbacks> callbacks, PassRefPtr<Element> element) 64 void CustomElementScheduler::scheduleAttachedCallback(PassRefPtr<CustomElementLi fecycleCallbacks> callbacks, PassRefPtr<Element> element)
59 { 65 {
60 if (!callbacks->hasAttachedCallback()) 66 if (!callbacks->hasAttachedCallback())
61 return; 67 return;
62 68
63 CustomElementCallbackQueue* queue = instance().schedule(element); 69 CustomElementCallbackQueue* queue = instance().schedule(element);
64 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C ustomElementLifecycleCallbacks::Attached)); 70 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C ustomElementLifecycleCallbacks::Attached));
65 } 71 }
66 72
67 void CustomElementScheduler::scheduleDetachedCallback(PassRefPtr<CustomElementLi fecycleCallbacks> callbacks, PassRefPtr<Element> element) 73 void CustomElementScheduler::scheduleDetachedCallback(PassRefPtr<CustomElementLi fecycleCallbacks> callbacks, PassRefPtr<Element> element)
68 { 74 {
69 if (!callbacks->hasDetachedCallback()) 75 if (!callbacks->hasDetachedCallback())
70 return; 76 return;
71 77
72 CustomElementCallbackQueue* queue = instance().schedule(element); 78 CustomElementCallbackQueue* queue = instance().schedule(element);
73 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C ustomElementLifecycleCallbacks::Detached)); 79 queue->append(CustomElementCallbackInvocation::createInvocation(callbacks, C ustomElementLifecycleCallbacks::Detached));
74 } 80 }
75 81
76 void CustomElementScheduler::scheduleResolutionStep(const CustomElementDescripto r& descriptor, PassRefPtr<Element> element) 82 void CustomElementScheduler::resolveOrScheduleResolution(PassRefPtr<CustomElemen tRegistrationContext> context, PassRefPtr<Element> element, const CustomElementD escriptor& descriptor)
77 { 83 {
78 RefPtr<CustomElementRegistrationContext> context = element->document().regis trationContext(); 84 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) {
79 CustomElementCallbackQueue* queue = instance().schedule(element); 85 context->resolve(element.get(), descriptor);
80 queue->append(CustomElementResolutionStep::create(context.release(), descrip tor)); 86 return;
87 }
88
89 HTMLImport* import = element->document().import();
90 OwnPtr<CustomElementMicrotaskResolutionStep> step = CustomElementMicrotaskRe solutionStep::create(context, element, descriptor);
91 instance().m_microtaskDispatcher.enqueue(import, step.release());
81 } 92 }
82 93
83 CustomElementMicrotaskImportStep* CustomElementScheduler::scheduleImport(HTMLImp ortChild* import) 94 CustomElementMicrotaskImportStep* CustomElementScheduler::scheduleImport(HTMLImp ortChild* import)
84 { 95 {
85 ASSERT(!import->isDone()); 96 ASSERT(!import->isDone());
86 ASSERT(import->parent()); 97 ASSERT(import->parent());
87 98
88 OwnPtr<CustomElementMicrotaskImportStep> step = CustomElementMicrotaskImport Step::create(); 99 OwnPtr<CustomElementMicrotaskImportStep> step = CustomElementMicrotaskImport Step::create();
89 CustomElementMicrotaskImportStep* rawStep = step.get(); 100 CustomElementMicrotaskImportStep* rawStep = step.get();
90 101
91 // Ownership of the new step is transferred to the parent 102 // Ownership of the new step is transferred to the parent
92 // processing step, or the base queue. 103 // processing step, or the base queue.
93 if (CustomElementMicrotaskImportStep* parentStep = import->parent()->customE lementMicrotaskStep()) 104 instance().m_microtaskDispatcher.enqueue(import->parent(), step.release());
94 parentStep->enqueue(step.release());
95 else
96 instance().m_baseMicrotaskQueue.enqueue(step.release());
97 105
98 return rawStep; 106 return rawStep;
99 } 107 }
100 108
101 CustomElementScheduler& CustomElementScheduler::instance() 109 CustomElementScheduler& CustomElementScheduler::instance()
102 { 110 {
103 DEFINE_STATIC_LOCAL(CustomElementScheduler, instance, ()); 111 DEFINE_STATIC_LOCAL(CustomElementScheduler, instance, ());
104 return instance; 112 return instance;
105 } 113 }
106 114
(...skipping 25 matching lines...) Expand all
132 // element. 140 // element.
133 return callbackQueue; 141 return callbackQueue;
134 } 142 }
135 143
136 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) { 144 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) {
137 // The processing stack is active. 145 // The processing stack is active.
138 CustomElementCallbackDispatcher::instance().enqueue(callbackQueue); 146 CustomElementCallbackDispatcher::instance().enqueue(callbackQueue);
139 return callbackQueue; 147 return callbackQueue;
140 } 148 }
141 149
142 HTMLImport* import = element->document().import(); 150 m_microtaskDispatcher.enqueue(callbackQueue);
143 if (import && import->customElementMicrotaskStep()) {
144 // The base element queue is active, but the element is in a
145 // parser-created import.
146 import->customElementMicrotaskStep()->enqueue(CustomElementMicrotaskElem entStep::create(callbackQueue));
147 return callbackQueue;
148 }
149
150 // The base element queue is active. The element is not in a
151 // parser-created import.
152 m_baseMicrotaskQueue.enqueue(CustomElementMicrotaskElementStep::create(callb ackQueue));
153 return callbackQueue; 151 return callbackQueue;
154 } 152 }
155 153
156 bool CustomElementScheduler::dispatch() 154 bool CustomElementScheduler::dispatch()
157 { 155 {
158 ASSERT(isMainThread()); 156 ASSERT(isMainThread());
159 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope()) 157 if (CustomElementCallbackDispatcher::inCallbackDeliveryScope())
160 return false; 158 return false;
161 159
162 CustomElementMicrotaskStep::Result result = m_baseMicrotaskQueue.dispatch(); 160 bool didWork = m_microtaskDispatcher.dispatch();
163 if (m_baseMicrotaskQueue.isEmpty()) 161 ASSERT(m_microtaskDispatcher.elementQueueIsEmpty());
164 clearElementCallbackQueueMap(); 162 clearElementCallbackQueueMap();
165 163 return didWork;
166 return result & CustomElementMicrotaskStep::DidWork;
167 } 164 }
168 165
169 } // namespace WebCore 166 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/custom/CustomElementScheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698