OLD | NEW |
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 "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
11 #include "core/dom/ElementRegistrationOptions.h" | 11 #include "core/dom/ElementRegistrationOptions.h" |
12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
13 #include "core/dom/custom/CEReactionsScope.h" | 13 #include "core/dom/custom/CEReactionsScope.h" |
14 #include "core/dom/custom/CustomElement.h" | 14 #include "core/dom/custom/CustomElement.h" |
15 #include "core/dom/custom/CustomElementDefinition.h" | 15 #include "core/dom/custom/CustomElementDefinition.h" |
16 #include "core/dom/custom/CustomElementDefinitionBuilder.h" | 16 #include "core/dom/custom/CustomElementDefinitionBuilder.h" |
17 #include "core/dom/custom/CustomElementDescriptor.h" | 17 #include "core/dom/custom/CustomElementDescriptor.h" |
18 #include "core/dom/custom/CustomElementUpgradeReaction.h" | 18 #include "core/dom/custom/CustomElementUpgradeReaction.h" |
19 #include "core/dom/custom/CustomElementUpgradeSorter.h" | 19 #include "core/dom/custom/CustomElementUpgradeSorter.h" |
20 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 20 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
| 21 #include "wtf/Allocator.h" |
21 | 22 |
22 namespace blink { | 23 namespace blink { |
23 | 24 |
| 25 class CustomElementsRegistry::NameIsBeingDefined final { |
| 26 STACK_ALLOCATED(); |
| 27 DISALLOW_IMPLICIT_CONSTRUCTORS(NameIsBeingDefined); |
| 28 public: |
| 29 NameIsBeingDefined( |
| 30 CustomElementsRegistry* registry, |
| 31 const AtomicString& name) |
| 32 : m_registry(registry) |
| 33 , m_name(name) |
| 34 { |
| 35 DCHECK(!m_registry->m_namesBeingDefined.contains(name)); |
| 36 m_registry->m_namesBeingDefined.add(name); |
| 37 } |
| 38 |
| 39 ~NameIsBeingDefined() |
| 40 { |
| 41 m_registry->m_namesBeingDefined.remove(m_name); |
| 42 } |
| 43 |
| 44 private: |
| 45 Member<CustomElementsRegistry> m_registry; |
| 46 const AtomicString& m_name; |
| 47 }; |
| 48 |
24 CustomElementsRegistry* CustomElementsRegistry::create( | 49 CustomElementsRegistry* CustomElementsRegistry::create( |
25 Document* document) | 50 Document* document) |
26 { | 51 { |
27 CustomElementsRegistry* registry = new CustomElementsRegistry(document); | 52 CustomElementsRegistry* registry = new CustomElementsRegistry(document); |
28 if (V0CustomElementRegistrationContext* v0Context = registry->v0()) | 53 if (V0CustomElementRegistrationContext* v0Context = registry->v0()) |
29 v0Context->setV1(registry); | 54 v0Context->setV1(registry); |
30 return registry; | 55 return registry; |
31 } | 56 } |
32 | 57 |
33 CustomElementsRegistry::CustomElementsRegistry(Document* document) | 58 CustomElementsRegistry::CustomElementsRegistry(Document* document) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 if (!builder.checkConstructorIntrinsics()) | 95 if (!builder.checkConstructorIntrinsics()) |
71 return; | 96 return; |
72 | 97 |
73 if (!CustomElement::isValidName(name)) { | 98 if (!CustomElement::isValidName(name)) { |
74 exceptionState.throwDOMException( | 99 exceptionState.throwDOMException( |
75 SyntaxError, | 100 SyntaxError, |
76 "\"" + name + "\" is not a valid custom element name"); | 101 "\"" + name + "\" is not a valid custom element name"); |
77 return; | 102 return; |
78 } | 103 } |
79 | 104 |
| 105 if (m_namesBeingDefined.contains(name)) { |
| 106 exceptionState.throwDOMException( |
| 107 NotSupportedError, |
| 108 "this name is already being defined in this registry"); |
| 109 return; |
| 110 } |
| 111 NameIsBeingDefined defining(this, name); |
| 112 |
80 if (nameIsDefined(name) || v0NameIsDefined(name)) { | 113 if (nameIsDefined(name) || v0NameIsDefined(name)) { |
81 exceptionState.throwDOMException( | 114 exceptionState.throwDOMException( |
82 NotSupportedError, | 115 NotSupportedError, |
83 "this name has already been used with this registry"); | 116 "this name has already been used with this registry"); |
84 return; | 117 return; |
85 } | 118 } |
86 | 119 |
87 if (!builder.checkConstructorNotRegistered()) | 120 if (!builder.checkConstructorNotRegistered()) |
88 return; | 121 return; |
89 | 122 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 if (!element || !desc.matches(*element)) | 223 if (!element || !desc.matches(*element)) |
191 continue; | 224 continue; |
192 sorter.add(element); | 225 sorter.add(element); |
193 } | 226 } |
194 | 227 |
195 m_upgradeCandidates->remove(it); | 228 m_upgradeCandidates->remove(it); |
196 sorter.sorted(elements, m_document.get()); | 229 sorter.sorted(elements, m_document.get()); |
197 } | 230 } |
198 | 231 |
199 } // namespace blink | 232 } // namespace blink |
OLD | NEW |