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