Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / core / fetch / ResourceLoaderOptions.h
blob53a78bf621efc63ab9d92281ce7844fb58ec10d9
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
31 #ifndef ResourceLoaderOptions_h
32 #define ResourceLoaderOptions_h
34 #include "core/fetch/FetchInitiatorInfo.h"
35 #include "platform/CrossThreadCopier.h"
36 #include "platform/weborigin/SecurityOrigin.h"
37 #include "wtf/Allocator.h"
39 namespace blink {
41 enum DataBufferingPolicy {
42 BufferData,
43 DoNotBufferData
46 enum ContentSecurityPolicyDisposition {
47 CheckContentSecurityPolicy,
48 DoNotCheckContentSecurityPolicy
51 enum RequestInitiatorContext {
52 DocumentContext,
53 WorkerContext,
56 enum StoredCredentials {
57 AllowStoredCredentials,
58 DoNotAllowStoredCredentials
61 // APIs like XMLHttpRequest and EventSource let the user decide
62 // whether to send credentials, but they're always sent for
63 // same-origin requests. Additional information is needed to handle
64 // cross-origin redirects correctly.
65 enum CredentialRequest {
66 ClientRequestedCredentials,
67 ClientDidNotRequestCredentials
70 enum SynchronousPolicy {
71 RequestSynchronously,
72 RequestAsynchronously
75 // A resource fetch can be marked as being CORS enabled. The loader
76 // must perform an access check upon seeing the response.
77 enum CORSEnabled {
78 NotCORSEnabled,
79 IsCORSEnabled
82 struct ResourceLoaderOptions {
83 WTF_MAKE_FAST_ALLOCATED(ResourceLoaderOptions);
84 public:
85 ResourceLoaderOptions()
86 : dataBufferingPolicy(BufferData)
87 , allowCredentials(DoNotAllowStoredCredentials)
88 , credentialsRequested(ClientDidNotRequestCredentials)
89 , contentSecurityPolicyOption(CheckContentSecurityPolicy)
90 , requestInitiatorContext(DocumentContext)
91 , synchronousPolicy(RequestAsynchronously)
92 , corsEnabled(NotCORSEnabled)
96 ResourceLoaderOptions(
97 DataBufferingPolicy dataBufferingPolicy,
98 StoredCredentials allowCredentials,
99 CredentialRequest credentialsRequested,
100 ContentSecurityPolicyDisposition contentSecurityPolicyOption,
101 RequestInitiatorContext requestInitiatorContext)
102 : dataBufferingPolicy(dataBufferingPolicy)
103 , allowCredentials(allowCredentials)
104 , credentialsRequested(credentialsRequested)
105 , contentSecurityPolicyOption(contentSecurityPolicyOption)
106 , requestInitiatorContext(requestInitiatorContext)
107 , synchronousPolicy(RequestAsynchronously)
108 , corsEnabled(NotCORSEnabled)
112 // Answers the question "can a separate request with these
113 // different options be re-used" (e.g. preload request)
114 // The safe (but possibly slow) answer is always false.
115 bool canReuseRequest(const ResourceLoaderOptions& other) const
117 // dataBufferingPolicy differences are believed to be safe for re-use.
118 // FIXME: check allowCredentials.
119 // FIXME: check credentialsRequested.
120 // FIXME: check contentSecurityPolicyOption.
121 // initiatorInfo is purely informational and should be benign for re-use.
122 // requestInitiatorContext is benign (indicates document vs. worker)
123 // synchronousPolicy (safe to re-use an async XHR response for sync, etc.)
124 return corsEnabled == other.corsEnabled;
125 // securityOrigin has more complicated checks which callers are responsible for.
128 // When adding members, CrossThreadResourceLoaderOptionsData should be
129 // updated.
130 DataBufferingPolicy dataBufferingPolicy;
131 StoredCredentials allowCredentials; // Whether HTTP credentials and cookies are sent with the request.
132 CredentialRequest credentialsRequested; // Whether the client (e.g. XHR) wanted credentials in the first place.
133 ContentSecurityPolicyDisposition contentSecurityPolicyOption;
134 FetchInitiatorInfo initiatorInfo;
135 RequestInitiatorContext requestInitiatorContext;
136 SynchronousPolicy synchronousPolicy;
137 CORSEnabled corsEnabled; // If the resource is loaded out-of-origin, whether or not to use CORS.
138 RefPtr<SecurityOrigin> securityOrigin;
141 // Encode AtomicString (in FetchInitiatorInfo) as String to cross threads.
142 struct CrossThreadResourceLoaderOptionsData {
143 DISALLOW_ALLOCATION();
144 explicit CrossThreadResourceLoaderOptionsData(const ResourceLoaderOptions& options)
145 : dataBufferingPolicy(options.dataBufferingPolicy)
146 , allowCredentials(options.allowCredentials)
147 , credentialsRequested(options.credentialsRequested)
148 , contentSecurityPolicyOption(options.contentSecurityPolicyOption)
149 , initiatorInfo(options.initiatorInfo)
150 , requestInitiatorContext(options.requestInitiatorContext)
151 , synchronousPolicy(options.synchronousPolicy)
152 , corsEnabled(options.corsEnabled)
153 , securityOrigin(options.securityOrigin ? options.securityOrigin->isolatedCopy() : nullptr) { }
155 operator ResourceLoaderOptions() const
157 ResourceLoaderOptions options;
158 options.dataBufferingPolicy = dataBufferingPolicy;
159 options.allowCredentials = allowCredentials;
160 options.credentialsRequested = credentialsRequested;
161 options.contentSecurityPolicyOption = contentSecurityPolicyOption;
162 options.initiatorInfo = initiatorInfo;
163 options.requestInitiatorContext = requestInitiatorContext;
164 options.synchronousPolicy = synchronousPolicy;
165 options.corsEnabled = corsEnabled;
166 options.securityOrigin = securityOrigin;
167 return options;
170 DataBufferingPolicy dataBufferingPolicy;
171 StoredCredentials allowCredentials;
172 CredentialRequest credentialsRequested;
173 ContentSecurityPolicyDisposition contentSecurityPolicyOption;
174 CrossThreadFetchInitiatorInfoData initiatorInfo;
175 RequestInitiatorContext requestInitiatorContext;
176 SynchronousPolicy synchronousPolicy;
177 CORSEnabled corsEnabled;
178 RefPtr<SecurityOrigin> securityOrigin;
181 template<> struct CrossThreadCopierBase<false, false, false, ResourceLoaderOptions> {
182 typedef CrossThreadResourceLoaderOptionsData Type;
183 static Type copy(const ResourceLoaderOptions& options)
185 return CrossThreadResourceLoaderOptionsData(options);
189 } // namespace blink
191 #endif // ResourceLoaderOptions_h