c0902dfd6ac86fb00dde36229dde75601e91a291
[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() = default;
39
40 void NetworkProcessCreationParameters::encode(IPC::Encoder& encoder) const
41 {
42     encoder.encodeEnum(cacheModel);
43     encoder << canHandleHTTPSServerTrustEvaluation;
44 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
45     encoder << shouldEnableNetworkCacheSpeculativeRevalidation;
46 #endif
47 #if PLATFORM(MAC)
48     encoder << uiProcessCookieStorageIdentifier;
49 #endif
50 #if PLATFORM(IOS_FAMILY)
51     encoder << cookieStorageDirectoryExtensionHandle;
52     encoder << containerCachesDirectoryExtensionHandle;
53     encoder << parentBundleDirectoryExtensionHandle;
54 #endif
55     encoder << shouldSuppressMemoryPressureHandler;
56     encoder << shouldUseTestingNetworkSession;
57     encoder << urlSchemesRegisteredForCustomProtocols;
58 #if PLATFORM(COCOA)
59     encoder << uiProcessBundleIdentifier;
60     encoder << uiProcessSDKVersion;
61 #if PLATFORM(IOS_FAMILY)
62     encoder << ctDataConnectionServiceType;
63 #endif
64     IPC::encode(encoder, networkATSContext.get());
65     encoder << storageAccessAPIEnabled;
66     encoder << suppressesConnectionTerminationOnSystemChange;
67 #endif
68     encoder << defaultDataStoreParameters;
69 #if USE(SOUP)
70     encoder.encodeEnum(cookieAcceptPolicy);
71     encoder << ignoreTLSErrors;
72     encoder << languages;
73     encoder << proxySettings;
74 #endif
75
76     encoder << urlSchemesRegisteredAsSecure;
77     encoder << urlSchemesRegisteredAsBypassingContentSecurityPolicy;
78     encoder << urlSchemesRegisteredAsLocal;
79     encoder << urlSchemesRegisteredAsNoAccess;
80     encoder << urlSchemesRegisteredAsDisplayIsolated;
81     encoder << urlSchemesRegisteredAsCORSEnabled;
82     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
83
84 #if ENABLE(SERVICE_WORKER)
85     encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle << urlSchemesServiceWorkersCanHandle << shouldDisableServiceWorkerProcessTerminationDelay;
86 #endif
87     encoder << shouldEnableITPDatabase;
88     encoder << downloadMonitorSpeedMultiplier;
89     encoder << enableAdClickAttributionDebugMode;
90     encoder << hstsStorageDirectory;
91     encoder << hstsStorageDirectoryExtensionHandle;
92     encoder << enableLegacyTLS;
93 }
94
95 bool NetworkProcessCreationParameters::decode(IPC::Decoder& decoder, NetworkProcessCreationParameters& result)
96 {
97     if (!decoder.decodeEnum(result.cacheModel))
98         return false;
99     if (!decoder.decode(result.canHandleHTTPSServerTrustEvaluation))
100         return false;
101
102 #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
103     if (!decoder.decode(result.shouldEnableNetworkCacheSpeculativeRevalidation))
104         return false;
105 #endif
106 #if PLATFORM(MAC)
107     if (!decoder.decode(result.uiProcessCookieStorageIdentifier))
108         return false;
109 #endif
110 #if PLATFORM(IOS_FAMILY)
111     Optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
112     decoder >> cookieStorageDirectoryExtensionHandle;
113     if (!cookieStorageDirectoryExtensionHandle)
114         return false;
115     result.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
116
117     Optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
118     decoder >> containerCachesDirectoryExtensionHandle;
119     if (!containerCachesDirectoryExtensionHandle)
120         return false;
121     result.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
122
123     Optional<SandboxExtension::Handle> parentBundleDirectoryExtensionHandle;
124     decoder >> parentBundleDirectoryExtensionHandle;
125     if (!parentBundleDirectoryExtensionHandle)
126         return false;
127     result.parentBundleDirectoryExtensionHandle = WTFMove(*parentBundleDirectoryExtensionHandle);
128 #endif
129     if (!decoder.decode(result.shouldSuppressMemoryPressureHandler))
130         return false;
131     if (!decoder.decode(result.shouldUseTestingNetworkSession))
132         return false;
133     if (!decoder.decode(result.urlSchemesRegisteredForCustomProtocols))
134         return false;
135 #if PLATFORM(COCOA)
136     if (!decoder.decode(result.uiProcessBundleIdentifier))
137         return false;
138     if (!decoder.decode(result.uiProcessSDKVersion))
139         return false;
140 #if PLATFORM(IOS_FAMILY)
141     if (!decoder.decode(result.ctDataConnectionServiceType))
142         return false;
143 #endif
144     if (!IPC::decode(decoder, result.networkATSContext))
145         return false;
146     if (!decoder.decode(result.storageAccessAPIEnabled))
147         return false;
148     if (!decoder.decode(result.suppressesConnectionTerminationOnSystemChange))
149         return false;
150 #endif
151
152     Optional<WebsiteDataStoreParameters> defaultDataStoreParameters;
153     decoder >> defaultDataStoreParameters;
154     if (!defaultDataStoreParameters)
155         return false;
156     result.defaultDataStoreParameters = WTFMove(*defaultDataStoreParameters);
157
158 #if USE(SOUP)
159     if (!decoder.decodeEnum(result.cookieAcceptPolicy))
160         return false;
161     if (!decoder.decode(result.ignoreTLSErrors))
162         return false;
163     if (!decoder.decode(result.languages))
164         return false;
165     if (!decoder.decode(result.proxySettings))
166         return false;
167 #endif
168
169     if (!decoder.decode(result.urlSchemesRegisteredAsSecure))
170         return false;
171     if (!decoder.decode(result.urlSchemesRegisteredAsBypassingContentSecurityPolicy))
172         return false;
173     if (!decoder.decode(result.urlSchemesRegisteredAsLocal))
174         return false;
175     if (!decoder.decode(result.urlSchemesRegisteredAsNoAccess))
176         return false;
177     if (!decoder.decode(result.urlSchemesRegisteredAsDisplayIsolated))
178         return false;
179     if (!decoder.decode(result.urlSchemesRegisteredAsCORSEnabled))
180         return false;
181     if (!decoder.decode(result.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
182         return false;
183
184 #if ENABLE(SERVICE_WORKER)
185     if (!decoder.decode(result.serviceWorkerRegistrationDirectory))
186         return false;
187     
188     Optional<SandboxExtension::Handle> serviceWorkerRegistrationDirectoryExtensionHandle;
189     decoder >> serviceWorkerRegistrationDirectoryExtensionHandle;
190     if (!serviceWorkerRegistrationDirectoryExtensionHandle)
191         return false;
192     result.serviceWorkerRegistrationDirectoryExtensionHandle = WTFMove(*serviceWorkerRegistrationDirectoryExtensionHandle);
193     
194     if (!decoder.decode(result.urlSchemesServiceWorkersCanHandle))
195         return false;
196     
197     if (!decoder.decode(result.shouldDisableServiceWorkerProcessTerminationDelay))
198         return false;
199 #endif
200
201     if (!decoder.decode(result.shouldEnableITPDatabase))
202         return false;
203
204     Optional<uint32_t> downloadMonitorSpeedMultiplier;
205     decoder >> downloadMonitorSpeedMultiplier;
206     if (!downloadMonitorSpeedMultiplier)
207         return false;
208     result.downloadMonitorSpeedMultiplier = *downloadMonitorSpeedMultiplier;
209
210     if (!decoder.decode(result.enableAdClickAttributionDebugMode))
211         return false;
212
213     if (!decoder.decode(result.hstsStorageDirectory))
214         return false;
215
216     if (!decoder.decode(result.hstsStorageDirectoryExtensionHandle))
217         return false;
218     
219     if (!decoder.decode(result.enableLegacyTLS))
220         return false;
221
222     return true;
223 }
224
225 } // namespace WebKit