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

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

Issue 2002903002: Hook createElement for Custom Elements V1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fb55576c5c0db3774ea8c68b6b824ebb26f2300c..be999ff97e8929c4c489d4de7bc1add1ca49635c 100644
--- a/third_party/WebKit/Source/core/dom/custom/CustomElement.cpp
+++ b/third_party/WebKit/Source/core/dom/custom/CustomElement.cpp
@@ -4,6 +4,12 @@
#include "core/dom/custom/CustomElement.h"
+#include "core/dom/Document.h"
+#include "core/dom/Element.h"
+#include "core/dom/QualifiedName.h"
+#include "core/dom/custom/V0CustomElement.h"
+#include "core/dom/custom/V0CustomElementRegistrationContext.h"
+#include "core/html/HTMLElement.h"
#include "platform/text/Character.h"
#include "wtf/text/AtomicStringHash.h"
@@ -45,4 +51,43 @@ bool CustomElement::isValidName(const AtomicString& name)
return !hyphenContainingElementNames.contains(name);
}
+bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicString& localName)
+{
+ // 7.3 of https://dom.spec.whatwg.org/#concept-create-element
+ return document.frame()
kojii 2016/05/23 09:40:20 Is this correct condition when the spec says "has
+ && isValidName(localName);
+}
+
+bool CustomElement::shouldCreateCustomElement(Document& document, const QualifiedName& tagName)
+{
+ return shouldCreateCustomElement(document, tagName.localName())
+ && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI;
+}
+
+HTMLElement* CustomElement::createCustomElement(Document& document, const AtomicString& localName)
+{
+ return createCustomElement(document,
+ QualifiedName(nullAtom, document.convertLocalName(localName), HTMLNames::xhtmlNamespaceURI));
+}
+
+HTMLElement* CustomElement::createCustomElement(Document& document, const QualifiedName& tagName)
+{
+ DCHECK(shouldCreateCustomElement(document, tagName));
+
+ // TODO(kojii): This does not lookup already defined custom elements yet.
+
+ HTMLElement* element;
+ if (V0CustomElement::isValidName(tagName.localName()) && document.registrationContext()) {
+ Element* e = document.registrationContext()->createCustomTagElement(document, tagName);
+ SECURITY_DCHECK(e->isHTMLElement());
+ element = toHTMLElement(e);
+ } else {
+ element = HTMLElement::create(tagName, document);
+ }
+
+ element->setCustomElementState(CustomElementState::Undefined);
+
+ return element;
+}
+
} // namespace blink
« 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