a9f1cd7fea5375d7f4220c15670b36477cb45cbc
[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     encoder << hstsStorageDirectory;
61     encoder << hstsStorageDirectoryExtensionHandle;
62 #if USE(SOUP)
63     encoder << cookiePersistentStoragePath;
64     encoder << cookiePersistentStorageType;
65     encoder << persistentCredentialStorageEnabled;
66     encoder << ignoreTLSErrors;
67     encoder << proxySettings;
68 #endif
69 #if USE(CURL)
70     encoder << cookiePersistentStorageFile;
71     encoder << proxySettings;
72 #endif
73     encoder << networkCacheDirectory << networkCacheDirectoryExtensionHandle;
74
75     encoder << deviceManagementRestrictionsEnabled;
76     encoder << allLoadsBlockedByDeviceManagementRestrictionsForTesting;
77     encoder << dataConnectionServiceType;
78     encoder << fastServerTrustEvaluationEnabled;
79     encoder << networkCacheSpeculativeValidationEnabled;
80     encoder << shouldUseTestingNetworkSession;
81     encoder << staleWhileRevalidateEnabled;
82     encoder << testSpeedMultiplier;
83     encoder << suppressesConnectionTerminationOnSystemChange;
84     encoder << allowsServerPreconnect;
85     encoder << requiresSecureHTTPSProxyConnection;
86     encoder << preventsSystemHTTPProxyAuthentication;
87     encoder << appHasRequestedCrossWebsiteTrackingPermission;
88     encoder << resourceLoadStatisticsParameters;
89 }
90
91 Optional<NetworkSessionCreationParameters> NetworkSessionCreationParameters::decode(IPC::Decoder& decoder)
92 {
93     Optional<PAL::SessionID> sessionID;
94     decoder >> sessionID;
95     if (!sessionID)
96         return WTF::nullopt;
97     
98     Optional<String> boundInterfaceIdentifier;
99     decoder >> boundInterfaceIdentifier;
100     if (!boundInterfaceIdentifier)
101         return WTF::nullopt;
102     
103     Optional<AllowsCellularAccess> allowsCellularAccess;
104     decoder >> allowsCellularAccess;
105     if (!allowsCellularAccess)
106         return WTF::nullopt;
107     
108 #if PLATFORM(COCOA)
109     RetainPtr<CFDictionaryRef> proxyConfiguration;
110     if (!IPC::decode(decoder, proxyConfiguration))
111         return WTF::nullopt;
112     
113     Optional<String> sourceApplicationBundleIdentifier;
114     decoder >> sourceApplicationBundleIdentifier;
115     if (!sourceApplicationBundleIdentifier)
116         return WTF::nullopt;
117     
118     Optional<String> sourceApplicationSecondaryIdentifier;
119     decoder >> sourceApplicationSecondaryIdentifier;
120     if (!sourceApplicationSecondaryIdentifier)
121         return WTF::nullopt;
122
123     Optional<bool> shouldLogCookieInformation;
124     decoder >> shouldLogCookieInformation;
125     if (!shouldLogCookieInformation)
126         return WTF::nullopt;
127     
128     Optional<Seconds> loadThrottleLatency;
129     decoder >> loadThrottleLatency;
130     if (!loadThrottleLatency)
131         return WTF::nullopt;
132     
133     Optional<URL> httpProxy;
134     decoder >> httpProxy;
135     if (!httpProxy)
136         return WTF::nullopt;
137
138     Optional<URL> httpsProxy;
139     decoder >> httpsProxy;
140     if (!httpsProxy)
141         return WTF::nullopt;
142 #endif
143
144 #if HAVE(CFNETWORK_ALTERNATIVE_SERVICE)
145     Optional<String> alternativeServiceDirectory;
146     decoder >> alternativeServiceDirectory;
147     if (!alternativeServiceDirectory)
148         return WTF::nullopt;
149
150     Optional<SandboxExtension::Handle> alternativeServiceDirectoryExtensionHandle;
151     decoder >> alternativeServiceDirectoryExtensionHandle;
152     if (!alternativeServiceDirectoryExtensionHandle)
153         return WTF::nullopt;
154     
155     Optional<bool> http3Enabled;
156     decoder >> http3Enabled;
157     if (!http3Enabled)
158         return WTF::nullopt;
159 #endif
160
161     Optional<String> hstsStorageDirectory;
162     decoder >> hstsStorageDirectory;
163     if (!hstsStorageDirectory)
164         return WTF::nullopt;
165
166     Optional<SandboxExtension::Handle> hstsStorageDirectoryExtensionHandle;
167     decoder >> hstsStorageDirectoryExtensionHandle;
168     if (!hstsStorageDirectoryExtensionHandle)
169         return WTF::nullopt;
170     
171 #if USE(SOUP)
172     Optional<String> cookiePersistentStoragePath;
173     decoder >> cookiePersistentStoragePath;
174     if (!cookiePersistentStoragePath)
175         return WTF::nullopt;
176
177     Optional<SoupCookiePersistentStorageType> cookiePersistentStorageType;
178     decoder >> cookiePersistentStorageType;
179     if (!cookiePersistentStorageType)
180         return WTF::nullopt;
181
182     Optional<bool> persistentCredentialStorageEnabled;
183     decoder >> persistentCredentialStorageEnabled;
184     if (!persistentCredentialStorageEnabled)
185         return WTF::nullopt;
186
187     Optional<bool> ignoreTLSErrors;
188     decoder >> ignoreTLSErrors;
189     if (!ignoreTLSErrors)
190         return WTF::nullopt;
191
192     Optional<WebCore::SoupNetworkProxySettings> proxySettings;
193     decoder >> proxySettings;
194     if (!proxySettings)
195         return WTF::nullopt;
196 #endif
197
198 #if USE(CURL)
199     Optional<String> cookiePersistentStorageFile;
200     decoder >> cookiePersistentStorageFile;
201     if (!cookiePersistentStorageFile)
202         return WTF::nullopt;
203
204     Optional<WebCore::CurlProxySettings> proxySettings;
205     decoder >> proxySettings;
206     if (!proxySettings)
207         return WTF::nullopt;
208 #endif
209
210     Optional<String> networkCacheDirectory;
211     decoder >> networkCacheDirectory;
212     if (!networkCacheDirectory)
213         return WTF::nullopt;
214     
215     Optional<SandboxExtension::Handle> networkCacheDirectoryExtensionHandle;
216     decoder >> networkCacheDirectoryExtensionHandle;
217     if (!networkCacheDirectoryExtensionHandle)
218         return WTF::nullopt;
219
220     Optional<bool> deviceManagementRestrictionsEnabled;
221     decoder >> deviceManagementRestrictionsEnabled;
222     if (!deviceManagementRestrictionsEnabled)
223         return WTF::nullopt;
224
225     Optional<bool> allLoadsBlockedByDeviceManagementRestrictionsForTesting;
226     decoder >> allLoadsBlockedByDeviceManagementRestrictionsForTesting;
227     if (!allLoadsBlockedByDeviceManagementRestrictionsForTesting)
228         return WTF::nullopt;
229
230     Optional<String> dataConnectionServiceType;
231     decoder >> dataConnectionServiceType;
232     if (!dataConnectionServiceType)
233         return WTF::nullopt;
234     
235     Optional<bool> fastServerTrustEvaluationEnabled;
236     decoder >> fastServerTrustEvaluationEnabled;
237     if (!fastServerTrustEvaluationEnabled)
238         return WTF::nullopt;
239     
240     Optional<bool> networkCacheSpeculativeValidationEnabled;
241     decoder >> networkCacheSpeculativeValidationEnabled;
242     if (!networkCacheSpeculativeValidationEnabled)
243         return WTF::nullopt;
244     
245     Optional<bool> shouldUseTestingNetworkSession;
246     decoder >> shouldUseTestingNetworkSession;
247     if (!shouldUseTestingNetworkSession)
248         return WTF::nullopt;
249
250     Optional<bool> staleWhileRevalidateEnabled;
251     decoder >> staleWhileRevalidateEnabled;
252     if (!staleWhileRevalidateEnabled)
253         return WTF::nullopt;
254
255     Optional<unsigned> testSpeedMultiplier;
256     decoder >> testSpeedMultiplier;
257     if (!testSpeedMultiplier)
258         return WTF::nullopt;
259     
260     Optional<bool> suppressesConnectionTerminationOnSystemChange;
261     decoder >> suppressesConnectionTerminationOnSystemChange;
262     if (!suppressesConnectionTerminationOnSystemChange)
263         return WTF::nullopt;
264
265     Optional<bool> allowsServerPreconnect;
266     decoder >> allowsServerPreconnect;
267     if (!allowsServerPreconnect)
268         return WTF::nullopt;
269
270     Optional<bool> requiresSecureHTTPSProxyConnection;
271     decoder >> requiresSecureHTTPSProxyConnection;
272     if (!requiresSecureHTTPSProxyConnection)
273         return WTF::nullopt;
274     
275     Optional<bool> preventsSystemHTTPProxyAuthentication;
276     decoder >> preventsSystemHTTPProxyAuthentication;
277     if (!preventsSystemHTTPProxyAuthentication)
278         return WTF::nullopt;
279     
280     Optional<bool> appHasRequestedCrossWebsiteTrackingPermission;
281     decoder >> appHasRequestedCrossWebsiteTrackingPermission;
282     if (!appHasRequestedCrossWebsiteTrackingPermission)
283         return WTF::nullopt;
284
285     Optional<ResourceLoadStatisticsParameters> resourceLoadStatisticsParameters;
286     decoder >> resourceLoadStatisticsParameters;
287     if (!resourceLoadStatisticsParameters)
288         return WTF::nullopt;
289     
290     return {{
291         *sessionID
292         , WTFMove(*boundInterfaceIdentifier)
293         , WTFMove(*allowsCellularAccess)
294 #if PLATFORM(COCOA)
295         , WTFMove(proxyConfiguration)
296         , WTFMove(*sourceApplicationBundleIdentifier)
297         , WTFMove(*sourceApplicationSecondaryIdentifier)
298         , WTFMove(*shouldLogCookieInformation)
299         , WTFMove(*loadThrottleLatency)
300         , WTFMove(*httpProxy)
301         , WTFMove(*httpsProxy)
302 #endif
303 #if HAVE(CFNETWORK_ALTERNATIVE_SERVICE)
304         , WTFMove(*alternativeServiceDirectory)
305         , WTFMove(*alternativeServiceDirectoryExtensionHandle)
306         , WTFMove(*http3Enabled)
307 #endif
308         , WTFMove(*hstsStorageDirectory)
309         , WTFMove(*hstsStorageDirectoryExtensionHandle)
310 #if USE(SOUP)
311         , WTFMove(*cookiePersistentStoragePath)
312         , WTFMove(*cookiePersistentStorageType)
313         , WTFMove(*persistentCredentialStorageEnabled)
314         , WTFMove(*ignoreTLSErrors)
315         , WTFMove(*proxySettings)
316 #endif
317 #if USE(CURL)
318         , WTFMove(*cookiePersistentStorageFile)
319         , WTFMove(*proxySettings)
320 #endif
321         , WTFMove(*deviceManagementRestrictionsEnabled)
322         , WTFMove(*allLoadsBlockedByDeviceManagementRestrictionsForTesting)
323         , WTFMove(*networkCacheDirectory)
324         , WTFMove(*networkCacheDirectoryExtensionHandle)
325         , WTFMove(*dataConnectionServiceType)
326         , WTFMove(*fastServerTrustEvaluationEnabled)
327         , WTFMove(*networkCacheSpeculativeValidationEnabled)
328         , WTFMove(*shouldUseTestingNetworkSession)
329         , WTFMove(*staleWhileRevalidateEnabled)
330         , WTFMove(*testSpeedMultiplier)
331         , WTFMove(*suppressesConnectionTerminationOnSystemChange)
332         , WTFMove(*allowsServerPreconnect)
333         , WTFMove(*requiresSecureHTTPSProxyConnection)
334         , WTFMove(*preventsSystemHTTPProxyAuthentication)
335         , WTFMove(*appHasRequestedCrossWebsiteTrackingPermission)
336         , WTFMove(*resourceLoadStatisticsParameters)
337     }};
338 }
339
340 } // namespace WebKit