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