1 | /* |
2 | * Copyright (C) 2012 Apple 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 |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "NetworkResourceLoadParameters.h" |
28 | |
29 | #include "WebCoreArgumentCoders.h" |
30 | |
31 | namespace WebKit { |
32 | using namespace WebCore; |
33 | |
34 | void NetworkResourceLoadParameters::encode(IPC::Encoder& encoder) const |
35 | { |
36 | encoder << identifier; |
37 | encoder << webPageID; |
38 | encoder << webFrameID; |
39 | encoder << parentPID; |
40 | encoder << sessionID; |
41 | encoder << request; |
42 | |
43 | encoder << static_cast<bool>(request.httpBody()); |
44 | if (request.httpBody()) { |
45 | request.httpBody()->encode(encoder); |
46 | |
47 | const Vector<FormDataElement>& elements = request.httpBody()->elements(); |
48 | size_t fileCount = 0; |
49 | for (size_t i = 0, count = elements.size(); i < count; ++i) { |
50 | if (WTF::holds_alternative<FormDataElement::EncodedFileData>(elements[i].data)) |
51 | ++fileCount; |
52 | } |
53 | |
54 | SandboxExtension::HandleArray requestBodySandboxExtensions; |
55 | requestBodySandboxExtensions.allocate(fileCount); |
56 | size_t extensionIndex = 0; |
57 | for (size_t i = 0, count = elements.size(); i < count; ++i) { |
58 | const FormDataElement& element = elements[i]; |
59 | if (auto* fileData = WTF::get_if<FormDataElement::EncodedFileData>(element.data)) { |
60 | const String& path = fileData->shouldGenerateFile ? fileData->generatedFilename : fileData->filename; |
61 | SandboxExtension::createHandle(path, SandboxExtension::Type::ReadOnly, requestBodySandboxExtensions[extensionIndex++]); |
62 | } |
63 | } |
64 | encoder << requestBodySandboxExtensions; |
65 | } |
66 | |
67 | if (request.url().isLocalFile()) { |
68 | SandboxExtension::Handle requestSandboxExtension; |
69 | SandboxExtension::createHandle(request.url().fileSystemPath(), SandboxExtension::Type::ReadOnly, requestSandboxExtension); |
70 | encoder << requestSandboxExtension; |
71 | } |
72 | |
73 | encoder.encodeEnum(contentSniffingPolicy); |
74 | encoder.encodeEnum(contentEncodingSniffingPolicy); |
75 | encoder.encodeEnum(storedCredentialsPolicy); |
76 | encoder.encodeEnum(clientCredentialPolicy); |
77 | encoder.encodeEnum(shouldPreconnectOnly); |
78 | encoder << shouldClearReferrerOnHTTPSToHTTPRedirect; |
79 | encoder << needsCertificateInfo; |
80 | encoder << isMainFrameNavigation; |
81 | encoder << maximumBufferingTime; |
82 | |
83 | encoder << static_cast<bool>(sourceOrigin); |
84 | if (sourceOrigin) |
85 | encoder << *sourceOrigin; |
86 | encoder << options; |
87 | encoder << cspResponseHeaders; |
88 | encoder << originalRequestHeaders; |
89 | |
90 | encoder << shouldRestrictHTTPResponseAccess; |
91 | |
92 | encoder.encodeEnum(preflightPolicy); |
93 | |
94 | encoder << shouldEnableCrossOriginResourcePolicy; |
95 | |
96 | encoder << frameAncestorOrigins; |
97 | encoder << isHTTPSUpgradeEnabled; |
98 | |
99 | #if ENABLE(CONTENT_EXTENSIONS) |
100 | encoder << mainDocumentURL; |
101 | encoder << userContentControllerIdentifier; |
102 | #endif |
103 | } |
104 | |
105 | bool NetworkResourceLoadParameters::decode(IPC::Decoder& decoder, NetworkResourceLoadParameters& result) |
106 | { |
107 | if (!decoder.decode(result.identifier)) |
108 | return false; |
109 | |
110 | if (!decoder.decode(result.webPageID)) |
111 | return false; |
112 | |
113 | if (!decoder.decode(result.webFrameID)) |
114 | return false; |
115 | |
116 | if (!decoder.decode(result.parentPID)) |
117 | return false; |
118 | |
119 | if (!decoder.decode(result.sessionID)) |
120 | return false; |
121 | |
122 | if (!decoder.decode(result.request)) |
123 | return false; |
124 | |
125 | bool hasHTTPBody; |
126 | if (!decoder.decode(hasHTTPBody)) |
127 | return false; |
128 | |
129 | if (hasHTTPBody) { |
130 | RefPtr<FormData> formData = FormData::decode(decoder); |
131 | if (!formData) |
132 | return false; |
133 | result.request.setHTTPBody(WTFMove(formData)); |
134 | |
135 | Optional<SandboxExtension::HandleArray> requestBodySandboxExtensionHandles; |
136 | decoder >> requestBodySandboxExtensionHandles; |
137 | if (!requestBodySandboxExtensionHandles) |
138 | return false; |
139 | for (size_t i = 0; i < requestBodySandboxExtensionHandles->size(); ++i) { |
140 | if (auto extension = SandboxExtension::create(WTFMove(requestBodySandboxExtensionHandles->at(i)))) |
141 | result.requestBodySandboxExtensions.append(WTFMove(extension)); |
142 | } |
143 | } |
144 | |
145 | if (result.request.url().isLocalFile()) { |
146 | Optional<SandboxExtension::Handle> resourceSandboxExtensionHandle; |
147 | decoder >> resourceSandboxExtensionHandle; |
148 | if (!resourceSandboxExtensionHandle) |
149 | return false; |
150 | result.resourceSandboxExtension = SandboxExtension::create(WTFMove(*resourceSandboxExtensionHandle)); |
151 | } |
152 | |
153 | if (!decoder.decodeEnum(result.contentSniffingPolicy)) |
154 | return false; |
155 | if (!decoder.decodeEnum(result.contentEncodingSniffingPolicy)) |
156 | return false; |
157 | if (!decoder.decodeEnum(result.storedCredentialsPolicy)) |
158 | return false; |
159 | if (!decoder.decodeEnum(result.clientCredentialPolicy)) |
160 | return false; |
161 | if (!decoder.decodeEnum(result.shouldPreconnectOnly)) |
162 | return false; |
163 | if (!decoder.decode(result.shouldClearReferrerOnHTTPSToHTTPRedirect)) |
164 | return false; |
165 | if (!decoder.decode(result.needsCertificateInfo)) |
166 | return false; |
167 | if (!decoder.decode(result.isMainFrameNavigation)) |
168 | return false; |
169 | if (!decoder.decode(result.maximumBufferingTime)) |
170 | return false; |
171 | |
172 | bool hasSourceOrigin; |
173 | if (!decoder.decode(hasSourceOrigin)) |
174 | return false; |
175 | if (hasSourceOrigin) { |
176 | result.sourceOrigin = SecurityOrigin::decode(decoder); |
177 | if (!result.sourceOrigin) |
178 | return false; |
179 | } |
180 | |
181 | Optional<FetchOptions> options; |
182 | decoder >> options; |
183 | if (!options) |
184 | return false; |
185 | result.options = *options; |
186 | |
187 | if (!decoder.decode(result.cspResponseHeaders)) |
188 | return false; |
189 | if (!decoder.decode(result.originalRequestHeaders)) |
190 | return false; |
191 | |
192 | Optional<bool> shouldRestrictHTTPResponseAccess; |
193 | decoder >> shouldRestrictHTTPResponseAccess; |
194 | if (!shouldRestrictHTTPResponseAccess) |
195 | return false; |
196 | result.shouldRestrictHTTPResponseAccess = *shouldRestrictHTTPResponseAccess; |
197 | |
198 | if (!decoder.decodeEnum(result.preflightPolicy)) |
199 | return false; |
200 | |
201 | Optional<bool> shouldEnableCrossOriginResourcePolicy; |
202 | decoder >> shouldEnableCrossOriginResourcePolicy; |
203 | if (!shouldEnableCrossOriginResourcePolicy) |
204 | return false; |
205 | result.shouldEnableCrossOriginResourcePolicy = *shouldEnableCrossOriginResourcePolicy; |
206 | |
207 | if (!decoder.decode(result.frameAncestorOrigins)) |
208 | return false; |
209 | |
210 | Optional<bool> isHTTPSUpgradeEnabled; |
211 | decoder >> isHTTPSUpgradeEnabled; |
212 | if (!isHTTPSUpgradeEnabled) |
213 | return false; |
214 | result.isHTTPSUpgradeEnabled = *isHTTPSUpgradeEnabled; |
215 | |
216 | #if ENABLE(CONTENT_EXTENSIONS) |
217 | if (!decoder.decode(result.mainDocumentURL)) |
218 | return false; |
219 | |
220 | Optional<Optional<UserContentControllerIdentifier>> userContentControllerIdentifier; |
221 | decoder >> userContentControllerIdentifier; |
222 | if (!userContentControllerIdentifier) |
223 | return false; |
224 | result.userContentControllerIdentifier = *userContentControllerIdentifier; |
225 | #endif |
226 | |
227 | return true; |
228 | } |
229 | |
230 | } // namespace WebKit |
231 | |