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 "DecoderAdapter.h"
32 #include "EncoderAdapter.h"
33 #include "WebCoreArgumentCoders.h"
35 #if ENABLE(NETWORK_PROCESS)
37 using namespace WebCore;
40 NetworkResourceLoadParameters::NetworkResourceLoadParameters()
44 , priority(ResourceLoadPriorityVeryLow)
45 , contentSniffingPolicy(SniffContent)
46 , allowStoredCredentials(DoNotAllowStoredCredentials)
47 , inPrivateBrowsingMode(false)
48 , shouldClearReferrerOnHTTPSToHTTPRedirect(true)
49 , isMainResource(false)
53 void NetworkResourceLoadParameters::encode(CoreIPC::ArgumentEncoder& encoder) const
55 encoder << identifier;
57 encoder << webFrameID;
60 encoder << static_cast<bool>(request.httpBody());
61 if (request.httpBody()) {
62 EncoderAdapter httpBodyEncoderAdapter;
63 request.httpBody()->encode(httpBodyEncoderAdapter);
64 encoder << httpBodyEncoderAdapter.dataReference();
66 const Vector<FormDataElement>& elements = request.httpBody()->elements();
68 for (size_t i = 0, count = elements.size(); i < count; ++i) {
69 if (elements[i].m_type == FormDataElement::encodedFile)
73 SandboxExtension::HandleArray requestBodySandboxExtensions;
74 requestBodySandboxExtensions.allocate(fileCount);
75 size_t extensionIndex = 0;
76 for (size_t i = 0, count = elements.size(); i < count; ++i) {
77 const FormDataElement& element = elements[i];
78 if (element.m_type == FormDataElement::encodedFile) {
79 const String& path = element.m_shouldGenerateFile ? element.m_generatedFilename : element.m_filename;
80 SandboxExtension::createHandle(path, SandboxExtension::ReadOnly, requestBodySandboxExtensions[extensionIndex++]);
83 encoder << requestBodySandboxExtensions;
86 if (request.url().isLocalFile()) {
87 SandboxExtension::Handle requestSandboxExtension;
88 SandboxExtension::createHandle(request.url().fileSystemPath(), SandboxExtension::ReadOnly, requestSandboxExtension);
89 encoder << requestSandboxExtension;
92 encoder.encodeEnum(priority);
93 encoder.encodeEnum(contentSniffingPolicy);
94 encoder.encodeEnum(allowStoredCredentials);
95 encoder << inPrivateBrowsingMode;
96 encoder << shouldClearReferrerOnHTTPSToHTTPRedirect;
97 encoder << isMainResource;
100 bool NetworkResourceLoadParameters::decode(CoreIPC::ArgumentDecoder& decoder, NetworkResourceLoadParameters& result)
102 if (!decoder.decode(result.identifier))
105 if (!decoder.decode(result.webPageID))
108 if (!decoder.decode(result.webFrameID))
111 if (!decoder.decode(result.request))
115 if (!decoder.decode(hasHTTPBody))
119 CoreIPC::DataReference formData;
120 if (!decoder.decode(formData))
122 DecoderAdapter httpBodyDecoderAdapter(formData.data(), formData.size());
123 result.request.setHTTPBody(FormData::decode(httpBodyDecoderAdapter));
125 if (!decoder.decode(result.requestBodySandboxExtensions))
129 if (result.request.url().isLocalFile()) {
130 if (!decoder.decode(result.resourceSandboxExtension))
134 if (!decoder.decodeEnum(result.priority))
136 if (!decoder.decodeEnum(result.contentSniffingPolicy))
138 if (!decoder.decodeEnum(result.allowStoredCredentials))
140 if (!decoder.decode(result.inPrivateBrowsingMode))
142 if (!decoder.decode(result.shouldClearReferrerOnHTTPSToHTTPRedirect))
144 if (!decoder.decode(result.isMainResource))
150 } // namespace WebKit
152 #endif // ENABLE(NETWORK_PROCESS)