From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/html/LinkRelAttribute.cpp | 105 ++++++++++++++++--------------- 1 file changed, 56 insertions(+), 49 deletions(-) (limited to 'Source/WebCore/html/LinkRelAttribute.cpp') diff --git a/Source/WebCore/html/LinkRelAttribute.cpp b/Source/WebCore/html/LinkRelAttribute.cpp index 712e37069..b76955c50 100644 --- a/Source/WebCore/html/LinkRelAttribute.cpp +++ b/Source/WebCore/html/LinkRelAttribute.cpp @@ -32,73 +32,80 @@ #include "config.h" #include "LinkRelAttribute.h" +#include "LinkIconType.h" +#include "RuntimeEnabledFeatures.h" +#include + namespace WebCore { LinkRelAttribute::LinkRelAttribute() - : m_isStyleSheet(false) - , m_iconType(InvalidIcon) - , m_isAlternate(false) - , m_isDNSPrefetch(false) -#if ENABLE(LINK_PREFETCH) - , m_isLinkPrefetch(false) - , m_isLinkSubresource(false) -#endif { } +// Keep LinkRelAttribute::isSupported() in sync when updating this constructor. LinkRelAttribute::LinkRelAttribute(const String& rel) - : m_isStyleSheet(false) - , m_iconType(InvalidIcon) - , m_isAlternate(false) - , m_isDNSPrefetch(false) -#if ENABLE(LINK_PREFETCH) - , m_isLinkPrefetch(false) - , m_isLinkSubresource(false) -#endif { - if (equalIgnoringCase(rel, "stylesheet")) - m_isStyleSheet = true; - else if (equalIgnoringCase(rel, "icon") || equalIgnoringCase(rel, "shortcut icon")) - m_iconType = Favicon; -#if ENABLE(TOUCH_ICON_LOADING) - else if (equalIgnoringCase(rel, "apple-touch-icon")) - m_iconType = TouchIcon; - else if (equalIgnoringCase(rel, "apple-touch-icon-precomposed")) - m_iconType = TouchPrecomposedIcon; -#endif - else if (equalIgnoringCase(rel, "dns-prefetch")) - m_isDNSPrefetch = true; - else if (equalIgnoringCase(rel, "alternate stylesheet") || equalIgnoringCase(rel, "stylesheet alternate")) { - m_isStyleSheet = true; - m_isAlternate = true; + if (equalLettersIgnoringASCIICase(rel, "stylesheet")) + isStyleSheet = true; + else if (equalLettersIgnoringASCIICase(rel, "icon") || equalLettersIgnoringASCIICase(rel, "shortcut icon")) + iconType = LinkIconType::Favicon; + else if (equalLettersIgnoringASCIICase(rel, "apple-touch-icon")) + iconType = LinkIconType::TouchIcon; + else if (equalLettersIgnoringASCIICase(rel, "apple-touch-icon-precomposed")) + iconType = LinkIconType::TouchPrecomposedIcon; + else if (equalLettersIgnoringASCIICase(rel, "dns-prefetch")) + isDNSPrefetch = true; + else if (RuntimeEnabledFeatures::sharedFeatures().linkPreloadEnabled() && equalLettersIgnoringASCIICase(rel, "preload")) + isLinkPreload = true; + else if (equalLettersIgnoringASCIICase(rel, "alternate stylesheet") || equalLettersIgnoringASCIICase(rel, "stylesheet alternate")) { + isStyleSheet = true; + isAlternate = true; } else { // Tokenize the rel attribute and set bits based on specific keywords that we find. String relCopy = rel; relCopy.replace('\n', ' '); Vector list; relCopy.split(' ', list); - Vector::const_iterator end = list.end(); - for (Vector::const_iterator it = list.begin(); it != end; ++it) { - if (equalIgnoringCase(*it, "stylesheet")) - m_isStyleSheet = true; - else if (equalIgnoringCase(*it, "alternate")) - m_isAlternate = true; - else if (equalIgnoringCase(*it, "icon")) - m_iconType = Favicon; -#if ENABLE(TOUCH_ICON_LOADING) - else if (equalIgnoringCase(*it, "apple-touch-icon")) - m_iconType = TouchIcon; - else if (equalIgnoringCase(*it, "apple-touch-icon-precomposed")) - m_iconType = TouchPrecomposedIcon; -#endif + for (auto& word : list) { + if (equalLettersIgnoringASCIICase(word, "stylesheet")) + isStyleSheet = true; + else if (equalLettersIgnoringASCIICase(word, "alternate")) + isAlternate = true; + else if (equalLettersIgnoringASCIICase(word, "icon")) + iconType = LinkIconType::Favicon; + else if (equalLettersIgnoringASCIICase(word, "apple-touch-icon")) + iconType = LinkIconType::TouchIcon; + else if (equalLettersIgnoringASCIICase(word, "apple-touch-icon-precomposed")) + iconType = LinkIconType::TouchPrecomposedIcon; #if ENABLE(LINK_PREFETCH) - else if (equalIgnoringCase(*it, "prefetch")) - m_isLinkPrefetch = true; - else if (equalIgnoringCase(*it, "subresource")) - m_isLinkSubresource = true; + else if (equalLettersIgnoringASCIICase(word, "prefetch")) + isLinkPrefetch = true; + else if (equalLettersIgnoringASCIICase(word, "subresource")) + isLinkSubresource = true; #endif } } } +// https://html.spec.whatwg.org/#linkTypes +bool LinkRelAttribute::isSupported(StringView attribute) +{ + static const char* const supportedAttributes[] = { + "alternate", "dns-prefetch", "icon", "stylesheet", "apple-touch-icon", "apple-touch-icon-precomposed", +#if ENABLE(LINK_PREFETCH) + "prefetch", "subresource", +#endif + }; + + for (auto* supportedAttribute : supportedAttributes) { + if (equalIgnoringASCIICase(attribute, supportedAttribute)) + return true; + } + + if (RuntimeEnabledFeatures::sharedFeatures().linkPreloadEnabled() && equalIgnoringASCIICase(attribute, "preload")) + return true; + + return false; +} + } -- cgit v1.2.1