[WK2] Expose a few drawing/compositing settings on WKPreferences(Private)
[WebKit-https.git] / Source / WebKit / mac / WebView / WebPreferences.mm
1 /*
2  * Copyright (C) 2005, 2006, 2007, 2011, 2012, 2014 Apple Inc. All rights reserved.
3  *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer. 
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution. 
14  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission. 
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #import "WebPreferencesPrivate.h"
31 #import "WebPreferenceKeysPrivate.h"
32
33 #import "WebApplicationCache.h"
34 #import "WebFrameNetworkingContext.h"
35 #import "WebKitLogging.h"
36 #import "WebKitNSStringExtras.h"
37 #import "WebKitSystemBits.h"
38 #import "WebKitSystemInterface.h"
39 #import "WebKitVersionChecks.h"
40 #import "WebNSDictionaryExtras.h"
41 #import "WebNSURLExtras.h"
42 #import "WebSystemInterface.h"
43 #import <WebCore/ApplicationCacheStorage.h>
44 #import <WebCore/AudioSession.h>
45 #import <WebCore/NetworkStorageSession.h>
46 #import <WebCore/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     InitWebCoreSystemInterface();
398
399     NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
400         @"Times",                       WebKitStandardFontPreferenceKey,
401         @"Courier",                     WebKitFixedFontPreferenceKey,
402         @"Times",                       WebKitSerifFontPreferenceKey,
403         @"Helvetica",                   WebKitSansSerifFontPreferenceKey,
404 #if !PLATFORM(IOS)
405         @"Apple Chancery",              WebKitCursiveFontPreferenceKey,
406 #else
407         @"Snell Roundhand",             WebKitCursiveFontPreferenceKey,
408 #endif
409         @"Papyrus",                     WebKitFantasyFontPreferenceKey,
410 #if PLATFORM(IOS)
411         @"AppleColorEmoji",             WebKitPictographFontPreferenceKey,
412 #else
413         @"Apple Color Emoji",           WebKitPictographFontPreferenceKey,
414 #endif
415         @"0",                           WebKitMinimumFontSizePreferenceKey,
416         @"9",                           WebKitMinimumLogicalFontSizePreferenceKey, 
417         @"16",                          WebKitDefaultFontSizePreferenceKey,
418         @"13",                          WebKitDefaultFixedFontSizePreferenceKey,
419         @"ISO-8859-1",                  WebKitDefaultTextEncodingNamePreferenceKey,
420         [NSNumber numberWithBool:NO],   WebKitUsesEncodingDetectorPreferenceKey,
421         [NSNumber numberWithBool:NO],   WebKitUserStyleSheetEnabledPreferenceKey,
422         @"",                            WebKitUserStyleSheetLocationPreferenceKey,
423 #if !PLATFORM(IOS)
424         [NSNumber numberWithBool:NO],   WebKitShouldPrintBackgroundsPreferenceKey,
425         [NSNumber numberWithBool:NO],   WebKitTextAreasAreResizablePreferenceKey,
426 #endif
427         [NSNumber numberWithBool:NO],   WebKitShrinksStandaloneImagesToFitPreferenceKey,
428 #if !PLATFORM(IOS)
429         [NSNumber numberWithBool:YES],  WebKitJavaEnabledPreferenceKey,
430 #endif
431         [NSNumber numberWithBool:YES],  WebKitJavaScriptEnabledPreferenceKey,
432         [NSNumber numberWithBool:YES],  WebKitWebSecurityEnabledPreferenceKey,
433         [NSNumber numberWithBool:YES],  WebKitAllowUniversalAccessFromFileURLsPreferenceKey,
434         [NSNumber numberWithBool:YES],  WebKitAllowFileAccessFromFileURLsPreferenceKey,
435 #if PLATFORM(IOS)
436         [NSNumber numberWithBool:NO],   WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey,
437 #else
438         [NSNumber numberWithBool:YES],  WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey,
439 #endif
440         [NSNumber numberWithBool:YES],  WebKitPluginsEnabledPreferenceKey,
441         [NSNumber numberWithBool:YES],  WebKitDatabasesEnabledPreferenceKey,
442 #if PLATFORM(IOS)
443         [NSNumber numberWithBool:NO],   WebKitStorageTrackerEnabledPreferenceKey,
444 #endif
445         [NSNumber numberWithBool:YES],  WebKitLocalStorageEnabledPreferenceKey,
446         [NSNumber numberWithBool:NO],   WebKitExperimentalNotificationsEnabledPreferenceKey,
447         [NSNumber numberWithBool:YES],  WebKitAllowAnimatedImagesPreferenceKey,
448         [NSNumber numberWithBool:YES],  WebKitAllowAnimatedImageLoopingPreferenceKey,
449         [NSNumber numberWithBool:YES],  WebKitDisplayImagesKey,
450         [NSNumber numberWithBool:NO],   WebKitLoadSiteIconsKey,
451         @"1800",                        WebKitBackForwardCacheExpirationIntervalKey,
452 #if !PLATFORM(IOS)
453         [NSNumber numberWithBool:NO],   WebKitTabToLinksPreferenceKey,
454 #endif
455         [NSNumber numberWithBool:NO],   WebKitPrivateBrowsingEnabledPreferenceKey,
456 #if !PLATFORM(IOS)
457         [NSNumber numberWithBool:NO],   WebKitRespectStandardStyleKeyEquivalentsPreferenceKey,
458         [NSNumber numberWithBool:NO],   WebKitShowsURLsInToolTipsPreferenceKey,
459         [NSNumber numberWithBool:NO],   WebKitShowsToolTipOverTruncatedTextPreferenceKey,
460         @"1",                           WebKitPDFDisplayModePreferenceKey,
461         @"0",                           WebKitPDFScaleFactorPreferenceKey,
462 #endif
463         @"0",                           WebKitUseSiteSpecificSpoofingPreferenceKey,
464         [NSNumber numberWithInt:WebKitEditableLinkDefaultBehavior], WebKitEditableLinkBehaviorPreferenceKey,
465 #if !PLATFORM(IOS)
466         [NSNumber numberWithInt:WebTextDirectionSubmenuAutomaticallyIncluded],
467                                         WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey,
468         [NSNumber numberWithBool:NO],   WebKitDOMPasteAllowedPreferenceKey,
469 #endif
470         [NSNumber numberWithBool:YES],  WebKitUsesPageCachePreferenceKey,
471         [NSNumber numberWithInt:cacheModelForMainBundle()], WebKitCacheModelPreferenceKey,
472         [NSNumber numberWithBool:YES],  WebKitPageCacheSupportsPluginsPreferenceKey,
473         [NSNumber numberWithBool:NO],   WebKitDeveloperExtrasEnabledPreferenceKey,
474         [NSNumber numberWithBool:NO],   WebKitJavaScriptExperimentsEnabledPreferenceKey,
475         [NSNumber numberWithBool:YES],  WebKitAuthorAndUserStylesEnabledPreferenceKey,
476         [NSNumber numberWithBool:NO],   WebKitApplicationChromeModeEnabledPreferenceKey,
477         [NSNumber numberWithBool:NO],   WebKitWebArchiveDebugModeEnabledPreferenceKey,
478         [NSNumber numberWithBool:NO],   WebKitLocalFileContentSniffingEnabledPreferenceKey,
479         [NSNumber numberWithBool:NO],   WebKitOfflineWebApplicationCacheEnabledPreferenceKey,
480         [NSNumber numberWithBool:YES],  WebKitZoomsTextOnlyPreferenceKey,
481         [NSNumber numberWithBool:NO],   WebKitJavaScriptCanAccessClipboardPreferenceKey,
482         [NSNumber numberWithBool:YES],  WebKitXSSAuditorEnabledPreferenceKey,
483         [NSNumber numberWithBool:YES],  WebKitAcceleratedCompositingEnabledPreferenceKey,
484         [NSNumber numberWithBool:YES], WebKitCSSRegionsEnabledPreferenceKey,
485         [NSNumber numberWithBool:YES], WebKitCSSCompositingEnabledPreferenceKey,
486 #if PLATFORM(IOS) && !PLATFORM(IOS_SIMULATOR)
487         [NSNumber numberWithBool:YES],  WebKitAcceleratedDrawingEnabledPreferenceKey,
488         [NSNumber numberWithBool:YES],  WebKitCanvasUsesAcceleratedDrawingPreferenceKey,
489 #else
490         [NSNumber numberWithBool:NO],  WebKitAcceleratedDrawingEnabledPreferenceKey,
491         [NSNumber numberWithBool:NO],  WebKitCanvasUsesAcceleratedDrawingPreferenceKey,
492 #endif
493         [NSNumber numberWithBool:NO],   WebKitShowDebugBordersPreferenceKey,
494         [NSNumber numberWithBool:NO],   WebKitShowRepaintCounterPreferenceKey,
495         [NSNumber numberWithBool:YES],  WebKitWebGLEnabledPreferenceKey,
496         [NSNumber numberWithBool:NO],   WebKitMultithreadedWebGLEnabledPreferenceKey,
497         [NSNumber numberWithBool:NO],  WebKitForceSoftwareWebGLRenderingPreferenceKey,
498         [NSNumber numberWithBool:NO],   WebKitAccelerated2dCanvasEnabledPreferenceKey,
499         [NSNumber numberWithBool:YES],  WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey,
500 #if PLATFORM(IOS)
501         [NSNumber numberWithBool:YES],  WebKitFrameFlatteningEnabledPreferenceKey,
502 #else
503         [NSNumber numberWithBool:NO],   WebKitFrameFlatteningEnabledPreferenceKey,
504 #endif
505         [NSNumber numberWithBool:NO],   WebKitSpatialNavigationEnabledPreferenceKey,
506         [NSNumber numberWithBool:NO],  WebKitDNSPrefetchingEnabledPreferenceKey,
507         [NSNumber numberWithBool:NO],   WebKitFullScreenEnabledPreferenceKey,
508         [NSNumber numberWithBool:NO],   WebKitAsynchronousSpellCheckingEnabledPreferenceKey,
509         [NSNumber numberWithBool:YES],  WebKitHyperlinkAuditingEnabledPreferenceKey,
510         [NSNumber numberWithBool:NO],   WebKitUsePreHTML5ParserQuirksKey,
511         [NSNumber numberWithBool:YES],  WebKitAVFoundationEnabledKey,
512         [NSNumber numberWithBool:NO],   WebKitSuppressesIncrementalRenderingKey,
513 #if !PLATFORM(IOS)
514         [NSNumber numberWithBool:NO],   WebKitMediaPlaybackRequiresUserGesturePreferenceKey,
515         [NSNumber numberWithBool:YES],  WebKitMediaPlaybackAllowsInlinePreferenceKey,
516         [NSNumber numberWithBool:NO],   WebKitWebAudioEnabledPreferenceKey,
517         [NSNumber numberWithBool:YES],  WebKitBackspaceKeyNavigationEnabledKey,
518         [NSNumber numberWithBool:NO],   WebKitShouldDisplaySubtitlesPreferenceKey,
519         [NSNumber numberWithBool:NO],   WebKitShouldDisplayCaptionsPreferenceKey,
520         [NSNumber numberWithBool:NO],   WebKitShouldDisplayTextDescriptionsPreferenceKey,
521         [NSNumber numberWithBool:YES],  WebKitNotificationsEnabledKey,
522         [NSNumber numberWithBool:NO],   WebKitShouldRespectImageOrientationKey,
523 #else
524         [NSNumber numberWithBool:YES],  WebKitMediaPlaybackRequiresUserGesturePreferenceKey,
525         [NSNumber numberWithBool:NO],   WebKitMediaPlaybackAllowsInlinePreferenceKey,
526         [NSNumber numberWithBool:YES],  WebKitMediaPlaybackAllowsAirPlayPreferenceKey,
527         [NSNumber numberWithUnsignedInt:AudioSession::None],  WebKitAudioSessionCategoryOverride,
528         [NSNumber numberWithBool:YES],  WebKitAVKitEnabled,
529         [NSNumber numberWithLongLong:WebCore::ApplicationCacheStorage::noQuota()], WebKitApplicationCacheTotalQuota,
530
531         // Per-Origin Quota on iOS is 25MB. When the quota is reached for a particular origin
532         // the quota for that origin can be increased. See also webView:exceededApplicationCacheOriginQuotaForSecurityOrigin:totalSpaceNeeded in WebUI/WebUIDelegate.m.
533         [NSNumber numberWithLongLong:(25 * 1024 * 1024)], WebKitApplicationCacheDefaultOriginQuota,
534
535         // Enable WebAudio by default in all iOS UIWebViews
536         [NSNumber numberWithBool:YES],   WebKitWebAudioEnabledPreferenceKey,
537
538         [NSNumber numberWithBool:YES],   WebKitShouldRespectImageOrientationKey,
539 #endif // PLATFORM(IOS)
540         [NSNumber numberWithBool:YES],  WebKitRequestAnimationFrameEnabledPreferenceKey,
541         [NSNumber numberWithBool:NO],   WebKitWantsBalancedSetDefersLoadingBehaviorKey,
542         [NSNumber numberWithBool:NO],   WebKitDiagnosticLoggingEnabledKey,
543 #if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
544         [NSNumber numberWithBool:NO],
545 #else
546         [NSNumber numberWithBool:YES],
547 #endif
548                                         WebKitScreenFontSubstitutionEnabledKey,
549         [NSNumber numberWithInt:WebAllowAllStorage], WebKitStorageBlockingPolicyKey,
550         [NSNumber numberWithBool:NO],   WebKitPlugInSnapshottingEnabledPreferenceKey,
551
552 #if PLATFORM(IOS)
553         [NSNumber numberWithBool:NO],   WebKitTelephoneParsingEnabledPreferenceKey,
554         [NSNumber numberWithInt:-1],      WebKitLayoutIntervalPreferenceKey,
555         [NSNumber numberWithFloat:-1.0f], WebKitMaxParseDurationPreferenceKey,
556         [NSNumber numberWithBool:NO],     WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey,
557         [NSNumber numberWithInt:-1],      WebKitPageCacheSizePreferenceKey,
558         [NSNumber numberWithInt:-1],      WebKitObjectCacheSizePreferenceKey,
559         [NSNumber numberWithInt:-1],      WebKitNSURLMemoryCacheSizePreferenceKey,
560         [NSNumber numberWithInt:-1],      WebKitNSURLDiskCacheSizePreferenceKey,
561         [NSNumber numberWithBool:NO],     WebKitAlwaysRequestGeolocationPermissionPreferenceKey,
562         [NSNumber numberWithInt:InterpolationLow], WebKitInterpolationQualityPreferenceKey,
563         [NSNumber numberWithBool:YES],    WebKitPasswordEchoEnabledPreferenceKey,
564         [NSNumber numberWithFloat:2.0f],  WebKitPasswordEchoDurationPreferenceKey,
565         [NSNumber numberWithBool:NO],     WebKitNetworkDataUsageTrackingEnabledPreferenceKey,
566         @"",                              WebKitNetworkInterfaceNamePreferenceKey,
567 #endif
568 #if ENABLE(IOS_TEXT_AUTOSIZING)
569         [NSNumber numberWithFloat:WKGetMinimumZoomFontSize()], WebKitMinimumZoomFontSizePreferenceKey,
570 #endif
571 #if ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
572         [NSNumber numberWithBool:YES], WebKitDiskImageCacheEnabledPreferenceKey,
573         [NSNumber numberWithUnsignedInt:(100 * 1024)], WebKitDiskImageCacheMinimumImageSizePreferenceKey,
574         [NSNumber numberWithUnsignedInt:(100 * 1024 * 1024)], WebKitDiskImageCacheMaximumCacheSizePreferenceKey,
575 #endif
576         [NSNumber numberWithLongLong:ApplicationCacheStorage::noQuota()], WebKitApplicationCacheTotalQuota,
577         [NSNumber numberWithLongLong:ApplicationCacheStorage::noQuota()], WebKitApplicationCacheDefaultOriginQuota,
578         [NSNumber numberWithBool:YES],  WebKitQTKitEnabledPreferenceKey,
579         [NSNumber numberWithBool:NO], WebKitHiddenPageDOMTimerThrottlingEnabledPreferenceKey,
580         [NSNumber numberWithBool:NO], WebKitHiddenPageCSSAnimationSuspensionEnabledPreferenceKey,
581         [NSNumber numberWithBool:NO], WebKitLowPowerVideoAudioBufferSizeEnabledPreferenceKey,
582         
583         [NSNumber numberWithBool:NO], WebKitUseLegacyTextAlignPositionedElementBehaviorPreferenceKey,
584 #if ENABLE(MEDIA_SOURCE)
585         [NSNumber numberWithBool:YES], WebKitMediaSourceEnabledPreferenceKey,
586 #endif
587 #if ENABLE(SERVICE_CONTROLS)
588         [NSNumber numberWithBool:NO], WebKitImageControlsEnabledPreferenceKey,
589 #endif
590         [NSNumber numberWithBool:NO], WebKitEnableInheritURIQueryComponentPreferenceKey,
591         nil];
592
593 #if !PLATFORM(IOS)
594     // This value shouldn't ever change, which is assumed in the initialization of WebKitPDFDisplayModePreferenceKey above
595     ASSERT(kPDFDisplaySinglePageContinuous == 1);
596 #endif
597     [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
598 }
599
600 - (void)dealloc
601 {
602     [self _updatePrivateBrowsingStateTo:NO];
603
604     delete _private;
605     [super dealloc];
606 }
607
608 - (NSString *)identifier
609 {
610     return _private->identifier.get();
611 }
612
613 - (id)_valueForKey:(NSString *)key
614 {
615     NSString *_key = KEY(key);
616 #if PLATFORM(IOS)
617     __block id o = nil;
618     dispatch_sync(_private->readWriteQueue, ^{
619         o = [_private->values.get() objectForKey:_key];
620     });
621 #else
622     id o = [_private->values.get() objectForKey:_key];
623 #endif
624     if (o)
625         return o;
626     o = [[NSUserDefaults standardUserDefaults] objectForKey:_key];
627     if (!o && key != _key)
628         o = [[NSUserDefaults standardUserDefaults] objectForKey:key];
629     return o;
630 }
631
632 - (NSString *)_stringValueForKey:(NSString *)key
633 {
634     id s = [self _valueForKey:key];
635     return [s isKindOfClass:[NSString class]] ? (NSString *)s : nil;
636 }
637
638 - (void)_setStringValue:(NSString *)value forKey:(NSString *)key
639 {
640     if ([[self _stringValueForKey:key] isEqualToString:value])
641         return;
642     NSString *_key = KEY(key);
643 #if PLATFORM(IOS)
644     dispatch_barrier_sync(_private->readWriteQueue, ^{
645 #endif
646     [_private->values.get() setObject:value forKey:_key];
647 #if PLATFORM(IOS)
648     });
649 #endif
650     if (_private->autosaves)
651         [[NSUserDefaults standardUserDefaults] setObject:value forKey:_key];
652     [self _postPreferencesChangedNotification];
653 }
654
655 - (int)_integerValueForKey:(NSString *)key
656 {
657     id o = [self _valueForKey:key];
658     return [o respondsToSelector:@selector(intValue)] ? [o intValue] : 0;
659 }
660
661 - (void)_setIntegerValue:(int)value forKey:(NSString *)key
662 {
663     if ([self _integerValueForKey:key] == value)
664         return;
665     NSString *_key = KEY(key);
666 #if PLATFORM(IOS)
667     dispatch_barrier_sync(_private->readWriteQueue, ^{
668 #endif
669     [_private->values.get() _webkit_setInt:value forKey:_key];
670 #if PLATFORM(IOS)
671     });
672 #endif
673     if (_private->autosaves)
674         [[NSUserDefaults standardUserDefaults] setInteger:value forKey:_key];
675     [self _postPreferencesChangedNotification];
676 }
677
678 #if PLATFORM(IOS)
679 - (unsigned int)_unsignedIntValueForKey:(NSString *)key
680 {
681     id o = [self _valueForKey:key];
682     return [o respondsToSelector:@selector(unsignedIntValue)] ? [o unsignedIntValue] : 0;
683 }
684
685 - (void)_setUnsignedIntValue:(unsigned int)value forKey:(NSString *)key
686 {    if ([self _unsignedIntValueForKey:key] == value)
687         return;
688     NSString *_key = KEY(key);
689     dispatch_barrier_sync(_private->readWriteQueue, ^{
690     [_private->values.get() _webkit_setUnsignedInt:value forKey:_key];
691     });
692     if (_private->autosaves)
693         [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInt:value] forKey:_key];
694     [self _postPreferencesChangedNotification];
695 }
696 #endif
697
698 - (float)_floatValueForKey:(NSString *)key
699 {
700     id o = [self _valueForKey:key];
701     return [o respondsToSelector:@selector(floatValue)] ? [o floatValue] : 0.0f;
702 }
703
704 - (void)_setFloatValue:(float)value forKey:(NSString *)key
705 {
706     if ([self _floatValueForKey:key] == value)
707         return;
708     NSString *_key = KEY(key);
709 #if PLATFORM(IOS)
710     dispatch_barrier_sync(_private->readWriteQueue, ^{
711 #endif
712     [_private->values.get() _webkit_setFloat:value forKey:_key];
713 #if PLATFORM(IOS)
714     });
715 #endif
716     if (_private->autosaves)
717         [[NSUserDefaults standardUserDefaults] setFloat:value forKey:_key];
718     [self _postPreferencesChangedNotification];
719 }
720
721 - (BOOL)_boolValueForKey:(NSString *)key
722 {
723     return [self _integerValueForKey:key] != 0;
724 }
725
726 - (void)_setBoolValue:(BOOL)value forKey:(NSString *)key
727 {
728     if ([self _boolValueForKey:key] == value)
729         return;
730     NSString *_key = KEY(key);
731 #if PLATFORM(IOS)
732     dispatch_barrier_sync(_private->readWriteQueue, ^{
733 #endif
734     [_private->values.get() _webkit_setBool:value forKey:_key];
735 #if PLATFORM(IOS)
736     });
737 #endif
738     if (_private->autosaves)
739         [[NSUserDefaults standardUserDefaults] setBool:value forKey:_key];
740     [self _postPreferencesChangedNotification];
741 }
742
743 - (long long)_longLongValueForKey:(NSString *)key
744 {
745     id o = [self _valueForKey:key];
746     return [o respondsToSelector:@selector(longLongValue)] ? [o longLongValue] : 0;
747 }
748
749 - (void)_setLongLongValue:(long long)value forKey:(NSString *)key
750 {
751     if ([self _longLongValueForKey:key] == value)
752         return;
753     NSString *_key = KEY(key);
754 #if PLATFORM(IOS)
755     dispatch_barrier_sync(_private->readWriteQueue, ^{
756 #endif
757     [_private->values.get() _webkit_setLongLong:value forKey:_key];
758 #if PLATFORM(IOS)
759     });
760 #endif
761     if (_private->autosaves)
762         [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithLongLong:value] forKey:_key];
763     [self _postPreferencesChangedNotification];
764 }
765
766 - (unsigned long long)_unsignedLongLongValueForKey:(NSString *)key
767 {
768     id o = [self _valueForKey:key];
769     return [o respondsToSelector:@selector(unsignedLongLongValue)] ? [o unsignedLongLongValue] : 0;
770 }
771
772 - (void)_setUnsignedLongLongValue:(unsigned long long)value forKey:(NSString *)key
773 {
774     if ([self _unsignedLongLongValueForKey:key] == value)
775         return;
776     NSString *_key = KEY(key);
777 #if PLATFORM(IOS)
778     dispatch_barrier_sync(_private->readWriteQueue, ^{
779 #endif
780     [_private->values.get() _webkit_setUnsignedLongLong:value forKey:_key];
781 #if PLATFORM(IOS)
782     });
783 #endif
784     if (_private->autosaves)
785         [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedLongLong:value] forKey:_key];
786     [self _postPreferencesChangedNotification];
787 }
788
789 - (NSString *)standardFontFamily
790 {
791     return [self _stringValueForKey: WebKitStandardFontPreferenceKey];
792 }
793
794 - (void)setStandardFontFamily:(NSString *)family
795 {
796     [self _setStringValue: family forKey: WebKitStandardFontPreferenceKey];
797 }
798
799 - (NSString *)fixedFontFamily
800 {
801     return [self _stringValueForKey: WebKitFixedFontPreferenceKey];
802 }
803
804 - (void)setFixedFontFamily:(NSString *)family
805 {
806     [self _setStringValue: family forKey: WebKitFixedFontPreferenceKey];
807 }
808
809 - (NSString *)serifFontFamily
810 {
811     return [self _stringValueForKey: WebKitSerifFontPreferenceKey];
812 }
813
814 - (void)setSerifFontFamily:(NSString *)family 
815 {
816     [self _setStringValue: family forKey: WebKitSerifFontPreferenceKey];
817 }
818
819 - (NSString *)sansSerifFontFamily
820 {
821     return [self _stringValueForKey: WebKitSansSerifFontPreferenceKey];
822 }
823
824 - (void)setSansSerifFontFamily:(NSString *)family
825 {
826     [self _setStringValue: family forKey: WebKitSansSerifFontPreferenceKey];
827 }
828
829 - (NSString *)cursiveFontFamily
830 {
831     return [self _stringValueForKey: WebKitCursiveFontPreferenceKey];
832 }
833
834 - (void)setCursiveFontFamily:(NSString *)family
835 {
836     [self _setStringValue: family forKey: WebKitCursiveFontPreferenceKey];
837 }
838
839 - (NSString *)fantasyFontFamily
840 {
841     return [self _stringValueForKey: WebKitFantasyFontPreferenceKey];
842 }
843
844 - (void)setFantasyFontFamily:(NSString *)family
845 {
846     [self _setStringValue: family forKey: WebKitFantasyFontPreferenceKey];
847 }
848
849 - (int)defaultFontSize
850 {
851     return [self _integerValueForKey: WebKitDefaultFontSizePreferenceKey];
852 }
853
854 - (void)setDefaultFontSize:(int)size
855 {
856     [self _setIntegerValue: size forKey: WebKitDefaultFontSizePreferenceKey];
857 }
858
859 - (int)defaultFixedFontSize
860 {
861     return [self _integerValueForKey: WebKitDefaultFixedFontSizePreferenceKey];
862 }
863
864 - (void)setDefaultFixedFontSize:(int)size
865 {
866     [self _setIntegerValue: size forKey: WebKitDefaultFixedFontSizePreferenceKey];
867 }
868
869 - (int)minimumFontSize
870 {
871     return [self _integerValueForKey: WebKitMinimumFontSizePreferenceKey];
872 }
873
874 - (void)setMinimumFontSize:(int)size
875 {
876     [self _setIntegerValue: size forKey: WebKitMinimumFontSizePreferenceKey];
877 }
878
879 - (int)minimumLogicalFontSize
880 {
881   return [self _integerValueForKey: WebKitMinimumLogicalFontSizePreferenceKey];
882 }
883
884 - (void)setMinimumLogicalFontSize:(int)size
885 {
886   [self _setIntegerValue: size forKey: WebKitMinimumLogicalFontSizePreferenceKey];
887 }
888
889 - (NSString *)defaultTextEncodingName
890 {
891     return [self _stringValueForKey: WebKitDefaultTextEncodingNamePreferenceKey];
892 }
893
894 - (void)setDefaultTextEncodingName:(NSString *)encoding
895 {
896     [self _setStringValue: encoding forKey: WebKitDefaultTextEncodingNamePreferenceKey];
897 }
898
899 #if !PLATFORM(IOS)
900 - (BOOL)userStyleSheetEnabled
901 {
902     return [self _boolValueForKey: WebKitUserStyleSheetEnabledPreferenceKey];
903 }
904
905 - (void)setUserStyleSheetEnabled:(BOOL)flag
906 {
907     [self _setBoolValue: flag forKey: WebKitUserStyleSheetEnabledPreferenceKey];
908 }
909
910 - (NSURL *)userStyleSheetLocation
911 {
912     NSString *locationString = [self _stringValueForKey: WebKitUserStyleSheetLocationPreferenceKey];
913     
914     if ([locationString _webkit_looksLikeAbsoluteURL]) {
915         return [NSURL _web_URLWithDataAsString:locationString];
916     } else {
917         locationString = [locationString stringByExpandingTildeInPath];
918         return [NSURL fileURLWithPath:locationString];
919     }
920 }
921
922 - (void)setUserStyleSheetLocation:(NSURL *)URL
923 {
924     NSString *locationString;
925     
926     if ([URL isFileURL]) {
927         locationString = [[URL path] _web_stringByAbbreviatingWithTildeInPath];
928     } else {
929         locationString = [URL _web_originalDataAsString];
930     }
931
932     if (!locationString)
933         locationString = @"";
934
935     [self _setStringValue:locationString forKey: WebKitUserStyleSheetLocationPreferenceKey];
936 }
937 #else
938
939 // These methods have had their implementations removed on iOS since it
940 // is wrong to have such a setting stored in preferences that, when read,
941 // is applied to all WebViews in a iOS process. Such a design might work
942 // OK for an application like Safari on Mac OS X, where the only WebViews
943 // in use display web content in a straightforward manner. However, it is
944 // wrong for iOS, where WebViews are used for various purposes, like
945 // text editing, text rendering, and displaying web content.
946 // 
947 // I have changed the user style sheet mechanism to be a per-WebView
948 // setting, rather than a per-process preference. This seems to give the
949 // behavior we want for iOS.
950
951 - (BOOL)userStyleSheetEnabled
952 {
953     return NO;
954 }
955
956 - (void)setUserStyleSheetEnabled:(BOOL)flag
957 {
958     // no-op
959 }
960
961 - (NSURL *)userStyleSheetLocation
962 {
963     return nil;
964 }
965
966 - (void)setUserStyleSheetLocation:(NSURL *)URL
967 {
968     // no-op
969 }
970 #endif // PLATFORM(IOS)
971
972 #if !PLATFORM(IOS)
973 - (BOOL)shouldPrintBackgrounds
974 {
975     return [self _boolValueForKey: WebKitShouldPrintBackgroundsPreferenceKey];
976 }
977
978 - (void)setShouldPrintBackgrounds:(BOOL)flag
979 {
980     [self _setBoolValue: flag forKey: WebKitShouldPrintBackgroundsPreferenceKey];
981 }
982 #endif
983
984 - (BOOL)isJavaEnabled
985 {
986     return [self _boolValueForKey: WebKitJavaEnabledPreferenceKey];
987 }
988
989 - (void)setJavaEnabled:(BOOL)flag
990 {
991     [self _setBoolValue: flag forKey: WebKitJavaEnabledPreferenceKey];
992 }
993
994 - (BOOL)isJavaScriptEnabled
995 {
996     return [self _boolValueForKey: WebKitJavaScriptEnabledPreferenceKey];
997 }
998
999 - (void)setJavaScriptEnabled:(BOOL)flag
1000 {
1001     [self _setBoolValue: flag forKey: WebKitJavaScriptEnabledPreferenceKey];
1002 }
1003
1004 - (BOOL)javaScriptCanOpenWindowsAutomatically
1005 {
1006     return [self _boolValueForKey: WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey];
1007 }
1008
1009 - (void)setJavaScriptCanOpenWindowsAutomatically:(BOOL)flag
1010 {
1011     [self _setBoolValue: flag forKey: WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey];
1012 }
1013
1014 - (BOOL)arePlugInsEnabled
1015 {
1016     return [self _boolValueForKey: WebKitPluginsEnabledPreferenceKey];
1017 }
1018
1019 - (void)setPlugInsEnabled:(BOOL)flag
1020 {
1021     [self _setBoolValue: flag forKey: WebKitPluginsEnabledPreferenceKey];
1022 }
1023
1024 - (BOOL)allowsAnimatedImages
1025 {
1026     return [self _boolValueForKey: WebKitAllowAnimatedImagesPreferenceKey];
1027 }
1028
1029 - (void)setAllowsAnimatedImages:(BOOL)flag
1030 {
1031     [self _setBoolValue: flag forKey: WebKitAllowAnimatedImagesPreferenceKey];
1032 }
1033
1034 - (BOOL)allowsAnimatedImageLooping
1035 {
1036     return [self _boolValueForKey: WebKitAllowAnimatedImageLoopingPreferenceKey];
1037 }
1038
1039 - (void)setAllowsAnimatedImageLooping: (BOOL)flag
1040 {
1041     [self _setBoolValue: flag forKey: WebKitAllowAnimatedImageLoopingPreferenceKey];
1042 }
1043
1044 - (void)setLoadsImagesAutomatically: (BOOL)flag
1045 {
1046     [self _setBoolValue: flag forKey: WebKitDisplayImagesKey];
1047 }
1048
1049 - (BOOL)loadsImagesAutomatically
1050 {
1051     return [self _boolValueForKey: WebKitDisplayImagesKey];
1052 }
1053
1054 - (void)setAutosaves:(BOOL)flag
1055 {
1056     _private->autosaves = flag;
1057 }
1058
1059 - (BOOL)autosaves
1060 {
1061     return _private->autosaves;
1062 }
1063
1064 #if !PLATFORM(IOS)
1065 - (void)setTabsToLinks:(BOOL)flag
1066 {
1067     [self _setBoolValue: flag forKey: WebKitTabToLinksPreferenceKey];
1068 }
1069
1070 - (BOOL)tabsToLinks
1071 {
1072     return [self _boolValueForKey:WebKitTabToLinksPreferenceKey];
1073 }
1074 #endif
1075
1076 - (void)setPrivateBrowsingEnabled:(BOOL)enabled
1077 {
1078     [self _updatePrivateBrowsingStateTo:enabled];
1079     [self _setBoolValue:enabled forKey:WebKitPrivateBrowsingEnabledPreferenceKey];
1080 }
1081
1082 - (BOOL)privateBrowsingEnabled
1083 {
1084     // Changes to private browsing defaults do not have effect on existing WebPreferences, and must be done through -setPrivateBrowsingEnabled.
1085     // This is needed to accurately track private browsing sessions in the process.
1086     return _private->inPrivateBrowsing;
1087 }
1088
1089 - (void)_updatePrivateBrowsingStateTo:(BOOL)enabled
1090 {
1091     if (!_private) {
1092         ASSERT(!enabled);
1093         return;
1094     }
1095
1096     if (enabled == _private->inPrivateBrowsing)
1097         return;
1098     if (enabled > _private->inPrivateBrowsing) {
1099         WebFrameNetworkingContext::ensurePrivateBrowsingSession();
1100         ++webPreferencesInstanceCountWithPrivateBrowsingEnabled;
1101     } else {
1102         ASSERT(webPreferencesInstanceCountWithPrivateBrowsingEnabled);
1103         --webPreferencesInstanceCountWithPrivateBrowsingEnabled;
1104         if (!webPreferencesInstanceCountWithPrivateBrowsingEnabled)
1105             WebFrameNetworkingContext::destroyPrivateBrowsingSession();
1106     }
1107     _private->inPrivateBrowsing = enabled;
1108 }
1109
1110 - (void)setUsesPageCache:(BOOL)usesPageCache
1111 {
1112     [self _setBoolValue:usesPageCache forKey:WebKitUsesPageCachePreferenceKey];
1113 }
1114
1115 - (BOOL)usesPageCache
1116 {
1117     return [self _boolValueForKey:WebKitUsesPageCachePreferenceKey];
1118 }
1119
1120 - (void)_postCacheModelChangedNotification
1121 {
1122 #if !PLATFORM(IOS)
1123     if (!pthread_main_np()) {
1124         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1125         return;
1126     }
1127 #endif
1128
1129     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesCacheModelChangedInternalNotification object:self userInfo:nil];
1130 }
1131
1132 - (void)setCacheModel:(WebCacheModel)cacheModel
1133 {
1134     [self _setIntegerValue:cacheModel forKey:WebKitCacheModelPreferenceKey];
1135     [self setAutomaticallyDetectsCacheModel:NO];
1136     [self _postCacheModelChangedNotification];
1137 }
1138
1139 - (WebCacheModel)cacheModel
1140 {
1141     return (WebCacheModel)[self _integerValueForKey:WebKitCacheModelPreferenceKey];
1142 }
1143
1144
1145 - (void)setSuppressesIncrementalRendering:(BOOL)suppressesIncrementalRendering
1146 {
1147     [self _setBoolValue:suppressesIncrementalRendering forKey:WebKitSuppressesIncrementalRenderingKey];
1148 }
1149
1150 - (BOOL)suppressesIncrementalRendering
1151 {
1152     return [self _boolValueForKey:WebKitSuppressesIncrementalRenderingKey];
1153 }
1154
1155 @end
1156
1157 @implementation WebPreferences (WebPrivate)
1158
1159 #if PLATFORM(IOS) && !(__IPHONE_OS_VERSION_MIN_REQUIRED >= 60000)
1160 - (void) setWebInspectorServerEnabled:(BOOL)flag
1161 {
1162 }
1163 #endif
1164
1165 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
1166 - (void)_setAllowCompositingLayerVisualDegradation:(BOOL)flag
1167 {
1168 }
1169 #endif
1170
1171 - (BOOL)isDNSPrefetchingEnabled
1172 {
1173     return [self _boolValueForKey:WebKitDNSPrefetchingEnabledPreferenceKey];
1174 }
1175
1176 - (void)setDNSPrefetchingEnabled:(BOOL)flag
1177 {
1178     [self _setBoolValue:flag forKey:WebKitDNSPrefetchingEnabledPreferenceKey];
1179 }
1180
1181 - (BOOL)developerExtrasEnabled
1182 {
1183     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
1184     if ([defaults boolForKey:@"DisableWebKitDeveloperExtras"])
1185         return NO;
1186 #ifdef NDEBUG
1187     if ([defaults boolForKey:@"WebKitDeveloperExtras"] || [defaults boolForKey:@"IncludeDebugMenu"])
1188         return YES;
1189     return [self _boolValueForKey:WebKitDeveloperExtrasEnabledPreferenceKey];
1190 #else
1191     return YES; // always enable in debug builds
1192 #endif
1193 }
1194
1195 - (void)setJavaScriptExperimentsEnabled:(BOOL)flag
1196 {
1197     [self _setBoolValue:flag forKey:WebKitJavaScriptExperimentsEnabledPreferenceKey];
1198 }
1199
1200 - (BOOL)javaScriptExperimentsEnabled
1201 {
1202     return [self _boolValueForKey:WebKitJavaScriptExperimentsEnabledPreferenceKey];
1203 }
1204
1205 - (void)setDeveloperExtrasEnabled:(BOOL)flag
1206 {
1207     [self _setBoolValue:flag forKey:WebKitDeveloperExtrasEnabledPreferenceKey];
1208 }
1209
1210 - (BOOL)authorAndUserStylesEnabled
1211 {
1212     return [self _boolValueForKey:WebKitAuthorAndUserStylesEnabledPreferenceKey];
1213 }
1214
1215 - (void)setAuthorAndUserStylesEnabled:(BOOL)flag
1216 {
1217     [self _setBoolValue:flag forKey:WebKitAuthorAndUserStylesEnabledPreferenceKey];
1218 }
1219
1220 - (BOOL)applicationChromeModeEnabled
1221 {
1222     return [self _boolValueForKey:WebKitApplicationChromeModeEnabledPreferenceKey];
1223 }
1224
1225 - (void)setApplicationChromeModeEnabled:(BOOL)flag
1226 {
1227     [self _setBoolValue:flag forKey:WebKitApplicationChromeModeEnabledPreferenceKey];
1228 }
1229
1230 - (BOOL)webArchiveDebugModeEnabled
1231 {
1232     return [self _boolValueForKey:WebKitWebArchiveDebugModeEnabledPreferenceKey];
1233 }
1234
1235 - (void)setWebArchiveDebugModeEnabled:(BOOL)flag
1236 {
1237     [self _setBoolValue:flag forKey:WebKitWebArchiveDebugModeEnabledPreferenceKey];
1238 }
1239
1240 - (BOOL)localFileContentSniffingEnabled
1241 {
1242     return [self _boolValueForKey:WebKitLocalFileContentSniffingEnabledPreferenceKey];
1243 }
1244
1245 - (void)setLocalFileContentSniffingEnabled:(BOOL)flag
1246 {
1247     [self _setBoolValue:flag forKey:WebKitLocalFileContentSniffingEnabledPreferenceKey];
1248 }
1249
1250 - (BOOL)offlineWebApplicationCacheEnabled
1251 {
1252     return [self _boolValueForKey:WebKitOfflineWebApplicationCacheEnabledPreferenceKey];
1253 }
1254
1255 - (void)setOfflineWebApplicationCacheEnabled:(BOOL)flag
1256 {
1257     [self _setBoolValue:flag forKey:WebKitOfflineWebApplicationCacheEnabledPreferenceKey];
1258 }
1259
1260 - (BOOL)zoomsTextOnly
1261 {
1262     return [self _boolValueForKey:WebKitZoomsTextOnlyPreferenceKey];
1263 }
1264
1265 - (void)setZoomsTextOnly:(BOOL)flag
1266 {
1267     [self _setBoolValue:flag forKey:WebKitZoomsTextOnlyPreferenceKey];
1268 }
1269
1270 - (BOOL)javaScriptCanAccessClipboard
1271 {
1272     return [self _boolValueForKey:WebKitJavaScriptCanAccessClipboardPreferenceKey];
1273 }
1274
1275 - (void)setJavaScriptCanAccessClipboard:(BOOL)flag
1276 {
1277     [self _setBoolValue:flag forKey:WebKitJavaScriptCanAccessClipboardPreferenceKey];
1278 }
1279
1280 - (BOOL)isXSSAuditorEnabled
1281 {
1282     return [self _boolValueForKey:WebKitXSSAuditorEnabledPreferenceKey];
1283 }
1284
1285 - (void)setXSSAuditorEnabled:(BOOL)flag
1286 {
1287     [self _setBoolValue:flag forKey:WebKitXSSAuditorEnabledPreferenceKey];
1288 }
1289
1290 #if !PLATFORM(IOS)
1291 - (BOOL)respectStandardStyleKeyEquivalents
1292 {
1293     return [self _boolValueForKey:WebKitRespectStandardStyleKeyEquivalentsPreferenceKey];
1294 }
1295
1296 - (void)setRespectStandardStyleKeyEquivalents:(BOOL)flag
1297 {
1298     [self _setBoolValue:flag forKey:WebKitRespectStandardStyleKeyEquivalentsPreferenceKey];
1299 }
1300
1301 - (BOOL)showsURLsInToolTips
1302 {
1303     return [self _boolValueForKey:WebKitShowsURLsInToolTipsPreferenceKey];
1304 }
1305
1306 - (void)setShowsURLsInToolTips:(BOOL)flag
1307 {
1308     [self _setBoolValue:flag forKey:WebKitShowsURLsInToolTipsPreferenceKey];
1309 }
1310
1311 - (BOOL)showsToolTipOverTruncatedText
1312 {
1313     return [self _boolValueForKey:WebKitShowsToolTipOverTruncatedTextPreferenceKey];
1314 }
1315
1316 - (void)setShowsToolTipOverTruncatedText:(BOOL)flag
1317 {
1318     [self _setBoolValue:flag forKey:WebKitShowsToolTipOverTruncatedTextPreferenceKey];
1319 }
1320
1321 - (BOOL)textAreasAreResizable
1322 {
1323     return [self _boolValueForKey: WebKitTextAreasAreResizablePreferenceKey];
1324 }
1325
1326 - (void)setTextAreasAreResizable:(BOOL)flag
1327 {
1328     [self _setBoolValue: flag forKey: WebKitTextAreasAreResizablePreferenceKey];
1329 }
1330 #endif // !PLATFORM(IOS)
1331
1332 - (BOOL)shrinksStandaloneImagesToFit
1333 {
1334     return [self _boolValueForKey:WebKitShrinksStandaloneImagesToFitPreferenceKey];
1335 }
1336
1337 - (void)setShrinksStandaloneImagesToFit:(BOOL)flag
1338 {
1339     [self _setBoolValue:flag forKey:WebKitShrinksStandaloneImagesToFitPreferenceKey];
1340 }
1341
1342 - (BOOL)automaticallyDetectsCacheModel
1343 {
1344     return _private->automaticallyDetectsCacheModel;
1345 }
1346
1347 - (void)setAutomaticallyDetectsCacheModel:(BOOL)automaticallyDetectsCacheModel
1348 {
1349     _private->automaticallyDetectsCacheModel = automaticallyDetectsCacheModel;
1350 }
1351
1352 - (BOOL)usesEncodingDetector
1353 {
1354     return [self _boolValueForKey: WebKitUsesEncodingDetectorPreferenceKey];
1355 }
1356
1357 - (void)setUsesEncodingDetector:(BOOL)flag
1358 {
1359     [self _setBoolValue: flag forKey: WebKitUsesEncodingDetectorPreferenceKey];
1360 }
1361
1362 - (BOOL)isWebSecurityEnabled
1363 {
1364     return [self _boolValueForKey: WebKitWebSecurityEnabledPreferenceKey];
1365 }
1366
1367 - (void)setWebSecurityEnabled:(BOOL)flag
1368 {
1369     [self _setBoolValue: flag forKey: WebKitWebSecurityEnabledPreferenceKey];
1370 }
1371
1372 - (BOOL)allowUniversalAccessFromFileURLs
1373 {
1374     return [self _boolValueForKey: WebKitAllowUniversalAccessFromFileURLsPreferenceKey];
1375 }
1376
1377 - (void)setAllowUniversalAccessFromFileURLs:(BOOL)flag
1378 {
1379     [self _setBoolValue: flag forKey: WebKitAllowUniversalAccessFromFileURLsPreferenceKey];
1380 }
1381
1382 - (BOOL)allowFileAccessFromFileURLs
1383 {
1384     return [self _boolValueForKey: WebKitAllowFileAccessFromFileURLsPreferenceKey];
1385 }
1386
1387 - (void)setAllowFileAccessFromFileURLs:(BOOL)flag
1388 {
1389     [self _setBoolValue: flag forKey: WebKitAllowFileAccessFromFileURLsPreferenceKey];
1390 }
1391
1392 - (NSTimeInterval)_backForwardCacheExpirationInterval
1393 {
1394     return (NSTimeInterval)[self _floatValueForKey:WebKitBackForwardCacheExpirationIntervalKey];
1395 }
1396
1397 #if PLATFORM(IOS)
1398 - (BOOL)_standalone
1399 {
1400     return [self _boolValueForKey:WebKitStandalonePreferenceKey];
1401 }
1402
1403 - (void)_setStandalone:(BOOL)flag
1404 {
1405     [self _setBoolValue:flag forKey:WebKitStandalonePreferenceKey];
1406 }
1407
1408 - (void)_setTelephoneNumberParsingEnabled:(BOOL)flag
1409 {
1410     [self _setBoolValue:flag forKey:WebKitTelephoneParsingEnabledPreferenceKey];
1411 }
1412
1413 - (BOOL)_telephoneNumberParsingEnabled
1414 {
1415     return [self _boolValueForKey:WebKitTelephoneParsingEnabledPreferenceKey];
1416 }
1417 #endif
1418
1419 #if ENABLE(IOS_TEXT_AUTOSIZING)
1420 - (void)_setMinimumZoomFontSize:(float)size
1421 {
1422     [self _setFloatValue:size forKey:WebKitMinimumZoomFontSizePreferenceKey];
1423 }
1424
1425 - (float)_minimumZoomFontSize
1426 {
1427     return [self _floatValueForKey:WebKitMinimumZoomFontSizePreferenceKey];
1428 }
1429 #endif
1430
1431 #if PLATFORM(IOS)
1432 - (void)_setLayoutInterval:(int)l
1433 {
1434     [self _setIntegerValue:l forKey:WebKitLayoutIntervalPreferenceKey];
1435 }
1436
1437 - (int)_layoutInterval
1438 {
1439     return [self _integerValueForKey:WebKitLayoutIntervalPreferenceKey];
1440 }
1441
1442 - (void)_setMaxParseDuration:(float)d
1443 {
1444     [self _setFloatValue:d forKey:WebKitMaxParseDurationPreferenceKey];
1445 }
1446
1447 - (float)_maxParseDuration
1448 {
1449     return [self _floatValueForKey:WebKitMaxParseDurationPreferenceKey];
1450 }
1451
1452 - (void)_setPageCacheSize:(int)size
1453 {
1454     [self _setIntegerValue:size forKey:WebKitPageCacheSizePreferenceKey];
1455 }
1456
1457 - (int)_pageCacheSize
1458 {
1459     return [self _integerValueForKey:WebKitPageCacheSizePreferenceKey];
1460 }
1461
1462 - (void)_setObjectCacheSize:(int)size
1463 {
1464     [self _setIntegerValue:size forKey:WebKitObjectCacheSizePreferenceKey];
1465 }
1466
1467 - (int)_objectCacheSize
1468 {
1469     return [self _integerValueForKey:WebKitObjectCacheSizePreferenceKey];
1470 }
1471
1472 - (void)_setNSURLMemoryCacheSize:(int)size
1473 {
1474     [self _setIntegerValue:size forKey:WebKitNSURLMemoryCacheSizePreferenceKey];
1475 }
1476
1477 - (int)_NSURLMemoryCacheSize
1478 {
1479     return [self _integerValueForKey:WebKitNSURLMemoryCacheSizePreferenceKey];
1480 }
1481
1482 - (void)_setNSURLDiskCacheSize:(int)size
1483 {
1484     [self _setIntegerValue:size forKey:WebKitNSURLDiskCacheSizePreferenceKey];
1485 }
1486
1487 - (int)_NSURLDiskCacheSize
1488 {
1489     return [self _integerValueForKey:WebKitNSURLDiskCacheSizePreferenceKey];
1490 }
1491
1492 - (void)_setAlwaysUseBaselineOfPrimaryFont:(BOOL)flag
1493 {
1494     [self _setBoolValue:flag forKey:WebKitAlwaysUseBaselineOfPrimaryFontPreferenceKey];
1495 }
1496
1497 - (BOOL)_alwaysUseBaselineOfPrimaryFont
1498 {
1499     return [self _boolValueForKey:WebKitAlwaysUseBaselineOfPrimaryFontPreferenceKey];
1500 }
1501
1502 - (void)_setAllowMultiElementImplicitFormSubmission:(BOOL)flag
1503 {
1504     [self _setBoolValue:flag forKey:WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey];
1505 }
1506
1507 - (BOOL)_allowMultiElementImplicitFormSubmission
1508 {
1509     return [self _boolValueForKey:WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey];
1510 }
1511
1512 - (void)_setAlwaysRequestGeolocationPermission:(BOOL)flag
1513 {
1514     [self _setBoolValue:flag forKey:WebKitAlwaysRequestGeolocationPermissionPreferenceKey];
1515 }
1516
1517 - (BOOL)_alwaysRequestGeolocationPermission
1518 {
1519     return [self _boolValueForKey:WebKitAlwaysRequestGeolocationPermissionPreferenceKey];
1520 }
1521
1522 - (void)_setAlwaysUseAcceleratedOverflowScroll:(BOOL)flag
1523 {
1524     [self _setBoolValue:flag forKey:WebKitAlwaysUseAcceleratedOverflowScrollPreferenceKey];
1525 }
1526
1527 - (BOOL)_alwaysUseAcceleratedOverflowScroll
1528 {
1529     return [self _boolValueForKey:WebKitAlwaysUseAcceleratedOverflowScrollPreferenceKey];
1530 }
1531
1532 - (void)_setInterpolationQuality:(int)quality
1533 {
1534     [self _setIntegerValue:quality forKey:WebKitInterpolationQualityPreferenceKey];
1535 }
1536
1537 - (int)_interpolationQuality
1538 {
1539     return [self _integerValueForKey:WebKitInterpolationQualityPreferenceKey];
1540 }
1541
1542 - (BOOL)_allowPasswordEcho
1543 {
1544     return [self _boolValueForKey:WebKitPasswordEchoEnabledPreferenceKey];
1545 }
1546
1547 - (float)_passwordEchoDuration
1548 {
1549     return [self _floatValueForKey:WebKitPasswordEchoDurationPreferenceKey];
1550 }
1551
1552 #endif // PLATFORM(IOS)
1553
1554 #if !PLATFORM(IOS)
1555 - (float)PDFScaleFactor
1556 {
1557     return [self _floatValueForKey:WebKitPDFScaleFactorPreferenceKey];
1558 }
1559
1560 - (void)setPDFScaleFactor:(float)factor
1561 {
1562     [self _setFloatValue:factor forKey:WebKitPDFScaleFactorPreferenceKey];
1563 }
1564 #endif
1565
1566 - (int64_t)applicationCacheTotalQuota
1567 {
1568     return [self _longLongValueForKey:WebKitApplicationCacheTotalQuota];
1569 }
1570
1571 - (void)setApplicationCacheTotalQuota:(int64_t)quota
1572 {
1573     [self _setLongLongValue:quota forKey:WebKitApplicationCacheTotalQuota];
1574
1575     // Application Cache Preferences are stored on the global cache storage manager, not in Settings.
1576     [WebApplicationCache setMaximumSize:quota];
1577 }
1578
1579 - (int64_t)applicationCacheDefaultOriginQuota
1580 {
1581     return [self _longLongValueForKey:WebKitApplicationCacheDefaultOriginQuota];
1582 }
1583
1584 - (void)setApplicationCacheDefaultOriginQuota:(int64_t)quota
1585 {
1586     [self _setLongLongValue:quota forKey:WebKitApplicationCacheDefaultOriginQuota];
1587 }
1588
1589 #if !PLATFORM(IOS)
1590 - (PDFDisplayMode)PDFDisplayMode
1591 {
1592     PDFDisplayMode value = [self _integerValueForKey:WebKitPDFDisplayModePreferenceKey];
1593     if (value != kPDFDisplaySinglePage && value != kPDFDisplaySinglePageContinuous && value != kPDFDisplayTwoUp && value != kPDFDisplayTwoUpContinuous) {
1594         // protect against new modes from future versions of OS X stored in defaults
1595         value = kPDFDisplaySinglePageContinuous;
1596     }
1597     return value;
1598 }
1599
1600 - (void)setPDFDisplayMode:(PDFDisplayMode)mode
1601 {
1602     [self _setIntegerValue:mode forKey:WebKitPDFDisplayModePreferenceKey];
1603 }
1604 #endif
1605
1606 - (WebKitEditableLinkBehavior)editableLinkBehavior
1607 {
1608     WebKitEditableLinkBehavior value = static_cast<WebKitEditableLinkBehavior> ([self _integerValueForKey:WebKitEditableLinkBehaviorPreferenceKey]);
1609     if (value != WebKitEditableLinkDefaultBehavior &&
1610         value != WebKitEditableLinkAlwaysLive &&
1611         value != WebKitEditableLinkNeverLive &&
1612         value != WebKitEditableLinkOnlyLiveWithShiftKey &&
1613         value != WebKitEditableLinkLiveWhenNotFocused) {
1614         // ensure that a valid result is returned
1615         value = WebKitEditableLinkDefaultBehavior;
1616     }
1617     
1618     return value;
1619 }
1620
1621 - (void)setEditableLinkBehavior:(WebKitEditableLinkBehavior)behavior
1622 {
1623     [self _setIntegerValue:behavior forKey:WebKitEditableLinkBehaviorPreferenceKey];
1624 }
1625
1626 - (WebTextDirectionSubmenuInclusionBehavior)textDirectionSubmenuInclusionBehavior
1627 {
1628     WebTextDirectionSubmenuInclusionBehavior value = static_cast<WebTextDirectionSubmenuInclusionBehavior>([self _integerValueForKey:WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey]);
1629     if (value != WebTextDirectionSubmenuNeverIncluded &&
1630         value != WebTextDirectionSubmenuAutomaticallyIncluded &&
1631         value != WebTextDirectionSubmenuAlwaysIncluded) {
1632         // Ensure that a valid result is returned.
1633         value = WebTextDirectionSubmenuNeverIncluded;
1634     }
1635     return value;
1636 }
1637
1638 - (void)setTextDirectionSubmenuInclusionBehavior:(WebTextDirectionSubmenuInclusionBehavior)behavior
1639 {
1640     [self _setIntegerValue:behavior forKey:WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey];
1641 }
1642
1643 - (BOOL)_useSiteSpecificSpoofing
1644 {
1645     return [self _boolValueForKey:WebKitUseSiteSpecificSpoofingPreferenceKey];
1646 }
1647
1648 - (void)_setUseSiteSpecificSpoofing:(BOOL)newValue
1649 {
1650     [self _setBoolValue:newValue forKey:WebKitUseSiteSpecificSpoofingPreferenceKey];
1651 }
1652
1653 - (BOOL)databasesEnabled
1654 {
1655     return [self _boolValueForKey:WebKitDatabasesEnabledPreferenceKey];
1656 }
1657
1658 - (void)setDatabasesEnabled:(BOOL)databasesEnabled
1659 {
1660     [self _setBoolValue:databasesEnabled forKey:WebKitDatabasesEnabledPreferenceKey];
1661 }
1662
1663 #if PLATFORM(IOS)
1664 - (BOOL)storageTrackerEnabled
1665 {
1666     return [self _boolValueForKey:WebKitStorageTrackerEnabledPreferenceKey];
1667 }
1668
1669 - (void)setStorageTrackerEnabled:(BOOL)storageTrackerEnabled
1670 {
1671     [self _setBoolValue:storageTrackerEnabled forKey:WebKitStorageTrackerEnabledPreferenceKey];
1672 }
1673 #endif
1674
1675 - (BOOL)localStorageEnabled
1676 {
1677     return [self _boolValueForKey:WebKitLocalStorageEnabledPreferenceKey];
1678 }
1679
1680 - (void)setLocalStorageEnabled:(BOOL)localStorageEnabled
1681 {
1682     [self _setBoolValue:localStorageEnabled forKey:WebKitLocalStorageEnabledPreferenceKey];
1683 }
1684
1685 - (BOOL)experimentalNotificationsEnabled
1686 {
1687     return [self _boolValueForKey:WebKitExperimentalNotificationsEnabledPreferenceKey];
1688 }
1689
1690 - (void)setExperimentalNotificationsEnabled:(BOOL)experimentalNotificationsEnabled
1691 {
1692     [self _setBoolValue:experimentalNotificationsEnabled forKey:WebKitExperimentalNotificationsEnabledPreferenceKey];
1693 }
1694
1695 + (WebPreferences *)_getInstanceForIdentifier:(NSString *)ident
1696 {
1697     LOG(Encoding, "requesting for %@\n", ident);
1698
1699     if (!ident)
1700         return _standardPreferences;
1701     
1702     WebPreferences *instance = [webPreferencesInstances objectForKey:[self _concatenateKeyWithIBCreatorID:ident]];
1703
1704     return instance;
1705 }
1706
1707 + (void)_setInstance:(WebPreferences *)instance forIdentifier:(NSString *)ident
1708 {
1709     if (!webPreferencesInstances)
1710         webPreferencesInstances = [[NSMutableDictionary alloc] init];
1711     if (ident) {
1712         [webPreferencesInstances setObject:instance forKey:[self _concatenateKeyWithIBCreatorID:ident]];
1713         LOG(Encoding, "recording %p for %@\n", instance, [self _concatenateKeyWithIBCreatorID:ident]);
1714     }
1715 }
1716
1717 + (void)_checkLastReferenceForIdentifier:(id)identifier
1718 {
1719     // FIXME: This won't work at all under garbage collection because retainCount returns a constant.
1720     // We may need to change WebPreferences API so there's an explicit way to end the lifetime of one.
1721     WebPreferences *instance = [webPreferencesInstances objectForKey:identifier];
1722     if ([instance retainCount] == 1)
1723         [webPreferencesInstances removeObjectForKey:identifier];
1724 }
1725
1726 + (void)_removeReferenceForIdentifier:(NSString *)ident
1727 {
1728     if (ident)
1729         [self performSelector:@selector(_checkLastReferenceForIdentifier:) withObject:[self _concatenateKeyWithIBCreatorID:ident] afterDelay:0.1];
1730 }
1731
1732 - (void)_postPreferencesChangedNotification
1733 {
1734 #if !PLATFORM(IOS)
1735     if (!pthread_main_np()) {
1736         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1737         return;
1738     }
1739 #endif
1740
1741     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedInternalNotification object:self userInfo:nil];
1742     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedNotification object:self userInfo:nil];
1743 }
1744
1745 - (void)_postPreferencesChangedAPINotification
1746 {
1747     if (!pthread_main_np()) {
1748         [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
1749         return;
1750     }
1751
1752     [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesChangedNotification object:self userInfo:nil];
1753 }
1754
1755 + (CFStringEncoding)_systemCFStringEncoding
1756 {
1757     return WKGetWebDefaultCFStringEncoding();
1758 }
1759
1760 + (void)_setInitialDefaultTextEncodingToSystemEncoding
1761 {
1762     NSString *systemEncodingName = (NSString *)CFStringConvertEncodingToIANACharSetName([self _systemCFStringEncoding]);
1763
1764     // CFStringConvertEncodingToIANACharSetName() returns cp949 for kTextEncodingDOSKorean AKA "extended EUC-KR" AKA windows-949.
1765     // ICU uses this name for a different encoding, so we need to change the name to a value that actually gives us windows-949.
1766     // In addition, this value must match what is used in Safari, see <rdar://problem/5579292>.
1767     // On some OS versions, the result is CP949 (uppercase).
1768     if ([systemEncodingName _webkit_isCaseInsensitiveEqualToString:@"cp949"])
1769         systemEncodingName = @"ks_c_5601-1987";
1770     [[NSUserDefaults standardUserDefaults] registerDefaults:
1771         [NSDictionary dictionaryWithObject:systemEncodingName forKey:WebKitDefaultTextEncodingNamePreferenceKey]];
1772 }
1773
1774 static NSString *classIBCreatorID = nil;
1775
1776 + (void)_setIBCreatorID:(NSString *)string
1777 {
1778     NSString *old = classIBCreatorID;
1779     classIBCreatorID = [string copy];
1780     [old release];
1781 }
1782
1783 + (void)_switchNetworkLoaderToNewTestingSession
1784 {
1785     NetworkStorageSession::switchToNewTestingSession();
1786 }
1787
1788 + (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy
1789 {
1790     WKSetHTTPCookieAcceptPolicy(NetworkStorageSession::defaultStorageSession().cookieStorage().get(), policy);
1791 }
1792
1793 - (BOOL)isDOMPasteAllowed
1794 {
1795     return [self _boolValueForKey:WebKitDOMPasteAllowedPreferenceKey];
1796 }
1797
1798 - (void)setDOMPasteAllowed:(BOOL)DOMPasteAllowed
1799 {
1800     [self _setBoolValue:DOMPasteAllowed forKey:WebKitDOMPasteAllowedPreferenceKey];
1801 }
1802
1803 - (NSString *)_localStorageDatabasePath
1804 {
1805     return [[self _stringValueForKey:WebKitLocalStorageDatabasePathPreferenceKey] stringByStandardizingPath];
1806 }
1807
1808 - (void)_setLocalStorageDatabasePath:(NSString *)path
1809 {
1810     [self _setStringValue:[path stringByStandardizingPath] forKey:WebKitLocalStorageDatabasePathPreferenceKey];
1811 }
1812
1813 - (NSString *)_ftpDirectoryTemplatePath
1814 {
1815     return [[self _stringValueForKey:WebKitFTPDirectoryTemplatePath] stringByStandardizingPath];
1816 }
1817
1818 - (void)_setFTPDirectoryTemplatePath:(NSString *)path
1819 {
1820     [self _setStringValue:[path stringByStandardizingPath] forKey:WebKitFTPDirectoryTemplatePath];
1821 }
1822
1823 - (BOOL)_forceFTPDirectoryListings
1824 {
1825     return [self _boolValueForKey:WebKitForceFTPDirectoryListings];
1826 }
1827
1828 - (void)_setForceFTPDirectoryListings:(BOOL)force
1829 {
1830     [self _setBoolValue:force forKey:WebKitForceFTPDirectoryListings];
1831 }
1832
1833 - (BOOL)acceleratedDrawingEnabled
1834 {
1835     return [self _boolValueForKey:WebKitAcceleratedDrawingEnabledPreferenceKey];
1836 }
1837
1838 - (void)setAcceleratedDrawingEnabled:(BOOL)enabled
1839 {
1840     [self _setBoolValue:enabled forKey:WebKitAcceleratedDrawingEnabledPreferenceKey];
1841 }
1842
1843 - (BOOL)canvasUsesAcceleratedDrawing
1844 {
1845     return [self _boolValueForKey:WebKitCanvasUsesAcceleratedDrawingPreferenceKey];
1846 }
1847
1848 - (void)setCanvasUsesAcceleratedDrawing:(BOOL)enabled
1849 {
1850     [self _setBoolValue:enabled forKey:WebKitCanvasUsesAcceleratedDrawingPreferenceKey];
1851 }
1852
1853 - (BOOL)acceleratedCompositingEnabled
1854 {
1855     return [self _boolValueForKey:WebKitAcceleratedCompositingEnabledPreferenceKey];
1856 }
1857
1858 - (void)setAcceleratedCompositingEnabled:(BOOL)enabled
1859 {
1860     [self _setBoolValue:enabled forKey:WebKitAcceleratedCompositingEnabledPreferenceKey];
1861 }
1862
1863 - (BOOL)cssRegionsEnabled
1864 {
1865     return [self _boolValueForKey:WebKitCSSRegionsEnabledPreferenceKey];
1866 }
1867
1868 - (void)setCSSRegionsEnabled:(BOOL)enabled
1869 {
1870     [self _setBoolValue:enabled forKey:WebKitCSSRegionsEnabledPreferenceKey];
1871 }
1872
1873 - (BOOL)cssCompositingEnabled
1874 {
1875     return [self _boolValueForKey:WebKitCSSCompositingEnabledPreferenceKey];
1876 }
1877
1878 - (void)setCSSCompositingEnabled:(BOOL)enabled
1879 {
1880     [self _setBoolValue:enabled forKey:WebKitCSSCompositingEnabledPreferenceKey];
1881 }
1882
1883 - (BOOL)showDebugBorders
1884 {
1885     return [self _boolValueForKey:WebKitShowDebugBordersPreferenceKey];
1886 }
1887
1888 - (void)setShowDebugBorders:(BOOL)enabled
1889 {
1890     [self _setBoolValue:enabled forKey:WebKitShowDebugBordersPreferenceKey];
1891 }
1892
1893 - (BOOL)showRepaintCounter
1894 {
1895     return [self _boolValueForKey:WebKitShowRepaintCounterPreferenceKey];
1896 }
1897
1898 - (void)setShowRepaintCounter:(BOOL)enabled
1899 {
1900     [self _setBoolValue:enabled forKey:WebKitShowRepaintCounterPreferenceKey];
1901 }
1902
1903 - (BOOL)webAudioEnabled
1904 {
1905     return [self _boolValueForKey:WebKitWebAudioEnabledPreferenceKey];
1906 }
1907
1908 - (void)setWebAudioEnabled:(BOOL)enabled
1909 {
1910     [self _setBoolValue:enabled forKey:WebKitWebAudioEnabledPreferenceKey];
1911 }
1912
1913 - (BOOL)subpixelCSSOMElementMetricsEnabled
1914 {
1915     return [self _boolValueForKey:WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey];
1916 }
1917
1918 - (void)setSubpixelCSSOMElementMetricsEnabled:(BOOL)enabled
1919 {
1920     [self _setBoolValue:enabled forKey:WebKitSubpixelCSSOMElementMetricsEnabledPreferenceKey];
1921 }
1922
1923 - (BOOL)webGLEnabled
1924 {
1925     return [self _boolValueForKey:WebKitWebGLEnabledPreferenceKey];
1926 }
1927
1928 - (void)setWebGLEnabled:(BOOL)enabled
1929 {
1930     [self _setBoolValue:enabled forKey:WebKitWebGLEnabledPreferenceKey];
1931 }
1932
1933 - (BOOL)multithreadedWebGLEnabled
1934 {
1935     return [self _boolValueForKey:WebKitMultithreadedWebGLEnabledPreferenceKey];
1936 }
1937
1938 - (void)setMultithreadedWebGLEnabled:(BOOL)enabled
1939 {
1940     [self _setBoolValue:enabled forKey:WebKitMultithreadedWebGLEnabledPreferenceKey];
1941 }
1942
1943 - (BOOL)forceSoftwareWebGLRendering
1944 {
1945     return [self _boolValueForKey:WebKitForceSoftwareWebGLRenderingPreferenceKey];
1946 }
1947
1948 - (void)setForceSoftwareWebGLRendering:(BOOL)forced
1949 {
1950     [self _setBoolValue:forced forKey:WebKitForceSoftwareWebGLRenderingPreferenceKey];
1951 }
1952
1953 - (BOOL)accelerated2dCanvasEnabled
1954 {
1955     return [self _boolValueForKey:WebKitAccelerated2dCanvasEnabledPreferenceKey];
1956 }
1957
1958 - (void)setAccelerated2dCanvasEnabled:(BOOL)enabled
1959 {
1960     [self _setBoolValue:enabled forKey:WebKitAccelerated2dCanvasEnabledPreferenceKey];
1961 }
1962
1963 #if ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
1964 - (BOOL)diskImageCacheEnabled
1965 {
1966     return [self _boolValueForKey:WebKitDiskImageCacheEnabledPreferenceKey];
1967 }
1968
1969 - (void)setDiskImageCacheEnabled:(BOOL)enabled
1970 {
1971     [self _setBoolValue:enabled forKey:WebKitDiskImageCacheEnabledPreferenceKey];
1972 }
1973
1974 - (unsigned)diskImageCacheMinimumImageSize
1975 {
1976     return [self _integerValueForKey:WebKitDiskImageCacheMinimumImageSizePreferenceKey];
1977 }
1978
1979 - (void)setDiskImageCacheMinimumImageSize:(unsigned)minimumSize
1980 {
1981     [self _setIntegerValue:minimumSize forKey:WebKitDiskImageCacheMinimumImageSizePreferenceKey];
1982 }
1983
1984 - (unsigned)diskImageCacheMaximumCacheSize
1985 {
1986     return [self _integerValueForKey:WebKitDiskImageCacheMaximumCacheSizePreferenceKey];
1987 }
1988
1989 - (void)setDiskImageCacheMaximumCacheSize:(unsigned)maximumSize
1990 {
1991     [self _setIntegerValue:maximumSize forKey:WebKitDiskImageCacheMaximumCacheSizePreferenceKey];
1992 }
1993
1994 - (NSString *)_diskImageCacheSavedCacheDirectory
1995 {
1996     return [[self _stringValueForKey:WebKitDiskImageCacheSavedCacheDirectoryKey] stringByStandardizingPath];
1997 }
1998
1999 - (void)_setDiskImageCacheSavedCacheDirectory:(NSString *)path
2000 {
2001     [self _setStringValue:[path stringByStandardizingPath] forKey:WebKitDiskImageCacheSavedCacheDirectoryKey];
2002 }
2003 #endif // ENABLE(DISK_IMAGE_CACHE) && PLATFORM(IOS)
2004
2005 - (BOOL)isFrameFlatteningEnabled
2006 {
2007     return [self _boolValueForKey:WebKitFrameFlatteningEnabledPreferenceKey];
2008 }
2009
2010 - (void)setFrameFlatteningEnabled:(BOOL)flag
2011 {
2012     [self _setBoolValue:flag forKey:WebKitFrameFlatteningEnabledPreferenceKey];
2013 }
2014
2015 - (BOOL)isSpatialNavigationEnabled
2016 {
2017     return [self _boolValueForKey:WebKitSpatialNavigationEnabledPreferenceKey];
2018 }
2019
2020 - (void)setSpatialNavigationEnabled:(BOOL)flag
2021 {
2022     [self _setBoolValue:flag forKey:WebKitSpatialNavigationEnabledPreferenceKey];
2023 }
2024
2025 - (BOOL)paginateDuringLayoutEnabled
2026 {
2027     return [self _boolValueForKey:WebKitPaginateDuringLayoutEnabledPreferenceKey];
2028 }
2029
2030 - (void)setPaginateDuringLayoutEnabled:(BOOL)flag
2031 {
2032     [self _setBoolValue:flag forKey:WebKitPaginateDuringLayoutEnabledPreferenceKey];
2033 }
2034
2035 - (BOOL)hyperlinkAuditingEnabled
2036 {
2037     return [self _boolValueForKey:WebKitHyperlinkAuditingEnabledPreferenceKey];
2038 }
2039
2040 - (void)setHyperlinkAuditingEnabled:(BOOL)flag
2041 {
2042     [self _setBoolValue:flag forKey:WebKitHyperlinkAuditingEnabledPreferenceKey];
2043 }
2044
2045 - (BOOL)usePreHTML5ParserQuirks
2046 {
2047     return [self _boolValueForKey:WebKitUsePreHTML5ParserQuirksKey];
2048 }
2049
2050 - (void)setUsePreHTML5ParserQuirks:(BOOL)flag
2051 {
2052     [self _setBoolValue:flag forKey:WebKitUsePreHTML5ParserQuirksKey];
2053 }
2054
2055 - (void)didRemoveFromWebView
2056 {
2057     ASSERT(_private->numWebViews);
2058     if (--_private->numWebViews == 0)
2059         [[NSNotificationCenter defaultCenter]
2060             postNotificationName:WebPreferencesRemovedNotification
2061                           object:self
2062                         userInfo:nil];
2063 }
2064
2065 - (void)willAddToWebView
2066 {
2067     ++_private->numWebViews;
2068 }
2069
2070 - (void)_setPreferenceForTestWithValue:(NSString *)value forKey:(NSString *)key
2071 {
2072     [self _setStringValue:value forKey:key];
2073 }
2074
2075 - (void)setFullScreenEnabled:(BOOL)flag
2076 {
2077     [self _setBoolValue:flag forKey:WebKitFullScreenEnabledPreferenceKey];
2078 }
2079
2080 - (BOOL)fullScreenEnabled
2081 {
2082     return [self _boolValueForKey:WebKitFullScreenEnabledPreferenceKey];
2083 }
2084
2085 - (void)setAsynchronousSpellCheckingEnabled:(BOOL)flag
2086 {
2087     [self _setBoolValue:flag forKey:WebKitAsynchronousSpellCheckingEnabledPreferenceKey];
2088 }
2089
2090 - (BOOL)asynchronousSpellCheckingEnabled
2091 {
2092     return [self _boolValueForKey:WebKitAsynchronousSpellCheckingEnabledPreferenceKey];
2093 }
2094
2095 + (void)setWebKitLinkTimeVersion:(int)version
2096 {
2097     setWebKitLinkTimeVersion(version);
2098 }
2099
2100 - (void)setLoadsSiteIconsIgnoringImageLoadingPreference: (BOOL)flag
2101 {
2102     [self _setBoolValue: flag forKey: WebKitLoadSiteIconsKey];
2103 }
2104
2105 - (BOOL)loadsSiteIconsIgnoringImageLoadingPreference
2106 {
2107     return [self _boolValueForKey: WebKitLoadSiteIconsKey];
2108 }
2109
2110 - (void)setAVFoundationEnabled:(BOOL)flag
2111 {
2112     [self _setBoolValue:flag forKey:WebKitAVFoundationEnabledKey];
2113 }
2114
2115 - (BOOL)isAVFoundationEnabled
2116 {
2117     return [self _boolValueForKey:WebKitAVFoundationEnabledKey];
2118 }
2119
2120 - (void)setQTKitEnabled:(BOOL)flag
2121 {
2122     [self _setBoolValue:flag forKey:WebKitQTKitEnabledPreferenceKey];
2123 }
2124
2125 - (BOOL)isQTKitEnabled
2126 {
2127     return [self _boolValueForKey:WebKitQTKitEnabledPreferenceKey];
2128 }
2129
2130 - (void)setVideoPluginProxyEnabled:(BOOL)flag
2131 {
2132     // No-op, left for SPI compatibility.
2133 }
2134
2135 - (BOOL)isVideoPluginProxyEnabled
2136 {
2137     return NO;
2138 }
2139
2140 - (void)setHixie76WebSocketProtocolEnabled:(BOOL)flag
2141 {
2142 }
2143
2144 - (BOOL)isHixie76WebSocketProtocolEnabled
2145 {
2146     return false;
2147 }
2148
2149 - (BOOL)isInheritURIQueryComponentEnabled
2150 {
2151     return [self _boolValueForKey: WebKitEnableInheritURIQueryComponentPreferenceKey];
2152 }
2153
2154 - (void)setEnableInheritURIQueryComponent:(BOOL)flag
2155 {
2156     [self _setBoolValue:flag forKey: WebKitEnableInheritURIQueryComponentPreferenceKey];
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)setShouldRespectImageOrientation:(BOOL)flag
2392 {
2393     [self _setBoolValue:flag forKey:WebKitShouldRespectImageOrientationKey];
2394 }
2395
2396 - (BOOL)shouldRespectImageOrientation
2397 {
2398     return [self _boolValueForKey:WebKitShouldRespectImageOrientationKey];
2399 }
2400
2401 - (BOOL)requestAnimationFrameEnabled
2402 {
2403     return [self _boolValueForKey:WebKitRequestAnimationFrameEnabledPreferenceKey];
2404 }
2405
2406 - (void)setRequestAnimationFrameEnabled:(BOOL)enabled
2407 {
2408     [self _setBoolValue:enabled forKey:WebKitRequestAnimationFrameEnabledPreferenceKey];
2409 }
2410
2411 - (void)setIncrementalRenderingSuppressionTimeoutInSeconds:(NSTimeInterval)timeout
2412 {
2413     [self _setFloatValue:timeout forKey:WebKitIncrementalRenderingSuppressionTimeoutInSecondsKey];
2414 }
2415
2416 - (NSTimeInterval)incrementalRenderingSuppressionTimeoutInSeconds
2417 {
2418     return [self _floatValueForKey:WebKitIncrementalRenderingSuppressionTimeoutInSecondsKey];
2419 }
2420
2421 - (BOOL)diagnosticLoggingEnabled
2422 {
2423     return [self _boolValueForKey:WebKitDiagnosticLoggingEnabledKey];
2424 }
2425
2426 - (void)setDiagnosticLoggingEnabled:(BOOL)enabled
2427 {
2428     [self _setBoolValue:enabled forKey:WebKitDiagnosticLoggingEnabledKey];
2429 }
2430
2431 static bool needsScreenFontsEnabledQuirk()
2432 {
2433 #if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
2434     static bool is1PasswordNeedingScreenFontsQuirk = WKExecutableWasLinkedOnOrBeforeMountainLion()
2435         && [[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"ws.agile.1Password"];
2436     return is1PasswordNeedingScreenFontsQuirk;
2437 #else
2438     return NO;
2439 #endif
2440 }
2441
2442 - (BOOL)screenFontSubstitutionEnabled
2443 {
2444     if (needsScreenFontsEnabledQuirk())
2445         return YES;
2446     return [self _boolValueForKey:WebKitScreenFontSubstitutionEnabledKey];
2447 }
2448
2449 - (void)setScreenFontSubstitutionEnabled:(BOOL)enabled
2450 {
2451     [self _setBoolValue:enabled forKey:WebKitScreenFontSubstitutionEnabledKey];
2452 }
2453
2454 - (void)setStorageBlockingPolicy:(WebStorageBlockingPolicy)storageBlockingPolicy
2455 {
2456 #if PLATFORM(IOS)
2457     // We don't want to write the setting out, so we just reset the default instead of storing the new setting.
2458     // FIXME: This code removes any defaults previously registered by client process, which is not appropriate for this method to do.
2459     NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:storageBlockingPolicy] forKey:WebKitStorageBlockingPolicyKey];
2460     [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
2461 #else
2462     [self _setIntegerValue:storageBlockingPolicy forKey:WebKitStorageBlockingPolicyKey];
2463 #endif
2464 }
2465
2466 - (WebStorageBlockingPolicy)storageBlockingPolicy
2467 {
2468     return static_cast<WebStorageBlockingPolicy>([self _integerValueForKey:WebKitStorageBlockingPolicyKey]);
2469 }
2470
2471 - (BOOL)plugInSnapshottingEnabled
2472 {
2473     return [self _boolValueForKey:WebKitPlugInSnapshottingEnabledPreferenceKey];
2474 }
2475
2476 - (void)setPlugInSnapshottingEnabled:(BOOL)enabled
2477 {
2478     [self _setBoolValue:enabled forKey:WebKitPlugInSnapshottingEnabledPreferenceKey];
2479 }
2480
2481 - (BOOL)hiddenPageDOMTimerThrottlingEnabled
2482 {
2483     return [self _boolValueForKey:WebKitHiddenPageDOMTimerThrottlingEnabledPreferenceKey];
2484 }
2485
2486 - (void)setHiddenPageDOMTimerThrottlingEnabled:(BOOL)enabled
2487 {
2488     [self _setBoolValue:enabled forKey:WebKitHiddenPageDOMTimerThrottlingEnabledPreferenceKey];
2489 }
2490
2491 - (BOOL)hiddenPageCSSAnimationSuspensionEnabled
2492 {
2493     return [self _boolValueForKey:WebKitHiddenPageCSSAnimationSuspensionEnabledPreferenceKey];
2494 }
2495
2496 - (void)setHiddenPageCSSAnimationSuspensionEnabled:(BOOL)enabled
2497 {
2498     [self _setBoolValue:enabled forKey:WebKitHiddenPageCSSAnimationSuspensionEnabledPreferenceKey];
2499 }
2500
2501 - (BOOL)lowPowerVideoAudioBufferSizeEnabled
2502 {
2503     return [self _boolValueForKey:WebKitLowPowerVideoAudioBufferSizeEnabledPreferenceKey];
2504 }
2505
2506 - (void)setLowPowerVideoAudioBufferSizeEnabled:(BOOL)enabled
2507 {
2508     [self _setBoolValue:enabled forKey:WebKitLowPowerVideoAudioBufferSizeEnabledPreferenceKey];
2509 }
2510
2511 - (BOOL)useLegacyTextAlignPositionedElementBehavior
2512 {
2513     return [self _boolValueForKey:WebKitUseLegacyTextAlignPositionedElementBehaviorPreferenceKey];
2514 }
2515
2516 - (void)setUseLegacyTextAlignPositionedElementBehavior:(BOOL)enabled
2517 {
2518     [self _setBoolValue:enabled forKey:WebKitUseLegacyTextAlignPositionedElementBehaviorPreferenceKey];
2519 }
2520
2521 - (BOOL)mediaSourceEnabled
2522 {
2523     return [self _boolValueForKey:WebKitMediaSourceEnabledPreferenceKey];
2524 }
2525
2526 - (void)setMediaSourceEnabled:(BOOL)enabled
2527 {
2528     [self _setBoolValue:enabled forKey:WebKitMediaSourceEnabledPreferenceKey];
2529 }
2530
2531 - (BOOL)imageControlsEnabled
2532 {
2533     return [self _boolValueForKey:WebKitImageControlsEnabledPreferenceKey];
2534 }
2535
2536 - (void)setImageControlsEnabled:(BOOL)enabled
2537 {
2538     [self _setBoolValue:enabled forKey:WebKitImageControlsEnabledPreferenceKey];
2539 }
2540
2541 - (BOOL)gamepadsEnabled
2542 {
2543     return [self _boolValueForKey:WebKitGamepadsEnabledPreferenceKey];
2544 }
2545
2546 - (void)setGamepadsEnabled:(BOOL)flag
2547 {
2548     [self _setBoolValue:flag forKey:WebKitGamepadsEnabledPreferenceKey];
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