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

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

Issue 2505573002: CustomElements: createCustomElementSync accepts a definition (Closed)
Patch Set: createCustomElementSync accepts a definition Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/CustomElement.h" 5 #include "core/dom/custom/CustomElement.h"
6 6
7 #include "core/HTMLElementFactory.h" 7 #include "core/HTMLElementFactory.h"
8 #include "core/HTMLElementTypeHelpers.h" 8 #include "core/HTMLElementTypeHelpers.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/QualifiedName.h" 10 #include "core/dom/QualifiedName.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // first. 54 // first.
55 DEFINE_STATIC_LOCAL(HashSet<AtomicString>, hyphenatedSpecElementNames, 55 DEFINE_STATIC_LOCAL(HashSet<AtomicString>, hyphenatedSpecElementNames,
56 ({ 56 ({
57 "annotation-xml", "color-profile", "font-face", 57 "annotation-xml", "color-profile", "font-face",
58 "font-face-src", "font-face-uri", "font-face-format", 58 "font-face-src", "font-face-uri", "font-face-format",
59 "font-face-name", "missing-glyph", 59 "font-face-name", "missing-glyph",
60 })); 60 }));
61 return hyphenatedSpecElementNames.contains(name); 61 return hyphenatedSpecElementNames.contains(name);
62 } 62 }
63 63
64 bool CustomElement::shouldCreateCustomElement(const AtomicString& localName) { 64 bool CustomElement::shouldCreateCustomElement(const AtomicString& name) {
65 return RuntimeEnabledFeatures::customElementsV1Enabled() && 65 return RuntimeEnabledFeatures::customElementsV1Enabled() && isValidName(name);
66 isValidName(localName);
67 } 66 }
68 67
69 bool CustomElement::shouldCreateCustomElement(const QualifiedName& tagName) { 68 bool CustomElement::shouldCreateCustomElement(const QualifiedName& tagName) {
70 return shouldCreateCustomElement(tagName.localName()) && 69 return shouldCreateCustomElement(tagName.localName()) &&
71 tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; 70 tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI;
72 } 71 }
73 72
73 bool CustomElement::shouldCreateCustomizedBuiltinElement(
74 const AtomicString& localName) {
75 return htmlElementTypeForTag(localName) !=
76 HTMLElementType::kHTMLUnknownElement &&
77 RuntimeEnabledFeatures::customElementsBuiltinEnabled();
78 }
79
80 bool CustomElement::shouldCreateCustomizedBuiltinElement(
81 const QualifiedName& tagName) {
82 return shouldCreateCustomizedBuiltinElement(tagName.localName()) &&
83 tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI;
84 }
85
74 static CustomElementDefinition* definitionFor( 86 static CustomElementDefinition* definitionFor(
75 const Document& document, 87 const Document& document,
76 const CustomElementDescriptor desc) { 88 const CustomElementDescriptor desc) {
77 if (CustomElementRegistry* registry = CustomElement::registry(document)) 89 if (CustomElementRegistry* registry = CustomElement::registry(document))
78 return registry->definitionFor(desc); 90 return registry->definitionFor(desc);
79 return nullptr; 91 return nullptr;
80 } 92 }
81 93
82 HTMLElement* CustomElement::createCustomElementSync( 94 HTMLElement* CustomElement::createCustomElementSync(
83 Document& document, 95 Document& document,
96 const QualifiedName& tagName) {
97 CustomElementDefinition* definition = nullptr;
98 CustomElementRegistry* registry = CustomElement::registry(document);
99 if (registry) {
100 definition = registry->definitionFor(
101 CustomElementDescriptor(tagName.localName(), tagName.localName()));
102 }
103 return createCustomElementSync(document, tagName, definition);
104 }
105
106 HTMLElement* CustomElement::createCustomElementSync(
107 Document& document,
84 const AtomicString& localName, 108 const AtomicString& localName,
85 const AtomicString& is) { 109 CustomElementDefinition* definition) {
86 return createCustomElementSync( 110 return createCustomElementSync(
87 document, 111 document,
88 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), is); 112 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI),
113 definition);
89 } 114 }
90 115
91 // https://dom.spec.whatwg.org/#concept-create-element 116 // https://dom.spec.whatwg.org/#concept-create-element
92 HTMLElement* CustomElement::createCustomElementSync( 117 HTMLElement* CustomElement::createCustomElementSync(
93 Document& document, 118 Document& document,
94 const QualifiedName& tagName, 119 const QualifiedName& tagName,
95 const AtomicString& is) { 120 CustomElementDefinition* definition) {
96 const AtomicString& name = 121 DCHECK(shouldCreateCustomElement(tagName) ||
97 (is.isNull() || is.isEmpty()) ? tagName.localName() : is; 122 shouldCreateCustomizedBuiltinElement(tagName));
98 DCHECK(shouldCreateCustomElement(name));
99 const CustomElementDescriptor desc(name, tagName.localName());
100 CustomElementDefinition* definition = definitionFor(document, desc);
101 HTMLElement* element; 123 HTMLElement* element;
102 124
103 if (definition && desc.isAutonomous()) { 125 if (definition && definition->descriptor().isAutonomous()) {
104 // 6. If definition is non-null and we have an autonomous custom element 126 // 6. If definition is non-null and we have an autonomous custom element
105 element = definition->createElementSync(document, tagName); 127 element = definition->createElementSync(document, tagName);
106 } else if (definition) { 128 } else if (definition) {
107 // 5. If definition is non-null and we have a customized built-in element 129 // 5. If definition is non-null and we have a customized built-in element
108 element = createUndefinedElement(document, tagName); 130 element = createUndefinedElement(document, tagName);
109 definition->upgrade(element); 131 definition->upgrade(element);
110 } else { 132 } else {
111 // 7. Otherwise 133 // 7. Otherwise
112 element = createUndefinedElement(document, tagName); 134 element = createUndefinedElement(document, tagName);
113 } 135 }
(...skipping 14 matching lines...) Expand all
128 CustomElementDescriptor(tagName.localName(), tagName.localName()))) 150 CustomElementDescriptor(tagName.localName(), tagName.localName())))
129 return definition->createElementAsync(document, tagName); 151 return definition->createElementAsync(document, tagName);
130 152
131 return createUndefinedElement(document, tagName); 153 return createUndefinedElement(document, tagName);
132 } 154 }
133 155
134 // Create a HTMLElement 156 // Create a HTMLElement
135 HTMLElement* CustomElement::createUndefinedElement( 157 HTMLElement* CustomElement::createUndefinedElement(
136 Document& document, 158 Document& document,
137 const QualifiedName& tagName) { 159 const QualifiedName& tagName) {
138 bool shouldCreateBuiltin = 160 bool shouldCreateBuiltin = shouldCreateCustomizedBuiltinElement(tagName);
139 htmlElementTypeForTag(tagName.localName()) !=
140 HTMLElementType::kHTMLUnknownElement &&
141 RuntimeEnabledFeatures::customElementsBuiltinEnabled();
142 DCHECK(shouldCreateCustomElement(tagName) || shouldCreateBuiltin); 161 DCHECK(shouldCreateCustomElement(tagName) || shouldCreateBuiltin);
143 162
144 HTMLElement* element; 163 HTMLElement* element;
145 if (V0CustomElement::isValidName(tagName.localName()) && 164 if (V0CustomElement::isValidName(tagName.localName()) &&
146 document.registrationContext()) { 165 document.registrationContext()) {
147 Element* v0element = document.registrationContext()->createCustomTagElement( 166 Element* v0element = document.registrationContext()->createCustomTagElement(
148 document, tagName); 167 document, tagName);
149 SECURITY_DCHECK(v0element->isHTMLElement()); 168 SECURITY_DCHECK(v0element->isHTMLElement());
150 element = toHTMLElement(v0element); 169 element = toHTMLElement(v0element);
151 } else if (shouldCreateBuiltin) { 170 } else if (shouldCreateBuiltin) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 if (!registry) 258 if (!registry)
240 return; 259 return;
241 if (CustomElementDefinition* definition = registry->definitionFor( 260 if (CustomElementDefinition* definition = registry->definitionFor(
242 CustomElementDescriptor(element->localName(), element->localName()))) 261 CustomElementDescriptor(element->localName(), element->localName())))
243 definition->enqueueUpgradeReaction(element); 262 definition->enqueueUpgradeReaction(element);
244 else 263 else
245 registry->addCandidate(element); 264 registry->addCandidate(element);
246 } 265 }
247 266
248 } // namespace blink 267 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/custom/CustomElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698