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 #include "core/dom/custom/CustomElement.h" | 5 #include "core/dom/custom/CustomElement.h" |
6 | 6 |
7 #include "platform/text/Character.h" | 7 #include "platform/text/Character.h" |
| 8 #include "wtf/text/AtomicStringHash.h" |
8 | 9 |
9 namespace blink { | 10 namespace blink { |
10 | 11 |
11 bool CustomElement::isPotentialCustomElementName(const AtomicString& name) | 12 bool CustomElement::isValidName(const AtomicString& name) |
12 { | 13 { |
13 if (!name.length() || name[0] < 'a' || name[0] > 'z') | 14 if (!name.length() || name[0] < 'a' || name[0] > 'z') |
14 return false; | 15 return false; |
15 | 16 |
16 bool hasHyphens = false; | 17 bool hasHyphens = false; |
17 for (size_t i = 1; i < name.length(); ) { | 18 for (size_t i = 1; i < name.length(); ) { |
18 UChar32 ch; | 19 UChar32 ch; |
19 if (name.is8Bit()) | 20 if (name.is8Bit()) |
20 ch = name[i++]; | 21 ch = name[i++]; |
21 else | 22 else |
22 U16_NEXT(name.characters16(), i, name.length(), ch); | 23 U16_NEXT(name.characters16(), i, name.length(), ch); |
23 if (ch == '-') | 24 if (ch == '-') |
24 hasHyphens = true; | 25 hasHyphens = true; |
25 else if (!Character::isPotentialCustomElementNameChar(ch)) | 26 else if (!Character::isPotentialCustomElementNameChar(ch)) |
26 return false; | 27 return false; |
27 } | 28 } |
28 return hasHyphens; | 29 if (!hasHyphens) |
| 30 return false; |
| 31 |
| 32 // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-elemen
t-name |
| 33 DEFINE_STATIC_LOCAL(HashSet<AtomicString>, hyphenContainingElementNames, ())
; |
| 34 if (hyphenContainingElementNames.isEmpty()) { |
| 35 hyphenContainingElementNames.add("annotation-xml"); |
| 36 hyphenContainingElementNames.add("color-profile"); |
| 37 hyphenContainingElementNames.add("font-face"); |
| 38 hyphenContainingElementNames.add("font-face-src"); |
| 39 hyphenContainingElementNames.add("font-face-uri"); |
| 40 hyphenContainingElementNames.add("font-face-format"); |
| 41 hyphenContainingElementNames.add("font-face-name"); |
| 42 hyphenContainingElementNames.add("missing-glyph"); |
| 43 } |
| 44 |
| 45 return !hyphenContainingElementNames.contains(name); |
29 } | 46 } |
30 | 47 |
31 } // namespace blink | 48 } // namespace blink |
OLD | NEW |