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

Unified 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: Made changes 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/custom/CustomElement.cpp
diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElement.cpp b/third_party/WebKit/Source/core/dom/custom/CustomElement.cpp
index c86abfe261a64bc17246a54fb299ed9729dde3cd..9c1f3d9159f7e6d810c01ee75877ddab27e5190b 100644
--- a/third_party/WebKit/Source/core/dom/custom/CustomElement.cpp
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElement.cpp
@@ -4,6 +4,8 @@
#include "core/dom/custom/CustomElement.h"
+#include "core/HTMLElementFactory.h"
+#include "core/HTMLElementTypeHelpers.h"
#include "core/dom/Document.h"
#include "core/dom/QualifiedName.h"
#include "core/dom/custom/CEReactionsScope.h"
@@ -79,21 +81,36 @@ static CustomElementDefinition* definitionFor(
HTMLElement* CustomElement::createCustomElementSync(
Document& document,
- const AtomicString& localName) {
+ const AtomicString& localName,
+ const AtomicString& is) {
return createCustomElementSync(
document,
- QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI));
+ QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), is);
}
+// https://dom.spec.whatwg.org/#concept-create-element
HTMLElement* CustomElement::createCustomElementSync(
Document& document,
- const QualifiedName& tagName) {
- DCHECK(shouldCreateCustomElement(tagName));
- if (CustomElementDefinition* definition = definitionFor(
- document,
- CustomElementDescriptor(tagName.localName(), tagName.localName())))
- return definition->createElementSync(document, tagName);
- return createUndefinedElement(document, tagName);
+ const QualifiedName& tagName,
+ const AtomicString& is) {
+ const AtomicString& name = is.isNull() ? tagName.localName() : is;
+ DCHECK(shouldCreateCustomElement(name));
dominicc (has gone to gerrit) 2016/11/08 08:36:29 Could you do a debug build and try something like
+ const CustomElementDescriptor desc(name, tagName.localName());
+ CustomElementDefinition* definition = definitionFor(document, desc);
+ HTMLElement* element;
+
+ if (definition && desc.isAutonomous()) {
+ // 6. If definition is non-null and we have an autonomous custom element
+ element = definition->createElementSync(document, tagName);
+ } else if (definition) {
+ // 5. If definition is non-null and we have a customized built-in element
+ element = createUndefinedElement(document, tagName);
+ definition->upgrade(element);
+ } else {
+ // 7. Otherwise
+ element = createUndefinedElement(document, tagName);
+ }
+ return element;
}
HTMLElement* CustomElement::createCustomElementAsync(
@@ -113,10 +130,15 @@ HTMLElement* CustomElement::createCustomElementAsync(
return createUndefinedElement(document, tagName);
}
+// Create a HTMLElement
HTMLElement* CustomElement::createUndefinedElement(
Document& document,
const QualifiedName& tagName) {
- DCHECK(shouldCreateCustomElement(tagName));
+ bool shouldCreateBuiltin =
+ htmlElementTypeForTag(tagName.localName()) !=
+ HTMLElementType::kHTMLUnknownElement &&
+ RuntimeEnabledFeatures::customElementsBuiltinEnabled();
+ DCHECK(shouldCreateCustomElement(tagName) || shouldCreateBuiltin);
HTMLElement* element;
if (V0CustomElement::isValidName(tagName.localName()) &&
@@ -125,6 +147,9 @@ HTMLElement* CustomElement::createUndefinedElement(
document, tagName);
SECURITY_DCHECK(v0element->isHTMLElement());
element = toHTMLElement(v0element);
+ } else if (shouldCreateBuiltin) {
+ element = HTMLElementFactory::createHTMLElement(
+ tagName.localName(), document, nullptr, CreatedByCreateElement);
} else {
element = HTMLElement::create(tagName, document);
}

Powered by Google App Engine
This is Rietveld 408576698