Fix typo in WKPreferences _iceCandidateFiltertingEnabled property
[WebKit-https.git] / Source / WebKit / UIProcess / API / Cocoa / WKPreferences.mm
1 /*
2  * Copyright (C) 2014-2016 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 "WKPreferencesInternal.h"
28
29 #if WK_API_ENABLED
30
31 #import "APIArray.h"
32 #import "WKNSArray.h"
33 #import "WebPreferences.h"
34 #import "_WKExperimentalFeature.h"
35 #import "_WKExperimentalFeatureInternal.h"
36 #import <WebCore/SecurityOrigin.h>
37 #import <wtf/RetainPtr.h>
38
39 @implementation WKPreferences
40
41 - (instancetype)init
42 {
43     if (!(self = [super init]))
44         return nil;
45
46     API::Object::constructInWrapper<WebKit::WebPreferences>(self, String(), "WebKit", "WebKitDebug");
47     return self;
48 }
49
50 - (void)dealloc
51 {
52     _preferences->~WebPreferences();
53
54     [super dealloc];
55 }
56
57 // FIXME: We currently only encode/decode API preferences. We should consider whether we should
58 // encode/decode SPI preferences as well.
59
60 - (void)encodeWithCoder:(NSCoder *)coder
61 {
62     [coder encodeDouble:self.minimumFontSize forKey:@"minimumFontSize"];
63     [coder encodeBool:self.javaScriptEnabled forKey:@"javaScriptEnabled"];
64     [coder encodeBool:self.javaScriptCanOpenWindowsAutomatically forKey:@"javaScriptCanOpenWindowsAutomatically"];
65
66 #if PLATFORM(MAC)
67     [coder encodeBool:self.javaEnabled forKey:@"javaEnabled"];
68     [coder encodeBool:self.plugInsEnabled forKey:@"plugInsEnabled"];
69     [coder encodeBool:self.tabFocusesLinks forKey:@"tabFocusesLinks"];
70 #endif
71 }
72
73 - (instancetype)initWithCoder:(NSCoder *)coder
74 {
75     if (!(self = [self init]))
76         return nil;
77
78     self.minimumFontSize = [coder decodeDoubleForKey:@"minimumFontSize"];
79     self.javaScriptEnabled = [coder decodeBoolForKey:@"javaScriptEnabled"];
80     self.javaScriptCanOpenWindowsAutomatically = [coder decodeBoolForKey:@"javaScriptCanOpenWindowsAutomatically"];
81
82 #if PLATFORM(MAC)
83     self.javaEnabled = [coder decodeBoolForKey:@"javaEnabled"];
84     self.plugInsEnabled = [coder decodeBoolForKey:@"plugInsEnabled"];
85     self.tabFocusesLinks = [coder decodeBoolForKey:@"tabFocusesLinks"];
86 #endif
87
88     return self;
89 }
90
91 - (CGFloat)minimumFontSize
92 {
93     return _preferences->minimumFontSize();
94 }
95
96 - (void)setMinimumFontSize:(CGFloat)minimumFontSize
97 {
98     _preferences->setMinimumFontSize(minimumFontSize);
99 }
100
101 - (BOOL)javaScriptEnabled
102 {
103     return _preferences->javaScriptEnabled();
104 }
105
106 - (void)setJavaScriptEnabled:(BOOL)javaScriptEnabled
107 {
108     _preferences->setJavaScriptEnabled(javaScriptEnabled);
109 }
110
111 - (BOOL)javaScriptCanOpenWindowsAutomatically
112 {
113     return _preferences->javaScriptCanOpenWindowsAutomatically();
114 }
115
116 - (void)setJavaScriptCanOpenWindowsAutomatically:(BOOL)javaScriptCanOpenWindowsAutomatically
117 {
118     _preferences->setJavaScriptCanOpenWindowsAutomatically(javaScriptCanOpenWindowsAutomatically);
119 }
120
121 #pragma mark OS X-specific methods
122
123 #if PLATFORM(MAC)
124
125 - (BOOL)javaEnabled
126 {
127     return _preferences->javaEnabled();
128 }
129
130 - (void)setJavaEnabled:(BOOL)javaEnabled
131 {
132     _preferences->setJavaEnabled(javaEnabled);
133 }
134
135 - (BOOL)plugInsEnabled
136 {
137     return _preferences->pluginsEnabled();
138 }
139
140 - (void)setPlugInsEnabled:(BOOL)plugInsEnabled
141 {
142     _preferences->setPluginsEnabled(plugInsEnabled);
143 }
144
145 - (BOOL)tabFocusesLinks
146 {
147     return _preferences->tabsToLinks();
148 }
149
150 - (void)setTabFocusesLinks:(BOOL)tabFocusesLinks
151 {
152     _preferences->setTabsToLinks(tabFocusesLinks);
153 }
154
155 #endif
156
157 #pragma mark WKObject protocol implementation
158
159 - (API::Object&)_apiObject
160 {
161     return *_preferences;
162 }
163
164 @end
165
166 @implementation WKPreferences (WKPrivate)
167
168 - (BOOL)_telephoneNumberDetectionIsEnabled
169 {
170     return _preferences->telephoneNumberParsingEnabled();
171 }
172
173 - (void)_setTelephoneNumberDetectionIsEnabled:(BOOL)telephoneNumberDetectionIsEnabled
174 {
175     _preferences->setTelephoneNumberParsingEnabled(telephoneNumberDetectionIsEnabled);
176 }
177
178 static WebCore::SecurityOrigin::StorageBlockingPolicy toStorageBlockingPolicy(_WKStorageBlockingPolicy policy)
179 {
180     switch (policy) {
181     case _WKStorageBlockingPolicyAllowAll:
182         return WebCore::SecurityOrigin::AllowAllStorage;
183     case _WKStorageBlockingPolicyBlockThirdParty:
184         return WebCore::SecurityOrigin::BlockThirdPartyStorage;
185     case _WKStorageBlockingPolicyBlockAll:
186         return WebCore::SecurityOrigin::BlockAllStorage;
187     }
188
189     ASSERT_NOT_REACHED();
190     return WebCore::SecurityOrigin::AllowAllStorage;
191 }
192
193 static _WKStorageBlockingPolicy toAPI(WebCore::SecurityOrigin::StorageBlockingPolicy policy)
194 {
195     switch (policy) {
196     case WebCore::SecurityOrigin::AllowAllStorage:
197         return _WKStorageBlockingPolicyAllowAll;
198     case WebCore::SecurityOrigin::BlockThirdPartyStorage:
199         return _WKStorageBlockingPolicyBlockThirdParty;
200     case WebCore::SecurityOrigin::BlockAllStorage:
201         return _WKStorageBlockingPolicyBlockAll;
202     }
203
204     ASSERT_NOT_REACHED();
205     return _WKStorageBlockingPolicyAllowAll;
206 }
207
208 - (_WKStorageBlockingPolicy)_storageBlockingPolicy
209 {
210     return toAPI(static_cast<WebCore::SecurityOrigin::StorageBlockingPolicy>(_preferences->storageBlockingPolicy()));
211 }
212
213 - (void)_setStorageBlockingPolicy:(_WKStorageBlockingPolicy)policy
214 {
215     _preferences->setStorageBlockingPolicy(toStorageBlockingPolicy(policy));
216 }
217
218 - (BOOL)_offlineApplicationCacheIsEnabled
219 {
220     return _preferences->offlineWebApplicationCacheEnabled();
221 }
222
223 - (void)_setOfflineApplicationCacheIsEnabled:(BOOL)offlineApplicationCacheIsEnabled
224 {
225     _preferences->setOfflineWebApplicationCacheEnabled(offlineApplicationCacheIsEnabled);
226 }
227
228 - (BOOL)_fullScreenEnabled
229 {
230     return _preferences->fullScreenEnabled();
231 }
232
233 - (void)_setFullScreenEnabled:(BOOL)fullScreenEnabled
234 {
235     _preferences->setFullScreenEnabled(fullScreenEnabled);
236 }
237
238 - (BOOL)_allowsPictureInPictureMediaPlayback
239 {
240     return _preferences->allowsPictureInPictureMediaPlayback();
241 }
242
243 - (void)_setAllowsPictureInPictureMediaPlayback:(BOOL)allowed
244 {
245     _preferences->setAllowsPictureInPictureMediaPlayback(allowed);
246 }
247
248 - (BOOL)_compositingBordersVisible
249 {
250     return _preferences->compositingBordersVisible();
251 }
252
253 - (void)_setCompositingBordersVisible:(BOOL)compositingBordersVisible
254 {
255     _preferences->setCompositingBordersVisible(compositingBordersVisible);
256 }
257
258 - (BOOL)_compositingRepaintCountersVisible
259 {
260     return _preferences->compositingRepaintCountersVisible();
261 }
262
263 - (void)_setCompositingRepaintCountersVisible:(BOOL)repaintCountersVisible
264 {
265     _preferences->setCompositingRepaintCountersVisible(repaintCountersVisible);
266 }
267
268 - (BOOL)_tiledScrollingIndicatorVisible
269 {
270     return _preferences->tiledScrollingIndicatorVisible();
271 }
272
273 - (void)_setTiledScrollingIndicatorVisible:(BOOL)tiledScrollingIndicatorVisible
274 {
275     _preferences->setTiledScrollingIndicatorVisible(tiledScrollingIndicatorVisible);
276 }
277
278 - (BOOL)_resourceUsageOverlayVisible
279 {
280     return _preferences->resourceUsageOverlayVisible();
281 }
282
283 - (void)_setResourceUsageOverlayVisible:(BOOL)resourceUsageOverlayVisible
284 {
285     _preferences->setResourceUsageOverlayVisible(resourceUsageOverlayVisible);
286 }
287
288 - (_WKDebugOverlayRegions)_visibleDebugOverlayRegions
289 {
290     return _preferences->visibleDebugOverlayRegions();
291 }
292
293 - (void)_setVisibleDebugOverlayRegions:(_WKDebugOverlayRegions)regionFlags
294 {
295     _preferences->setVisibleDebugOverlayRegions(regionFlags);
296 }
297
298 - (BOOL)_simpleLineLayoutEnabled
299 {
300     return _preferences->simpleLineLayoutEnabled();
301 }
302
303 - (void)_setSimpleLineLayoutEnabled:(BOOL)simpleLineLayoutEnabled
304 {
305     _preferences->setSimpleLineLayoutEnabled(simpleLineLayoutEnabled);
306 }
307
308 - (BOOL)_simpleLineLayoutDebugBordersEnabled
309 {
310     return _preferences->simpleLineLayoutDebugBordersEnabled();
311 }
312
313 - (void)_setSimpleLineLayoutDebugBordersEnabled:(BOOL)simpleLineLayoutDebugBordersEnabled
314 {
315     _preferences->setSimpleLineLayoutDebugBordersEnabled(simpleLineLayoutDebugBordersEnabled);
316 }
317
318 - (BOOL)_acceleratedDrawingEnabled
319 {
320     return _preferences->acceleratedDrawingEnabled();
321 }
322
323 - (void)_setAcceleratedDrawingEnabled:(BOOL)acceleratedDrawingEnabled
324 {
325     _preferences->setAcceleratedDrawingEnabled(acceleratedDrawingEnabled);
326 }
327
328 - (BOOL)_displayListDrawingEnabled
329 {
330     return _preferences->displayListDrawingEnabled();
331 }
332
333 - (void)_setDisplayListDrawingEnabled:(BOOL)displayListDrawingEnabled
334 {
335     _preferences->setDisplayListDrawingEnabled(displayListDrawingEnabled);
336 }
337
338 - (BOOL)_visualViewportEnabled
339 {
340     return _preferences->visualViewportEnabled();
341 }
342
343 - (void)_setVisualViewportEnabled:(BOOL)_visualViewportEnabled
344 {
345     _preferences->setVisualViewportEnabled(_visualViewportEnabled);
346 }
347
348 - (BOOL)_largeImageAsyncDecodingEnabled
349 {
350     return _preferences->largeImageAsyncDecodingEnabled();
351 }
352
353 - (void)_setLargeImageAsyncDecodingEnabled:(BOOL)_largeImageAsyncDecodingEnabled
354 {
355     _preferences->setLargeImageAsyncDecodingEnabled(_largeImageAsyncDecodingEnabled);
356 }
357
358 - (BOOL)_animatedImageAsyncDecodingEnabled
359 {
360     return _preferences->animatedImageAsyncDecodingEnabled();
361 }
362
363 - (void)_setAnimatedImageAsyncDecodingEnabled:(BOOL)_animatedImageAsyncDecodingEnabled
364 {
365     _preferences->setAnimatedImageAsyncDecodingEnabled(_animatedImageAsyncDecodingEnabled);
366 }
367
368 - (BOOL)_textAutosizingEnabled
369 {
370     return _preferences->textAutosizingEnabled();
371 }
372
373 - (void)_setTextAutosizingEnabled:(BOOL)enabled
374 {
375     _preferences->setTextAutosizingEnabled(enabled);
376 }
377
378 - (BOOL)_subpixelAntialiasedLayerTextEnabled
379 {
380     return _preferences->subpixelAntialiasedLayerTextEnabled();
381 }
382
383 - (void)_setSubpixelAntialiasedLayerTextEnabled:(BOOL)enabled
384 {
385     _preferences->setSubpixelAntialiasedLayerTextEnabled(enabled);
386 }
387
388 - (BOOL)_developerExtrasEnabled
389 {
390     return _preferences->developerExtrasEnabled();
391 }
392
393 - (void)_setDeveloperExtrasEnabled:(BOOL)developerExtrasEnabled
394 {
395     _preferences->setDeveloperExtrasEnabled(developerExtrasEnabled);
396 }
397
398 - (BOOL)_logsPageMessagesToSystemConsoleEnabled
399 {
400     return _preferences->logsPageMessagesToSystemConsoleEnabled();
401 }
402
403 - (void)_setLogsPageMessagesToSystemConsoleEnabled:(BOOL)logsPageMessagesToSystemConsoleEnabled
404 {
405     _preferences->setLogsPageMessagesToSystemConsoleEnabled(logsPageMessagesToSystemConsoleEnabled);
406 }
407
408 - (BOOL)_hiddenPageDOMTimerThrottlingEnabled
409 {
410     return _preferences->hiddenPageDOMTimerThrottlingEnabled();
411 }
412
413 - (void)_setHiddenPageDOMTimerThrottlingEnabled:(BOOL)hiddenPageDOMTimerThrottlingEnabled
414 {
415     _preferences->setHiddenPageDOMTimerThrottlingEnabled(hiddenPageDOMTimerThrottlingEnabled);
416 }
417
418 - (BOOL)_hiddenPageDOMTimerThrottlingAutoIncreases
419 {
420     return _preferences->hiddenPageDOMTimerThrottlingAutoIncreases();
421 }
422
423 - (void)_setHiddenPageDOMTimerThrottlingAutoIncreases:(BOOL)hiddenPageDOMTimerThrottlingAutoIncreases
424 {
425     _preferences->setHiddenPageDOMTimerThrottlingAutoIncreases(hiddenPageDOMTimerThrottlingAutoIncreases);
426 }
427
428 - (BOOL)_pageVisibilityBasedProcessSuppressionEnabled
429 {
430     return _preferences->pageVisibilityBasedProcessSuppressionEnabled();
431 }
432
433 - (void)_setPageVisibilityBasedProcessSuppressionEnabled:(BOOL)pageVisibilityBasedProcessSuppressionEnabled
434 {
435     _preferences->setPageVisibilityBasedProcessSuppressionEnabled(pageVisibilityBasedProcessSuppressionEnabled);
436 }
437
438 - (BOOL)_allowFileAccessFromFileURLs
439 {
440     return _preferences->allowFileAccessFromFileURLs();
441 }
442
443 - (void)_setAllowFileAccessFromFileURLs:(BOOL)allowFileAccessFromFileURLs
444 {
445     _preferences->setAllowFileAccessFromFileURLs(allowFileAccessFromFileURLs);
446 }
447
448 - (_WKJavaScriptRuntimeFlags)_javaScriptRuntimeFlags
449 {
450     return _preferences->javaScriptRuntimeFlags();
451 }
452
453 - (void)_setJavaScriptRuntimeFlags:(_WKJavaScriptRuntimeFlags)javaScriptRuntimeFlags
454 {
455     _preferences->setJavaScriptRuntimeFlags(javaScriptRuntimeFlags);
456 }
457
458 - (BOOL)_isStandalone
459 {
460     return _preferences->standalone();
461 }
462
463 - (void)_setStandalone:(BOOL)standalone
464 {
465     _preferences->setStandalone(standalone);
466 }
467
468 - (BOOL)_diagnosticLoggingEnabled
469 {
470     return _preferences->diagnosticLoggingEnabled();
471 }
472
473 - (void)_setDiagnosticLoggingEnabled:(BOOL)diagnosticLoggingEnabled
474 {
475     _preferences->setDiagnosticLoggingEnabled(diagnosticLoggingEnabled);
476 }
477
478 - (NSUInteger)_defaultFontSize
479 {
480     return _preferences->defaultFontSize();
481 }
482
483 - (void)_setDefaultFontSize:(NSUInteger)defaultFontSize
484 {
485     _preferences->setDefaultFontSize(defaultFontSize);
486 }
487
488 - (NSUInteger)_defaultFixedPitchFontSize
489 {
490     return _preferences->defaultFixedFontSize();
491 }
492
493 - (void)_setDefaultFixedPitchFontSize:(NSUInteger)defaultFixedPitchFontSize
494 {
495     _preferences->setDefaultFixedFontSize(defaultFixedPitchFontSize);
496 }
497
498 - (NSString *)_fixedPitchFontFamily
499 {
500     return _preferences->fixedFontFamily();
501 }
502
503 - (void)_setFixedPitchFontFamily:(NSString *)fixedPitchFontFamily
504 {
505     _preferences->setFixedFontFamily(fixedPitchFontFamily);
506 }
507
508 + (NSArray<_WKExperimentalFeature *> *)_experimentalFeatures
509 {
510     auto features = WebKit::WebPreferences::experimentalFeatures();
511     return [wrapper(API::Array::create(WTFMove(features)).leakRef()) autorelease];
512 }
513
514 - (BOOL)_isEnabledForFeature:(_WKExperimentalFeature *)feature
515 {
516     return _preferences->isEnabledForFeature(*feature->_experimentalFeature);
517 }
518
519 - (void)_setEnabled:(BOOL)value forFeature:(_WKExperimentalFeature *)feature
520 {
521     _preferences->setEnabledForFeature(value, *feature->_experimentalFeature);
522 }
523
524 - (BOOL)_applePayCapabilityDisclosureAllowed
525 {
526 #if ENABLE(APPLE_PAY)
527     return _preferences->applePayCapabilityDisclosureAllowed();
528 #else
529     return NO;
530 #endif
531 }
532
533 - (void)_setApplePayCapabilityDisclosureAllowed:(BOOL)applePayCapabilityDisclosureAllowed
534 {
535 #if ENABLE(APPLE_PAY)
536     _preferences->setApplePayCapabilityDisclosureAllowed(applePayCapabilityDisclosureAllowed);
537 #endif
538 }
539
540 - (BOOL)_shouldSuppressKeyboardInputDuringProvisionalNavigation
541 {
542     return _preferences->shouldSuppressKeyboardInputDuringProvisionalNavigation();
543 }
544
545 - (void)_setShouldSuppressKeyboardInputDuringProvisionalNavigation:(BOOL)shouldSuppress
546 {
547     _preferences->setShouldSuppressKeyboardInputDuringProvisionalNavigation(shouldSuppress);
548 }
549
550 - (BOOL)_loadsImagesAutomatically
551 {
552     return _preferences->loadsImagesAutomatically();
553 }
554
555 - (void)_setLoadsImagesAutomatically:(BOOL)loadsImagesAutomatically
556 {
557     _preferences->setLoadsImagesAutomatically(loadsImagesAutomatically);
558 }
559
560 - (BOOL)_mediaDevicesEnabled
561 {
562     return _preferences->mediaDevicesEnabled();
563 }
564
565 - (void)_setMediaDevicesEnabled:(BOOL)enabled
566 {
567     _preferences->setMediaDevicesEnabled(enabled);
568 }
569
570 - (BOOL)_mockCaptureDevicesEnabled
571 {
572     return _preferences->mockCaptureDevicesEnabled();
573 }
574
575 - (void)_setMockCaptureDevicesEnabled:(BOOL)enabled
576 {
577     _preferences->setMockCaptureDevicesEnabled(enabled);
578 }
579
580 - (BOOL)_mediaCaptureRequiresSecureConnection
581 {
582     return _preferences->mediaCaptureRequiresSecureConnection();
583 }
584
585 - (void)_setMediaCaptureRequiresSecureConnection:(BOOL)requiresSecureConnection
586 {
587     _preferences->setMediaCaptureRequiresSecureConnection(requiresSecureConnection);
588 }
589
590 - (BOOL)_enumeratingAllNetworkInterfacesEnabled
591 {
592     return _preferences->enumeratingAllNetworkInterfacesEnabled();
593 }
594
595 - (void)_setEnumeratingAllNetworkInterfacesEnabled:(BOOL)enabled
596 {
597     _preferences->setEnumeratingAllNetworkInterfacesEnabled(enabled);
598 }
599
600 - (BOOL)_iceCandidateFilteringEnabled
601 {
602     return _preferences->iceCandidateFilteringEnabled();
603 }
604
605 - (void)_setICECandidateFilteringEnabled:(BOOL)enabled
606 {
607     _preferences->setICECandidateFilteringEnabled(enabled);
608 }
609
610 - (BOOL)_webRTCLegacyAPIEnabled
611 {
612     return !_preferences->webRTCLegacyAPIDisabled();
613 }
614
615 - (void)_setWebRTCLegacyAPIEnabled:(BOOL)enabled
616 {
617     _preferences->setWebRTCLegacyAPIDisabled(!enabled);
618 }
619
620 - (void)_setJavaScriptCanAccessClipboard:(BOOL)javaScriptCanAccessClipboard
621 {
622     _preferences->setJavaScriptCanAccessClipboard(javaScriptCanAccessClipboard);
623 }
624
625 - (BOOL)_javaScriptCanAccessClipboard
626 {
627     return _preferences->javaScriptCanAccessClipboard();
628 }
629
630 - (void)_setDOMPasteAllowed:(BOOL)domPasteAllowed
631 {
632     _preferences->setDOMPasteAllowed(domPasteAllowed);
633 }
634
635 - (BOOL)_domPasteAllowed
636 {
637     return _preferences->domPasteAllowed();
638 }
639
640 @end
641
642 #endif // WK_API_ENABLED