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