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