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

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

Issue 2054433002: Implement "create an element" when sync for Custom Element V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@async-ce
Patch Set: dominicc/haraken review Created 4 years, 6 months 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
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/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"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return RuntimeEnabledFeatures::customElementsV1Enabled() 72 return RuntimeEnabledFeatures::customElementsV1Enabled()
73 && document.frame() && isValidName(localName); 73 && document.frame() && isValidName(localName);
74 } 74 }
75 75
76 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie dName& tagName) 76 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie dName& tagName)
77 { 77 {
78 return shouldCreateCustomElement(document, tagName.localName()) 78 return shouldCreateCustomElement(document, tagName.localName())
79 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI; 79 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI;
80 } 80 }
81 81
82 HTMLElement* CustomElement::createCustomElement(Document& document, const Atomic String& localName, CreateElementFlags flags) 82 static CustomElementDefinition* definitionForName(const Document& document, cons t QualifiedName& name)
83 { 83 {
84 return createCustomElement(document, 84 if (CustomElementsRegistry* registry = CustomElement::registry(document))
85 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), 85 return registry->definitionForName(name.localName());
86 flags); 86 return nullptr;
87 } 87 }
88 88
89 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName, CreateElementFlags flags) 89 HTMLElement* CustomElement::createCustomElementSync(Document& document, const At omicString& localName, ExceptionState& exceptionState)
90 { 90 {
91 DCHECK(shouldCreateCustomElement(document, tagName)); 91 return createCustomElementSync(document,
92 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI),
93 exceptionState);
94 }
95
96 HTMLElement* CustomElement::createCustomElementSync(Document& document, const Qu alifiedName& tagName, ExceptionState& exceptionState)
97 {
98 CHECK(shouldCreateCustomElement(document, tagName));
92 99
93 // To create an element: 100 // To create an element:
94 // https://dom.spec.whatwg.org/#concept-create-element 101 // https://dom.spec.whatwg.org/#concept-create-element
95 // 6. If definition is non-null, then: 102 // 6. If definition is non-null, then:
103 // 6.1. If the synchronous custom elements flag is set:
104 if (CustomElementDefinition* definition = definitionForName(document, tagNam e))
105 return definition->createElementSync(document, tagName, exceptionState);
106
107 return createUndefinedElement(document, tagName);
108 }
109
110 HTMLElement* CustomElement::createCustomElementSync(Document& document, const Qu alifiedName& tagName)
111 {
112 CHECK(shouldCreateCustomElement(document, tagName));
113
114 // When invoked from "create an element for a token":
115 // https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for- the-token
116 // 7. If this step throws an exception, then report the exception,
117 // and let element be instead a new element that implements
118 // HTMLUnknownElement.
119 if (CustomElementDefinition* definition = definitionForName(document, tagNam e))
120 return definition->createElementSync(document, tagName);
121
122 return createUndefinedElement(document, tagName);
123 }
124
125 HTMLElement* CustomElement::createCustomElementAsync(Document& document, const Q ualifiedName& tagName)
126 {
127 CHECK(shouldCreateCustomElement(document, tagName));
128
129 // To create an element:
130 // https://dom.spec.whatwg.org/#concept-create-element
131 // 6. If definition is non-null, then:
132 // 6.2. If the synchronous custom elements flag is not set:
133 if (CustomElementDefinition* definition = definitionForName(document, tagNam e))
134 return definition->createElementAsync(document, tagName);
135
136 return createUndefinedElement(document, tagName);
137 }
138
139 HTMLElement* CustomElement::createUndefinedElement(Document& document, const Qua lifiedName& tagName)
140 {
141 DCHECK(shouldCreateCustomElement(document, tagName));
142
96 HTMLElement* element; 143 HTMLElement* element;
97 if (CustomElementsRegistry* registry = CustomElement::registry(document)) {
98 if (CustomElementDefinition* definition = registry->definitionForName(ta gName.localName())) {
99 // 6.2. If the synchronous custom elements flag is not set:
100 if (flags & AsynchronousCustomElements)
101 return createCustomElementAsync(document, *definition, tagName);
102
103 // TODO(kojii): Synchronous mode implementation coming after async.
104 }
105 }
106
107 if (V0CustomElement::isValidName(tagName.localName()) && document.registrati onContext()) { 144 if (V0CustomElement::isValidName(tagName.localName()) && document.registrati onContext()) {
108 Element* v0element = document.registrationContext()->createCustomTagElem ent(document, tagName); 145 Element* v0element = document.registrationContext()->createCustomTagElem ent(document, tagName);
109 SECURITY_DCHECK(v0element->isHTMLElement()); 146 SECURITY_DCHECK(v0element->isHTMLElement());
110 element = toHTMLElement(v0element); 147 element = toHTMLElement(v0element);
111 } else { 148 } else {
112 element = HTMLElement::create(tagName, document); 149 element = HTMLElement::create(tagName, document);
113 } 150 }
114 151
115 element->setCustomElementState(CustomElementState::Undefined); 152 element->setCustomElementState(CustomElementState::Undefined);
116 153
117 return element; 154 return element;
118 } 155 }
119 156
120 HTMLElement* CustomElement::createCustomElementAsync(Document& document,
121 CustomElementDefinition& definition, const QualifiedName& tagName)
122 {
123 // https://dom.spec.whatwg.org/#concept-create-element
124 // 6. If definition is non-null, then:
125 // 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
127 // interface, with no attributes, namespace set to the HTML namespace,
128 // namespace prefix set to prefix, local name set to localName, custom
129 // element state set to "undefined", and node document set to document.
130 HTMLElement* element = HTMLElement::create(tagName, document);
131 element->setCustomElementState(CustomElementState::Undefined);
132 // 6.2.2. Enqueue a custom element upgrade reaction given result and
133 // definition.
134 enqueueUpgradeReaction(element, &definition);
135 return element;
136 }
137
138 void CustomElement::enqueueUpgradeReaction(Element* element, CustomElementDefini tion* definition) 157 void CustomElement::enqueueUpgradeReaction(Element* element, CustomElementDefini tion* definition)
139 { 158 {
140 // CEReactionsScope must be created by [CEReactions] in IDL, 159 // CEReactionsScope must be created by [CEReactions] in IDL,
141 // or callers must setup explicitly if it does not go through bindings. 160 // or callers must setup explicitly if it does not go through bindings.
142 DCHECK(CEReactionsScope::current()); 161 DCHECK(CEReactionsScope::current());
143 CEReactionsScope::current()->enqueue(element, 162 CEReactionsScope::current()->enqueue(element,
144 new CustomElementUpgradeReaction(definition)); 163 new CustomElementUpgradeReaction(definition));
145 } 164 }
146 165
147 } // namespace blink 166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698