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