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

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElement.h

Issue 2288653002: Make custom element name checks faster and fewer (Closed)
Patch Set: Lift the is8Bit check. Created 4 years, 3 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 #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/RuntimeEnabledFeatures.h"
12 #include "platform/text/Character.h"
11 #include "wtf/Allocator.h" 13 #include "wtf/Allocator.h"
12 #include "wtf/text/AtomicString.h" 14 #include "wtf/text/AtomicString.h"
13 15
14 namespace blink { 16 namespace blink {
15 17
16 class Document; 18 class Document;
17 class Element; 19 class Element;
18 class HTMLElement; 20 class HTMLElement;
19 class QualifiedName; 21 class QualifiedName;
20 class CustomElementDefinition; 22 class CustomElementDefinition;
21 class CustomElementReaction; 23 class CustomElementReaction;
22 class CustomElementRegistry; 24 class CustomElementRegistry;
23 25
24 class CORE_EXPORT CustomElement { 26 class CORE_EXPORT CustomElement {
25 STATIC_ONLY(CustomElement); 27 STATIC_ONLY(CustomElement);
26 public: 28 public:
27 // Retrieves the CustomElementRegistry for Element, if any. This 29 // Retrieves the CustomElementRegistry for Element, if any. This
28 // may be a different object for a given element over its lifetime 30 // may be a different object for a given element over its lifetime
29 // as it moves between documents. 31 // as it moves between documents.
30 static CustomElementRegistry* registry(const Element&); 32 static CustomElementRegistry* registry(const Element&);
31 static CustomElementRegistry* registry(const Document&); 33 static CustomElementRegistry* registry(const Document&);
32 34
33 static CustomElementDefinition* definitionForElement(const Element*); 35 static CustomElementDefinition* definitionForElement(const Element*);
34 36
35 static bool isValidName(const AtomicString& name); 37 static bool isValidName(const AtomicString& name)
38 {
39 if (!name.length() || name[0] < 'a' || name[0] > 'z')
kouhei (in TOK) 2016/08/29 06:59:55 Can we refactor the name[0] check as a platform/te
40 return false;
36 41
37 static bool shouldCreateCustomElement(const AtomicString& localName); 42 bool hasHyphens = false;
43 if (name.is8Bit()) {
44 for (size_t i = 1; i < name.length(); ) {
45 UChar ch = name[i++];
46 if (ch == '-')
47 hasHyphens = true;
48 else if (!Character::isPotentialCustomElementNameChar(ch))
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);
55 if (ch == '-')
56 hasHyphens = true;
57 else if (!Character::isPotentialCustomElementNameChar(ch))
58 return false;
59 }
60 }
61 return hasHyphens && !isHyphenContainingElementName(name);
62 }
63
64 static bool shouldCreateCustomElement(const AtomicString& localName)
65 {
66 return RuntimeEnabledFeatures::customElementsV1Enabled()
67 && isValidName(localName);
68 }
69
38 static bool shouldCreateCustomElement(const QualifiedName&); 70 static bool shouldCreateCustomElement(const QualifiedName&);
39 71
40 static HTMLElement* createCustomElementSync(Document&, const AtomicString& l ocalName, ExceptionState&); 72 static HTMLElement* createCustomElementSync(Document&, const AtomicString& l ocalName, ExceptionState*);
esprehn 2016/08/30 21:32:32 We normally do ExceptionState& and then default ar
41 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&, ExceptionState&); 73 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&, ExceptionState*);
42 static HTMLElement* createCustomElementSync(Document&, const QualifiedName&) ;
43 static HTMLElement* createCustomElementAsync(Document&, const QualifiedName& ); 74 static HTMLElement* createCustomElementAsync(Document&, const QualifiedName& );
44 75
45 static HTMLElement* createFailedElement(Document&, const QualifiedName&); 76 static HTMLElement* createFailedElement(Document&, const QualifiedName&);
46 77
47 static void enqueue(Element*, CustomElementReaction*); 78 static void enqueue(Element*, CustomElementReaction*);
48 static void enqueueConnectedCallback(Element*); 79 static void enqueueConnectedCallback(Element*);
49 static void enqueueDisconnectedCallback(Element*); 80 static void enqueueDisconnectedCallback(Element*);
50 static void enqueueAdoptedCallback(Element*); 81 static void enqueueAdoptedCallback(Element*);
51 static void enqueueAttributeChangedCallback(Element*, const QualifiedName&, 82 static void enqueueAttributeChangedCallback(Element*, const QualifiedName&,
52 const AtomicString& oldValue, const AtomicString& newValue); 83 const AtomicString& oldValue, const AtomicString& newValue);
53 84
54 static void tryToUpgrade(Element*); 85 static void tryToUpgrade(Element*);
55 86
56 private: 87 private:
57 static HTMLElement* createUndefinedElement(Document&, const QualifiedName&); 88 static HTMLElement* createUndefinedElement(Document&, const QualifiedName&);
89
90 // A hyphen-containing element name is an element name from a
91 // specification which contains a hyphen, for example, font-face
92 // from SVG. These are not allowed as custom element names.
93 static bool isHyphenContainingElementName(const AtomicString&);
58 }; 94 };
59 95
60 } // namespace blink 96 } // namespace blink
61 97
62 #endif // CustomElement_h 98 #endif // CustomElement_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698