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

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: Rebase. 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 return definition->descriptor() == desc ? definition : nullptr;
kouhei (in TOK) 2016/08/15 02:10:31 What are the cases where "definition->descriptor()
203 }
204
192 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const 205 bool CustomElementsRegistry::nameIsDefined(const AtomicString& name) const
193 { 206 {
194 return m_definitions.contains(name); 207 return m_definitions.contains(name);
195 } 208 }
196 209
197 V0CustomElementRegistrationContext* CustomElementsRegistry::v0() 210 void CustomElementsRegistry::entangle(V0CustomElementRegistrationContext* v0)
198 { 211 {
199 return m_document->registrationContext(); 212 m_v0->add(v0);
213 v0->setV1(this);
200 } 214 }
201 215
202 bool CustomElementsRegistry::v0NameIsDefined(const AtomicString& name) 216 bool CustomElementsRegistry::v0NameIsDefined(const AtomicString& name)
203 { 217 {
204 if (V0CustomElementRegistrationContext* v0Context = v0()) 218 for (const auto& v0 : *m_v0) {
205 return v0Context->nameIsDefined(name); 219 if (v0->nameIsDefined(name))
220 return true;
221 }
206 return false; 222 return false;
207 } 223 }
208 224
209 CustomElementDefinition* CustomElementsRegistry::definitionForName( 225 CustomElementDefinition* CustomElementsRegistry::definitionForName(
210 const AtomicString& name) const 226 const AtomicString& name) const
211 { 227 {
212 return m_definitions.get(name); 228 return m_definitions.get(name);
213 } 229 }
214 230
215 void CustomElementsRegistry::addCandidate(Element* candidate) 231 void CustomElementsRegistry::addCandidate(Element* candidate)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (it == m_upgradeCandidates->end()) 273 if (it == m_upgradeCandidates->end())
258 return; 274 return;
259 CustomElementUpgradeSorter sorter; 275 CustomElementUpgradeSorter sorter;
260 for (Element* element : *it.get()->value) { 276 for (Element* element : *it.get()->value) {
261 if (!element || !desc.matches(*element)) 277 if (!element || !desc.matches(*element))
262 continue; 278 continue;
263 sorter.add(element); 279 sorter.add(element);
264 } 280 }
265 281
266 m_upgradeCandidates->remove(it); 282 m_upgradeCandidates->remove(it);
267 sorter.sorted(elements, m_document.get()); 283
284 Document* document = m_owner->document();
285 if (!document)
286 return;
287
288 sorter.sorted(elements, document);
268 } 289 }
269 290
270 } // namespace blink 291 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698