3825a0d0f35d08a2a53bd652208cd8d6877d7425
[WebKit-https.git] / Source / WebKit / mac / WebView / WebPreferences.mm
1 /*
2  * Copyright (C) 2005, 2006, 2007, 2011, 2012, 2014 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  */
29
30 #import "WebPreferencesPrivate.h"
31 #import "WebPreferenceKeysPrivate.h"
32
33 #import "WebApplicationCache.h"
34 #import "WebFrameNetworkingContext.h"
35 #import "WebKitLogging.h"
36 #import "WebKitNSStringExtras.h"
37 #import "WebKitSystemBits.h"
38 #import "WebKitSystemInterface.h"
39 #import "WebKitVersionChecks.h"
40 #import "WebNSDictionaryExtras.h"
41 #import "WebNSURLExtras.h"
42 #import "WebSystemInterface.h"
43 #import <WebCore/ApplicationCacheStorage.h>
44 #import <WebCore/AudioSession.h>
45 #import <WebCore/NetworkStorageSession.h>
46 #import <WebCore/PlatformCookieJar.h>
47 #import <WebCore/ResourceHandle.h>
48 #import <WebCore/TextEncodingRegistry.h>
49 #import <runtime/InitializeThreading.h>
50 #import <wtf/MainThread.h>
51 #import <wtf/RetainPtr.h>
52 #import <wtf/RunLoop.h>
53
54 enum {
55     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3
56 };
57
58 using namespace WebCore;
59
60 #if PLATFORM(IOS)
61 #import <AudioToolbox/AudioSession.h>
62 #import <WebCore/GraphicsContext.h>
63 #import <WebCore/ImageSource.h>
64 #import <WebCore/WebCoreThreadMessage.h>
65 #endif
66
67 NSString *WebPreferencesChangedNotification = @"WebPreferencesChangedNotification";
68 NSString *WebPreferencesRemovedNotification = @"WebPreferencesRemovedNotification";
69 NSString *WebPreferencesChangedInternalNotification = @"WebPreferencesChangedInternalNotification";
70 NSString *WebPreferencesCacheModelChangedInternalNotification = @"WebPreferencesCacheModelChangedInternalNotification";
71
72 #define KEY(x) (_private->identifier ? [_private->identifier.get() stringByAppendingString:(x)] : (x))
73
74 enum { WebPreferencesVersion = 1 };
75
76 static WebPreferences *_standardPreferences;
77 static NSMutableDictionary *webPreferencesInstances;
78
79 static unsigned webPreferencesInstanceCountWithPrivateBrowsingEnabled;
80
81 static bool contains(const char* const array[], int count, const char* item)
82 {
83     if (!item)
84         return false;
85
86     for (int i = 0; i < count; i++)
87         if (!strcasecmp(array[i], item))
88             return true;
89     return false;
90 }
91
92 static WebCacheModel cacheModelForMainBundle(void)
93 {
94     @autoreleasepool {
95         // Apps that probably need the small setting
96         static const char* const documentViewerIDs[] = {
97             "Microsoft/com.microsoft.Messenger",
98             "com.adiumX.adiumX", 
99             "com.alientechnology.Proteus",
100             "com.apple.Dashcode",
101             "com.apple.iChat", 
102             "com.barebones.bbedit",
103             "com.barebones.textwrangler",
104             "com.barebones.yojimbo",
105             "com.equinux.iSale4",
106             "com.growl.growlframework",
107             "com.intrarts.PandoraMan",
108             "com.karelia.Sandvox",
109             "com.macromates.textmate",
110             "com.realmacsoftware.rapidweaverpro",
111             "com.red-sweater.marsedit",
112             "com.yahoo.messenger3",
113             "de.codingmonkeys.SubEthaEdit",
114             "fi.karppinen.Pyro",
115             "info.colloquy", 
116             "kungfoo.tv.ecto",
117         };
118
119         // Apps that probably need the medium setting
120         static const char* const documentBrowserIDs[] = {
121             "com.apple.Dictionary",
122             "com.apple.Xcode",
123             "com.apple.dashboard.client", 
124             "com.apple.helpviewer",
125             "com.culturedcode.xyle",
126             "com.macrabbit.CSSEdit",
127             "com.panic.Coda",
128             "com.ranchero.NetNewsWire",
129             "com.thinkmac.NewsLife",
130             "org.xlife.NewsFire",
131             "uk.co.opencommunity.vienna2",
132         };
133
134         // Apps that probably need the large setting
135         static const char* const primaryWebBrowserIDs[] = {
136             "com.app4mac.KidsBrowser"
137             "com.app4mac.wKiosk",
138             "com.freeverse.bumpercar",
139             "com.omnigroup.OmniWeb5",
140             "com.sunrisebrowser.Sunrise",
141             "net.hmdt-web.Shiira",
142         };
143
144         const char* bundleID = [[[NSBundle mainBundle] bundleIdentifier] UTF8String];
145         if (contains(documentViewerIDs, sizeof(documentViewerIDs) / sizeof(documentViewerIDs[0]), bundleID))
146             return WebCacheModelDocumentViewer;
147         if (contains(documentBrowserIDs, sizeof(documentBrowserIDs) / sizeof(documentBrowserIDs[0]), bundleID))
148             return WebCacheModelDocumentBrowser;
149         if (contains(primaryWebBrowserIDs, sizeof(primaryWebBrowserIDs) / sizeof(primaryWebBrowserIDs[0]), bundleID))
150             return WebCacheModelPrimaryWebBrowser;
151
152         bool isLinkedAgainstWebKit = WebKitLinkedOnOrAfter(0);
153         if (!isLinkedAgainstWebKit)
154             return WebCacheModelDocumentViewer; // Apps that don't link against WebKit probably aren't meant to be browsers.
155
156 #if !PLATFORM(IOS)
157         bool isLegacyApp = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_CACHE_MODEL_API);
158 #else
159         bool isLegacyApp = false;
160 #endif
161         if (isLegacyApp)
162             return WebCacheModelDocumentBrowser; // To avoid regressions in apps that depended on old WebKit's large cache.
163
164         return WebCacheModelDocumentViewer; // To save memory.
165     }
166 }
167
168 @interface WebPreferences ()
169 - (void)_postCacheModelChangedNotification;
170 @end
171
172 @interface WebPreferences (WebInternal)
173 + (NSString *)_concatenateKeyWithIBCreatorID:(NSString *)key;
174 + (NSString *)_IBCreatorID;
175 @end
176
177 struct WebPreferencesPrivate
178 {
179 public:
180     WebPreferencesPrivate()
181     : inPrivateBrowsing(NO)
182     , autosaves(NO)
183     , automaticallyDetectsCacheModel(NO)
184     , numWebViews(0)
185 #if PLATFORM(IOS)
186     , readWriteQueue(dispatch_queue_create("com.apple.WebPreferences.ReadWriteQueue", DISPATCH_QUEUE_CONCURRENT))
187 #endif
188     {
189     }
190
191 #if PLATFORM(IOS)
192     ~WebPreferencesPrivate()
193     {
194         dispatch_release(readWriteQueue);
195     }
196 #endif
197
198     RetainPtr<NSMutableDictionary> values;
199     BOOL inPrivateBrowsing;
200     RetainPtr<NSString> identifier;
201     BOOL autosaves;
202     BOOL automaticallyDetectsCacheModel;
203     unsigned numWebViews;
204 #if PLATFORM(IOS)
205     dispatch_queue_t readWriteQueue;
206 #endif
207 };
208
209 @interface WebPreferences (WebForwardDeclarations)
210 // This pseudo-category is needed so these methods can be used from within other category implementations
211 // without being in the public header file.
212 - (BOOL)_boolValueForKey:(NSString *)key;
213 - (void)_setBoolValue:(BOOL)value forKey:(NSString *)key;
214 - (int)_integerValueForKey:(NSString *)key;
215 - (void)_setIntegerValue:(int)value forKey:(NSString *)key;
216 - (float)_floatValueForKey:(NSString *)key;
217 - (void)_setFloatValue:(float)value forKey:(NSString *)key;
218 - (void)_setLongLongValue:(long long)value forKey:(NSString *)key;
219 - (long long)_longLongValueForKey:(NSString *)key;
220 - (void)_setUnsignedLongLongValue:(unsigned long long)value forKey:(NSString *)key;
221 - (unsigned long long)_unsignedLongLongValueForKey:(NSString *)key;
222 @end
223
224 #if PLATFORM(IOS)
225 @interface WebPreferences ()
226 - (id)initWithIdentifier:(NSString *)anIdentifier sendChangeNotification:(BOOL)sendChangeNotification;
227 @end
228 #endif
229
230 @implementation WebPreferences
231
232 - (instancetype)init
233 {
234     // Create fake identifier
235     static int instanceCount = 1;
236     NSString *fakeIdentifier;
237     
238     // At least ensure that identifier hasn't been already used.  
239     fakeIdentifier = [NSString stringWithFormat:@"WebPreferences%d", instanceCount++];
240     while ([[self class] _getInstanceForIdentifier:fakeIdentifier]){
241         fakeIdentifier = [NSString stringWithFormat:@"WebPreferences%d", instanceCount++];
242     }
243     
244     return [self initWithIdentifier:fakeIdentifier];
245 }
246
247 #if PLATFORM(IOS)
248 - (id)initWithIdentifier:(NSString *)anIdentifier
249 {
250     return [self initWithIdentifier:anIdentifier sendChangeNotification:YES];
251 }
252 #endif
253
254 #if PLATFORM(IOS)
255 - (instancetype)initWithIdentifier:(NSString *)anIdentifier sendChangeNotification:(BOOL)sendChangeNotification
256 #else
257 - (instancetype)initWithIdentifier:(NSString *)anIdentifier
258 #endif
259 {
260     WebPreferences *instance = [[self class] _getInstanceForIdentifier:anIdentifier];
261     if (instance) {
262         [self release];
263         return [instance retain];
264     }
265
266     self = [super init];
267     if (!self)
268         return nil;
269
270     _private = new WebPreferencesPrivate;
271     _private->values = adoptNS([[NSMutableDictionary alloc] init]);
272     _private->identifier = adoptNS([anIdentifier copy]);
273     _private->automaticallyDetectsCacheModel = YES;
274
275     [[self class] _setInstance:self forIdentifier:_private->identifier.get()];
276
277     [self _updatePrivateBrowsingStateTo:[self privateBrowsingEnabled]];
278
279 #if PLATFORM(IOS)
280     if (sendChangeNotification) {
281         [self _postPreferencesChangedNotification];
282         [self _postCacheModelChangedNotification];
283     }
284 #else
285     [self _postPreferencesChangedNotification];
286     [self _postCacheModelChangedNotification];
287 #endif
288
289     return self;
290 }
291
292 - (instancetype)initWithCoder:(NSCoder *)decoder
293 {
294     self = [super init];
295     if (!self)
296         return nil;
297
298     _private = new WebPreferencesPrivate;
299     _private->automaticallyDetectsCacheModel = YES;
300
301     @try {
302         id identifier = nil;
303         id values = nil;
304         if ([decoder allowsKeyedCoding]) {
305             identifier = [decoder decodeObjectForKey:@"Identifier"];
306             values = [decoder decodeObjectForKey:@"Values"];
307         } else {
308             int version;
309             [decoder decodeValueOfObjCType:@encode(int) at:&version];
310             if (version == 1) {
311                 identifier = [decoder decodeObject];
312                 values = [decoder decodeObject];
313             }
314         }
315
316         if ([identifier isKindOfClass:[NSString class]])
317             _private->identifier = adoptNS([identifier copy]);
318         if ([values isKindOfClass:[NSDictionary class]])
319             _private->values = adoptNS([values mutableCopy]); // ensure dictionary is mutable
320
321         LOG(Encoding, "Identifier = %@, Values = %@\n", _private->identifier.get(), _private->values.get());
322     } @catch(id) {
323         [self release];
324         return nil;
325     }
326
327     // If we load a nib multiple times, or have instances in multiple
328     // nibs with the same name, the first guy up wins.
329     WebPreferences *instance = [[self class] _getInstanceForIdentifier:_private->identifier.get()];
330     if (instance) {
331         [self release];
332         self = [instance retain];
333     } else {
334         [[self class] _setInstance:self forIdentifier:_private->identifier.get()];
335         [self _updatePrivateBrowsingStateTo:[self privateBrowsingEnabled]];
336     }
337
338     return self;
339 }
340
341 - (void)encodeWithCoder:(NSCoder *)encoder
342 {
343     if ([encoder allowsKeyedCoding]){
344         [encoder encodeObject:_private->identifier.get() forKey:@"Identifier"];
345 #if PLATFORM(IOS)
346         dispatch_sync(_private->readWriteQueue, ^{
347 #endif
348         [encoder encodeObject:_private->values.get() forKey:@"Values"];
349         LOG (Encoding, "Identifier = %@, Values = %@\n", _private->identifier.get(), _private->values.get());
350 #if PLATFORM(IOS)
351         });
352 #endif
353     }
354     else {
355         int version = WebPreferencesVersion;
356         [encoder encodeValueOfObjCType:@encode(int) at:&version];
357         [encoder encodeObject:_private->identifier.get()];
358 #if PLATFORM(IOS)
359         dispatch_sync(_private->readWriteQueue, ^{
360 #endif
361         [encoder encodeObject:_private->values.get()];
362 #if PLATFORM(IOS)
363         });
364 #endif
365     }
366 }
367
368 + (WebPreferences *)standardPreferences
369 {
370 #if !PLATFORM(IOS)
371     if (_standardPreferences == nil) {
372         _standardPreferences = [[WebPreferences alloc] initWithIdentifier:nil];
373         [_standardPreferences setAutosaves:YES];
374     }
375 #else
376     // FIXME: This check is necessary to avoid recursion (see <rdar://problem/9564337>), but it also makes _standardPreferences construction not thread safe.
377     if (_standardPreferences)
378         return _standardPreferences;
379
380     static dispatch_once_t pred;
381     dispatch_once(&pred, ^{
382         _standardPreferences = [[WebPreferences alloc] initWithIdentifier:nil sendChangeNotification:NO];
383         [_standardPreferences _postPreferencesChangedNotification];
384         [_standardPreferences setAutosaves:YES];
385     });
386 #endif
387
388     return _standardPreferences;
389 }
390
391 // if we ever have more than one WebPreferences object, this would move to init
392 + (void)initialize
393 {
394 #if !PLATFORM(IOS)
395     JSC::initializeThreading();
396     WTF::initializeMainThreadToProcessMainThread();
397     RunLoop::initializeMainRunLoop();
398 #endif
399     InitWebCoreSystemInterface();
400
401     NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
402         @"Times",                       WebKitStandardFontPreferenceKey,
403         @"Courier",                     WebKitFixedFontPreferenceKey,
404         @"Times",                       WebKitSerifFontPreferenceKey,
405         @"Helvetica",                   WebKitSansSerifFontPreferenceKey,
406 #if !PLATFORM(IOS)
407         @"Apple Chancery",              WebKitCursiveFontPreferenceKey,
408 #else
409         @"Snell Roundhand",             WebKitCursiveFontPreferenceKey,
410 #endif
411         @"Papyrus",                     WebKitFantasyFontPreferenceKey,
412 #if PLATFORM(IOS)
413         @"AppleColorEmoji",             WebKitPictographFontPreferenceKey,
414 #else
415         @"Apple Color Emoji",           WebKitPictographFontPreferenceKey,
416 #endif
417         @"0",                           WebKitMinimumFontSizePreferenceKey,
418         @"9",                           WebKitMinimumLogicalFontSizePreferenceKey, 
419         @"16",                          WebKitDefaultFontSizePreferenceKey,
420         @(YES),                         WebKitAntialiasedFontDilationEnabledKey,
421         @"13",                          WebKitDefaultFixedFontSizePreferenceKey,
422         @"ISO-8859-1",                  WebKitDefaultTextEncodingNamePreferenceKey,
423         [NSNumber numberWithBool:NO],   WebKitUsesEncodingDetectorPreferenceKey,
424         [NSNumber numberWithBool:NO],   WebKitUserStyleSheetEnabledPreferenceKey,
425         @"",                            WebKitUserStyleSheetLocationPreferenceKey,
426 #if !PLATFORM(IOS)
427         [NSNumber numberWithBool:NO],   WebKitShouldPrintBackgroundsPreferenceKey,
428         [NSNumber numberWithBool:NO],   WebKitTextAreasAreResizablePreferenceKey,
429 #endif
430         [NSNumber numberWithBool:NO],   WebKitShrinksStandaloneImagesToFitPreferenceKey,
431 #if !PLATFORM(IOS)
432         [NSNumber numberWithBool:YES],  WebKitJavaEnabledPreferenceKey,
433 #endif
434         [NSNumber numberWithBool:YES],  WebKitJavaScriptEnabledPreferenceKey,
435         [NSNumber numberWithBool:YES],  WebKitJavaScriptMarkupEnabledPreferenceKey,
436         [NSNumber numberWithBool:YES],  WebKitWebSecurityEnabledPreferenceKey,
437         [NSNumber numberWithBool:YES],  WebKitAllowUniversalAccessFromFileURLsPreferenceKey,
438         [NSNumber numberWithBool:YES],  WebKitAllowFileAccessFromFileURLsPreferenceKey,
439 #if PLATFORM(IOS)
440         [NSNumber numberWithBool:NO],   WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey,
441 #else
442         [NSNumber numberWithBool:YES],  WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey,
443 #endif
444         [NSNumber numberWithBool:YES],  WebKitPluginsEnabledPreferenceKey,
445         [NSNumber numberWithBool:YES],  WebKitDatabasesEnabledPreferenceKey,
446 #if PLATFORM(IOS)
447         [NSNumber numberWithBool:NO],   WebKitStorageTrackerEnabledPreferenceKey,
448 #endif
449         [NSNumber numberWithBool:YES],  WebKitLocalStorageEnabledPreferenceKey,
450         [NSNumber numberWithBool:NO],   WebKitExperimentalNotificationsEnabledPreferenceKey,
451         [NSNumber numberWithBool:YES],  WebKitAllowAnimatedImagesPreferenceKey,
452         [NSNumber numberWithBool:YES],  WebKitAllowAnimatedImageLoopingPreferenceKey,
453         [NSNumber numberWithBool:YES],  WebKitDisplayImagesKey,
454         [NSNumber numberWithBool:NO],   WebKitLoadSiteIconsKey,
455         @"1800",                        WebKitBackForwardCacheExpirationIntervalKey,
456 #if !PLATFORM(IOS)
457         [NSNumber numberWithBool:NO],   WebKitTabToLinksPreferenceKey,
458 #endif
459         [NSNumber numberWithBool:NO],   WebKitPrivateBrowsingEnabledPreferenceKey,
460 #if !PLATFORM(IOS)
461         [NSNumber numberWithBool:NO],   WebKitRespectStandardStyleKeyEquivalentsPreferenceKey,
462         [NSNumber numberWithBool:NO],   WebKitShowsURLsInToolTipsPreferenceKey,
463         [NSNumber numberWithBool:NO],   WebKitShowsToolTipOverTruncatedTextPreferenceKey,
464         @"1",                           WebKitPDFDisplayModePreferenceKey,
465         @"0",                           WebKitPDFScaleFactorPreferenceKey,
466 #endif
467         @"0",                           WebKitUseSiteSpecificSpoofingPreferenceKey,
468         [NSNumber numberWithInt:WebKitEditableLinkDefaultBehavior], WebKitEditableLinkBehaviorPreferenceKey,
469 #if !PLATFORM(IOS)
470         [NSNumber numberWithInt:WebTextDirectionSubmenuAutomaticallyIncluded],
471                                         WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey,
472         [NSNumber numberWithBool:NO],   WebKitDOMPasteAllowedPreferenceKey,
473 #endif
474         [NSNumber numberWithBool:YES],  WebKitUsesPageCachePreferenceKey,
475         [NSNumber numberWithInt:cacheModelForMainBundle()], WebKitCacheModelPreferenceKey,
476         [NSNumber numberWithBool:YES],  WebKitPageCacheSupportsPluginsPreferenceKey,
477         [NSNumber numberWithBool:NO],   WebKitDeveloperExtrasEnabledPreferenceKey,
478         [NSNumber numberWithUnsignedInt:0], WebKitJavaScriptRuntimeFlagsPreferenceKey,
479         [NSNumber numberWithBool:YES],  WebKitAuthorAndUserStylesEnabledPreferenceKey,
480         [NSNumber numberWithBool:YES],  WebKitDOMTimersThrottlingEnabledPreferenceKey,
481         [NSNumber numberWithBool:NO],   WebKitWebArchiveDebugModeEnabledPreferenceKey,
482         [NSNumber numberWithBool:NO],   WebKitLocalFileContentSniffingEnabledPreferenceKey,
483         [NSNumber numberWithBool:NO],   WebKitOfflineWebApplicationCacheEnabledPreferenceKey,
484         [NSNumber numberWithBool:YES],  WebKitZoomsTextOnlyPreferenceKey,
485         [NSNumber numberWithBool:NO],   WebKitJavaScriptCanAccessClipboardPreferenceKey,
486         [NSNumber numberWithBool:YES],  WebKitXSSAuditorEnabledPreferenceKey,
487         [NSNumber numberWithBool:YES],  WebKitAcceleratedCompositingEnabledPreferenceKey,
488         [NSNumber numberWithBool:YES], WebKitCSSRegionsEnabledPreferenceKey,
489         [NSNumber numberWithBool:YES], WebKitCSSCompositingEnabledPreferenceKey,
490 #if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR)
491         [NSNumber numberWithBool:YES],  WebKitAcceleratedDrawingEnabledPreferenceKey,
492         [NSNumber numberWithBool:YES],  WebKitCanvasUsesAcceleratedDrawingPreferenceKey,
493 #else
494         [NSNumber numberWithBool:NO],  WebKitAcceleratedDrawingEnabledPreferenceKey,
495         [NSNumber numberWithBool:NO],  WebKitCanvasUsesAcceleratedDrawingPreferenceKey,
496 #endif
497         [NSNumber numberWithBool:NO],   WebKitShowDebugBordersPreferenceKey,
498         [NSNumber numberWithBool:NO],   WebKitSimpleLineLayoutDebugBordersEnabledPreferenceKey,
499         [NSNumber numberWithBool:NO],   WebKitShowRepaintCounterPreferenceKey,
500         [NSNumber numberWithBool:YES],  WebKitWebGLEnabledPreferenceKey,
501         [NSNumber numberWithBool:NO],  WebKitForceSoftwareWebGLRenderingPreferenceKey,
502         [NSNumber numberWithBool:NO],   WebKitAccelerated2dCanvasEnabledPreferenceKey,
503         [NSNumber numberWithBool:NO],  WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey,
504 #if PLATFORM(IOS)
505         [NSNumber numberWithBool:YES],  WebKitFrameFlatteningEnabledPreferenceKey,
506 #else
507         [NSNumber numberWithBool:NO],   WebKitFrameFlatteningEnabledPreferenceKey,
508 #endif
509         [NSNumber numberWithBool:NO],   WebKitSpatialNavigationEnabledPreferenceKey,
510         [NSNumber numberWithBool:NO],  WebKitDNSPrefetchingEnabledPreferenceKey,
511         [NSNumber numberWithBool:NO],   WebKitFullScreenEnabledPreferenceKey,
512         [NSNumber numberWithBool:NO],   WebKitAsynchronousSpellCheckingEnabledPreferenceKey,
513         [NSNumber numberWithBool:YES],  WebKitHyperlinkAuditingEnabledPreferenceKey,
514         [NSNumber numberWithBool:NO],   WebKitUsePreHTML5ParserQuirksKey,
515         [NSNumber numberWithBool:YES],  WebKitAVFoundationEnabledKey,
516         [NSNumber numberWithBool:NO],   WebKitSuppressesIncrementalRenderingKey,
517 #if !PLATFORM(IOS)
518         [NSNumber numberWithBool:NO],   WebKitMediaPlaybackRequiresUserGesturePreferenceKey,
519         [NSNumber numberWithBool:YES],  WebKitMediaPlaybackAllowsInlinePreferenceKey,
520         [NSNumber numberWithBool:NO],   WebKitWebAudioEnabledPreferenceKey,
521         [NSNumber numberWithBool:YES],  WebKitBackspaceKeyNavigationEnabledKey,
522         [NSNumber numberWithBool:NO],   WebKitShouldDisplaySubtitlesPreferenceKey,
523         [NSNumber numberWithBool:NO],   WebKitShouldDisplayCaptionsPreferenceKey,
524         [NSNumber numberWithBool:NO],   WebKitShouldDisplayTextDescriptionsPreferenceKey,
525         [NSNumber numberWithBool:YES],  WebKitNotificationsEnabledKey,
526         [NSNumber numberWithBool:NO],   WebKitShouldRespectImageOrientationKey,
527 #else
528         [NSNumber numberWithBool:YES],  WebKitMediaPlaybackRequiresUserGesturePreferenceKey,
529         [NSNumber numberWithBool:NO],   WebKitMediaPlaybackAllowsInlinePreferenceKey,
530         [NSNumber numberWithBool:YES],  WebKitMediaPlaybackAllowsAirPlayPreferenceKey,
531         [NSNumber numberWithUnsignedInt:AudioSession::None],  WebKitAudioSessionCategoryOverride,
532 #if HAVE(AVKIT)
533         [NSNumber numberWithBool:YES],  WebKitAVKitEnabled,
534 #endif
535         [NSNumber numberWithLongLong:WebCore::ApplicationCacheStorage::noQuota()], WebKitApplicationCacheTotalQuota,
536
537         // Per-Origin Quota on iOS is 25MB. When the quota is reached for a particular origin
538         // the quota for that origin can be increased. See also webView:exceededApplicationCacheOriginQuotaForSecurityOrigin:totalSpaceNeeded in WebUI/WebUIDelegate.m.
539         [NSNumber numberWithLongLong:(25 * 1024 * 1024)], WebKitApplicationCacheDefaultOriginQuota,
540
541         // Enable WebAudio by default in all iOS UIWebViews
542         [NSNumber numberWithBool:YES],   WebKitWebAudioEnabledPreferenceKey,
543
544         [NSNumber numberWithBool:YES],   WebKitShouldRespectImageOrientationKey,
545 #endif // PLATFORM(IOS)
546         [NSNumber numberWithBool:YES],  WebKitAllowsAlternateFullscreenPreferenceKey,
547         [NSNumber numberWithBool:YES],  WebKitRequestAnimationFrameEnabledPreferenceKey,
548         [NSNumber numberWithBool:NO],   WebKitWantsBalancedSetDefersLoadingBehaviorKey,
549         [NSNumber numberWithBool:NO],   WebKitDiagnosticLoggingEnabledKey,
550         [NSNumber numberWithInt:WebAllowAllStorage], WebKitStorageBlockingPolicyKey,
551         [NSNumber numberWithBool:NO],   WebKitPlugInSnapshottingEnabledPreferenceKey,
552
553 #if PLATFORM(IOS)
554         [NSNumber numberWithBool:NO],   WebKitTelephoneParsingEnabledPreferenceKey,
555         [NSNumber numberWithInt:-1],      WebKitLayoutIntervalPreferenceKey,
556         [NSNumber numberWithFloat:-1.0f], WebKitMaxParseDurationPreferenceKey,
557         [NSNumber numberWithBool:NO],     WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey,
558         [NSNumber numberWithBool:NO],     WebKitAlwaysRequestGeolocationPermissionPreferenceKey,
559         [NSNumber numberWithInt:InterpolationLow], WebKitInterpolationQualityPreferenceKey,
560         [NSNumber numberWithBool:YES],    WebKitPasswordEchoEnabledPreferenceKey,
561         [NSNumber numberWithFloat:2.0f],  WebKitPasswordEchoDurationPreferenceKey,
562         [NSNumber numberWithBool:NO],     WebKitNetworkDataUsageTrackingEnabledPreferenceKey,
563         @"",                              WebKitNetworkInterfaceNamePreferenceKey,
564 #endif
565 #if ENABLE(IOS_TEXT_AUTOSIZING)
566         [NSNumber numberWithFloat:WKGetMinimumZoomFontSize()], WebKitMinimumZoomFontSizePreferenceKey,
567 #endif
568         [NSNumber numberWithLongLong:ApplicationCacheStorage::noQuota()], WebKitApplicationCacheTotalQuota,
569         [NSNumber numberWithLongLong:ApplicationCacheStorage::noQuota()], WebKitApplicationCacheDefaultOriginQuota,
570         [NSNumber numberWithBool:YES],  WebKitQTKitEnabledPreferenceKey,
571         [NSNumber numberWithBool:NO], WebKitHiddenPageDOMTimerThrottlingEnabledPreferenceKey,
572         [NSNumber numberWithBool:NO], WebKitHiddenPageCSSAnimationSuspensionEnabledPreferenceKey,
573         [NSNumber numberWithBool:NO], WebKitLowPowerVideoAudioBufferSizeEnabledPreferenceKey,
574         
575         [NSNumber numberWithBool:NO], WebKitUseLegacyTextAlignPositionedElementBehaviorPreferenceKey,
576 #if ENABLE(MEDIA_SOURCE)
577         [NSNumber numberWithBool:YES], WebKitMediaSourceEnabledPreferenceKey,
578 #endif
579 #if ENABLE(SERVICE_CONTROLS)
580         [NSNumber numberWithBool:NO], WebKitImageControlsEnabledPreferenceKey,
581         [NSNumber numberWithBool:NO], WebKitServiceControlsEnabledPreferenceKey,
582 #endif
583         [NSNumber numberWithBool:NO], WebKitEnableInheritURIQueryComponentPreferenceKey,
584 #if ENABLE(ENCRYPTED_MEDIA_V2)
585         @"~/Library/WebKit/MediaKeys", WebKitMediaKeysStorageDirectoryKey,
586 #endif
587         nil];
588
589 #if !PLATFORM(IOS)
590     // This value shouldn't ever change, which is assumed in the initialization of WebKitPDFDisplayModePreferenceKey above
591     ASSERT(kPDFDisplaySinglePageContinuous == 1);
592 #endif
593     [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
594 }
595
596 - (void)dealloc
597 {
598     [self _updatePrivateBrowsingStateTo:NO];
599
600     delete _private;
601     [super dealloc];
602 }
603
604 - (NSString *)identifier
605 {
606     return _private->identifier.get();
607 }
608
609 - (id)_valueForKey:(NSString *)key
610 {
611     NSString *_key = KEY(key);
612 #if PLATFORM(IOS)
613     __block id o = nil;
614     dispatch_sync(_private->readWriteQueue, ^{
615         o = [_private->values.get() objectForKey:_key];
616     });
617 #else
618     id o = [_private->values.get() objectForKey:_key];
619 #endif
620     if (o)
621         return o;
622     o = [[NSUserDefaults standardUserDefaults] objectForKey:_key];
623     if (!o && key != _key)
624         o = [[NSUserDefaults standardUserDefaults] objectForKey:key];
625     return o;
626 }
627
628 - (NSString *)_stringValueForKey:(NSString *)key
629 {
630     id s = [self _valueForKey:key];
631     return [s isKindOfClass:[NSString class]] ? (NSString *)s : nil;
632 }
633
634 - (void)_setStringValue:(NSString *)value forKey:(NSString *)key
635 {
636     if ([[self _stringValueForKey:key] isEqualToString:value])
637         return;
638     NSString *_key = KEY(key);
639 #if PLATFORM(IOS)
640     dispatch_barrier_sync(_private->readWriteQueue, ^{
641 #endif
642     [_private->values.get() setObject:value forKey:_key];
643 #if PLATFORM(IOS)
644     });
645 #endif
646     if (_private->autosaves)
647         [[NSUserDefaults standardUserDefaults] setObject:value forKey:_key];
648     [self _postPreferencesChangedNotification];
649 }
650
651 - (int)_integerValueForKey:(NSString *)key
652 {
653     id o = [self _valueForKey:key];
654     return [o respondsToSelector:@selector(intValue)] ? [o intValue] : 0;
655 }
656
657 - (void)_setIntegerValue:(int)value forKey:(NSString *)key
658 {
659     if ([self _integerValueForKey:key] == value)
660         return;
661     NSString *_key = KEY(key);
662 #if PLATFORM(IOS)
663     dispatch_barrier_sync(_private->readWriteQueue, ^{
664 #endif
665     [_private->values.get() _webkit_setInt:value forKey:_key];
666 #if PLATFORM(IOS)
667     });
668 #endif
669     if (_private->autosaves)
670         [[NSUserDefaults standardUserDefaults] setInteger:value forKey:_key];
671     [self _postPreferencesChangedNotification];
672 }
673
674 - (unsigned int)_unsignedIntValueForKey:(NSString *)key
675 {
676     id o = [self _valueForKey:key];
677     return [o respondsToSelector:@selector(unsignedIntValue)] ? [o unsignedIntValue] : 0;
678 }
679
680 - (void)_setUnsignedIntValue:(unsigned int)value forKey:(NSString *)key
681 {    if ([self _unsignedIntValueForKey:key] == value)
682         return;
683     NSString *_key = KEY(key);
684 #if PLATFORM(IOS)
685     dispatch_barrier_sync(_private->readWriteQueue, ^{
686 #endif
687     [_private->values.get() _webkit_setUnsignedInt:value forKey:_key];
688 #if PLATFORM(IOS)
689     });
690 #endif
691     if (_private->autosaves)
692         [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInt:value] forKey:_key];
693     [self _postPreferencesChangedNotification];
694 }
695
696 - (float)_floatValueForKey:(NSString *)key
697 {
698     id o = [self _valueForKey:key];
699     return [o respondsToSelector:@selector(floatValue)] ? [o floatValue] : 0.0f;
700 }
701
702 - (void)_setFloatValue:(float)value forKey:(NSString *)key
703 {
704     if ([self _floatValueForKey:key] == value)
705         return;
706     NSString *_key = KEY(key);
707 #if PLATFORM(IOS)
708     dispatch_barrier_sync(_private->readWriteQueue, ^{
709 #endif
710     [_private->values.get() _webkit_setFloat:value forKey:_key];
711 #if PLATFORM(IOS)
712     });
713 #endif
714     if (_private->autosaves)
715         [[NSUserDefaults standardUserDefaults] setFloat:value forKey:_key];
716     [self _postPreferencesChangedNotification];
717 }
718
719 - (BOOL)_boolValueForKey:(NSString *)key
720 {
721     return [self _integerValueForKey:key] != 0;
722 }
723
724 - (void)_setBoolValue:(BOOL)value forKey:(NSString *)key
725 {
726     if ([self _boolValueForKey:key] == value)
727         return;
728     NSString *_key = KEY(key);
729 #if PLATFORM(IOS)
730     dispatch_barrier_sync(_private->readWriteQueue, ^{
731 #endif
732     [_private->values.get() _webkit_setBool:value forKey:_key];
733 #if PLATFORM(IOS)
734     });
735 #endif
736     if (_private->autosaves)
737         [[NSUserDefaults standardUserDefaults] setBool:value forKey:_key];
738     [self _postPreferencesChangedNotification];
739 }
740
741 - (long long)_longLongValueForKey:(NSString *)key
742 {
743     id o = [self _valueForKey:key];
744     return [o respondsToSelector:@selector(longLongValue)] ? [o longLongValue] : 0;
745 }
746
747 - (void)_setLongLongValue:(long long)value forKey:(NSString *)key
748 {
749     if ([self _longLongValueForKey:key] == value)
750         return;
751     NSString *_key = KEY(key);
752 #if PLATFORM(IOS)
753     dispatch_barrier_sync(_private->readWriteQueue, ^{
754 #endif
755     [_private->values.get() _webkit_setLongLong:value forKey:_key];
756 #if PLATFORM(IOS)
757     });
758 #endif
759     if (_private->autosaves)
760         [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithLongLong:value] forKey:_key];
761     [self _postPreferencesChangedNotification];
762 }
763
764 - (unsigned long long)_unsignedLongLongValueForKey:(NSString *)key
765 {
766     id o = [self _valueForKey:key];
767     return [o respondsToSelector:@selector(unsignedLongLongValue)] ? [o unsignedLongLongValue] : 0;
768 }
769
770 - (void)_setUnsignedLongLongValue:(unsigned long long)value forKey:(NSString *)key
771 {
772     if ([self _unsignedLongLongValueForKey:key] == value)
773         return;
774     NSString *_key = KEY(key);
775 #if PLATFORM(IOS)
776     dispatch_barrier_sync(_private->readWriteQueue, ^{
777 #endif
778     [_private->values.get() _webkit_setUnsignedLongLong:value forKey:_key];
779 #if PLATFORM(IOS)
780     });
781 #endif
782     if (_private->autosaves)
783         [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedLongLong:value] forKey:_key];
784     [self _postPreferencesChangedNotification];
785 }
786
787 - (NSString *)standardFontFamily
788 {
789     return [self _stringValueForKey: WebKitStandardFontPreferenceKey];
790 }
791
792 - (void)setStandardFontFamily:(NSString *)family
793 {
794     [self _setStringValue: family forKey: WebKitStandardFontPreferenceKey];
795 }
796
797 - (NSString *)fixedFontFamily
798 {
799     return [self _stringValueForKey: WebKitFixedFontPreferenceKey];
800 }
801
802 - (void)setFixedFontFamily:(NSString *)family
803 {
804     [self _setStringValue: family forKey: WebKitFixedFontPreferenceKey];
805 }
806
807 - (NSString *)serifFontFamily
808 {
809     return [self _stringValueForKey: WebKitSerifFontPreferenceKey];
810 }
811
812 - (void)setSerifFontFamily:(NSString *)family 
813 {
814     [self _setStringValue: family forKey: WebKitSerifFontPreferenceKey];
815 }
816
817 - (NSString *)sansSerifFontFamily
818 {
819     return [self _stringValueForKey: WebKitSansSerifFontPreferenceKey];
820 }
821
822 - (void)setSansSerifFontFamily:(NSString *)family
823 {
824     [self _setStringValue: family forKey: WebKitSansSerifFontPreferenceKey];
825 }
826
827 - (NSString *)cursiveFontFamily
828 {
829     return [self _stringValueForKey: WebKitCursiveFontPreferenceKey];
830 }
831
832 - (void)setCursiveFontFamily:(NSString *)family
833 {
834     [self _setStringValue: family forKey: WebKitCursiveFontPreferenceKey];
835 }
836
837 - (NSString *)fantasyFontFamily
838 {
839     return [self _stringValueForKey: WebKitFantasyFontPreferenceKey];
840 }
841
842 - (void)setFantasyFontFamily:(NSString *)family
843 {
844     [self _setStringValue: family forKey: WebKitFantasyFontPreferenceKey];
845 }
846
847 - (int)defaultFontSize
848 {
849     return [self _integerValueForKey: WebKitDefaultFontSizePreferenceKey];
850 }
851
852 - (void)setDefaultFontSize:(int)size
853 {
854     [self _setIntegerValue: size forKey: WebKitDefaultFontSizePreferenceKey];
855 }
856
857 - (int)defaultFixedFontSize
858 {
859     return [self _integerValueForKey: WebKitDefaultFixedFontSizePreferenceKey];
860 }
861
862 - (void)setDefaultFixedFontSize:(int)size
863 {
864     [self _setIntegerValue: size forKey: WebKitDefaultFixedFontSizePreferenceKey];
865 }
866
867 - (int)minimumFontSize
868 {
869     return [self _integerValueForKey: WebKitMinimumFontSizePreferenceKey];
870 }
871
872 - (void)setMinimumFontSize:(int)size
873 {
874     [self _setIntegerValue: size forKey: WebKitMinimumFontSizePreferenceKey];
875 }
876
877 - (int)minimumLogicalFontSize
878 {
879   return [self _integerValueForKey: WebKitMinimumLogicalFontSizePreferenceKey];
880 }
881
882 - (void)setMinimumLogicalFontSize:(int)size
883 {
884   [self _setIntegerValue: size forKey: WebKitMinimumLogicalFontSizePreferenceKey];
885 }
886
887 - (NSString *)defaultTextEncodingName
888 {
889     return [self _stringValueForKey: WebKitDefaultTextEncodingNamePreferenceKey];
890 }
891
892 - (void)setDefaultTextEncodingName:(NSString *)encoding
893 {
894     [self _setStringValue: encoding forKey: WebKitDefaultTextEncodingNamePreferenceKey];
895 }
896
897 #if !PLATFORM(IOS)
898 - (BOOL)userStyleSheetEnabled
899 {
900     return [self _boolValueForKey: WebKitUserStyleSheetEnabledPreferenceKey];
901 }
902
903 - (void)setUserStyleSheetEnabled:(BOOL)flag
904 {
905     [self _setBoolValue: flag forKey: WebKitUserStyleSheetEnabledPreferenceKey];
906 }
907
908 - (NSURL *)userStyleSheetLocation
909 {
910     NSString *locationString = [self _stringValueForKey: WebKitUserStyleSheetLocationPreferenceKey];
911     
912     if ([locationString _webkit_looksLikeAbsoluteURL]) {
913         return [NSURL _web_URLWithDataAsString:locationString];
914     } else {
915         locationString = [locationString stringByExpandingTildeInPath];
916         return [NSURL fileURLWithPath:locationString];
917     }
918 }
919
920 - (void)setUserStyleSheetLocation:(NSURL *)URL
921 {
922     NSString *locationString;
923     
924     if ([URL isFileURL]) {
925         locationString = [[URL path] _web_stringByAbbreviatingWithTildeInPath];
926     } else {
927         locationString = [URL _web_originalDataAsString];
928     }
929
930     if (!locationString)
931         locationString = @"";
932
933     [self _setStringValue:locationString forKey: WebKitUserStyleSheetLocationPreferenceKey];
934 }
935 #else
936
937 // These methods have had their implementations removed on iOS since it
938 // is wrong to have such a setting stored in preferences that, when read,
939 // is applied to all WebViews in a iOS process. Such a design might work
940 // OK for an application like Safari on Mac OS X, where the only WebViews
941 // in use display web content in a straightforward manner. However, it is
942 // wrong for iOS, where WebViews are used for various purposes, like
943 // text editing, text rendering, and displaying web content.
944 // 
945 // I have changed the user style sheet mechanism to be a per-WebView
946 // setting, rather than a per-process preference. This seems to give the
947 // behavior we want for iOS.
948
949 - (BOOL)userStyleSheetEnabled
950 {
951     return NO;
952 }
953
954 - (void)setUserStyleSheetEnabled:(BOOL)flag
955 {
956     // no-op
957 }
958
959 - (NSURL *)userStyleSheetLocation
960 {
961     return nil;
962 }
963
964 - (void)setUserStyleSheetLocation:(NSURL *)URL
965 {
966     // no-op
967 }
968 #endif // PLATFORM(IOS)
969
970 #if !PLATFORM(IOS)
971 - (BOOL)shouldPrintBackgrounds
972 {
973     return [self _boolValueForKey: WebKitShouldPrintBackgroundsPreferenceKey];
974 }
975
976 - (void)setShouldPrintBackgrounds:(BOOL)flag
977 {
978     [self _setBoolValue: flag forKey: WebKitShouldPrintBackgroundsPreferenceKey];
979 }
980 #endif
981
982 - (BOOL)isJavaEnabled
983 {
984     return [self _boolValueForKey: WebKitJavaEnabledPreferenceKey];
985 }
986
987 - (void)setJavaEnabled:(BOOL)flag
988 {
989     [self _setBoolValue: flag forKey: WebKitJavaEnabledPreferenceKey];
990 }
991
992 - (BOOL)isJavaScriptEnabled
993 {
994     return [self _boolValueForKey: WebKitJavaScriptEnabledPreferenceKey];
995 }
996
997 - (void)setJavaScriptEnabled:(BOOL)flag
998 {
999     [self _setBoolValue: flag forKey: WebKitJavaScriptEnabledPreferenceKey];
1000 }
1001
1002 - (BOOL)javaScriptCanOpenWindowsAutomatically
1003 {
1004     return [self _boolValueForKey: WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey];
1005 }
1006
1007 - (void)setJavaScriptCanOpenWindowsAutomatically:(BOOL)flag
1008 {
1009     [self _setBoolValue: flag forKey: WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey];
1010 }
1011
1012 - (BOOL)arePlugInsEnabled
1013 {
1014     return [self _boolValueForKey: WebKitPluginsEnabledPreferenceKey];
1015 }
1016
1017 - (void)setPlugInsEnabled:(BOOL)flag
1018 {
1019     [self _setBoolValue: flag forKey: WebKitPluginsEnabledPreferenceKey];
1020 }
1021
1022 - (BOOL)allowsAnimatedImages
1023 {
1024     return [self _boolValueForKey: WebKitAllowAnimatedImagesPreferenceKey];
1025 }
1026
1027 - (void)setAllowsAnimatedImages:(BOOL)flag
1028 {
1029     [self _setBoolValue: flag forKey: WebKitAllowAnimatedImagesPreferenceKey];
1030 }
1031
1032 - (BOOL)allowsAnimatedImageLooping
1033 {
1034     return [self _boolValueForKey: WebKitAllowAnimatedImageLoopingPreferenceKey];
1035 }
1036
1037 - (void)setAllowsAnimatedImageLooping: (BOOL)flag
1038 {
1039     [self _setBoolValue: flag forKey: WebKitAllowAnimatedImageLoopingPreferenceKey];
1040 }
1041
1042 - (void)setLoadsImagesAutomatically: (BOOL)flag
1043 {
1044     [self _setBoolValue: flag forKey: WebKitDisplayImagesKey];
1045 }
1046
1047 - (BOOL)loadsImagesAutomatically
1048 {
1049     return [self _boolValueForKey: WebKitDisplayImagesKey];
1050 }
1051
1052 - (void)setAutosaves:(BOOL)flag
1053 {
1054     _private->autosaves = flag;
1055 }
1056
1057 - (BOOL)autosaves
1058 {
1059     return _private->autosaves;
1060 }
1061
1062 #if !PLATFORM(IOS)
1063 - (void)setTabsToLinks:(BOOL)flag
1064 {
1065     [self _setBoolValue: flag forKey: WebKitTabToLinksPreferenceKey];
1066 }
1067
1068 - (BOOL)tabsToLinks
1069 {
1070     return [self _boolValueForKey:WebKitTabToLinksPreferenceKey];
1071 }
1072 #endif
1073
1074 - (void)setPrivateBrowsingEnabled:(BOOL)enabled
1075 {
1076     [self _updatePrivateBrowsingStateTo:enabled];
1077     [self _setBoolValue:enabled forKey:WebKitPrivateBrowsingEnabledPreferenceKey];
1078 }
1079
1080 - (BOOL)privateBrowsingEnabled
1081 {
1082     // Changes to private browsing defaults do not have effect on existing WebPreferences, and must be done through -setPrivateBrowsingEnabled.
1083     // This is needed to accurately track private browsing sessions in the process.
1084     return _private->inPrivateBrowsing;
1085 }
1086
1087 - (void)_updatePrivateBrowsingStateTo:(BOOL)enabled
1088 {
1089     if (!_private) {
1090         ASSERT(!enabled);
1091         return;
1092     }
1093
1094     if (enabled == _private->inPrivateBrowsing)
1095         return;
1096     if (enabled > _private->inPrivateBrowsing) {
1097         WebFrameNetworkingContext::ensurePrivateBrowsingSession();
1098         ++webPreferencesInstanceCountWithPrivateBrowsingEnabled;
1099     } else {
1100         ASSERT(webPreferencesInstanceCountWithPrivateBrowsingEnabled);
1101         --webPreferencesInstanceCountWithPrivateBrowsingEnabled;
1102         if (!webPreferencesInstanceCountWithPrivateBrowsingEnabled)
1103             WebFrameNetworkingContext::destroyPrivateBrowsingSession();
1104     }
1105     _private->inPrivateBrowsing = enabled;
1106 }
1107
1108 - (void)setUsesPageCache:(BOOL)usesPageCache
1109 {
1110     [self _setBoolValue:usesPageCache forKey:WebKitUsesPageCachePreferenceKey];
1111 }
1112
1113 - (BOOL)usesPageCache
1114 {
1115     return [self _boolValueForKey:WebKitUsesPageCachePreferenceKey];
1116 }
1117
1118 - (void)_postCacheModelChangedNotification
1119 {
1120 #if !PLATFORM(IOS)
1121     if (!pthread_main_np()) {
1122         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1123         return;
1124     }
1125 #endif
1126
1127     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesCacheModelChangedInternalNotification object:self userInfo:nil];
1128 }
1129
1130 - (void)setCacheModel:(WebCacheModel)cacheModel
1131 {
1132     [self _setIntegerValue:cacheModel forKey:WebKitCacheModelPreferenceKey];
1133     [self setAutomaticallyDetectsCacheModel:NO];
1134     [self _postCacheModelChangedNotification];
1135 }
1136
1137 - (WebCacheModel)cacheModel
1138 {
1139     return (WebCacheModel)[self _integerValueForKey:WebKitCacheModelPreferenceKey];
1140 }
1141
1142
1143 - (void)setSuppressesIncrementalRendering:(BOOL)suppressesIncrementalRendering
1144 {
1145     [self _setBoolValue:suppressesIncrementalRendering forKey:WebKitSuppressesIncrementalRenderingKey];
1146 }
1147
1148 - (BOOL)suppressesIncrementalRendering
1149 {
1150     return [self _boolValueForKey:WebKitSuppressesIncrementalRenderingKey];
1151 }
1152
1153 @end
1154
1155 @implementation WebPreferences (WebPrivate)
1156
1157 #if PLATFORM(IOS) && !(__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000)
1158 - (void) setWebInspectorServerEnabled:(BOOL)flag
1159 {
1160 }
1161 #endif
1162
1163 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
1164 - (void)_setAllowCompositingLayerVisualDegradation:(BOOL)flag
1165 {
1166 }
1167 #endif
1168
1169 - (BOOL)isDNSPrefetchingEnabled
1170 {
1171     return [self _boolValueForKey:WebKitDNSPrefetchingEnabledPreferenceKey];
1172 }
1173
1174 - (void)setDNSPrefetchingEnabled:(BOOL)flag
1175 {
1176     [self _setBoolValue:flag forKey:WebKitDNSPrefetchingEnabledPreferenceKey];
1177 }
1178
1179 - (BOOL)developerExtrasEnabled
1180 {
1181     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
1182     if ([defaults boolForKey:@"DisableWebKitDeveloperExtras"])
1183         return NO;
1184 #ifdef NDEBUG
1185     if ([defaults boolForKey:@"WebKitDeveloperExtras"] || [defaults boolForKey:@"IncludeDebugMenu"])
1186         return YES;
1187     return [self _boolValueForKey:WebKitDeveloperExtrasEnabledPreferenceKey];
1188 #else
1189     return YES; // always enable in debug builds
1190 #endif
1191 }
1192
1193 - (WebKitJavaScriptRuntimeFlags)javaScriptRuntimeFlags
1194 {
1195     return static_cast<WebKitJavaScriptRuntimeFlags>([self _unsignedIntValueForKey:WebKitJavaScriptRuntimeFlagsPreferenceKey]);
1196 }
1197
1198 - (void)setJavaScriptRuntimeFlags:(WebKitJavaScriptRuntimeFlags)flags
1199 {
1200     [self _setUnsignedIntValue:flags forKey:WebKitJavaScriptRuntimeFlagsPreferenceKey];
1201 }
1202
1203 - (void)setDeveloperExtrasEnabled:(BOOL)flag
1204 {
1205     [self _setBoolValue:flag forKey:WebKitDeveloperExtrasEnabledPreferenceKey];
1206 }
1207
1208 - (BOOL)authorAndUserStylesEnabled
1209 {
1210     return [self _boolValueForKey:WebKitAuthorAndUserStylesEnabledPreferenceKey];
1211 }
1212
1213 - (void)setAuthorAndUserStylesEnabled:(BOOL)flag
1214 {
1215     [self _setBoolValue:flag forKey:WebKitAuthorAndUserStylesEnabledPreferenceKey];
1216 }
1217
1218 // FIXME: applicationChromeMode is no longer needed by ToT, but is still used in Safari 8.
1219 - (BOOL)applicationChromeModeEnabled
1220 {
1221     return NO;
1222 }
1223
1224 - (void)setApplicationChromeModeEnabled:(BOOL)flag
1225 {
1226 }
1227
1228 - (BOOL)domTimersThrottlingEnabled
1229 {
1230     return [self _boolValueForKey:WebKitDOMTimersThrottlingEnabledPreferenceKey];
1231 }
1232
1233 - (void)setDOMTimersThrottlingEnabled:(BOOL)flag
1234 {
1235     [self _setBoolValue:flag forKey:WebKitDOMTimersThrottlingEnabledPreferenceKey];
1236 }
1237
1238 - (BOOL)webArchiveDebugModeEnabled
1239 {
1240     return [self _boolValueForKey:WebKitWebArchiveDebugModeEnabledPreferenceKey];
1241 }
1242
1243 - (void)setWebArchiveDebugModeEnabled:(BOOL)flag
1244 {
1245     [self _setBoolValue:flag forKey:WebKitWebArchiveDebugModeEnabledPreferenceKey];
1246 }
1247
1248 - (BOOL)localFileContentSniffingEnabled
1249 {
1250     return [self _boolValueForKey:WebKitLocalFileContentSniffingEnabledPreferenceKey];
1251 }
1252
1253 - (void)setLocalFileContentSniffingEnabled:(BOOL)flag
1254 {
1255     [self _setBoolValue:flag forKey:WebKitLocalFileContentSniffingEnabledPreferenceKey];
1256 }
1257
1258 - (BOOL)offlineWebApplicationCacheEnabled
1259 {
1260     return [self _boolValueForKey:WebKitOfflineWebApplicationCacheEnabledPreferenceKey];
1261 }
1262
1263 - (void)setOfflineWebApplicationCacheEnabled:(BOOL)flag
1264 {
1265     [self _setBoolValue:flag forKey:WebKitOfflineWebApplicationCacheEnabledPreferenceKey];
1266 }
1267
1268 - (BOOL)zoomsTextOnly
1269 {
1270     return [self _boolValueForKey:WebKitZoomsTextOnlyPreferenceKey];
1271 }
1272
1273 - (void)setZoomsTextOnly:(BOOL)flag
1274 {
1275     [self _setBoolValue:flag forKey:WebKitZoomsTextOnlyPreferenceKey];
1276 }
1277
1278 - (BOOL)javaScriptCanAccessClipboard
1279 {
1280     return [self _boolValueForKey:WebKitJavaScriptCanAccessClipboardPreferenceKey];
1281 }
1282
1283 - (void)setJavaScriptCanAccessClipboard:(BOOL)flag
1284 {
1285     [self _setBoolValue:flag forKey:WebKitJavaScriptCanAccessClipboardPreferenceKey];
1286 }
1287
1288 - (BOOL)isXSSAuditorEnabled
1289 {
1290     return [self _boolValueForKey:WebKitXSSAuditorEnabledPreferenceKey];
1291 }
1292
1293 - (void)setXSSAuditorEnabled:(BOOL)flag
1294 {
1295     [self _setBoolValue:flag forKey:WebKitXSSAuditorEnabledPreferenceKey];
1296 }
1297
1298 #if !PLATFORM(IOS)
1299 - (BOOL)respectStandardStyleKeyEquivalents
1300 {
1301     return [self _boolValueForKey:WebKitRespectStandardStyleKeyEquivalentsPreferenceKey];
1302 }
1303
1304 - (void)setRespectStandardStyleKeyEquivalents:(BOOL)flag
1305 {
1306     [self _setBoolValue:flag forKey:WebKitRespectStandardStyleKeyEquivalentsPreferenceKey];
1307 }
1308
1309 - (BOOL)showsURLsInToolTips
1310 {
1311     return [self _boolValueForKey:WebKitShowsURLsInToolTipsPreferenceKey];
1312 }
1313
1314 - (void)setShowsURLsInToolTips:(BOOL)flag
1315 {
1316     [self _setBoolValue:flag forKey:WebKitShowsURLsInToolTipsPreferenceKey];
1317 }
1318
1319 - (BOOL)showsToolTipOverTruncatedText
1320 {
1321     return [self _boolValueForKey:WebKitShowsToolTipOverTruncatedTextPreferenceKey];
1322 }
1323
1324 - (void)setShowsToolTipOverTruncatedText:(BOOL)flag
1325 {
1326     [self _setBoolValue:flag forKey:WebKitShowsToolTipOverTruncatedTextPreferenceKey];
1327 }
1328
1329 - (BOOL)textAreasAreResizable
1330 {
1331     return [self _boolValueForKey: WebKitTextAreasAreResizablePreferenceKey];
1332 }
1333
1334 - (void)setTextAreasAreResizable:(BOOL)flag
1335 {
1336     [self _setBoolValue: flag forKey: WebKitTextAreasAreResizablePreferenceKey];
1337 }
1338 #endif // !PLATFORM(IOS)
1339
1340 - (BOOL)shrinksStandaloneImagesToFit
1341 {
1342     return [self _boolValueForKey:WebKitShrinksStandaloneImagesToFitPreferenceKey];
1343 }
1344
1345 - (void)setShrinksStandaloneImagesToFit:(BOOL)flag
1346 {
1347     [self _setBoolValue:flag forKey:WebKitShrinksStandaloneImagesToFitPreferenceKey];
1348 }
1349
1350 - (BOOL)automaticallyDetectsCacheModel
1351 {
1352     return _private->automaticallyDetectsCacheModel;
1353 }
1354
1355 - (void)setAutomaticallyDetectsCacheModel:(BOOL)automaticallyDetectsCacheModel
1356 {
1357     _private->automaticallyDetectsCacheModel = automaticallyDetectsCacheModel;
1358 }
1359
1360 - (BOOL)usesEncodingDetector
1361 {
1362     return [self _boolValueForKey: WebKitUsesEncodingDetectorPreferenceKey];
1363 }
1364
1365 - (void)setUsesEncodingDetector:(BOOL)flag
1366 {
1367     [self _setBoolValue: flag forKey: WebKitUsesEncodingDetectorPreferenceKey];
1368 }
1369
1370 - (BOOL)isWebSecurityEnabled
1371 {
1372     return [self _boolValueForKey: WebKitWebSecurityEnabledPreferenceKey];
1373 }
1374
1375 - (void)setWebSecurityEnabled:(BOOL)flag
1376 {
1377     [self _setBoolValue: flag forKey: WebKitWebSecurityEnabledPreferenceKey];
1378 }
1379
1380 - (BOOL)allowUniversalAccessFromFileURLs
1381 {
1382     return [self _boolValueForKey: WebKitAllowUniversalAccessFromFileURLsPreferenceKey];
1383 }
1384
1385 - (void)setAllowUniversalAccessFromFileURLs:(BOOL)flag
1386 {
1387     [self _setBoolValue: flag forKey: WebKitAllowUniversalAccessFromFileURLsPreferenceKey];
1388 }
1389
1390 - (BOOL)allowFileAccessFromFileURLs
1391 {
1392     return [self _boolValueForKey: WebKitAllowFileAccessFromFileURLsPreferenceKey];
1393 }
1394
1395 - (void)setAllowFileAccessFromFileURLs:(BOOL)flag
1396 {
1397     [self _setBoolValue: flag forKey: WebKitAllowFileAccessFromFileURLsPreferenceKey];
1398 }
1399
1400 - (NSTimeInterval)_backForwardCacheExpirationInterval
1401 {
1402     return (NSTimeInterval)[self _floatValueForKey:WebKitBackForwardCacheExpirationIntervalKey];
1403 }
1404
1405 #if PLATFORM(IOS)
1406 - (BOOL)_standalone
1407 {
1408     return [self _boolValueForKey:WebKitStandalonePreferenceKey];
1409 }
1410
1411 - (void)_setStandalone:(BOOL)flag
1412 {
1413     [self _setBoolValue:flag forKey:WebKitStandalonePreferenceKey];
1414 }
1415
1416 - (void)_setTelephoneNumberParsingEnabled:(BOOL)flag
1417 {
1418     [self _setBoolValue:flag forKey:WebKitTelephoneParsingEnabledPreferenceKey];
1419 }
1420
1421 - (BOOL)_telephoneNumberParsingEnabled
1422 {
1423     return [self _boolValueForKey:WebKitTelephoneParsingEnabledPreferenceKey];
1424 }
1425 #endif
1426
1427 #if ENABLE(IOS_TEXT_AUTOSIZING)
1428 - (void)_setMinimumZoomFontSize:(float)size
1429 {
1430     [self _setFloatValue:size forKey:WebKitMinimumZoomFontSizePreferenceKey];
1431 }
1432
1433 - (float)_minimumZoomFontSize
1434 {
1435     return [self _floatValueForKey:WebKitMinimumZoomFontSizePreferenceKey];
1436 }
1437 #endif
1438
1439 #if PLATFORM(IOS)
1440 - (void)_setLayoutInterval:(int)l
1441 {
1442     [self _setIntegerValue:l forKey:WebKitLayoutIntervalPreferenceKey];
1443 }
1444
1445 - (int)_layoutInterval
1446 {
1447     return [self _integerValueForKey:WebKitLayoutIntervalPreferenceKey];
1448 }
1449
1450 - (void)_setMaxParseDuration:(float)d
1451 {
1452     [self _setFloatValue:d forKey:WebKitMaxParseDurationPreferenceKey];
1453 }
1454
1455 - (float)_maxParseDuration
1456 {
1457     return [self _floatValueForKey:WebKitMaxParseDurationPreferenceKey];
1458 }
1459
1460 - (void)_setAllowMultiElementImplicitFormSubmission:(BOOL)flag
1461 {
1462     [self _setBoolValue:flag forKey:WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey];
1463 }
1464
1465 - (BOOL)_allowMultiElementImplicitFormSubmission
1466 {
1467     return [self _boolValueForKey:WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey];
1468 }
1469
1470 - (void)_setAlwaysRequestGeolocationPermission:(BOOL)flag
1471 {
1472     [self _setBoolValue:flag forKey:WebKitAlwaysRequestGeolocationPermissionPreferenceKey];
1473 }
1474
1475 - (BOOL)_alwaysRequestGeolocationPermission
1476 {
1477     return [self _boolValueForKey:WebKitAlwaysRequestGeolocationPermissionPreferenceKey];
1478 }
1479
1480 - (void)_setAlwaysUseAcceleratedOverflowScroll:(BOOL)flag
1481 {
1482     [self _setBoolValue:flag forKey:WebKitAlwaysUseAcceleratedOverflowScrollPreferenceKey];
1483 }
1484
1485 - (BOOL)_alwaysUseAcceleratedOverflowScroll
1486 {
1487     return [self _boolValueForKey:WebKitAlwaysUseAcceleratedOverflowScrollPreferenceKey];
1488 }
1489
1490 - (void)_setInterpolationQuality:(int)quality
1491 {
1492     [self _setIntegerValue:quality forKey:WebKitInterpolationQualityPreferenceKey];
1493 }
1494
1495 - (int)_interpolationQuality
1496 {
1497     return [self _integerValueForKey:WebKitInterpolationQualityPreferenceKey];
1498 }
1499
1500 - (BOOL)_allowPasswordEcho
1501 {
1502     return [self _boolValueForKey:WebKitPasswordEchoEnabledPreferenceKey];
1503 }
1504
1505 - (float)_passwordEchoDuration
1506 {
1507     return [self _floatValueForKey:WebKitPasswordEchoDurationPreferenceKey];
1508 }
1509
1510 #endif // PLATFORM(IOS)
1511
1512 #if !PLATFORM(IOS)
1513 - (float)PDFScaleFactor
1514 {
1515     return [self _floatValueForKey:WebKitPDFScaleFactorPreferenceKey];
1516 }
1517
1518 - (void)setPDFScaleFactor:(float)factor
1519 {
1520     [self _setFloatValue:factor forKey:WebKitPDFScaleFactorPreferenceKey];
1521 }
1522 #endif
1523
1524 - (int64_t)applicationCacheTotalQuota
1525 {
1526     return [self _longLongValueForKey:WebKitApplicationCacheTotalQuota];
1527 }
1528
1529 - (void)setApplicationCacheTotalQuota:(int64_t)quota
1530 {
1531     [self _setLongLongValue:quota forKey:WebKitApplicationCacheTotalQuota];
1532
1533     // Application Cache Preferences are stored on the global cache storage manager, not in Settings.
1534     [WebApplicationCache setMaximumSize:quota];
1535 }
1536
1537 - (int64_t)applicationCacheDefaultOriginQuota
1538 {
1539     return [self _longLongValueForKey:WebKitApplicationCacheDefaultOriginQuota];
1540 }
1541
1542 - (void)setApplicationCacheDefaultOriginQuota:(int64_t)quota
1543 {
1544     [self _setLongLongValue:quota forKey:WebKitApplicationCacheDefaultOriginQuota];
1545 }
1546
1547 #if !PLATFORM(IOS)
1548 - (PDFDisplayMode)PDFDisplayMode
1549 {
1550     PDFDisplayMode value = [self _integerValueForKey:WebKitPDFDisplayModePreferenceKey];
1551     if (value != kPDFDisplaySinglePage && value != kPDFDisplaySinglePageContinuous && value != kPDFDisplayTwoUp && value != kPDFDisplayTwoUpContinuous) {
1552         // protect against new modes from future versions of OS X stored in defaults
1553         value = kPDFDisplaySinglePageContinuous;
1554     }
1555     return value;
1556 }
1557
1558 - (void)setPDFDisplayMode:(PDFDisplayMode)mode
1559 {
1560     [self _setIntegerValue:mode forKey:WebKitPDFDisplayModePreferenceKey];
1561 }
1562 #endif
1563
1564 - (WebKitEditableLinkBehavior)editableLinkBehavior
1565 {
1566     WebKitEditableLinkBehavior value = static_cast<WebKitEditableLinkBehavior> ([self _integerValueForKey:WebKitEditableLinkBehaviorPreferenceKey]);
1567     if (value != WebKitEditableLinkDefaultBehavior &&
1568         value != WebKitEditableLinkAlwaysLive &&
1569         value != WebKitEditableLinkNeverLive &&
1570         value != WebKitEditableLinkOnlyLiveWithShiftKey &&
1571         value != WebKitEditableLinkLiveWhenNotFocused) {
1572         // ensure that a valid result is returned
1573         value = WebKitEditableLinkDefaultBehavior;
1574     }
1575     
1576     return value;
1577 }
1578
1579 - (void)setEditableLinkBehavior:(WebKitEditableLinkBehavior)behavior
1580 {
1581     [self _setIntegerValue:behavior forKey:WebKitEditableLinkBehaviorPreferenceKey];
1582 }
1583
1584 - (WebTextDirectionSubmenuInclusionBehavior)textDirectionSubmenuInclusionBehavior
1585 {
1586     WebTextDirectionSubmenuInclusionBehavior value = static_cast<WebTextDirectionSubmenuInclusionBehavior>([self _integerValueForKey:WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey]);
1587     if (value != WebTextDirectionSubmenuNeverIncluded &&
1588         value != WebTextDirectionSubmenuAutomaticallyIncluded &&
1589         value != WebTextDirectionSubmenuAlwaysIncluded) {
1590         // Ensure that a valid result is returned.
1591         value = WebTextDirectionSubmenuNeverIncluded;
1592     }
1593     return value;
1594 }
1595
1596 - (void)setTextDirectionSubmenuInclusionBehavior:(WebTextDirectionSubmenuInclusionBehavior)behavior
1597 {
1598     [self _setIntegerValue:behavior forKey:WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey];
1599 }
1600
1601 - (BOOL)_useSiteSpecificSpoofing
1602 {
1603     return [self _boolValueForKey:WebKitUseSiteSpecificSpoofingPreferenceKey];
1604 }
1605
1606 - (void)_setUseSiteSpecificSpoofing:(BOOL)newValue
1607 {
1608     [self _setBoolValue:newValue forKey:WebKitUseSiteSpecificSpoofingPreferenceKey];
1609 }
1610
1611 - (BOOL)databasesEnabled
1612 {
1613     return [self _boolValueForKey:WebKitDatabasesEnabledPreferenceKey];
1614 }
1615
1616 - (void)setDatabasesEnabled:(BOOL)databasesEnabled
1617 {
1618     [self _setBoolValue:databasesEnabled forKey:WebKitDatabasesEnabledPreferenceKey];
1619 }
1620
1621 #if PLATFORM(IOS)
1622 - (BOOL)storageTrackerEnabled
1623 {
1624     return [self _boolValueForKey:WebKitStorageTrackerEnabledPreferenceKey];
1625 }
1626
1627 - (void)setStorageTrackerEnabled:(BOOL)storageTrackerEnabled
1628 {
1629     [self _setBoolValue:storageTrackerEnabled forKey:WebKitStorageTrackerEnabledPreferenceKey];
1630 }
1631 #endif
1632
1633 - (BOOL)localStorageEnabled
1634 {
1635     return [self _boolValueForKey:WebKitLocalStorageEnabledPreferenceKey];
1636 }
1637
1638 - (void)setLocalStorageEnabled:(BOOL)localStorageEnabled
1639 {
1640     [self _setBoolValue:localStorageEnabled forKey:WebKitLocalStorageEnabledPreferenceKey];
1641 }
1642
1643 - (BOOL)experimentalNotificationsEnabled
1644 {
1645     return [self _boolValueForKey:WebKitExperimentalNotificationsEnabledPreferenceKey];
1646 }
1647
1648 - (void)setExperimentalNotificationsEnabled:(BOOL)experimentalNotificationsEnabled
1649 {
1650     [self _setBoolValue:experimentalNotificationsEnabled forKey:WebKitExperimentalNotificationsEnabledPreferenceKey];
1651 }
1652
1653 + (WebPreferences *)_getInstanceForIdentifier:(NSString *)ident
1654 {
1655     LOG(Encoding, "requesting for %@\n", ident);
1656
1657     if (!ident)
1658         return _standardPreferences;
1659     
1660     WebPreferences *instance = [webPreferencesInstances objectForKey:[self _concatenateKeyWithIBCreatorID:ident]];
1661
1662     return instance;
1663 }
1664
1665 + (void)_setInstance:(WebPreferences *)instance forIdentifier:(NSString *)ident
1666 {
1667     if (!webPreferencesInstances)
1668         webPreferencesInstances = [[NSMutableDictionary alloc] init];
1669     if (ident) {
1670         [webPreferencesInstances setObject:instance forKey:[self _concatenateKeyWithIBCreatorID:ident]];
1671         LOG(Encoding, "recording %p for %@\n", instance, [self _concatenateKeyWithIBCreatorID:ident]);
1672     }
1673 }
1674
1675 + (void)_checkLastReferenceForIdentifier:(id)identifier
1676 {
1677     // FIXME: This won't work at all under garbage collection because retainCount returns a constant.
1678     // We may need to change WebPreferences API so there's an explicit way to end the lifetime of one.
1679     WebPreferences *instance = [webPreferencesInstances objectForKey:identifier];
1680     if ([instance retainCount] == 1)
1681         [webPreferencesInstances removeObjectForKey:identifier];
1682 }
1683
1684 + (void)_removeReferenceForIdentifier:(NSString *)ident
1685 {
1686     if (ident)
1687         [self performSelector:@selector(_checkLastReferenceForIdentifier:) withObject:[self _concatenateKeyWithIBCreatorID:ident] afterDelay:0.1];
1688 }
1689
1690 - (void)_postPreferencesChangedNotification
1691 {
1692 #if !PLATFORM(IOS)
1693     if (!pthread_main_np()) {
1694         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1695         return;
1696     }
1697 #endif
1698
1699     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedInternalNotification object:self userInfo:nil];
1700     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedNotification object:self userInfo:nil];
1701 }
1702
1703 - (void)_postPreferencesChangedAPINotification
1704 {
1705     if (!pthread_main_np()) {
1706         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1707         return;
1708     }
1709
1710     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedNotification object:self userInfo:nil];
1711 }
1712
1713 + (CFStringEncoding)_systemCFStringEncoding
1714 {
1715     return WKGetWebDefaultCFStringEncoding();
1716 }
1717
1718 + (void)_setInitialDefaultTextEncodingToSystemEncoding
1719 {
1720     [[NSUserDefaults standardUserDefaults] registerDefaults:
1721         [NSDictionary dictionaryWithObject:defaultTextEncodingNameForSystemLanguage() forKey:WebKitDefaultTextEncodingNamePreferenceKey]];
1722 }
1723
1724 static NSString *classIBCreatorID = nil;
1725
1726 + (void)_setIBCreatorID:(NSString *)string
1727 {
1728     NSString *old = classIBCreatorID;
1729     classIBCreatorID = [string copy];
1730     [old release];
1731 }
1732
1733 + (void)_switchNetworkLoaderToNewTestingSession
1734 {
1735     NetworkStorageSession::switchToNewTestingSession();
1736 }
1737
1738 + (void)_clearNetworkLoaderSession
1739 {
1740     WebCore::deleteAllCookies(NetworkStorageSession::defaultStorageSession());
1741 }
1742
1743 + (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy
1744 {
1745     WKSetHTTPCookieAcceptPolicy(NetworkStorageSession::defaultStorageSession().cookieStorage().get(), policy);
1746 }
1747
1748 - (BOOL)isDOMPasteAllowed
1749 {
1750     return [self _boolValueForKey:WebKitDOMPasteAllowedPreferenceKey];
1751 }
1752
1753 - (void)setDOMPasteAllowed:(BOOL)DOMPasteAllowed
1754 {
1755     [self _setBoolValue:DOMPasteAllowed forKey:WebKitDOMPasteAllowedPreferenceKey];
1756 }
1757
1758 - (NSString *)_localStorageDatabasePath
1759 {
1760     return [[self _stringValueForKey:WebKitLocalStorageDatabasePathPreferenceKey] stringByStandardizingPath];
1761 }
1762
1763 - (void)_setLocalStorageDatabasePath:(NSString *)path
1764 {
1765     [self _setStringValue:[path stringByStandardizingPath] forKey:WebKitLocalStorageDatabasePathPreferenceKey];
1766 }
1767
1768 - (NSString *)_ftpDirectoryTemplatePath
1769 {
1770     return [[self _stringValueForKey:WebKitFTPDirectoryTemplatePath] stringByStandardizingPath];
1771 }
1772
1773 - (void)_setFTPDirectoryTemplatePath:(NSString *)path
1774 {
1775     [self _setStringValue:[path stringByStandardizingPath] forKey:WebKitFTPDirectoryTemplatePath];
1776 }
1777
1778 - (BOOL)_forceFTPDirectoryListings
1779 {
1780     return [self _boolValueForKey:WebKitForceFTPDirectoryListings];
1781 }
1782
1783 - (void)_setForceFTPDirectoryListings:(BOOL)force
1784 {
1785     [self _setBoolValue:force forKey:WebKitForceFTPDirectoryListings];
1786 }
1787
1788 - (BOOL)acceleratedDrawingEnabled
1789 {
1790     return [self _boolValueForKey:WebKitAcceleratedDrawingEnabledPreferenceKey];
1791 }
1792
1793 - (void)setAcceleratedDrawingEnabled:(BOOL)enabled
1794 {
1795     [self _setBoolValue:enabled forKey:WebKitAcceleratedDrawingEnabledPreferenceKey];
1796 }
1797
1798 - (BOOL)canvasUsesAcceleratedDrawing
1799 {
1800     return [self _boolValueForKey:WebKitCanvasUsesAcceleratedDrawingPreferenceKey];
1801 }
1802
1803 - (void)setCanvasUsesAcceleratedDrawing:(BOOL)enabled
1804 {
1805     [self _setBoolValue:enabled forKey:WebKitCanvasUsesAcceleratedDrawingPreferenceKey];
1806 }
1807
1808 - (BOOL)acceleratedCompositingEnabled
1809 {
1810     return [self _boolValueForKey:WebKitAcceleratedCompositingEnabledPreferenceKey];
1811 }
1812
1813 - (void)setAcceleratedCompositingEnabled:(BOOL)enabled
1814 {
1815     [self _setBoolValue:enabled forKey:WebKitAcceleratedCompositingEnabledPreferenceKey];
1816 }
1817
1818 - (BOOL)cssRegionsEnabled
1819 {
1820     return [self _boolValueForKey:WebKitCSSRegionsEnabledPreferenceKey];
1821 }
1822
1823 - (void)setCSSRegionsEnabled:(BOOL)enabled
1824 {
1825     [self _setBoolValue:enabled forKey:WebKitCSSRegionsEnabledPreferenceKey];
1826 }
1827
1828 - (BOOL)cssCompositingEnabled
1829 {
1830     return [self _boolValueForKey:WebKitCSSCompositingEnabledPreferenceKey];
1831 }
1832
1833 - (void)setCSSCompositingEnabled:(BOOL)enabled
1834 {
1835     [self _setBoolValue:enabled forKey:WebKitCSSCompositingEnabledPreferenceKey];
1836 }
1837
1838 - (BOOL)showDebugBorders
1839 {
1840     return [self _boolValueForKey:WebKitShowDebugBordersPreferenceKey];
1841 }
1842
1843 - (void)setShowDebugBorders:(BOOL)enabled
1844 {
1845     [self _setBoolValue:enabled forKey:WebKitShowDebugBordersPreferenceKey];
1846 }
1847
1848 - (BOOL)simpleLineLayoutDebugBordersEnabled
1849 {
1850     return [self _boolValueForKey:WebKitSimpleLineLayoutDebugBordersEnabledPreferenceKey];
1851 }
1852
1853 - (void)setSimpleLineLayoutDebugBordersEnabled:(BOOL)enabled
1854 {
1855     [self _setBoolValue:enabled forKey:WebKitSimpleLineLayoutDebugBordersEnabledPreferenceKey];
1856 }
1857
1858 - (BOOL)showRepaintCounter
1859 {
1860     return [self _boolValueForKey:WebKitShowRepaintCounterPreferenceKey];
1861 }
1862
1863 - (void)setShowRepaintCounter:(BOOL)enabled
1864 {
1865     [self _setBoolValue:enabled forKey:WebKitShowRepaintCounterPreferenceKey];
1866 }
1867
1868 - (BOOL)webAudioEnabled
1869 {
1870     return [self _boolValueForKey:WebKitWebAudioEnabledPreferenceKey];
1871 }
1872
1873 - (void)setWebAudioEnabled:(BOOL)enabled
1874 {
1875     [self _setBoolValue:enabled forKey:WebKitWebAudioEnabledPreferenceKey];
1876 }
1877
1878 - (BOOL)subpixelCSSOMElementMetricsEnabled
1879 {
1880     return [self _boolValueForKey:WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey];
1881 }
1882
1883 - (void)setSubpixelCSSOMElementMetricsEnabled:(BOOL)enabled
1884 {
1885     [self _setBoolValue:enabled forKey:WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey];
1886 }
1887
1888 - (BOOL)webGLEnabled
1889 {
1890     return [self _boolValueForKey:WebKitWebGLEnabledPreferenceKey];
1891 }
1892
1893 - (void)setWebGLEnabled:(BOOL)enabled
1894 {
1895     [self _setBoolValue:enabled forKey:WebKitWebGLEnabledPreferenceKey];
1896 }
1897
1898 - (BOOL)forceSoftwareWebGLRendering
1899 {
1900     return [self _boolValueForKey:WebKitForceSoftwareWebGLRenderingPreferenceKey];
1901 }
1902
1903 - (void)setForceSoftwareWebGLRendering:(BOOL)forced
1904 {
1905     [self _setBoolValue:forced forKey:WebKitForceSoftwareWebGLRenderingPreferenceKey];
1906 }
1907
1908 - (BOOL)accelerated2dCanvasEnabled
1909 {
1910     return [self _boolValueForKey:WebKitAccelerated2dCanvasEnabledPreferenceKey];
1911 }
1912
1913 - (void)setAccelerated2dCanvasEnabled:(BOOL)enabled
1914 {
1915     [self _setBoolValue:enabled forKey:WebKitAccelerated2dCanvasEnabledPreferenceKey];
1916 }
1917
1918 - (void)setDiskImageCacheEnabled:(BOOL)enabled
1919 {
1920     // Staging. Can be removed once there are no more callers.
1921 }
1922
1923 - (BOOL)isFrameFlatteningEnabled
1924 {
1925     return [self _boolValueForKey:WebKitFrameFlatteningEnabledPreferenceKey];
1926 }
1927
1928 - (void)setFrameFlatteningEnabled:(BOOL)flag
1929 {
1930     [self _setBoolValue:flag forKey:WebKitFrameFlatteningEnabledPreferenceKey];
1931 }
1932
1933 - (BOOL)isSpatialNavigationEnabled
1934 {
1935     return [self _boolValueForKey:WebKitSpatialNavigationEnabledPreferenceKey];
1936 }
1937
1938 - (void)setSpatialNavigationEnabled:(BOOL)flag
1939 {
1940     [self _setBoolValue:flag forKey:WebKitSpatialNavigationEnabledPreferenceKey];
1941 }
1942
1943 - (BOOL)paginateDuringLayoutEnabled
1944 {
1945     return [self _boolValueForKey:WebKitPaginateDuringLayoutEnabledPreferenceKey];
1946 }
1947
1948 - (void)setPaginateDuringLayoutEnabled:(BOOL)flag
1949 {
1950     [self _setBoolValue:flag forKey:WebKitPaginateDuringLayoutEnabledPreferenceKey];
1951 }
1952
1953 - (BOOL)hyperlinkAuditingEnabled
1954 {
1955     return [self _boolValueForKey:WebKitHyperlinkAuditingEnabledPreferenceKey];
1956 }
1957
1958 - (void)setHyperlinkAuditingEnabled:(BOOL)flag
1959 {
1960     [self _setBoolValue:flag forKey:WebKitHyperlinkAuditingEnabledPreferenceKey];
1961 }
1962
1963 - (BOOL)usePreHTML5ParserQuirks
1964 {
1965     return [self _boolValueForKey:WebKitUsePreHTML5ParserQuirksKey];
1966 }
1967
1968 - (void)setUsePreHTML5ParserQuirks:(BOOL)flag
1969 {
1970     [self _setBoolValue:flag forKey:WebKitUsePreHTML5ParserQuirksKey];
1971 }
1972
1973 - (void)didRemoveFromWebView
1974 {
1975     ASSERT(_private->numWebViews);
1976     if (--_private->numWebViews == 0)
1977         [[NSNotificationCenter defaultCenter]
1978             postNotificationName:WebPreferencesRemovedNotification
1979                           object:self
1980                         userInfo:nil];
1981 }
1982
1983 - (void)willAddToWebView
1984 {
1985     ++_private->numWebViews;
1986 }
1987
1988 - (void)_setPreferenceForTestWithValue:(NSString *)value forKey:(NSString *)key
1989 {
1990     [self _setStringValue:value forKey:key];
1991 }
1992
1993 - (void)setFullScreenEnabled:(BOOL)flag
1994 {
1995     [self _setBoolValue:flag forKey:WebKitFullScreenEnabledPreferenceKey];
1996 }
1997
1998 - (BOOL)fullScreenEnabled
1999 {
2000     return [self _boolValueForKey:WebKitFullScreenEnabledPreferenceKey];
2001 }
2002
2003 - (void)setAsynchronousSpellCheckingEnabled:(BOOL)flag
2004 {
2005     [self _setBoolValue:flag forKey:WebKitAsynchronousSpellCheckingEnabledPreferenceKey];
2006 }
2007
2008 - (BOOL)asynchronousSpellCheckingEnabled
2009 {
2010     return [self _boolValueForKey:WebKitAsynchronousSpellCheckingEnabledPreferenceKey];
2011 }
2012
2013 + (void)setWebKitLinkTimeVersion:(int)version
2014 {
2015     setWebKitLinkTimeVersion(version);
2016 }
2017
2018 - (void)setLoadsSiteIconsIgnoringImageLoadingPreference: (BOOL)flag
2019 {
2020     [self _setBoolValue: flag forKey: WebKitLoadSiteIconsKey];
2021 }
2022
2023 - (BOOL)loadsSiteIconsIgnoringImageLoadingPreference
2024 {
2025     return [self _boolValueForKey: WebKitLoadSiteIconsKey];
2026 }
2027
2028 - (void)setAVFoundationEnabled:(BOOL)flag
2029 {
2030     [self _setBoolValue:flag forKey:WebKitAVFoundationEnabledKey];
2031 }
2032
2033 - (BOOL)isAVFoundationEnabled
2034 {
2035     return [self _boolValueForKey:WebKitAVFoundationEnabledKey];
2036 }
2037
2038 - (void)setQTKitEnabled:(BOOL)flag
2039 {
2040     [self _setBoolValue:flag forKey:WebKitQTKitEnabledPreferenceKey];
2041 }
2042
2043 - (BOOL)isQTKitEnabled
2044 {
2045     return [self _boolValueForKey:WebKitQTKitEnabledPreferenceKey];
2046 }
2047
2048 - (void)setVideoPluginProxyEnabled:(BOOL)flag
2049 {
2050     // No-op, left for SPI compatibility.
2051 }
2052
2053 - (BOOL)isVideoPluginProxyEnabled
2054 {
2055     return NO;
2056 }
2057
2058 - (void)setHixie76WebSocketProtocolEnabled:(BOOL)flag
2059 {
2060 }
2061
2062 - (BOOL)isHixie76WebSocketProtocolEnabled
2063 {
2064     return false;
2065 }
2066
2067 - (BOOL)isInheritURIQueryComponentEnabled
2068 {
2069     return [self _boolValueForKey: WebKitEnableInheritURIQueryComponentPreferenceKey];
2070 }
2071
2072 - (void)setEnableInheritURIQueryComponent:(BOOL)flag
2073 {
2074     [self _setBoolValue:flag forKey: WebKitEnableInheritURIQueryComponentPreferenceKey];
2075 }
2076
2077 #if PLATFORM(IOS)
2078 - (BOOL)mediaPlaybackAllowsAirPlay
2079 {
2080     return [self _boolValueForKey:WebKitMediaPlaybackAllowsAirPlayPreferenceKey];
2081 }
2082
2083 - (void)setMediaPlaybackAllowsAirPlay:(BOOL)flag
2084 {
2085     [self _setBoolValue:flag forKey:WebKitMediaPlaybackAllowsAirPlayPreferenceKey];
2086 }
2087
2088 - (unsigned)audioSessionCategoryOverride
2089 {
2090     return [self _unsignedIntValueForKey:WebKitAudioSessionCategoryOverride];
2091 }
2092
2093 - (void)setAudioSessionCategoryOverride:(unsigned)override
2094 {
2095     if (override > AudioSession::AudioProcessing) {
2096         // Clients are passing us OSTypes values from AudioToolbox/AudioSession.h,
2097         // which need to be translated into AudioSession::CategoryType:
2098         switch (override) {
2099         case kAudioSessionCategory_AmbientSound:
2100             override = AudioSession::AmbientSound;
2101             break;
2102         case kAudioSessionCategory_SoloAmbientSound:
2103             override = AudioSession::SoloAmbientSound;
2104             break;
2105         case kAudioSessionCategory_MediaPlayback:
2106             override = AudioSession::MediaPlayback;
2107             break;
2108         case kAudioSessionCategory_RecordAudio:
2109             override = AudioSession::RecordAudio;
2110             break;
2111         case kAudioSessionCategory_PlayAndRecord:
2112             override = AudioSession::PlayAndRecord;
2113             break;
2114         case kAudioSessionCategory_AudioProcessing:
2115             override = AudioSession::AudioProcessing;
2116             break;
2117         default:
2118             override = AudioSession::None;
2119             break;
2120         }
2121     }
2122
2123     [self _setUnsignedIntValue:override forKey:WebKitAudioSessionCategoryOverride];
2124 }
2125
2126 - (BOOL)avKitEnabled
2127 {
2128     return [self _boolValueForKey:WebKitAVKitEnabled];
2129 }
2130
2131 - (void)setAVKitEnabled:(bool)flag
2132 {
2133 #if HAVE(AVKIT)
2134     [self _setBoolValue:flag forKey:WebKitAVKitEnabled];
2135 #endif
2136 }
2137
2138 - (BOOL)networkDataUsageTrackingEnabled
2139 {
2140     return [self _boolValueForKey:WebKitNetworkDataUsageTrackingEnabledPreferenceKey];
2141 }
2142
2143 - (void)setNetworkDataUsageTrackingEnabled:(bool)trackingEnabled
2144 {
2145     [self _setBoolValue:trackingEnabled forKey:WebKitNetworkDataUsageTrackingEnabledPreferenceKey];
2146 }
2147
2148 - (NSString *)networkInterfaceName
2149 {
2150     return [self _stringValueForKey:WebKitNetworkInterfaceNamePreferenceKey];
2151 }
2152
2153 - (void)setNetworkInterfaceName:(NSString *)name
2154 {
2155     [self _setStringValue:name forKey:WebKitNetworkInterfaceNamePreferenceKey];
2156 }
2157 #endif // PLATFORM(IOS)
2158
2159 - (BOOL)mediaPlaybackRequiresUserGesture
2160 {
2161     return [self _boolValueForKey:WebKitMediaPlaybackRequiresUserGesturePreferenceKey];
2162 }
2163
2164 - (void)setMediaPlaybackRequiresUserGesture:(BOOL)flag
2165 {
2166     [self _setBoolValue:flag forKey:WebKitMediaPlaybackRequiresUserGesturePreferenceKey];
2167 }
2168
2169 - (BOOL)mediaPlaybackAllowsInline
2170 {
2171     return [self _boolValueForKey:WebKitMediaPlaybackAllowsInlinePreferenceKey];
2172 }
2173
2174 - (void)setMediaPlaybackAllowsInline:(BOOL)flag
2175 {
2176     [self _setBoolValue:flag forKey:WebKitMediaPlaybackAllowsInlinePreferenceKey];
2177 }
2178
2179 - (BOOL)allowsAlternateFullscreen
2180 {
2181     return [self _boolValueForKey:WebKitAllowsAlternateFullscreenPreferenceKey];
2182 }
2183
2184 - (void)setAllowsAlternateFullscreen:(BOOL)flag
2185 {
2186     [self _setBoolValue:flag forKey:WebKitAllowsAlternateFullscreenPreferenceKey];
2187 }
2188
2189 - (BOOL)mockScrollbarsEnabled
2190 {
2191     return [self _boolValueForKey:WebKitMockScrollbarsEnabledPreferenceKey];
2192 }
2193
2194 - (void)setMockScrollbarsEnabled:(BOOL)flag
2195 {
2196     [self _setBoolValue:flag forKey:WebKitMockScrollbarsEnabledPreferenceKey];
2197 }
2198
2199 - (NSString *)pictographFontFamily
2200 {
2201     return [self _stringValueForKey: WebKitPictographFontPreferenceKey];
2202 }
2203
2204 - (void)setPictographFontFamily:(NSString *)family
2205 {
2206     [self _setStringValue: family forKey: WebKitPictographFontPreferenceKey];
2207 }
2208
2209 - (BOOL)pageCacheSupportsPlugins
2210 {
2211     return [self _boolValueForKey:WebKitPageCacheSupportsPluginsPreferenceKey];
2212 }
2213
2214 - (void)setPageCacheSupportsPlugins:(BOOL)flag
2215 {
2216     [self _setBoolValue:flag forKey:WebKitPageCacheSupportsPluginsPreferenceKey];
2217
2218 }
2219
2220 #if PLATFORM(IOS)
2221 - (void)_invalidateCachedPreferences
2222 {
2223     dispatch_barrier_sync(_private->readWriteQueue, ^{
2224         if (_private->values)
2225             _private->values = adoptNS([[NSMutableDictionary alloc] init]);
2226     });
2227
2228     [self _updatePrivateBrowsingStateTo:[self privateBrowsingEnabled]];
2229
2230     // Tell any live WebViews to refresh their preferences
2231     [self _postPreferencesChangedNotification];
2232 }
2233
2234 - (void)_synchronizeWebStoragePolicyWithCookiePolicy
2235 {
2236     // FIXME: This should be done in clients, WebKit shouldn't be making such policy decisions.
2237
2238     NSHTTPCookieAcceptPolicy cookieAcceptPolicy = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookieAcceptPolicy];
2239     WebStorageBlockingPolicy storageBlockingPolicy;
2240     switch (static_cast<unsigned>(cookieAcceptPolicy)) {
2241     case NSHTTPCookieAcceptPolicyAlways:
2242         storageBlockingPolicy = WebAllowAllStorage;
2243         break;
2244     case NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain:
2245     case NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain:
2246         storageBlockingPolicy = WebBlockThirdPartyStorage;
2247         break;
2248     case NSHTTPCookieAcceptPolicyNever:
2249         storageBlockingPolicy = WebBlockAllStorage;
2250         break;
2251     default:
2252         ASSERT_NOT_REACHED();
2253         storageBlockingPolicy = WebBlockAllStorage;
2254         break;
2255     }    
2256
2257     [self setStorageBlockingPolicy:storageBlockingPolicy];
2258 }
2259 #endif
2260
2261 - (void)setBackspaceKeyNavigationEnabled:(BOOL)flag
2262 {
2263     [self _setBoolValue:flag forKey:WebKitBackspaceKeyNavigationEnabledKey];
2264 }
2265
2266 - (BOOL)backspaceKeyNavigationEnabled
2267 {
2268     return [self _boolValueForKey:WebKitBackspaceKeyNavigationEnabledKey];
2269 }
2270
2271 - (void)setWantsBalancedSetDefersLoadingBehavior:(BOOL)flag
2272 {
2273     [self _setBoolValue:flag forKey:WebKitWantsBalancedSetDefersLoadingBehaviorKey];
2274 }
2275
2276 - (BOOL)wantsBalancedSetDefersLoadingBehavior
2277 {
2278     return [self _boolValueForKey:WebKitWantsBalancedSetDefersLoadingBehaviorKey];
2279 }
2280
2281 - (void)setShouldDisplaySubtitles:(BOOL)flag
2282 {
2283     [self _setBoolValue:flag forKey:WebKitShouldDisplaySubtitlesPreferenceKey];
2284 }
2285
2286 - (BOOL)shouldDisplaySubtitles
2287 {
2288     return [self _boolValueForKey:WebKitShouldDisplaySubtitlesPreferenceKey];
2289 }
2290
2291 - (void)setShouldDisplayCaptions:(BOOL)flag
2292 {
2293     [self _setBoolValue:flag forKey:WebKitShouldDisplayCaptionsPreferenceKey];
2294 }
2295
2296 - (BOOL)shouldDisplayCaptions
2297 {
2298     return [self _boolValueForKey:WebKitShouldDisplayCaptionsPreferenceKey];
2299 }
2300
2301 - (void)setShouldDisplayTextDescriptions:(BOOL)flag
2302 {
2303     [self _setBoolValue:flag forKey:WebKitShouldDisplayTextDescriptionsPreferenceKey];
2304 }
2305
2306 - (BOOL)shouldDisplayTextDescriptions
2307 {
2308     return [self _boolValueForKey:WebKitShouldDisplayTextDescriptionsPreferenceKey];
2309 }
2310
2311 - (void)setNotificationsEnabled:(BOOL)flag
2312 {
2313     [self _setBoolValue:flag forKey:WebKitNotificationsEnabledKey];
2314 }
2315
2316 - (BOOL)notificationsEnabled
2317 {
2318     return [self _boolValueForKey:WebKitNotificationsEnabledKey];
2319 }
2320
2321 - (void)setShouldRespectImageOrientation:(BOOL)flag
2322 {
2323     [self _setBoolValue:flag forKey:WebKitShouldRespectImageOrientationKey];
2324 }
2325
2326 - (BOOL)shouldRespectImageOrientation
2327 {
2328     return [self _boolValueForKey:WebKitShouldRespectImageOrientationKey];
2329 }
2330
2331 - (BOOL)requestAnimationFrameEnabled
2332 {
2333     return [self _boolValueForKey:WebKitRequestAnimationFrameEnabledPreferenceKey];
2334 }
2335
2336 - (void)setRequestAnimationFrameEnabled:(BOOL)enabled
2337 {
2338     [self _setBoolValue:enabled forKey:WebKitRequestAnimationFrameEnabledPreferenceKey];
2339 }
2340
2341 - (void)setIncrementalRenderingSuppressionTimeoutInSeconds:(NSTimeInterval)timeout
2342 {
2343     [self _setFloatValue:timeout forKey:WebKitIncrementalRenderingSuppressionTimeoutInSecondsKey];
2344 }
2345
2346 - (NSTimeInterval)incrementalRenderingSuppressionTimeoutInSeconds
2347 {
2348     return [self _floatValueForKey:WebKitIncrementalRenderingSuppressionTimeoutInSecondsKey];
2349 }
2350
2351 - (BOOL)diagnosticLoggingEnabled
2352 {
2353     return [self _boolValueForKey:WebKitDiagnosticLoggingEnabledKey];
2354 }
2355
2356 - (void)setDiagnosticLoggingEnabled:(BOOL)enabled
2357 {
2358     [self _setBoolValue:enabled forKey:WebKitDiagnosticLoggingEnabledKey];
2359 }
2360
2361 - (void)setStorageBlockingPolicy:(WebStorageBlockingPolicy)storageBlockingPolicy
2362 {
2363 #if PLATFORM(IOS)
2364     // We don't want to write the setting out, so we just reset the default instead of storing the new setting.
2365     // FIXME: This code removes any defaults previously registered by client process, which is not appropriate for this method to do.
2366     NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:storageBlockingPolicy] forKey:WebKitStorageBlockingPolicyKey];
2367     [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
2368 #else
2369     [self _setIntegerValue:storageBlockingPolicy forKey:WebKitStorageBlockingPolicyKey];
2370 #endif
2371 }
2372
2373 - (WebStorageBlockingPolicy)storageBlockingPolicy
2374 {
2375     return static_cast<WebStorageBlockingPolicy>([self _integerValueForKey:WebKitStorageBlockingPolicyKey]);
2376 }
2377
2378 - (BOOL)plugInSnapshottingEnabled
2379 {
2380     return [self _boolValueForKey:WebKitPlugInSnapshottingEnabledPreferenceKey];
2381 }
2382
2383 - (void)setPlugInSnapshottingEnabled:(BOOL)enabled
2384 {
2385     [self _setBoolValue:enabled forKey:WebKitPlugInSnapshottingEnabledPreferenceKey];
2386 }
2387
2388 - (BOOL)hiddenPageDOMTimerThrottlingEnabled
2389 {
2390     return [self _boolValueForKey:WebKitHiddenPageDOMTimerThrottlingEnabledPreferenceKey];
2391 }
2392
2393 - (void)setHiddenPageDOMTimerThrottlingEnabled:(BOOL)enabled
2394 {
2395     [self _setBoolValue:enabled forKey:WebKitHiddenPageDOMTimerThrottlingEnabledPreferenceKey];
2396 }
2397
2398 - (BOOL)hiddenPageCSSAnimationSuspensionEnabled
2399 {
2400     return [self _boolValueForKey:WebKitHiddenPageCSSAnimationSuspensionEnabledPreferenceKey];
2401 }
2402
2403 - (void)setHiddenPageCSSAnimationSuspensionEnabled:(BOOL)enabled
2404 {
2405     [self _setBoolValue:enabled forKey:WebKitHiddenPageCSSAnimationSuspensionEnabledPreferenceKey];
2406 }
2407
2408 - (BOOL)lowPowerVideoAudioBufferSizeEnabled
2409 {
2410     return [self _boolValueForKey:WebKitLowPowerVideoAudioBufferSizeEnabledPreferenceKey];
2411 }
2412
2413 - (void)setLowPowerVideoAudioBufferSizeEnabled:(BOOL)enabled
2414 {
2415     [self _setBoolValue:enabled forKey:WebKitLowPowerVideoAudioBufferSizeEnabledPreferenceKey];
2416 }
2417
2418 - (BOOL)useLegacyTextAlignPositionedElementBehavior
2419 {
2420     return [self _boolValueForKey:WebKitUseLegacyTextAlignPositionedElementBehaviorPreferenceKey];
2421 }
2422
2423 - (void)setUseLegacyTextAlignPositionedElementBehavior:(BOOL)enabled
2424 {
2425     [self _setBoolValue:enabled forKey:WebKitUseLegacyTextAlignPositionedElementBehaviorPreferenceKey];
2426 }
2427
2428 - (BOOL)mediaSourceEnabled
2429 {
2430     return [self _boolValueForKey:WebKitMediaSourceEnabledPreferenceKey];
2431 }
2432
2433 - (void)setMediaSourceEnabled:(BOOL)enabled
2434 {
2435     [self _setBoolValue:enabled forKey:WebKitMediaSourceEnabledPreferenceKey];
2436 }
2437
2438 - (BOOL)imageControlsEnabled
2439 {
2440     return [self _boolValueForKey:WebKitImageControlsEnabledPreferenceKey];
2441 }
2442
2443 - (void)setImageControlsEnabled:(BOOL)enabled
2444 {
2445     [self _setBoolValue:enabled forKey:WebKitImageControlsEnabledPreferenceKey];
2446 }
2447
2448 - (BOOL)serviceControlsEnabled
2449 {
2450     return [self _boolValueForKey:WebKitServiceControlsEnabledPreferenceKey];
2451 }
2452
2453 - (void)setServiceControlsEnabled:(BOOL)enabled
2454 {
2455     [self _setBoolValue:enabled forKey:WebKitServiceControlsEnabledPreferenceKey];
2456 }
2457
2458 - (BOOL)gamepadsEnabled
2459 {
2460     return [self _boolValueForKey:WebKitGamepadsEnabledPreferenceKey];
2461 }
2462
2463 - (void)setGamepadsEnabled:(BOOL)flag
2464 {
2465     [self _setBoolValue:flag forKey:WebKitGamepadsEnabledPreferenceKey];
2466 }
2467
2468 - (BOOL)shouldConvertPositionStyleOnCopy
2469 {
2470     return [self _boolValueForKey:WebKitShouldConvertPositionStyleOnCopyPreferenceKey];
2471 }
2472
2473 - (void)setShouldConvertPositionStyleOnCopy:(BOOL)enabled
2474 {
2475     [self _setBoolValue:enabled forKey:WebKitShouldConvertPositionStyleOnCopyPreferenceKey];
2476 }
2477
2478 - (NSString *)mediaKeysStorageDirectory
2479 {
2480     return [[self _stringValueForKey:WebKitMediaKeysStorageDirectoryKey] stringByStandardizingPath];
2481 }
2482
2483 - (void)setMediaKeysStorageDirectory:(NSString *)directory
2484 {
2485     [self _setStringValue:directory forKey:WebKitMediaKeysStorageDirectoryKey];
2486 }
2487
2488 - (void)setAntialiasedFontDilationEnabled:(BOOL)enabled
2489 {
2490     [self _setBoolValue:enabled forKey:WebKitAntialiasedFontDilationEnabledKey];
2491 }
2492
2493 - (BOOL)antialiasedFontDilationEnabled
2494 {
2495     return [self _boolValueForKey:WebKitAntialiasedFontDilationEnabledKey];
2496 }
2497
2498 - (BOOL)javaScriptMarkupEnabled
2499 {
2500     return [self _boolValueForKey:WebKitJavaScriptMarkupEnabledPreferenceKey];
2501 }
2502
2503 - (void)setJavaScriptMarkupEnabled:(BOOL)flag
2504 {
2505     [self _setBoolValue:flag forKey:WebKitJavaScriptMarkupEnabledPreferenceKey];
2506 }
2507
2508 @end
2509
2510 @implementation WebPreferences (WebInternal)
2511
2512 + (NSString *)_IBCreatorID
2513 {
2514     return classIBCreatorID;
2515 }
2516
2517 + (NSString *)_concatenateKeyWithIBCreatorID:(NSString *)key
2518 {
2519     NSString *IBCreatorID = [WebPreferences _IBCreatorID];
2520     if (!IBCreatorID)
2521         return key;
2522     return [IBCreatorID stringByAppendingString:key];
2523 }
2524
2525 @end