Chromium Code Reviews| Index: third_party/WebKit/Source/core/dom/custom/CustomElement.h |
| diff --git a/third_party/WebKit/Source/core/dom/custom/CustomElement.h b/third_party/WebKit/Source/core/dom/custom/CustomElement.h |
| index ec8f3c1546b5e74181b1b0e7f308088f848439f2..7974b2508b5d8191e1633172847b5c8e8dbdf0ab 100644 |
| --- a/third_party/WebKit/Source/core/dom/custom/CustomElement.h |
| +++ b/third_party/WebKit/Source/core/dom/custom/CustomElement.h |
| @@ -8,6 +8,8 @@ |
| #include "core/CoreExport.h" |
| #include "core/HTMLNames.h" |
| #include "core/dom/Element.h" |
| +#include "platform/RuntimeEnabledFeatures.h" |
| +#include "platform/text/Character.h" |
| #include "wtf/Allocator.h" |
| #include "wtf/text/AtomicString.h" |
| @@ -32,14 +34,43 @@ public: |
| static CustomElementDefinition* definitionForElement(const Element*); |
| - static bool isValidName(const AtomicString& name); |
| + static bool isValidName(const AtomicString& name) |
| + { |
| + 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
|
| + return false; |
| + |
| + bool hasHyphens = false; |
| + if (name.is8Bit()) { |
| + for (size_t i = 1; i < name.length(); ) { |
| + UChar ch = name[i++]; |
| + if (ch == '-') |
| + hasHyphens = true; |
| + else if (!Character::isPotentialCustomElementNameChar(ch)) |
| + return false; |
| + } |
| + } else { |
| + for (size_t i = 1; i < name.length(); ) { |
| + UChar32 ch; |
| + U16_NEXT(name.characters16(), i, name.length(), ch); |
| + if (ch == '-') |
| + hasHyphens = true; |
| + else if (!Character::isPotentialCustomElementNameChar(ch)) |
| + return false; |
| + } |
| + } |
| + return hasHyphens && !isHyphenContainingElementName(name); |
| + } |
| + |
| + static bool shouldCreateCustomElement(const AtomicString& localName) |
| + { |
| + return RuntimeEnabledFeatures::customElementsV1Enabled() |
| + && isValidName(localName); |
| + } |
| - static bool shouldCreateCustomElement(const AtomicString& localName); |
| static bool shouldCreateCustomElement(const QualifiedName&); |
| - static HTMLElement* createCustomElementSync(Document&, const AtomicString& localName, ExceptionState&); |
| - static HTMLElement* createCustomElementSync(Document&, const QualifiedName&, ExceptionState&); |
| - static HTMLElement* createCustomElementSync(Document&, const QualifiedName&); |
| + static HTMLElement* createCustomElementSync(Document&, const AtomicString& localName, ExceptionState*); |
|
esprehn
2016/08/30 21:32:32
We normally do ExceptionState& and then default ar
|
| + static HTMLElement* createCustomElementSync(Document&, const QualifiedName&, ExceptionState*); |
| static HTMLElement* createCustomElementAsync(Document&, const QualifiedName&); |
| static HTMLElement* createFailedElement(Document&, const QualifiedName&); |
| @@ -55,6 +86,11 @@ public: |
| private: |
| static HTMLElement* createUndefinedElement(Document&, const QualifiedName&); |
| + |
| + // A hyphen-containing element name is an element name from a |
| + // specification which contains a hyphen, for example, font-face |
| + // from SVG. These are not allowed as custom element names. |
| + static bool isHyphenContainingElementName(const AtomicString&); |
| }; |
| } // namespace blink |