1/*
2 * Copyright 2015 The Chromium Authors. All rights reserved.
3 * Copyright (C) 2016 Akamai Technologies Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include <wtf/text/WTFString.h>
30
31namespace WebCore {
32
33class LinkHeader {
34public:
35 template <typename CharacterType>
36 LinkHeader(CharacterType*& position, CharacterType* const end);
37
38 const String& url() const { return m_url; }
39 const String& rel() const { return m_rel; }
40 const String& as() const { return m_as; }
41 const String& mimeType() const { return m_mimeType; }
42 const String& media() const { return m_media; }
43 const String& crossOrigin() const { return m_crossOrigin; }
44 const String& imageSrcSet() const { return m_imageSrcSet; }
45 const String& imageSizes() const { return m_imageSizes; }
46 bool valid() const { return m_isValid; }
47 bool isViewportDependent() const { return !media().isEmpty() || !imageSrcSet().isEmpty() || !imageSizes().isEmpty(); }
48
49 enum LinkParameterName {
50 LinkParameterRel,
51 LinkParameterAnchor,
52 LinkParameterTitle,
53 LinkParameterMedia,
54 LinkParameterType,
55 LinkParameterRev,
56 LinkParameterHreflang,
57 // Beyond this point, only link-extension parameters
58 LinkParameterUnknown,
59 LinkParameterCrossOrigin,
60 LinkParameterAs,
61 LinkParameterImageSrcSet,
62 LinkParameterImageSizes,
63 };
64
65private:
66 void setValue(LinkParameterName, String&& value);
67
68 String m_url;
69 String m_rel;
70 String m_as;
71 String m_mimeType;
72 String m_media;
73 String m_crossOrigin;
74 String m_imageSrcSet;
75 String m_imageSizes;
76 bool m_isValid { true };
77};
78
79class LinkHeaderSet {
80public:
81 LinkHeaderSet(const String& header);
82
83 Vector<LinkHeader>::const_iterator begin() const { return m_headerSet.begin(); }
84 Vector<LinkHeader>::const_iterator end() const { return m_headerSet.end(); }
85
86private:
87 template <typename CharacterType>
88 void init(CharacterType* headerValue, size_t length);
89
90 Vector<LinkHeader> m_headerSet;
91};
92
93} // namespace WebCore
94
95