Unreviewed, reverting r260769.
[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     encoder << mimeTypesMap;
177 #endif
178
179 #if PLATFORM(IOS_FAMILY)
180     encoder << currentUserInterfaceIdiomIsPad;
181     encoder << supportsPictureInPicture;
182     encoder << cssValueToSystemColorMap;
183     encoder << focusRingColor;
184     encoder << localizedDeviceModel;
185 #endif
186
187 #if PLATFORM(COCOA)
188     // FIXME(207716): The following should be removed when the GPU process is complete.
189     encoder << mediaExtensionHandles;
190 #if ENABLE(CFPREFS_DIRECT_MODE)
191     encoder << preferencesExtensionHandles;
192     encoder << encodedGlobalPreferences;
193 #endif
194 #endif
195
196 #if PLATFORM(GTK)
197     encoder << useSystemAppearanceForScrollbars;
198 #endif
199 }
200
201 bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreationParameters& parameters)
202 {
203     if (!decoder.decode(parameters.injectedBundlePath))
204         return false;
205     
206     Optional<SandboxExtension::Handle> injectedBundlePathExtensionHandle;
207     decoder >> injectedBundlePathExtensionHandle;
208     if (!injectedBundlePathExtensionHandle)
209         return false;
210     parameters.injectedBundlePathExtensionHandle = WTFMove(*injectedBundlePathExtensionHandle);
211
212     Optional<SandboxExtension::HandleArray> additionalSandboxExtensionHandles;
213     decoder >> additionalSandboxExtensionHandles;
214     if (!additionalSandboxExtensionHandles)
215         return false;
216     parameters.additionalSandboxExtensionHandles = WTFMove(*additionalSandboxExtensionHandles);
217     if (!decoder.decode(parameters.initializationUserData))
218         return false;
219
220 #if PLATFORM(IOS_FAMILY)
221     
222     Optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
223     decoder >> cookieStorageDirectoryExtensionHandle;
224     if (!cookieStorageDirectoryExtensionHandle)
225         return false;
226     parameters.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
227
228     Optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
229     decoder >> containerCachesDirectoryExtensionHandle;
230     if (!containerCachesDirectoryExtensionHandle)
231         return false;
232     parameters.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
233
234     Optional<SandboxExtension::Handle> containerTemporaryDirectoryExtensionHandle;
235     decoder >> containerTemporaryDirectoryExtensionHandle;
236     if (!containerTemporaryDirectoryExtensionHandle)
237         return false;
238     parameters.containerTemporaryDirectoryExtensionHandle = WTFMove(*containerTemporaryDirectoryExtensionHandle);
239
240 #endif
241     if (!decoder.decode(parameters.webCoreLoggingChannels))
242         return false;
243     if (!decoder.decode(parameters.webKitLoggingChannels))
244         return false;
245
246 #if ENABLE(MEDIA_STREAM)
247
248     Optional<SandboxExtension::Handle> audioCaptureExtensionHandle;
249     decoder >> audioCaptureExtensionHandle;
250     if (!audioCaptureExtensionHandle)
251         return false;
252     parameters.audioCaptureExtensionHandle = WTFMove(*audioCaptureExtensionHandle);
253 #endif
254     if (!decoder.decode(parameters.urlSchemesRegisteredAsEmptyDocument))
255         return false;
256     if (!decoder.decode(parameters.urlSchemesRegisteredAsSecure))
257         return false;
258     if (!decoder.decode(parameters.urlSchemesRegisteredAsBypassingContentSecurityPolicy))
259         return false;
260     if (!decoder.decode(parameters.urlSchemesForWhichDomainRelaxationIsForbidden))
261         return false;
262     if (!decoder.decode(parameters.urlSchemesRegisteredAsLocal))
263         return false;
264     if (!decoder.decode(parameters.urlSchemesRegisteredAsNoAccess))
265         return false;
266     if (!decoder.decode(parameters.urlSchemesRegisteredAsDisplayIsolated))
267         return false;
268     if (!decoder.decode(parameters.urlSchemesRegisteredAsCORSEnabled))
269         return false;
270     if (!decoder.decode(parameters.urlSchemesRegisteredAsAlwaysRevalidated))
271         return false;
272     if (!decoder.decode(parameters.urlSchemesRegisteredAsCachePartitioned))
273         return false;
274     if (!decoder.decode(parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
275         return false;
276     if (!decoder.decodeEnum(parameters.cacheModel))
277         return false;
278     if (!decoder.decode(parameters.shouldAlwaysUseComplexTextCodePath))
279         return false;
280     if (!decoder.decode(parameters.shouldEnableMemoryPressureReliefLogging))
281         return false;
282     if (!decoder.decode(parameters.shouldSuppressMemoryPressureHandler))
283         return false;
284     if (!decoder.decode(parameters.shouldUseFontSmoothing))
285         return false;
286     if (!decoder.decode(parameters.fontWhitelist))
287         return false;
288     if (!decoder.decode(parameters.terminationTimeout))
289         return false;
290     if (!decoder.decode(parameters.languages))
291         return false;
292 #if USE(GSTREAMER)
293     if (!decoder.decode(parameters.gstreamerOptions))
294         return false;
295 #endif
296     if (!decoder.decode(parameters.textCheckerState))
297         return false;
298     if (!decoder.decode(parameters.fullKeyboardAccessEnabled))
299         return false;
300     if (!decoder.decode(parameters.defaultRequestTimeoutInterval))
301         return false;
302     if (!decoder.decode(parameters.backForwardCacheCapacity))
303         return false;
304 #if PLATFORM(COCOA)
305     if (!decoder.decode(parameters.uiProcessBundleIdentifier))
306         return false;
307     if (!decoder.decode(parameters.uiProcessSDKVersion))
308         return false;
309 #endif
310     if (!decoder.decode(parameters.presentingApplicationPID))
311         return false;
312 #if PLATFORM(COCOA)
313     if (!decoder.decode(parameters.accessibilityEnhancedUserInterfaceEnabled))
314         return false;
315     if (!decoder.decode(parameters.acceleratedCompositingPort))
316         return false;
317     if (!decoder.decode(parameters.uiProcessBundleResourcePath))
318         return false;
319     
320     Optional<SandboxExtension::Handle> uiProcessBundleResourcePathExtensionHandle;
321     decoder >> uiProcessBundleResourcePathExtensionHandle;
322     if (!uiProcessBundleResourcePathExtensionHandle)
323         return false;
324     parameters.uiProcessBundleResourcePathExtensionHandle = WTFMove(*uiProcessBundleResourcePathExtensionHandle);
325
326     if (!decoder.decode(parameters.shouldEnableJIT))
327         return false;
328     if (!decoder.decode(parameters.shouldEnableFTLJIT))
329         return false;
330
331     bool hasBundleParameterData;
332     if (!decoder.decode(hasBundleParameterData))
333         return false;
334
335     if (hasBundleParameterData) {
336         IPC::DataReference dataReference;
337         if (!decoder.decode(dataReference))
338             return false;
339
340         parameters.bundleParameterData = API::Data::create(dataReference.data(), dataReference.size());
341     }
342 #endif
343
344 #if ENABLE(NOTIFICATIONS)
345     if (!decoder.decode(parameters.notificationPermissions))
346         return false;
347 #endif
348
349     if (!decoder.decode(parameters.plugInAutoStartOrigins))
350         return false;
351     if (!decoder.decode(parameters.memoryCacheDisabled))
352         return false;
353     if (!decoder.decode(parameters.attrStyleEnabled))
354         return false;
355
356 #if ENABLE(SERVICE_CONTROLS)
357     if (!decoder.decode(parameters.hasImageServices))
358         return false;
359     if (!decoder.decode(parameters.hasSelectionServices))
360         return false;
361     if (!decoder.decode(parameters.hasRichContentServices))
362         return false;
363 #endif
364
365 #if ENABLE(NETSCAPE_PLUGIN_API)
366     if (!decoder.decode(parameters.pluginLoadClientPolicies))
367         return false;
368 #endif
369
370 #if PLATFORM(COCOA)
371     if (!IPC::decode(decoder, parameters.networkATSContext))
372         return false;
373 #endif
374
375 #if PLATFORM(WAYLAND)
376     if (!decoder.decode(parameters.waylandCompositorDisplayName))
377         return false;
378 #endif
379
380 #if USE(SOUP)
381     if (!decoder.decode(parameters.proxySettings))
382         return false;
383 #endif
384
385 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
386     if (!decoder.decode(parameters.shouldLogUserInteraction))
387         return false;
388 #endif
389
390 #if PLATFORM(COCOA)
391     if (!decoder.decode(parameters.mediaMIMETypes))
392         return false;
393
394     Optional<WebCore::ScreenProperties> screenProperties;
395     decoder >> screenProperties;
396     if (!screenProperties)
397         return false;
398     parameters.screenProperties = WTFMove(*screenProperties);
399 #endif
400
401 #if PLATFORM(MAC)
402     if (!decoder.decode(parameters.useOverlayScrollbars))
403         return false;
404 #endif
405
406 #if USE(WPE_RENDERER)
407     if (!decoder.decode(parameters.isServiceWorkerProcess))
408         return false;
409     if (!decoder.decode(parameters.hostClientFileDescriptor))
410         return false;
411     if (!decoder.decode(parameters.implementationLibraryName))
412         return false;
413 #endif
414
415     Optional<Optional<WebProcessDataStoreParameters>> websiteDataStoreParameters;
416     decoder >> websiteDataStoreParameters;
417     if (!websiteDataStoreParameters)
418         return false;
419     parameters.websiteDataStoreParameters = WTFMove(*websiteDataStoreParameters);
420
421 #if PLATFORM(IOS)
422     Optional<Optional<SandboxExtension::Handle>> compilerServiceExtensionHandle;
423     decoder >> compilerServiceExtensionHandle;
424     if (!compilerServiceExtensionHandle)
425         return false;
426     parameters.compilerServiceExtensionHandle = WTFMove(*compilerServiceExtensionHandle);
427
428     Optional<Optional<SandboxExtension::Handle>> contentFilterExtensionHandle;
429     decoder >> contentFilterExtensionHandle;
430     if (!contentFilterExtensionHandle)
431         return false;
432     parameters.contentFilterExtensionHandle = WTFMove(*contentFilterExtensionHandle);
433
434     Optional<Optional<SandboxExtension::Handle>> frontboardServiceExtensionHandle;
435     decoder >> frontboardServiceExtensionHandle;
436     if (!frontboardServiceExtensionHandle)
437         return false;
438     parameters.frontboardServiceExtensionHandle = WTFMove(*frontboardServiceExtensionHandle);
439 #endif
440
441 #if PLATFORM(IOS_FAMILY)
442     Optional<Optional<SandboxExtension::Handle>> diagnosticsExtensionHandle;
443     decoder >> diagnosticsExtensionHandle;
444     if (!diagnosticsExtensionHandle)
445         return false;
446     parameters.diagnosticsExtensionHandle = WTFMove(*diagnosticsExtensionHandle);
447
448     Optional<Optional<SandboxExtension::Handle>> runningboardExtensionHandle;
449     decoder >> runningboardExtensionHandle;
450     if (!runningboardExtensionHandle)
451         return false;
452     parameters.runningboardExtensionHandle = WTFMove(*runningboardExtensionHandle);
453
454     Optional<SandboxExtension::HandleArray> dynamicMachExtensionHandles;
455     decoder >> dynamicMachExtensionHandles;
456     if (!dynamicMachExtensionHandles)
457         return false;
458     parameters.dynamicMachExtensionHandles = WTFMove(*dynamicMachExtensionHandles);
459
460     Optional<SandboxExtension::HandleArray> dynamicIOKitExtensionHandles;
461     decoder >> dynamicIOKitExtensionHandles;
462     if (!dynamicIOKitExtensionHandles)
463         return false;
464     parameters.dynamicIOKitExtensionHandles = WTFMove(*dynamicIOKitExtensionHandles);
465 #endif
466
467 #if PLATFORM(COCOA)
468     Optional<Optional<SandboxExtension::Handle>> neHelperExtensionHandle;
469     decoder >> neHelperExtensionHandle;
470     if (!neHelperExtensionHandle)
471         return false;
472     parameters.neHelperExtensionHandle = WTFMove(*neHelperExtensionHandle);
473
474     Optional<Optional<SandboxExtension::Handle>> neSessionManagerExtensionHandle;
475     decoder >> neSessionManagerExtensionHandle;
476     if (!neSessionManagerExtensionHandle)
477         return false;
478     parameters.neSessionManagerExtensionHandle = WTFMove(*neSessionManagerExtensionHandle);
479
480     Optional<Optional<SandboxExtension::Handle>> mapDBExtensionHandle;
481     decoder >> mapDBExtensionHandle;
482     if (!mapDBExtensionHandle)
483         return false;
484     parameters.mapDBExtensionHandle = WTFMove(*mapDBExtensionHandle);
485
486     Optional<bool> systemHasBattery;
487     decoder >> systemHasBattery;
488     if (!systemHasBattery)
489         return false;
490     parameters.systemHasBattery = WTFMove(*systemHasBattery);
491
492     Optional<Optional<HashMap<String, Vector<String>, ASCIICaseInsensitiveHash>>> mimeTypesMap;
493     decoder >> mimeTypesMap;
494     if (!mimeTypesMap)
495         return false;
496     parameters.mimeTypesMap = WTFMove(*mimeTypesMap);
497 #endif
498
499 #if PLATFORM(IOS_FAMILY)
500     if (!decoder.decode(parameters.currentUserInterfaceIdiomIsPad))
501         return false;
502
503     if (!decoder.decode(parameters.supportsPictureInPicture))
504         return false;
505
506     Optional<WebCore::RenderThemeIOS::CSSValueToSystemColorMap> cssValueToSystemColorMap;
507     decoder >> cssValueToSystemColorMap;
508     if (!cssValueToSystemColorMap)
509         return false;
510     parameters.cssValueToSystemColorMap = WTFMove(*cssValueToSystemColorMap);
511
512     Optional<WebCore::Color> focusRingColor;
513     decoder >> focusRingColor;
514     if (!focusRingColor)
515         return false;
516     parameters.focusRingColor = WTFMove(*focusRingColor);
517     
518     if (!decoder.decode(parameters.localizedDeviceModel))
519         return false;
520 #endif
521
522 #if PLATFORM(COCOA)
523     // FIXME(207716): The following should be removed when the GPU process is complete.
524     Optional<SandboxExtension::HandleArray> mediaExtensionHandles;
525     decoder >> mediaExtensionHandles;
526     if (!mediaExtensionHandles)
527         return false;
528     parameters.mediaExtensionHandles = WTFMove(*mediaExtensionHandles);
529     // FIXME(207716): End region to remove.
530
531 #if ENABLE(CFPREFS_DIRECT_MODE)
532     Optional<Optional<SandboxExtension::HandleArray>> preferencesExtensionHandles;
533     decoder >> preferencesExtensionHandles;
534     if (!preferencesExtensionHandles)
535         return false;
536     parameters.preferencesExtensionHandles = WTFMove(*preferencesExtensionHandles);
537
538     Optional<String> encodedGlobalPreferences;
539     decoder >> encodedGlobalPreferences;
540     if (!encodedGlobalPreferences)
541         return false;
542     parameters.encodedGlobalPreferences = WTFMove(*encodedGlobalPreferences);
543 #endif
544 #endif
545
546 #if PLATFORM(GTK)
547     Optional<bool> useSystemAppearanceForScrollbars;
548     decoder >> useSystemAppearanceForScrollbars;
549     if (!useSystemAppearanceForScrollbars)
550         return false;
551     parameters.useSystemAppearanceForScrollbars = WTFMove(*useSystemAppearanceForScrollbars);
552 #endif
553
554     return true;
555 }
556
557 } // namespace WebKit