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