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