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

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

Issue 2477713003: Custom Elements: Check Definition in createElement, Create Customized Built-in Elements Sync (Closed)
Patch Set: patch fix 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"
8 #include "core/HTMLElementTypeHelpers.h"
7 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
8 #include "core/dom/QualifiedName.h" 10 #include "core/dom/QualifiedName.h"
9 #include "core/dom/custom/CEReactionsScope.h" 11 #include "core/dom/custom/CEReactionsScope.h"
10 #include "core/dom/custom/CustomElementDefinition.h" 12 #include "core/dom/custom/CustomElementDefinition.h"
11 #include "core/dom/custom/CustomElementReactionStack.h" 13 #include "core/dom/custom/CustomElementReactionStack.h"
12 #include "core/dom/custom/CustomElementRegistry.h" 14 #include "core/dom/custom/CustomElementRegistry.h"
13 #include "core/dom/custom/V0CustomElement.h" 15 #include "core/dom/custom/V0CustomElement.h"
14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" 16 #include "core/dom/custom/V0CustomElementRegistrationContext.h"
15 #include "core/frame/LocalDOMWindow.h" 17 #include "core/frame/LocalDOMWindow.h"
16 #include "core/html/HTMLElement.h" 18 #include "core/html/HTMLElement.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 static CustomElementDefinition* definitionFor( 74 static CustomElementDefinition* definitionFor(
73 const Document& document, 75 const Document& document,
74 const CustomElementDescriptor desc) { 76 const CustomElementDescriptor desc) {
75 if (CustomElementRegistry* registry = CustomElement::registry(document)) 77 if (CustomElementRegistry* registry = CustomElement::registry(document))
76 return registry->definitionFor(desc); 78 return registry->definitionFor(desc);
77 return nullptr; 79 return nullptr;
78 } 80 }
79 81
80 HTMLElement* CustomElement::createCustomElementSync( 82 HTMLElement* CustomElement::createCustomElementSync(
81 Document& document, 83 Document& document,
82 const AtomicString& localName) { 84 const AtomicString& localName,
85 const AtomicString& is) {
83 return createCustomElementSync( 86 return createCustomElementSync(
84 document, 87 document,
85 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI)); 88 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), is);
86 } 89 }
87 90
91 // https://dom.spec.whatwg.org/#concept-create-element
88 HTMLElement* CustomElement::createCustomElementSync( 92 HTMLElement* CustomElement::createCustomElementSync(
89 Document& document, 93 Document& document,
90 const QualifiedName& tagName) { 94 const QualifiedName& tagName,
91 DCHECK(shouldCreateCustomElement(tagName)); 95 const AtomicString& is) {
92 if (CustomElementDefinition* definition = definitionFor( 96 const AtomicString& name =
93 document, 97 (is.isNull() || is.isEmpty()) ? tagName.localName() : is;
94 CustomElementDescriptor(tagName.localName(), tagName.localName()))) 98 DCHECK(shouldCreateCustomElement(name));
95 return definition->createElementSync(document, tagName); 99 const CustomElementDescriptor desc(name, tagName.localName());
96 return createUndefinedElement(document, tagName); 100 CustomElementDefinition* definition = definitionFor(document, desc);
101 HTMLElement* element;
102
103 if (definition && desc.isAutonomous()) {
104 // 6. If definition is non-null and we have an autonomous custom element
105 element = definition->createElementSync(document, tagName);
106 } else if (definition) {
107 // 5. If definition is non-null and we have a customized built-in element
108 element = createUndefinedElement(document, tagName);
109 definition->upgrade(element);
110 } else {
111 // 7. Otherwise
112 element = createUndefinedElement(document, tagName);
113 }
114 return element;
97 } 115 }
98 116
99 HTMLElement* CustomElement::createCustomElementAsync( 117 HTMLElement* CustomElement::createCustomElementAsync(
100 Document& document, 118 Document& document,
101 const QualifiedName& tagName) { 119 const QualifiedName& tagName) {
102 DCHECK(shouldCreateCustomElement(tagName)); 120 DCHECK(shouldCreateCustomElement(tagName));
103 121
104 // To create an element: 122 // To create an element:
105 // https://dom.spec.whatwg.org/#concept-create-element 123 // https://dom.spec.whatwg.org/#concept-create-element
106 // 6. If definition is non-null, then: 124 // 6. If definition is non-null, then:
107 // 6.2. If the synchronous custom elements flag is not set: 125 // 6.2. If the synchronous custom elements flag is not set:
108 if (CustomElementDefinition* definition = definitionFor( 126 if (CustomElementDefinition* definition = definitionFor(
109 document, 127 document,
110 CustomElementDescriptor(tagName.localName(), tagName.localName()))) 128 CustomElementDescriptor(tagName.localName(), tagName.localName())))
111 return definition->createElementAsync(document, tagName); 129 return definition->createElementAsync(document, tagName);
112 130
113 return createUndefinedElement(document, tagName); 131 return createUndefinedElement(document, tagName);
114 } 132 }
115 133
134 // Create a HTMLElement
116 HTMLElement* CustomElement::createUndefinedElement( 135 HTMLElement* CustomElement::createUndefinedElement(
117 Document& document, 136 Document& document,
118 const QualifiedName& tagName) { 137 const QualifiedName& tagName) {
119 DCHECK(shouldCreateCustomElement(tagName)); 138 bool shouldCreateBuiltin =
139 htmlElementTypeForTag(tagName.localName()) !=
140 HTMLElementType::kHTMLUnknownElement &&
141 RuntimeEnabledFeatures::customElementsBuiltinEnabled();
142 DCHECK(shouldCreateCustomElement(tagName) || shouldCreateBuiltin);
120 143
121 HTMLElement* element; 144 HTMLElement* element;
122 if (V0CustomElement::isValidName(tagName.localName()) && 145 if (V0CustomElement::isValidName(tagName.localName()) &&
123 document.registrationContext()) { 146 document.registrationContext()) {
124 Element* v0element = document.registrationContext()->createCustomTagElement( 147 Element* v0element = document.registrationContext()->createCustomTagElement(
125 document, tagName); 148 document, tagName);
126 SECURITY_DCHECK(v0element->isHTMLElement()); 149 SECURITY_DCHECK(v0element->isHTMLElement());
127 element = toHTMLElement(v0element); 150 element = toHTMLElement(v0element);
151 } else if (shouldCreateBuiltin) {
152 element = HTMLElementFactory::createHTMLElement(
153 tagName.localName(), document, nullptr, CreatedByCreateElement);
128 } else { 154 } else {
129 element = HTMLElement::create(tagName, document); 155 element = HTMLElement::create(tagName, document);
130 } 156 }
131 157
132 element->setCustomElementState(CustomElementState::Undefined); 158 element->setCustomElementState(CustomElementState::Undefined);
133 159
134 return element; 160 return element;
135 } 161 }
136 162
137 HTMLElement* CustomElement::createFailedElement(Document& document, 163 HTMLElement* CustomElement::createFailedElement(Document& document,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if (!registry) 239 if (!registry)
214 return; 240 return;
215 if (CustomElementDefinition* definition = registry->definitionFor( 241 if (CustomElementDefinition* definition = registry->definitionFor(
216 CustomElementDescriptor(element->localName(), element->localName()))) 242 CustomElementDescriptor(element->localName(), element->localName())))
217 definition->enqueueUpgradeReaction(element); 243 definition->enqueueUpgradeReaction(element);
218 else 244 else
219 registry->addCandidate(element); 245 registry->addCandidate(element);
220 } 246 }
221 247
222 } // namespace blink 248 } // 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