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