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#include "platform/RuntimeEnabledFeatures.h"
36
37namespace blink {
38
39LinkRelAttribute::LinkRelAttribute(const String& rel)
40    : m_iconType(InvalidIcon)
41    , m_isStyleSheet(false)
42    , m_isAlternate(false)
43    , m_isDNSPrefetch(false)
44    , m_isLinkPrefetch(false)
45    , m_isLinkSubresource(false)
46    , m_isLinkPrerender(false)
47    , m_isLinkNext(false)
48    , m_isImport(false)
49    , m_isManifest(false)
50    , m_isTransitionExitingStylesheet(false)
51{
52    if (rel.isEmpty())
53        return;
54    String relCopy = rel;
55    relCopy.replace('\n', ' ');
56    Vector<String> list;
57    relCopy.split(' ', list);
58    Vector<String>::const_iterator end = list.end();
59    for (Vector<String>::const_iterator it = list.begin(); it != end; ++it) {
60        if (equalIgnoringCase(*it, "stylesheet")) {
61            if (!m_isImport)
62                m_isStyleSheet = true;
63        } else if (equalIgnoringCase(*it, "import")) {
64            if (!m_isStyleSheet)
65                m_isImport = true;
66        } else if (equalIgnoringCase(*it, "alternate")) {
67            m_isAlternate = true;
68        } else if (equalIgnoringCase(*it, "icon")) {
69            // This also allows "shortcut icon" since we just ignore the non-standard "shortcut" token.
70            // FIXME: This doesn't really follow the spec that requires "shortcut icon" to be the
71            // entire string http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon
72            m_iconType = Favicon;
73        } else if (equalIgnoringCase(*it, "prefetch")) {
74            m_isLinkPrefetch = true;
75        } else if (equalIgnoringCase(*it, "dns-prefetch")) {
76            m_isDNSPrefetch = true;
77        } else if (equalIgnoringCase(*it, "subresource")) {
78            m_isLinkSubresource = true;
79        } else if (equalIgnoringCase(*it, "prerender")) {
80            m_isLinkPrerender = true;
81        } else if (equalIgnoringCase(*it, "next")) {
82            m_isLinkNext = true;
83        } else if (equalIgnoringCase(*it, "apple-touch-icon")) {
84            if (RuntimeEnabledFeatures::touchIconLoadingEnabled())
85                m_iconType = TouchIcon;
86        } else if (equalIgnoringCase(*it, "apple-touch-icon-precomposed")) {
87            if (RuntimeEnabledFeatures::touchIconLoadingEnabled())
88                m_iconType = TouchPrecomposedIcon;
89        } else if (equalIgnoringCase(*it, "manifest")) {
90            m_isManifest = true;
91        } else if (equalIgnoringCase(rel, "transition-exiting-stylesheet")) {
92            if (RuntimeEnabledFeatures::navigationTransitionsEnabled())
93                m_isTransitionExitingStylesheet = true;
94        }
95    }
96}
97
98}
99