2 * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #import "WKPreferencesInternal.h"
33 #import "WebPreferences.h"
34 #import "_WKExperimentalFeature.h"
35 #import "_WKExperimentalFeatureInternal.h"
36 #import <WebCore/SecurityOrigin.h>
37 #import <wtf/RetainPtr.h>
39 @implementation WKPreferences
43 if (!(self = [super init]))
46 API::Object::constructInWrapper<WebKit::WebPreferences>(self, String(), "WebKit", "WebKitDebug");
52 _preferences->~WebPreferences();
57 // FIXME: We currently only encode/decode API preferences. We should consider whether we should
58 // encode/decode SPI preferences as well.
60 - (void)encodeWithCoder:(NSCoder *)coder
62 [coder encodeDouble:self.minimumFontSize forKey:@"minimumFontSize"];
63 [coder encodeBool:self.javaScriptEnabled forKey:@"javaScriptEnabled"];
64 [coder encodeBool:self.javaScriptCanOpenWindowsAutomatically forKey:@"javaScriptCanOpenWindowsAutomatically"];
67 [coder encodeBool:self.javaEnabled forKey:@"javaEnabled"];
68 [coder encodeBool:self.plugInsEnabled forKey:@"plugInsEnabled"];
69 [coder encodeBool:self.tabFocusesLinks forKey:@"tabFocusesLinks"];
73 - (instancetype)initWithCoder:(NSCoder *)coder
75 if (!(self = [self init]))
78 self.minimumFontSize = [coder decodeDoubleForKey:@"minimumFontSize"];
79 self.javaScriptEnabled = [coder decodeBoolForKey:@"javaScriptEnabled"];
80 self.javaScriptCanOpenWindowsAutomatically = [coder decodeBoolForKey:@"javaScriptCanOpenWindowsAutomatically"];
83 self.javaEnabled = [coder decodeBoolForKey:@"javaEnabled"];
84 self.plugInsEnabled = [coder decodeBoolForKey:@"plugInsEnabled"];
85 self.tabFocusesLinks = [coder decodeBoolForKey:@"tabFocusesLinks"];
91 - (CGFloat)minimumFontSize
93 return _preferences->minimumFontSize();
96 - (void)setMinimumFontSize:(CGFloat)minimumFontSize
98 _preferences->setMinimumFontSize(minimumFontSize);
101 - (BOOL)javaScriptEnabled
103 return _preferences->javaScriptEnabled();
106 - (void)setJavaScriptEnabled:(BOOL)javaScriptEnabled
108 _preferences->setJavaScriptEnabled(javaScriptEnabled);
111 - (BOOL)javaScriptCanOpenWindowsAutomatically
113 return _preferences->javaScriptCanOpenWindowsAutomatically();
116 - (void)setJavaScriptCanOpenWindowsAutomatically:(BOOL)javaScriptCanOpenWindowsAutomatically
118 _preferences->setJavaScriptCanOpenWindowsAutomatically(javaScriptCanOpenWindowsAutomatically);
121 #pragma mark OS X-specific methods
127 return _preferences->javaEnabled();
130 - (void)setJavaEnabled:(BOOL)javaEnabled
132 _preferences->setJavaEnabled(javaEnabled);
135 - (BOOL)plugInsEnabled
137 return _preferences->pluginsEnabled();
140 - (void)setPlugInsEnabled:(BOOL)plugInsEnabled
142 _preferences->setPluginsEnabled(plugInsEnabled);
145 - (BOOL)tabFocusesLinks
147 return _preferences->tabsToLinks();
150 - (void)setTabFocusesLinks:(BOOL)tabFocusesLinks
152 _preferences->setTabsToLinks(tabFocusesLinks);
157 #pragma mark WKObject protocol implementation
159 - (API::Object&)_apiObject
161 return *_preferences;
166 @implementation WKPreferences (WKPrivate)
168 - (BOOL)_telephoneNumberDetectionIsEnabled
170 return _preferences->telephoneNumberParsingEnabled();
173 - (void)_setTelephoneNumberDetectionIsEnabled:(BOOL)telephoneNumberDetectionIsEnabled
175 _preferences->setTelephoneNumberParsingEnabled(telephoneNumberDetectionIsEnabled);
178 static WebCore::SecurityOrigin::StorageBlockingPolicy toStorageBlockingPolicy(_WKStorageBlockingPolicy 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;
189 ASSERT_NOT_REACHED();
190 return WebCore::SecurityOrigin::AllowAllStorage;
193 static _WKStorageBlockingPolicy toAPI(WebCore::SecurityOrigin::StorageBlockingPolicy 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;
204 ASSERT_NOT_REACHED();
205 return _WKStorageBlockingPolicyAllowAll;
208 - (_WKStorageBlockingPolicy)_storageBlockingPolicy
210 return toAPI(static_cast<WebCore::SecurityOrigin::StorageBlockingPolicy>(_preferences->storageBlockingPolicy()));
213 - (void)_setStorageBlockingPolicy:(_WKStorageBlockingPolicy)policy
215 _preferences->setStorageBlockingPolicy(toStorageBlockingPolicy(policy));
218 - (BOOL)_offlineApplicationCacheIsEnabled
220 return _preferences->offlineWebApplicationCacheEnabled();
223 - (void)_setOfflineApplicationCacheIsEnabled:(BOOL)offlineApplicationCacheIsEnabled
225 _preferences->setOfflineWebApplicationCacheEnabled(offlineApplicationCacheIsEnabled);
228 - (BOOL)_fullScreenEnabled
230 return _preferences->fullScreenEnabled();
233 - (void)_setFullScreenEnabled:(BOOL)fullScreenEnabled
235 _preferences->setFullScreenEnabled(fullScreenEnabled);
238 - (BOOL)_allowsPictureInPictureMediaPlayback
240 return _preferences->allowsPictureInPictureMediaPlayback();
243 - (void)_setAllowsPictureInPictureMediaPlayback:(BOOL)allowed
245 _preferences->setAllowsPictureInPictureMediaPlayback(allowed);
248 - (BOOL)_compositingBordersVisible
250 return _preferences->compositingBordersVisible();
253 - (void)_setCompositingBordersVisible:(BOOL)compositingBordersVisible
255 _preferences->setCompositingBordersVisible(compositingBordersVisible);
258 - (BOOL)_compositingRepaintCountersVisible
260 return _preferences->compositingRepaintCountersVisible();
263 - (void)_setCompositingRepaintCountersVisible:(BOOL)repaintCountersVisible
265 _preferences->setCompositingRepaintCountersVisible(repaintCountersVisible);
268 - (BOOL)_tiledScrollingIndicatorVisible
270 return _preferences->tiledScrollingIndicatorVisible();
273 - (void)_setTiledScrollingIndicatorVisible:(BOOL)tiledScrollingIndicatorVisible
275 _preferences->setTiledScrollingIndicatorVisible(tiledScrollingIndicatorVisible);
278 - (BOOL)_resourceUsageOverlayVisible
280 return _preferences->resourceUsageOverlayVisible();
283 - (void)_setResourceUsageOverlayVisible:(BOOL)resourceUsageOverlayVisible
285 _preferences->setResourceUsageOverlayVisible(resourceUsageOverlayVisible);
288 - (_WKDebugOverlayRegions)_visibleDebugOverlayRegions
290 return _preferences->visibleDebugOverlayRegions();
293 - (void)_setVisibleDebugOverlayRegions:(_WKDebugOverlayRegions)regionFlags
295 _preferences->setVisibleDebugOverlayRegions(regionFlags);
298 - (BOOL)_simpleLineLayoutEnabled
300 return _preferences->simpleLineLayoutEnabled();
303 - (void)_setSimpleLineLayoutEnabled:(BOOL)simpleLineLayoutEnabled
305 _preferences->setSimpleLineLayoutEnabled(simpleLineLayoutEnabled);
308 - (BOOL)_simpleLineLayoutDebugBordersEnabled
310 return _preferences->simpleLineLayoutDebugBordersEnabled();
313 - (void)_setSimpleLineLayoutDebugBordersEnabled:(BOOL)simpleLineLayoutDebugBordersEnabled
315 _preferences->setSimpleLineLayoutDebugBordersEnabled(simpleLineLayoutDebugBordersEnabled);
318 - (BOOL)_acceleratedDrawingEnabled
320 return _preferences->acceleratedDrawingEnabled();
323 - (void)_setAcceleratedDrawingEnabled:(BOOL)acceleratedDrawingEnabled
325 _preferences->setAcceleratedDrawingEnabled(acceleratedDrawingEnabled);
328 - (BOOL)_displayListDrawingEnabled
330 return _preferences->displayListDrawingEnabled();
333 - (void)_setDisplayListDrawingEnabled:(BOOL)displayListDrawingEnabled
335 _preferences->setDisplayListDrawingEnabled(displayListDrawingEnabled);
338 - (BOOL)_visualViewportEnabled
340 return _preferences->visualViewportEnabled();
343 - (void)_setVisualViewportEnabled:(BOOL)_visualViewportEnabled
345 _preferences->setVisualViewportEnabled(_visualViewportEnabled);
348 - (BOOL)_largeImageAsyncDecodingEnabled
350 return _preferences->largeImageAsyncDecodingEnabled();
353 - (void)_setLargeImageAsyncDecodingEnabled:(BOOL)_largeImageAsyncDecodingEnabled
355 _preferences->setLargeImageAsyncDecodingEnabled(_largeImageAsyncDecodingEnabled);
358 - (BOOL)_animatedImageAsyncDecodingEnabled
360 return _preferences->animatedImageAsyncDecodingEnabled();
363 - (void)_setAnimatedImageAsyncDecodingEnabled:(BOOL)_animatedImageAsyncDecodingEnabled
365 _preferences->setAnimatedImageAsyncDecodingEnabled(_animatedImageAsyncDecodingEnabled);
368 - (BOOL)_textAutosizingEnabled
370 return _preferences->textAutosizingEnabled();
373 - (void)_setTextAutosizingEnabled:(BOOL)enabled
375 _preferences->setTextAutosizingEnabled(enabled);
378 - (BOOL)_subpixelAntialiasedLayerTextEnabled
380 return _preferences->subpixelAntialiasedLayerTextEnabled();
383 - (void)_setSubpixelAntialiasedLayerTextEnabled:(BOOL)enabled
385 _preferences->setSubpixelAntialiasedLayerTextEnabled(enabled);
388 - (BOOL)_developerExtrasEnabled
390 return _preferences->developerExtrasEnabled();
393 - (void)_setDeveloperExtrasEnabled:(BOOL)developerExtrasEnabled
395 _preferences->setDeveloperExtrasEnabled(developerExtrasEnabled);
398 - (BOOL)_logsPageMessagesToSystemConsoleEnabled
400 return _preferences->logsPageMessagesToSystemConsoleEnabled();
403 - (void)_setLogsPageMessagesToSystemConsoleEnabled:(BOOL)logsPageMessagesToSystemConsoleEnabled
405 _preferences->setLogsPageMessagesToSystemConsoleEnabled(logsPageMessagesToSystemConsoleEnabled);
408 - (BOOL)_hiddenPageDOMTimerThrottlingEnabled
410 return _preferences->hiddenPageDOMTimerThrottlingEnabled();
413 - (void)_setHiddenPageDOMTimerThrottlingEnabled:(BOOL)hiddenPageDOMTimerThrottlingEnabled
415 _preferences->setHiddenPageDOMTimerThrottlingEnabled(hiddenPageDOMTimerThrottlingEnabled);
418 - (BOOL)_hiddenPageDOMTimerThrottlingAutoIncreases
420 return _preferences->hiddenPageDOMTimerThrottlingAutoIncreases();
423 - (void)_setHiddenPageDOMTimerThrottlingAutoIncreases:(BOOL)hiddenPageDOMTimerThrottlingAutoIncreases
425 _preferences->setHiddenPageDOMTimerThrottlingAutoIncreases(hiddenPageDOMTimerThrottlingAutoIncreases);
428 - (BOOL)_pageVisibilityBasedProcessSuppressionEnabled
430 return _preferences->pageVisibilityBasedProcessSuppressionEnabled();
433 - (void)_setPageVisibilityBasedProcessSuppressionEnabled:(BOOL)pageVisibilityBasedProcessSuppressionEnabled
435 _preferences->setPageVisibilityBasedProcessSuppressionEnabled(pageVisibilityBasedProcessSuppressionEnabled);
438 - (BOOL)_allowFileAccessFromFileURLs
440 return _preferences->allowFileAccessFromFileURLs();
443 - (void)_setAllowFileAccessFromFileURLs:(BOOL)allowFileAccessFromFileURLs
445 _preferences->setAllowFileAccessFromFileURLs(allowFileAccessFromFileURLs);
448 - (_WKJavaScriptRuntimeFlags)_javaScriptRuntimeFlags
450 return _preferences->javaScriptRuntimeFlags();
453 - (void)_setJavaScriptRuntimeFlags:(_WKJavaScriptRuntimeFlags)javaScriptRuntimeFlags
455 _preferences->setJavaScriptRuntimeFlags(javaScriptRuntimeFlags);
458 - (BOOL)_isStandalone
460 return _preferences->standalone();
463 - (void)_setStandalone:(BOOL)standalone
465 _preferences->setStandalone(standalone);
468 - (BOOL)_diagnosticLoggingEnabled
470 return _preferences->diagnosticLoggingEnabled();
473 - (void)_setDiagnosticLoggingEnabled:(BOOL)diagnosticLoggingEnabled
475 _preferences->setDiagnosticLoggingEnabled(diagnosticLoggingEnabled);
478 - (NSUInteger)_defaultFontSize
480 return _preferences->defaultFontSize();
483 - (void)_setDefaultFontSize:(NSUInteger)defaultFontSize
485 _preferences->setDefaultFontSize(defaultFontSize);
488 - (NSUInteger)_defaultFixedPitchFontSize
490 return _preferences->defaultFixedFontSize();
493 - (void)_setDefaultFixedPitchFontSize:(NSUInteger)defaultFixedPitchFontSize
495 _preferences->setDefaultFixedFontSize(defaultFixedPitchFontSize);
498 - (NSString *)_fixedPitchFontFamily
500 return _preferences->fixedFontFamily();
503 - (void)_setFixedPitchFontFamily:(NSString *)fixedPitchFontFamily
505 _preferences->setFixedFontFamily(fixedPitchFontFamily);
508 + (NSArray<_WKExperimentalFeature *> *)_experimentalFeatures
510 auto features = WebKit::WebPreferences::experimentalFeatures();
511 return [wrapper(API::Array::create(WTFMove(features)).leakRef()) autorelease];
514 - (BOOL)_isEnabledForFeature:(_WKExperimentalFeature *)feature
516 return _preferences->isEnabledForFeature(*feature->_experimentalFeature);
519 - (void)_setEnabled:(BOOL)value forFeature:(_WKExperimentalFeature *)feature
521 _preferences->setEnabledForFeature(value, *feature->_experimentalFeature);
524 - (BOOL)_applePayCapabilityDisclosureAllowed
526 #if ENABLE(APPLE_PAY)
527 return _preferences->applePayCapabilityDisclosureAllowed();
533 - (void)_setApplePayCapabilityDisclosureAllowed:(BOOL)applePayCapabilityDisclosureAllowed
535 #if ENABLE(APPLE_PAY)
536 _preferences->setApplePayCapabilityDisclosureAllowed(applePayCapabilityDisclosureAllowed);
540 - (BOOL)_shouldSuppressKeyboardInputDuringProvisionalNavigation
542 return _preferences->shouldSuppressKeyboardInputDuringProvisionalNavigation();
545 - (void)_setShouldSuppressKeyboardInputDuringProvisionalNavigation:(BOOL)shouldSuppress
547 _preferences->setShouldSuppressKeyboardInputDuringProvisionalNavigation(shouldSuppress);
550 - (BOOL)_loadsImagesAutomatically
552 return _preferences->loadsImagesAutomatically();
555 - (void)_setLoadsImagesAutomatically:(BOOL)loadsImagesAutomatically
557 _preferences->setLoadsImagesAutomatically(loadsImagesAutomatically);
560 - (BOOL)_mediaDevicesEnabled
562 return _preferences->mediaDevicesEnabled();
565 - (void)_setMediaDevicesEnabled:(BOOL)enabled
567 _preferences->setMediaDevicesEnabled(enabled);
570 - (BOOL)_mockCaptureDevicesEnabled
572 return _preferences->mockCaptureDevicesEnabled();
575 - (void)_setMockCaptureDevicesEnabled:(BOOL)enabled
577 _preferences->setMockCaptureDevicesEnabled(enabled);
580 - (BOOL)_mediaCaptureRequiresSecureConnection
582 return _preferences->mediaCaptureRequiresSecureConnection();
585 - (void)_setMediaCaptureRequiresSecureConnection:(BOOL)requiresSecureConnection
587 _preferences->setMediaCaptureRequiresSecureConnection(requiresSecureConnection);
590 - (BOOL)_enumeratingAllNetworkInterfacesEnabled
592 return _preferences->enumeratingAllNetworkInterfacesEnabled();
595 - (void)_setEnumeratingAllNetworkInterfacesEnabled:(BOOL)enabled
597 _preferences->setEnumeratingAllNetworkInterfacesEnabled(enabled);
600 - (BOOL)_iceCandidateFiltertingEnabled
602 return _preferences->iceCandidateFilteringEnabled();
605 - (void)_setICECandidateFilteringEnabled:(BOOL)enabled
607 _preferences->setICECandidateFilteringEnabled(enabled);
610 - (BOOL)_webRTCLegacyAPIEnabled
612 return !_preferences->webRTCLegacyAPIDisabled();
615 - (void)_setWebRTCLegacyAPIEnabled:(BOOL)enabled
617 _preferences->setWebRTCLegacyAPIDisabled(!enabled);
620 - (void)_setJavaScriptCanAccessClipboard:(BOOL)javaScriptCanAccessClipboard
622 _preferences->setJavaScriptCanAccessClipboard(javaScriptCanAccessClipboard);
625 - (BOOL)_javaScriptCanAccessClipboard
627 return _preferences->javaScriptCanAccessClipboard();
630 - (void)_setMediaDocumentEntersFullscreenAutomatically:(BOOL)mediaDocumentEntersFullscreenAutomatically
632 _preferences->setMediaDocumentEntersFullscreenAutomatically(mediaDocumentEntersFullscreenAutomatically);
635 - (BOOL)_mediaDocumentEntersFullscreenAutomatically
637 return _preferences->mediaDocumentEntersFullscreenAutomatically();
642 #endif // WK_API_ENABLED