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