Source/WebKit:
[WebKit-https.git] / Source / WebKit / Shared / WebProcessCreationParameters.cpp
1 /*
2  * Copyright (C) 2010-2018 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 "WebProcessCreationParameters.h"
28
29 #include "APIData.h"
30 #if PLATFORM(COCOA)
31 #include "ArgumentCodersCF.h"
32 #endif
33 #include "WebCoreArgumentCoders.h"
34
35 namespace WebKit {
36
37 WebProcessCreationParameters::WebProcessCreationParameters()
38 {
39 }
40
41 WebProcessCreationParameters::~WebProcessCreationParameters()
42 {
43 }
44
45 void WebProcessCreationParameters::encode(IPC::Encoder& encoder) const
46 {
47     encoder << injectedBundlePath;
48     encoder << injectedBundlePathExtensionHandle;
49     encoder << additionalSandboxExtensionHandles;
50     encoder << initializationUserData;
51     encoder << applicationCacheDirectory;
52     encoder << applicationCacheFlatFileSubdirectoryName;
53     encoder << applicationCacheDirectoryExtensionHandle;
54     encoder << webSQLDatabaseDirectory;
55     encoder << webSQLDatabaseDirectoryExtensionHandle;
56     encoder << mediaCacheDirectory;
57     encoder << mediaCacheDirectoryExtensionHandle;
58     encoder << javaScriptConfigurationDirectory;
59     encoder << javaScriptConfigurationDirectoryExtensionHandle;
60 #if PLATFORM(COCOA)
61     encoder << uiProcessCookieStorageIdentifier;
62 #endif
63 #if PLATFORM(IOS)
64     encoder << cookieStorageDirectoryExtensionHandle;
65     encoder << containerCachesDirectoryExtensionHandle;
66     encoder << containerTemporaryDirectoryExtensionHandle;
67 #endif
68     encoder << mediaKeyStorageDirectory;
69     encoder << webCoreLoggingChannels;
70     encoder << webKitLoggingChannels;
71     encoder << mediaKeyStorageDirectoryExtensionHandle;
72 #if ENABLE(MEDIA_STREAM)
73     encoder << audioCaptureExtensionHandle;
74     encoder << shouldCaptureAudioInUIProcess;
75 #endif
76     encoder << shouldUseTestingNetworkSession;
77     encoder << urlSchemesRegisteredAsEmptyDocument;
78     encoder << urlSchemesRegisteredAsSecure;
79     encoder << urlSchemesRegisteredAsBypassingContentSecurityPolicy;
80     encoder << urlSchemesForWhichDomainRelaxationIsForbidden;
81     encoder << urlSchemesRegisteredAsLocal;
82     encoder << urlSchemesRegisteredAsNoAccess;
83     encoder << urlSchemesRegisteredAsDisplayIsolated;
84     encoder << urlSchemesRegisteredAsCORSEnabled;
85     encoder << urlSchemesRegisteredAsAlwaysRevalidated;
86     encoder << urlSchemesRegisteredAsCachePartitioned;
87     encoder << urlSchemesServiceWorkersCanHandle;
88     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
89     encoder.encodeEnum(cacheModel);
90     encoder << shouldAlwaysUseComplexTextCodePath;
91     encoder << shouldEnableMemoryPressureReliefLogging;
92     encoder << shouldSuppressMemoryPressureHandler;
93     encoder << shouldUseFontSmoothing;
94     encoder << resourceLoadStatisticsEnabled;
95     encoder << fontWhitelist;
96     encoder << terminationTimeout;
97     encoder << languages;
98 #if USE(GSTREAMER)
99     encoder << gstreamerOptions;
100 #endif
101     encoder << textCheckerState;
102     encoder << fullKeyboardAccessEnabled;
103     encoder << defaultRequestTimeoutInterval;
104 #if PLATFORM(COCOA)
105     encoder << uiProcessBundleIdentifier;
106 #endif
107     encoder << presentingApplicationPID;
108 #if PLATFORM(COCOA)
109     encoder << accessibilityEnhancedUserInterfaceEnabled;
110     encoder << acceleratedCompositingPort;
111     encoder << uiProcessBundleResourcePath;
112     encoder << uiProcessBundleResourcePathExtensionHandle;
113     encoder << shouldEnableJIT;
114     encoder << shouldEnableFTLJIT;
115     encoder << !!bundleParameterData;
116     if (bundleParameterData)
117         encoder << bundleParameterData->dataReference();
118 #endif
119
120 #if ENABLE(NOTIFICATIONS)
121     encoder << notificationPermissions;
122 #endif
123
124     encoder << plugInAutoStartOriginHashes;
125     encoder << plugInAutoStartOrigins;
126     encoder << memoryCacheDisabled;
127
128 #if ENABLE(SERVICE_CONTROLS)
129     encoder << hasImageServices;
130     encoder << hasSelectionServices;
131     encoder << hasRichContentServices;
132 #endif
133
134 #if ENABLE(NETSCAPE_PLUGIN_API)
135     encoder << pluginLoadClientPolicies;
136 #endif
137
138 #if PLATFORM(COCOA)
139     IPC::encode(encoder, networkATSContext.get());
140 #endif
141
142 #if OS(LINUX)
143     encoder << memoryPressureMonitorHandle;
144 #endif
145
146 #if PLATFORM(WAYLAND)
147     encoder << waylandCompositorDisplayName;
148 #endif
149
150 #if USE(SOUP)
151     encoder << proxySettings;
152 #endif
153
154 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
155     encoder << shouldLogUserInteraction;
156 #endif
157 }
158
159 bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreationParameters& parameters)
160 {
161     if (!decoder.decode(parameters.injectedBundlePath))
162         return false;
163     
164     std::optional<SandboxExtension::Handle> injectedBundlePathExtensionHandle;
165     decoder >> injectedBundlePathExtensionHandle;
166     if (!injectedBundlePathExtensionHandle)
167         return false;
168     parameters.injectedBundlePathExtensionHandle = WTFMove(*injectedBundlePathExtensionHandle);
169
170     if (!decoder.decode(parameters.additionalSandboxExtensionHandles))
171         return false;
172     if (!decoder.decode(parameters.initializationUserData))
173         return false;
174     if (!decoder.decode(parameters.applicationCacheDirectory))
175         return false;
176     if (!decoder.decode(parameters.applicationCacheFlatFileSubdirectoryName))
177         return false;
178     
179     std::optional<SandboxExtension::Handle> applicationCacheDirectoryExtensionHandle;
180     decoder >> applicationCacheDirectoryExtensionHandle;
181     if (!applicationCacheDirectoryExtensionHandle)
182         return false;
183     parameters.applicationCacheDirectoryExtensionHandle = WTFMove(*applicationCacheDirectoryExtensionHandle);
184
185     if (!decoder.decode(parameters.webSQLDatabaseDirectory))
186         return false;
187
188     std::optional<SandboxExtension::Handle> webSQLDatabaseDirectoryExtensionHandle;
189     decoder >> webSQLDatabaseDirectoryExtensionHandle;
190     if (!webSQLDatabaseDirectoryExtensionHandle)
191         return false;
192     parameters.webSQLDatabaseDirectoryExtensionHandle = WTFMove(*webSQLDatabaseDirectoryExtensionHandle);
193
194     if (!decoder.decode(parameters.mediaCacheDirectory))
195         return false;
196     
197     std::optional<SandboxExtension::Handle> mediaCacheDirectoryExtensionHandle;
198     decoder >> mediaCacheDirectoryExtensionHandle;
199     if (!mediaCacheDirectoryExtensionHandle)
200         return false;
201     parameters.mediaCacheDirectoryExtensionHandle = WTFMove(*mediaCacheDirectoryExtensionHandle);
202
203     if (!decoder.decode(parameters.javaScriptConfigurationDirectory))
204         return false;
205     
206     std::optional<SandboxExtension::Handle> javaScriptConfigurationDirectoryExtensionHandle;
207     decoder >> javaScriptConfigurationDirectoryExtensionHandle;
208     if (!javaScriptConfigurationDirectoryExtensionHandle)
209         return false;
210     parameters.javaScriptConfigurationDirectoryExtensionHandle = WTFMove(*javaScriptConfigurationDirectoryExtensionHandle);
211
212 #if PLATFORM(COCOA)
213     if (!decoder.decode(parameters.uiProcessCookieStorageIdentifier))
214         return false;
215 #endif
216 #if PLATFORM(IOS)
217     
218     std::optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
219     decoder >> cookieStorageDirectoryExtensionHandle;
220     if (!cookieStorageDirectoryExtensionHandle)
221         return false;
222     parameters.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
223
224     std::optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
225     decoder >> containerCachesDirectoryExtensionHandle;
226     if (!containerCachesDirectoryExtensionHandle)
227         return false;
228     parameters.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
229
230     std::optional<SandboxExtension::Handle> containerTemporaryDirectoryExtensionHandle;
231     decoder >> containerTemporaryDirectoryExtensionHandle;
232     if (!containerTemporaryDirectoryExtensionHandle)
233         return false;
234     parameters.containerTemporaryDirectoryExtensionHandle = WTFMove(*containerTemporaryDirectoryExtensionHandle);
235
236 #endif
237     if (!decoder.decode(parameters.mediaKeyStorageDirectory))
238         return false;
239     if (!decoder.decode(parameters.webCoreLoggingChannels))
240         return false;
241     if (!decoder.decode(parameters.webKitLoggingChannels))
242         return false;
243     
244     std::optional<SandboxExtension::Handle> mediaKeyStorageDirectoryExtensionHandle;
245     decoder >> mediaKeyStorageDirectoryExtensionHandle;
246     if (!mediaKeyStorageDirectoryExtensionHandle)
247         return false;
248     parameters.mediaKeyStorageDirectoryExtensionHandle = WTFMove(*mediaKeyStorageDirectoryExtensionHandle);
249
250 #if ENABLE(MEDIA_STREAM)
251
252     std::optional<SandboxExtension::Handle> audioCaptureExtensionHandle;
253     decoder >> audioCaptureExtensionHandle;
254     if (!audioCaptureExtensionHandle)
255         return false;
256     parameters.audioCaptureExtensionHandle = WTFMove(*audioCaptureExtensionHandle);
257
258     if (!decoder.decode(parameters.shouldCaptureAudioInUIProcess))
259         return false;
260 #endif
261     if (!decoder.decode(parameters.shouldUseTestingNetworkSession))
262         return false;
263     if (!decoder.decode(parameters.urlSchemesRegisteredAsEmptyDocument))
264         return false;
265     if (!decoder.decode(parameters.urlSchemesRegisteredAsSecure))
266         return false;
267     if (!decoder.decode(parameters.urlSchemesRegisteredAsBypassingContentSecurityPolicy))
268         return false;
269     if (!decoder.decode(parameters.urlSchemesForWhichDomainRelaxationIsForbidden))
270         return false;
271     if (!decoder.decode(parameters.urlSchemesRegisteredAsLocal))
272         return false;
273     if (!decoder.decode(parameters.urlSchemesRegisteredAsNoAccess))
274         return false;
275     if (!decoder.decode(parameters.urlSchemesRegisteredAsDisplayIsolated))
276         return false;
277     if (!decoder.decode(parameters.urlSchemesRegisteredAsCORSEnabled))
278         return false;
279     if (!decoder.decode(parameters.urlSchemesRegisteredAsAlwaysRevalidated))
280         return false;
281     if (!decoder.decode(parameters.urlSchemesRegisteredAsCachePartitioned))
282         return false;
283     if (!decoder.decode(parameters.urlSchemesServiceWorkersCanHandle))
284         return false;
285     if (!decoder.decode(parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
286         return false;
287     if (!decoder.decodeEnum(parameters.cacheModel))
288         return false;
289     if (!decoder.decode(parameters.shouldAlwaysUseComplexTextCodePath))
290         return false;
291     if (!decoder.decode(parameters.shouldEnableMemoryPressureReliefLogging))
292         return false;
293     if (!decoder.decode(parameters.shouldSuppressMemoryPressureHandler))
294         return false;
295     if (!decoder.decode(parameters.shouldUseFontSmoothing))
296         return false;
297     if (!decoder.decode(parameters.resourceLoadStatisticsEnabled))
298         return false;
299     if (!decoder.decode(parameters.fontWhitelist))
300         return false;
301     if (!decoder.decode(parameters.terminationTimeout))
302         return false;
303     if (!decoder.decode(parameters.languages))
304         return false;
305 #if USE(GSTREAMER)
306     if (!decoder.decode(parameters.gstreamerOptions))
307         return false;
308 #endif
309     if (!decoder.decode(parameters.textCheckerState))
310         return false;
311     if (!decoder.decode(parameters.fullKeyboardAccessEnabled))
312         return false;
313     if (!decoder.decode(parameters.defaultRequestTimeoutInterval))
314         return false;
315 #if PLATFORM(COCOA)
316     if (!decoder.decode(parameters.uiProcessBundleIdentifier))
317         return false;
318 #endif
319     if (!decoder.decode(parameters.presentingApplicationPID))
320         return false;
321 #if PLATFORM(COCOA)
322     if (!decoder.decode(parameters.accessibilityEnhancedUserInterfaceEnabled))
323         return false;
324     if (!decoder.decode(parameters.acceleratedCompositingPort))
325         return false;
326     if (!decoder.decode(parameters.uiProcessBundleResourcePath))
327         return false;
328     
329     std::optional<SandboxExtension::Handle> uiProcessBundleResourcePathExtensionHandle;
330     decoder >> uiProcessBundleResourcePathExtensionHandle;
331     if (!uiProcessBundleResourcePathExtensionHandle)
332         return false;
333     parameters.uiProcessBundleResourcePathExtensionHandle = WTFMove(*uiProcessBundleResourcePathExtensionHandle);
334
335     if (!decoder.decode(parameters.shouldEnableJIT))
336         return false;
337     if (!decoder.decode(parameters.shouldEnableFTLJIT))
338         return false;
339
340     bool hasBundleParameterData;
341     if (!decoder.decode(hasBundleParameterData))
342         return false;
343
344     if (hasBundleParameterData) {
345         IPC::DataReference dataReference;
346         if (!decoder.decode(dataReference))
347             return false;
348
349         parameters.bundleParameterData = API::Data::create(dataReference.data(), dataReference.size());
350     }
351 #endif
352
353 #if ENABLE(NOTIFICATIONS)
354     if (!decoder.decode(parameters.notificationPermissions))
355         return false;
356 #endif
357
358     if (!decoder.decode(parameters.plugInAutoStartOriginHashes))
359         return false;
360     if (!decoder.decode(parameters.plugInAutoStartOrigins))
361         return false;
362     if (!decoder.decode(parameters.memoryCacheDisabled))
363         return false;
364
365 #if ENABLE(SERVICE_CONTROLS)
366     if (!decoder.decode(parameters.hasImageServices))
367         return false;
368     if (!decoder.decode(parameters.hasSelectionServices))
369         return false;
370     if (!decoder.decode(parameters.hasRichContentServices))
371         return false;
372 #endif
373
374 #if ENABLE(NETSCAPE_PLUGIN_API)
375     if (!decoder.decode(parameters.pluginLoadClientPolicies))
376         return false;
377 #endif
378
379 #if PLATFORM(COCOA)
380     if (!IPC::decode(decoder, parameters.networkATSContext))
381         return false;
382 #endif
383
384 #if OS(LINUX)
385     if (!decoder.decode(parameters.memoryPressureMonitorHandle))
386         return false;
387 #endif
388
389 #if PLATFORM(WAYLAND)
390     if (!decoder.decode(parameters.waylandCompositorDisplayName))
391         return false;
392 #endif
393
394 #if USE(SOUP)
395     if (!decoder.decode(parameters.proxySettings))
396         return false;
397 #endif
398
399 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
400     if (!decoder.decode(parameters.shouldLogUserInteraction))
401         return false;
402 #endif
403
404     return true;
405 }
406
407 } // namespace WebKit