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