880e12fb816222517759e638c420fb09becf1db6
[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
112 bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProcessCreationParameters& result)
113 {
114     std::optional<NetworkSessionCreationParameters> defaultSessionParameters;
115     decoder >> defaultSessionParameters;
116     if (!defaultSessionParameters)
117         return false;
118     result.defaultSessionParameters = WTFMove(*defaultSessionParameters);
119
120     if (!decoder.decode(result.privateBrowsingEnabled))
121         return false;
122     if (!decoder.decodeEnum(result.cacheModel))
123         return false;
124     if (!decoder.decode(result.diskCacheSizeOverride))
125         return false;
126     if (!decoder.decode(result.canHandleHTTPSServerTrustEvaluation))
127         return false;
128     if (!decoder.decode(result.cacheStorageDirectory))
129         return false;
130     if (!decoder.decode(result.cacheStoragePerOriginQuota))
131         return false;
132     
133     std::optional<SandboxExtension::Handle> cacheStorageDirectoryExtensionHandle;
134     decoder >> cacheStorageDirectoryExtensionHandle;
135     if (!cacheStorageDirectoryExtensionHandle)
136         return false;
137     result.cacheStorageDirectoryExtensionHandle = WTFMove(*cacheStorageDirectoryExtensionHandle);
138
139     if (!decoder.decode(result.diskCacheDirectory))
140         return false;
141     
142     std::optional<SandboxExtension::Handle> diskCacheDirectoryExtensionHandle;
143     decoder >> diskCacheDirectoryExtensionHandle;
144     if (!diskCacheDirectoryExtensionHandle)
145         return false;
146     result.diskCacheDirectoryExtensionHandle = WTFMove(*diskCacheDirectoryExtensionHandle);
147
148     if (!decoder.decode(result.shouldEnableNetworkCache))
149         return false;
150     if (!decoder.decode(result.shouldEnableNetworkCacheEfficacyLogging))
151         return false;
152 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
153     if (!decoder.decode(result.shouldEnableNetworkCacheSpeculativeRevalidation))
154         return false;
155 #endif
156 #if PLATFORM(MAC)
157     if (!decoder.decode(result.uiProcessCookieStorageIdentifier))
158         return false;
159 #endif
160 #if PLATFORM(IOS)
161     std::optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
162     decoder >> cookieStorageDirectoryExtensionHandle;
163     if (!cookieStorageDirectoryExtensionHandle)
164         return false;
165     result.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
166
167     std::optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
168     decoder >> containerCachesDirectoryExtensionHandle;
169     if (!containerCachesDirectoryExtensionHandle)
170         return false;
171     result.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
172
173     std::optional<SandboxExtension::Handle> parentBundleDirectoryExtensionHandle;
174     decoder >> parentBundleDirectoryExtensionHandle;
175     if (!parentBundleDirectoryExtensionHandle)
176         return false;
177     result.parentBundleDirectoryExtensionHandle = WTFMove(*parentBundleDirectoryExtensionHandle);
178 #endif
179     if (!decoder.decode(result.shouldSuppressMemoryPressureHandler))
180         return false;
181     if (!decoder.decode(result.shouldUseTestingNetworkSession))
182         return false;
183     if (!decoder.decode(result.loadThrottleLatency))
184         return false;
185     if (!decoder.decode(result.urlSchemesRegisteredForCustomProtocols))
186         return false;
187     if (!decoder.decode(result.presentingApplicationPID))
188         return false;
189 #if PLATFORM(COCOA)
190     if (!decoder.decode(result.parentProcessName))
191         return false;
192     if (!decoder.decode(result.uiProcessBundleIdentifier))
193         return false;
194     if (!decoder.decode(result.nsURLCacheMemoryCapacity))
195         return false;
196     if (!decoder.decode(result.nsURLCacheDiskCapacity))
197         return false;
198     if (!decoder.decode(result.sourceApplicationBundleIdentifier))
199         return false;
200     if (!decoder.decode(result.sourceApplicationSecondaryIdentifier))
201         return false;
202 #if PLATFORM(IOS)
203     if (!decoder.decode(result.ctDataConnectionServiceType))
204         return false;
205 #endif
206     if (!decoder.decode(result.httpProxy))
207         return false;
208     if (!decoder.decode(result.httpsProxy))
209         return false;
210 #if PLATFORM(COCOA)
211     if (!IPC::decode(decoder, result.networkATSContext))
212         return false;
213 #endif
214     if (!decoder.decode(result.cookieStoragePartitioningEnabled))
215         return false;
216     if (!decoder.decode(result.storageAccessAPIEnabled))
217         return false;
218 #endif
219
220 #if USE(SOUP)
221     if (!decoder.decode(result.cookiePersistentStoragePath))
222         return false;
223     if (!decoder.decode(result.cookiePersistentStorageType))
224         return false;
225     if (!decoder.decodeEnum(result.cookieAcceptPolicy))
226         return false;
227     if (!decoder.decode(result.ignoreTLSErrors))
228         return false;
229     if (!decoder.decode(result.languages))
230         return false;
231     if (!decoder.decode(result.proxySettings))
232         return false;
233 #elif USE(CURL)
234     if (!decoder.decode(result.cookiePersistentStorageFile))
235         return false;
236 #endif
237
238 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
239     if (!decoder.decode(result.logCookieInformation))
240         return false;
241 #endif
242
243 #if OS(LINUX)
244     if (!decoder.decode(result.memoryPressureMonitorHandle))
245         return false;
246 #endif
247
248 #if ENABLE(NETWORK_CAPTURE)
249     if (!decoder.decode(result.recordReplayMode))
250         return false;
251     if (!decoder.decode(result.recordReplayCacheLocation))
252         return false;
253 #endif
254
255     return true;
256 }
257
258 } // namespace WebKit