3a92699bd7d16b9a285725d410da1a934fc75d89
[WebKit.git] / Source / WebKit / Shared / WebProcessCreationParameters.cpp
1 /*
2  * Copyright (C) 2010-2020 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(WebProcessCreationParameters&&) = default;
38 WebProcessCreationParameters& WebProcessCreationParameters::operator=(WebProcessCreationParameters&&) = default;
39
40 WebProcessCreationParameters::WebProcessCreationParameters()
41 {
42 }
43
44 WebProcessCreationParameters::~WebProcessCreationParameters()
45 {
46 }
47
48 void WebProcessCreationParameters::encode(IPC::Encoder& encoder) const
49 {
50     encoder << injectedBundlePath;
51     encoder << injectedBundlePathExtensionHandle;
52     encoder << additionalSandboxExtensionHandles;
53     encoder << initializationUserData;
54 #if PLATFORM(IOS_FAMILY)
55     encoder << cookieStorageDirectoryExtensionHandle;
56     encoder << containerCachesDirectoryExtensionHandle;
57     encoder << containerTemporaryDirectoryExtensionHandle;
58 #endif
59     encoder << webCoreLoggingChannels;
60     encoder << webKitLoggingChannels;
61 #if ENABLE(MEDIA_STREAM)
62     encoder << audioCaptureExtensionHandle;
63 #endif
64     encoder << urlSchemesRegisteredAsEmptyDocument;
65     encoder << urlSchemesRegisteredAsSecure;
66     encoder << urlSchemesRegisteredAsBypassingContentSecurityPolicy;
67     encoder << urlSchemesForWhichDomainRelaxationIsForbidden;
68     encoder << urlSchemesRegisteredAsLocal;
69     encoder << urlSchemesRegisteredAsNoAccess;
70     encoder << urlSchemesRegisteredAsDisplayIsolated;
71     encoder << urlSchemesRegisteredAsCORSEnabled;
72     encoder << urlSchemesRegisteredAsAlwaysRevalidated;
73     encoder << urlSchemesRegisteredAsCachePartitioned;
74     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
75     encoder.encodeEnum(cacheModel);
76     encoder << shouldAlwaysUseComplexTextCodePath;
77     encoder << shouldEnableMemoryPressureReliefLogging;
78     encoder << shouldSuppressMemoryPressureHandler;
79     encoder << shouldUseFontSmoothing;
80     encoder << fontWhitelist;
81     encoder << terminationTimeout;
82     encoder << languages;
83 #if USE(GSTREAMER)
84     encoder << gstreamerOptions;
85 #endif
86     encoder << textCheckerState;
87     encoder << fullKeyboardAccessEnabled;
88     encoder << defaultRequestTimeoutInterval;
89     encoder << backForwardCacheCapacity;
90 #if PLATFORM(COCOA)
91     encoder << uiProcessBundleIdentifier;
92     encoder << uiProcessSDKVersion;
93 #endif
94     encoder << presentingApplicationPID;
95 #if PLATFORM(COCOA)
96     encoder << accessibilityEnhancedUserInterfaceEnabled;
97     encoder << acceleratedCompositingPort;
98     encoder << uiProcessBundleResourcePath;
99     encoder << uiProcessBundleResourcePathExtensionHandle;
100     encoder << shouldEnableJIT;
101     encoder << shouldEnableFTLJIT;
102     encoder << !!bundleParameterData;
103     if (bundleParameterData)
104         encoder << bundleParameterData->dataReference();
105 #endif
106
107 #if ENABLE(NOTIFICATIONS)
108     encoder << notificationPermissions;
109 #endif
110
111     encoder << plugInAutoStartOrigins;
112     encoder << memoryCacheDisabled;
113     encoder << attrStyleEnabled;
114
115 #if ENABLE(SERVICE_CONTROLS)
116     encoder << hasImageServices;
117     encoder << hasSelectionServices;
118     encoder << hasRichContentServices;
119 #endif
120
121 #if ENABLE(NETSCAPE_PLUGIN_API)
122     encoder << pluginLoadClientPolicies;
123 #endif
124
125 #if PLATFORM(COCOA)
126     IPC::encode(encoder, networkATSContext.get());
127 #endif
128
129 #if PLATFORM(WAYLAND)
130     encoder << waylandCompositorDisplayName;
131 #endif
132
133 #if USE(SOUP)
134     encoder << proxySettings;
135 #endif
136
137 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
138     encoder << shouldLogUserInteraction;
139 #endif
140
141 #if PLATFORM(COCOA)
142     encoder << mediaMIMETypes;
143     encoder << screenProperties;
144 #endif
145
146 #if PLATFORM(MAC)
147     encoder << useOverlayScrollbars;
148 #endif
149
150 #if USE(WPE_RENDERER)
151     encoder << isServiceWorkerProcess;
152     encoder << hostClientFileDescriptor;
153     encoder << implementationLibraryName;
154 #endif
155
156     encoder << websiteDataStoreParameters;
157     
158 #if PLATFORM(IOS)
159     encoder << compilerServiceExtensionHandle;
160     encoder << contentFilterExtensionHandle;
161     encoder << frontboardServiceExtensionHandle;
162 #endif
163
164 #if PLATFORM(IOS_FAMILY)
165     encoder << diagnosticsExtensionHandle;
166     encoder << runningboardExtensionHandle;
167     encoder << dynamicMachExtensionHandles;
168     encoder << dynamicIOKitExtensionHandles;
169 #endif
170
171 #if PLATFORM(COCOA)
172     encoder << neHelperExtensionHandle;
173     encoder << neSessionManagerExtensionHandle;
174     encoder << mapDBExtensionHandle;
175     encoder << systemHasBattery;
176 #endif
177
178 #if PLATFORM(IOS_FAMILY)
179     encoder << currentUserInterfaceIdiomIsPad;
180     encoder << supportsPictureInPicture;
181     encoder << cssValueToSystemColorMap;
182     encoder << focusRingColor;
183     encoder << localizedDeviceModel;
184 #endif
185
186 #if PLATFORM(COCOA)
187     // FIXME(207716): The following should be removed when the GPU process is complete.
188     encoder << mediaExtensionHandles;
189 #if ENABLE(CFPREFS_DIRECT_MODE)
190     encoder << preferencesExtensionHandles;
191     encoder << encodedGlobalPreferences;
192 #endif
193 #endif
194
195 #if PLATFORM(GTK)
196     encoder << useSystemAppearanceForScrollbars;
197 #endif
198 }
199
200 bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreationParameters& parameters)
201 {
202     if (!decoder.decode(parameters.injectedBundlePath))
203         return false;
204     
205     Optional<SandboxExtension::Handle> injectedBundlePathExtensionHandle;
206     decoder >> injectedBundlePathExtensionHandle;
207     if (!injectedBundlePathExtensionHandle)
208         return false;
209     parameters.injectedBundlePathExtensionHandle = WTFMove(*injectedBundlePathExtensionHandle);
210
211     Optional<SandboxExtension::HandleArray> additionalSandboxExtensionHandles;
212     decoder >> additionalSandboxExtensionHandles;
213     if (!additionalSandboxExtensionHandles)
214         return false;
215     parameters.additionalSandboxExtensionHandles = WTFMove(*additionalSandboxExtensionHandles);
216     if (!decoder.decode(parameters.initializationUserData))
217         return false;
218
219 #if PLATFORM(IOS_FAMILY)
220     
221     Optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
222     decoder >> cookieStorageDirectoryExtensionHandle;
223     if (!cookieStorageDirectoryExtensionHandle)
224         return false;
225     parameters.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
226
227     Optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
228     decoder >> containerCachesDirectoryExtensionHandle;
229     if (!containerCachesDirectoryExtensionHandle)
230         return false;
231     parameters.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
232
233     Optional<SandboxExtension::Handle> containerTemporaryDirectoryExtensionHandle;
234     decoder >> containerTemporaryDirectoryExtensionHandle;
235     if (!containerTemporaryDirectoryExtensionHandle)
236         return false;
237     parameters.containerTemporaryDirectoryExtensionHandle = WTFMove(*containerTemporaryDirectoryExtensionHandle);
238
239 #endif
240     if (!decoder.decode(parameters.webCoreLoggingChannels))
241         return false;
242     if (!decoder.decode(parameters.webKitLoggingChannels))
243         return false;
244
245 #if ENABLE(MEDIA_STREAM)
246
247     Optional<SandboxExtension::Handle> audioCaptureExtensionHandle;
248     decoder >> audioCaptureExtensionHandle;
249     if (!audioCaptureExtensionHandle)
250         return false;
251     parameters.audioCaptureExtensionHandle = WTFMove(*audioCaptureExtensionHandle);
252 #endif
253     if (!decoder.decode(parameters.urlSchemesRegisteredAsEmptyDocument))
254         return false;
255     if (!decoder.decode(parameters.urlSchemesRegisteredAsSecure))
256         return false;
257     if (!decoder.decode(parameters.urlSchemesRegisteredAsBypassingContentSecurityPolicy))
258         return false;
259     if (!decoder.decode(parameters.urlSchemesForWhichDomainRelaxationIsForbidden))
260         return false;
261     if (!decoder.decode(parameters.urlSchemesRegisteredAsLocal))
262         return false;
263     if (!decoder.decode(parameters.urlSchemesRegisteredAsNoAccess))
264         return false;
265     if (!decoder.decode(parameters.urlSchemesRegisteredAsDisplayIsolated))
266         return false;
267     if (!decoder.decode(parameters.urlSchemesRegisteredAsCORSEnabled))
268         return false;
269     if (!decoder.decode(parameters.urlSchemesRegisteredAsAlwaysRevalidated))
270         return false;
271     if (!decoder.decode(parameters.urlSchemesRegisteredAsCachePartitioned))
272         return false;
273     if (!decoder.decode(parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
274         return false;
275     if (!decoder.decodeEnum(parameters.cacheModel))
276         return false;
277     if (!decoder.decode(parameters.shouldAlwaysUseComplexTextCodePath))
278         return false;
279     if (!decoder.decode(parameters.shouldEnableMemoryPressureReliefLogging))
280         return false;
281     if (!decoder.decode(parameters.shouldSuppressMemoryPressureHandler))
282         return false;
283     if (!decoder.decode(parameters.shouldUseFontSmoothing))
284         return false;
285     if (!decoder.decode(parameters.fontWhitelist))
286         return false;
287     if (!decoder.decode(parameters.terminationTimeout))
288         return false;
289     if (!decoder.decode(parameters.languages))
290         return false;
291 #if USE(GSTREAMER)
292     if (!decoder.decode(parameters.gstreamerOptions))
293         return false;
294 #endif
295     if (!decoder.decode(parameters.textCheckerState))
296         return false;
297     if (!decoder.decode(parameters.fullKeyboardAccessEnabled))
298         return false;
299     if (!decoder.decode(parameters.defaultRequestTimeoutInterval))
300         return false;
301     if (!decoder.decode(parameters.backForwardCacheCapacity))
302         return false;
303 #if PLATFORM(COCOA)
304     if (!decoder.decode(parameters.uiProcessBundleIdentifier))
305         return false;
306     if (!decoder.decode(parameters.uiProcessSDKVersion))
307         return false;
308 #endif
309     if (!decoder.decode(parameters.presentingApplicationPID))
310         return false;
311 #if PLATFORM(COCOA)
312     if (!decoder.decode(parameters.accessibilityEnhancedUserInterfaceEnabled))
313         return false;
314     if (!decoder.decode(parameters.acceleratedCompositingPort))
315         return false;
316     if (!decoder.decode(parameters.uiProcessBundleResourcePath))
317         return false;
318     
319     Optional<SandboxExtension::Handle> uiProcessBundleResourcePathExtensionHandle;
320     decoder >> uiProcessBundleResourcePathExtensionHandle;
321     if (!uiProcessBundleResourcePathExtensionHandle)
322         return false;
323     parameters.uiProcessBundleResourcePathExtensionHandle = WTFMove(*uiProcessBundleResourcePathExtensionHandle);
324
325     if (!decoder.decode(parameters.shouldEnableJIT))
326         return false;
327     if (!decoder.decode(parameters.shouldEnableFTLJIT))
328         return false;
329
330     bool hasBundleParameterData;
331     if (!decoder.decode(hasBundleParameterData))
332         return false;
333
334     if (hasBundleParameterData) {
335         IPC::DataReference dataReference;
336         if (!decoder.decode(dataReference))
337             return false;
338
339         parameters.bundleParameterData = API::Data::create(dataReference.data(), dataReference.size());
340     }
341 #endif
342
343 #if ENABLE(NOTIFICATIONS)
344     if (!decoder.decode(parameters.notificationPermissions))
345         return false;
346 #endif
347
348     if (!decoder.decode(parameters.plugInAutoStartOrigins))
349         return false;
350     if (!decoder.decode(parameters.memoryCacheDisabled))
351         return false;
352     if (!decoder.decode(parameters.attrStyleEnabled))
353         return false;
354
355 #if ENABLE(SERVICE_CONTROLS)
356     if (!decoder.decode(parameters.hasImageServices))
357         return false;
358     if (!decoder.decode(parameters.hasSelectionServices))
359         return false;
360     if (!decoder.decode(parameters.hasRichContentServices))
361         return false;
362 #endif
363
364 #if ENABLE(NETSCAPE_PLUGIN_API)
365     if (!decoder.decode(parameters.pluginLoadClientPolicies))
366         return false;
367 #endif
368
369 #if PLATFORM(COCOA)
370     if (!IPC::decode(decoder, parameters.networkATSContext))
371         return false;
372 #endif
373
374 #if PLATFORM(WAYLAND)
375     if (!decoder.decode(parameters.waylandCompositorDisplayName))
376         return false;
377 #endif
378
379 #if USE(SOUP)
380     if (!decoder.decode(parameters.proxySettings))
381         return false;
382 #endif
383
384 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
385     if (!decoder.decode(parameters.shouldLogUserInteraction))
386         return false;
387 #endif
388
389 #if PLATFORM(COCOA)
390     if (!decoder.decode(parameters.mediaMIMETypes))
391         return false;
392
393     Optional<WebCore::ScreenProperties> screenProperties;
394     decoder >> screenProperties;
395     if (!screenProperties)
396         return false;
397     parameters.screenProperties = WTFMove(*screenProperties);
398 #endif
399
400 #if PLATFORM(MAC)
401     if (!decoder.decode(parameters.useOverlayScrollbars))
402         return false;
403 #endif
404
405 #if USE(WPE_RENDERER)
406     if (!decoder.decode(parameters.isServiceWorkerProcess))
407         return false;
408     if (!decoder.decode(parameters.hostClientFileDescriptor))
409         return false;
410     if (!decoder.decode(parameters.implementationLibraryName))
411         return false;
412 #endif
413
414     Optional<Optional<WebProcessDataStoreParameters>> websiteDataStoreParameters;
415     decoder >> websiteDataStoreParameters;
416     if (!websiteDataStoreParameters)
417         return false;
418     parameters.websiteDataStoreParameters = WTFMove(*websiteDataStoreParameters);
419
420 #if PLATFORM(IOS)
421     Optional<Optional<SandboxExtension::Handle>> compilerServiceExtensionHandle;
422     decoder >> compilerServiceExtensionHandle;
423     if (!compilerServiceExtensionHandle)
424         return false;
425     parameters.compilerServiceExtensionHandle = WTFMove(*compilerServiceExtensionHandle);
426
427     Optional<Optional<SandboxExtension::Handle>> contentFilterExtensionHandle;
428     decoder >> contentFilterExtensionHandle;
429     if (!contentFilterExtensionHandle)
430         return false;
431     parameters.contentFilterExtensionHandle = WTFMove(*contentFilterExtensionHandle);
432
433     Optional<Optional<SandboxExtension::Handle>> frontboardServiceExtensionHandle;
434     decoder >> frontboardServiceExtensionHandle;
435     if (!frontboardServiceExtensionHandle)
436         return false;
437     parameters.frontboardServiceExtensionHandle = WTFMove(*frontboardServiceExtensionHandle);
438 #endif
439
440 #if PLATFORM(IOS_FAMILY)
441     Optional<Optional<SandboxExtension::Handle>> diagnosticsExtensionHandle;
442     decoder >> diagnosticsExtensionHandle;
443     if (!diagnosticsExtensionHandle)
444         return false;
445     parameters.diagnosticsExtensionHandle = WTFMove(*diagnosticsExtensionHandle);
446
447     Optional<Optional<SandboxExtension::Handle>> runningboardExtensionHandle;
448     decoder >> runningboardExtensionHandle;
449     if (!runningboardExtensionHandle)
450         return false;
451     parameters.runningboardExtensionHandle = WTFMove(*runningboardExtensionHandle);
452
453     Optional<SandboxExtension::HandleArray> dynamicMachExtensionHandles;
454     decoder >> dynamicMachExtensionHandles;
455     if (!dynamicMachExtensionHandles)
456         return false;
457     parameters.dynamicMachExtensionHandles = WTFMove(*dynamicMachExtensionHandles);
458
459     Optional<SandboxExtension::HandleArray> dynamicIOKitExtensionHandles;
460     decoder >> dynamicIOKitExtensionHandles;
461     if (!dynamicIOKitExtensionHandles)
462         return false;
463     parameters.dynamicIOKitExtensionHandles = WTFMove(*dynamicIOKitExtensionHandles);
464 #endif
465
466 #if PLATFORM(COCOA)
467     Optional<Optional<SandboxExtension::Handle>> neHelperExtensionHandle;
468     decoder >> neHelperExtensionHandle;
469     if (!neHelperExtensionHandle)
470         return false;
471     parameters.neHelperExtensionHandle = WTFMove(*neHelperExtensionHandle);
472
473     Optional<Optional<SandboxExtension::Handle>> neSessionManagerExtensionHandle;
474     decoder >> neSessionManagerExtensionHandle;
475     if (!neSessionManagerExtensionHandle)
476         return false;
477     parameters.neSessionManagerExtensionHandle = WTFMove(*neSessionManagerExtensionHandle);
478
479     Optional<Optional<SandboxExtension::Handle>> mapDBExtensionHandle;
480     decoder >> mapDBExtensionHandle;
481     if (!mapDBExtensionHandle)
482         return false;
483     parameters.mapDBExtensionHandle = WTFMove(*mapDBExtensionHandle);
484
485     Optional<bool> systemHasBattery;
486     decoder >> systemHasBattery;
487     if (!systemHasBattery)
488         return false;
489     parameters.systemHasBattery = WTFMove(*systemHasBattery);
490 #endif
491
492 #if PLATFORM(IOS_FAMILY)
493     if (!decoder.decode(parameters.currentUserInterfaceIdiomIsPad))
494         return false;
495
496     if (!decoder.decode(parameters.supportsPictureInPicture))
497         return false;
498
499     Optional<WebCore::RenderThemeIOS::CSSValueToSystemColorMap> cssValueToSystemColorMap;
500     decoder >> cssValueToSystemColorMap;
501     if (!cssValueToSystemColorMap)
502         return false;
503     parameters.cssValueToSystemColorMap = WTFMove(*cssValueToSystemColorMap);
504
505     Optional<WebCore::Color> focusRingColor;
506     decoder >> focusRingColor;
507     if (!focusRingColor)
508         return false;
509     parameters.focusRingColor = WTFMove(*focusRingColor);
510     
511     if (!decoder.decode(parameters.localizedDeviceModel))
512         return false;
513 #endif
514
515 #if PLATFORM(COCOA)
516     // FIXME(207716): The following should be removed when the GPU process is complete.
517     Optional<SandboxExtension::HandleArray> mediaExtensionHandles;
518     decoder >> mediaExtensionHandles;
519     if (!mediaExtensionHandles)
520         return false;
521     parameters.mediaExtensionHandles = WTFMove(*mediaExtensionHandles);
522     // FIXME(207716): End region to remove.
523
524 #if ENABLE(CFPREFS_DIRECT_MODE)
525     Optional<Optional<SandboxExtension::HandleArray>> preferencesExtensionHandles;
526     decoder >> preferencesExtensionHandles;
527     if (!preferencesExtensionHandles)
528         return false;
529     parameters.preferencesExtensionHandles = WTFMove(*preferencesExtensionHandles);
530
531     Optional<String> encodedGlobalPreferences;
532     decoder >> encodedGlobalPreferences;
533     if (!encodedGlobalPreferences)
534         return false;
535     parameters.encodedGlobalPreferences = WTFMove(*encodedGlobalPreferences);
536 #endif
537 #endif
538
539 #if PLATFORM(GTK)
540     Optional<bool> useSystemAppearanceForScrollbars;
541     decoder >> useSystemAppearanceForScrollbars;
542     if (!useSystemAppearanceForScrollbars)
543         return false;
544     parameters.useSystemAppearanceForScrollbars = WTFMove(*useSystemAppearanceForScrollbars);
545 #endif
546
547     return true;
548 }
549
550 } // namespace WebKit