2 * Copyright (C) 2012 Apple 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
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.
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.
27 #include "NetworkResourceLoadParameters.h"
29 #include "ArgumentCoders.h"
30 #include "DataReference.h"
31 #include "WebCoreArgumentCoders.h"
32 #include <WebCore/SecurityOriginData.h>
34 using namespace WebCore;
38 void NetworkResourceLoadParameters::encode(IPC::Encoder& encoder) const
40 encoder << identifier;
42 encoder << webFrameID;
46 encoder << static_cast<bool>(request.httpBody());
47 if (request.httpBody()) {
48 request.httpBody()->encode(encoder);
50 const Vector<FormDataElement>& elements = request.httpBody()->elements();
52 for (size_t i = 0, count = elements.size(); i < count; ++i) {
53 if (elements[i].m_type == FormDataElement::Type::EncodedFile)
57 SandboxExtension::HandleArray requestBodySandboxExtensions;
58 requestBodySandboxExtensions.allocate(fileCount);
59 size_t extensionIndex = 0;
60 for (size_t i = 0, count = elements.size(); i < count; ++i) {
61 const FormDataElement& element = elements[i];
62 if (element.m_type == FormDataElement::Type::EncodedFile) {
63 const String& path = element.m_shouldGenerateFile ? element.m_generatedFilename : element.m_filename;
64 SandboxExtension::createHandle(path, SandboxExtension::ReadOnly, requestBodySandboxExtensions[extensionIndex++]);
67 encoder << requestBodySandboxExtensions;
70 if (request.url().isLocalFile()) {
71 SandboxExtension::Handle requestSandboxExtension;
72 SandboxExtension::createHandle(request.url().fileSystemPath(), SandboxExtension::ReadOnly, requestSandboxExtension);
73 encoder << requestSandboxExtension;
76 encoder.encodeEnum(contentSniffingPolicy);
77 encoder.encodeEnum(allowStoredCredentials);
78 encoder.encodeEnum(clientCredentialPolicy);
79 encoder << shouldFollowRedirects;
80 encoder << shouldClearReferrerOnHTTPSToHTTPRedirect;
81 encoder << defersLoading;
82 encoder << needsCertificateInfo;
83 encoder << maximumBufferingTime;
84 encoder << derivedCachedDataTypesToRetrieve;
86 encoder << static_cast<bool>(sourceOrigin);
88 encoder << SecurityOriginData::fromSecurityOrigin(*sourceOrigin);
89 encoder.encodeEnum(mode);
90 encoder << cspResponseHeaders;
93 bool NetworkResourceLoadParameters::decode(IPC::Decoder& decoder, NetworkResourceLoadParameters& result)
95 if (!decoder.decode(result.identifier))
98 if (!decoder.decode(result.webPageID))
101 if (!decoder.decode(result.webFrameID))
104 if (!decoder.decode(result.sessionID))
107 if (!decoder.decode(result.request))
111 if (!decoder.decode(hasHTTPBody))
115 RefPtr<FormData> formData = FormData::decode(decoder);
118 result.request.setHTTPBody(WTFMove(formData));
120 SandboxExtension::HandleArray requestBodySandboxExtensionHandles;
121 if (!decoder.decode(requestBodySandboxExtensionHandles))
123 for (size_t i = 0; i < requestBodySandboxExtensionHandles.size(); ++i) {
124 if (auto extension = SandboxExtension::create(requestBodySandboxExtensionHandles[i]))
125 result.requestBodySandboxExtensions.append(WTFMove(extension));
129 if (result.request.url().isLocalFile()) {
130 SandboxExtension::Handle resourceSandboxExtensionHandle;
131 if (!decoder.decode(resourceSandboxExtensionHandle))
133 result.resourceSandboxExtension = SandboxExtension::create(resourceSandboxExtensionHandle);
136 if (!decoder.decodeEnum(result.contentSniffingPolicy))
138 if (!decoder.decodeEnum(result.allowStoredCredentials))
140 if (!decoder.decodeEnum(result.clientCredentialPolicy))
142 if (!decoder.decode(result.shouldFollowRedirects))
144 if (!decoder.decode(result.shouldClearReferrerOnHTTPSToHTTPRedirect))
146 if (!decoder.decode(result.defersLoading))
148 if (!decoder.decode(result.needsCertificateInfo))
150 if (!decoder.decode(result.maximumBufferingTime))
152 if (!decoder.decode(result.derivedCachedDataTypesToRetrieve))
155 bool hasSourceOrigin;
156 if (!decoder.decode(hasSourceOrigin))
158 if (hasSourceOrigin) {
159 SecurityOriginData sourceOriginData;
160 if (!decoder.decode(sourceOriginData))
162 ASSERT(!sourceOriginData.isEmpty());
163 result.sourceOrigin = sourceOriginData.securityOrigin();
165 if (!decoder.decodeEnum(result.mode))
167 if (!decoder.decode(result.cspResponseHeaders))
173 } // namespace WebKit