| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 * | 29 * |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "core/html/LinkRelAttribute.h" | 33 #include "core/html/LinkRelAttribute.h" |
| 34 | 34 |
| 35 #include "RuntimeEnabledFeatures.h" | 35 #include "RuntimeEnabledFeatures.h" |
| 36 #include "wtf/text/WTFString.h" | |
| 37 | 36 |
| 38 namespace WebCore { | 37 namespace WebCore { |
| 39 | 38 |
| 40 LinkRelAttribute::LinkRelAttribute() | |
| 41 : m_iconType(InvalidIcon) | |
| 42 , m_isStyleSheet(false) | |
| 43 , m_isAlternate(false) | |
| 44 , m_isDNSPrefetch(false) | |
| 45 , m_isLinkPrefetch(false) | |
| 46 , m_isLinkSubresource(false) | |
| 47 , m_isLinkPrerender(false) | |
| 48 , m_isLinkNext(false) | |
| 49 , m_isImport(false) | |
| 50 { | |
| 51 } | |
| 52 | |
| 53 LinkRelAttribute::LinkRelAttribute(const String& rel) | 39 LinkRelAttribute::LinkRelAttribute(const String& rel) |
| 54 : m_iconType(InvalidIcon) | 40 : m_iconType(InvalidIcon) |
| 55 , m_isStyleSheet(false) | 41 , m_isStyleSheet(false) |
| 56 , m_isAlternate(false) | 42 , m_isAlternate(false) |
| 57 , m_isDNSPrefetch(false) | 43 , m_isDNSPrefetch(false) |
| 58 , m_isLinkPrefetch(false) | 44 , m_isLinkPrefetch(false) |
| 59 , m_isLinkSubresource(false) | 45 , m_isLinkSubresource(false) |
| 60 , m_isLinkPrerender(false) | 46 , m_isLinkPrerender(false) |
| 61 , m_isLinkNext(false) | 47 , m_isLinkNext(false) |
| 62 , m_isImport(false) | 48 , m_isImport(false) |
| 63 { | 49 { |
| 64 if (equalIgnoringCase(rel, "stylesheet")) { | 50 if (rel.isEmpty()) |
| 65 m_isStyleSheet = true; | 51 return; |
| 66 } else if (equalIgnoringCase(rel, "icon") || equalIgnoringCase(rel, "shortcu
t icon")) { | 52 String relCopy = rel; |
| 67 m_iconType = Favicon; | 53 relCopy.replace('\n', ' '); |
| 68 } else if (equalIgnoringCase(rel, "dns-prefetch")) { | 54 Vector<String> list; |
| 69 m_isDNSPrefetch = true; | 55 relCopy.split(' ', list); |
| 70 } else if (equalIgnoringCase(rel, "alternate stylesheet") || equalIgnoringCa
se(rel, "stylesheet alternate")) { | 56 Vector<String>::const_iterator end = list.end(); |
| 71 m_isStyleSheet = true; | 57 for (Vector<String>::const_iterator it = list.begin(); it != end; ++it) { |
| 72 m_isAlternate = true; | 58 if (equalIgnoringCase(*it, "stylesheet")) { |
| 73 } else if (equalIgnoringCase(rel, "import")) { | 59 if (!m_isImport) |
| 74 m_isImport = true; | |
| 75 } else if (equalIgnoringCase(rel, "apple-touch-icon")) { | |
| 76 if (RuntimeEnabledFeatures::touchIconLoadingEnabled()) { | |
| 77 m_iconType = TouchIcon; | |
| 78 } | |
| 79 } else if (equalIgnoringCase(rel, "apple-touch-icon-precomposed")) { | |
| 80 if (RuntimeEnabledFeatures::touchIconLoadingEnabled()) { | |
| 81 m_iconType = TouchPrecomposedIcon; | |
| 82 } | |
| 83 } else { | |
| 84 // Tokenize the rel attribute and set bits based on specific keywords th
at we find. | |
| 85 String relCopy = rel; | |
| 86 relCopy.replace('\n', ' '); | |
| 87 Vector<String> list; | |
| 88 relCopy.split(' ', list); | |
| 89 Vector<String>::const_iterator end = list.end(); | |
| 90 for (Vector<String>::const_iterator it = list.begin(); it != end; ++it)
{ | |
| 91 if (equalIgnoringCase(*it, "stylesheet")) { | |
| 92 m_isStyleSheet = true; | 60 m_isStyleSheet = true; |
| 93 } else if (equalIgnoringCase(*it, "alternate")) { | 61 } else if (equalIgnoringCase(*it, "import")) { |
| 94 m_isAlternate = true; | 62 if (!m_isStyleSheet) |
| 95 } else if (equalIgnoringCase(*it, "icon")) { | 63 m_isImport = true; |
| 96 m_iconType = Favicon; | 64 } else if (equalIgnoringCase(*it, "alternate")) { |
| 97 } else if (equalIgnoringCase(*it, "prefetch")) { | 65 m_isAlternate = true; |
| 98 m_isLinkPrefetch = true; | 66 } else if (equalIgnoringCase(*it, "icon")) { |
| 99 } else if (equalIgnoringCase(*it, "subresource")) { | 67 // This also allows "shortcut icon" since we just ignore the non-sta
ndard "shortcut" token. |
| 100 m_isLinkSubresource = true; | 68 // FIXME: This doesn't really follow the spec that requires "shortcu
t icon" to be the |
| 101 } else if (equalIgnoringCase(*it, "prerender")) { | 69 // entire string http://www.whatwg.org/specs/web-apps/current-work/m
ultipage/links.html#rel-icon |
| 102 m_isLinkPrerender = true; | 70 m_iconType = Favicon; |
| 103 } else if (equalIgnoringCase(*it, "next")) { | 71 } else if (equalIgnoringCase(*it, "prefetch")) { |
| 104 m_isLinkNext = true; | 72 m_isLinkPrefetch = true; |
| 105 } else if (equalIgnoringCase(*it, "apple-touch-icon")) { | 73 } else if (equalIgnoringCase(*it, "dns-prefetch")) { |
| 106 if (RuntimeEnabledFeatures::touchIconLoadingEnabled()) { | 74 m_isDNSPrefetch = true; |
| 107 m_iconType = TouchIcon; | 75 } else if (equalIgnoringCase(*it, "subresource")) { |
| 108 } | 76 m_isLinkSubresource = true; |
| 109 } else if (equalIgnoringCase(*it, "apple-touch-icon-precomposed")) { | 77 } else if (equalIgnoringCase(*it, "prerender")) { |
| 110 if (RuntimeEnabledFeatures::touchIconLoadingEnabled()) { | 78 m_isLinkPrerender = true; |
| 111 m_iconType = TouchPrecomposedIcon; | 79 } else if (equalIgnoringCase(*it, "next")) { |
| 112 } | 80 m_isLinkNext = true; |
| 113 } | 81 } else if (equalIgnoringCase(*it, "apple-touch-icon")) { |
| 82 if (RuntimeEnabledFeatures::touchIconLoadingEnabled()) |
| 83 m_iconType = TouchIcon; |
| 84 } else if (equalIgnoringCase(*it, "apple-touch-icon-precomposed")) { |
| 85 if (RuntimeEnabledFeatures::touchIconLoadingEnabled()) |
| 86 m_iconType = TouchPrecomposedIcon; |
| 114 } | 87 } |
| 115 } | 88 } |
| 116 } | 89 } |
| 117 | 90 |
| 118 } | 91 } |
| OLD | NEW |