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