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/CustomElement.h" | 5 #include "core/dom/custom/CustomElement.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/dom/QualifiedName.h" | 8 #include "core/dom/QualifiedName.h" |
9 #include "core/dom/custom/CEReactionsScope.h" | |
10 #include "core/dom/custom/CustomElementDefinition.h" | 9 #include "core/dom/custom/CustomElementDefinition.h" |
11 #include "core/dom/custom/CustomElementUpgradeReaction.h" | |
12 #include "core/dom/custom/CustomElementsRegistry.h" | 10 #include "core/dom/custom/CustomElementsRegistry.h" |
13 #include "core/dom/custom/V0CustomElement.h" | 11 #include "core/dom/custom/V0CustomElement.h" |
14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 12 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
15 #include "core/frame/LocalDOMWindow.h" | 13 #include "core/frame/LocalDOMWindow.h" |
16 #include "core/html/HTMLElement.h" | 14 #include "core/html/HTMLElement.h" |
17 #include "platform/text/Character.h" | 15 #include "platform/text/Character.h" |
18 #include "wtf/text/AtomicStringHash.h" | 16 #include "wtf/text/AtomicStringHash.h" |
19 | 17 |
20 namespace blink { | 18 namespace blink { |
21 | 19 |
22 CustomElementsRegistry* CustomElement::registry(const Element& element) | 20 CustomElementsRegistry* CustomElement::registry(const Element& element) |
23 { | 21 { |
24 return registry(element.document()); | 22 return registry(element.document()); |
25 } | 23 } |
26 | 24 |
27 CustomElementsRegistry* CustomElement::registry(const Document& document) | 25 CustomElementsRegistry* CustomElement::registry(const Document& document) |
28 { | 26 { |
29 if (LocalDOMWindow* window = document.domWindow()) | 27 if (LocalDOMWindow* window = document.domWindow()) |
30 return window->customElements(); | 28 return window->customElements(); |
31 return nullptr; | 29 return nullptr; |
32 } | 30 } |
33 | 31 |
32 CustomElementDefinition* CustomElement::definitionForElement(const Element& elem ent) | |
33 { | |
34 if (CustomElementsRegistry* registry = CustomElement::registry(element)) | |
35 return registry->definitionForName(element.localName()); | |
36 return nullptr; | |
37 } | |
38 | |
34 bool CustomElement::isValidName(const AtomicString& name) | 39 bool CustomElement::isValidName(const AtomicString& name) |
35 { | 40 { |
36 if (!name.length() || name[0] < 'a' || name[0] > 'z') | 41 if (!name.length() || name[0] < 'a' || name[0] > 'z') |
37 return false; | 42 return false; |
38 | 43 |
39 bool hasHyphens = false; | 44 bool hasHyphens = false; |
40 for (size_t i = 1; i < name.length(); ) { | 45 for (size_t i = 1; i < name.length(); ) { |
41 UChar32 ch; | 46 UChar32 ch; |
42 if (name.is8Bit()) | 47 if (name.is8Bit()) |
43 ch = name[i++]; | 48 ch = name[i++]; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 // 6. If definition is non-null, then: | 129 // 6. If definition is non-null, then: |
125 // 6.2. If the synchronous custom elements flag is not set: | 130 // 6.2. If the synchronous custom elements flag is not set: |
126 // 6.2.1. Set result to a new element that implements the HTMLElement | 131 // 6.2.1. Set result to a new element that implements the HTMLElement |
127 // interface, with no attributes, namespace set to the HTML namespace, | 132 // interface, with no attributes, namespace set to the HTML namespace, |
128 // namespace prefix set to prefix, local name set to localName, custom | 133 // namespace prefix set to prefix, local name set to localName, custom |
129 // element state set to "undefined", and node document set to document. | 134 // element state set to "undefined", and node document set to document. |
130 HTMLElement* element = HTMLElement::create(tagName, document); | 135 HTMLElement* element = HTMLElement::create(tagName, document); |
131 element->setCustomElementState(CustomElementState::Undefined); | 136 element->setCustomElementState(CustomElementState::Undefined); |
132 // 6.2.2. Enqueue a custom element upgrade reaction given result and | 137 // 6.2.2. Enqueue a custom element upgrade reaction given result and |
133 // definition. | 138 // definition. |
134 enqueueUpgradeReaction(element, &definition); | 139 definition.enqueueUpgradeReaction(element); |
135 return element; | 140 return element; |
136 } | 141 } |
137 | 142 |
138 void CustomElement::enqueueUpgradeReaction(Element* element, CustomElementDefini tion* definition) | 143 void CustomElement::enqueueConnectedCallback(Element* element) |
139 { | 144 { |
140 // CEReactionsScope must be created by [CEReactions] in IDL, | 145 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); |
141 // or callers must setup explicitly if it does not go through bindings. | 146 CustomElementDefinition* definition = definitionForElement(*element); |
142 DCHECK(CEReactionsScope::current()); | 147 DCHECK(definition); |
dominicc (has gone to gerrit)
2016/06/13 07:59:01
We will null deref right after this, so this DCHEC
| |
143 CEReactionsScope::current()->enqueue(element, | 148 if (definition->hasConnectedCallback()) |
144 new CustomElementUpgradeReaction(definition)); | 149 definition->enqueueConnectedCallback(element); |
150 } | |
151 | |
152 void CustomElement::enqueueDisconnectedCallback(Element* element) | |
153 { | |
154 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); | |
155 CustomElementDefinition* definition = definitionForElement(*element); | |
156 DCHECK(definition); | |
157 if (definition->hasDisconnectedCallback()) | |
158 definition->enqueueDisconnectedCallback(element); | |
159 } | |
160 | |
161 | |
162 void CustomElement::enqueueAttributeChangedCallback(Element* element, | |
163 const QualifiedName& name, | |
164 const AtomicString& oldValue, const AtomicString& newValue) | |
165 { | |
166 DCHECK_EQ(element->getCustomElementState(), CustomElementState::Custom); | |
167 CustomElementDefinition* definition = definitionForElement(*element); | |
168 DCHECK(definition); | |
169 if (definition->hasAttributeChangedCallback(name)) | |
170 definition->enqueueAttributeChangedCallback(element, name, oldValue, new Value); | |
145 } | 171 } |
146 | 172 |
147 } // namespace blink | 173 } // namespace blink |
OLD | NEW |