1 /* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29 * 30 */ 31 32 #include "config.h" 33 #include "core/html/LinkRelAttribute.h" 34 35 namespace WebCore { 36 37 LinkRelAttribute::LinkRelAttribute() 38 : m_iconType(InvalidIcon) 39 , m_isStyleSheet(false) 40 , m_isAlternate(false) 41 , m_isDNSPrefetch(false) 42 , m_isLinkPrefetch(false) 43 , m_isLinkSubresource(false) 44 , m_isLinkPrerender(false) 45 , m_isImport(false) 46 { 47 } 48 49 LinkRelAttribute::LinkRelAttribute(const String& rel) 50 : m_iconType(InvalidIcon) 51 , m_isStyleSheet(false) 52 , m_isAlternate(false) 53 , m_isDNSPrefetch(false) 54 , m_isLinkPrefetch(false) 55 , m_isLinkSubresource(false) 56 , m_isLinkPrerender(false) 57 , m_isImport(false) 58 { 59 if (equalIgnoringCase(rel, "stylesheet")) 60 m_isStyleSheet = true; 61 else if (equalIgnoringCase(rel, "icon") || equalIgnoringCase(rel, "shortcut icon")) 62 m_iconType = Favicon; 63 #if ENABLE(TOUCH_ICON_LOADING) 64 else if (equalIgnoringCase(rel, "apple-touch-icon")) 65 m_iconType = TouchIcon; 66 else if (equalIgnoringCase(rel, "apple-touch-icon-precomposed")) 67 m_iconType = TouchPrecomposedIcon; 68 #endif 69 else if (equalIgnoringCase(rel, "dns-prefetch")) 70 m_isDNSPrefetch = true; 71 else if (equalIgnoringCase(rel, "alternate stylesheet") || equalIgnoringCase(rel, "stylesheet alternate")) { 72 m_isStyleSheet = true; 73 m_isAlternate = true; 74 } else if (equalIgnoringCase(rel, "import")) { 75 m_isImport = true; 76 } else { 77 // Tokenize the rel attribute and set bits based on specific keywords that we find. 78 String relCopy = rel; 79 relCopy.replace('\n', ' '); 80 Vector<String> list; 81 relCopy.split(' ', list); 82 Vector<String>::const_iterator end = list.end(); 83 for (Vector<String>::const_iterator it = list.begin(); it != end; ++it) { 84 if (equalIgnoringCase(*it, "stylesheet")) 85 m_isStyleSheet = true; 86 else if (equalIgnoringCase(*it, "alternate")) 87 m_isAlternate = true; 88 else if (equalIgnoringCase(*it, "icon")) 89 m_iconType = Favicon; 90 #if ENABLE(TOUCH_ICON_LOADING) 91 else if (equalIgnoringCase(*it, "apple-touch-icon")) 92 m_iconType = TouchIcon; 93 else if (equalIgnoringCase(*it, "apple-touch-icon-precomposed")) 94 m_iconType = TouchPrecomposedIcon; 95 #endif 96 else if (equalIgnoringCase(*it, "prefetch")) 97 m_isLinkPrefetch = true; 98 else if (equalIgnoringCase(*it, "subresource")) 99 m_isLinkSubresource = true; 100 else if (equalIgnoringCase(*it, "prerender")) 101 m_isLinkPrerender = true; 102 } 103 } 104 } 105 106 } 107