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#pragma once
32
33#include "ContentSecurityPolicyResponseHeaders.h"
34#include "FetchOptions.h"
35#include "HTTPHeaderNames.h"
36#include "ServiceWorkerTypes.h"
37#include "StoredCredentialsPolicy.h"
38#include <wtf/HashSet.h>
39#include <wtf/Vector.h>
40#include <wtf/text/WTFString.h>
41
42namespace WebCore {
43
44enum class SendCallbackPolicy : uint8_t {
45 SendCallbacks,
46 DoNotSendCallbacks
47};
48
49// FIXME: These options are named poorly. We only implement force disabling content sniffing, not enabling it,
50// and even that only on some platforms.
51enum class ContentSniffingPolicy : uint8_t {
52 SniffContent,
53 DoNotSniffContent
54};
55
56enum class DataBufferingPolicy : uint8_t {
57 BufferData,
58 DoNotBufferData
59};
60
61enum class SecurityCheckPolicy : uint8_t {
62 SkipSecurityCheck,
63 DoSecurityCheck
64};
65
66enum class CertificateInfoPolicy : uint8_t {
67 IncludeCertificateInfo,
68 DoNotIncludeCertificateInfo
69};
70
71enum class ContentSecurityPolicyImposition : uint8_t {
72 SkipPolicyCheck,
73 DoPolicyCheck
74};
75
76enum class DefersLoadingPolicy : uint8_t {
77 AllowDefersLoading,
78 DisallowDefersLoading
79};
80
81enum class CachingPolicy : uint8_t {
82 AllowCaching,
83 DisallowCaching
84};
85
86enum class ClientCredentialPolicy : uint8_t {
87 CannotAskClientForCredentials,
88 MayAskClientForCredentials
89};
90
91enum class SameOriginDataURLFlag : uint8_t {
92 Set,
93 Unset
94};
95
96enum class InitiatorContext : uint8_t {
97 Document,
98 Worker,
99};
100
101enum class ServiceWorkersMode : uint8_t {
102 All,
103 None,
104 Only // An error will happen if service worker is not handling the fetch. Used to bypass preflight safely.
105};
106
107enum class ApplicationCacheMode : uint8_t {
108 Use,
109 Bypass
110};
111
112// FIXME: These options are named poorly. We only implement force disabling content encoding sniffing, not enabling it,
113// and even that only on some platforms.
114enum class ContentEncodingSniffingPolicy : uint8_t {
115 Sniff,
116 DoNotSniff,
117};
118
119enum class PreflightPolicy : uint8_t {
120 Consider,
121 Force,
122 Prevent
123};
124
125enum class LoadedFromOpaqueSource : uint8_t {
126 Yes,
127 No
128};
129
130struct ResourceLoaderOptions : public FetchOptions {
131 ResourceLoaderOptions() { }
132
133 ResourceLoaderOptions(FetchOptions options) : FetchOptions { WTFMove(options) } { }
134
135 ResourceLoaderOptions(SendCallbackPolicy sendLoadCallbacks, ContentSniffingPolicy sniffContent, DataBufferingPolicy dataBufferingPolicy, StoredCredentialsPolicy storedCredentialsPolicy, ClientCredentialPolicy credentialPolicy, FetchOptions::Credentials credentials, SecurityCheckPolicy securityCheck, FetchOptions::Mode mode, CertificateInfoPolicy certificateInfoPolicy, ContentSecurityPolicyImposition contentSecurityPolicyImposition, DefersLoadingPolicy defersLoadingPolicy, CachingPolicy cachingPolicy)
136 : sendLoadCallbacks(sendLoadCallbacks)
137 , sniffContent(sniffContent)
138 , dataBufferingPolicy(dataBufferingPolicy)
139 , storedCredentialsPolicy(storedCredentialsPolicy)
140 , securityCheck(securityCheck)
141 , certificateInfoPolicy(certificateInfoPolicy)
142 , contentSecurityPolicyImposition(contentSecurityPolicyImposition)
143 , defersLoadingPolicy(defersLoadingPolicy)
144 , cachingPolicy(cachingPolicy)
145 , clientCredentialPolicy(credentialPolicy)
146 {
147 this->credentials = credentials;
148 this->mode = mode;
149 }
150
151#if ENABLE(SERVICE_WORKER)
152 Optional<ServiceWorkerRegistrationIdentifier> serviceWorkerRegistrationIdentifier;
153#endif
154 HashSet<HTTPHeaderName, WTF::IntHash<HTTPHeaderName>, WTF::StrongEnumHashTraits<HTTPHeaderName>> httpHeadersToKeep;
155 Optional<ContentSecurityPolicyResponseHeaders> cspResponseHeaders;
156 unsigned maxRedirectCount { 20 };
157
158 SendCallbackPolicy sendLoadCallbacks { SendCallbackPolicy::DoNotSendCallbacks };
159 ContentSniffingPolicy sniffContent { ContentSniffingPolicy::DoNotSniffContent };
160 ContentEncodingSniffingPolicy sniffContentEncoding { ContentEncodingSniffingPolicy::Sniff };
161 DataBufferingPolicy dataBufferingPolicy { DataBufferingPolicy::BufferData };
162 StoredCredentialsPolicy storedCredentialsPolicy { StoredCredentialsPolicy::DoNotUse };
163 SecurityCheckPolicy securityCheck { SecurityCheckPolicy::DoSecurityCheck };
164 CertificateInfoPolicy certificateInfoPolicy { CertificateInfoPolicy::DoNotIncludeCertificateInfo };
165 ContentSecurityPolicyImposition contentSecurityPolicyImposition { ContentSecurityPolicyImposition::DoPolicyCheck };
166 DefersLoadingPolicy defersLoadingPolicy { DefersLoadingPolicy::AllowDefersLoading };
167 CachingPolicy cachingPolicy { CachingPolicy::AllowCaching };
168 SameOriginDataURLFlag sameOriginDataURLFlag { SameOriginDataURLFlag::Unset };
169 InitiatorContext initiatorContext { InitiatorContext::Document };
170 ServiceWorkersMode serviceWorkersMode { ServiceWorkersMode::All };
171 ApplicationCacheMode applicationCacheMode { ApplicationCacheMode::Use };
172 ClientCredentialPolicy clientCredentialPolicy { ClientCredentialPolicy::CannotAskClientForCredentials };
173 PreflightPolicy preflightPolicy { PreflightPolicy::Consider };
174 LoadedFromOpaqueSource loadedFromOpaqueSource { LoadedFromOpaqueSource::No };
175};
176
177} // namespace WebCore
178