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" | 9 #include "core/dom/custom/CEReactionsScope.h" |
10 #include "core/dom/custom/CustomElementDefinition.h" | 10 #include "core/dom/custom/CustomElementDefinition.h" |
11 #include "core/dom/custom/CustomElementReactionStack.h" | 11 #include "core/dom/custom/CustomElementReactionStack.h" |
12 #include "core/dom/custom/CustomElementsRegistry.h" | 12 #include "core/dom/custom/CustomElementsRegistry.h" |
13 #include "core/dom/custom/V0CustomElement.h" | 13 #include "core/dom/custom/V0CustomElement.h" |
14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
15 #include "core/frame/LocalDOMWindow.h" | 15 #include "core/frame/LocalDOMWindow.h" |
16 #include "core/html/HTMLElement.h" | 16 #include "core/html/HTMLElement.h" |
17 #include "core/html/HTMLUnknownElement.h" | 17 #include "core/html/HTMLUnknownElement.h" |
18 #include "platform/text/Character.h" | 18 #include "platform/text/Character.h" |
19 #include "wtf/text/AtomicStringHash.h" | 19 #include "wtf/text/AtomicStringHash.h" |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 | 22 |
23 CustomElementsRegistry* CustomElement::registry(const Element& element) | 23 CustomElementsRegistry* CustomElement::registry(const Element& element) |
24 { | 24 { |
25 return registry(element.document()); | 25 return registry(element.document()); |
26 } | 26 } |
| 27 |
27 CustomElementsRegistry* CustomElement::registry(const Document& document) | 28 CustomElementsRegistry* CustomElement::registry(const Document& document) |
28 { | 29 { |
29 if (LocalDOMWindow* window = document.domWindow()) | 30 if (Document* contextDocument = const_cast<Document&>(document).contextDocum
ent()) { |
30 return window->customElements(); | 31 if (LocalDOMWindow* window = contextDocument->domWindow()) |
| 32 return window->customElements(); |
| 33 } |
31 return nullptr; | 34 return nullptr; |
32 } | 35 } |
33 | 36 |
34 static CustomElementDefinition* definitionForElementWithoutCheck(const Element&
element) | 37 static CustomElementDefinition* definitionForElementWithoutCheck(const Element&
element) |
35 { | 38 { |
36 DCHECK_EQ(element.getCustomElementState(), CustomElementState::Custom); | 39 DCHECK_EQ(element.getCustomElementState(), CustomElementState::Custom); |
37 return element.customElementDefinition(); | 40 return element.customElementDefinition(); |
38 } | 41 } |
39 | 42 |
40 CustomElementDefinition* CustomElement::definitionForElement(const Element* elem
ent) | 43 CustomElementDefinition* CustomElement::definitionForElement(const Element* elem
ent) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 "font-face-format", | 77 "font-face-format", |
75 "font-face-name", | 78 "font-face-name", |
76 "missing-glyph", | 79 "missing-glyph", |
77 })); | 80 })); |
78 return !hyphenContainingElementNames.contains(name); | 81 return !hyphenContainingElementNames.contains(name); |
79 } | 82 } |
80 | 83 |
81 bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicSt
ring& localName) | 84 bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicSt
ring& localName) |
82 { | 85 { |
83 return RuntimeEnabledFeatures::customElementsV1Enabled() | 86 return RuntimeEnabledFeatures::customElementsV1Enabled() |
| 87 && document.contextDocument() && document.contextDocument()->frame() |
84 && isValidName(localName); | 88 && isValidName(localName); |
85 } | 89 } |
86 | 90 |
87 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie
dName& tagName) | 91 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie
dName& tagName) |
88 { | 92 { |
89 return shouldCreateCustomElement(document, tagName.localName()) | 93 return shouldCreateCustomElement(document, tagName.localName()) |
90 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; | 94 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; |
91 } | 95 } |
92 | 96 |
93 static CustomElementDefinition* definitionForName(const Document& document, cons
t QualifiedName& name) | 97 static CustomElementDefinition* definitionForName(const Document& document, cons
t QualifiedName& name) |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 CustomElementsRegistry* registry = CustomElement::registry(*element); | 244 CustomElementsRegistry* registry = CustomElement::registry(*element); |
241 if (!registry) | 245 if (!registry) |
242 return; | 246 return; |
243 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) | 247 if (CustomElementDefinition* definition = registry->definitionForName(elemen
t->localName())) |
244 definition->enqueueUpgradeReaction(element); | 248 definition->enqueueUpgradeReaction(element); |
245 else | 249 else |
246 registry->addCandidate(element); | 250 registry->addCandidate(element); |
247 } | 251 } |
248 | 252 |
249 } // namespace blink | 253 } // namespace blink |
OLD | NEW |