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