7be5f983a59bb000b6be5beaf710b396265469c0
[WebKit-https.git] / Source / WebCore / loader / ResourceLoaderOptions.h
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
42 namespace WebCore {
43
44 enum SendCallbackPolicy {
45     SendCallbacks,
46     DoNotSendCallbacks
47 };
48
49 enum ContentSniffingPolicy {
50     SniffContent,
51     DoNotSniffContent
52 };
53
54 enum DataBufferingPolicy {
55     BufferData,
56     DoNotBufferData
57 };
58
59 enum SecurityCheckPolicy {
60     SkipSecurityCheck,
61     DoSecurityCheck
62 };
63
64 enum CertificateInfoPolicy {
65     IncludeCertificateInfo,
66     DoNotIncludeCertificateInfo
67 };
68
69 enum class ContentSecurityPolicyImposition : uint8_t {
70     SkipPolicyCheck,
71     DoPolicyCheck
72 };
73
74 enum class DefersLoadingPolicy : uint8_t {
75     AllowDefersLoading,
76     DisallowDefersLoading
77 };
78
79 enum class CachingPolicy : uint8_t {
80     AllowCaching,
81     DisallowCaching
82 };
83
84 enum class ClientCredentialPolicy {
85     CannotAskClientForCredentials,
86     MayAskClientForCredentials
87 };
88
89 enum class SameOriginDataURLFlag {
90     Set,
91     Unset
92 };
93
94 enum class InitiatorContext {
95     Document,
96     Worker,
97 };
98
99 enum class ServiceWorkersMode {
100     All,
101     None,
102     Only // An error will happen if service worker is not handling the fetch. Used to bypass preflight safely.
103 };
104
105 enum class ApplicationCacheMode {
106     Use,
107     Bypass
108 };
109
110 enum class ContentEncodingSniffingPolicy {
111     Sniff,
112     DoNotSniff,
113 };
114
115 enum class PreflightPolicy {
116     Consider,
117     Force,
118     Prevent
119 };
120
121 struct ResourceLoaderOptions : public FetchOptions {
122     ResourceLoaderOptions() { }
123
124     ResourceLoaderOptions(FetchOptions options) : FetchOptions { WTFMove(options) } { }
125
126     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)
127         : sendLoadCallbacks(sendLoadCallbacks)
128         , sniffContent(sniffContent)
129         , dataBufferingPolicy(dataBufferingPolicy)
130         , storedCredentialsPolicy(storedCredentialsPolicy)
131         , securityCheck(securityCheck)
132         , certificateInfoPolicy(certificateInfoPolicy)
133         , contentSecurityPolicyImposition(contentSecurityPolicyImposition)
134         , defersLoadingPolicy(defersLoadingPolicy)
135         , cachingPolicy(cachingPolicy)
136         , clientCredentialPolicy(credentialPolicy)
137     {
138         this->credentials = credentials;
139         this->mode = mode;
140     }
141
142     SendCallbackPolicy sendLoadCallbacks { DoNotSendCallbacks };
143     ContentSniffingPolicy sniffContent { DoNotSniffContent };
144     ContentEncodingSniffingPolicy sniffContentEncoding { ContentEncodingSniffingPolicy::Sniff };
145     DataBufferingPolicy dataBufferingPolicy { BufferData };
146     StoredCredentialsPolicy storedCredentialsPolicy { StoredCredentialsPolicy::DoNotUse };
147     SecurityCheckPolicy securityCheck { DoSecurityCheck };
148     CertificateInfoPolicy certificateInfoPolicy { DoNotIncludeCertificateInfo };
149     ContentSecurityPolicyImposition contentSecurityPolicyImposition { ContentSecurityPolicyImposition::DoPolicyCheck };
150     DefersLoadingPolicy defersLoadingPolicy { DefersLoadingPolicy::AllowDefersLoading };
151     CachingPolicy cachingPolicy { CachingPolicy::AllowCaching };
152     SameOriginDataURLFlag sameOriginDataURLFlag { SameOriginDataURLFlag::Unset };
153     InitiatorContext initiatorContext { InitiatorContext::Document };
154     ServiceWorkersMode serviceWorkersMode { ServiceWorkersMode::All };
155     ApplicationCacheMode applicationCacheMode { ApplicationCacheMode::Use };
156 #if ENABLE(SERVICE_WORKER)
157     std::optional<ServiceWorkerRegistrationIdentifier> serviceWorkerRegistrationIdentifier;
158 #endif
159     HashSet<HTTPHeaderName, WTF::IntHash<HTTPHeaderName>, WTF::StrongEnumHashTraits<HTTPHeaderName>> httpHeadersToKeep;
160
161     ClientCredentialPolicy clientCredentialPolicy { ClientCredentialPolicy::CannotAskClientForCredentials };
162     unsigned maxRedirectCount { 20 };
163
164     Vector<String> derivedCachedDataTypesToRetrieve;
165
166     PreflightPolicy preflightPolicy { PreflightPolicy::Consider };
167     std::optional<ContentSecurityPolicyResponseHeaders> cspResponseHeaders;
168 };
169
170 } // namespace WebCore