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

Side by Side 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: dominicc review 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 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"
8 #include "core/dom/Element.h"
9 #include "core/dom/QualifiedName.h"
10 #include "core/dom/custom/V0CustomElement.h"
11 #include "core/dom/custom/V0CustomElementRegistrationContext.h"
12 #include "core/html/HTMLElement.h"
7 #include "platform/text/Character.h" 13 #include "platform/text/Character.h"
8 #include "wtf/text/AtomicStringHash.h" 14 #include "wtf/text/AtomicStringHash.h"
9 15
10 namespace blink { 16 namespace blink {
11 17
12 bool CustomElement::isValidName(const AtomicString& name) 18 bool CustomElement::isValidName(const AtomicString& name)
13 { 19 {
14 if (!name.length() || name[0] < 'a' || name[0] > 'z') 20 if (!name.length() || name[0] < 'a' || name[0] > 'z')
15 return false; 21 return false;
16 22
(...skipping 21 matching lines...) Expand all
38 hyphenContainingElementNames.add("font-face-src"); 44 hyphenContainingElementNames.add("font-face-src");
39 hyphenContainingElementNames.add("font-face-uri"); 45 hyphenContainingElementNames.add("font-face-uri");
40 hyphenContainingElementNames.add("font-face-format"); 46 hyphenContainingElementNames.add("font-face-format");
41 hyphenContainingElementNames.add("font-face-name"); 47 hyphenContainingElementNames.add("font-face-name");
42 hyphenContainingElementNames.add("missing-glyph"); 48 hyphenContainingElementNames.add("missing-glyph");
43 } 49 }
44 50
45 return !hyphenContainingElementNames.contains(name); 51 return !hyphenContainingElementNames.contains(name);
46 } 52 }
47 53
54 bool CustomElement::shouldCreateCustomElement(Document& document, const AtomicSt ring& localName)
55 {
56 return RuntimeEnabledFeatures::customElementsV1Enabled()
57 && document.frame() && isValidName(localName);
58 }
59
60 bool CustomElement::shouldCreateCustomElement(Document& document, const Qualifie dName& tagName)
61 {
62 return shouldCreateCustomElement(document, tagName.localName())
63 && tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI;
64 }
65
66 HTMLElement* CustomElement::createCustomElement(Document& document, const Atomic String& localName)
67 {
68 return createCustomElement(document,
69 QualifiedName(nullAtom, document.convertLocalName(localName), HTMLNames: :xhtmlNamespaceURI));
70 }
71
72 HTMLElement* CustomElement::createCustomElement(Document& document, const Qualif iedName& tagName)
73 {
74 DCHECK(shouldCreateCustomElement(document, tagName));
75
76 // TODO(kojii): Look up already defined custom elements when custom element
77 // queues and upgrade are implemented.
78
79 HTMLElement* element;
80 if (V0CustomElement::isValidName(tagName.localName()) && document.registrati onContext()) {
81 Element* v0element = document.registrationContext()->createCustomTagElem ent(document, tagName);
82 SECURITY_DCHECK(v0element->isHTMLElement());
83 element = toHTMLElement(v0element);
84 } else {
85 element = HTMLElement::create(tagName, document);
86 }
87
88 element->setCustomElementState(CustomElementState::Undefined);
89
90 return element;
91 }
92
48 } // namespace blink 93 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698