Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef CustomElement_h | 5 #ifndef CustomElement_h |
| 6 #define CustomElement_h | 6 #define CustomElement_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/HTMLNames.h" | 9 #include "core/HTMLNames.h" |
| 10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
| 11 #include "platform/text/Character.h" | |
| 11 #include "wtf/Allocator.h" | 12 #include "wtf/Allocator.h" |
| 12 #include "wtf/text/AtomicString.h" | 13 #include "wtf/text/AtomicString.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 class Document; | 17 class Document; |
| 17 class Element; | 18 class Element; |
| 18 class HTMLElement; | 19 class HTMLElement; |
| 19 class QualifiedName; | 20 class QualifiedName; |
| 20 class CustomElementDefinition; | 21 class CustomElementDefinition; |
| 21 class CustomElementReaction; | 22 class CustomElementReaction; |
| 22 class CustomElementRegistry; | 23 class CustomElementRegistry; |
| 23 | 24 |
| 24 class CORE_EXPORT CustomElement { | 25 class CORE_EXPORT CustomElement { |
| 25 STATIC_ONLY(CustomElement); | 26 STATIC_ONLY(CustomElement); |
| 26 public: | 27 public: |
| 27 // Retrieves the CustomElementRegistry for Element, if any. This | 28 // Retrieves the CustomElementRegistry for Element, if any. This |
| 28 // may be a different object for a given element over its lifetime | 29 // may be a different object for a given element over its lifetime |
| 29 // as it moves between documents. | 30 // as it moves between documents. |
| 30 static CustomElementRegistry* registry(const Element&); | 31 static CustomElementRegistry* registry(const Element&); |
| 31 static CustomElementRegistry* registry(const Document&); | 32 static CustomElementRegistry* registry(const Document&); |
| 32 | 33 |
| 33 static CustomElementDefinition* definitionForElement(const Element*); | 34 static CustomElementDefinition* definitionForElement(const Element*); |
| 34 | 35 |
| 35 static bool isValidName(const AtomicString& name); | 36 static bool isValidName(const AtomicString& name) |
| 37 { | |
| 38 // This quickly rejects all common built-in element names. | |
| 39 if (name.find('-', 1) == kNotFound) | |
| 40 return false; | |
| 41 | |
| 42 // Note: All valid names start with an ASCII character. | |
|
esprehn
2016/09/02 00:53:20
for v1 we could just lookup the element in the reg
| |
| 43 if (!Character::isPotentialCustomElementNameStartChar(name[0])) | |
| 44 return false; | |
| 45 | |
| 46 if (name.is8Bit()) { | |
| 47 for (size_t i = 1; i < name.length(); ++i) { | |
| 48 if (!Character::isPotentialCustomElementName8BitChar(name[i])) | |
|
esprehn
2016/09/02 00:53:20
this is checking is8Bit and isNull() repeatedly in
esprehn
2016/09/02 00:55:31
This is also doing bounds checks, so you can save
| |
| 49 return false; | |
| 50 } | |
| 51 } else { | |
| 52 for (size_t i = 1; i < name.length(); ) { | |
| 53 UChar32 ch; | |
| 54 U16_NEXT(name.characters16(), i, name.length(), ch); | |
|
esprehn
2016/09/02 00:53:20
ditto, you're checking for null repeatedly inside
| |
| 55 if (!Character::isPotentialCustomElementNameChar(ch)) | |
| 56 return false; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 return !isHyphenatedSpecElementName(name); | |
| 61 } | |
| 36 | 62 |
| 37 static bool shouldCreateCustomElement(const AtomicString& localName); | 63 static bool shouldCreateCustomElement(const AtomicString& localName); |
| 38 static bool shouldCreateCustomElement(const QualifiedName&); | 64 static bool shouldCreateCustomElement(const QualifiedName&); |
| 39 | 65 |
| 40 static HTMLElement* createCustomElementSync(Document&, const AtomicString& l ocalName, ExceptionState&); | 66 static HTMLElement* createCustomElementSync(Document&, const AtomicString& l ocalName, ExceptionState&); |
| 41 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&, ExceptionState&); | 67 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&, ExceptionState&); |
| 42 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&) ; | 68 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&) ; |
| 43 static HTMLElement* createCustomElementAsync(Document&, const QualifiedName& ); | 69 static HTMLElement* createCustomElementAsync(Document&, const QualifiedName& ); |
| 44 | 70 |
| 45 static HTMLElement* createFailedElement(Document&, const QualifiedName&); | 71 static HTMLElement* createFailedElement(Document&, const QualifiedName&); |
| 46 | 72 |
| 47 static void enqueue(Element*, CustomElementReaction*); | 73 static void enqueue(Element*, CustomElementReaction*); |
| 48 static void enqueueConnectedCallback(Element*); | 74 static void enqueueConnectedCallback(Element*); |
| 49 static void enqueueDisconnectedCallback(Element*); | 75 static void enqueueDisconnectedCallback(Element*); |
| 50 static void enqueueAdoptedCallback(Element*); | 76 static void enqueueAdoptedCallback(Element*); |
| 51 static void enqueueAttributeChangedCallback(Element*, const QualifiedName&, | 77 static void enqueueAttributeChangedCallback(Element*, const QualifiedName&, |
| 52 const AtomicString& oldValue, const AtomicString& newValue); | 78 const AtomicString& oldValue, const AtomicString& newValue); |
| 53 | 79 |
| 54 static void tryToUpgrade(Element*); | 80 static void tryToUpgrade(Element*); |
| 55 | 81 |
| 56 private: | 82 private: |
| 83 // Some existing specs have element names with hyphens in them, | |
| 84 // like font-face in SVG. The custom elements spec explicitly | |
| 85 // disallows these as custom element names. | |
| 86 // https://html.spec.whatwg.org/#valid-custom-element-name | |
| 87 static bool isHyphenatedSpecElementName(const AtomicString&); | |
| 57 static HTMLElement* createUndefinedElement(Document&, const QualifiedName&); | 88 static HTMLElement* createUndefinedElement(Document&, const QualifiedName&); |
| 58 }; | 89 }; |
| 59 | 90 |
| 60 } // namespace blink | 91 } // namespace blink |
| 61 | 92 |
| 62 #endif // CustomElement_h | 93 #endif // CustomElement_h |
| OLD | NEW |