Enable Session API.
[WebKit-https.git] / Source / WebKit2 / Shared / Network / NetworkResourceLoadParameters.cpp
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 "ArgumentCoders.h"
30 #include "DataReference.h"
31 #include "DecoderAdapter.h"
32 #include "EncoderAdapter.h"
33 #include "WebCoreArgumentCoders.h"
34
35 #if ENABLE(NETWORK_PROCESS)
36
37 using namespace WebCore;
38
39 namespace WebKit {
40 NetworkResourceLoadParameters::NetworkResourceLoadParameters()
41     : identifier(0)
42     , webPageID(0)
43     , webFrameID(0)
44     , sessionID(0)
45     , priority(ResourceLoadPriorityVeryLow)
46     , contentSniffingPolicy(SniffContent)
47     , allowStoredCredentials(DoNotAllowStoredCredentials)
48     , clientCredentialPolicy(DoNotAskClientForAnyCredentials)
49     , shouldClearReferrerOnHTTPSToHTTPRedirect(true)
50     , isMainResource(false)
51 {
52 }
53
54 void NetworkResourceLoadParameters::encode(IPC::ArgumentEncoder& encoder) const
55 {
56     encoder << identifier;
57     encoder << webPageID;
58     encoder << webFrameID;
59     encoder << sessionID;
60     encoder << request;
61
62     encoder << static_cast<bool>(request.httpBody());
63     if (request.httpBody()) {
64         EncoderAdapter httpBodyEncoderAdapter;
65         request.httpBody()->encode(httpBodyEncoderAdapter);
66         encoder << httpBodyEncoderAdapter.dataReference();
67
68         const Vector<FormDataElement>& elements = request.httpBody()->elements();
69         size_t fileCount = 0;
70         for (size_t i = 0, count = elements.size(); i < count; ++i) {
71             if (elements[i].m_type == FormDataElement::encodedFile)
72                 ++fileCount;
73         }
74
75         SandboxExtension::HandleArray requestBodySandboxExtensions;
76         requestBodySandboxExtensions.allocate(fileCount);
77         size_t extensionIndex = 0;
78         for (size_t i = 0, count = elements.size(); i < count; ++i) {
79             const FormDataElement& element = elements[i];
80             if (element.m_type == FormDataElement::encodedFile) {
81                 const String& path = element.m_shouldGenerateFile ? element.m_generatedFilename : element.m_filename;
82                 SandboxExtension::createHandle(path, SandboxExtension::ReadOnly, requestBodySandboxExtensions[extensionIndex++]);
83             }
84         }
85         encoder << requestBodySandboxExtensions;
86     }
87
88     if (request.url().isLocalFile()) {
89         SandboxExtension::Handle requestSandboxExtension;
90         SandboxExtension::createHandle(request.url().fileSystemPath(), SandboxExtension::ReadOnly, requestSandboxExtension);
91         encoder << requestSandboxExtension;
92     }
93
94     encoder.encodeEnum(priority);
95     encoder.encodeEnum(contentSniffingPolicy);
96     encoder.encodeEnum(allowStoredCredentials);
97     encoder.encodeEnum(clientCredentialPolicy);
98     encoder << shouldClearReferrerOnHTTPSToHTTPRedirect;
99     encoder << isMainResource;
100 }
101
102 bool NetworkResourceLoadParameters::decode(IPC::ArgumentDecoder& decoder, NetworkResourceLoadParameters& result)
103 {
104     if (!decoder.decode(result.identifier))
105         return false;
106
107     if (!decoder.decode(result.webPageID))
108         return false;
109
110     if (!decoder.decode(result.webFrameID))
111         return false;
112
113     if (!decoder.decode(result.sessionID))
114         return false;
115
116     if (!decoder.decode(result.request))
117         return false;
118
119     bool hasHTTPBody;
120     if (!decoder.decode(hasHTTPBody))
121         return false;
122
123     if (hasHTTPBody) {
124         IPC::DataReference formData;
125         if (!decoder.decode(formData))
126             return false;
127         DecoderAdapter httpBodyDecoderAdapter(formData.data(), formData.size());
128         result.request.setHTTPBody(FormData::decode(httpBodyDecoderAdapter));
129
130         if (!decoder.decode(result.requestBodySandboxExtensions))
131             return false;
132     }
133
134     if (result.request.url().isLocalFile()) {
135         if (!decoder.decode(result.resourceSandboxExtension))
136             return false;
137     }
138
139     if (!decoder.decodeEnum(result.priority))
140         return false;
141     if (!decoder.decodeEnum(result.contentSniffingPolicy))
142         return false;
143     if (!decoder.decodeEnum(result.allowStoredCredentials))
144         return false;
145     if (!decoder.decodeEnum(result.clientCredentialPolicy))
146         return false;
147     if (!decoder.decode(result.shouldClearReferrerOnHTTPSToHTTPRedirect))
148         return false;
149     if (!decoder.decode(result.isMainResource))
150         return false;
151
152     return true;
153 }
154     
155 } // namespace WebKit
156
157 #endif // ENABLE(NETWORK_PROCESS)