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

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElementsRegistry.cpp

Issue 2200613002: The HTML parser synchronously creates custom elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Eliminate redundant TODOs. Created 4 years, 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/dom/custom/CustomElementsRegistry.h" 5 #include "core/dom/custom/CustomElementsRegistry.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h" 8 #include "bindings/core/v8/ScriptCustomElementDefinitionBuilder.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
11 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
12 #include "core/dom/Element.h" 12 #include "core/dom/Element.h"
13 #include "core/dom/ElementRegistrationOptions.h" 13 #include "core/dom/ElementRegistrationOptions.h"
14 #include "core/dom/ExceptionCode.h" 14 #include "core/dom/ExceptionCode.h"
15 #include "core/dom/custom/CEReactionsScope.h" 15 #include "core/dom/custom/CEReactionsScope.h"
16 #include "core/dom/custom/CustomElement.h" 16 #include "core/dom/custom/CustomElement.h"
17 #include "core/dom/custom/CustomElementDefinition.h" 17 #include "core/dom/custom/CustomElementDefinition.h"
18 #include "core/dom/custom/CustomElementDefinitionBuilder.h" 18 #include "core/dom/custom/CustomElementDefinitionBuilder.h"
19 #include "core/dom/custom/CustomElementDescriptor.h" 19 #include "core/dom/custom/CustomElementDescriptor.h"
20 #include "core/dom/custom/CustomElementUpgradeReaction.h" 20 #include "core/dom/custom/CustomElementUpgradeReaction.h"
21 #include "core/dom/custom/CustomElementUpgradeSorter.h" 21 #include "core/dom/custom/CustomElementUpgradeSorter.h"
22 #include "core/dom/custom/V0CustomElementRegistrationContext.h" 22 #include "core/dom/custom/V0CustomElementRegistrationContext.h"
23 #include "core/frame/LocalDOMWindow.h"
23 #include "wtf/Allocator.h" 24 #include "wtf/Allocator.h"
24 25
25 namespace blink { 26 namespace blink {
26 27
27 // Returns true if |name| is invalid. 28 // Returns true if |name| is invalid.
28 static bool throwIfInvalidName( 29 static bool throwIfInvalidName(
29 const AtomicString& name, 30 const AtomicString& name,
30 ExceptionState& exceptionState) 31 ExceptionState& exceptionState)
31 { 32 {
32 if (CustomElement::isValidName(name)) 33 if (CustomElement::isValidName(name))
(...skipping 23 matching lines...) Expand all
56 { 57 {
57 m_registry->m_namesBeingDefined.remove(m_name); 58 m_registry->m_namesBeingDefined.remove(m_name);
58 } 59 }
59 60
60 private: 61 private:
61 Member<CustomElementsRegistry> m_registry; 62 Member<CustomElementsRegistry> m_registry;
62 const AtomicString& m_name; 63 const AtomicString& m_name;
63 }; 64 };
64 65
65 CustomElementsRegistry* CustomElementsRegistry::create( 66 CustomElementsRegistry* CustomElementsRegistry::create(
66 Document* document) 67 const LocalDOMWindow* owner)
67 { 68 {
68 CustomElementsRegistry* registry = new CustomElementsRegistry(document); 69 CustomElementsRegistry* registry = new CustomElementsRegistry(owner);
69 if (V0CustomElementRegistrationContext* v0Context = registry->v0()) 70 Document* document = owner->document();
70 v0Context->setV1(registry); 71 if (V0CustomElementRegistrationContext* v0 =
72 document ? document->registrationContext() : nullptr)
73 registry->entangle(v0);
71 return registry; 74 return registry;
72 } 75 }
73 76
74 CustomElementsRegistry::CustomElementsRegistry(Document* document) 77 CustomElementsRegistry::CustomElementsRegistry(const LocalDOMWindow* owner)
75 : m_document(document) 78 : m_owner(owner)
79 , m_v0 (new V0RegistrySet())
76 , m_upgradeCandidates(new UpgradeCandidateMap()) 80 , m_upgradeCandidates(new UpgradeCandidateMap())
77 { 81 {
78 } 82 }
79 83
80 DEFINE_TRACE(CustomElementsRegistry) 84 DEFINE_TRACE(CustomElementsRegistry)
81 { 85 {
82 visitor->trace(m_definitions); 86 visitor->trace(m_definitions);
83 visitor->trace(m_document); 87 visitor->trace(m_owner);
88 visitor->trace(m_v0);
84 visitor->trace(m_upgradeCandidates); 89 visitor->trace(m_upgradeCandidates);
85 visitor->trace(m_whenDefinedPromiseMap); 90 visitor->trace(m_whenDefinedPromiseMap);
86 } 91 }
87 92
88 void CustomElementsRegistry::define( 93 void CustomElementsRegistry::define(
89 ScriptState* scriptState, 94 ScriptState* scriptState,
90 const AtomicString& name, 95 const AtomicString& name,
91 const ScriptValue& constructor, 96 const ScriptValue& constructor,
92 const ElementRegistrationOptions& options, 97 const ElementRegistrationOptions& options,
93 ExceptionState& exceptionState) 98 ExceptionState& exceptionState)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 { 187 {
183 CustomElementDefinition* definition = definitionForName(name); 188 CustomElementDefinition* definition = definitionForName(name);
184 if (!definition) { 189 if (!definition) {
185 // Binding layer converts |ScriptValue()| to script specific value, 190 // Binding layer converts |ScriptValue()| to script specific value,
186 // e.g. |undefined| for v8. 191 // e.g. |undefined| for v8.
187 return ScriptValue(); 192 return ScriptValue();
188 } 193 }
189 return definition->getConstructorForScript(); 194 return definition->getConstructorForScript();
190 } 195 }
191 196
197 CustomElementDefinition* CustomElementsRegistry::definitionFor(const CustomEleme ntDescriptor& desc) const
198 {
199 CustomElementDefinition* definition = definitionForName(desc.name());
200 if (!definition)
201 return nullptr;
202 // The definition for a customized built-in element, such as
203 // <button is="my-button"> should not be provided for an
204 // autonomous element, such as <my-button>, even though the
205 // name "my-button" matches.
206 return definition->descriptor() == desc ? definition : nullptr;
207 }
208
192 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const 209 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const
193 { 210 {
194 return m_definitions.contains(name); 211 return m_definitions.contains(name);
195 } 212 }
196 213
197 V0CustomElementRegistrationContext* CustomElementsRegistry::v0() 214 void CustomElementsRegistry::entangle(V0CustomElementRegistrationContext* v0)
198 { 215 {
199 return m_document->registrationContext(); 216 m_v0->add(v0);
217 v0->setV1(this);
200 } 218 }
201 219
202 bool CustomElementsRegistry::v0NameIsDefined(const AtomicString& name) 220 bool CustomElementsRegistry::v0NameIsDefined(const AtomicString& name)
203 { 221 {
204 if (V0CustomElementRegistrationContext* v0Context = v0()) 222 for (const auto& v0 : *m_v0) {
205 return v0Context->nameIsDefined(name); 223 if (v0->nameIsDefined(name))
224 return true;
225 }
206 return false; 226 return false;
207 } 227 }
208 228
209 CustomElementDefinition* CustomElementsRegistry::definitionForName( 229 CustomElementDefinition* CustomElementsRegistry::definitionForName(
210 const AtomicString& name) const 230 const AtomicString& name) const
211 { 231 {
212 return m_definitions.get(name); 232 return m_definitions.get(name);
213 } 233 }
214 234
215 void CustomElementsRegistry::addCandidate(Element* candidate) 235 void CustomElementsRegistry::addCandidate(Element* candidate)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (it == m_upgradeCandidates->end()) 277 if (it == m_upgradeCandidates->end())
258 return; 278 return;
259 CustomElementUpgradeSorter sorter; 279 CustomElementUpgradeSorter sorter;
260 for (Element* element : *it.get()->value) { 280 for (Element* element : *it.get()->value) {
261 if (!element || !desc.matches(*element)) 281 if (!element || !desc.matches(*element))
262 continue; 282 continue;
263 sorter.add(element); 283 sorter.add(element);
264 } 284 }
265 285
266 m_upgradeCandidates->remove(it); 286 m_upgradeCandidates->remove(it);
267 sorter.sorted(elements, m_document.get()); 287
288 Document* document = m_owner->document();
289 if (!document)
290 return;
291
292 sorter.sorted(elements, document);
268 } 293 }
269 294
270 } // namespace blink 295 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698