a1b22b9c385ba104ce841fd3a31deaeeee73aee2
[WebKit-https.git] / Source / WebKit / NetworkProcess / NetworkProcessCreationParameters.cpp
1 /*
2  * Copyright (C) 2012-2017 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 "NetworkProcessCreationParameters.h"
28
29 #include "ArgumentCoders.h"
30 #include "WebCoreArgumentCoders.h"
31
32 #if PLATFORM(COCOA)
33 #include "ArgumentCodersCF.h"
34 #endif
35
36 namespace WebKit {
37
38 NetworkProcessCreationParameters::NetworkProcessCreationParameters()
39 {
40 }
41
42 void NetworkProcessCreationParameters::encode(IPC::Encoder& encoder) const
43 {
44     encoder << defaultSessionParameters;
45     encoder << privateBrowsingEnabled;
46     encoder.encodeEnum(cacheModel);
47     encoder << diskCacheSizeOverride;
48     encoder << canHandleHTTPSServerTrustEvaluation;
49     encoder << cacheStorageDirectory;
50     encoder << cacheStoragePerOriginQuota;
51     encoder << cacheStorageDirectoryExtensionHandle;
52     encoder << diskCacheDirectory;
53     encoder << diskCacheDirectoryExtensionHandle;
54     encoder << shouldEnableNetworkCache;
55     encoder << shouldEnableNetworkCacheEfficacyLogging;
56 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
57     encoder << shouldEnableNetworkCacheSpeculativeRevalidation;
58 #endif
59 #if PLATFORM(MAC)
60     encoder << uiProcessCookieStorageIdentifier;
61 #endif
62 #if PLATFORM(IOS)
63     encoder << cookieStorageDirectoryExtensionHandle;
64     encoder << containerCachesDirectoryExtensionHandle;
65     encoder << parentBundleDirectoryExtensionHandle;
66 #endif
67     encoder << shouldSuppressMemoryPressureHandler;
68     encoder << shouldUseTestingNetworkSession;
69     encoder << loadThrottleLatency;
70     encoder << urlSchemesRegisteredForCustomProtocols;
71     encoder << presentingApplicationPID;
72 #if PLATFORM(COCOA)
73     encoder << parentProcessName;
74     encoder << uiProcessBundleIdentifier;
75     encoder << nsURLCacheMemoryCapacity;
76     encoder << nsURLCacheDiskCapacity;
77     encoder << sourceApplicationBundleIdentifier;
78     encoder << sourceApplicationSecondaryIdentifier;
79 #if PLATFORM(IOS)
80     encoder << ctDataConnectionServiceType;
81 #endif
82     encoder << httpProxy;
83     encoder << httpsProxy;
84 #if PLATFORM(COCOA)
85     IPC::encode(encoder, networkATSContext.get());
86 #endif
87     encoder << cookieStoragePartitioningEnabled;
88     encoder << storageAccessAPIEnabled;
89 #endif
90 #if USE(SOUP)
91     encoder << cookiePersistentStoragePath;
92     encoder << cookiePersistentStorageType;
93     encoder.encodeEnum(cookieAcceptPolicy);
94     encoder << ignoreTLSErrors;
95     encoder << languages;
96     encoder << proxySettings;
97 #elif USE(CURL)
98     encoder << cookiePersistentStorageFile;
99 #endif
100 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
101     encoder << logCookieInformation;
102 #endif
103 #if OS(LINUX)
104     encoder << memoryPressureMonitorHandle;
105 #endif
106 #if ENABLE(NETWORK_CAPTURE)
107     encoder << recordReplayMode;
108     encoder << recordReplayCacheLocation;
109 #endif
110
111     encoder << urlSchemesRegisteredAsSecure;
112     encoder << urlSchemesRegisteredAsBypassingContentSecurityPolicy;
113     encoder << urlSchemesRegisteredAsLocal;
114     encoder << urlSchemesRegisteredAsNoAccess;
115     encoder << urlSchemesRegisteredAsDisplayIsolated;
116     encoder << urlSchemesRegisteredAsCORSEnabled;
117     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
118
119     encoder << tracksResourceLoadMilestones;
120     
121 #if ENABLE(WIFI_ASSERTIONS)
122     encoder << wirelessContextIdentifier;
123 #endif
124 }
125
126 bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProcessCreationParameters& result)
127 {
128     std::optional<NetworkSessionCreationParameters> defaultSessionParameters;
129     decoder >> defaultSessionParameters;
130     if (!defaultSessionParameters)
131         return false;
132     result.defaultSessionParameters = WTFMove(*defaultSessionParameters);
133
134     if (!decoder.decode(result.privateBrowsingEnabled))
135         return false;
136     if (!decoder.decodeEnum(result.cacheModel))
137         return false;
138     if (!decoder.decode(result.diskCacheSizeOverride))
139         return false;
140     if (!decoder.decode(result.canHandleHTTPSServerTrustEvaluation))
141         return false;
142     if (!decoder.decode(result.cacheStorageDirectory))
143         return false;
144     if (!decoder.decode(result.cacheStoragePerOriginQuota))
145         return false;
146     
147     std::optional<SandboxExtension::Handle> cacheStorageDirectoryExtensionHandle;
148     decoder >> cacheStorageDirectoryExtensionHandle;
149     if (!cacheStorageDirectoryExtensionHandle)
150         return false;
151     result.cacheStorageDirectoryExtensionHandle = WTFMove(*cacheStorageDirectoryExtensionHandle);
152
153     if (!decoder.decode(result.diskCacheDirectory))
154         return false;
155     
156     std::optional<SandboxExtension::Handle> diskCacheDirectoryExtensionHandle;
157     decoder >> diskCacheDirectoryExtensionHandle;
158     if (!diskCacheDirectoryExtensionHandle)
159         return false;
160     result.diskCacheDirectoryExtensionHandle = WTFMove(*diskCacheDirectoryExtensionHandle);
161
162     if (!decoder.decode(result.shouldEnableNetworkCache))
163         return false;
164     if (!decoder.decode(result.shouldEnableNetworkCacheEfficacyLogging))
165         return false;
166 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
167     if (!decoder.decode(result.shouldEnableNetworkCacheSpeculativeRevalidation))
168         return false;
169 #endif
170 #if PLATFORM(MAC)
171     if (!decoder.decode(result.uiProcessCookieStorageIdentifier))
172         return false;
173 #endif
174 #if PLATFORM(IOS)
175     std::optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
176     decoder >> cookieStorageDirectoryExtensionHandle;
177     if (!cookieStorageDirectoryExtensionHandle)
178         return false;
179     result.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
180
181     std::optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
182     decoder >> containerCachesDirectoryExtensionHandle;
183     if (!containerCachesDirectoryExtensionHandle)
184         return false;
185     result.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
186
187     std::optional<SandboxExtension::Handle> parentBundleDirectoryExtensionHandle;
188     decoder >> parentBundleDirectoryExtensionHandle;
189     if (!parentBundleDirectoryExtensionHandle)
190         return false;
191     result.parentBundleDirectoryExtensionHandle = WTFMove(*parentBundleDirectoryExtensionHandle);
192 #endif
193     if (!decoder.decode(result.shouldSuppressMemoryPressureHandler))
194         return false;
195     if (!decoder.decode(result.shouldUseTestingNetworkSession))
196         return false;
197     if (!decoder.decode(result.loadThrottleLatency))
198         return false;
199     if (!decoder.decode(result.urlSchemesRegisteredForCustomProtocols))
200         return false;
201     if (!decoder.decode(result.presentingApplicationPID))
202         return false;
203 #if PLATFORM(COCOA)
204     if (!decoder.decode(result.parentProcessName))
205         return false;
206     if (!decoder.decode(result.uiProcessBundleIdentifier))
207         return false;
208     if (!decoder.decode(result.nsURLCacheMemoryCapacity))
209         return false;
210     if (!decoder.decode(result.nsURLCacheDiskCapacity))
211         return false;
212     if (!decoder.decode(result.sourceApplicationBundleIdentifier))
213         return false;
214     if (!decoder.decode(result.sourceApplicationSecondaryIdentifier))
215         return false;
216 #if PLATFORM(IOS)
217     if (!decoder.decode(result.ctDataConnectionServiceType))
218         return false;
219 #endif
220     if (!decoder.decode(result.httpProxy))
221         return false;
222     if (!decoder.decode(result.httpsProxy))
223         return false;
224 #if PLATFORM(COCOA)
225     if (!IPC::decode(decoder, result.networkATSContext))
226         return false;
227 #endif
228     if (!decoder.decode(result.cookieStoragePartitioningEnabled))
229         return false;
230     if (!decoder.decode(result.storageAccessAPIEnabled))
231         return false;
232 #endif
233
234 #if USE(SOUP)
235     if (!decoder.decode(result.cookiePersistentStoragePath))
236         return false;
237     if (!decoder.decode(result.cookiePersistentStorageType))
238         return false;
239     if (!decoder.decodeEnum(result.cookieAcceptPolicy))
240         return false;
241     if (!decoder.decode(result.ignoreTLSErrors))
242         return false;
243     if (!decoder.decode(result.languages))
244         return false;
245     if (!decoder.decode(result.proxySettings))
246         return false;
247 #elif USE(CURL)
248     if (!decoder.decode(result.cookiePersistentStorageFile))
249         return false;
250 #endif
251
252 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
253     if (!decoder.decode(result.logCookieInformation))
254         return false;
255 #endif
256
257 #if OS(LINUX)
258     if (!decoder.decode(result.memoryPressureMonitorHandle))
259         return false;
260 #endif
261
262 #if ENABLE(NETWORK_CAPTURE)
263     if (!decoder.decode(result.recordReplayMode))
264         return false;
265     if (!decoder.decode(result.recordReplayCacheLocation))
266         return false;
267 #endif
268
269     if (!decoder.decode(result.urlSchemesRegisteredAsSecure))
270         return false;
271     if (!decoder.decode(result.urlSchemesRegisteredAsBypassingContentSecurityPolicy))
272         return false;
273     if (!decoder.decode(result.urlSchemesRegisteredAsLocal))
274         return false;
275     if (!decoder.decode(result.urlSchemesRegisteredAsNoAccess))
276         return false;
277     if (!decoder.decode(result.urlSchemesRegisteredAsDisplayIsolated))
278         return false;
279     if (!decoder.decode(result.urlSchemesRegisteredAsCORSEnabled))
280         return false;
281     if (!decoder.decode(result.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
282         return false;
283
284     if (!decoder.decode(result.tracksResourceLoadMilestones))
285         return false;
286
287 #if ENABLE(WIFI_ASSERTIONS)
288     if (!decoder.decode(result.wirelessContextIdentifier))
289         return false;
290 #endif
291
292     return true;
293 }
294
295 } // namespace WebKit