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