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

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: Prefer ExceptionState over throw 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 HTMLElement* CustomElement::createCustomElement(Document& document, const Atomic String& localName, CreateElementFlags flags)
83 { 83 {
84 return createCustomElement(document, 84 return createCustomElement(document,
85 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), 85 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI),
86 flags); 86 flags);
87 } 87 }
88 88
89 HTMLElement* CustomElement::createCustomElement(Document& document, const Atomic String& localName, CreateElementFlags flags,
90 ExceptionState& exceptionState)
91 {
92 return createCustomElement(document,
93 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI),
94 flags, exceptionState);
95 }
96
89 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName, CreateElementFlags flags) 97 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName, CreateElementFlags flags)
90 { 98 {
99 return createCustomElement(document, tagName, flags, nullptr);
100 }
101
102 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName, CreateElementFlags flags,
103 ExceptionState& exceptionState)
104 {
105 return createCustomElement(document, tagName, flags, &exceptionState);
106 }
107
108 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName, CreateElementFlags flags,
109 ExceptionState* exceptionState)
110 {
91 DCHECK(shouldCreateCustomElement(document, tagName)); 111 DCHECK(shouldCreateCustomElement(document, tagName));
92 112
93 // To create an element: 113 // To create an element:
94 // https://dom.spec.whatwg.org/#concept-create-element 114 // https://dom.spec.whatwg.org/#concept-create-element
95 // 6. If definition is non-null, then: 115 // 6. If definition is non-null, then:
96 HTMLElement* element; 116 HTMLElement* element;
97 if (CustomElementsRegistry* registry = CustomElement::registry(document)) { 117 if (CustomElementsRegistry* registry = CustomElement::registry(document)) {
98 if (CustomElementDefinition* definition = registry->definitionForName(ta gName.localName())) { 118 if (CustomElementDefinition* definition = registry->definitionForName(ta gName.localName())) {
99 // 6.2. If the synchronous custom elements flag is not set: 119 // 6.2. If the synchronous custom elements flag is not set:
100 if (flags & AsynchronousCustomElements) 120 if (flags & AsynchronousCustomElements)
101 return createCustomElementAsync(document, *definition, tagName); 121 return createCustomElementAsync(document, *definition, tagName);
102 122
103 // TODO(kojii): Synchronous mode implementation coming after async. 123 // When invoked from "create an element for a token":
124 // https://html.spec.whatwg.org/multipage/syntax.html#create-an-elem ent-for-the-token
125 // 7. If this step throws an exception, then report the exception,
126 // and let element be instead a new element that implements
127 // HTMLUnknownElement.
128 if (!exceptionState)
129 return definition->createElementByRunningConstructor(document, t agName);
130
131 // 6.1. If the synchronous custom elements flag is set:
132 return definition->createElementByRunningConstructor(document, tagNa me, *exceptionState);
104 } 133 }
105 } 134 }
106 135
107 if (V0CustomElement::isValidName(tagName.localName()) && document.registrati onContext()) { 136 if (V0CustomElement::isValidName(tagName.localName()) && document.registrati onContext()) {
108 Element* v0element = document.registrationContext()->createCustomTagElem ent(document, tagName); 137 Element* v0element = document.registrationContext()->createCustomTagElem ent(document, tagName);
109 SECURITY_DCHECK(v0element->isHTMLElement()); 138 SECURITY_DCHECK(v0element->isHTMLElement());
110 element = toHTMLElement(v0element); 139 element = toHTMLElement(v0element);
111 } else { 140 } else {
112 element = HTMLElement::create(tagName, document); 141 element = HTMLElement::create(tagName, document);
113 } 142 }
(...skipping 24 matching lines...) Expand all
138 void CustomElement::enqueueUpgradeReaction(Element* element, CustomElementDefini tion* definition) 167 void CustomElement::enqueueUpgradeReaction(Element* element, CustomElementDefini tion* definition)
139 { 168 {
140 // CEReactionsScope must be created by [CEReactions] in IDL, 169 // CEReactionsScope must be created by [CEReactions] in IDL,
141 // or callers must setup explicitly if it does not go through bindings. 170 // or callers must setup explicitly if it does not go through bindings.
142 DCHECK(CEReactionsScope::current()); 171 DCHECK(CEReactionsScope::current());
143 CEReactionsScope::current()->enqueue(element, 172 CEReactionsScope::current()->enqueue(element,
144 new CustomElementUpgradeReaction(definition)); 173 new CustomElementUpgradeReaction(definition));
145 } 174 }
146 175
147 } // namespace blink 176 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698