Requests handled by Service Worker should not go through preflighting
[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 "FetchOptions.h"
34 #include "ServiceWorkerIdentifier.h"
35 #include "StoredCredentialsPolicy.h"
36 #include <wtf/Vector.h>
37 #include <wtf/text/WTFString.h>
38
39 namespace WebCore {
40
41 enum SendCallbackPolicy {
42     SendCallbacks,
43     DoNotSendCallbacks
44 };
45
46 enum ContentSniffingPolicy {
47     SniffContent,
48     DoNotSniffContent
49 };
50
51 enum DataBufferingPolicy {
52     BufferData,
53     DoNotBufferData
54 };
55
56 enum SecurityCheckPolicy {
57     SkipSecurityCheck,
58     DoSecurityCheck
59 };
60
61 enum CertificateInfoPolicy {
62     IncludeCertificateInfo,
63     DoNotIncludeCertificateInfo
64 };
65
66 enum class ContentSecurityPolicyImposition : uint8_t {
67     SkipPolicyCheck,
68     DoPolicyCheck
69 };
70
71 enum class DefersLoadingPolicy : uint8_t {
72     AllowDefersLoading,
73     DisallowDefersLoading
74 };
75
76 enum class CachingPolicy : uint8_t {
77     AllowCaching,
78     DisallowCaching
79 };
80
81 enum class ClientCredentialPolicy {
82     CannotAskClientForCredentials,
83     MayAskClientForCredentials
84 };
85
86 enum class SameOriginDataURLFlag {
87     Set,
88     Unset
89 };
90
91 enum class InitiatorContext {
92     Document,
93     Worker,
94 };
95
96 enum class ServiceWorkersMode {
97     All,
98     None,
99     Only // An error will happen if service worker is not handling the fetch. Used to bypass preflight safely.
100 };
101
102 enum class ContentEncodingSniffingPolicy {
103     Sniff,
104     DoNotSniff,
105 };
106
107 struct ResourceLoaderOptions : public FetchOptions {
108     ResourceLoaderOptions() { }
109
110     ResourceLoaderOptions(const FetchOptions& options) : FetchOptions(options) { }
111
112     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)
113         : sendLoadCallbacks(sendLoadCallbacks)
114         , sniffContent(sniffContent)
115         , dataBufferingPolicy(dataBufferingPolicy)
116         , storedCredentialsPolicy(storedCredentialsPolicy)
117         , securityCheck(securityCheck)
118         , certificateInfoPolicy(certificateInfoPolicy)
119         , contentSecurityPolicyImposition(contentSecurityPolicyImposition)
120         , defersLoadingPolicy(defersLoadingPolicy)
121         , cachingPolicy(cachingPolicy)
122         , clientCredentialPolicy(credentialPolicy)
123     {
124         this->credentials = credentials;
125         this->mode = mode;
126     }
127
128     SendCallbackPolicy sendLoadCallbacks { DoNotSendCallbacks };
129     ContentSniffingPolicy sniffContent { DoNotSniffContent };
130     ContentEncodingSniffingPolicy sniffContentEncoding { ContentEncodingSniffingPolicy::Sniff };
131     DataBufferingPolicy dataBufferingPolicy { BufferData };
132     StoredCredentialsPolicy storedCredentialsPolicy { StoredCredentialsPolicy::DoNotUse };
133     SecurityCheckPolicy securityCheck { DoSecurityCheck };
134     CertificateInfoPolicy certificateInfoPolicy { DoNotIncludeCertificateInfo };
135     ContentSecurityPolicyImposition contentSecurityPolicyImposition { ContentSecurityPolicyImposition::DoPolicyCheck };
136     DefersLoadingPolicy defersLoadingPolicy { DefersLoadingPolicy::AllowDefersLoading };
137     CachingPolicy cachingPolicy { CachingPolicy::AllowCaching };
138     SameOriginDataURLFlag sameOriginDataURLFlag { SameOriginDataURLFlag::Unset };
139     InitiatorContext initiatorContext { InitiatorContext::Document };
140     ServiceWorkersMode serviceWorkersMode { ServiceWorkersMode::All };
141 #if ENABLE(SERVICE_WORKER)
142     std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier;
143 #endif
144
145     ClientCredentialPolicy clientCredentialPolicy { ClientCredentialPolicy::CannotAskClientForCredentials };
146     unsigned maxRedirectCount { 20 };
147
148     Vector<String> derivedCachedDataTypesToRetrieve;
149 };
150
151 } // namespace WebCore