3d83cd236ba9dcf6f4fc4e177a9d51486a9a61a4
[WebKit-https.git] / Source / WebKit / NetworkProcess / NetworkSessionCreationParameters.cpp
1 /*
2  * Copyright (C) 2018-2020 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 "NetworkSessionCreationParameters.h"
28
29 #include "ArgumentCoders.h"
30
31 #if PLATFORM(COCOA)
32 #include "ArgumentCodersCF.h"
33 #endif
34
35 #if USE(CURL)
36 #include "WebCoreArgumentCoders.h"
37 #endif
38
39 namespace WebKit {
40
41 void NetworkSessionCreationParameters::encode(IPC::Encoder& encoder) const
42 {
43     encoder << sessionID;
44     encoder << boundInterfaceIdentifier;
45     encoder << allowsCellularAccess;
46 #if PLATFORM(COCOA)
47     IPC::encode(encoder, proxyConfiguration.get());
48     encoder << sourceApplicationBundleIdentifier;
49     encoder << sourceApplicationSecondaryIdentifier;
50     encoder << shouldLogCookieInformation;
51     encoder << loadThrottleLatency;
52     encoder << httpProxy;
53     encoder << httpsProxy;
54 #endif
55 #if HAVE(CFNETWORK_ALTERNATIVE_SERVICE)
56     encoder << alternativeServiceDirectory;
57     encoder << alternativeServiceDirectoryExtensionHandle;
58     encoder << http3Enabled;
59 #endif
60 #if USE(SOUP)
61     encoder << cookiePersistentStoragePath;
62     encoder << cookiePersistentStorageType;
63     encoder << persistentCredentialStorageEnabled;
64 #endif
65 #if USE(CURL)
66     encoder << cookiePersistentStorageFile;
67     encoder << proxySettings;
68 #endif
69     encoder << networkCacheDirectory << networkCacheDirectoryExtensionHandle;
70
71     encoder << deviceManagementRestrictionsEnabled;
72     encoder << allLoadsBlockedByDeviceManagementRestrictionsForTesting;
73     encoder << dataConnectionServiceType;
74     encoder << fastServerTrustEvaluationEnabled;
75     encoder << networkCacheSpeculativeValidationEnabled;
76     encoder << shouldUseTestingNetworkSession;
77     encoder << staleWhileRevalidateEnabled;
78     encoder << testSpeedMultiplier;
79     encoder << suppressesConnectionTerminationOnSystemChange;
80     encoder << allowsServerPreconnect;
81     encoder << requiresSecureHTTPSProxyConnection;
82     encoder << preventsSystemHTTPProxyAuthentication;
83     encoder << resourceLoadStatisticsParameters;
84 }
85
86 Optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters::decode(IPC::Decoder& decoder)
87 {
88     Optional<PAL::SessionID> sessionID;
89     decoder >> sessionID;
90     if (!sessionID)
91         return WTF::nullopt;
92     
93     Optional<String> boundInterfaceIdentifier;
94     decoder >> boundInterfaceIdentifier;
95     if (!boundInterfaceIdentifier)
96         return WTF::nullopt;
97     
98     Optional<AllowsCellularAccess> allowsCellularAccess;
99     decoder >> allowsCellularAccess;
100     if (!allowsCellularAccess)
101         return WTF::nullopt;
102     
103 #if PLATFORM(COCOA)
104     RetainPtr<CFDictionaryRef> proxyConfiguration;
105     if (!IPC::decode(decoder, proxyConfiguration))
106         return WTF::nullopt;
107     
108     Optional<String> sourceApplicationBundleIdentifier;
109     decoder >> sourceApplicationBundleIdentifier;
110     if (!sourceApplicationBundleIdentifier)
111         return WTF::nullopt;
112     
113     Optional<String> sourceApplicationSecondaryIdentifier;
114     decoder >> sourceApplicationSecondaryIdentifier;
115     if (!sourceApplicationSecondaryIdentifier)
116         return WTF::nullopt;
117
118     Optional<bool> shouldLogCookieInformation;
119     decoder >> shouldLogCookieInformation;
120     if (!shouldLogCookieInformation)
121         return WTF::nullopt;
122     
123     Optional<Seconds> loadThrottleLatency;
124     decoder >> loadThrottleLatency;
125     if (!loadThrottleLatency)
126         return WTF::nullopt;
127     
128     Optional<URL> httpProxy;
129     decoder >> httpProxy;
130     if (!httpProxy)
131         return WTF::nullopt;
132
133     Optional<URL> httpsProxy;
134     decoder >> httpsProxy;
135     if (!httpsProxy)
136         return WTF::nullopt;
137 #endif
138
139 #if HAVE(CFNETWORK_ALTERNATIVE_SERVICE)
140     Optional<String> alternativeServiceDirectory;
141     decoder >> alternativeServiceDirectory;
142     if (!alternativeServiceDirectory)
143         return WTF::nullopt;
144
145     Optional<SandboxExtension::Handle> alternativeServiceDirectoryExtensionHandle;
146     decoder >> alternativeServiceDirectoryExtensionHandle;
147     if (!alternativeServiceDirectoryExtensionHandle)
148         return WTF::nullopt;
149     
150     Optional<bool> http3Enabled;
151     decoder >> http3Enabled;
152     if (!http3Enabled)
153         return WTF::nullopt;
154 #endif
155
156 #if USE(SOUP)
157     Optional<String> cookiePersistentStoragePath;
158     decoder >> cookiePersistentStoragePath;
159     if (!cookiePersistentStoragePath)
160         return WTF::nullopt;
161
162     Optional<SoupCookiePersistentStorageType> cookiePersistentStorageType;
163     decoder >> cookiePersistentStorageType;
164     if (!cookiePersistentStorageType)
165         return WTF::nullopt;
166
167     Optional<bool> persistentCredentialStorageEnabled;
168     decoder >> persistentCredentialStorageEnabled;
169     if (!persistentCredentialStorageEnabled)
170         return WTF::nullopt;
171 #endif
172
173 #if USE(CURL)
174     Optional<String> cookiePersistentStorageFile;
175     decoder >> cookiePersistentStorageFile;
176     if (!cookiePersistentStorageFile)
177         return WTF::nullopt;
178
179     Optional<WebCore::CurlProxySettings> proxySettings;
180     decoder >> proxySettings;
181     if (!proxySettings)
182         return WTF::nullopt;
183 #endif
184
185     Optional<String> networkCacheDirectory;
186     decoder >> networkCacheDirectory;
187     if (!networkCacheDirectory)
188         return WTF::nullopt;
189     
190     Optional<SandboxExtension::Handle> networkCacheDirectoryExtensionHandle;
191     decoder >> networkCacheDirectoryExtensionHandle;
192     if (!networkCacheDirectoryExtensionHandle)
193         return WTF::nullopt;
194
195     Optional<bool> deviceManagementRestrictionsEnabled;
196     decoder >> deviceManagementRestrictionsEnabled;
197     if (!deviceManagementRestrictionsEnabled)
198         return WTF::nullopt;
199
200     Optional<bool> allLoadsBlockedByDeviceManagementRestrictionsForTesting;
201     decoder >> allLoadsBlockedByDeviceManagementRestrictionsForTesting;
202     if (!allLoadsBlockedByDeviceManagementRestrictionsForTesting)
203         return WTF::nullopt;
204
205     Optional<String> dataConnectionServiceType;
206     decoder >> dataConnectionServiceType;
207     if (!dataConnectionServiceType)
208         return WTF::nullopt;
209     
210     Optional<bool> fastServerTrustEvaluationEnabled;
211     decoder >> fastServerTrustEvaluationEnabled;
212     if (!fastServerTrustEvaluationEnabled)
213         return WTF::nullopt;
214     
215     Optional<bool> networkCacheSpeculativeValidationEnabled;
216     decoder >> networkCacheSpeculativeValidationEnabled;
217     if (!networkCacheSpeculativeValidationEnabled)
218         return WTF::nullopt;
219     
220     Optional<bool> shouldUseTestingNetworkSession;
221     decoder >> shouldUseTestingNetworkSession;
222     if (!shouldUseTestingNetworkSession)
223         return WTF::nullopt;
224
225     Optional<bool> staleWhileRevalidateEnabled;
226     decoder >> staleWhileRevalidateEnabled;
227     if (!staleWhileRevalidateEnabled)
228         return WTF::nullopt;
229
230     Optional<unsigned> testSpeedMultiplier;
231     decoder >> testSpeedMultiplier;
232     if (!testSpeedMultiplier)
233         return WTF::nullopt;
234     
235     Optional<bool> suppressesConnectionTerminationOnSystemChange;
236     decoder >> suppressesConnectionTerminationOnSystemChange;
237     if (!suppressesConnectionTerminationOnSystemChange)
238         return WTF::nullopt;
239
240     Optional<bool> allowsServerPreconnect;
241     decoder >> allowsServerPreconnect;
242     if (!allowsServerPreconnect)
243         return WTF::nullopt;
244
245     Optional<bool> requiresSecureHTTPSProxyConnection;
246     decoder >> requiresSecureHTTPSProxyConnection;
247     if (!requiresSecureHTTPSProxyConnection)
248         return WTF::nullopt;
249     
250     Optional<bool> preventsSystemHTTPProxyAuthentication;
251     decoder >> preventsSystemHTTPProxyAuthentication;
252     if (!preventsSystemHTTPProxyAuthentication)
253         return WTF::nullopt;
254
255     Optional<ResourceLoadStatisticsParameters> resourceLoadStatisticsParameters;
256     decoder >> resourceLoadStatisticsParameters;
257     if (!resourceLoadStatisticsParameters)
258         return WTF::nullopt;
259     
260     return {{
261         *sessionID
262         , WTFMove(*boundInterfaceIdentifier)
263         , WTFMove(*allowsCellularAccess)
264 #if PLATFORM(COCOA)
265         , WTFMove(proxyConfiguration)
266         , WTFMove(*sourceApplicationBundleIdentifier)
267         , WTFMove(*sourceApplicationSecondaryIdentifier)
268         , WTFMove(*shouldLogCookieInformation)
269         , WTFMove(*loadThrottleLatency)
270         , WTFMove(*httpProxy)
271         , WTFMove(*httpsProxy)
272 #endif
273 #if HAVE(CFNETWORK_ALTERNATIVE_SERVICE)
274         , WTFMove(*alternativeServiceDirectory)
275         , WTFMove(*alternativeServiceDirectoryExtensionHandle)
276         , WTFMove(*http3Enabled)
277 #endif
278 #if USE(SOUP)
279         , WTFMove(*cookiePersistentStoragePath)
280         , WTFMove(*cookiePersistentStorageType)
281         , WTFMove(*persistentCredentialStorageEnabled)
282 #endif
283 #if USE(CURL)
284         , WTFMove(*cookiePersistentStorageFile)
285         , WTFMove(*proxySettings)
286 #endif
287         , WTFMove(*deviceManagementRestrictionsEnabled)
288         , WTFMove(*allLoadsBlockedByDeviceManagementRestrictionsForTesting)
289         , WTFMove(*networkCacheDirectory)
290         , WTFMove(*networkCacheDirectoryExtensionHandle)
291         , WTFMove(*dataConnectionServiceType)
292         , WTFMove(*fastServerTrustEvaluationEnabled)
293         , WTFMove(*networkCacheSpeculativeValidationEnabled)
294         , WTFMove(*shouldUseTestingNetworkSession)
295         , WTFMove(*staleWhileRevalidateEnabled)
296         , WTFMove(*testSpeedMultiplier)
297         , WTFMove(*suppressesConnectionTerminationOnSystemChange)
298         , WTFMove(*allowsServerPreconnect)
299         , WTFMove(*requiresSecureHTTPSProxyConnection)
300         , WTFMove(*preventsSystemHTTPProxyAuthentication)
301         , WTFMove(*resourceLoadStatisticsParameters)
302     }};
303 }
304
305 } // namespace WebKit