Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / LinkRelAttribute.cpp
blob9d04ca2e0994bb56230b51e39c5b91d262f0af08
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
32 #include "config.h"
33 #include "core/html/LinkRelAttribute.h"
35 #include "platform/RuntimeEnabledFeatures.h"
37 namespace blink {
39 LinkRelAttribute::LinkRelAttribute(const String& rel)
40 : m_iconType(InvalidIcon)
41 , m_isStyleSheet(false)
42 , m_isAlternate(false)
43 , m_isDNSPrefetch(false)
44 , m_isPreconnect(false)
45 , m_isLinkPrefetch(false)
46 , m_isLinkSubresource(false)
47 , m_isLinkPreload(false)
48 , m_isLinkPrerender(false)
49 , m_isLinkNext(false)
50 , m_isImport(false)
51 , m_isManifest(false)
53 if (rel.isEmpty())
54 return;
55 String relCopy = rel;
56 relCopy.replace('\n', ' ');
57 Vector<String> list;
58 relCopy.split(' ', list);
59 for (const String& linkType : list) {
60 if (equalIgnoringCase(linkType, "stylesheet")) {
61 if (!m_isImport)
62 m_isStyleSheet = true;
63 } else if (equalIgnoringCase(linkType, "import")) {
64 if (!m_isStyleSheet)
65 m_isImport = true;
66 } else if (equalIgnoringCase(linkType, "alternate")) {
67 m_isAlternate = true;
68 } else if (equalIgnoringCase(linkType, "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(linkType, "prefetch")) {
74 m_isLinkPrefetch = true;
75 } else if (equalIgnoringCase(linkType, "dns-prefetch")) {
76 m_isDNSPrefetch = true;
77 } else if (equalIgnoringCase(linkType, "preconnect")) {
78 if (RuntimeEnabledFeatures::linkPreconnectEnabled())
79 m_isPreconnect = true;
80 } else if (equalIgnoringCase(linkType, "subresource")) {
81 m_isLinkSubresource = true;
82 } else if (equalIgnoringCase(linkType, "preload")) {
83 if (RuntimeEnabledFeatures::linkPreloadEnabled())
84 m_isLinkPreload = true;
85 } else if (equalIgnoringCase(linkType, "prerender")) {
86 m_isLinkPrerender = true;
87 } else if (equalIgnoringCase(linkType, "next")) {
88 m_isLinkNext = true;
89 } else if (equalIgnoringCase(linkType, "apple-touch-icon")) {
90 if (RuntimeEnabledFeatures::touchIconLoadingEnabled())
91 m_iconType = TouchIcon;
92 } else if (equalIgnoringCase(linkType, "apple-touch-icon-precomposed")) {
93 if (RuntimeEnabledFeatures::touchIconLoadingEnabled())
94 m_iconType = TouchPrecomposedIcon;
95 } else if (equalIgnoringCase(linkType, "manifest")) {
96 m_isManifest = true;