48667f7fe8e441277dadc60cdda1cb66266164fc
[WebKit.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(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     encoder << shouldCaptureAudioInUIProcess;
64     encoder << shouldCaptureAudioInGPUProcess;
65     encoder << shouldCaptureVideoInUIProcess;
66     encoder << shouldCaptureDisplayInUIProcess;
67 #endif
68     encoder << urlSchemesRegisteredAsEmptyDocument;
69     encoder << urlSchemesRegisteredAsSecure;
70     encoder << urlSchemesRegisteredAsBypassingContentSecurityPolicy;
71     encoder << urlSchemesForWhichDomainRelaxationIsForbidden;
72     encoder << urlSchemesRegisteredAsLocal;
73     encoder << urlSchemesRegisteredAsNoAccess;
74     encoder << urlSchemesRegisteredAsDisplayIsolated;
75     encoder << urlSchemesRegisteredAsCORSEnabled;
76     encoder << urlSchemesRegisteredAsAlwaysRevalidated;
77     encoder << urlSchemesRegisteredAsCachePartitioned;
78     encoder << urlSchemesServiceWorkersCanHandle;
79     encoder << urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest;
80     encoder.encodeEnum(cacheModel);
81     encoder << shouldAlwaysUseComplexTextCodePath;
82     encoder << shouldEnableMemoryPressureReliefLogging;
83     encoder << shouldSuppressMemoryPressureHandler;
84     encoder << shouldUseFontSmoothing;
85     encoder << fontWhitelist;
86     encoder << terminationTimeout;
87     encoder << languages;
88 #if USE(GSTREAMER)
89     encoder << gstreamerOptions;
90 #endif
91     encoder << textCheckerState;
92     encoder << fullKeyboardAccessEnabled;
93     encoder << defaultRequestTimeoutInterval;
94     encoder << backForwardCacheCapacity;
95 #if PLATFORM(COCOA)
96     encoder << uiProcessBundleIdentifier;
97     encoder << uiProcessSDKVersion;
98 #endif
99     encoder << presentingApplicationPID;
100 #if PLATFORM(COCOA)
101     encoder << accessibilityEnhancedUserInterfaceEnabled;
102     encoder << acceleratedCompositingPort;
103     encoder << uiProcessBundleResourcePath;
104     encoder << uiProcessBundleResourcePathExtensionHandle;
105     encoder << shouldEnableJIT;
106     encoder << shouldEnableFTLJIT;
107     encoder << !!bundleParameterData;
108     if (bundleParameterData)
109         encoder << bundleParameterData->dataReference();
110 #endif
111
112 #if ENABLE(NOTIFICATIONS)
113     encoder << notificationPermissions;
114 #endif
115
116     encoder << plugInAutoStartOrigins;
117     encoder << memoryCacheDisabled;
118     encoder << attrStyleEnabled;
119
120 #if ENABLE(SERVICE_CONTROLS)
121     encoder << hasImageServices;
122     encoder << hasSelectionServices;
123     encoder << hasRichContentServices;
124 #endif
125
126 #if ENABLE(NETSCAPE_PLUGIN_API)
127     encoder << pluginLoadClientPolicies;
128 #endif
129
130 #if PLATFORM(COCOA)
131     IPC::encode(encoder, networkATSContext.get());
132 #endif
133
134 #if PLATFORM(WAYLAND)
135     encoder << waylandCompositorDisplayName;
136 #endif
137
138 #if USE(SOUP)
139     encoder << proxySettings;
140 #endif
141
142 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
143     encoder << shouldLogUserInteraction;
144 #endif
145
146 #if PLATFORM(COCOA)
147     encoder << mediaMIMETypes;
148 #endif
149
150 #if PLATFORM(MAC)
151     encoder << screenProperties;
152     encoder << useOverlayScrollbars;
153 #endif
154
155 #if USE(WPE_RENDERER)
156     encoder << isServiceWorkerProcess;
157     encoder << hostClientFileDescriptor;
158     encoder << implementationLibraryName;
159 #endif
160
161     encoder << websiteDataStoreParameters;
162     
163 #if PLATFORM(IOS)
164     encoder << compilerServiceExtensionHandle;
165 #endif
166     
167 #if PLATFORM(COCOA)
168     encoder << neHelperExtensionHandle;
169     encoder << neSessionManagerExtensionHandle;
170 #endif
171 }
172
173 bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreationParameters& parameters)
174 {
175     if (!decoder.decode(parameters.injectedBundlePath))
176         return false;
177     
178     Optional<SandboxExtension::Handle> injectedBundlePathExtensionHandle;
179     decoder >> injectedBundlePathExtensionHandle;
180     if (!injectedBundlePathExtensionHandle)
181         return false;
182     parameters.injectedBundlePathExtensionHandle = WTFMove(*injectedBundlePathExtensionHandle);
183
184     Optional<SandboxExtension::HandleArray> additionalSandboxExtensionHandles;
185     decoder >> additionalSandboxExtensionHandles;
186     if (!additionalSandboxExtensionHandles)
187         return false;
188     parameters.additionalSandboxExtensionHandles = WTFMove(*additionalSandboxExtensionHandles);
189     if (!decoder.decode(parameters.initializationUserData))
190         return false;
191
192 #if PLATFORM(IOS_FAMILY)
193     
194     Optional<SandboxExtension::Handle> cookieStorageDirectoryExtensionHandle;
195     decoder >> cookieStorageDirectoryExtensionHandle;
196     if (!cookieStorageDirectoryExtensionHandle)
197         return false;
198     parameters.cookieStorageDirectoryExtensionHandle = WTFMove(*cookieStorageDirectoryExtensionHandle);
199
200     Optional<SandboxExtension::Handle> containerCachesDirectoryExtensionHandle;
201     decoder >> containerCachesDirectoryExtensionHandle;
202     if (!containerCachesDirectoryExtensionHandle)
203         return false;
204     parameters.containerCachesDirectoryExtensionHandle = WTFMove(*containerCachesDirectoryExtensionHandle);
205
206     Optional<SandboxExtension::Handle> containerTemporaryDirectoryExtensionHandle;
207     decoder >> containerTemporaryDirectoryExtensionHandle;
208     if (!containerTemporaryDirectoryExtensionHandle)
209         return false;
210     parameters.containerTemporaryDirectoryExtensionHandle = WTFMove(*containerTemporaryDirectoryExtensionHandle);
211
212 #endif
213     if (!decoder.decode(parameters.webCoreLoggingChannels))
214         return false;
215     if (!decoder.decode(parameters.webKitLoggingChannels))
216         return false;
217
218 #if ENABLE(MEDIA_STREAM)
219
220     Optional<SandboxExtension::Handle> audioCaptureExtensionHandle;
221     decoder >> audioCaptureExtensionHandle;
222     if (!audioCaptureExtensionHandle)
223         return false;
224     parameters.audioCaptureExtensionHandle = WTFMove(*audioCaptureExtensionHandle);
225
226     if (!decoder.decode(parameters.shouldCaptureAudioInUIProcess))
227         return false;
228     if (!decoder.decode(parameters.shouldCaptureAudioInGPUProcess))
229         return false;
230     if (!decoder.decode(parameters.shouldCaptureVideoInUIProcess))
231         return false;
232     if (!decoder.decode(parameters.shouldCaptureDisplayInUIProcess))
233         return false;
234 #endif
235     if (!decoder.decode(parameters.urlSchemesRegisteredAsEmptyDocument))
236         return false;
237     if (!decoder.decode(parameters.urlSchemesRegisteredAsSecure))
238         return false;
239     if (!decoder.decode(parameters.urlSchemesRegisteredAsBypassingContentSecurityPolicy))
240         return false;
241     if (!decoder.decode(parameters.urlSchemesForWhichDomainRelaxationIsForbidden))
242         return false;
243     if (!decoder.decode(parameters.urlSchemesRegisteredAsLocal))
244         return false;
245     if (!decoder.decode(parameters.urlSchemesRegisteredAsNoAccess))
246         return false;
247     if (!decoder.decode(parameters.urlSchemesRegisteredAsDisplayIsolated))
248         return false;
249     if (!decoder.decode(parameters.urlSchemesRegisteredAsCORSEnabled))
250         return false;
251     if (!decoder.decode(parameters.urlSchemesRegisteredAsAlwaysRevalidated))
252         return false;
253     if (!decoder.decode(parameters.urlSchemesRegisteredAsCachePartitioned))
254         return false;
255     if (!decoder.decode(parameters.urlSchemesServiceWorkersCanHandle))
256         return false;
257     if (!decoder.decode(parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest))
258         return false;
259     if (!decoder.decodeEnum(parameters.cacheModel))
260         return false;
261     if (!decoder.decode(parameters.shouldAlwaysUseComplexTextCodePath))
262         return false;
263     if (!decoder.decode(parameters.shouldEnableMemoryPressureReliefLogging))
264         return false;
265     if (!decoder.decode(parameters.shouldSuppressMemoryPressureHandler))
266         return false;
267     if (!decoder.decode(parameters.shouldUseFontSmoothing))
268         return false;
269     if (!decoder.decode(parameters.fontWhitelist))
270         return false;
271     if (!decoder.decode(parameters.terminationTimeout))
272         return false;
273     if (!decoder.decode(parameters.languages))
274         return false;
275 #if USE(GSTREAMER)
276     if (!decoder.decode(parameters.gstreamerOptions))
277         return false;
278 #endif
279     if (!decoder.decode(parameters.textCheckerState))
280         return false;
281     if (!decoder.decode(parameters.fullKeyboardAccessEnabled))
282         return false;
283     if (!decoder.decode(parameters.defaultRequestTimeoutInterval))
284         return false;
285     if (!decoder.decode(parameters.backForwardCacheCapacity))
286         return false;
287 #if PLATFORM(COCOA)
288     if (!decoder.decode(parameters.uiProcessBundleIdentifier))
289         return false;
290     if (!decoder.decode(parameters.uiProcessSDKVersion))
291         return false;
292 #endif
293     if (!decoder.decode(parameters.presentingApplicationPID))
294         return false;
295 #if PLATFORM(COCOA)
296     if (!decoder.decode(parameters.accessibilityEnhancedUserInterfaceEnabled))
297         return false;
298     if (!decoder.decode(parameters.acceleratedCompositingPort))
299         return false;
300     if (!decoder.decode(parameters.uiProcessBundleResourcePath))
301         return false;
302     
303     Optional<SandboxExtension::Handle> uiProcessBundleResourcePathExtensionHandle;
304     decoder >> uiProcessBundleResourcePathExtensionHandle;
305     if (!uiProcessBundleResourcePathExtensionHandle)
306         return false;
307     parameters.uiProcessBundleResourcePathExtensionHandle = WTFMove(*uiProcessBundleResourcePathExtensionHandle);
308
309     if (!decoder.decode(parameters.shouldEnableJIT))
310         return false;
311     if (!decoder.decode(parameters.shouldEnableFTLJIT))
312         return false;
313
314     bool hasBundleParameterData;
315     if (!decoder.decode(hasBundleParameterData))
316         return false;
317
318     if (hasBundleParameterData) {
319         IPC::DataReference dataReference;
320         if (!decoder.decode(dataReference))
321             return false;
322
323         parameters.bundleParameterData = API::Data::create(dataReference.data(), dataReference.size());
324     }
325 #endif
326
327 #if ENABLE(NOTIFICATIONS)
328     if (!decoder.decode(parameters.notificationPermissions))
329         return false;
330 #endif
331
332     if (!decoder.decode(parameters.plugInAutoStartOrigins))
333         return false;
334     if (!decoder.decode(parameters.memoryCacheDisabled))
335         return false;
336     if (!decoder.decode(parameters.attrStyleEnabled))
337         return false;
338
339 #if ENABLE(SERVICE_CONTROLS)
340     if (!decoder.decode(parameters.hasImageServices))
341         return false;
342     if (!decoder.decode(parameters.hasSelectionServices))
343         return false;
344     if (!decoder.decode(parameters.hasRichContentServices))
345         return false;
346 #endif
347
348 #if ENABLE(NETSCAPE_PLUGIN_API)
349     if (!decoder.decode(parameters.pluginLoadClientPolicies))
350         return false;
351 #endif
352
353 #if PLATFORM(COCOA)
354     if (!IPC::decode(decoder, parameters.networkATSContext))
355         return false;
356 #endif
357
358 #if PLATFORM(WAYLAND)
359     if (!decoder.decode(parameters.waylandCompositorDisplayName))
360         return false;
361 #endif
362
363 #if USE(SOUP)
364     if (!decoder.decode(parameters.proxySettings))
365         return false;
366 #endif
367
368 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
369     if (!decoder.decode(parameters.shouldLogUserInteraction))
370         return false;
371 #endif
372
373 #if PLATFORM(COCOA)
374     if (!decoder.decode(parameters.mediaMIMETypes))
375         return false;
376 #endif
377
378 #if PLATFORM(MAC)
379     Optional<WebCore::ScreenProperties> screenProperties;
380     decoder >> screenProperties;
381     if (!screenProperties)
382         return false;
383     parameters.screenProperties = WTFMove(*screenProperties);
384     if (!decoder.decode(parameters.useOverlayScrollbars))
385         return false;
386 #endif
387
388 #if USE(WPE_RENDERER)
389     if (!decoder.decode(parameters.isServiceWorkerProcess))
390         return false;
391     if (!decoder.decode(parameters.hostClientFileDescriptor))
392         return false;
393     if (!decoder.decode(parameters.implementationLibraryName))
394         return false;
395 #endif
396
397     Optional<Optional<WebProcessDataStoreParameters>> websiteDataStoreParameters;
398     decoder >> websiteDataStoreParameters;
399     if (!websiteDataStoreParameters)
400         return false;
401     parameters.websiteDataStoreParameters = WTFMove(*websiteDataStoreParameters);
402
403 #if PLATFORM(IOS)
404     Optional<Optional<SandboxExtension::Handle>> compilerServiceExtensionHandle;
405     decoder >> compilerServiceExtensionHandle;
406     if (!compilerServiceExtensionHandle)
407         return false;
408     parameters.compilerServiceExtensionHandle = WTFMove(*compilerServiceExtensionHandle);
409 #endif
410
411 #if PLATFORM(COCOA)
412     Optional<Optional<SandboxExtension::Handle>> neHelperExtensionHandle;
413     decoder >> neHelperExtensionHandle;
414     if (!neHelperExtensionHandle)
415         return false;
416     parameters.neHelperExtensionHandle = WTFMove(*neHelperExtensionHandle);
417
418     Optional<Optional<SandboxExtension::Handle>> neSessionManagerExtensionHandle;
419     decoder >> neSessionManagerExtensionHandle;
420     if (!neSessionManagerExtensionHandle)
421         return false;
422     parameters.neSessionManagerExtensionHandle = WTFMove(*neSessionManagerExtensionHandle);
423 #endif
424
425     return true;
426 }
427
428 } // namespace WebKit