AX: Remove CSSDisplayContentsAXSupportEnabled flag
[webkit.git] / Source / WebKitLegacy / mac / WebView / WebPreferences.mm
blob75aa8f273754931ba50b0b510377429619c0dd82
1 /*
2  * Copyright (C) 2005-2022 Apple Inc. All rights reserved.
3  *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
30 #import "WebPreferencesInternal.h"
32 #import "NetworkStorageSessionMap.h"
33 #import "TestingFunctions.h"
34 #import "WebApplicationCache.h"
35 #import "WebFeature.h"
36 #import "WebFrameNetworkingContext.h"
37 #import "WebKitLogging.h"
38 #import "WebKitNSStringExtras.h"
39 #import "WebKitVersionChecks.h"
40 #import "WebNSDictionaryExtras.h"
41 #import "WebNSURLExtras.h"
42 #import "WebPreferenceKeysPrivate.h"
43 #import "WebPreferencesDefinitions.h"
44 #import <JavaScriptCore/InitializeThreading.h>
45 #import <WebCore/ApplicationCacheStorage.h>
46 #import <WebCore/AudioSession.h>
47 #import <WebCore/DeprecatedGlobalSettings.h>
48 #import <WebCore/MediaPlayerEnums.h>
49 #import <WebCore/NetworkStorageSession.h>
50 #import <WebCore/RuntimeApplicationChecks.h>
51 #import <WebCore/Settings.h>
52 #import <WebCore/WebCoreJITOperations.h>
53 #import <pal/spi/cf/CFNetworkSPI.h>
54 #import <pal/text/TextEncodingRegistry.h>
55 #import <wtf/Compiler.h>
56 #import <wtf/MainThread.h>
57 #import <wtf/OptionSet.h>
58 #import <wtf/RetainPtr.h>
59 #import <wtf/RunLoop.h>
60 #import <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
62 using namespace WebCore;
64 #if PLATFORM(IOS_FAMILY)
65 #import <WebCore/GraphicsContext.h>
66 #import <WebCore/WebCoreThreadMessage.h>
67 #endif
69 NSString *WebPreferencesChangedNotification = @"WebPreferencesChangedNotification";
70 NSString *WebPreferencesRemovedNotification = @"WebPreferencesRemovedNotification";
71 NSString *WebPreferencesChangedInternalNotification = @"WebPreferencesChangedInternalNotification";
72 NSString *WebPreferencesCacheModelChangedInternalNotification = @"WebPreferencesCacheModelChangedInternalNotification";
74 #define KEY(x) (_private->identifier ? [_private->identifier.get() stringByAppendingString:(x)] : (x))
76 enum { WebPreferencesVersion = 1 };
78 static RetainPtr<WebPreferences>& standardPreferences()
80     static NeverDestroyed<RetainPtr<WebPreferences>> standardPreferences;
81     return standardPreferences;
84 static RetainPtr<NSMutableDictionary>& webPreferencesInstances()
86     static NeverDestroyed<RetainPtr<NSMutableDictionary>> webPreferencesInstances;
87     return webPreferencesInstances;
90 static unsigned webPreferencesInstanceCountWithPrivateBrowsingEnabled;
92 template<unsigned size> static bool contains(const char* const (&array)[size], const char* item)
94     if (!item)
95         return false;
96     for (auto* string : array) {
97         if (equalIgnoringASCIICase(string, item))
98             return true;
99     }
100     return false;
103 static WebCacheModel cacheModelForMainBundle(NSString *bundleIdentifier)
105     @autoreleasepool {
106         // Apps that probably need the small setting
107         static const char* const documentViewerIDs[] = {
108             "Microsoft/com.microsoft.Messenger",
109             "com.adiumX.adiumX",
110             "com.alientechnology.Proteus",
111             "com.apple.Dashcode",
112             "com.apple.iChat",
113             "com.barebones.bbedit",
114             "com.barebones.textwrangler",
115             "com.barebones.yojimbo",
116             "com.equinux.iSale4",
117             "com.growl.growlframework",
118             "com.intrarts.PandoraMan",
119             "com.karelia.Sandvox",
120             "com.macromates.textmate",
121             "com.realmacsoftware.rapidweaverpro",
122             "com.red-sweater.marsedit",
123             "com.yahoo.messenger3",
124             "de.codingmonkeys.SubEthaEdit",
125             "fi.karppinen.Pyro",
126             "info.colloquy",
127             "kungfoo.tv.ecto",
128         };
130         // Apps that probably need the medium setting
131         static const char* const documentBrowserIDs[] = {
132             "com.apple.Dictionary",
133             "com.apple.Xcode",
134             "com.apple.helpviewer",
135             "com.culturedcode.xyle",
136             "com.macrabbit.CSSEdit",
137             "com.panic.Coda",
138             "com.ranchero.NetNewsWire",
139             "com.thinkmac.NewsLife",
140             "org.xlife.NewsFire",
141             "uk.co.opencommunity.vienna2",
142         };
144         // Apps that probably need the large setting
145         static const char* const primaryWebBrowserIDs[] = {
146             "com.app4mac.KidsBrowser",
147             "com.app4mac.wKiosk",
148             "com.freeverse.bumpercar",
149             "com.omnigroup.OmniWeb5",
150             "com.sunrisebrowser.Sunrise",
151             "net.hmdt-web.Shiira",
152         };
154         const char* bundleID = [bundleIdentifier UTF8String];
155         if (contains(documentViewerIDs, bundleID))
156             return WebCacheModelDocumentViewer;
157         if (contains(documentBrowserIDs, bundleID))
158             return WebCacheModelDocumentBrowser;
159         if (contains(primaryWebBrowserIDs, bundleID))
160             return WebCacheModelPrimaryWebBrowser;
162         bool isLinkedAgainstWebKit = WebKitLinkedOnOrAfter(0);
163         if (!isLinkedAgainstWebKit)
164             return WebCacheModelDocumentViewer; // Apps that don't link against WebKit probably aren't meant to be browsers.
166 #if !PLATFORM(IOS_FAMILY)
167         bool isLegacyApp = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_CACHE_MODEL_API);
168 #else
169         bool isLegacyApp = false;
170 #endif
171         if (isLegacyApp)
172             return WebCacheModelDocumentBrowser; // To avoid regressions in apps that depended on old WebKit's large cache.
174         return WebCacheModelDocumentViewer; // To save memory.
175     }
178 #if ENABLE(BUILD_FOR_TESTING)
179 WebCacheModel TestWebPreferencesCacheModelForMainBundle(NSString *bundleIdentifier)
181     return cacheModelForMainBundle(bundleIdentifier);
183 #endif // ENABLE(BUILD_FOR_TESTING)
185 @interface WebPreferences ()
186 - (void)_postCacheModelChangedNotification;
187 @end
189 @interface WebPreferences (WebInternal)
190 + (NSString *)_concatenateKeyWithIBCreatorID:(NSString *)key;
191 + (NSString *)_IBCreatorID;
192 @end
194 enum class UpdateAfterBatchType : uint8_t {
195     API         = 1 << 0,
196     Internal    = 1 << 1
199 struct WebPreferencesPrivate
201 public:
202     WebPreferencesPrivate()
203 #if PLATFORM(IOS_FAMILY)
204         : readWriteQueue { adoptNS(dispatch_queue_create("com.apple.WebPreferences.ReadWriteQueue", DISPATCH_QUEUE_CONCURRENT)) }
205 #endif
206     {
207     }
209 #if PLATFORM(IOS_FAMILY)
210     RetainPtr<dispatch_queue_t> readWriteQueue;
211 #endif
212     RetainPtr<NSMutableDictionary> values;
213     RetainPtr<NSString> identifier;
214     BOOL inPrivateBrowsing { NO };
215     BOOL autosaves { NO };
216     BOOL automaticallyDetectsCacheModel { NO };
217     unsigned numWebViews { 0 };
218     unsigned updateBatchCount { 0 };
219     OptionSet<UpdateAfterBatchType> updateAfterBatchType;
222 #if PLATFORM(IOS_FAMILY)
223 @interface WebPreferences ()
224 - (id)initWithIdentifier:(NSString *)anIdentifier sendChangeNotification:(BOOL)sendChangeNotification;
225 @end
226 #endif
228 @implementation WebPreferences
230 - (instancetype)init
232     // Create fake identifier
233     static int instanceCount = 1;
234     NSString *fakeIdentifier;
236     // At least ensure that identifier hasn't been already used.
237     fakeIdentifier = [NSString stringWithFormat:@"WebPreferences%d", instanceCount++];
238     while ([[self class] _getInstanceForIdentifier:fakeIdentifier]){
239         fakeIdentifier = [NSString stringWithFormat:@"WebPreferences%d", instanceCount++];
240     }
242     return [self initWithIdentifier:fakeIdentifier];
245 #if PLATFORM(IOS_FAMILY)
246 - (id)initWithIdentifier:(NSString *)anIdentifier
248     return [self initWithIdentifier:anIdentifier sendChangeNotification:YES];
250 #endif
252 #if PLATFORM(IOS_FAMILY)
253 - (instancetype)initWithIdentifier:(NSString *)anIdentifier sendChangeNotification:(BOOL)sendChangeNotification
254 #else
255 - (instancetype)initWithIdentifier:(NSString *)anIdentifier
256 #endif
258     WebPreferences *instance = [[self class] _getInstanceForIdentifier:anIdentifier];
259     if (instance) {
260         [self release];
261         return [instance retain];
262     }
264     self = [super init];
265     if (!self)
266         return nil;
268     _private = new WebPreferencesPrivate;
269     _private->values = adoptNS([[NSMutableDictionary alloc] init]);
270     _private->identifier = adoptNS([anIdentifier copy]);
271     _private->automaticallyDetectsCacheModel = YES;
273     [[self class] _setInstance:self forIdentifier:_private->identifier.get()];
275     [self _updatePrivateBrowsingStateTo:[self privateBrowsingEnabled]];
277 #if PLATFORM(IOS_FAMILY)
278     if (sendChangeNotification) {
279         [self _postPreferencesChangedNotification];
280         [self _postCacheModelChangedNotification];
281     }
282 #else
283     [self _postPreferencesChangedNotification];
284     [self _postCacheModelChangedNotification];
285 #endif
287     return self;
290 - (instancetype)initWithCoder:(NSCoder *)decoder
292     self = [super init];
293     if (!self)
294         return nil;
296     _private = new WebPreferencesPrivate;
297     _private->automaticallyDetectsCacheModel = YES;
299     @try {
300         id identifier = nil;
301         id values = nil;
302         if ([decoder allowsKeyedCoding]) {
303             identifier = [decoder decodeObjectForKey:@"Identifier"];
304             values = [decoder decodeObjectForKey:@"Values"];
305         } else {
306             int version;
307             [decoder decodeValueOfObjCType:@encode(int) at:&version size:sizeof(int)];
308             if (version == 1) {
309                 identifier = [decoder decodeObject];
310                 values = [decoder decodeObject];
311             }
312         }
314         if ([identifier isKindOfClass:[NSString class]])
315             _private->identifier = adoptNS([identifier copy]);
316         if ([values isKindOfClass:[NSDictionary class]])
317             _private->values = adoptNS([values mutableCopy]); // ensure dictionary is mutable
319         LOG(Encoding, "Identifier = %@, Values = %@\n", _private->identifier.get(), _private->values.get());
320     } @catch(id) {
321         [self release];
322         return nil;
323     }
325     // If we load a nib multiple times, or have instances in multiple
326     // nibs with the same name, the first guy up wins.
327     WebPreferences *instance = [[self class] _getInstanceForIdentifier:_private->identifier.get()];
328     if (instance) {
329         [self release];
330         self = [instance retain];
331     } else {
332         [[self class] _setInstance:self forIdentifier:_private->identifier.get()];
333         [self _updatePrivateBrowsingStateTo:[self privateBrowsingEnabled]];
334     }
336     return self;
339 - (void)encodeWithCoder:(NSCoder *)encoder
341     if ([encoder allowsKeyedCoding]){
342         [encoder encodeObject:_private->identifier.get() forKey:@"Identifier"];
343 #if PLATFORM(IOS_FAMILY)
344         dispatch_sync(_private->readWriteQueue.get(), ^{
345 #endif
346         [encoder encodeObject:_private->values.get() forKey:@"Values"];
347         LOG (Encoding, "Identifier = %@, Values = %@\n", _private->identifier.get(), _private->values.get());
348 #if PLATFORM(IOS_FAMILY)
349         });
350 #endif
351     }
352     else {
353         int version = WebPreferencesVersion;
354         [encoder encodeValueOfObjCType:@encode(int) at:&version];
355         [encoder encodeObject:_private->identifier.get()];
356 #if PLATFORM(IOS_FAMILY)
357         dispatch_sync(_private->readWriteQueue.get(), ^{
358 #endif
359         [encoder encodeObject:_private->values.get()];
360 #if PLATFORM(IOS_FAMILY)
361         });
362 #endif
363     }
366 + (WebPreferences *)standardPreferences
368 #if !PLATFORM(IOS_FAMILY)
369     if (!standardPreferences()) {
370         standardPreferences() = adoptNS([[WebPreferences alloc] initWithIdentifier:nil]);
371         [standardPreferences() setAutosaves:YES];
372     }
373 #else
374     static dispatch_once_t pred;
375     dispatch_once(&pred, ^{
376         standardPreferences() = adoptNS([[WebPreferences alloc] initWithIdentifier:nil sendChangeNotification:NO]);
377         [standardPreferences() _postPreferencesChangedNotification];
378         [standardPreferences() setAutosaves:YES];
379     });
380 #endif
382     return standardPreferences().get();
385 // if we ever have more than one WebPreferences object, this would move to init
386 + (void)initialize
388 #if PLATFORM(MAC)
389     JSC::initialize();
390     WTF::initializeMainThread();
391     WebCore::populateJITOperations();
392 #endif
394     NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
395         INITIALIZE_DEFAULT_PREFERENCES_DICTIONARY_FROM_GENERATED_PREFERENCES
397         @NO, WebKitUserStyleSheetEnabledPreferenceKey,
398         @"", WebKitUserStyleSheetLocationPreferenceKey,
399         @YES, WebKitAllowAnimatedImagesPreferenceKey,
400         @YES, WebKitAllowAnimatedImageLoopingPreferenceKey,
401         @"1800", WebKitBackForwardCacheExpirationIntervalKey,
402         @NO, WebKitPrivateBrowsingEnabledPreferenceKey,
403         @(cacheModelForMainBundle([[NSBundle mainBundle] bundleIdentifier])), WebKitCacheModelPreferenceKey,
404         @YES, WebKitZoomsTextOnlyPreferenceKey,
405         [NSNumber numberWithLongLong:ApplicationCacheStorage::noQuota()], WebKitApplicationCacheTotalQuota,
407         // FIXME: Are these relevent to WebKitLegacy? If not, we should remove them.
408         @NO, WebKitResourceLoadStatisticsEnabledPreferenceKey,
409         @NO, WebKitDebugInAppBrowserPrivacyEnabledPreferenceKey,
411 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
412         @"~/Library/WebKit/MediaKeys", WebKitMediaKeysStorageDirectoryKey,
413 #endif
415 #if PLATFORM(MAC)
416         @NO, WebKitRespectStandardStyleKeyEquivalentsPreferenceKey,
417         @"1", WebKitPDFDisplayModePreferenceKey,
418         @"0", WebKitPDFScaleFactorPreferenceKey,
419         @(WebTextDirectionSubmenuAutomaticallyIncluded), WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey,
420         [NSNumber numberWithLongLong:ApplicationCacheStorage::noQuota()], WebKitApplicationCacheDefaultOriginQuota,
421 #endif
423 #if PLATFORM(IOS_FAMILY)
424         @NO, WebKitStorageTrackerEnabledPreferenceKey,
425         @(static_cast<unsigned>(AudioSession::CategoryType::None)), WebKitAudioSessionCategoryOverride,
427         // Per-Origin Quota on iOS is 25MB. When the quota is reached for a particular origin
428         // the quota for that origin can be increased. See also webView:exceededApplicationCacheOriginQuotaForSecurityOrigin:totalSpaceNeeded in WebUI/WebUIDelegate.m.
429         [NSNumber numberWithLongLong:(25 * 1024 * 1024)], WebKitApplicationCacheDefaultOriginQuota,
431         @NO, WebKitAlwaysRequestGeolocationPermissionPreferenceKey,
432         @(static_cast<int>(InterpolationQuality::Low)), WebKitInterpolationQualityPreferenceKey,
433         @NO, WebKitNetworkDataUsageTrackingEnabledPreferenceKey,
434         @"", WebKitNetworkInterfaceNamePreferenceKey,
435 #endif
436         nil];
438 #if !PLATFORM(IOS_FAMILY)
439     // This value shouldn't ever change, which is assumed in the initialization of WebKitPDFDisplayModePreferenceKey above
440     ASSERT(kPDFDisplaySinglePageContinuous == 1);
441 #endif
442     [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
445 - (void)dealloc
447     [self _updatePrivateBrowsingStateTo:NO];
449     delete _private;
450     [super dealloc];
453 - (NSString *)identifier
455     return _private->identifier.get();
458 - (id)_valueForKey:(NSString *)key
460     NSString *_key = KEY(key);
461 #if PLATFORM(IOS_FAMILY)
462     __block id o = nil;
463     dispatch_sync(_private->readWriteQueue.get(), ^{
464         o = [_private->values.get() objectForKey:_key];
465     });
466 #else
467     id o = [_private->values.get() objectForKey:_key];
468 #endif
469     if (o)
470         return o;
471     o = [[NSUserDefaults standardUserDefaults] objectForKey:_key];
472     if (!o && key != _key)
473         o = [[NSUserDefaults standardUserDefaults] objectForKey:key];
474     return o;
477 - (NSString *)_stringValueForKey:(NSString *)key
479     id s = [self _valueForKey:key];
480     return [s isKindOfClass:[NSString class]] ? (NSString *)s : nil;
483 - (void)_setStringValue:(NSString *)value forKey:(NSString *)key
485     if ([[self _stringValueForKey:key] isEqualToString:value])
486         return;
487     NSString *_key = KEY(key);
488 #if PLATFORM(IOS_FAMILY)
489     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
490 #endif
491     [_private->values.get() setObject:value forKey:_key];
492 #if PLATFORM(IOS_FAMILY)
493     });
494 #endif
495     if (_private->autosaves)
496         [[NSUserDefaults standardUserDefaults] setObject:value forKey:_key];
497     [self _postPreferencesChangedNotification];
500 - (NSArray<NSString *> *)_stringArrayValueForKey:(NSString *)key
502     id value = [self _valueForKey:key];
503     if (![value isKindOfClass:[NSArray class]])
504         return nil;
506     NSArray *array = (NSArray *)value;
507     for (id object in array) {
508         if (![object isKindOfClass:[NSString class]])
509             return nil;
510     }
512     return (NSArray<NSString *> *)array;
515 - (void)_setStringArrayValueForKey:(NSArray<NSString *> *)value forKey:(NSString *)key
517     NSString *_key = KEY(key);
518 #if PLATFORM(IOS_FAMILY)
519     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
520 #endif
521         [_private->values.get() setObject:value forKey:_key];
522 #if PLATFORM(IOS_FAMILY)
523     });
524 #endif
525     if (_private->autosaves)
526         [[NSUserDefaults standardUserDefaults] setObject:value forKey:_key];
527     [self _postPreferencesChangedNotification];
530 - (int)_integerValueForKey:(NSString *)key
532     id o = [self _valueForKey:key];
533     return [o respondsToSelector:@selector(intValue)] ? [o intValue] : 0;
536 - (void)_setIntegerValue:(int)value forKey:(NSString *)key
538     if ([self _integerValueForKey:key] == value)
539         return;
540     NSString *_key = KEY(key);
541 #if PLATFORM(IOS_FAMILY)
542     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
543 #endif
544     [_private->values.get() setObject:@(value) forKey:_key];
545 #if PLATFORM(IOS_FAMILY)
546     });
547 #endif
548     if (_private->autosaves)
549         [[NSUserDefaults standardUserDefaults] setInteger:value forKey:_key];
550     [self _postPreferencesChangedNotification];
553 - (unsigned int)_unsignedIntValueForKey:(NSString *)key
555     id o = [self _valueForKey:key];
556     return [o respondsToSelector:@selector(unsignedIntValue)] ? [o unsignedIntValue] : 0;
559 - (void)_setUnsignedIntValue:(unsigned int)value forKey:(NSString *)key
561     if ([self _unsignedIntValueForKey:key] == value)
562         return;
563     NSString *_key = KEY(key);
564 #if PLATFORM(IOS_FAMILY)
565     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
566 #endif
567     [_private->values.get() setObject:@(value) forKey:_key];
568 #if PLATFORM(IOS_FAMILY)
569     });
570 #endif
571     if (_private->autosaves)
572         [[NSUserDefaults standardUserDefaults] setObject:@(value) forKey:_key];
573     [self _postPreferencesChangedNotification];
576 - (float)_floatValueForKey:(NSString *)key
578     id o = [self _valueForKey:key];
579     return [o respondsToSelector:@selector(floatValue)] ? [o floatValue] : 0.0f;
582 - (void)_setFloatValue:(float)value forKey:(NSString *)key
584     if ([self _floatValueForKey:key] == value)
585         return;
586     NSString *_key = KEY(key);
587 #if PLATFORM(IOS_FAMILY)
588     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
589 #endif
590     [_private->values.get() setObject:@(value) forKey:_key];
591 #if PLATFORM(IOS_FAMILY)
592     });
593 #endif
594     if (_private->autosaves)
595         [[NSUserDefaults standardUserDefaults] setFloat:value forKey:_key];
596     [self _postPreferencesChangedNotification];
599 - (BOOL)_boolValueForKey:(NSString *)key
601     return [self _integerValueForKey:key] != 0;
604 - (void)_setBoolValue:(BOOL)value forKey:(NSString *)key
606     if ([self _boolValueForKey:key] == value)
607         return;
608     NSString *_key = KEY(key);
609 #if PLATFORM(IOS_FAMILY)
610     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
611 #endif
612     [_private->values.get() setObject:@(value) forKey:_key];
613 #if PLATFORM(IOS_FAMILY)
614     });
615 #endif
616     if (_private->autosaves)
617         [[NSUserDefaults standardUserDefaults] setBool:value forKey:_key];
618     [self _postPreferencesChangedNotification];
621 - (long long)_longLongValueForKey:(NSString *)key
623     id o = [self _valueForKey:key];
624     return [o respondsToSelector:@selector(longLongValue)] ? [o longLongValue] : 0;
627 - (void)_setLongLongValue:(long long)value forKey:(NSString *)key
629     if ([self _longLongValueForKey:key] == value)
630         return;
631     NSString *_key = KEY(key);
632 #if PLATFORM(IOS_FAMILY)
633     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
634 #endif
635     [_private->values.get() setObject:@(value) forKey:_key];
636 #if PLATFORM(IOS_FAMILY)
637     });
638 #endif
639     if (_private->autosaves)
640         [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithLongLong:value] forKey:_key];
641     [self _postPreferencesChangedNotification];
644 - (unsigned long long)_unsignedLongLongValueForKey:(NSString *)key
646     id o = [self _valueForKey:key];
647     return [o respondsToSelector:@selector(unsignedLongLongValue)] ? [o unsignedLongLongValue] : 0;
650 - (void)_setUnsignedLongLongValue:(unsigned long long)value forKey:(NSString *)key
652     if ([self _unsignedLongLongValueForKey:key] == value)
653         return;
654     NSString *_key = KEY(key);
655 #if PLATFORM(IOS_FAMILY)
656     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
657 #endif
658     [_private->values.get() setObject:@(value) forKey:_key];
659 #if PLATFORM(IOS_FAMILY)
660     });
661 #endif
662     if (_private->autosaves)
663         [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedLongLong:value] forKey:_key];
664     [self _postPreferencesChangedNotification];
667 - (NSString *)standardFontFamily
669     return [self _stringValueForKey: WebKitStandardFontPreferenceKey];
672 - (void)setStandardFontFamily:(NSString *)family
674     [self _setStringValue: family forKey: WebKitStandardFontPreferenceKey];
677 - (NSString *)fixedFontFamily
679     return [self _stringValueForKey: WebKitFixedFontPreferenceKey];
682 - (void)setFixedFontFamily:(NSString *)family
684     [self _setStringValue: family forKey: WebKitFixedFontPreferenceKey];
687 - (NSString *)serifFontFamily
689     return [self _stringValueForKey: WebKitSerifFontPreferenceKey];
692 - (void)setSerifFontFamily:(NSString *)family
694     [self _setStringValue: family forKey: WebKitSerifFontPreferenceKey];
697 - (NSString *)sansSerifFontFamily
699     return [self _stringValueForKey: WebKitSansSerifFontPreferenceKey];
702 - (void)setSansSerifFontFamily:(NSString *)family
704     [self _setStringValue: family forKey: WebKitSansSerifFontPreferenceKey];
707 - (NSString *)cursiveFontFamily
709     return [self _stringValueForKey: WebKitCursiveFontPreferenceKey];
712 - (void)setCursiveFontFamily:(NSString *)family
714     [self _setStringValue: family forKey: WebKitCursiveFontPreferenceKey];
717 - (NSString *)fantasyFontFamily
719     return [self _stringValueForKey: WebKitFantasyFontPreferenceKey];
722 - (void)setFantasyFontFamily:(NSString *)family
724     [self _setStringValue: family forKey: WebKitFantasyFontPreferenceKey];
727 - (int)defaultFontSize
729     return [self _integerValueForKey: WebKitDefaultFontSizePreferenceKey];
732 - (void)setDefaultFontSize:(int)size
734     [self _setIntegerValue: size forKey: WebKitDefaultFontSizePreferenceKey];
737 - (int)defaultFixedFontSize
739     return [self _integerValueForKey: WebKitDefaultFixedFontSizePreferenceKey];
742 - (void)setDefaultFixedFontSize:(int)size
744     [self _setIntegerValue: size forKey: WebKitDefaultFixedFontSizePreferenceKey];
747 - (int)minimumFontSize
749     return [self _integerValueForKey: WebKitMinimumFontSizePreferenceKey];
752 - (void)setMinimumFontSize:(int)size
754     [self _setIntegerValue: size forKey: WebKitMinimumFontSizePreferenceKey];
757 - (int)minimumLogicalFontSize
759   return [self _integerValueForKey: WebKitMinimumLogicalFontSizePreferenceKey];
762 - (void)setMinimumLogicalFontSize:(int)size
764   [self _setIntegerValue: size forKey: WebKitMinimumLogicalFontSizePreferenceKey];
767 - (NSString *)defaultTextEncodingName
769     return [self _stringValueForKey: WebKitDefaultTextEncodingNamePreferenceKey];
772 - (void)setDefaultTextEncodingName:(NSString *)encoding
774     [self _setStringValue: encoding forKey: WebKitDefaultTextEncodingNamePreferenceKey];
777 #if !PLATFORM(IOS_FAMILY)
778 - (BOOL)userStyleSheetEnabled
780     return [self _boolValueForKey: WebKitUserStyleSheetEnabledPreferenceKey];
783 - (void)setUserStyleSheetEnabled:(BOOL)flag
785     [self _setBoolValue: flag forKey: WebKitUserStyleSheetEnabledPreferenceKey];
788 - (NSURL *)userStyleSheetLocation
790     NSString *locationString = [self _stringValueForKey: WebKitUserStyleSheetLocationPreferenceKey];
792     if ([locationString _webkit_looksLikeAbsoluteURL]) {
793         return [NSURL _web_URLWithDataAsString:locationString];
794     } else {
795         locationString = [locationString stringByExpandingTildeInPath];
796         return [NSURL fileURLWithPath:locationString isDirectory:NO];
797     }
800 - (void)setUserStyleSheetLocation:(NSURL *)URL
802     NSString *locationString;
804     if ([URL isFileURL]) {
805         locationString = [[URL path] _web_stringByAbbreviatingWithTildeInPath];
806     } else {
807         locationString = [URL _web_originalDataAsString];
808     }
810     if (!locationString)
811         locationString = @"";
813     [self _setStringValue:locationString forKey: WebKitUserStyleSheetLocationPreferenceKey];
815 #else
817 // These methods have had their implementations removed on iOS since it
818 // is wrong to have such a setting stored in preferences that, when read,
819 // is applied to all WebViews in a iOS process. Such a design might work
820 // OK for an application like Safari on Mac OS X, where the only WebViews
821 // in use display web content in a straightforward manner. However, it is
822 // wrong for iOS, where WebViews are used for various purposes, like
823 // text editing, text rendering, and displaying web content.
825 // I have changed the user style sheet mechanism to be a per-WebView
826 // setting, rather than a per-process preference. This seems to give the
827 // behavior we want for iOS.
829 - (BOOL)userStyleSheetEnabled
831     return NO;
834 - (void)setUserStyleSheetEnabled:(BOOL)flag
836     // no-op
839 - (NSURL *)userStyleSheetLocation
841     return nil;
844 - (void)setUserStyleSheetLocation:(NSURL *)URL
846     // no-op
848 #endif // PLATFORM(IOS_FAMILY)
850 #if !PLATFORM(IOS_FAMILY)
851 - (BOOL)shouldPrintBackgrounds
853     return [self _boolValueForKey: WebKitShouldPrintBackgroundsPreferenceKey];
856 - (void)setShouldPrintBackgrounds:(BOOL)flag
858     [self _setBoolValue: flag forKey: WebKitShouldPrintBackgroundsPreferenceKey];
860 #endif
862 - (BOOL)isJavaScriptEnabled
864     return [self _boolValueForKey: WebKitJavaScriptEnabledPreferenceKey];
867 - (void)setJavaScriptEnabled:(BOOL)flag
869     [self _setBoolValue: flag forKey: WebKitJavaScriptEnabledPreferenceKey];
872 - (BOOL)javaScriptCanOpenWindowsAutomatically
874     return [self _boolValueForKey: WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey];
877 - (void)setJavaScriptCanOpenWindowsAutomatically:(BOOL)flag
879     [self _setBoolValue: flag forKey: WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey];
882 - (BOOL)arePlugInsEnabled
884     return [self _boolValueForKey: WebKitPluginsEnabledPreferenceKey];
887 - (void)setPlugInsEnabled:(BOOL)flag
889     [self _setBoolValue: flag forKey: WebKitPluginsEnabledPreferenceKey];
892 - (BOOL)allowsAnimatedImages
894     return [self _boolValueForKey: WebKitAllowAnimatedImagesPreferenceKey];
897 - (void)setAllowsAnimatedImages:(BOOL)flag
899     [self _setBoolValue: flag forKey: WebKitAllowAnimatedImagesPreferenceKey];
902 - (BOOL)allowsAnimatedImageLooping
904     return [self _boolValueForKey: WebKitAllowAnimatedImageLoopingPreferenceKey];
907 - (void)setAllowsAnimatedImageLooping: (BOOL)flag
909     [self _setBoolValue: flag forKey: WebKitAllowAnimatedImageLoopingPreferenceKey];
912 - (void)setLoadsImagesAutomatically: (BOOL)flag
914     [self _setBoolValue: flag forKey: WebKitDisplayImagesKey];
917 - (BOOL)loadsImagesAutomatically
919     return [self _boolValueForKey: WebKitDisplayImagesKey];
922 - (void)setAdditionalSupportedImageTypes:(NSArray<NSString*> *)imageTypes
924     [self _setStringArrayValueForKey:imageTypes forKey:WebKitAdditionalSupportedImageTypesKey];
927 - (NSArray<NSString *> *)additionalSupportedImageTypes
929     return [self _stringArrayValueForKey:WebKitAdditionalSupportedImageTypesKey];
932 - (void)setAutosaves:(BOOL)flag
934     _private->autosaves = flag;
937 - (BOOL)autosaves
939     return _private->autosaves;
942 #if !PLATFORM(IOS_FAMILY)
943 - (void)setTabsToLinks:(BOOL)flag
945     [self _setBoolValue: flag forKey: WebKitTabToLinksPreferenceKey];
948 - (BOOL)tabsToLinks
950     return [self _boolValueForKey:WebKitTabToLinksPreferenceKey];
952 #endif
954 - (void)setPrivateBrowsingEnabled:(BOOL)enabled
956     [self _updatePrivateBrowsingStateTo:enabled];
957     [self _setBoolValue:enabled forKey:WebKitPrivateBrowsingEnabledPreferenceKey];
960 - (BOOL)privateBrowsingEnabled
962     // Changes to private browsing defaults do not have effect on existing WebPreferences, and must be done through -setPrivateBrowsingEnabled.
963     // This is needed to accurately track private browsing sessions in the process.
964     return _private->inPrivateBrowsing;
967 - (void)_updatePrivateBrowsingStateTo:(BOOL)enabled
969     if (!_private) {
970         ASSERT(!enabled);
971         return;
972     }
974     if (enabled == _private->inPrivateBrowsing)
975         return;
976     if (enabled > _private->inPrivateBrowsing) {
977         WebFrameNetworkingContext::ensurePrivateBrowsingSession();
978         ++webPreferencesInstanceCountWithPrivateBrowsingEnabled;
979     } else {
980         ASSERT(webPreferencesInstanceCountWithPrivateBrowsingEnabled);
981         --webPreferencesInstanceCountWithPrivateBrowsingEnabled;
982         if (!webPreferencesInstanceCountWithPrivateBrowsingEnabled)
983             WebFrameNetworkingContext::destroyPrivateBrowsingSession();
984     }
985     _private->inPrivateBrowsing = enabled;
988 - (void)setUsesPageCache:(BOOL)usesPageCache
990     [self _setBoolValue:usesPageCache forKey:WebKitUsesPageCachePreferenceKey];
993 - (BOOL)usesPageCache
995     return [self _boolValueForKey:WebKitUsesPageCachePreferenceKey];
998 - (void)_postCacheModelChangedNotification
1000 #if !PLATFORM(IOS_FAMILY)
1001     if (!pthread_main_np()) {
1002         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1003         return;
1004     }
1005 #endif
1007     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesCacheModelChangedInternalNotification object:self userInfo:nil];
1010 - (void)setCacheModel:(WebCacheModel)cacheModel
1012     [self _setIntegerValue:cacheModel forKey:WebKitCacheModelPreferenceKey];
1013     [self setAutomaticallyDetectsCacheModel:NO];
1014     [self _postCacheModelChangedNotification];
1017 - (WebCacheModel)cacheModel
1019     return (WebCacheModel)[self _integerValueForKey:WebKitCacheModelPreferenceKey];
1023 - (void)setSuppressesIncrementalRendering:(BOOL)suppressesIncrementalRendering
1025     [self _setBoolValue:suppressesIncrementalRendering forKey:WebKitSuppressesIncrementalRenderingKey];
1028 - (BOOL)suppressesIncrementalRendering
1030     return [self _boolValueForKey:WebKitSuppressesIncrementalRenderingKey];
1033 - (BOOL)allowsAirPlayForMediaPlayback
1035 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
1036     return [self _boolValueForKey:WebKitAllowsAirPlayForMediaPlaybackPreferenceKey];
1037 #else
1038     return false;
1039 #endif
1042 - (void)setAllowsAirPlayForMediaPlayback:(BOOL)flag
1044 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
1045     [self _setBoolValue:flag forKey:WebKitAllowsAirPlayForMediaPlaybackPreferenceKey];
1046 #endif
1049 @end
1051 @implementation WebPreferences (WebPrivate)
1053 - (BOOL)isDNSPrefetchingEnabled
1055     return [self _boolValueForKey:WebKitDNSPrefetchingEnabledPreferenceKey];
1058 - (void)setDNSPrefetchingEnabled:(BOOL)flag
1060     [self _setBoolValue:flag forKey:WebKitDNSPrefetchingEnabledPreferenceKey];
1063 - (BOOL)developerExtrasEnabled
1065     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
1066     if ([defaults boolForKey:@"DisableWebKitDeveloperExtras"])
1067         return NO;
1068 #ifdef NDEBUG
1069     if ([defaults boolForKey:@"WebKitDeveloperExtras"] || [defaults boolForKey:@"IncludeDebugMenu"])
1070         return YES;
1071     return [self _boolValueForKey:WebKitDeveloperExtrasEnabledPreferenceKey];
1072 #else
1073     return YES; // always enable in debug builds
1074 #endif
1077 - (WebKitJavaScriptRuntimeFlags)javaScriptRuntimeFlags
1079     return static_cast<WebKitJavaScriptRuntimeFlags>([self _unsignedIntValueForKey:WebKitJavaScriptRuntimeFlagsPreferenceKey]);
1082 - (void)setJavaScriptRuntimeFlags:(WebKitJavaScriptRuntimeFlags)flags
1084     [self _setUnsignedIntValue:flags forKey:WebKitJavaScriptRuntimeFlagsPreferenceKey];
1087 - (void)setDeveloperExtrasEnabled:(BOOL)flag
1089     [self _setBoolValue:flag forKey:WebKitDeveloperExtrasEnabledPreferenceKey];
1092 - (BOOL)authorAndUserStylesEnabled
1094     return [self _boolValueForKey:WebKitAuthorAndUserStylesEnabledPreferenceKey];
1097 - (void)setAuthorAndUserStylesEnabled:(BOOL)flag
1099     [self _setBoolValue:flag forKey:WebKitAuthorAndUserStylesEnabledPreferenceKey];
1102 // FIXME: applicationChromeMode is no longer needed by ToT, but is still used in Safari 8.
1103 - (BOOL)applicationChromeModeEnabled
1105     return NO;
1108 - (void)setApplicationChromeModeEnabled:(BOOL)flag
1112 - (BOOL)domTimersThrottlingEnabled
1114     return [self _boolValueForKey:WebKitDOMTimersThrottlingEnabledPreferenceKey];
1117 - (void)setDOMTimersThrottlingEnabled:(BOOL)flag
1119     [self _setBoolValue:flag forKey:WebKitDOMTimersThrottlingEnabledPreferenceKey];
1122 - (BOOL)webArchiveDebugModeEnabled
1124     return [self _boolValueForKey:WebKitWebArchiveDebugModeEnabledPreferenceKey];
1127 - (void)setWebArchiveDebugModeEnabled:(BOOL)flag
1129     [self _setBoolValue:flag forKey:WebKitWebArchiveDebugModeEnabledPreferenceKey];
1132 - (BOOL)localFileContentSniffingEnabled
1134     return [self _boolValueForKey:WebKitLocalFileContentSniffingEnabledPreferenceKey];
1137 - (void)setLocalFileContentSniffingEnabled:(BOOL)flag
1139     [self _setBoolValue:flag forKey:WebKitLocalFileContentSniffingEnabledPreferenceKey];
1142 - (BOOL)offlineWebApplicationCacheEnabled
1144     return [self _boolValueForKey:WebKitOfflineWebApplicationCacheEnabledPreferenceKey];
1147 - (void)setOfflineWebApplicationCacheEnabled:(BOOL)flag
1149     [self _setBoolValue:flag forKey:WebKitOfflineWebApplicationCacheEnabledPreferenceKey];
1152 - (BOOL)zoomsTextOnly
1154     return [self _boolValueForKey:WebKitZoomsTextOnlyPreferenceKey];
1157 - (void)setZoomsTextOnly:(BOOL)flag
1159     [self _setBoolValue:flag forKey:WebKitZoomsTextOnlyPreferenceKey];
1162 - (BOOL)javaScriptCanAccessClipboard
1164     return [self _boolValueForKey:WebKitJavaScriptCanAccessClipboardPreferenceKey];
1167 - (void)setJavaScriptCanAccessClipboard:(BOOL)flag
1169     [self _setBoolValue:flag forKey:WebKitJavaScriptCanAccessClipboardPreferenceKey];
1172 #if !PLATFORM(IOS_FAMILY)
1173 - (BOOL)respectStandardStyleKeyEquivalents
1175     return [self _boolValueForKey:WebKitRespectStandardStyleKeyEquivalentsPreferenceKey];
1178 - (void)setRespectStandardStyleKeyEquivalents:(BOOL)flag
1180     [self _setBoolValue:flag forKey:WebKitRespectStandardStyleKeyEquivalentsPreferenceKey];
1183 - (BOOL)showsURLsInToolTips
1185     return [self _boolValueForKey:WebKitShowsURLsInToolTipsPreferenceKey];
1188 - (void)setShowsURLsInToolTips:(BOOL)flag
1190     [self _setBoolValue:flag forKey:WebKitShowsURLsInToolTipsPreferenceKey];
1193 - (BOOL)showsToolTipOverTruncatedText
1195     return [self _boolValueForKey:WebKitShowsToolTipOverTruncatedTextPreferenceKey];
1198 - (void)setShowsToolTipOverTruncatedText:(BOOL)flag
1200     [self _setBoolValue:flag forKey:WebKitShowsToolTipOverTruncatedTextPreferenceKey];
1203 - (BOOL)textAreasAreResizable
1205     return [self _boolValueForKey: WebKitTextAreasAreResizablePreferenceKey];
1208 - (void)setTextAreasAreResizable:(BOOL)flag
1210     [self _setBoolValue: flag forKey: WebKitTextAreasAreResizablePreferenceKey];
1212 #endif // !PLATFORM(IOS_FAMILY)
1214 - (BOOL)shrinksStandaloneImagesToFit
1216     return [self _boolValueForKey:WebKitShrinksStandaloneImagesToFitPreferenceKey];
1219 - (void)setShrinksStandaloneImagesToFit:(BOOL)flag
1221     [self _setBoolValue:flag forKey:WebKitShrinksStandaloneImagesToFitPreferenceKey];
1224 - (BOOL)automaticallyDetectsCacheModel
1226     return _private->automaticallyDetectsCacheModel;
1229 - (void)setAutomaticallyDetectsCacheModel:(BOOL)automaticallyDetectsCacheModel
1231     _private->automaticallyDetectsCacheModel = automaticallyDetectsCacheModel;
1234 - (BOOL)usesEncodingDetector
1236     return [self _boolValueForKey: WebKitUsesEncodingDetectorPreferenceKey];
1239 - (void)setUsesEncodingDetector:(BOOL)flag
1241     [self _setBoolValue: flag forKey: WebKitUsesEncodingDetectorPreferenceKey];
1244 - (BOOL)isWebSecurityEnabled
1246     return [self _boolValueForKey: WebKitWebSecurityEnabledPreferenceKey];
1249 - (void)setWebSecurityEnabled:(BOOL)flag
1251     [self _setBoolValue: flag forKey: WebKitWebSecurityEnabledPreferenceKey];
1254 - (BOOL)allowUniversalAccessFromFileURLs
1256     return [self _boolValueForKey: WebKitAllowUniversalAccessFromFileURLsPreferenceKey];
1259 - (void)setAllowUniversalAccessFromFileURLs:(BOOL)flag
1261     [self _setBoolValue: flag forKey: WebKitAllowUniversalAccessFromFileURLsPreferenceKey];
1264 - (BOOL)allowFileAccessFromFileURLs
1266     return [self _boolValueForKey: WebKitAllowFileAccessFromFileURLsPreferenceKey];
1269 - (void)setAllowFileAccessFromFileURLs:(BOOL)flag
1271     [self _setBoolValue: flag forKey: WebKitAllowFileAccessFromFileURLsPreferenceKey];
1274 - (BOOL)allowTopNavigationToDataURLs
1276     return [self _boolValueForKey: WebKitAllowTopNavigationToDataURLsPreferenceKey];
1279 - (void)setAllowTopNavigationToDataURLs:(BOOL)flag
1281     [self _setBoolValue: flag forKey: WebKitAllowTopNavigationToDataURLsPreferenceKey];
1284 - (BOOL)allowCrossOriginSubresourcesToAskForCredentials
1286     return [self _boolValueForKey:WebKitAllowCrossOriginSubresourcesToAskForCredentialsKey];
1289 - (void)setAllowCrossOriginSubresourcesToAskForCredentials:(BOOL)flag
1291     [self _setBoolValue:flag forKey:WebKitAllowCrossOriginSubresourcesToAskForCredentialsKey];
1294 - (BOOL)needsStorageAccessFromFileURLsQuirk
1296     return [self _boolValueForKey: WebKitNeedsStorageAccessFromFileURLsQuirkKey];
1299 -(void)setNeedsStorageAccessFromFileURLsQuirk:(BOOL)flag
1301     [self _setBoolValue: flag forKey: WebKitNeedsStorageAccessFromFileURLsQuirkKey];
1304 - (NSTimeInterval)_backForwardCacheExpirationInterval
1306     return (NSTimeInterval)[self _floatValueForKey:WebKitBackForwardCacheExpirationIntervalKey];
1309 #if PLATFORM(IOS_FAMILY)
1310 - (BOOL)_standalone
1312     return [self _boolValueForKey:WebKitStandalonePreferenceKey];
1315 - (void)_setStandalone:(BOOL)flag
1317     [self _setBoolValue:flag forKey:WebKitStandalonePreferenceKey];
1320 - (void)_setTelephoneNumberParsingEnabled:(BOOL)flag
1322     [self _setBoolValue:flag forKey:WebKitTelephoneParsingEnabledPreferenceKey];
1325 - (BOOL)_telephoneNumberParsingEnabled
1327     return [self _boolValueForKey:WebKitTelephoneParsingEnabledPreferenceKey];
1330 - (BOOL)contentChangeObserverEnabled
1332     return [self _boolValueForKey:WebKitContentChangeObserverEnabledPreferenceKey];
1335 - (void)setContentChangeObserverEnabled:(BOOL)enabled
1337     [self _setBoolValue:enabled forKey:WebKitContentChangeObserverEnabledPreferenceKey];
1339 #endif
1341 #if ENABLE(TEXT_AUTOSIZING)
1342 - (void)_setMinimumZoomFontSize:(float)size
1344     [self _setFloatValue:size forKey:WebKitMinimumZoomFontSizePreferenceKey];
1347 - (float)_minimumZoomFontSize
1349     return [self _floatValueForKey:WebKitMinimumZoomFontSizePreferenceKey];
1352 - (void)_setTextAutosizingEnabled:(BOOL)enabled
1354     [self _setBoolValue:enabled forKey:WebKitTextAutosizingEnabledPreferenceKey];
1357 - (BOOL)_textAutosizingEnabled
1359     return [self _boolValueForKey:WebKitTextAutosizingEnabledPreferenceKey];
1361 #endif
1363 #if PLATFORM(IOS_FAMILY)
1364 - (void)_setMaxParseDuration:(float)d
1366     [self _setFloatValue:d forKey:WebKitMaxParseDurationPreferenceKey];
1369 - (float)_maxParseDuration
1371     return [self _floatValueForKey:WebKitMaxParseDurationPreferenceKey];
1374 - (void)_setAllowMultiElementImplicitFormSubmission:(BOOL)flag
1376     [self _setBoolValue:flag forKey:WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey];
1379 - (BOOL)_allowMultiElementImplicitFormSubmission
1381     return [self _boolValueForKey:WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey];
1384 - (void)_setAlwaysRequestGeolocationPermission:(BOOL)flag
1386     [self _setBoolValue:flag forKey:WebKitAlwaysRequestGeolocationPermissionPreferenceKey];
1389 - (BOOL)_alwaysRequestGeolocationPermission
1391     return [self _boolValueForKey:WebKitAlwaysRequestGeolocationPermissionPreferenceKey];
1394 - (void)_setInterpolationQuality:(int)quality
1396     [self _setIntegerValue:quality forKey:WebKitInterpolationQualityPreferenceKey];
1399 - (int)_interpolationQuality
1401     return [self _integerValueForKey:WebKitInterpolationQualityPreferenceKey];
1404 - (BOOL)_allowPasswordEcho
1406     return [self _boolValueForKey:WebKitPasswordEchoEnabledPreferenceKey];
1409 - (float)_passwordEchoDuration
1411     return [self _floatValueForKey:WebKitPasswordEchoDurationPreferenceKey];
1414 #endif // PLATFORM(IOS_FAMILY)
1416 #if !PLATFORM(IOS_FAMILY)
1417 - (float)PDFScaleFactor
1419     return [self _floatValueForKey:WebKitPDFScaleFactorPreferenceKey];
1422 - (void)setPDFScaleFactor:(float)factor
1424     [self _setFloatValue:factor forKey:WebKitPDFScaleFactorPreferenceKey];
1426 #endif
1428 - (int64_t)applicationCacheTotalQuota
1430     return [self _longLongValueForKey:WebKitApplicationCacheTotalQuota];
1433 - (void)setApplicationCacheTotalQuota:(int64_t)quota
1435     [self _setLongLongValue:quota forKey:WebKitApplicationCacheTotalQuota];
1437     // Application Cache Preferences are stored on the global cache storage manager, not in Settings.
1438     [WebApplicationCache setMaximumSize:quota];
1441 - (int64_t)applicationCacheDefaultOriginQuota
1443     return [self _longLongValueForKey:WebKitApplicationCacheDefaultOriginQuota];
1446 - (void)setApplicationCacheDefaultOriginQuota:(int64_t)quota
1448     [self _setLongLongValue:quota forKey:WebKitApplicationCacheDefaultOriginQuota];
1451 #if !PLATFORM(IOS_FAMILY)
1452 - (PDFDisplayMode)PDFDisplayMode
1454     PDFDisplayMode value = static_cast<PDFDisplayMode>([self _integerValueForKey:WebKitPDFDisplayModePreferenceKey]);
1455     if (value != kPDFDisplaySinglePage && value != kPDFDisplaySinglePageContinuous && value != kPDFDisplayTwoUp && value != kPDFDisplayTwoUpContinuous) {
1456         // protect against new modes from future versions of OS X stored in defaults
1457         value = kPDFDisplaySinglePageContinuous;
1458     }
1459     return value;
1462 - (void)setPDFDisplayMode:(PDFDisplayMode)mode
1464     [self _setIntegerValue:mode forKey:WebKitPDFDisplayModePreferenceKey];
1466 #endif
1468 - (WebKitEditableLinkBehavior)editableLinkBehavior
1470     WebKitEditableLinkBehavior value = static_cast<WebKitEditableLinkBehavior> ([self _integerValueForKey:WebKitEditableLinkBehaviorPreferenceKey]);
1471     if (value != WebKitEditableLinkDefaultBehavior &&
1472         value != WebKitEditableLinkAlwaysLive &&
1473         value != WebKitEditableLinkNeverLive &&
1474         value != WebKitEditableLinkOnlyLiveWithShiftKey &&
1475         value != WebKitEditableLinkLiveWhenNotFocused) {
1476         // ensure that a valid result is returned
1477         value = WebKitEditableLinkDefaultBehavior;
1478     }
1480     return value;
1483 - (void)setEditableLinkBehavior:(WebKitEditableLinkBehavior)behavior
1485     [self _setIntegerValue:behavior forKey:WebKitEditableLinkBehaviorPreferenceKey];
1488 - (WebTextDirectionSubmenuInclusionBehavior)textDirectionSubmenuInclusionBehavior
1490     auto value = static_cast<WebTextDirectionSubmenuInclusionBehavior>([self _integerValueForKey:WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey]);
1491     if (value != WebTextDirectionSubmenuNeverIncluded &&
1492         value != WebTextDirectionSubmenuAutomaticallyIncluded &&
1493         value != WebTextDirectionSubmenuAlwaysIncluded) {
1494         // Ensure that a valid result is returned.
1495         value = WebTextDirectionSubmenuNeverIncluded;
1496     }
1497     return value;
1500 - (void)setTextDirectionSubmenuInclusionBehavior:(WebTextDirectionSubmenuInclusionBehavior)behavior
1502     [self _setIntegerValue:behavior forKey:WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey];
1505 - (BOOL)_useSiteSpecificSpoofing
1507     return [self _boolValueForKey:WebKitUseSiteSpecificSpoofingPreferenceKey];
1510 - (void)_setUseSiteSpecificSpoofing:(BOOL)newValue
1512     [self _setBoolValue:newValue forKey:WebKitUseSiteSpecificSpoofingPreferenceKey];
1515 - (BOOL)databasesEnabled
1517     return [self _boolValueForKey:WebKitDatabasesEnabledPreferenceKey];
1520 - (void)setDatabasesEnabled:(BOOL)databasesEnabled
1522     [self _setBoolValue:databasesEnabled forKey:WebKitDatabasesEnabledPreferenceKey];
1525 #if PLATFORM(IOS_FAMILY)
1526 - (BOOL)storageTrackerEnabled
1528     return [self _boolValueForKey:WebKitStorageTrackerEnabledPreferenceKey];
1531 - (void)setStorageTrackerEnabled:(BOOL)storageTrackerEnabled
1533     [self _setBoolValue:storageTrackerEnabled forKey:WebKitStorageTrackerEnabledPreferenceKey];
1535 #endif
1537 - (BOOL)localStorageEnabled
1539     return [self _boolValueForKey:WebKitLocalStorageEnabledPreferenceKey];
1542 - (void)setLocalStorageEnabled:(BOOL)localStorageEnabled
1544     [self _setBoolValue:localStorageEnabled forKey:WebKitLocalStorageEnabledPreferenceKey];
1547 + (WebPreferences *)_getInstanceForIdentifier:(NSString *)ident
1549     LOG(Encoding, "requesting for %@\n", ident);
1551     if (!ident)
1552         return standardPreferences().get();
1554     WebPreferences *instance = [webPreferencesInstances() objectForKey:[self _concatenateKeyWithIBCreatorID:ident]];
1556     return instance;
1559 + (void)_setInstance:(WebPreferences *)instance forIdentifier:(NSString *)ident
1561     if (!ident)
1562         return;
1564     auto& instances = webPreferencesInstances();
1565     if (!instances)
1566         instances = adoptNS([[NSMutableDictionary alloc] init]);
1567     [instances setObject:instance forKey:[self _concatenateKeyWithIBCreatorID:ident]];
1568     LOG(Encoding, "recording %p for %@\n", instance, [self _concatenateKeyWithIBCreatorID:ident]);
1571 + (void)_checkLastReferenceForIdentifier:(id)identifier
1573     // FIXME: This won't work at all under garbage collection because retainCount returns a constant.
1574     // We may need to change WebPreferences API so there's an explicit way to end the lifetime of one.
1575     WebPreferences *instance = [webPreferencesInstances() objectForKey:identifier];
1576     if ([instance retainCount] == 1)
1577         [webPreferencesInstances() removeObjectForKey:identifier];
1580 + (void)_removeReferenceForIdentifier:(NSString *)ident
1582     if (ident)
1583         [self performSelector:@selector(_checkLastReferenceForIdentifier:) withObject:[self _concatenateKeyWithIBCreatorID:ident] afterDelay:0.1];
1586 - (void)_startBatchingUpdates
1588     if (!_private->updateBatchCount)
1589         _private->updateAfterBatchType = { };
1591     _private->updateBatchCount++;
1594 - (void)_stopBatchingUpdates
1596     ASSERT(_private->updateBatchCount > 0);
1597     if (_private->updateBatchCount <= 0)
1598         NSLog(@"ERROR: Unbalanced _startBatchingUpdates/_stopBatchingUpdates.");
1600     _private->updateBatchCount--;
1601     if (!_private->updateBatchCount) {
1602         if (_private->updateAfterBatchType.contains(UpdateAfterBatchType::Internal)) {
1603             if (_private->updateAfterBatchType.contains(UpdateAfterBatchType::API))
1604                 [self _postPreferencesChangedNotification];
1605             else
1606                 [self _postPreferencesChangedAPINotification];
1607         }
1608     }
1611 - (void)_batchUpdatePreferencesInBlock:(void (^)(WebPreferences *))block
1613     [self _startBatchingUpdates];
1614     block(self);
1615     [self _stopBatchingUpdates];
1618 - (void)_resetForTesting
1620     _private->values = adoptNS([[NSMutableDictionary alloc] init]);
1621     [self _postPreferencesChangedNotification];
1624 - (void)_postPreferencesChangedNotification
1626 #if !PLATFORM(IOS_FAMILY)
1627     if (!pthread_main_np()) {
1628         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1629         return;
1630     }
1631 #endif
1633     if (_private->updateBatchCount) {
1634         _private->updateAfterBatchType.add({ UpdateAfterBatchType::API, UpdateAfterBatchType::Internal });
1635         return;
1636     }
1638     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedInternalNotification object:self userInfo:nil];
1639     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedNotification object:self userInfo:nil];
1642 - (void)_postPreferencesChangedAPINotification
1644     if (!pthread_main_np()) {
1645         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1646         return;
1647     }
1649     if (_private->updateBatchCount) {
1650         _private->updateAfterBatchType.add({ UpdateAfterBatchType::Internal });
1651         return;
1652     }
1654     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedNotification object:self userInfo:nil];
1657 + (CFStringEncoding)_systemCFStringEncoding
1659     return PAL::webDefaultCFStringEncoding();
1662 + (void)_setInitialDefaultTextEncodingToSystemEncoding
1664     [[NSUserDefaults standardUserDefaults] registerDefaults:
1665         @{ WebKitDefaultTextEncodingNamePreferenceKey: PAL::defaultTextEncodingNameForSystemLanguage() }];
1668 static RetainPtr<NSString>& classIBCreatorID()
1670     static NeverDestroyed<RetainPtr<NSString>> classIBCreatorID;
1671     return classIBCreatorID;
1674 + (void)_setIBCreatorID:(NSString *)string
1676     classIBCreatorID() = adoptNS([string copy]);
1679 - (BOOL)isDOMPasteAllowed
1681     return [self _boolValueForKey:WebKitDOMPasteAllowedPreferenceKey];
1684 - (void)setDOMPasteAllowed:(BOOL)DOMPasteAllowed
1686     [self _setBoolValue:DOMPasteAllowed forKey:WebKitDOMPasteAllowedPreferenceKey];
1689 - (NSString *)_localStorageDatabasePath
1691     return [[self _stringValueForKey:WebKitLocalStorageDatabasePathPreferenceKey] stringByStandardizingPath];
1694 - (void)_setLocalStorageDatabasePath:(NSString *)path
1696     [self _setStringValue:[path stringByStandardizingPath] forKey:WebKitLocalStorageDatabasePathPreferenceKey];
1699 - (NSString *)_ftpDirectoryTemplatePath
1701     return [[self _stringValueForKey:WebKitFTPDirectoryTemplatePath] stringByStandardizingPath];
1704 - (void)_setFTPDirectoryTemplatePath:(NSString *)path
1706     [self _setStringValue:[path stringByStandardizingPath] forKey:WebKitFTPDirectoryTemplatePath];
1709 - (BOOL)_forceFTPDirectoryListings
1711     return [self _boolValueForKey:WebKitForceFTPDirectoryListings];
1714 - (void)_setForceFTPDirectoryListings:(BOOL)force
1716     [self _setBoolValue:force forKey:WebKitForceFTPDirectoryListings];
1719 - (BOOL)acceleratedDrawingEnabled
1721     return [self _boolValueForKey:WebKitAcceleratedDrawingEnabledPreferenceKey];
1724 - (void)setAcceleratedDrawingEnabled:(BOOL)enabled
1726     [self _setBoolValue:enabled forKey:WebKitAcceleratedDrawingEnabledPreferenceKey];
1729 - (BOOL)displayListDrawingEnabled
1731     return [self _boolValueForKey:WebKitDisplayListDrawingEnabledPreferenceKey];
1734 - (void)setDisplayListDrawingEnabled:(BOOL)enabled
1736     [self _setBoolValue:enabled forKey:WebKitDisplayListDrawingEnabledPreferenceKey];
1739 - (BOOL)resourceLoadStatisticsEnabled
1741     return [self _boolValueForKey:WebKitResourceLoadStatisticsEnabledPreferenceKey];
1744 - (void)setResourceLoadStatisticsEnabled:(BOOL)enabled
1746     [self _setBoolValue:enabled forKey:WebKitResourceLoadStatisticsEnabledPreferenceKey];
1749 - (BOOL)largeImageAsyncDecodingEnabled
1751     return [self _boolValueForKey:WebKitLargeImageAsyncDecodingEnabledPreferenceKey];
1754 - (void)setLargeImageAsyncDecodingEnabled:(BOOL)enabled
1756     [self _setBoolValue:enabled forKey:WebKitLargeImageAsyncDecodingEnabledPreferenceKey];
1759 - (BOOL)animatedImageAsyncDecodingEnabled
1761     return [self _boolValueForKey:WebKitAnimatedImageAsyncDecodingEnabledPreferenceKey];
1764 - (void)setAnimatedImageAsyncDecodingEnabled:(BOOL)enabled
1766     [self _setBoolValue:enabled forKey:WebKitAnimatedImageAsyncDecodingEnabledPreferenceKey];
1769 - (BOOL)canvasUsesAcceleratedDrawing
1771     return [self _boolValueForKey:WebKitCanvasUsesAcceleratedDrawingPreferenceKey];
1774 - (void)setCanvasUsesAcceleratedDrawing:(BOOL)enabled
1776     [self _setBoolValue:enabled forKey:WebKitCanvasUsesAcceleratedDrawingPreferenceKey];
1779 - (BOOL)acceleratedCompositingEnabled
1781     return [self _boolValueForKey:WebKitAcceleratedCompositingEnabledPreferenceKey];
1784 - (void)setAcceleratedCompositingEnabled:(BOOL)enabled
1786     [self _setBoolValue:enabled forKey:WebKitAcceleratedCompositingEnabledPreferenceKey];
1789 - (BOOL)showDebugBorders
1791     return [self _boolValueForKey:WebKitShowDebugBordersPreferenceKey];
1794 - (void)setShowDebugBorders:(BOOL)enabled
1796     [self _setBoolValue:enabled forKey:WebKitShowDebugBordersPreferenceKey];
1799 - (BOOL)subpixelAntialiasedLayerTextEnabled
1801     return [self _boolValueForKey:WebKitSubpixelAntialiasedLayerTextEnabledPreferenceKey];
1804 - (void)setSubpixelAntialiasedLayerTextEnabled:(BOOL)enabled
1806     [self _setBoolValue:enabled forKey:WebKitSubpixelAntialiasedLayerTextEnabledPreferenceKey];
1809 - (BOOL)legacyLineLayoutVisualCoverageEnabled
1811     return [self _boolValueForKey:WebKitLegacyLineLayoutVisualCoverageEnabledPreferenceKey];
1814 - (void)setLegacyLineLayoutVisualCoverageEnabled:(BOOL)enabled
1816     [self _setBoolValue:enabled forKey:WebKitLegacyLineLayoutVisualCoverageEnabledPreferenceKey];
1819 - (BOOL)showRepaintCounter
1821     return [self _boolValueForKey:WebKitShowRepaintCounterPreferenceKey];
1824 - (void)setShowRepaintCounter:(BOOL)enabled
1826     [self _setBoolValue:enabled forKey:WebKitShowRepaintCounterPreferenceKey];
1829 - (BOOL)webAudioEnabled
1831     return [self _boolValueForKey:WebKitWebAudioEnabledPreferenceKey];
1834 - (void)setWebAudioEnabled:(BOOL)enabled
1836     [self _setBoolValue:enabled forKey:WebKitWebAudioEnabledPreferenceKey];
1839 - (BOOL)webGLEnabled
1841     return [self _boolValueForKey:WebKitWebGLEnabledPreferenceKey];
1844 - (void)setWebGLEnabled:(BOOL)enabled
1846     [self _setBoolValue:enabled forKey:WebKitWebGLEnabledPreferenceKey];
1849 - (BOOL)forceLowPowerGPUForWebGL
1851     return [self _boolValueForKey:WebKitForceWebGLUsesLowPowerPreferenceKey];
1854 - (void)setForceWebGLUsesLowPower:(BOOL)forceLowPower
1856     [self _setBoolValue:forceLowPower forKey:WebKitForceWebGLUsesLowPowerPreferenceKey];
1859 - (BOOL)isFrameFlatteningEnabled
1861     return [self _unsignedIntValueForKey:WebKitFrameFlatteningPreferenceKey] != WebKitFrameFlatteningDisabled;
1864 - (void)setFrameFlatteningEnabled:(BOOL)flattening
1866     WebKitFrameFlattening value = flattening ? WebKitFrameFlatteningFullyEnabled : WebKitFrameFlatteningDisabled;
1867     [self _setUnsignedIntValue:value forKey:WebKitFrameFlatteningPreferenceKey];
1870 - (WebKitFrameFlattening)frameFlattening
1872     return static_cast<WebKitFrameFlattening>([self _unsignedIntValueForKey:WebKitFrameFlatteningPreferenceKey]);
1875 - (void)setFrameFlattening:(WebKitFrameFlattening)flattening
1877     [self _setUnsignedIntValue:flattening forKey:WebKitFrameFlatteningPreferenceKey];
1880 - (BOOL)asyncFrameScrollingEnabled
1882     return [self _boolValueForKey:WebKitAsyncFrameScrollingEnabledPreferenceKey];
1885 - (void)setAsyncFrameScrollingEnabled:(BOOL)enabled
1887     [self _setBoolValue:enabled forKey:WebKitAsyncFrameScrollingEnabledPreferenceKey];
1890 - (BOOL)isSpatialNavigationEnabled
1892     return [self _boolValueForKey:WebKitSpatialNavigationEnabledPreferenceKey];
1895 - (void)setSpatialNavigationEnabled:(BOOL)flag
1897     [self _setBoolValue:flag forKey:WebKitSpatialNavigationEnabledPreferenceKey];
1900 - (BOOL)paginateDuringLayoutEnabled
1902     return [self _boolValueForKey:WebKitPaginateDuringLayoutEnabledPreferenceKey];
1905 - (void)setPaginateDuringLayoutEnabled:(BOOL)flag
1907     [self _setBoolValue:flag forKey:WebKitPaginateDuringLayoutEnabledPreferenceKey];
1910 - (BOOL)hyperlinkAuditingEnabled
1912     return [self _boolValueForKey:WebKitHyperlinkAuditingEnabledPreferenceKey];
1915 - (void)setHyperlinkAuditingEnabled:(BOOL)flag
1917     [self _setBoolValue:flag forKey:WebKitHyperlinkAuditingEnabledPreferenceKey];
1920 - (BOOL)usePreHTML5ParserQuirks
1922     return [self _boolValueForKey:WebKitUsePreHTML5ParserQuirksKey];
1925 - (void)setUsePreHTML5ParserQuirks:(BOOL)flag
1927     [self _setBoolValue:flag forKey:WebKitUsePreHTML5ParserQuirksKey];
1930 - (void)didRemoveFromWebView
1932     ASSERT(_private->numWebViews);
1933     if (--_private->numWebViews == 0)
1934         [[NSNotificationCenter defaultCenter]
1935             postNotificationName:WebPreferencesRemovedNotification
1936                           object:self
1937                         userInfo:nil];
1940 - (void)willAddToWebView
1942     ++_private->numWebViews;
1945 - (void)setFullScreenEnabled:(BOOL)flag
1947     [self _setBoolValue:flag forKey:WebKitFullScreenEnabledPreferenceKey];
1950 - (BOOL)fullScreenEnabled
1952     return [self _boolValueForKey:WebKitFullScreenEnabledPreferenceKey];
1955 - (void)setAsynchronousSpellCheckingEnabled:(BOOL)flag
1957     [self _setBoolValue:flag forKey:WebKitAsynchronousSpellCheckingEnabledPreferenceKey];
1960 - (BOOL)asynchronousSpellCheckingEnabled
1962     return [self _boolValueForKey:WebKitAsynchronousSpellCheckingEnabledPreferenceKey];
1965 + (void)setWebKitLinkTimeVersion:(int)version
1967     setWebKitLinkTimeVersion(version);
1970 - (void)setLoadsSiteIconsIgnoringImageLoadingPreference: (BOOL)flag
1972     [self _setBoolValue: flag forKey: WebKitLoadSiteIconsKey];
1975 - (BOOL)loadsSiteIconsIgnoringImageLoadingPreference
1977     return [self _boolValueForKey: WebKitLoadSiteIconsKey];
1980 - (void)setAVFoundationEnabled:(BOOL)flag
1982     [self _setBoolValue:flag forKey:WebKitAVFoundationEnabledKey];
1985 - (BOOL)isAVFoundationEnabled
1987     return [self _boolValueForKey:WebKitAVFoundationEnabledKey];
1990 - (void)setAVFoundationNSURLSessionEnabled:(BOOL)flag
1994 - (BOOL)isAVFoundationNSURLSessionEnabled
1996     return YES;
1999 - (BOOL)isInheritURIQueryComponentEnabled
2001     return [self _boolValueForKey: WebKitEnableInheritURIQueryComponentPreferenceKey];
2004 - (void)setEnableInheritURIQueryComponent:(BOOL)flag
2006     [self _setBoolValue:flag forKey: WebKitEnableInheritURIQueryComponentPreferenceKey];
2009 #if PLATFORM(IOS_FAMILY)
2010 - (BOOL)mediaPlaybackAllowsAirPlay
2012     return [self _boolValueForKey:WebKitAllowsAirPlayForMediaPlaybackPreferenceKey];
2015 - (void)setMediaPlaybackAllowsAirPlay:(BOOL)flag
2017     [self _setBoolValue:flag forKey:WebKitAllowsAirPlayForMediaPlaybackPreferenceKey];
2020 - (unsigned)audioSessionCategoryOverride
2022     return [self _unsignedIntValueForKey:WebKitAudioSessionCategoryOverride];
2025 - (void)setAudioSessionCategoryOverride:(unsigned)override
2027     if (override > static_cast<unsigned>(AudioSession::CategoryType::AudioProcessing)) {
2028         // Clients are passing us OSTypes values from AudioToolbox/AudioSession.h,
2029         // which need to be translated into AudioSession::CategoryType:
2030         switch (override) {
2031         case WebKitAudioSessionCategoryAmbientSound:
2032             override = static_cast<unsigned>(AudioSession::CategoryType::AmbientSound);
2033             break;
2034         case WebKitAudioSessionCategorySoloAmbientSound:
2035             override = static_cast<unsigned>(AudioSession::CategoryType::SoloAmbientSound);
2036             break;
2037         case WebKitAudioSessionCategoryMediaPlayback:
2038             override = static_cast<unsigned>(AudioSession::CategoryType::MediaPlayback);
2039             break;
2040         case WebKitAudioSessionCategoryRecordAudio:
2041             override = static_cast<unsigned>(AudioSession::CategoryType::RecordAudio);
2042             break;
2043         case WebKitAudioSessionCategoryPlayAndRecord:
2044             override = static_cast<unsigned>(AudioSession::CategoryType::PlayAndRecord);
2045             break;
2046         case WebKitAudioSessionCategoryAudioProcessing:
2047             override = static_cast<unsigned>(AudioSession::CategoryType::AudioProcessing);
2048             break;
2049         default:
2050             override = static_cast<unsigned>(AudioSession::CategoryType::None);
2051             break;
2052         }
2053     }
2055     [self _setUnsignedIntValue:override forKey:WebKitAudioSessionCategoryOverride];
2058 - (BOOL)networkDataUsageTrackingEnabled
2060     return [self _boolValueForKey:WebKitNetworkDataUsageTrackingEnabledPreferenceKey];
2063 - (void)setNetworkDataUsageTrackingEnabled:(BOOL)trackingEnabled
2065     [self _setBoolValue:trackingEnabled forKey:WebKitNetworkDataUsageTrackingEnabledPreferenceKey];
2068 - (NSString *)networkInterfaceName
2070     return [self _stringValueForKey:WebKitNetworkInterfaceNamePreferenceKey];
2073 - (void)setNetworkInterfaceName:(NSString *)name
2075     [self _setStringValue:name forKey:WebKitNetworkInterfaceNamePreferenceKey];
2077 #endif // PLATFORM(IOS_FAMILY)
2079 // Deprecated. Use -videoPlaybackRequiresUserGesture and -audioPlaybackRequiresUserGesture instead.
2080 - (BOOL)mediaPlaybackRequiresUserGesture
2082     return [self _boolValueForKey:WebKitRequiresUserGestureForMediaPlaybackPreferenceKey];
2085 // Deprecated. Use -setVideoPlaybackRequiresUserGesture and -setAudioPlaybackRequiresUserGesture instead.
2086 - (void)setMediaPlaybackRequiresUserGesture:(BOOL)flag
2088     [self _setBoolValue:flag forKey:WebKitRequiresUserGestureForMediaPlaybackPreferenceKey];
2091 - (BOOL)videoPlaybackRequiresUserGesture
2093     return [self _boolValueForKey:WebKitRequiresUserGestureForVideoPlaybackPreferenceKey];
2096 - (void)setVideoPlaybackRequiresUserGesture:(BOOL)flag
2098     [self _setBoolValue:flag forKey:WebKitRequiresUserGestureForVideoPlaybackPreferenceKey];
2101 - (BOOL)audioPlaybackRequiresUserGesture
2103     return [self _boolValueForKey:WebKitRequiresUserGestureForAudioPlaybackPreferenceKey];
2106 - (void)setAudioPlaybackRequiresUserGesture:(BOOL)flag
2108     [self _setBoolValue:flag forKey:WebKitRequiresUserGestureForAudioPlaybackPreferenceKey];
2111 - (BOOL)overrideUserGestureRequirementForMainContent
2113     return [self _boolValueForKey:WebKitMainContentUserGestureOverrideEnabledPreferenceKey];
2116 - (void)setOverrideUserGestureRequirementForMainContent:(BOOL)flag
2118     [self _setBoolValue:flag forKey:WebKitMainContentUserGestureOverrideEnabledPreferenceKey];
2121 - (BOOL)mediaPlaybackAllowsInline
2123     return [self _boolValueForKey:WebKitAllowsInlineMediaPlaybackPreferenceKey];
2126 - (void)setMediaPlaybackAllowsInline:(BOOL)flag
2128     [self _setBoolValue:flag forKey:WebKitAllowsInlineMediaPlaybackPreferenceKey];
2131 - (BOOL)inlineMediaPlaybackRequiresPlaysInlineAttribute
2133     return [self _boolValueForKey:WebKitInlineMediaPlaybackRequiresPlaysInlineAttributeKey];
2136 - (void)setInlineMediaPlaybackRequiresPlaysInlineAttribute:(BOOL)flag
2138     [self _setBoolValue:flag forKey:WebKitInlineMediaPlaybackRequiresPlaysInlineAttributeKey];
2141 - (BOOL)invisibleAutoplayNotPermitted
2143     return [self _boolValueForKey:WebKitInvisibleAutoplayNotPermittedKey];
2146 - (void)setInvisibleAutoplayNotPermitted:(BOOL)flag
2148     [self _setBoolValue:flag forKey:WebKitInvisibleAutoplayNotPermittedKey];
2151 - (BOOL)mediaControlsScaleWithPageZoom
2153     return [self _boolValueForKey:WebKitMediaControlsScaleWithPageZoomPreferenceKey];
2156 - (void)setMediaControlsScaleWithPageZoom:(BOOL)flag
2158     [self _setBoolValue:flag forKey:WebKitMediaControlsScaleWithPageZoomPreferenceKey];
2161 - (BOOL)allowsAlternateFullscreen
2163     return [self allowsPictureInPictureMediaPlayback];
2166 - (void)setAllowsAlternateFullscreen:(BOOL)flag
2168     [self setAllowsPictureInPictureMediaPlayback:flag];
2171 - (BOOL)allowsPictureInPictureMediaPlayback
2173     return [self _boolValueForKey:WebKitAllowsPictureInPictureMediaPlaybackPreferenceKey];
2176 - (void)setAllowsPictureInPictureMediaPlayback:(BOOL)flag
2178     [self _setBoolValue:flag forKey:WebKitAllowsPictureInPictureMediaPlaybackPreferenceKey];
2181 - (BOOL)mockScrollbarsEnabled
2183     return [self _boolValueForKey:WebKitMockScrollbarsEnabledPreferenceKey];
2186 - (void)setMockScrollbarsEnabled:(BOOL)flag
2188     [self _setBoolValue:flag forKey:WebKitMockScrollbarsEnabledPreferenceKey];
2191 - (NSString *)pictographFontFamily
2193     return [self _stringValueForKey: WebKitPictographFontPreferenceKey];
2196 - (void)setPictographFontFamily:(NSString *)family
2198     [self _setStringValue: family forKey: WebKitPictographFontPreferenceKey];
2201 - (BOOL)pageCacheSupportsPlugins
2203     return [self _boolValueForKey:WebKitPageCacheSupportsPluginsPreferenceKey];
2206 - (void)setPageCacheSupportsPlugins:(BOOL)flag
2208     [self _setBoolValue:flag forKey:WebKitPageCacheSupportsPluginsPreferenceKey];
2212 #if PLATFORM(IOS_FAMILY)
2213 - (void)_invalidateCachedPreferences
2215     dispatch_barrier_sync(_private->readWriteQueue.get(), ^{
2216         if (_private->values)
2217             _private->values = adoptNS([[NSMutableDictionary alloc] init]);
2218     });
2220     [self _updatePrivateBrowsingStateTo:[self privateBrowsingEnabled]];
2222     // Tell any live WebViews to refresh their preferences
2223     [self _postPreferencesChangedNotification];
2226 - (void)_synchronizeWebStoragePolicyWithCookiePolicy
2228     // FIXME: This should be done in clients, WebKit shouldn't be making such policy decisions.
2230     NSHTTPCookieAcceptPolicy cookieAcceptPolicy = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookieAcceptPolicy];
2231     WebStorageBlockingPolicy storageBlockingPolicy;
2232     switch (static_cast<unsigned>(cookieAcceptPolicy)) {
2233     case NSHTTPCookieAcceptPolicyAlways:
2234         storageBlockingPolicy = WebAllowAllStorage;
2235         break;
2236     case NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain:
2237     case NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain:
2238         storageBlockingPolicy = WebBlockThirdPartyStorage;
2239         break;
2240     case NSHTTPCookieAcceptPolicyNever:
2241         storageBlockingPolicy = WebBlockAllStorage;
2242         break;
2243     default:
2244         ASSERT_NOT_REACHED();
2245         storageBlockingPolicy = WebBlockAllStorage;
2246         break;
2247     }
2249     [self setStorageBlockingPolicy:storageBlockingPolicy];
2251 #endif
2253 - (void)setBackspaceKeyNavigationEnabled:(BOOL)flag
2255     [self _setBoolValue:flag forKey:WebKitBackspaceKeyNavigationEnabledKey];
2258 - (BOOL)backspaceKeyNavigationEnabled
2260     return [self _boolValueForKey:WebKitBackspaceKeyNavigationEnabledKey];
2263 - (void)setWantsBalancedSetDefersLoadingBehavior:(BOOL)flag
2265     [self _setBoolValue:flag forKey:WebKitWantsBalancedSetDefersLoadingBehaviorKey];
2268 - (BOOL)wantsBalancedSetDefersLoadingBehavior
2270     return [self _boolValueForKey:WebKitWantsBalancedSetDefersLoadingBehaviorKey];
2273 - (void)setShouldDisplaySubtitles:(BOOL)flag
2275     [self _setBoolValue:flag forKey:WebKitShouldDisplaySubtitlesPreferenceKey];
2278 - (BOOL)shouldDisplaySubtitles
2280     return [self _boolValueForKey:WebKitShouldDisplaySubtitlesPreferenceKey];
2283 - (void)setShouldDisplayCaptions:(BOOL)flag
2285     [self _setBoolValue:flag forKey:WebKitShouldDisplayCaptionsPreferenceKey];
2288 - (BOOL)shouldDisplayCaptions
2290     return [self _boolValueForKey:WebKitShouldDisplayCaptionsPreferenceKey];
2293 - (void)setShouldDisplayTextDescriptions:(BOOL)flag
2295     [self _setBoolValue:flag forKey:WebKitShouldDisplayTextDescriptionsPreferenceKey];
2298 - (BOOL)shouldDisplayTextDescriptions
2300     return [self _boolValueForKey:WebKitShouldDisplayTextDescriptionsPreferenceKey];
2303 - (void)setNotificationsEnabled:(BOOL)flag
2305     [self _setBoolValue:flag forKey:WebKitNotificationsEnabledKey];
2308 - (BOOL)notificationsEnabled
2310     return [self _boolValueForKey:WebKitNotificationsEnabledKey];
2313 - (void)setShouldRespectImageOrientation:(BOOL)flag
2315     [self _setBoolValue:flag forKey:WebKitShouldRespectImageOrientationKey];
2318 - (BOOL)shouldRespectImageOrientation
2320     return [self _boolValueForKey:WebKitShouldRespectImageOrientationKey];
2323 - (void)setIncrementalRenderingSuppressionTimeoutInSeconds:(NSTimeInterval)timeout
2325     [self _setFloatValue:timeout forKey:WebKitIncrementalRenderingSuppressionTimeoutInSecondsKey];
2328 - (NSTimeInterval)incrementalRenderingSuppressionTimeoutInSeconds
2330     return [self _floatValueForKey:WebKitIncrementalRenderingSuppressionTimeoutInSecondsKey];
2333 - (BOOL)diagnosticLoggingEnabled
2335     return [self _boolValueForKey:WebKitDiagnosticLoggingEnabledKey];
2338 - (void)setDiagnosticLoggingEnabled:(BOOL)enabled
2340     [self _setBoolValue:enabled forKey:WebKitDiagnosticLoggingEnabledKey];
2343 - (void)setStorageBlockingPolicy:(WebStorageBlockingPolicy)storageBlockingPolicy
2345 #if PLATFORM(IOS_FAMILY)
2346     // We don't want to write the setting out, so we just reset the default instead of storing the new setting.
2347     // FIXME: This code removes any defaults previously registered by client process, which is not appropriate for this method to do.
2348     [[NSUserDefaults standardUserDefaults] registerDefaults:@{ WebKitStorageBlockingPolicyKey: @(storageBlockingPolicy) }];
2349 #else
2350     [self _setIntegerValue:storageBlockingPolicy forKey:WebKitStorageBlockingPolicyKey];
2351 #endif
2354 - (WebStorageBlockingPolicy)storageBlockingPolicy
2356     return static_cast<WebStorageBlockingPolicy>([self _integerValueForKey:WebKitStorageBlockingPolicyKey]);
2359 - (BOOL)plugInSnapshottingEnabled
2361     return NO;
2364 - (void)setPlugInSnapshottingEnabled:(BOOL)enabled
2368 - (BOOL)hiddenPageDOMTimerThrottlingEnabled
2370     return [self _boolValueForKey:WebKitHiddenPageDOMTimerThrottlingEnabledPreferenceKey];
2373 - (void)setHiddenPageDOMTimerThrottlingEnabled:(BOOL)enabled
2375     [self _setBoolValue:enabled forKey:WebKitHiddenPageDOMTimerThrottlingEnabledPreferenceKey];
2378 - (BOOL)hiddenPageCSSAnimationSuspensionEnabled
2380     return [self _boolValueForKey:WebKitHiddenPageCSSAnimationSuspensionEnabledPreferenceKey];
2383 - (void)setHiddenPageCSSAnimationSuspensionEnabled:(BOOL)enabled
2385     [self _setBoolValue:enabled forKey:WebKitHiddenPageCSSAnimationSuspensionEnabledPreferenceKey];
2388 - (BOOL)lowPowerVideoAudioBufferSizeEnabled
2390     return [self _boolValueForKey:WebKitLowPowerVideoAudioBufferSizeEnabledPreferenceKey];
2393 - (void)setLowPowerVideoAudioBufferSizeEnabled:(BOOL)enabled
2395     [self _setBoolValue:enabled forKey:WebKitLowPowerVideoAudioBufferSizeEnabledPreferenceKey];
2398 - (BOOL)useLegacyTextAlignPositionedElementBehavior
2400     return [self _boolValueForKey:WebKitUseLegacyTextAlignPositionedElementBehaviorPreferenceKey];
2403 - (void)setUseLegacyTextAlignPositionedElementBehavior:(BOOL)enabled
2405     [self _setBoolValue:enabled forKey:WebKitUseLegacyTextAlignPositionedElementBehaviorPreferenceKey];
2408 - (BOOL)mediaSourceEnabled
2410     return [self _boolValueForKey:WebKitMediaSourceEnabledPreferenceKey];
2413 - (void)setMediaSourceEnabled:(BOOL)enabled
2415     [self _setBoolValue:enabled forKey:WebKitMediaSourceEnabledPreferenceKey];
2418 - (BOOL)sourceBufferChangeTypeEnabled
2420     return [self _boolValueForKey:WebKitSourceBufferChangeTypeEnabledPreferenceKey];
2423 - (void)setSourceBufferChangeTypeEnabled:(BOOL)enabled
2425     [self _setBoolValue:enabled forKey:WebKitSourceBufferChangeTypeEnabledPreferenceKey];
2428 - (BOOL)imageControlsEnabled
2430     // Image controls are no longer supported.
2431     return NO;
2434 - (void)setImageControlsEnabled:(BOOL)enabled
2436     // Image controls are no longer supported.
2437     UNUSED_PARAM(enabled);
2440 - (BOOL)serviceControlsEnabled
2442     return [self _boolValueForKey:WebKitServiceControlsEnabledPreferenceKey];
2445 - (void)setServiceControlsEnabled:(BOOL)enabled
2447     [self _setBoolValue:enabled forKey:WebKitServiceControlsEnabledPreferenceKey];
2450 - (BOOL)gamepadsEnabled
2452     return [self _boolValueForKey:WebKitGamepadsEnabledPreferenceKey];
2455 - (void)setGamepadsEnabled:(BOOL)flag
2457     [self _setBoolValue:flag forKey:WebKitGamepadsEnabledPreferenceKey];
2460 - (BOOL)shouldConvertPositionStyleOnCopy
2462     return [self _boolValueForKey:WebKitShouldConvertPositionStyleOnCopyPreferenceKey];
2465 - (void)setShouldConvertPositionStyleOnCopy:(BOOL)enabled
2467     [self _setBoolValue:enabled forKey:WebKitShouldConvertPositionStyleOnCopyPreferenceKey];
2470 - (NSString *)mediaKeysStorageDirectory
2472     return [[self _stringValueForKey:WebKitMediaKeysStorageDirectoryKey] stringByStandardizingPath];
2475 - (void)setMediaKeysStorageDirectory:(NSString *)directory
2477     [self _setStringValue:directory forKey:WebKitMediaKeysStorageDirectoryKey];
2480 - (BOOL)mediaDevicesEnabled
2482     return [self _boolValueForKey:WebKitMediaDevicesEnabledPreferenceKey];
2485 - (void)setMediaDevicesEnabled:(BOOL)flag
2487     [self _setBoolValue:flag forKey:WebKitMediaDevicesEnabledPreferenceKey];
2490 - (BOOL)mediaStreamEnabled
2492     return [self _boolValueForKey:WebKitMediaStreamEnabledPreferenceKey];
2495 - (void)setMediaStreamEnabled:(BOOL)flag
2497     [self _setBoolValue:flag forKey:WebKitMediaStreamEnabledPreferenceKey];
2500 - (BOOL)peerConnectionEnabled
2502     return [self _boolValueForKey:WebKitPeerConnectionEnabledPreferenceKey];
2505 - (void)setPeerConnectionEnabled:(BOOL)flag
2507     [self _setBoolValue:flag forKey:WebKitPeerConnectionEnabledPreferenceKey];
2510 - (BOOL)linkPreloadEnabled
2512     return [self _boolValueForKey:WebKitLinkPreloadEnabledPreferenceKey];
2515 - (void)setLinkPreloadEnabled:(BOOL)flag
2517     [self _setBoolValue:flag forKey:WebKitLinkPreloadEnabledPreferenceKey];
2520 - (BOOL)mediaPreloadingEnabled
2522     return [self _boolValueForKey:WebKitMediaPreloadingEnabledPreferenceKey];
2525 - (void)setMediaPreloadingEnabled:(BOOL)flag
2527     [self _setBoolValue:flag forKey:WebKitMediaPreloadingEnabledPreferenceKey];
2530 - (void)setMetaRefreshEnabled:(BOOL)enabled
2532     [self setHTTPEquivEnabled:enabled];
2535 - (BOOL)metaRefreshEnabled
2537     return [self httpEquivEnabled];
2540 - (void)setHTTPEquivEnabled:(BOOL)enabled
2542     [self _setBoolValue:enabled forKey:WebKitHTTPEquivEnabledPreferenceKey];
2545 - (BOOL)httpEquivEnabled
2547     return [self _boolValueForKey:WebKitHTTPEquivEnabledPreferenceKey];
2550 - (BOOL)javaScriptMarkupEnabled
2552     return [self _boolValueForKey:WebKitJavaScriptMarkupEnabledPreferenceKey];
2555 - (void)setJavaScriptMarkupEnabled:(BOOL)flag
2557     [self _setBoolValue:flag forKey:WebKitJavaScriptMarkupEnabledPreferenceKey];
2560 - (BOOL)mediaDataLoadsAutomatically
2562     return [self _boolValueForKey:WebKitMediaDataLoadsAutomaticallyPreferenceKey];
2565 - (void)setMediaDataLoadsAutomatically:(BOOL)flag
2567     [self _setBoolValue:flag forKey:WebKitMediaDataLoadsAutomaticallyPreferenceKey];
2570 - (BOOL)attachmentElementEnabled
2572     return [self _boolValueForKey:WebKitAttachmentElementEnabledPreferenceKey];
2575 - (void)setAttachmentElementEnabled:(BOOL)flag
2577     [self _setBoolValue:flag forKey:WebKitAttachmentElementEnabledPreferenceKey];
2580 - (BOOL)allowsInlineMediaPlaybackAfterFullscreen
2582     return [self _boolValueForKey:WebKitAllowsInlineMediaPlaybackAfterFullscreenPreferenceKey];
2585 - (void)setAllowsInlineMediaPlaybackAfterFullscreen:(BOOL)flag
2587     [self _setBoolValue:flag forKey:WebKitAllowsInlineMediaPlaybackAfterFullscreenPreferenceKey];
2590 - (BOOL)mockCaptureDevicesEnabled
2592     return [self _boolValueForKey:WebKitMockCaptureDevicesEnabledPreferenceKey];
2595 - (void)setMockCaptureDevicesEnabled:(BOOL)flag
2597     [self _setBoolValue:flag forKey:WebKitMockCaptureDevicesEnabledPreferenceKey];
2600 - (BOOL)mockCaptureDevicesPromptEnabled
2602     return [self _boolValueForKey:WebKitMockCaptureDevicesPromptEnabledPreferenceKey];
2605 - (void)setMockCaptureDevicesPromptEnabled:(BOOL)flag
2607     [self _setBoolValue:flag forKey:WebKitMockCaptureDevicesPromptEnabledPreferenceKey];
2610 - (BOOL)enumeratingAllNetworkInterfacesEnabled
2612     return [self _boolValueForKey:WebKitEnumeratingAllNetworkInterfacesEnabledPreferenceKey];
2615 - (void)setEnumeratingAllNetworkInterfacesEnabled:(BOOL)flag
2617     [self _setBoolValue:flag forKey:WebKitEnumeratingAllNetworkInterfacesEnabledPreferenceKey];
2620 - (BOOL)iceCandidateFilteringEnabled
2622     return [self _boolValueForKey:WebKitICECandidateFilteringEnabledPreferenceKey];
2625 - (void)setIceCandidateFilteringEnabled:(BOOL)flag
2627     [self _setBoolValue:flag forKey:WebKitICECandidateFilteringEnabledPreferenceKey];
2630 - (BOOL)mediaCaptureRequiresSecureConnection
2632     return [self _boolValueForKey:WebKitMediaCaptureRequiresSecureConnectionPreferenceKey];
2635 - (void)setMediaCaptureRequiresSecureConnection:(BOOL)flag
2637     [self _setBoolValue:flag forKey:WebKitMediaCaptureRequiresSecureConnectionPreferenceKey];
2640 - (BOOL)dataTransferItemsEnabled
2642     return [self _boolValueForKey:WebKitDataTransferItemsEnabledPreferenceKey];
2645 - (void)setDataTransferItemsEnabled:(BOOL)flag
2647     [self _setBoolValue:flag forKey:WebKitDataTransferItemsEnabledPreferenceKey];
2650 - (BOOL)customPasteboardDataEnabled
2652     return [self _boolValueForKey:WebKitCustomPasteboardDataEnabledPreferenceKey];
2655 - (void)setCustomPasteboardDataEnabled:(BOOL)flag
2657     [self _setBoolValue:flag forKey:WebKitCustomPasteboardDataEnabledPreferenceKey];
2660 - (BOOL)cacheAPIEnabled
2662     return [self _boolValueForKey:WebKitCacheAPIEnabledPreferenceKey];
2665 - (void)setCacheAPIEnabled:(BOOL)flag
2667     [self _setBoolValue:flag forKey:WebKitCacheAPIEnabledPreferenceKey];
2670 - (BOOL)downloadAttributeEnabled
2672     return [self _boolValueForKey:WebKitDownloadAttributeEnabledPreferenceKey];
2675 - (void)setDownloadAttributeEnabled:(BOOL)flag
2677     [self _setBoolValue:flag forKey:WebKitDownloadAttributeEnabledPreferenceKey];
2680 - (void)setDirectoryUploadEnabled:(BOOL)flag
2682     [self _setBoolValue:flag forKey:WebKitDirectoryUploadEnabledPreferenceKey];
2685 - (BOOL)directoryUploadEnabled
2687     return [self _boolValueForKey:WebKitDirectoryUploadEnabledPreferenceKey];
2690 - (BOOL)CSSOMViewScrollingAPIEnabled
2692     return [self _boolValueForKey:WebKitCSSOMViewScrollingAPIEnabledPreferenceKey];
2695 - (void)setCSSOMViewScrollingAPIEnabled:(BOOL)flag
2697     [self _setBoolValue:flag forKey:WebKitCSSOMViewScrollingAPIEnabledPreferenceKey];
2700 - (BOOL)menuItemElementEnabled
2702     return [self _boolValueForKey:WebKitMenuItemElementEnabledPreferenceKey];
2705 - (void)setMenuItemElementEnabled:(BOOL)flag
2707     [self _setBoolValue:flag forKey:WebKitMenuItemElementEnabledPreferenceKey];
2710 - (BOOL)mediaUserGestureInheritsFromDocument
2712     return [self _boolValueForKey:WebKitMediaUserGestureInheritsFromDocument];
2715 - (void)setMediaUserGestureInheritsFromDocument:(BOOL)flag
2717     [self _setBoolValue:flag forKey:WebKitMediaUserGestureInheritsFromDocument];
2720 #if PLATFORM(IOS_FAMILY)
2721 - (BOOL)quickLookDocumentSavingEnabled
2723     return [self _boolValueForKey:WebKitQuickLookDocumentSavingPreferenceKey];
2726 - (void)setQuickLookDocumentSavingEnabled:(BOOL)flag
2728     [self _setBoolValue:flag forKey:WebKitQuickLookDocumentSavingPreferenceKey];
2730 #endif
2732 - (NSString *)mediaContentTypesRequiringHardwareSupport
2734     return [self _stringValueForKey:WebKitMediaContentTypesRequiringHardwareSupportPreferenceKey];
2737 - (void)setMediaContentTypesRequiringHardwareSupport:(NSString *)value
2739     [self _setStringValue:value forKey:WebKitMediaContentTypesRequiringHardwareSupportPreferenceKey];
2742 - (BOOL)legacyEncryptedMediaAPIEnabled
2744     return [self _boolValueForKey:WebKitLegacyEncryptedMediaAPIEnabledKey];
2747 - (void)setLegacyEncryptedMediaAPIEnabled:(BOOL)flag
2749     [self _setBoolValue:flag forKey:WebKitLegacyEncryptedMediaAPIEnabledKey];
2752 - (BOOL)encryptedMediaAPIEnabled
2754     return [self _boolValueForKey:WebKitEncryptedMediaAPIEnabledKey];
2757 - (void)setEncryptedMediaAPIEnabled:(BOOL)flag
2759     [self _setBoolValue:flag forKey:WebKitEncryptedMediaAPIEnabledKey];
2762 - (BOOL)pictureInPictureAPIEnabled
2764     return [self _boolValueForKey:WebKitPictureInPictureAPIEnabledKey];
2767 - (void)setPictureInPictureAPIEnabled:(BOOL)flag
2769     [self _setBoolValue:flag forKey:WebKitPictureInPictureAPIEnabledKey];
2772 - (BOOL)constantPropertiesEnabled
2774     return [self _boolValueForKey:WebKitConstantPropertiesEnabledPreferenceKey];
2777 - (void)setConstantPropertiesEnabled:(BOOL)flag
2779     [self _setBoolValue:flag forKey:WebKitConstantPropertiesEnabledPreferenceKey];
2782 - (BOOL)colorFilterEnabled
2784     return [self _boolValueForKey:WebKitColorFilterEnabledPreferenceKey];
2787 - (void)setColorFilterEnabled:(BOOL)flag
2789     [self _setBoolValue:flag forKey:WebKitColorFilterEnabledPreferenceKey];
2792 - (BOOL)punchOutWhiteBackgroundsInDarkMode
2794     return [self _boolValueForKey:WebKitPunchOutWhiteBackgroundsInDarkModePreferenceKey];
2797 - (void)setPunchOutWhiteBackgroundsInDarkMode:(BOOL)flag
2799     [self _setBoolValue:flag forKey:WebKitPunchOutWhiteBackgroundsInDarkModePreferenceKey];
2802 - (BOOL)allowMediaContentTypesRequiringHardwareSupportAsFallback
2804     return [self _boolValueForKey:WebKitAllowMediaContentTypesRequiringHardwareSupportAsFallbackKey];
2807 - (void)setAllowMediaContentTypesRequiringHardwareSupportAsFallback:(BOOL)flag
2809     [self _setBoolValue:flag forKey:WebKitAllowMediaContentTypesRequiringHardwareSupportAsFallbackKey];
2812 - (BOOL)inspectorAdditionsEnabled
2814     return [self _boolValueForKey:WebKitInspectorAdditionsEnabledPreferenceKey];
2817 - (void)setInspectorAdditionsEnabled:(BOOL)flag
2819     [self _setBoolValue:flag forKey:WebKitInspectorAdditionsEnabledPreferenceKey];
2822 - (BOOL)mediaCapabilitiesEnabled
2824     return [self _boolValueForKey:WebKitMediaCapabilitiesEnabledPreferenceKey];
2827 - (void)setMediaCapabilitiesEnabled:(BOOL)flag
2829     [self _setBoolValue:flag forKey:WebKitMediaCapabilitiesEnabledPreferenceKey];
2832 - (BOOL)cssLogicalEnabled
2834     return [self _boolValueForKey:WebKitCSSLogicalEnabledPreferenceKey];
2837 - (void)setCSSLogicalEnabled:(BOOL)flag
2839     [self _setBoolValue:flag forKey:WebKitCSSLogicalEnabledPreferenceKey];
2842 - (BOOL)lineHeightUnitsEnabled
2844     return [self _boolValueForKey:WebKitLineHeightUnitsEnabledPreferenceKey];
2847 - (void)setLineHeightUnitsEnabled:(BOOL)flag
2849     [self _setBoolValue:flag forKey:WebKitLineHeightUnitsEnabledPreferenceKey];
2852 - (BOOL)layoutFormattingContextIntegrationEnabled
2854     return [self _boolValueForKey:WebKitLayoutFormattingContextIntegrationEnabledPreferenceKey];
2857 - (void)setLayoutFormattingContextIntegrationEnabled:(BOOL)flag
2859     [self _setBoolValue:flag forKey:WebKitLayoutFormattingContextIntegrationEnabledPreferenceKey];
2862 - (BOOL)isInAppBrowserPrivacyEnabled
2864     return [self _boolValueForKey:WebKitDebugInAppBrowserPrivacyEnabledPreferenceKey];
2867 - (void)setInAppBrowserPrivacyEnabled:(BOOL)flag
2869     [self _setBoolValue:flag forKey:WebKitDebugInAppBrowserPrivacyEnabledPreferenceKey];
2872 - (BOOL)webSQLEnabled
2874     return [self _boolValueForKey:WebKitWebSQLEnabledPreferenceKey];
2877 - (void)setWebSQLEnabled:(BOOL)webSQLEnabled
2879     [self _setBoolValue:webSQLEnabled forKey:WebKitWebSQLEnabledPreferenceKey];
2882 @end
2884 @implementation WebPreferences (WebInternal)
2886 + (NSString *)_IBCreatorID
2888     return classIBCreatorID().get();
2891 + (NSString *)_concatenateKeyWithIBCreatorID:(NSString *)key
2893     NSString *IBCreatorID = [WebPreferences _IBCreatorID];
2894     if (!IBCreatorID)
2895         return key;
2896     return [IBCreatorID stringByAppendingString:key];
2899 @end
2901 @implementation WebPreferences (WebPrivateFeatures)
2903 - (BOOL)_isEnabledForFeature:(WebFeature *)feature
2905     return [self _boolValueForKey:feature.preferenceKey];
2908 - (void)_setEnabled:(BOOL)value forFeature:(WebFeature *)feature
2910     [self _setBoolValue:value forKey:feature.preferenceKey];
2913 @end
2915 @implementation WebPreferences (WebPrivateTesting)
2917 + (void)_switchNetworkLoaderToNewTestingSession
2919 #if PLATFORM(IOS_FAMILY)
2920     WebThreadLock();
2921 #endif
2922     NetworkStorageSessionMap::switchToNewTestingSession();
2925 + (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy
2927     auto cookieStorage = NetworkStorageSessionMap::defaultStorageSession().cookieStorage();
2928     RELEASE_ASSERT(cookieStorage); // Will fail when NetworkStorageSessionMap::switchToNewTestingSession() was not called beforehand.
2929     CFHTTPCookieStorageSetCookieAcceptPolicy(cookieStorage.get(), policy);
2932 + (void)_clearNetworkLoaderSession
2934     NetworkStorageSessionMap::defaultStorageSession().deleteAllCookies();
2937 - (void)_setBoolPreferenceForTestingWithValue:(BOOL)value forKey:(NSString *)key
2939     [self _setBoolValue:value forKey:key];
2942 - (void)_setUInt32PreferenceForTestingWithValue:(uint32_t)value forKey:(NSString *)key
2944     [self _setIntegerValue:value forKey:key];
2947 - (void)_setDoublePreferenceForTestingWithValue:(double)value forKey:(NSString *)key
2949     [self _setFloatValue:value forKey:key];
2952 - (void)_setStringPreferenceForTestingWithValue:(NSString *)value forKey:(NSString *)key
2954     [self _setStringValue:value forKey:key];
2957 @end
2959 @implementation WebPreferences (WebPrivatePreferencesConvertedToWebFeature)
2961 - (BOOL)userGesturePromisePropagationEnabled
2963     return [self _boolValueForKey:WebKitUserGesturePromisePropagationEnabledPreferenceKey];
2966 - (void)setUserGesturePromisePropagationEnabled:(BOOL)flag
2968     [self _setBoolValue:flag forKey:WebKitUserGesturePromisePropagationEnabledPreferenceKey];
2971 - (BOOL)requestIdleCallbackEnabled
2973     return [self _boolValueForKey:WebKitRequestIdleCallbackEnabledPreferenceKey];
2976 - (void)setRequestIdleCallbackEnabled:(BOOL)flag
2978     [self _setBoolValue:flag forKey:WebKitRequestIdleCallbackEnabledPreferenceKey];
2981 - (BOOL)highlightAPIEnabled
2983     return [self _boolValueForKey:WebKitHighlightAPIEnabledPreferenceKey];
2986 - (void)setHighlightAPIEnabled:(BOOL)flag
2988     [self _setBoolValue:flag forKey:WebKitHighlightAPIEnabledPreferenceKey];
2991 - (BOOL)asyncClipboardAPIEnabled
2993     return [self _boolValueForKey:WebKitAsyncClipboardAPIEnabledPreferenceKey];
2996 - (void)setAsyncClipboardAPIEnabled:(BOOL)flag
2998     [self _setBoolValue:flag forKey:WebKitAsyncClipboardAPIEnabledPreferenceKey];
3001 - (BOOL)contactPickerAPIEnabled
3003     return [self _boolValueForKey:WebKitContactPickerAPIEnabledPreferenceKey];
3006 - (void)setContactPickerAPIEnabled:(BOOL)flag
3008     [self _setBoolValue:flag forKey:WebKitContactPickerAPIEnabledPreferenceKey];
3011 - (BOOL)intersectionObserverEnabled
3013     return [self _boolValueForKey:WebKitIntersectionObserverEnabledPreferenceKey];
3016 - (void)setIntersectionObserverEnabled:(BOOL)flag
3018     [self _setBoolValue:flag forKey:WebKitIntersectionObserverEnabledPreferenceKey];
3021 - (BOOL)visualViewportAPIEnabled
3023     return [self _boolValueForKey:WebKitVisualViewportAPIEnabledPreferenceKey];
3026 - (void)setVisualViewportAPIEnabled:(BOOL)flag
3028     [self _setBoolValue:flag forKey:WebKitVisualViewportAPIEnabledPreferenceKey];
3031 - (BOOL)syntheticEditingCommandsEnabled
3033     return [self _boolValueForKey:WebKitSyntheticEditingCommandsEnabledPreferenceKey];
3036 - (void)setSyntheticEditingCommandsEnabled:(BOOL)flag
3038     [self _setBoolValue:flag forKey:WebKitSyntheticEditingCommandsEnabledPreferenceKey];
3041 - (BOOL)CSSOMViewSmoothScrollingEnabled
3043     return [self _boolValueForKey:WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey];
3046 - (void)setCSSOMViewSmoothScrollingEnabled:(BOOL)flag
3048     [self _setBoolValue:flag forKey:WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey];
3051 - (BOOL)webAnimationsCompositeOperationsEnabled
3053     return [self _boolValueForKey:WebKitWebAnimationsCompositeOperationsEnabledPreferenceKey];
3056 - (void)setWebAnimationsCompositeOperationsEnabled:(BOOL)flag
3058     [self _setBoolValue:flag forKey:WebKitWebAnimationsCompositeOperationsEnabledPreferenceKey];
3061 - (BOOL)webAnimationsMutableTimelinesEnabled
3063     return [self _boolValueForKey:WebKitWebAnimationsMutableTimelinesEnabledPreferenceKey];
3066 - (void)setWebAnimationsMutableTimelinesEnabled:(BOOL)flag
3068     [self _setBoolValue:flag forKey:WebKitWebAnimationsMutableTimelinesEnabledPreferenceKey];
3071 - (BOOL)webGL2Enabled
3073     return [self _boolValueForKey:WebKitWebGL2EnabledPreferenceKey];
3076 - (void)setWebGL2Enabled:(BOOL)enabled
3078     [self _setBoolValue:enabled forKey:WebKitWebGL2EnabledPreferenceKey];
3081 - (BOOL)maskWebGLStringsEnabled
3083     return [self _boolValueForKey:WebKitMaskWebGLStringsEnabledPreferenceKey];
3086 - (void)setMaskWebGLStringsEnabled:(BOOL)enabled
3088     [self _setBoolValue:enabled forKey:WebKitMaskWebGLStringsEnabledPreferenceKey];
3091 - (BOOL)accessibilityObjectModelEnabled
3093     return [self _boolValueForKey:WebKitAccessibilityObjectModelEnabledPreferenceKey];
3096 - (void)setAccessibilityObjectModelEnabled:(BOOL)flag
3098     [self _setBoolValue:flag forKey:WebKitAccessibilityObjectModelEnabledPreferenceKey];
3101 - (BOOL)serverTimingEnabled
3103     return [self _boolValueForKey:WebKitServerTimingEnabledPreferenceKey];
3106 - (void)setServerTimingEnabled:(BOOL)flag
3108     [self _setBoolValue:flag forKey:WebKitServerTimingEnabledPreferenceKey];
3111 - (BOOL)CSSCustomPropertiesAndValuesEnabled
3113     return [self _boolValueForKey:WebKitCSSCustomPropertiesAndValuesEnabledPreferenceKey];
3116 - (void)setCSSCustomPropertiesAndValuesEnabled:(BOOL)flag
3118     [self _setBoolValue:flag forKey:WebKitCSSCustomPropertiesAndValuesEnabledPreferenceKey];
3121 - (BOOL)resizeObserverEnabled
3123     return [self _boolValueForKey:WebKitResizeObserverEnabledPreferenceKey];
3126 - (void)setResizeObserverEnabled:(BOOL)flag
3128     [self _setBoolValue:flag forKey:WebKitResizeObserverEnabledPreferenceKey];
3131 - (BOOL)privateClickMeasurementEnabled
3133     return [self _boolValueForKey:WebKitPrivateClickMeasurementEnabledPreferenceKey];
3136 - (void)setPrivateClickMeasurementEnabled:(BOOL)flag
3138     [self _setBoolValue:flag forKey:WebKitPrivateClickMeasurementEnabledPreferenceKey];
3141 - (BOOL)fetchAPIKeepAliveEnabled
3143     return [self _boolValueForKey:WebKitFetchAPIEnabledPreferenceKey];
3146 - (void)setFetchAPIKeepAliveEnabled:(BOOL)flag
3148     [self _setBoolValue:flag forKey:WebKitFetchAPIEnabledPreferenceKey];
3151 - (BOOL)genericCueAPIEnabled
3153     return [self _boolValueForKey:WebKitGenericCueAPIEnabledKey];
3156 - (void)setGenericCueAPIEnabled:(BOOL)flag
3158     [self _setBoolValue:flag forKey:WebKitGenericCueAPIEnabledKey];
3161 - (BOOL)aspectRatioOfImgFromWidthAndHeightEnabled
3163     return [self _boolValueForKey:WebKitAspectRatioOfImgFromWidthAndHeightEnabledPreferenceKey];
3166 - (void)setAspectRatioOfImgFromWidthAndHeightEnabled:(BOOL)flag
3168     [self _setBoolValue:flag forKey:WebKitAspectRatioOfImgFromWidthAndHeightEnabledPreferenceKey];
3171 - (BOOL)referrerPolicyAttributeEnabled
3173     return [self _boolValueForKey:WebKitReferrerPolicyAttributeEnabledPreferenceKey];
3176 - (void)setReferrerPolicyAttributeEnabled:(BOOL)flag
3178     [self _setBoolValue:flag forKey:WebKitReferrerPolicyAttributeEnabledPreferenceKey];
3181 - (BOOL)coreMathMLEnabled
3183     return [self _boolValueForKey:WebKitCoreMathMLEnabledPreferenceKey];
3186 - (void)setCoreMathMLEnabled:(BOOL)flag
3188     [self _setBoolValue:flag forKey:WebKitCoreMathMLEnabledPreferenceKey];
3191 - (BOOL)linkPreloadResponsiveImagesEnabled
3193     return [self _boolValueForKey:WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey];
3196 - (void)setLinkPreloadResponsiveImagesEnabled:(BOOL)flag
3198     [self _setBoolValue:flag forKey:WebKitLinkPreloadResponsiveImagesEnabledPreferenceKey];
3201 - (BOOL)remotePlaybackEnabled
3203     return [self _boolValueForKey:WebKitRemotePlaybackEnabledPreferenceKey];
3206 - (void)setRemotePlaybackEnabled:(BOOL)remotePlaybackEnabled
3208     [self _setBoolValue:remotePlaybackEnabled forKey:WebKitRemotePlaybackEnabledPreferenceKey];
3211 - (BOOL)readableByteStreamAPIEnabled
3213     return [self _boolValueForKey:WebKitReadableByteStreamAPIEnabledPreferenceKey];
3216 - (void)setReadableByteStreamAPIEnabled:(BOOL)flag
3218     [self _setBoolValue:flag forKey:WebKitReadableByteStreamAPIEnabledPreferenceKey];
3221 - (BOOL)transformStreamAPIEnabled
3223     return [self _boolValueForKey:WebKitTransformStreamAPIEnabledPreferenceKey];
3226 - (void)setTransformStreamAPIEnabled:(BOOL)flag
3228     [self _setBoolValue:flag forKey:WebKitTransformStreamAPIEnabledPreferenceKey];
3231 - (BOOL)_mediaRecorderEnabled
3233     return [self _boolValueForKey:WebKitMediaRecorderEnabledPreferenceKey];
3236 - (void)_setMediaRecorderEnabled:(BOOL)flag
3238     [self _setBoolValue:flag forKey:WebKitMediaRecorderEnabledPreferenceKey];
3241 - (BOOL)mediaRecorderEnabled
3243     return [self _boolValueForKey:WebKitMediaRecorderEnabledPreferenceKey];
3246 - (void)setMediaRecorderEnabled:(BOOL)flag
3248     [self _setBoolValue:flag forKey:WebKitMediaRecorderEnabledPreferenceKey];
3251 - (BOOL)CSSIndividualTransformPropertiesEnabled
3253     return [self _boolValueForKey:WebKitCSSIndividualTransformPropertiesEnabledPreferenceKey];
3256 - (void)setCSSIndividualTransformPropertiesEnabled:(BOOL)flag
3258     [self _setBoolValue:flag forKey:WebKitCSSIndividualTransformPropertiesEnabledPreferenceKey];
3261 - (BOOL)_speechRecognitionEnabled
3263     return [self _boolValueForKey:WebKitSpeechRecognitionEnabledPreferenceKey];
3266 - (void)_setSpeechRecognitionEnabled:(BOOL)flag
3268     [self _setBoolValue:flag forKey:WebKitSpeechRecognitionEnabledPreferenceKey];
3271 - (WebKitPitchCorrectionAlgorithm)_pitchCorrectionAlgorithm
3273     return static_cast<WebKitPitchCorrectionAlgorithm>([self _unsignedIntValueForKey:WebKitPitchCorrectionAlgorithmPreferenceKey]);
3276 - (void)_setPitchCorrectionAlgorithm:(WebKitPitchCorrectionAlgorithm)pitchCorrectionAlgorithm
3278     [self _setUnsignedIntValue:pitchCorrectionAlgorithm forKey:WebKitPitchCorrectionAlgorithmPreferenceKey];
3281 @end
3283 @implementation WebPreferences (WebPrivateObsolete)
3285 // The preferences in this category are deprecated and have no effect. They should
3286 // be removed when it is considered safe to do so.
3288 - (void)setSubpixelCSSOMElementMetricsEnabled:(BOOL)enabled
3290     [self _setBoolValue:enabled forKey:WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey];
3293 - (BOOL)subpixelCSSOMElementMetricsEnabled
3295     return [self _boolValueForKey:WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey];
3298 - (void)setUserTimingEnabled:(BOOL)flag
3302 - (BOOL)userTimingEnabled
3304     return YES;
3307 - (BOOL)requestAnimationFrameEnabled
3309     return YES;
3312 - (void)setRequestAnimationFrameEnabled:(BOOL)enabled
3316 - (void)setResourceTimingEnabled:(BOOL)flag
3320 - (BOOL)resourceTimingEnabled
3322     return YES;
3325 - (void)setCSSShadowPartsEnabled:(BOOL)flag
3329 - (BOOL)cssShadowPartsEnabled
3331     return YES;
3334 - (void)setIsSecureContextAttributeEnabled:(BOOL)flag
3338 - (BOOL)isSecureContextAttributeEnabled
3340     return YES;
3343 - (void)setFetchAPIEnabled:(BOOL)flag
3347 - (BOOL)fetchAPIEnabled
3349     return YES;
3352 - (void)setShadowDOMEnabled:(BOOL)flag
3356 - (BOOL)shadowDOMEnabled
3358     return YES;
3361 - (void)setCustomElementsEnabled:(BOOL)flag
3365 - (BOOL)customElementsEnabled
3367     return YES;
3370 - (BOOL)keygenElementEnabled
3372     return NO;
3375 - (void)setKeygenElementEnabled:(BOOL)flag
3379 - (void)setVideoPluginProxyEnabled:(BOOL)flag
3383 - (BOOL)isVideoPluginProxyEnabled
3385     return NO;
3388 - (void)setHixie76WebSocketProtocolEnabled:(BOOL)flag
3392 - (BOOL)isHixie76WebSocketProtocolEnabled
3394     return NO;
3397 - (void)setDiskImageCacheEnabled:(BOOL)enabled
3401 - (void)setAccelerated2dCanvasEnabled:(BOOL)enabled
3405 - (BOOL)accelerated2dCanvasEnabled
3407     return NO;
3410 - (void)setExperimentalNotificationsEnabled:(BOOL)enabled
3414 - (BOOL)experimentalNotificationsEnabled
3416     return NO;
3419 - (BOOL)selectionAcrossShadowBoundariesEnabled
3421     return YES;
3424 - (void)setSelectionAcrossShadowBoundariesEnabled:(BOOL)flag
3428 - (BOOL)isXSSAuditorEnabled
3430     return NO;
3433 - (void)setXSSAuditorEnabled:(BOOL)flag
3437 - (BOOL)isJavaEnabled
3439     return NO;
3442 - (void)setJavaEnabled:(BOOL)flag
3446 @end