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