Add a script to run ImageDiff manually
[WebKit-https.git] / Source / WebKit / UIProcess / API / Cocoa / _WKProcessPoolConfiguration.mm
1 /*
2  * Copyright (C) 2014-2019 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 #import "config.h"
27 #import "_WKProcessPoolConfigurationInternal.h"
28
29 #import "LegacyGlobalSettings.h"
30 #import <objc/runtime.h>
31 #import <wtf/RetainPtr.h>
32
33 @implementation _WKProcessPoolConfiguration
34
35 - (instancetype)init
36 {
37     if (!(self = [super init]))
38         return nil;
39
40     API::Object::constructInWrapper<API::ProcessPoolConfiguration>(self);
41
42     return self;
43 }
44
45 - (void)dealloc
46 {
47     _processPoolConfiguration->~ProcessPoolConfiguration();
48
49     [super dealloc];
50 }
51
52 - (NSURL *)injectedBundleURL
53 {
54     return [NSURL fileURLWithPath:_processPoolConfiguration->injectedBundlePath()];
55 }
56
57 - (void)setInjectedBundleURL:(NSURL *)injectedBundleURL
58 {
59     if (injectedBundleURL && !injectedBundleURL.isFileURL)
60         [NSException raise:NSInvalidArgumentException format:@"Injected Bundle URL must be a file URL"];
61
62     _processPoolConfiguration->setInjectedBundlePath(injectedBundleURL.path);
63 }
64
65 - (NSSet<Class> *)customClassesForParameterCoder
66 {
67     auto classes = _processPoolConfiguration->customClassesForParameterCoder();
68     if (classes.isEmpty())
69         return [NSSet set];
70
71     NSMutableSet *result = [[NSMutableSet alloc] initWithCapacity:classes.size()];
72     for (const auto& value : classes)
73         [result addObject: objc_lookUpClass(value.utf8().data())];
74
75     return [result autorelease];
76 }
77
78 - (void)setCustomClassesForParameterCoder:(NSSet<Class> *)classesForCoder
79 {
80     Vector<WTF::String> classes;
81     classes.reserveInitialCapacity(classesForCoder.count);
82     for (id classObj : classesForCoder) {
83         if (auto* string = NSStringFromClass(classObj))
84             classes.uncheckedAppend(string);
85     }
86
87     _processPoolConfiguration->setCustomClassesForParameterCoder(WTFMove(classes));
88 }
89
90 - (NSUInteger)maximumProcessCount
91 {
92     // Deprecated.
93     return NSUIntegerMax;
94 }
95
96 - (void)setMaximumProcessCount:(NSUInteger)maximumProcessCount
97 {
98     // Deprecated.
99 }
100
101 - (NSInteger)diskCacheSizeOverride
102 {
103     return 0;
104 }
105
106 - (void)setDiskCacheSizeOverride:(NSInteger)size
107 {
108 }
109
110 - (BOOL)diskCacheSpeculativeValidationEnabled
111 {
112     return NO;
113 }
114
115 - (void)setDiskCacheSpeculativeValidationEnabled:(BOOL)enabled
116 {
117 }
118
119 - (BOOL)ignoreSynchronousMessagingTimeoutsForTesting
120 {
121     return _processPoolConfiguration->ignoreSynchronousMessagingTimeoutsForTesting();
122 }
123
124 - (void)setIgnoreSynchronousMessagingTimeoutsForTesting:(BOOL)ignoreSynchronousMessagingTimeoutsForTesting
125 {
126     _processPoolConfiguration->setIgnoreSynchronousMessagingTimeoutsForTesting(ignoreSynchronousMessagingTimeoutsForTesting);
127 }
128
129 - (BOOL)attrStyleEnabled
130 {
131     return _processPoolConfiguration->attrStyleEnabled();
132 }
133
134 - (void)setAttrStyleEnabled:(BOOL)enabled
135 {
136     return _processPoolConfiguration->setAttrStyleEnabled(enabled);
137 }
138
139 - (NSArray<NSURL *> *)additionalReadAccessAllowedURLs
140 {
141     auto paths = _processPoolConfiguration->additionalReadAccessAllowedPaths();
142     if (paths.isEmpty())
143         return @[ ];
144
145     NSMutableArray *urls = [NSMutableArray arrayWithCapacity:paths.size()];
146     for (const auto& path : paths)
147         [urls addObject:[NSURL fileURLWithFileSystemRepresentation:path.data() isDirectory:NO relativeToURL:nil]];
148
149     return urls;
150 }
151
152 - (void)setAdditionalReadAccessAllowedURLs:(NSArray<NSURL *> *)additionalReadAccessAllowedURLs
153 {
154     Vector<CString> paths;
155     paths.reserveInitialCapacity(additionalReadAccessAllowedURLs.count);
156     for (NSURL *url in additionalReadAccessAllowedURLs) {
157         if (!url.isFileURL)
158             [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", url];
159
160         paths.uncheckedAppend(url.fileSystemRepresentation);
161     }
162
163     _processPoolConfiguration->setAdditionalReadAccessAllowedPaths(WTFMove(paths));
164 }
165
166 #if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
167 - (NSUInteger)wirelessContextIdentifier
168 {
169     return 0;
170 }
171
172 - (void)setWirelessContextIdentifier:(NSUInteger)identifier
173 {
174 }
175 #endif
176
177 - (NSArray *)cachePartitionedURLSchemes
178 {
179     auto schemes = _processPoolConfiguration->cachePartitionedURLSchemes();
180     if (schemes.isEmpty())
181         return @[];
182
183     NSMutableArray *array = [NSMutableArray arrayWithCapacity:schemes.size()];
184     for (const auto& scheme : schemes)
185         [array addObject:(NSString *)scheme];
186
187     return array;
188 }
189
190 - (void)setCachePartitionedURLSchemes:(NSArray *)cachePartitionedURLSchemes
191 {
192     Vector<String> schemes;
193     for (id urlScheme in cachePartitionedURLSchemes) {
194         if ([urlScheme isKindOfClass:[NSString class]])
195             schemes.append(String((NSString *)urlScheme));
196     }
197     
198     _processPoolConfiguration->setCachePartitionedURLSchemes(WTFMove(schemes));
199 }
200
201 - (NSArray *)alwaysRevalidatedURLSchemes
202 {
203     auto& schemes = _processPoolConfiguration->alwaysRevalidatedURLSchemes();
204     if (schemes.isEmpty())
205         return @[];
206
207     NSMutableArray *array = [NSMutableArray arrayWithCapacity:schemes.size()];
208     for (auto& scheme : schemes)
209         [array addObject:(NSString *)scheme];
210
211     return array;
212 }
213
214 - (void)setAlwaysRevalidatedURLSchemes:(NSArray *)alwaysRevalidatedURLSchemes
215 {
216     Vector<String> schemes;
217     schemes.reserveInitialCapacity(alwaysRevalidatedURLSchemes.count);
218     for (id scheme in alwaysRevalidatedURLSchemes) {
219         if ([scheme isKindOfClass:[NSString class]])
220             schemes.append((NSString *)scheme);
221     }
222
223     _processPoolConfiguration->setAlwaysRevalidatedURLSchemes(WTFMove(schemes));
224 }
225
226 - (NSString *)sourceApplicationBundleIdentifier
227 {
228     return nil;
229 }
230
231 - (void)setSourceApplicationBundleIdentifier:(NSString *)sourceApplicationBundleIdentifier
232 {
233 }
234
235 - (NSString *)sourceApplicationSecondaryIdentifier
236 {
237     return nil;
238 }
239
240 - (void)setSourceApplicationSecondaryIdentifier:(NSString *)sourceApplicationSecondaryIdentifier
241 {
242 }
243
244 - (BOOL)shouldCaptureAudioInUIProcess
245 {
246     return _processPoolConfiguration->shouldCaptureAudioInUIProcess();
247 }
248
249 - (void)setShouldCaptureAudioInUIProcess:(BOOL)shouldCaptureAudioInUIProcess
250 {
251     _processPoolConfiguration->setShouldCaptureAudioInUIProcess(shouldCaptureAudioInUIProcess);
252 }
253
254 - (void)setPresentingApplicationPID:(pid_t)presentingApplicationPID
255 {
256     _processPoolConfiguration->setPresentingApplicationPID(presentingApplicationPID);
257 }
258
259 - (pid_t)presentingApplicationPID
260 {
261     return _processPoolConfiguration->presentingApplicationPID();
262 }
263
264 - (void)setProcessSwapsOnNavigation:(BOOL)swaps
265 {
266     _processPoolConfiguration->setProcessSwapsOnNavigation(swaps);
267 }
268
269 - (BOOL)processSwapsOnNavigation
270 {
271     return _processPoolConfiguration->processSwapsOnNavigation();
272 }
273
274 - (void)setPrewarmsProcessesAutomatically:(BOOL)prewarms
275 {
276     _processPoolConfiguration->setIsAutomaticProcessWarmingEnabled(prewarms);
277 }
278
279 - (BOOL)prewarmsProcessesAutomatically
280 {
281     return _processPoolConfiguration->isAutomaticProcessWarmingEnabled();
282 }
283
284 - (void)setUsesWebProcessCache:(BOOL)value
285 {
286     _processPoolConfiguration->setUsesWebProcessCache(value);
287 }
288
289 - (BOOL)usesWebProcessCache
290 {
291     return _processPoolConfiguration->usesWebProcessCache();
292 }
293
294 - (void)setAlwaysKeepAndReuseSwappedProcesses:(BOOL)swaps
295 {
296     _processPoolConfiguration->setAlwaysKeepAndReuseSwappedProcesses(swaps);
297 }
298
299 - (BOOL)alwaysKeepAndReuseSwappedProcesses
300 {
301     return _processPoolConfiguration->alwaysKeepAndReuseSwappedProcesses();
302 }
303
304 - (void)setProcessSwapsOnWindowOpenWithOpener:(BOOL)swaps
305 {
306     _processPoolConfiguration->setProcessSwapsOnWindowOpenWithOpener(swaps);
307 }
308
309 - (BOOL)processSwapsOnWindowOpenWithOpener
310 {
311     return _processPoolConfiguration->processSwapsOnWindowOpenWithOpener();
312 }
313
314 - (BOOL)pageCacheEnabled
315 {
316     return _processPoolConfiguration->usesBackForwardCache();
317 }
318
319 - (void)setPageCacheEnabled:(BOOL)enabled
320 {
321     return _processPoolConfiguration->setUsesBackForwardCache(enabled);
322 }
323
324 - (BOOL)usesSingleWebProcess
325 {
326     return _processPoolConfiguration->usesSingleWebProcess();
327 }
328
329 - (void)setUsesSingleWebProcess:(BOOL)enabled
330 {
331     _processPoolConfiguration->setUsesSingleWebProcess(enabled);
332 }
333
334 - (BOOL)suppressesConnectionTerminationOnSystemChange
335 {
336     return _processPoolConfiguration->suppressesConnectionTerminationOnSystemChange();
337 }
338
339 - (BOOL)isJITEnabled
340 {
341     return _processPoolConfiguration->isJITEnabled();
342 }
343
344 - (void)setJITEnabled:(BOOL)enabled
345 {
346     _processPoolConfiguration->setJITEnabled(enabled);
347 }
348
349 - (void)setHSTSStorageDirectory:(NSURL *)directory
350 {
351     if (directory && ![directory isFileURL])
352         [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", directory];
353
354     // FIXME: Move this to _WKWebsiteDataStoreConfiguration once rdar://problem/50109631 is fixed.
355     WebKit::LegacyGlobalSettings::singleton().setHSTSStorageDirectory(directory.path);
356 }
357
358 - (NSURL *)hstsStorageDirectory
359 {
360     return [NSURL fileURLWithPath:WebKit::LegacyGlobalSettings::singleton().hstsStorageDirectory() isDirectory:YES];
361 }
362
363 - (void)setSuppressesConnectionTerminationOnSystemChange:(BOOL)suppressesConnectionTerminationOnSystemChange
364 {
365     _processPoolConfiguration->setSuppressesConnectionTerminationOnSystemChange(suppressesConnectionTerminationOnSystemChange);
366 }
367
368 #if PLATFORM(IOS_FAMILY)
369 - (NSString *)CTDataConnectionServiceType
370 {
371     return _processPoolConfiguration->ctDataConnectionServiceType();
372 }
373
374 - (void)setCTDataConnectionServiceType:(NSString *)ctDataConnectionServiceType
375 {
376     _processPoolConfiguration->setCTDataConnectionServiceType(ctDataConnectionServiceType);
377 }
378
379 - (BOOL)alwaysRunsAtBackgroundPriority
380 {
381     return _processPoolConfiguration->alwaysRunsAtBackgroundPriority();
382 }
383
384 - (void)setAlwaysRunsAtBackgroundPriority:(BOOL)alwaysRunsAtBackgroundPriority
385 {
386     _processPoolConfiguration->setAlwaysRunsAtBackgroundPriority(alwaysRunsAtBackgroundPriority);
387 }
388
389 - (BOOL)shouldTakeUIBackgroundAssertion
390 {
391     return _processPoolConfiguration->shouldTakeUIBackgroundAssertion();
392 }
393
394 - (void)setShouldTakeUIBackgroundAssertion:(BOOL)shouldTakeUIBackgroundAssertion
395 {
396     return _processPoolConfiguration->setShouldTakeUIBackgroundAssertion(shouldTakeUIBackgroundAssertion);
397 }
398 #endif
399
400 - (NSString *)description
401 {
402     NSString *description = [NSString stringWithFormat:@"<%@: %p", NSStringFromClass(self.class), self];
403
404     if (!_processPoolConfiguration->injectedBundlePath().isEmpty())
405         return [description stringByAppendingFormat:@"; injectedBundleURL: \"%@\">", [self injectedBundleURL]];
406
407     return [description stringByAppendingString:@">"];
408 }
409
410 - (id)copyWithZone:(NSZone *)zone
411 {
412     return [wrapper(_processPoolConfiguration->copy()) retain];
413 }
414
415 - (NSString *)customWebContentServiceBundleIdentifier
416 {
417     return _processPoolConfiguration->customWebContentServiceBundleIdentifier();
418 }
419
420 - (void)setCustomWebContentServiceBundleIdentifier:(NSString *)customWebContentServiceBundleIdentifier
421 {
422     _processPoolConfiguration->setCustomWebContentServiceBundleIdentifier(customWebContentServiceBundleIdentifier);
423 }
424
425 - (BOOL)configureJSCForTesting
426 {
427     return _processPoolConfiguration->shouldConfigureJSCForTesting();
428 }
429
430 - (void)setConfigureJSCForTesting:(BOOL)value
431 {
432     _processPoolConfiguration->setShouldConfigureJSCForTesting(value);
433 }
434
435 #pragma mark WKObject protocol implementation
436
437 - (API::Object&)_apiObject
438 {
439     return *_processPoolConfiguration;
440 }
441
442 @end