Move NetworkStorageSession ownership to NetworkProcess
[WebKit-https.git] / Source / WebKitLegacy / win / WebPreferences.cpp
1 /*
2  * Copyright (C) 2006-2011, 2014-2015 Apple Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "WebKit.h"
27 #include "WebKitDLL.h"
28 #include "WebPreferences.h"
29
30 #include "NetworkStorageSessionMap.h"
31 #include "WebNotificationCenter.h"
32 #include "WebPreferenceKeysPrivate.h"
33
34 #if USE(CG)
35 #include <CoreGraphics/CoreGraphics.h>
36 #include <WebCore/CACFLayerTreeHost.h>
37 #endif
38
39 #include <CoreFoundation/CoreFoundation.h>
40 #include <WebCore/COMPtr.h>
41 #include <WebCore/FileSystem.h>
42 #include <WebCore/FontCascade.h>
43 #include <WebCore/LocalizedStrings.h>
44 #include <WebCore/NetworkStorageSession.h>
45 #include <limits>
46 #include <shlobj.h>
47 #include <wchar.h>
48 #include <wtf/HashMap.h>
49 #include <wtf/NeverDestroyed.h>
50 #include <wtf/StdLibExtras.h>
51 #include <wtf/text/CString.h>
52 #include <wtf/text/StringHash.h>
53 #include <wtf/text/WTFString.h>
54
55 using namespace WebCore;
56 using std::numeric_limits;
57
58 static const String& oldPreferencesPath()
59 {
60     static String path = FileSystem::pathByAppendingComponent(FileSystem::roamingUserSpecificStorageDirectory(), "WebKitPreferences.plist");
61     return path;
62 }
63
64 template<typename NumberType> struct CFNumberTraits { static const CFNumberType Type; };
65 template<> struct CFNumberTraits<int> { static const CFNumberType Type = kCFNumberSInt32Type; };
66 template<> struct CFNumberTraits<LONGLONG> { static const CFNumberType Type = kCFNumberLongLongType; };
67 template<> struct CFNumberTraits<float> { static const CFNumberType Type = kCFNumberFloat32Type; };
68
69 template<typename NumberType>
70 static NumberType numberValueForPreferencesValue(CFPropertyListRef value)
71 {
72     if (!value)
73         return 0;
74
75     CFTypeID cfType = CFGetTypeID(value);
76     if (cfType == CFStringGetTypeID())
77         return static_cast<NumberType>(CFStringGetIntValue(static_cast<CFStringRef>(value)));
78     else if (cfType == CFBooleanGetTypeID()) {
79         Boolean boolVal = CFBooleanGetValue(static_cast<CFBooleanRef>(value));
80         return boolVal ? 1 : 0;
81     } else if (cfType == CFNumberGetTypeID()) {
82         NumberType val = 0;
83         CFNumberGetValue(static_cast<CFNumberRef>(value), CFNumberTraits<NumberType>::Type, &val);
84         return val;
85     }
86
87     return 0;
88 }
89
90 template<typename NumberType>
91 static RetainPtr<CFNumberRef> cfNumber(NumberType value)
92 {
93     return adoptCF(CFNumberCreate(0, CFNumberTraits<NumberType>::Type, &value));
94 }
95
96 static bool booleanValueForPreferencesValue(CFPropertyListRef value)
97 {
98     return numberValueForPreferencesValue<int>(value);
99 }
100
101 // WebPreferences ----------------------------------------------------------------
102
103 static CFDictionaryRef defaultSettings;
104
105 RetainPtr<CFStringRef> WebPreferences::m_applicationId = kCFPreferencesCurrentApplication;
106
107 static HashMap<WTF::String, COMPtr<WebPreferences>>& webPreferencesInstances()
108 {
109     static NeverDestroyed<HashMap<WTF::String, COMPtr<WebPreferences>>> webPreferencesInstances;
110     return webPreferencesInstances;
111 }
112
113 WebPreferences* WebPreferences::sharedStandardPreferences()
114 {
115     static WebPreferences* standardPreferences;
116     if (!standardPreferences) {
117         standardPreferences = WebPreferences::createInstance();
118         standardPreferences->setAutosaves(TRUE);
119         standardPreferences->load();
120     }
121
122     return standardPreferences;
123 }
124
125 WebPreferences::WebPreferences()
126 {
127     gClassCount++;
128     gClassNameCount().add("WebPreferences");
129 }
130
131 WebPreferences::~WebPreferences()
132 {
133     gClassCount--;
134     gClassNameCount().remove("WebPreferences");
135 }
136
137 WebPreferences* WebPreferences::createInstance()
138 {
139     WebPreferences* instance = new WebPreferences();
140     instance->AddRef();
141     return instance;
142 }
143
144 HRESULT WebPreferences::postPreferencesChangesNotification()
145 {
146     IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
147     HRESULT hr = nc->postNotificationName(webPreferencesChangedNotification(), static_cast<IWebPreferences*>(this), 0);
148     if (FAILED(hr))
149         return hr;
150
151     return S_OK;
152 }
153
154 WebPreferences* WebPreferences::getInstanceForIdentifier(BSTR identifier)
155 {
156     if (!identifier)
157         return sharedStandardPreferences();
158
159     WTF::String identifierString(identifier, SysStringLen(identifier));
160     if (identifierString.isEmpty())
161         return sharedStandardPreferences();
162
163     return webPreferencesInstances().get(identifierString);
164 }
165
166 void WebPreferences::setInstance(WebPreferences* instance, BSTR identifier)
167 {
168     if (!identifier || !instance)
169         return;
170     WTF::String identifierString(identifier, SysStringLen(identifier));
171     if (identifierString.isEmpty())
172         return;
173     webPreferencesInstances().add(identifierString, instance);
174 }
175
176 void WebPreferences::removeReferenceForIdentifier(BSTR identifier)
177 {
178     if (!identifier || webPreferencesInstances().isEmpty())
179         return;
180
181     WTF::String identifierString(identifier, SysStringLen(identifier));
182     if (identifierString.isEmpty())
183         return;
184     WebPreferences* webPreference = webPreferencesInstances().get(identifierString);
185     if (webPreference && webPreference->m_refCount == 1)
186         webPreferencesInstances().remove(identifierString);
187 }
188
189 CFStringRef WebPreferences::applicationId()
190 {
191     return m_applicationId.get();
192 }
193
194 void WebPreferences::initializeDefaultSettings()
195 {
196     if (defaultSettings)
197         return;
198
199     CFMutableDictionaryRef defaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
200
201     CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman"));
202     CFDictionaryAddValue(defaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New"));
203     CFDictionaryAddValue(defaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman"));
204     CFDictionaryAddValue(defaults, CFSTR(WebKitSansSerifFontPreferenceKey), CFSTR("Arial"));
205     CFDictionaryAddValue(defaults, CFSTR(WebKitCursiveFontPreferenceKey), CFSTR("Comic Sans MS"));
206     CFDictionaryAddValue(defaults, CFSTR(WebKitFantasyFontPreferenceKey), CFSTR("Comic Sans MS"));
207     CFDictionaryAddValue(defaults, CFSTR(WebKitPictographFontPreferenceKey), CFSTR("Segoe UI Symbol"));
208     CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumFontSizePreferenceKey), CFSTR("0"));
209     CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), CFSTR("9"));
210     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFontSizePreferenceKey), CFSTR("16"));
211     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFixedFontSizePreferenceKey), CFSTR("13"));
212
213     String defaultDefaultEncoding(WEB_UI_STRING("ISO-8859-1", "The default, default character encoding on Windows"));
214     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), defaultDefaultEncoding.createCFString().get());
215
216     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), kCFBooleanFalse);
217     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetLocationPreferenceKey), CFSTR(""));
218     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), kCFBooleanFalse);
219     CFDictionaryAddValue(defaults, CFSTR(WebKitTextAreasAreResizablePreferenceKey), kCFBooleanFalse);
220     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaEnabledPreferenceKey), kCFBooleanTrue);
221     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptEnabledPreferenceKey), kCFBooleanTrue);
222     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptRuntimeFlagsPreferenceKey), CFSTR("0"));
223     CFDictionaryAddValue(defaults, CFSTR(WebKitWebSecurityEnabledPreferenceKey), kCFBooleanTrue);
224     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowUniversalAccessFromFileURLsPreferenceKey), kCFBooleanFalse);
225     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowFileAccessFromFileURLsPreferenceKey), kCFBooleanTrue);
226     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanAccessClipboardPreferenceKey), kCFBooleanFalse);
227     CFDictionaryAddValue(defaults, CFSTR(WebKitXSSAuditorEnabledPreferenceKey), kCFBooleanTrue);
228     CFDictionaryAddValue(defaults, CFSTR(WebKitFrameFlatteningEnabledPreferenceKey), kCFBooleanFalse);
229     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), kCFBooleanTrue);
230     CFDictionaryAddValue(defaults, CFSTR(WebKitPluginsEnabledPreferenceKey), kCFBooleanTrue);
231     CFDictionaryAddValue(defaults, CFSTR(WebKitCSSRegionsEnabledPreferenceKey), kCFBooleanTrue);
232     CFDictionaryAddValue(defaults, CFSTR(WebKitDatabasesEnabledPreferenceKey), kCFBooleanTrue);
233     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageEnabledPreferenceKey), kCFBooleanTrue);
234     CFDictionaryAddValue(defaults, CFSTR(WebKitExperimentalNotificationsEnabledPreferenceKey), kCFBooleanFalse);
235     CFDictionaryAddValue(defaults, CFSTR(WebKitZoomsTextOnlyPreferenceKey), kCFBooleanTrue);
236     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImagesPreferenceKey), kCFBooleanTrue);
237     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), kCFBooleanTrue);
238     CFDictionaryAddValue(defaults, CFSTR(WebKitDisplayImagesKey), kCFBooleanTrue);
239     CFDictionaryAddValue(defaults, CFSTR(WebKitLoadSiteIconsKey), kCFBooleanFalse);
240     CFDictionaryAddValue(defaults, CFSTR(WebKitBackForwardCacheExpirationIntervalKey), CFSTR("1800"));
241     CFDictionaryAddValue(defaults, CFSTR(WebKitTabToLinksPreferenceKey), kCFBooleanFalse);
242     CFDictionaryAddValue(defaults, CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), kCFBooleanFalse);
243     CFDictionaryAddValue(defaults, CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey), kCFBooleanFalse);
244     CFDictionaryAddValue(defaults, CFSTR(WebKitShowsURLsInToolTipsPreferenceKey), kCFBooleanFalse);
245     CFDictionaryAddValue(defaults, CFSTR(WebKitShowsToolTipOverTruncatedTextPreferenceKey), kCFBooleanFalse);
246     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFDisplayModePreferenceKey), CFSTR("1"));
247     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFScaleFactorPreferenceKey), CFSTR("0"));
248     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplaySubtitlesPreferenceKey), kCFBooleanFalse);
249     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplayCaptionsPreferenceKey), kCFBooleanFalse);
250     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplayTextDescriptionsPreferenceKey), kCFBooleanFalse);
251
252     RetainPtr<CFStringRef> linkBehaviorStringRef = adoptCF(CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior));
253     CFDictionaryAddValue(defaults, CFSTR(WebKitEditableLinkBehaviorPreferenceKey), linkBehaviorStringRef.get());
254
255     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryItemLimitKey), CFSTR("1000"));
256     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryAgeInDaysLimitKey), CFSTR("7"));
257     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseLocationKey), CFSTR(""));
258     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseEnabledPreferenceKey), kCFBooleanTrue);
259     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingTypePreferenceKey), CFSTR("2"));
260     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingContrastPreferenceKey), CFSTR("2"));
261     CFDictionaryAddValue(defaults, CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), CFSTR("2"));
262     CFDictionaryAddValue(defaults, CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), kCFBooleanFalse);
263     CFDictionaryAddValue(defaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse);
264     CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
265     CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
266     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageDatabasePathPreferenceKey), CFSTR(""));
267
268     RetainPtr<CFStringRef> cacheModelRef = adoptCF(CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebCacheModelDocumentViewer));
269     CFDictionaryAddValue(defaults, CFSTR(WebKitCacheModelPreferenceKey), cacheModelRef.get());
270
271     CFDictionaryAddValue(defaults, CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey), kCFBooleanTrue);
272
273     CFDictionaryAddValue(defaults, CFSTR(WebKitOfflineWebApplicationCacheEnabledPreferenceKey), kCFBooleanFalse);
274
275     CFDictionaryAddValue(defaults, CFSTR(WebKitPaintNativeControlsPreferenceKey), kCFBooleanTrue);
276
277     CFDictionaryAddValue(defaults, CFSTR(WebKitUseHighResolutionTimersPreferenceKey), kCFBooleanTrue);
278
279 #if USE(CG)
280     CFDictionaryAddValue(defaults, CFSTR(WebKitAcceleratedCompositingEnabledPreferenceKey), kCFBooleanTrue);
281 #else
282     CFDictionaryAddValue(defaults, CFSTR(WebKitAcceleratedCompositingEnabledPreferenceKey), kCFBooleanFalse);
283 #endif
284
285     CFDictionaryAddValue(defaults, CFSTR(WebKitShowDebugBordersPreferenceKey), kCFBooleanFalse);
286
287     CFDictionaryAddValue(defaults, CFSTR(WebKitSpatialNavigationEnabledPreferenceKey), kCFBooleanFalse);
288
289     CFDictionaryAddValue(defaults, CFSTR(WebKitDNSPrefetchingEnabledPreferenceKey), kCFBooleanFalse);
290
291     CFDictionaryAddValue(defaults, CFSTR(WebKitHyperlinkAuditingEnabledPreferenceKey), kCFBooleanTrue);
292
293     CFDictionaryAddValue(defaults, CFSTR(WebKitMediaPlaybackRequiresUserGesturePreferenceKey), kCFBooleanFalse);
294     CFDictionaryAddValue(defaults, CFSTR(WebKitMediaPlaybackAllowsInlinePreferenceKey), kCFBooleanTrue);
295
296     CFDictionaryAddValue(defaults, CFSTR(WebKitRequestAnimationFrameEnabledPreferenceKey), kCFBooleanTrue);
297
298     CFDictionaryAddValue(defaults, CFSTR(WebKitFullScreenEnabledPreferenceKey), kCFBooleanFalse);
299
300     CFDictionaryAddValue(defaults, CFSTR(WebKitRequestAnimationFrameEnabledPreferenceKey), kCFBooleanFalse);
301
302     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowDisplayAndRunningOfInsecureContentPreferenceKey), kCFBooleanTrue);
303
304     CFDictionaryAddValue(defaults, CFSTR(WebKitFetchAPIEnabledPreferenceKey), kCFBooleanFalse);
305
306     CFDictionaryAddValue(defaults, CFSTR(WebKitShadowDOMEnabledPreferenceKey), kCFBooleanFalse);
307
308     CFDictionaryAddValue(defaults, CFSTR(WebKitCustomElementsEnabledPreferenceKey), kCFBooleanFalse);
309
310     CFDictionaryAddValue(defaults, CFSTR(WebKitWebAnimationsEnabledPreferenceKey), kCFBooleanTrue);
311
312     CFDictionaryAddValue(defaults, CFSTR(WebKitWebAnimationsCSSIntegrationEnabledPreferenceKey), kCFBooleanFalse);
313
314     CFDictionaryAddValue(defaults, CFSTR(WebKitUserTimingEnabledPreferenceKey), kCFBooleanFalse);
315
316     CFDictionaryAddValue(defaults, CFSTR(WebKitResourceTimingEnabledPreferenceKey), kCFBooleanFalse);
317
318     CFDictionaryAddValue(defaults, CFSTR(WebKitLinkPreloadEnabledPreferenceKey), kCFBooleanFalse);
319
320     CFDictionaryAddValue(defaults, CFSTR(WebKitMediaPreloadingEnabledPreferenceKey), kCFBooleanFalse);
321
322     CFDictionaryAddValue(defaults, CFSTR(WebKitIsSecureContextAttributeEnabledPreferenceKey), kCFBooleanFalse);
323
324     CFDictionaryAddValue(defaults, CFSTR(WebKitDataTransferItemsEnabledPreferenceKey), kCFBooleanFalse);
325
326     CFDictionaryAddValue(defaults, CFSTR(WebKitInspectorAdditionsEnabledPreferenceKey), kCFBooleanFalse);
327
328     CFDictionaryAddValue(defaults, CFSTR(WebKitVisualViewportAPIEnabledPreferenceKey), kCFBooleanFalse);
329
330     CFDictionaryAddValue(defaults, CFSTR(WebKitCSSOMViewScrollingAPIEnabledPreferenceKey), kCFBooleanFalse);
331
332     defaultSettings = defaults;
333 }
334
335 RetainPtr<CFPropertyListRef> WebPreferences::valueForKey(CFStringRef key)
336 {
337     RetainPtr<CFPropertyListRef> value = CFDictionaryGetValue(m_privatePrefs.get(), key);
338     if (value)
339         return value;
340
341     value = adoptCF(CFPreferencesCopyAppValue(key, applicationId()));
342     if (value)
343         return value;
344
345     return CFDictionaryGetValue(defaultSettings, key);
346 }
347
348 void WebPreferences::setValueForKey(CFStringRef key, CFPropertyListRef value)
349 {
350     CFDictionarySetValue(m_privatePrefs.get(), key, value);
351     if (m_autoSaves) {
352         CFPreferencesSetAppValue(key, value, applicationId());
353         save();
354     }
355 }
356
357 void WebPreferences::setValueForKey(const char* key, CFPropertyListRef value)
358 {
359     RetainPtr<CFStringRef> cfKey = adoptCF(CFStringCreateWithCString(0, key, kCFStringEncodingASCII));
360     setValueForKey(cfKey.get(), value);
361 }
362
363 RetainPtr<CFPropertyListRef> WebPreferences::valueForKey(const char* key)
364 {
365     RetainPtr<CFStringRef> cfKey = adoptCF(CFStringCreateWithCString(0, key, kCFStringEncodingASCII));
366     return valueForKey(cfKey.get());
367 }
368
369 BSTR WebPreferences::stringValueForKey(const char* key)
370 {
371     RetainPtr<CFPropertyListRef> value = valueForKey(key);
372     
373     if (!value || (CFGetTypeID(value.get()) != CFStringGetTypeID()))
374         return 0;
375
376     CFStringRef str = static_cast<CFStringRef>(value.get());
377
378     CFIndex length = CFStringGetLength(str);
379     const UniChar* uniChars = CFStringGetCharactersPtr(str);
380     if (uniChars)
381         return SysAllocStringLen((LPCTSTR)uniChars, length);
382
383     BSTR bstr = SysAllocStringLen(0, length);
384     if (!bstr)
385         return 0;
386
387     if (!CFStringGetCString(str, (char*)bstr, (length+1)*sizeof(WCHAR), kCFStringEncodingUTF16)) {
388         SysFreeString(bstr);
389         return 0;
390     }
391         
392     bstr[length] = 0;
393     return bstr;
394 }
395
396 int WebPreferences::integerValueForKey(const char* key)
397 {
398     return numberValueForPreferencesValue<int>(valueForKey(key).get());
399 }
400
401 BOOL WebPreferences::boolValueForKey(const char* key)
402 {
403     return booleanValueForPreferencesValue(valueForKey(key).get());
404 }
405
406 float WebPreferences::floatValueForKey(const char* key)
407 {
408     return numberValueForPreferencesValue<float>(valueForKey(key).get());
409 }
410
411 LONGLONG WebPreferences::longlongValueForKey(const char* key)
412 {
413     return numberValueForPreferencesValue<LONGLONG>(valueForKey(key).get());
414 }
415
416 void WebPreferences::setStringValue(const char* key, BSTR value)
417 {
418     BString val;
419     val.adoptBSTR(stringValueForKey(key));
420     if (val && !wcscmp(val, value))
421         return;
422     
423     RetainPtr<CFStringRef> valueRef = adoptCF(CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(value), static_cast<CFIndex>(wcslen(value))));
424     setValueForKey(key, valueRef.get());
425
426     postPreferencesChangesNotification();
427 }
428
429 void WebPreferences::setIntegerValue(const char* key, int value)
430 {
431     if (integerValueForKey(key) == value)
432         return;
433
434     setValueForKey(key, cfNumber(value).get());
435
436     postPreferencesChangesNotification();
437 }
438
439 void WebPreferences::setFloatValue(const char* key, float value)
440 {
441     if (floatValueForKey(key) == value)
442         return;
443
444     setValueForKey(key, cfNumber(value).get());
445
446     postPreferencesChangesNotification();
447 }
448
449 void WebPreferences::setBoolValue(const char* key, BOOL value)
450 {
451     if (boolValueForKey(key) == value)
452         return;
453
454     setValueForKey(key, value ? kCFBooleanTrue : kCFBooleanFalse);
455
456     postPreferencesChangesNotification();
457 }
458
459 void WebPreferences::setLongLongValue(const char* key, LONGLONG value)
460 {
461     if (longlongValueForKey(key) == value)
462         return;
463
464     setValueForKey(key, cfNumber(value).get());
465
466     postPreferencesChangesNotification();
467 }
468
469 BSTR WebPreferences::webPreferencesChangedNotification()
470 {
471     static BSTR webPreferencesChangedNotification = SysAllocString(WebPreferencesChangedNotification);
472     return webPreferencesChangedNotification;
473 }
474
475 BSTR WebPreferences::webPreferencesRemovedNotification()
476 {
477     static BSTR webPreferencesRemovedNotification = SysAllocString(WebPreferencesRemovedNotification);
478     return webPreferencesRemovedNotification;
479 }
480
481 void WebPreferences::save()
482 {
483     CFPreferencesAppSynchronize(applicationId());
484 }
485
486 void WebPreferences::load()
487 {
488     initializeDefaultSettings();
489
490     m_privatePrefs = adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
491
492     migrateWebKitPreferencesToCFPreferences();
493 }
494
495 void WebPreferences::migrateWebKitPreferencesToCFPreferences()
496 {
497     if (boolValueForKey(WebKitDidMigrateWebKitPreferencesToCFPreferencesPreferenceKey))
498         return;
499     bool oldValue = m_autoSaves;
500     m_autoSaves = true;
501     setBoolValue(WebKitDidMigrateWebKitPreferencesToCFPreferencesPreferenceKey, TRUE);
502     m_autoSaves = oldValue;
503
504     WTF::CString path = oldPreferencesPath().utf8();
505
506     RetainPtr<CFURLRef> urlRef = adoptCF(CFURLCreateFromFileSystemRepresentation(0, reinterpret_cast<const UInt8*>(path.data()), path.length(), false));
507     if (!urlRef)
508         return;
509
510     RetainPtr<CFReadStreamRef> stream = adoptCF(CFReadStreamCreateWithFile(0, urlRef.get()));
511     if (!stream)
512         return;
513
514     if (!CFReadStreamOpen(stream.get()))
515         return;
516
517     auto format = static_cast<CFPropertyListFormat>(kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0);
518     RetainPtr<CFPropertyListRef> plist = adoptCF(CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0));
519     CFReadStreamClose(stream.get());
520
521     if (!plist || CFGetTypeID(plist.get()) != CFDictionaryGetTypeID())
522         return;
523
524     copyWebKitPreferencesToCFPreferences(static_cast<CFDictionaryRef>(plist.get()));
525
526     FileSystem::deleteFile(oldPreferencesPath());
527 }
528
529 void WebPreferences::copyWebKitPreferencesToCFPreferences(CFDictionaryRef dict)
530 {
531     ASSERT_ARG(dict, dict);
532
533     int count = CFDictionaryGetCount(dict);
534     if (count <= 0)
535         return;
536
537     CFStringRef didRemoveDefaultsKey = CFSTR(WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey);
538     bool omitDefaults = !booleanValueForPreferencesValue(CFDictionaryGetValue(dict, didRemoveDefaultsKey));
539
540     Vector<CFTypeRef> keys(count);
541     Vector<CFTypeRef> values(count);
542     CFDictionaryGetKeysAndValues(dict, keys.data(), values.data());
543
544     for (int i = 0; i < count; ++i) {
545         if (!keys[i] || !values[i] || CFGetTypeID(keys[i]) != CFStringGetTypeID())
546             continue;
547
548         if (omitDefaults) {
549             CFTypeRef defaultValue = CFDictionaryGetValue(defaultSettings, keys[i]);
550             if (defaultValue && CFEqual(defaultValue, values[i]))
551                 continue;
552         }
553
554         setValueForKey(static_cast<CFStringRef>(keys[i]), values[i]);
555     }
556 }
557
558 // IUnknown -------------------------------------------------------------------
559
560 HRESULT WebPreferences::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
561 {
562     if (!ppvObject)
563         return E_POINTER;
564     *ppvObject = nullptr;
565     if (IsEqualGUID(riid, IID_IUnknown))
566         *ppvObject = static_cast<IWebPreferences*>(this);
567     else if (IsEqualGUID(riid, IID_IWebPreferences))
568         *ppvObject = static_cast<IWebPreferences*>(this);
569     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate))
570         *ppvObject = static_cast<IWebPreferencesPrivate*>(this);
571     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate2))
572         *ppvObject = static_cast<IWebPreferencesPrivate2*>(this);
573     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate3))
574         *ppvObject = static_cast<IWebPreferencesPrivate3*>(this);
575     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate4))
576         *ppvObject = static_cast<IWebPreferencesPrivate4*>(this);
577     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate5))
578         *ppvObject = static_cast<IWebPreferencesPrivate5*>(this);
579     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate6))
580         *ppvObject = static_cast<IWebPreferencesPrivate6*>(this);
581     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate7))
582         *ppvObject = static_cast<IWebPreferencesPrivate7*>(this);
583     else if (IsEqualGUID(riid, CLSID_WebPreferences))
584         *ppvObject = this;
585     else
586         return E_NOINTERFACE;
587
588     AddRef();
589     return S_OK;
590 }
591
592 ULONG WebPreferences::AddRef()
593 {
594     return ++m_refCount;
595 }
596
597 ULONG WebPreferences::Release()
598 {
599     ULONG newRef = --m_refCount;
600     if (!newRef)
601         delete(this);
602
603     return newRef;
604 }
605
606 // IWebPreferences ------------------------------------------------------------
607
608 HRESULT WebPreferences::standardPreferences(_COM_Outptr_opt_ IWebPreferences** standardPreferences)
609 {
610     if (!standardPreferences)
611         return E_POINTER;
612     *standardPreferences = sharedStandardPreferences();
613     (*standardPreferences)->AddRef();
614     return S_OK;
615 }
616
617 HRESULT WebPreferences::initWithIdentifier(_In_ BSTR anIdentifier, _COM_Outptr_opt_ IWebPreferences** preferences)
618 {
619     WebPreferences *instance = getInstanceForIdentifier(anIdentifier);
620     if (instance) {
621         *preferences = instance;
622         instance->AddRef();
623         return S_OK;
624     }
625
626     load();
627
628     *preferences = this;
629     AddRef();
630
631     if (anIdentifier) {
632         m_identifier = anIdentifier;
633         setInstance(this, m_identifier);
634     }
635
636     this->postPreferencesChangesNotification();
637
638     return S_OK;
639 }
640
641 HRESULT WebPreferences::identifier(__deref_opt_out BSTR* ident)
642 {
643     if (!ident)
644         return E_POINTER;
645     *ident = m_identifier ? SysAllocString(m_identifier) : nullptr;
646     return S_OK;
647 }
648
649 HRESULT WebPreferences::standardFontFamily(__deref_opt_out BSTR* family)
650 {
651     if (!family)
652         return E_POINTER;
653     *family = stringValueForKey(WebKitStandardFontPreferenceKey);
654     return (*family) ? S_OK : E_FAIL;
655 }
656
657 HRESULT WebPreferences::setStandardFontFamily(_In_ BSTR family)
658 {
659     setStringValue(WebKitStandardFontPreferenceKey, family);
660     return S_OK;
661 }
662
663 HRESULT WebPreferences::fixedFontFamily(__deref_opt_out BSTR* family)
664 {
665     if (!family)
666         return E_POINTER;
667     *family = stringValueForKey(WebKitFixedFontPreferenceKey);
668     return (*family) ? S_OK : E_FAIL;
669 }
670
671 HRESULT WebPreferences::setFixedFontFamily(_In_ BSTR family)
672 {
673     setStringValue(WebKitFixedFontPreferenceKey, family);
674     return S_OK;
675 }
676
677 HRESULT WebPreferences::serifFontFamily(__deref_opt_out BSTR* fontFamily)
678 {
679     if (!fontFamily)
680         return E_POINTER;
681     *fontFamily = stringValueForKey(WebKitSerifFontPreferenceKey);
682     return (*fontFamily) ? S_OK : E_FAIL;
683 }
684
685 HRESULT WebPreferences::setSerifFontFamily(_In_ BSTR family)
686 {
687     setStringValue(WebKitSerifFontPreferenceKey, family);
688     return S_OK;
689 }
690
691 HRESULT WebPreferences::sansSerifFontFamily(__deref_opt_out BSTR* family)
692 {
693     if (!family)
694         return E_POINTER;
695     *family = stringValueForKey(WebKitSansSerifFontPreferenceKey);
696     return (*family) ? S_OK : E_FAIL;
697 }
698
699 HRESULT WebPreferences::setSansSerifFontFamily(_In_ BSTR family)
700 {
701     setStringValue(WebKitSansSerifFontPreferenceKey, family);
702     return S_OK;
703 }
704
705 HRESULT WebPreferences::cursiveFontFamily(__deref_opt_out BSTR* family)
706 {
707     if (!family)
708         return E_POINTER;
709     *family = stringValueForKey(WebKitCursiveFontPreferenceKey);
710     return (*family) ? S_OK : E_FAIL;
711 }
712
713 HRESULT WebPreferences::setCursiveFontFamily(_In_ BSTR family)
714 {
715     setStringValue(WebKitCursiveFontPreferenceKey, family);
716     return S_OK;
717 }
718
719 HRESULT WebPreferences::fantasyFontFamily(__deref_opt_out BSTR* family)
720 {
721     if (!family)
722         return E_POINTER;
723     *family = stringValueForKey(WebKitFantasyFontPreferenceKey);
724     return (*family) ? S_OK : E_FAIL;
725 }
726
727 HRESULT WebPreferences::setFantasyFontFamily(_In_ BSTR family)
728 {
729     setStringValue(WebKitFantasyFontPreferenceKey, family);
730     return S_OK;
731 }
732
733 HRESULT WebPreferences::pictographFontFamily(__deref_opt_out BSTR* family)
734 {
735     if (!family)
736         return E_POINTER;
737     *family = stringValueForKey(WebKitPictographFontPreferenceKey);
738     return (*family) ? S_OK : E_FAIL;
739 }
740
741 HRESULT WebPreferences::setPictographFontFamily(_In_ BSTR family)
742 {
743     setStringValue(WebKitPictographFontPreferenceKey, family);
744     return S_OK;
745 }
746
747 HRESULT WebPreferences::defaultFontSize(_Out_  int* fontSize)
748 {
749     if (!fontSize)
750         return E_POINTER;
751     *fontSize = integerValueForKey(WebKitDefaultFontSizePreferenceKey);
752     return S_OK;
753 }
754
755 HRESULT WebPreferences::setDefaultFontSize(int fontSize)
756 {
757     setIntegerValue(WebKitDefaultFontSizePreferenceKey, fontSize);
758     return S_OK;
759 }
760
761 HRESULT WebPreferences::defaultFixedFontSize(_Out_ int* fontSize)
762 {
763     if (!fontSize)
764         return E_POINTER;
765     *fontSize = integerValueForKey(WebKitDefaultFixedFontSizePreferenceKey);
766     return S_OK;
767 }
768
769 HRESULT WebPreferences::setDefaultFixedFontSize(int fontSize)
770 {
771     setIntegerValue(WebKitDefaultFixedFontSizePreferenceKey, fontSize);
772     return S_OK;
773 }
774
775 HRESULT WebPreferences::minimumFontSize(_Out_ int* fontSize)
776 {
777     if (!fontSize)
778         return E_POINTER;
779     *fontSize = integerValueForKey(WebKitMinimumFontSizePreferenceKey);
780     return S_OK;
781 }
782
783 HRESULT WebPreferences::setMinimumFontSize(int fontSize)
784 {
785     setIntegerValue(WebKitMinimumFontSizePreferenceKey, fontSize);
786     return S_OK;
787 }
788
789 HRESULT WebPreferences::minimumLogicalFontSize(_Out_ int* fontSize)
790 {
791     if (!fontSize)
792         return E_POINTER;
793     *fontSize = integerValueForKey(WebKitMinimumLogicalFontSizePreferenceKey);
794     return S_OK;
795 }
796
797 HRESULT WebPreferences::setMinimumLogicalFontSize(int fontSize)
798 {
799     setIntegerValue(WebKitMinimumLogicalFontSizePreferenceKey, fontSize);
800     return S_OK;
801 }
802
803 HRESULT WebPreferences::defaultTextEncodingName(__deref_opt_out BSTR* name)
804 {
805     if (!name)
806         return E_POINTER;
807     *name = stringValueForKey(WebKitDefaultTextEncodingNamePreferenceKey);
808     return (*name) ? S_OK : E_FAIL;
809 }
810
811 HRESULT WebPreferences::setDefaultTextEncodingName(_In_ BSTR name)
812 {
813     setStringValue(WebKitDefaultTextEncodingNamePreferenceKey, name);
814     return S_OK;
815 }
816
817 HRESULT WebPreferences::userStyleSheetEnabled(_Out_ BOOL* enabled)
818 {
819     if (!enabled)
820         return E_POINTER;
821     *enabled = boolValueForKey(WebKitUserStyleSheetEnabledPreferenceKey);
822     return S_OK;
823 }
824
825 HRESULT WebPreferences::setUserStyleSheetEnabled(BOOL enabled)
826 {
827     setBoolValue(WebKitUserStyleSheetEnabledPreferenceKey, enabled);
828     return S_OK;
829 }
830
831 HRESULT WebPreferences::userStyleSheetLocation(__deref_opt_out BSTR* location)
832 {
833     if (!location)
834         return E_POINTER;
835     *location = stringValueForKey(WebKitUserStyleSheetLocationPreferenceKey);
836     return (*location) ? S_OK : E_FAIL;
837 }
838
839 HRESULT WebPreferences::setUserStyleSheetLocation(_In_ BSTR location)
840 {
841     setStringValue(WebKitUserStyleSheetLocationPreferenceKey, location);
842     return S_OK;
843 }
844
845 HRESULT WebPreferences::isJavaEnabled(_Out_ BOOL* enabled)
846 {
847     if (!enabled)
848         return E_POINTER;
849     *enabled = boolValueForKey(WebKitJavaEnabledPreferenceKey);
850     return S_OK;
851 }
852
853 HRESULT WebPreferences::setJavaEnabled(BOOL enabled)
854 {
855     setBoolValue(WebKitJavaEnabledPreferenceKey, enabled);
856     return S_OK;
857 }
858
859 HRESULT WebPreferences::isJavaScriptEnabled(_Out_ BOOL* enabled)
860 {
861     if (!enabled)
862         return E_POINTER;
863     *enabled = boolValueForKey(WebKitJavaScriptEnabledPreferenceKey);
864     return S_OK;
865 }
866
867 HRESULT WebPreferences::setJavaScriptEnabled(BOOL enabled)
868 {
869     setBoolValue(WebKitJavaScriptEnabledPreferenceKey, enabled);
870     return S_OK;
871 }
872
873 HRESULT WebPreferences::javaScriptRuntimeFlags(_Out_ unsigned* flags)
874 {
875     if (!flags)
876         return E_POINTER;
877     *flags = static_cast<unsigned>(integerValueForKey(WebKitJavaScriptRuntimeFlagsPreferenceKey));
878     return S_OK;
879 }
880
881 HRESULT WebPreferences::setJavaScriptRuntimeFlags(unsigned flags)
882 {
883     setIntegerValue(WebKitJavaScriptRuntimeFlagsPreferenceKey, static_cast<int>(flags));
884     return S_OK;
885 }
886
887 HRESULT WebPreferences::isWebSecurityEnabled(_Out_ BOOL* enabled)
888 {
889     if (!enabled)
890         return E_POINTER;
891     *enabled = boolValueForKey(WebKitWebSecurityEnabledPreferenceKey);
892     return S_OK;
893 }
894
895 HRESULT WebPreferences::setWebSecurityEnabled(BOOL enabled)
896 {
897     setBoolValue(WebKitWebSecurityEnabledPreferenceKey, enabled);
898     return S_OK;
899 }
900
901 HRESULT WebPreferences::allowUniversalAccessFromFileURLs(_Out_ BOOL* allowAccess)
902 {
903     if (!allowAccess)
904         return E_POINTER;
905     *allowAccess = boolValueForKey(WebKitAllowUniversalAccessFromFileURLsPreferenceKey);
906     return S_OK;
907 }
908
909 HRESULT WebPreferences::setAllowUniversalAccessFromFileURLs(BOOL allowAccess)
910 {
911     setBoolValue(WebKitAllowUniversalAccessFromFileURLsPreferenceKey, allowAccess);
912     return S_OK;
913 }
914
915 HRESULT WebPreferences::allowFileAccessFromFileURLs(_Out_ BOOL* allowAccess)
916 {
917     if (!allowAccess)
918         return E_POINTER;
919     *allowAccess = boolValueForKey(WebKitAllowFileAccessFromFileURLsPreferenceKey);
920     return S_OK;
921 }
922
923 HRESULT WebPreferences::setAllowFileAccessFromFileURLs(BOOL allowAccess)
924 {
925     setBoolValue(WebKitAllowFileAccessFromFileURLsPreferenceKey, allowAccess);
926     return S_OK;
927 }
928
929 HRESULT WebPreferences::javaScriptCanAccessClipboard(_Out_ BOOL* enabled)
930 {
931     if (!enabled)
932         return E_POINTER;
933     *enabled = boolValueForKey(WebKitJavaScriptCanAccessClipboardPreferenceKey);
934     return S_OK;
935 }
936
937 HRESULT WebPreferences::setJavaScriptCanAccessClipboard(BOOL enabled)
938 {
939     setBoolValue(WebKitJavaScriptCanAccessClipboardPreferenceKey, enabled);
940     return S_OK;
941 }
942
943 HRESULT WebPreferences::isXSSAuditorEnabled(_Out_ BOOL* enabled)
944 {
945     if (!enabled)
946         return E_POINTER;
947     *enabled = boolValueForKey(WebKitXSSAuditorEnabledPreferenceKey);
948     return S_OK;
949 }
950
951 HRESULT WebPreferences::setXSSAuditorEnabled(BOOL enabled)
952 {
953     setBoolValue(WebKitXSSAuditorEnabledPreferenceKey, enabled);
954     return S_OK;
955 }
956
957 HRESULT WebPreferences::isFrameFlatteningEnabled(_Out_ BOOL* enabled)
958 {
959     if (!enabled)
960         return E_POINTER;
961     *enabled = boolValueForKey(WebKitFrameFlatteningEnabledPreferenceKey);
962     return S_OK;
963 }
964
965 HRESULT WebPreferences::setFrameFlatteningEnabled(BOOL enabled)
966 {
967     setBoolValue(WebKitFrameFlatteningEnabledPreferenceKey, enabled);
968     return S_OK;
969 }
970
971 HRESULT WebPreferences::javaScriptCanOpenWindowsAutomatically(_Out_ BOOL* enabled)
972 {
973     if (!enabled)
974         return E_POINTER;
975     *enabled = boolValueForKey(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey);
976     return S_OK;
977 }
978
979 HRESULT WebPreferences::setJavaScriptCanOpenWindowsAutomatically(BOOL enabled)
980 {
981     setBoolValue(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey, enabled);
982     return S_OK;
983 }
984
985 HRESULT WebPreferences::arePlugInsEnabled(_Out_ BOOL* enabled)
986 {
987     if (!enabled)
988         return E_POINTER;
989     *enabled = boolValueForKey(WebKitPluginsEnabledPreferenceKey);
990     return S_OK;
991 }
992
993 HRESULT WebPreferences::setPlugInsEnabled(BOOL enabled)
994 {
995     setBoolValue(WebKitPluginsEnabledPreferenceKey, enabled);
996     return S_OK;
997 }
998
999 HRESULT WebPreferences::isCSSRegionsEnabled(_Out_ BOOL* enabled)
1000 {
1001     if (!enabled)
1002         return E_POINTER;
1003     *enabled = boolValueForKey(WebKitCSSRegionsEnabledPreferenceKey);
1004     return S_OK;
1005 }
1006
1007 HRESULT WebPreferences::setCSSRegionsEnabled(BOOL enabled)
1008 {
1009     setBoolValue(WebKitCSSRegionsEnabledPreferenceKey, enabled);
1010     return S_OK;
1011 }
1012
1013 HRESULT WebPreferences::allowsAnimatedImages(_Out_ BOOL* enabled)
1014 {
1015     if (!enabled)
1016         return E_POINTER;
1017     *enabled = boolValueForKey(WebKitAllowAnimatedImagesPreferenceKey);
1018     return S_OK;
1019 }
1020
1021 HRESULT WebPreferences::setAllowsAnimatedImages(BOOL enabled)
1022 {
1023     setBoolValue(WebKitAllowAnimatedImagesPreferenceKey, enabled);
1024     return S_OK;
1025 }
1026
1027 HRESULT WebPreferences::allowAnimatedImageLooping(_Out_ BOOL* enabled)
1028 {
1029     if (!enabled)
1030         return E_POINTER;
1031     *enabled = boolValueForKey(WebKitAllowAnimatedImageLoopingPreferenceKey);
1032     return S_OK;
1033 }
1034
1035 HRESULT WebPreferences::setAllowAnimatedImageLooping(BOOL enabled)
1036 {
1037     setBoolValue(WebKitAllowAnimatedImageLoopingPreferenceKey, enabled);
1038     return S_OK;
1039 }
1040
1041 HRESULT WebPreferences::setLoadsImagesAutomatically(BOOL enabled)
1042 {
1043     setBoolValue(WebKitDisplayImagesKey, enabled);
1044     return S_OK;
1045 }
1046
1047 HRESULT WebPreferences::loadsImagesAutomatically(_Out_ BOOL* enabled)
1048 {
1049     if (!enabled)
1050         return E_POINTER;
1051     *enabled = boolValueForKey(WebKitDisplayImagesKey);
1052     return S_OK;
1053 }
1054
1055 HRESULT WebPreferences::setLoadsSiteIconsIgnoringImageLoadingPreference(BOOL enabled)
1056 {
1057     setBoolValue(WebKitLoadSiteIconsKey, enabled);
1058     return S_OK;
1059 }
1060
1061 HRESULT WebPreferences::loadsSiteIconsIgnoringImageLoadingPreference(_Out_ BOOL* enabled)
1062 {
1063     if (!enabled)
1064         return E_POINTER;
1065     *enabled = boolValueForKey(WebKitLoadSiteIconsKey);
1066     return S_OK;
1067 }
1068
1069 HRESULT WebPreferences::setHixie76WebSocketProtocolEnabled(BOOL enabled)
1070 {
1071     return S_OK;
1072 }
1073
1074 HRESULT WebPreferences::hixie76WebSocketProtocolEnabled(_Out_ BOOL* enabled)
1075 {
1076     if (!enabled)
1077         return E_POINTER;
1078     *enabled = false;
1079     return S_OK;
1080 }
1081
1082 HRESULT WebPreferences::setMediaPlaybackRequiresUserGesture(BOOL enabled)
1083 {
1084     setBoolValue(WebKitMediaPlaybackRequiresUserGesturePreferenceKey, enabled);
1085     return S_OK;
1086 }
1087
1088 HRESULT WebPreferences::mediaPlaybackRequiresUserGesture(_Out_ BOOL* enabled)
1089 {
1090     if (!enabled)
1091         return E_POINTER;
1092     *enabled = boolValueForKey(WebKitMediaPlaybackRequiresUserGesturePreferenceKey);
1093     return S_OK;
1094 }
1095
1096 HRESULT WebPreferences::setMediaPlaybackAllowsInline(BOOL enabled)
1097 {
1098     setBoolValue(WebKitMediaPlaybackAllowsInlinePreferenceKey, enabled);
1099     return S_OK;
1100 }
1101
1102 HRESULT WebPreferences::mediaPlaybackAllowsInline(_Out_ BOOL* enabled)
1103 {
1104     if (!enabled)
1105         return E_POINTER;
1106     *enabled = boolValueForKey(WebKitMediaPlaybackAllowsInlinePreferenceKey);
1107     return S_OK;
1108 }
1109
1110 HRESULT WebPreferences::setAutosaves(BOOL enabled)
1111 {
1112     m_autoSaves = !!enabled;
1113     return S_OK;
1114 }
1115
1116 HRESULT WebPreferences::autosaves(_Out_ BOOL* enabled)
1117 {
1118     if (!enabled)
1119         return E_POINTER;
1120     *enabled = m_autoSaves ? TRUE : FALSE;
1121     return S_OK;
1122 }
1123
1124 HRESULT WebPreferences::setShouldPrintBackgrounds(BOOL enabled)
1125 {
1126     setBoolValue(WebKitShouldPrintBackgroundsPreferenceKey, enabled);
1127     return S_OK;
1128 }
1129
1130 HRESULT WebPreferences::shouldPrintBackgrounds(_Out_ BOOL* enabled)
1131 {
1132     if (!enabled)
1133         return E_POINTER;
1134     *enabled = boolValueForKey(WebKitShouldPrintBackgroundsPreferenceKey);
1135     return S_OK;
1136 }
1137
1138 HRESULT WebPreferences::setPrivateBrowsingEnabled(BOOL enabled)
1139 {
1140     setBoolValue(WebKitPrivateBrowsingEnabledPreferenceKey, enabled);
1141     return S_OK;
1142 }
1143
1144 HRESULT WebPreferences::privateBrowsingEnabled(_Out_ BOOL* enabled)
1145 {
1146     if (!enabled)
1147         return E_POINTER;
1148     *enabled = boolValueForKey(WebKitPrivateBrowsingEnabledPreferenceKey);
1149     return S_OK;
1150 }
1151
1152 HRESULT WebPreferences::setTabsToLinks(BOOL enabled)
1153 {
1154     setBoolValue(WebKitTabToLinksPreferenceKey, enabled);
1155     return S_OK;
1156 }
1157
1158 HRESULT WebPreferences::tabsToLinks(_Out_ BOOL* enabled)
1159 {
1160     *enabled = boolValueForKey(WebKitTabToLinksPreferenceKey);
1161     return S_OK;
1162 }
1163
1164 HRESULT WebPreferences::setUsesPageCache(BOOL usesPageCache)
1165 {
1166     setBoolValue(WebKitUsesPageCachePreferenceKey, usesPageCache);
1167     return S_OK;
1168 }
1169
1170 HRESULT WebPreferences::usesPageCache(_Out_ BOOL* usesPageCache)
1171 {
1172     if (!usesPageCache)
1173         return E_POINTER;
1174     *usesPageCache = boolValueForKey(WebKitUsesPageCachePreferenceKey);
1175     return S_OK;
1176 }
1177
1178 HRESULT WebPreferences::textAreasAreResizable(_Out_ BOOL* enabled)
1179 {
1180     if (!enabled)
1181         return E_POINTER;
1182     *enabled = boolValueForKey(WebKitTextAreasAreResizablePreferenceKey);
1183     return S_OK;
1184 }
1185
1186 HRESULT WebPreferences::setTextAreasAreResizable(BOOL enabled)
1187 {
1188     setBoolValue(WebKitTextAreasAreResizablePreferenceKey, enabled);
1189     return S_OK;
1190 }
1191
1192 HRESULT WebPreferences::historyItemLimit(_Out_ int* limit)
1193 {
1194     if (!limit)
1195         return E_POINTER;
1196     *limit = integerValueForKey(WebKitHistoryItemLimitKey);
1197     return S_OK;
1198 }
1199
1200 HRESULT WebPreferences::setHistoryItemLimit(int limit)
1201 {
1202     setIntegerValue(WebKitHistoryItemLimitKey, limit);
1203     return S_OK;
1204 }
1205
1206 HRESULT WebPreferences::historyAgeInDaysLimit(_Out_ int* limit)
1207 {
1208     if (!limit)
1209         return E_POINTER;
1210     *limit = integerValueForKey(WebKitHistoryAgeInDaysLimitKey);
1211     return S_OK;
1212 }
1213
1214 HRESULT WebPreferences::setHistoryAgeInDaysLimit(int limit)
1215 {
1216     setIntegerValue(WebKitHistoryAgeInDaysLimitKey, limit);
1217     return S_OK;
1218 }
1219
1220 HRESULT WebPreferences::unused1()
1221 {
1222     ASSERT_NOT_REACHED();
1223     return E_FAIL;
1224 }
1225
1226 HRESULT WebPreferences::unused2()
1227 {
1228     ASSERT_NOT_REACHED();
1229     return E_FAIL;
1230 }
1231
1232 HRESULT WebPreferences::iconDatabaseLocation(__deref_opt_out BSTR* location)
1233 {
1234     if (!location)
1235         return E_POINTER;
1236     *location = stringValueForKey(WebKitIconDatabaseLocationKey);
1237     return (*location) ? S_OK : E_FAIL;
1238 }
1239
1240 HRESULT WebPreferences::setIconDatabaseLocation(_In_ BSTR location)
1241 {
1242     setStringValue(WebKitIconDatabaseLocationKey, location);
1243     return S_OK;
1244 }
1245
1246 HRESULT WebPreferences::iconDatabaseEnabled(_Out_ BOOL* enabled)
1247 {
1248     if (!enabled)
1249         return E_POINTER;
1250     *enabled = boolValueForKey(WebKitIconDatabaseEnabledPreferenceKey);
1251     return S_OK;
1252 }
1253
1254 HRESULT WebPreferences::setIconDatabaseEnabled(BOOL enabled)
1255 {
1256     setBoolValue(WebKitIconDatabaseEnabledPreferenceKey, enabled);
1257     return S_OK;
1258 }
1259
1260 HRESULT WebPreferences::fontSmoothing(_Out_ FontSmoothingType* smoothingType)
1261 {
1262     if (!smoothingType)
1263         return E_POINTER;
1264     *smoothingType = static_cast<FontSmoothingType>(integerValueForKey(WebKitFontSmoothingTypePreferenceKey));
1265     return S_OK;
1266 }
1267
1268 HRESULT WebPreferences::setFontSmoothing(FontSmoothingType smoothingType)
1269 {
1270     setIntegerValue(WebKitFontSmoothingTypePreferenceKey, smoothingType);
1271     if (smoothingType == FontSmoothingTypeWindows)
1272         smoothingType = FontSmoothingTypeMedium;
1273 #if USE(CG)
1274     FontCascade::setFontSmoothingLevel((int)smoothingType);
1275 #endif
1276     return S_OK;
1277 }
1278
1279 HRESULT WebPreferences::fontSmoothingContrast(_Out_ float* contrast)
1280 {
1281     if (!contrast)
1282         return E_POINTER;
1283     *contrast = floatValueForKey(WebKitFontSmoothingContrastPreferenceKey);
1284     return S_OK;
1285 }
1286
1287 HRESULT WebPreferences::setFontSmoothingContrast(float contrast)
1288 {
1289     setFloatValue(WebKitFontSmoothingContrastPreferenceKey, contrast);
1290 #if USE(CG)
1291     FontCascade::setFontSmoothingContrast(contrast);
1292 #endif
1293     return S_OK;
1294 }
1295
1296 HRESULT WebPreferences::editableLinkBehavior(_Out_ WebKitEditableLinkBehavior* editableLinkBehavior)
1297 {
1298     if (!editableLinkBehavior)
1299         return E_POINTER;
1300     WebKitEditableLinkBehavior value = static_cast<WebKitEditableLinkBehavior>(integerValueForKey(WebKitEditableLinkBehaviorPreferenceKey));
1301     switch (value) {
1302         case WebKitEditableLinkDefaultBehavior:
1303         case WebKitEditableLinkAlwaysLive:
1304         case WebKitEditableLinkOnlyLiveWithShiftKey:
1305         case WebKitEditableLinkLiveWhenNotFocused:
1306         case WebKitEditableLinkNeverLive:
1307             *editableLinkBehavior = value;
1308             break;
1309         default: // ensure that a valid result is returned
1310             *editableLinkBehavior = WebKitEditableLinkDefaultBehavior;
1311             break;
1312     }
1313     return S_OK;
1314 }
1315
1316 HRESULT WebPreferences::setEditableLinkBehavior(WebKitEditableLinkBehavior behavior)
1317 {
1318     setIntegerValue(WebKitEditableLinkBehaviorPreferenceKey, behavior);
1319     return S_OK;
1320 }
1321
1322 HRESULT WebPreferences::unused5()
1323 {
1324     ASSERT_NOT_REACHED();
1325     return E_FAIL;
1326 }
1327
1328 HRESULT WebPreferences::unused6()
1329 {
1330     ASSERT_NOT_REACHED();
1331     return E_FAIL;
1332 }
1333
1334 HRESULT WebPreferences::mockScrollbarsEnabled(_Out_ BOOL* enabled)
1335 {
1336     if (!enabled)
1337         return E_POINTER;
1338     *enabled = boolValueForKey(WebKitMockScrollbarsEnabledPreferenceKey);
1339     return S_OK;
1340 }
1341
1342 HRESULT WebPreferences::setMockScrollbarsEnabled(BOOL enabled)
1343 {
1344     setBoolValue(WebKitMockScrollbarsEnabledPreferenceKey, enabled);
1345     return S_OK;
1346 }
1347
1348 // These two methods are no-ops, and only retained to keep
1349 // the Interface consistent. DO NOT USE THEM.
1350 HRESULT WebPreferences::screenFontSubstitutionEnabled(_Out_ BOOL* enabled)
1351 {
1352     if (!enabled)
1353         return E_POINTER;
1354     *enabled = false;
1355     return S_OK;
1356 }
1357
1358 HRESULT WebPreferences::setScreenFontSubstitutionEnabled(BOOL)
1359 {
1360     return S_OK;
1361 }
1362
1363 HRESULT WebPreferences::hyperlinkAuditingEnabled(_Out_ BOOL* enabled)
1364 {
1365     if (!enabled)
1366         return E_POINTER;
1367     *enabled = boolValueForKey(WebKitHyperlinkAuditingEnabledPreferenceKey);
1368     return S_OK;
1369 }
1370
1371 HRESULT WebPreferences::setHyperlinkAuditingEnabled(BOOL enabled)
1372 {
1373     setBoolValue(WebKitHyperlinkAuditingEnabledPreferenceKey, enabled);
1374     return S_OK;
1375 }
1376
1377 HRESULT WebPreferences::cookieStorageAcceptPolicy(_Out_ WebKitCookieStorageAcceptPolicy* acceptPolicy)
1378 {
1379     if (!acceptPolicy)
1380         return E_POINTER;
1381
1382     *acceptPolicy = static_cast<WebKitCookieStorageAcceptPolicy>(integerValueForKey(WebKitCookieStorageAcceptPolicyPreferenceKey));
1383     return S_OK;
1384 }
1385
1386 HRESULT WebPreferences::setCookieStorageAcceptPolicy(WebKitCookieStorageAcceptPolicy acceptPolicy)
1387 {
1388     setIntegerValue(WebKitCookieStorageAcceptPolicyPreferenceKey, acceptPolicy);
1389     return S_OK;
1390 }
1391
1392
1393 HRESULT WebPreferences::continuousSpellCheckingEnabled(_Out_ BOOL* enabled)
1394 {
1395     if (!enabled)
1396         return E_POINTER;
1397     *enabled = boolValueForKey(WebContinuousSpellCheckingEnabledPreferenceKey);
1398     return S_OK;
1399 }
1400
1401 HRESULT WebPreferences::setContinuousSpellCheckingEnabled(BOOL enabled)
1402 {
1403     setBoolValue(WebContinuousSpellCheckingEnabledPreferenceKey, enabled);
1404     return S_OK;
1405 }
1406
1407 HRESULT WebPreferences::grammarCheckingEnabled(_Out_ BOOL* enabled)
1408 {
1409     if (!enabled)
1410         return E_POINTER;
1411     *enabled = boolValueForKey(WebGrammarCheckingEnabledPreferenceKey);
1412     return S_OK;
1413 }
1414
1415 HRESULT WebPreferences::setGrammarCheckingEnabled(BOOL enabled)
1416 {
1417     setBoolValue(WebGrammarCheckingEnabledPreferenceKey, enabled);
1418     return S_OK;
1419 }
1420
1421 HRESULT WebPreferences::allowContinuousSpellChecking(_Out_ BOOL* enabled)
1422 {
1423     if (!enabled)
1424         return E_POINTER;
1425     *enabled = boolValueForKey(AllowContinuousSpellCheckingPreferenceKey);
1426     return S_OK;
1427 }
1428
1429 HRESULT WebPreferences::setAllowContinuousSpellChecking(BOOL enabled)
1430 {
1431     setBoolValue(AllowContinuousSpellCheckingPreferenceKey, enabled);
1432     return S_OK;
1433 }
1434
1435 HRESULT WebPreferences::unused7()
1436 {
1437     ASSERT_NOT_REACHED();
1438     return E_FAIL;
1439 }
1440
1441 HRESULT WebPreferences::unused8()
1442 {
1443     ASSERT_NOT_REACHED();
1444     return E_FAIL;
1445 }
1446
1447 HRESULT WebPreferences::isDOMPasteAllowed(_Out_ BOOL* enabled)
1448 {
1449     if (!enabled)
1450         return E_POINTER;
1451     *enabled = boolValueForKey(WebKitDOMPasteAllowedPreferenceKey);
1452     return S_OK;
1453 }
1454     
1455 HRESULT WebPreferences::setDOMPasteAllowed(BOOL enabled)
1456 {
1457     setBoolValue(WebKitDOMPasteAllowedPreferenceKey, enabled);
1458     return S_OK;
1459 }
1460
1461 HRESULT WebPreferences::cacheModel(_Out_ WebCacheModel* cacheModel)
1462 {
1463     if (!cacheModel)
1464         return E_POINTER;
1465
1466     *cacheModel = static_cast<WebCacheModel>(integerValueForKey(WebKitCacheModelPreferenceKey));
1467     return S_OK;
1468 }
1469
1470 HRESULT WebPreferences::setCacheModel(WebCacheModel cacheModel)
1471 {
1472     setIntegerValue(WebKitCacheModelPreferenceKey, cacheModel);
1473     return S_OK;
1474 }
1475
1476 HRESULT WebPreferences::unused3()
1477 {
1478     ASSERT_NOT_REACHED();
1479     return E_FAIL;
1480 }
1481
1482 HRESULT WebPreferences::unused4()
1483 {
1484     ASSERT_NOT_REACHED();
1485     return E_FAIL;
1486 }
1487
1488 // These two methods are no-ops, and only retained to keep
1489 // the Interface consistent. DO NOT USE THEM.
1490 HRESULT WebPreferences::shouldPaintNativeControls(_Out_ BOOL* enable)
1491 {
1492     if (!enable)
1493         return E_POINTER;
1494     *enable = FALSE;
1495     return S_OK;
1496 }
1497
1498 HRESULT WebPreferences::setShouldPaintNativeControls(BOOL)
1499 {
1500     return S_OK;
1501 }
1502
1503 HRESULT WebPreferences::setDeveloperExtrasEnabled(BOOL enabled)
1504 {
1505     setBoolValue(WebKitDeveloperExtrasEnabledPreferenceKey, enabled);
1506     return S_OK;
1507 }
1508
1509 HRESULT WebPreferences::developerExtrasEnabled(_Out_ BOOL* enabled)
1510 {
1511     if (!enabled)
1512         return E_POINTER;
1513
1514     *enabled = boolValueForKey(WebKitDeveloperExtrasEnabledPreferenceKey);
1515     return S_OK;
1516 }
1517
1518 bool WebPreferences::developerExtrasDisabledByOverride()
1519 {
1520     return !!boolValueForKey(DisableWebKitDeveloperExtrasPreferenceKey);
1521 }
1522
1523 HRESULT WebPreferences::setAutomaticallyDetectsCacheModel(BOOL automaticallyDetectsCacheModel)
1524 {
1525     m_automaticallyDetectsCacheModel = !!automaticallyDetectsCacheModel;
1526     return S_OK;
1527 }
1528
1529 HRESULT WebPreferences::automaticallyDetectsCacheModel(_Out_ BOOL* automaticallyDetectsCacheModel)
1530 {
1531     if (!automaticallyDetectsCacheModel)
1532         return E_POINTER;
1533
1534     *automaticallyDetectsCacheModel = m_automaticallyDetectsCacheModel;
1535     return S_OK;
1536 }
1537
1538 HRESULT WebPreferences::setAuthorAndUserStylesEnabled(BOOL enabled)
1539 {
1540     setBoolValue(WebKitAuthorAndUserStylesEnabledPreferenceKey, enabled);
1541     return S_OK;
1542 }
1543
1544 HRESULT WebPreferences::authorAndUserStylesEnabled(_Out_ BOOL* enabled)
1545 {
1546     if (!enabled)
1547         return E_POINTER;
1548
1549     *enabled = boolValueForKey(WebKitAuthorAndUserStylesEnabledPreferenceKey);
1550     return S_OK;
1551 }
1552
1553 // These two methods are no-ops, and only retained to keep
1554 // the Interface consistent. DO NOT USE THEM.
1555 HRESULT WebPreferences::inApplicationChromeMode(_Out_ BOOL* enabled)
1556 {
1557     if (!enabled)
1558         return E_POINTER;
1559     *enabled = FALSE;
1560     return S_OK;
1561 }
1562
1563 HRESULT WebPreferences::setApplicationChromeMode(BOOL)
1564 {
1565     return S_OK;
1566 }
1567
1568 HRESULT WebPreferences::setOfflineWebApplicationCacheEnabled(BOOL enabled)
1569 {
1570     setBoolValue(WebKitOfflineWebApplicationCacheEnabledPreferenceKey, enabled);
1571     return S_OK;
1572 }
1573
1574 HRESULT WebPreferences::offlineWebApplicationCacheEnabled(_Out_ BOOL* enabled)
1575 {
1576     if (!enabled)
1577         return E_POINTER;
1578     *enabled = boolValueForKey(WebKitOfflineWebApplicationCacheEnabledPreferenceKey);
1579     return S_OK;
1580 }
1581
1582 HRESULT WebPreferences::setDatabasesEnabled(BOOL enabled)
1583 {
1584     setBoolValue(WebKitDatabasesEnabledPreferenceKey, enabled);
1585     return S_OK;
1586 }
1587
1588 HRESULT WebPreferences::databasesEnabled(_Out_ BOOL* enabled)
1589 {
1590     if (!enabled)
1591         return E_POINTER;
1592     *enabled = boolValueForKey(WebKitDatabasesEnabledPreferenceKey);
1593     return S_OK;
1594 }
1595
1596 HRESULT WebPreferences::setLocalStorageEnabled(BOOL enabled)
1597 {
1598     setBoolValue(WebKitLocalStorageEnabledPreferenceKey, enabled);
1599     return S_OK;
1600 }
1601
1602 HRESULT WebPreferences::localStorageEnabled(_Out_ BOOL* enabled)
1603 {
1604     if (!enabled)
1605         return E_POINTER;
1606     *enabled = boolValueForKey(WebKitLocalStorageEnabledPreferenceKey);
1607     return S_OK;
1608 }
1609
1610 HRESULT WebPreferences::localStorageDatabasePath(__deref_opt_out BSTR* location)
1611 {
1612     if (!location)
1613         return E_POINTER;
1614     *location = stringValueForKey(WebKitLocalStorageDatabasePathPreferenceKey);
1615     return (*location) ? S_OK : E_FAIL;
1616 }
1617
1618 HRESULT WebPreferences::setLocalStorageDatabasePath(_In_ BSTR location)
1619 {
1620     setStringValue(WebKitLocalStorageDatabasePathPreferenceKey, location);
1621     return S_OK;
1622 }
1623
1624 HRESULT WebPreferences::setExperimentalNotificationsEnabled(BOOL enabled)
1625 {
1626     setBoolValue(WebKitExperimentalNotificationsEnabledPreferenceKey, enabled);
1627     return S_OK;
1628 }
1629
1630 HRESULT WebPreferences::experimentalNotificationsEnabled(_Out_ BOOL* enabled)
1631 {
1632     if (!enabled)
1633         return E_POINTER;
1634     *enabled = boolValueForKey(WebKitExperimentalNotificationsEnabledPreferenceKey);
1635     return S_OK;
1636 }
1637
1638 HRESULT WebPreferences::setZoomsTextOnly(BOOL zoomsTextOnly)
1639 {
1640     setBoolValue(WebKitZoomsTextOnlyPreferenceKey, zoomsTextOnly);
1641     return S_OK;
1642 }
1643
1644 HRESULT WebPreferences::zoomsTextOnly(_Out_ BOOL* zoomsTextOnly)
1645 {
1646     if (!zoomsTextOnly)
1647         return E_POINTER;
1648     *zoomsTextOnly = boolValueForKey(WebKitZoomsTextOnlyPreferenceKey);
1649     return S_OK;
1650 }
1651
1652 HRESULT WebPreferences::setShouldUseHighResolutionTimers(BOOL useHighResolutionTimers)
1653 {
1654     setBoolValue(WebKitUseHighResolutionTimersPreferenceKey, useHighResolutionTimers);
1655     return S_OK;
1656 }
1657
1658 HRESULT WebPreferences::shouldUseHighResolutionTimers(_Out_ BOOL* useHighResolutionTimers)
1659 {
1660     if (!useHighResolutionTimers)
1661         return E_POINTER;
1662     *useHighResolutionTimers = boolValueForKey(WebKitUseHighResolutionTimersPreferenceKey);
1663     return S_OK;
1664 }
1665
1666 HRESULT WebPreferences::setPreferenceForTest(_In_ BSTR key, _In_ BSTR value)
1667 {
1668     if (!SysStringLen(key) || !SysStringLen(value))
1669         return E_FAIL;
1670     RetainPtr<CFStringRef> keyString = adoptCF(CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(key), SysStringLen(key)));
1671     RetainPtr<CFStringRef> valueString = adoptCF(CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(value), SysStringLen(value)));
1672     setValueForKey(keyString.get(), valueString.get());
1673     postPreferencesChangesNotification();
1674     return S_OK;
1675 }
1676
1677 HRESULT WebPreferences::setAcceleratedCompositingEnabled(BOOL enabled)
1678 {
1679     setBoolValue(WebKitAcceleratedCompositingEnabledPreferenceKey, enabled);
1680     return S_OK;
1681 }
1682
1683 HRESULT WebPreferences::acceleratedCompositingEnabled(_Out_ BOOL* enabled)
1684 {
1685     if (!enabled)
1686         return E_POINTER;
1687 #if USE(CA)
1688     *enabled = CACFLayerTreeHost::acceleratedCompositingAvailable() && boolValueForKey(WebKitAcceleratedCompositingEnabledPreferenceKey);
1689 #else
1690     *enabled = TRUE;
1691 #endif
1692
1693     return S_OK;
1694 }
1695
1696 HRESULT WebPreferences::showDebugBorders(_Out_ BOOL* enabled)
1697 {
1698     if (!enabled)
1699         return E_POINTER;
1700     *enabled = boolValueForKey(WebKitShowDebugBordersPreferenceKey);
1701     return S_OK;
1702 }
1703
1704 HRESULT WebPreferences::setShowDebugBorders(BOOL enabled)
1705 {
1706     setBoolValue(WebKitShowDebugBordersPreferenceKey, enabled);
1707     return S_OK;
1708 }
1709
1710 HRESULT WebPreferences::showRepaintCounter(_Out_ BOOL* enabled)
1711 {
1712     if (!enabled)
1713         return E_POINTER;
1714     *enabled = boolValueForKey(WebKitShowRepaintCounterPreferenceKey);
1715     return S_OK;
1716 }
1717
1718 HRESULT WebPreferences::setShowRepaintCounter(BOOL enabled)
1719 {
1720     setBoolValue(WebKitShowRepaintCounterPreferenceKey, enabled);
1721     return S_OK;
1722 }
1723
1724 HRESULT WebPreferences::setCustomDragCursorsEnabled(BOOL enabled)
1725 {
1726     setBoolValue(WebKitCustomDragCursorsEnabledPreferenceKey, enabled);
1727     return S_OK;
1728 }
1729
1730 HRESULT WebPreferences::customDragCursorsEnabled(_Out_ BOOL* enabled)
1731 {
1732     if (!enabled)
1733         return E_POINTER;
1734     *enabled = boolValueForKey(WebKitCustomDragCursorsEnabledPreferenceKey);
1735     return S_OK;
1736 }
1737
1738 HRESULT WebPreferences::spatialNavigationEnabled(_Out_ BOOL* enabled)
1739 {
1740     if (!enabled)
1741         return E_POINTER;
1742     *enabled = boolValueForKey(WebKitSpatialNavigationEnabledPreferenceKey);
1743     return S_OK;
1744 }
1745
1746 HRESULT WebPreferences::setSpatialNavigationEnabled(BOOL enabled)
1747 {
1748     setBoolValue(WebKitSpatialNavigationEnabledPreferenceKey, enabled);
1749     return S_OK;
1750 }
1751
1752 HRESULT WebPreferences::setDNSPrefetchingEnabled(BOOL enabled)
1753 {
1754     setBoolValue(WebKitDNSPrefetchingEnabledPreferenceKey, enabled);
1755     return S_OK;
1756 }
1757
1758 HRESULT WebPreferences::isDNSPrefetchingEnabled(_Out_ BOOL* enabled)
1759 {
1760     if (!enabled)
1761         return E_POINTER;
1762     *enabled = boolValueForKey(WebKitDNSPrefetchingEnabledPreferenceKey);
1763     return S_OK;
1764 }
1765
1766 HRESULT WebPreferences::isFullScreenEnabled(_Out_ BOOL* enabled)
1767 {
1768 #if ENABLE(FULLSCREEN_API)
1769     if (!enabled)
1770         return E_POINTER;
1771
1772     *enabled = boolValueForKey(WebKitFullScreenEnabledPreferenceKey);
1773     return S_OK;
1774 #else
1775     return E_NOTIMPL;
1776 #endif
1777 }
1778
1779 HRESULT WebPreferences::setFullScreenEnabled(BOOL enabled)
1780 {
1781 #if ENABLE(FULLSCREEN_API)
1782     setBoolValue(WebKitFullScreenEnabledPreferenceKey, enabled);
1783     return S_OK;
1784 #else
1785     return E_NOTIMPL;
1786 #endif
1787 }
1788
1789 HRESULT WebPreferences::avFoundationEnabled(_Out_ BOOL* enabled)
1790 {
1791 #if USE(AVFOUNDATION)
1792     if (!enabled)
1793         return E_POINTER;
1794
1795     *enabled = boolValueForKey(WebKitAVFoundationEnabledPreferenceKey);
1796     return S_OK;
1797 #else
1798     return E_NOTIMPL;
1799 #endif
1800 }
1801
1802 HRESULT WebPreferences::setAVFoundationEnabled(BOOL enabled)
1803 {
1804 #if USE(AVFOUNDATION)
1805     setBoolValue(WebKitAVFoundationEnabledPreferenceKey, enabled);
1806     return S_OK;
1807 #else
1808     return E_NOTIMPL;
1809 #endif
1810 }
1811
1812 HRESULT WebPreferences::showsToolTipOverTruncatedText(_Out_ BOOL* showsToolTip)
1813 {
1814     if (!showsToolTip)
1815         return E_POINTER;
1816
1817     *showsToolTip = boolValueForKey(WebKitShowsToolTipOverTruncatedTextPreferenceKey);
1818     return S_OK;
1819 }
1820
1821 HRESULT WebPreferences::setShowsToolTipOverTruncatedText(BOOL showsToolTip)
1822 {
1823     setBoolValue(WebKitShowsToolTipOverTruncatedTextPreferenceKey, showsToolTip);
1824     return S_OK;
1825 }
1826
1827 HRESULT WebPreferences::shouldInvertColors(_Out_ BOOL* shouldInvertColors)
1828 {
1829     if (!shouldInvertColors)
1830         return E_POINTER;
1831
1832     *shouldInvertColors = boolValueForKey(WebKitShouldInvertColorsPreferenceKey);
1833     return S_OK;
1834 }
1835
1836 HRESULT WebPreferences::setShouldInvertColors(BOOL shouldInvertColors)
1837 {
1838     setBoolValue(WebKitShouldInvertColorsPreferenceKey, shouldInvertColors);
1839     return S_OK;
1840 }
1841
1842 void WebPreferences::willAddToWebView()
1843 {
1844     ++m_numWebViews;
1845 }
1846
1847 void WebPreferences::didRemoveFromWebView()
1848 {
1849     ASSERT(m_numWebViews);
1850     if (--m_numWebViews == 0) {
1851         IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
1852         nc->postNotificationName(webPreferencesRemovedNotification(), static_cast<IWebPreferences*>(this), 0);
1853     }
1854 }
1855
1856 HRESULT WebPreferences::shouldDisplaySubtitles(_Out_ BOOL* enabled)
1857 {
1858 #if ENABLE(VIDEO_TRACK)
1859     if (!enabled)
1860         return E_POINTER;
1861
1862     *enabled = boolValueForKey(WebKitShouldDisplaySubtitlesPreferenceKey);
1863     return S_OK;
1864 #else
1865     return E_NOTIMPL;
1866 #endif
1867 }
1868
1869 HRESULT WebPreferences::setShouldDisplaySubtitles(BOOL enabled)
1870 {
1871 #if ENABLE(VIDEO_TRACK)
1872     setBoolValue(WebKitShouldDisplaySubtitlesPreferenceKey, enabled);
1873     return S_OK;
1874 #else
1875     return E_NOTIMPL;
1876 #endif
1877 }
1878
1879 HRESULT WebPreferences::shouldDisplayCaptions(_Out_ BOOL* enabled)
1880 {
1881 #if ENABLE(VIDEO_TRACK)
1882     if (!enabled)
1883         return E_POINTER;
1884
1885     *enabled = boolValueForKey(WebKitShouldDisplayCaptionsPreferenceKey);
1886     return S_OK;
1887 #else
1888     return E_NOTIMPL;
1889 #endif
1890 }
1891
1892 HRESULT WebPreferences::setShouldDisplayCaptions(BOOL enabled)
1893 {
1894 #if ENABLE(VIDEO_TRACK)
1895     setBoolValue(WebKitShouldDisplayCaptionsPreferenceKey, enabled);
1896     return S_OK;
1897 #else
1898     return E_NOTIMPL;
1899 #endif
1900 }
1901
1902 HRESULT WebPreferences::shouldDisplayTextDescriptions(_Out_ BOOL* enabled)
1903 {
1904 #if ENABLE(VIDEO_TRACK)
1905     if (!enabled)
1906         return E_POINTER;
1907
1908     *enabled = boolValueForKey(WebKitShouldDisplayTextDescriptionsPreferenceKey);
1909     return S_OK;
1910 #else
1911     return E_NOTIMPL;
1912 #endif
1913 }
1914
1915 HRESULT WebPreferences::setShouldDisplayTextDescriptions(BOOL enabled)
1916 {
1917 #if ENABLE(VIDEO_TRACK)
1918     setBoolValue(WebKitShouldDisplayTextDescriptionsPreferenceKey, enabled);
1919     return S_OK;
1920 #else
1921     return E_NOTIMPL;
1922 #endif
1923 }
1924
1925 HRESULT WebPreferences::setRequestAnimationFrameEnabled(BOOL enabled)
1926 {
1927     setBoolValue(WebKitRequestAnimationFrameEnabledPreferenceKey, enabled);
1928     return S_OK;
1929 }
1930
1931 HRESULT WebPreferences::requestAnimationFrameEnabled(_Out_ BOOL* enabled)
1932 {
1933     if (!enabled)
1934         return E_POINTER;
1935     *enabled = boolValueForKey(WebKitRequestAnimationFrameEnabledPreferenceKey);
1936     return S_OK;
1937 }
1938
1939 HRESULT WebPreferences::isInheritURIQueryComponentEnabled(_Out_ BOOL* enabled)
1940 {
1941     if (!enabled)
1942         return E_POINTER;
1943     *enabled = boolValueForKey(WebKitEnableInheritURIQueryComponentPreferenceKey);
1944     return S_OK;
1945 }
1946
1947 HRESULT WebPreferences::setEnableInheritURIQueryComponent(BOOL enabled)
1948 {
1949     setBoolValue(WebKitEnableInheritURIQueryComponentPreferenceKey, enabled);
1950     return S_OK;
1951 }
1952
1953 HRESULT WebPreferences::allowDisplayAndRunningOfInsecureContent(_Out_ BOOL* enabled)
1954 {
1955     if (!enabled)
1956         return E_POINTER;
1957     *enabled = boolValueForKey(WebKitAllowDisplayAndRunningOfInsecureContentPreferenceKey);
1958     return S_OK;
1959 }
1960
1961 HRESULT WebPreferences::setAllowDisplayAndRunningOfInsecureContent(BOOL enabled)
1962 {
1963     setBoolValue(WebKitAllowDisplayAndRunningOfInsecureContentPreferenceKey, enabled);
1964     return S_OK;
1965 }
1966
1967 HRESULT WebPreferences::showTiledScrollingIndicator(_Out_ BOOL* enabled)
1968 {
1969     if (!enabled)
1970         return E_POINTER;
1971     *enabled = boolValueForKey(WebKitShowTiledScrollingIndicatorPreferenceKey);
1972     return S_OK;
1973 }
1974
1975 HRESULT WebPreferences::setShowTiledScrollingIndicator(BOOL enabled)
1976 {
1977     setBoolValue(WebKitShowTiledScrollingIndicatorPreferenceKey, enabled);
1978     return S_OK;
1979 }
1980
1981 HRESULT WebPreferences::fetchAPIEnabled(_Out_ BOOL* enabled)
1982 {
1983     if (!enabled)
1984         return E_POINTER;
1985     *enabled = boolValueForKey(WebKitFetchAPIEnabledPreferenceKey);
1986     return S_OK;
1987 }
1988
1989 HRESULT WebPreferences::setFetchAPIEnabled(BOOL enabled)
1990 {
1991     setBoolValue(WebKitFetchAPIEnabledPreferenceKey, enabled);
1992     return S_OK;
1993 }
1994
1995 HRESULT WebPreferences::shadowDOMEnabled(_Out_ BOOL* enabled)
1996 {
1997     if (!enabled)
1998         return E_POINTER;
1999     *enabled = boolValueForKey(WebKitShadowDOMEnabledPreferenceKey);
2000     return S_OK;
2001 }
2002
2003 HRESULT WebPreferences::setShadowDOMEnabled(BOOL enabled)
2004 {
2005     setBoolValue(WebKitShadowDOMEnabledPreferenceKey, enabled);
2006     return S_OK;
2007 }
2008
2009 HRESULT WebPreferences::customElementsEnabled(_Out_ BOOL* enabled)
2010 {
2011     if (!enabled)
2012         return E_POINTER;
2013     *enabled = boolValueForKey(WebKitCustomElementsEnabledPreferenceKey);
2014     return S_OK;
2015 }
2016
2017 HRESULT WebPreferences::setCustomElementsEnabled(BOOL enabled)
2018 {
2019     setBoolValue(WebKitCustomElementsEnabledPreferenceKey, enabled);
2020     return S_OK;
2021 }
2022
2023 HRESULT WebPreferences::menuItemElementEnabled(_Out_ BOOL* enabled)
2024 {
2025     if (!enabled)
2026         return E_POINTER;
2027     *enabled = boolValueForKey(WebKitMenuItemElementEnabledPreferenceKey);
2028     return S_OK;
2029 }
2030
2031 HRESULT WebPreferences::setMenuItemElementEnabled(BOOL enabled)
2032 {
2033     setBoolValue(WebKitMenuItemElementEnabledPreferenceKey, enabled);
2034     return S_OK;
2035 }
2036
2037 HRESULT WebPreferences::crossOriginWindowPolicySupportEnabled(_Out_ BOOL* enabled)
2038 {
2039     if (!enabled)
2040         return E_POINTER;
2041     *enabled = false;
2042     return S_OK;
2043 }
2044
2045 HRESULT WebPreferences::setCrossOriginWindowPolicySupportEnabled(BOOL)
2046 {
2047     return S_OK;
2048 }
2049
2050 HRESULT WebPreferences::setModernMediaControlsEnabled(BOOL enabled)
2051 {
2052     setBoolValue(WebKitModernMediaControlsEnabledPreferenceKey, enabled);
2053     return S_OK;
2054 }
2055
2056 HRESULT WebPreferences::modernMediaControlsEnabled(_Out_ BOOL* enabled)
2057 {
2058     if (!enabled)
2059         return E_POINTER;
2060     *enabled = boolValueForKey(WebKitModernMediaControlsEnabledPreferenceKey);
2061     return S_OK;
2062 }
2063
2064 HRESULT WebPreferences::webAnimationsCSSIntegrationEnabled(_Out_ BOOL* enabled)
2065 {
2066     if (!enabled)
2067         return E_POINTER;
2068     *enabled = boolValueForKey(WebKitWebAnimationsCSSIntegrationEnabledPreferenceKey);
2069     return S_OK;
2070 }
2071
2072 HRESULT WebPreferences::setWebAnimationsCSSIntegrationEnabled(BOOL enabled)
2073 {
2074     setBoolValue(WebKitWebAnimationsCSSIntegrationEnabledPreferenceKey, enabled);
2075     return S_OK;
2076 }
2077
2078 HRESULT WebPreferences::fetchAPIKeepAliveEnabled(_Out_ BOOL* enabled)
2079 {
2080     if (!enabled)
2081         return E_POINTER;
2082     *enabled = boolValueForKey(WebKitFetchAPIKeepAliveEnabledPreferenceKey);
2083     return S_OK;
2084 }
2085
2086 HRESULT WebPreferences::setFetchAPIKeepAliveEnabled(BOOL enabled)
2087 {
2088     setBoolValue(WebKitFetchAPIKeepAliveEnabledPreferenceKey, enabled);
2089     return S_OK;
2090 }
2091
2092 HRESULT WebPreferences::setLinkPreloadEnabled(BOOL enabled)
2093 {
2094     setBoolValue(WebKitLinkPreloadEnabledPreferenceKey, enabled);
2095     return S_OK;
2096 }
2097
2098 HRESULT WebPreferences::linkPreloadEnabled(_Out_ BOOL* enabled)
2099 {
2100     if (!enabled)
2101         return E_POINTER;
2102     *enabled = boolValueForKey(WebKitLinkPreloadEnabledPreferenceKey);
2103     return S_OK;
2104 }
2105
2106 HRESULT WebPreferences::setMediaPreloadingEnabled(BOOL enabled)
2107 {
2108     setBoolValue(WebKitMediaPreloadingEnabledPreferenceKey, enabled);
2109     return S_OK;
2110 }
2111
2112 HRESULT WebPreferences::mediaPreloadingEnabled(_Out_ BOOL* enabled)
2113 {
2114     if (!enabled)
2115         return E_POINTER;
2116     *enabled = boolValueForKey(WebKitMediaPreloadingEnabledPreferenceKey);
2117     return S_OK;
2118 }
2119
2120 HRESULT WebPreferences::clearNetworkLoaderSession()
2121 {
2122     NetworkStorageSessionMap::defaultStorageSession().deleteAllCookies();
2123     return S_OK;
2124 }
2125
2126 HRESULT WebPreferences::switchNetworkLoaderToNewTestingSession()
2127 {
2128     NetworkStorageSessionMap::switchToNewTestingSession();
2129     return S_OK;
2130 }
2131
2132 HRESULT WebPreferences::setIsSecureContextAttributeEnabled(BOOL enabled)
2133 {
2134     setBoolValue(WebKitIsSecureContextAttributeEnabledPreferenceKey, enabled);
2135     return S_OK;
2136 }
2137
2138 HRESULT WebPreferences::isSecureContextAttributeEnabled(_Out_ BOOL* enabled)
2139 {
2140     if (!enabled)
2141         return E_POINTER;
2142     *enabled = boolValueForKey(WebKitIsSecureContextAttributeEnabledPreferenceKey);
2143     return S_OK;
2144 }
2145
2146 HRESULT WebPreferences::dataTransferItemsEnabled(_Out_ BOOL* enabled)
2147 {
2148     if (!enabled)
2149         return E_POINTER;
2150     *enabled = boolValueForKey(WebKitDataTransferItemsEnabledPreferenceKey);
2151     return S_OK;
2152 }
2153
2154 HRESULT WebPreferences::setDataTransferItemsEnabled(BOOL enabled)
2155 {
2156     setBoolValue(WebKitDataTransferItemsEnabledPreferenceKey, enabled);
2157     return S_OK;
2158 }
2159
2160 HRESULT WebPreferences::inspectorAdditionsEnabled(_Out_ BOOL* enabled)
2161 {
2162     if (!enabled)
2163         return E_POINTER;
2164     *enabled = boolValueForKey(WebKitInspectorAdditionsEnabledPreferenceKey);
2165     return S_OK;
2166 }
2167
2168 HRESULT WebPreferences::setInspectorAdditionsEnabled(BOOL enabled)
2169 {
2170     setBoolValue(WebKitInspectorAdditionsEnabledPreferenceKey, enabled);
2171     return S_OK;
2172 }
2173
2174 HRESULT WebPreferences::visualViewportAPIEnabled(_Out_ BOOL* enabled)
2175 {
2176     if (!enabled)
2177         return E_POINTER;
2178     *enabled = boolValueForKey(WebKitVisualViewportAPIEnabledPreferenceKey);
2179     return S_OK;
2180 }
2181
2182 HRESULT WebPreferences::setVisualViewportAPIEnabled(BOOL enabled)
2183 {
2184     setBoolValue(WebKitVisualViewportAPIEnabledPreferenceKey, enabled);
2185     return S_OK;
2186 }
2187
2188 HRESULT WebPreferences::CSSOMViewScrollingAPIEnabled(_Out_ BOOL* enabled)
2189 {
2190     if (!enabled)
2191         return E_POINTER;
2192     *enabled = boolValueForKey(WebKitCSSOMViewScrollingAPIEnabledPreferenceKey);
2193     return S_OK;
2194 }
2195
2196 HRESULT WebPreferences::setCSSOMViewScrollingAPIEnabled(BOOL enabled)
2197 {
2198     setBoolValue(WebKitCSSOMViewScrollingAPIEnabledPreferenceKey, enabled);
2199     return S_OK;
2200 }
2201
2202 HRESULT WebPreferences::setApplicationId(BSTR applicationId)
2203 {
2204     m_applicationId = String(applicationId).createCFString();
2205     return S_OK;
2206 }
2207
2208 HRESULT WebPreferences::setWebAnimationsEnabled(BOOL enabled)
2209 {
2210     setBoolValue(WebKitWebAnimationsEnabledPreferenceKey, enabled);
2211     return S_OK;
2212 }
2213
2214 HRESULT WebPreferences::webAnimationsEnabled(_Out_ BOOL* enabled)
2215 {
2216     if (!enabled)
2217         return E_POINTER;
2218     *enabled = boolValueForKey(WebKitWebAnimationsEnabledPreferenceKey);
2219     return S_OK;
2220 }
2221
2222 HRESULT WebPreferences::setUserTimingEnabled(BOOL enabled)
2223 {
2224     setBoolValue(WebKitUserTimingEnabledPreferenceKey, enabled);
2225     return S_OK;
2226 }
2227
2228 HRESULT WebPreferences::userTimingEnabled(_Out_ BOOL* enabled)
2229 {
2230     if (!enabled)
2231         return E_POINTER;
2232     *enabled = boolValueForKey(WebKitUserTimingEnabledPreferenceKey);
2233     return S_OK;
2234 }
2235
2236 HRESULT WebPreferences::setResourceTimingEnabled(BOOL enabled)
2237 {
2238     setBoolValue(WebKitResourceTimingEnabledPreferenceKey, enabled);
2239     return S_OK;
2240 }
2241
2242 HRESULT WebPreferences::resourceTimingEnabled(_Out_ BOOL* enabled)
2243 {
2244     if (!enabled)
2245         return E_POINTER;
2246     *enabled = boolValueForKey(WebKitResourceTimingEnabledPreferenceKey);
2247     return S_OK;
2248 }
2249
2250 HRESULT WebPreferences::serverTimingEnabled(_Out_ BOOL* enabled)
2251 {
2252     if (!enabled)
2253         return E_POINTER;
2254     *enabled = boolValueForKey(WebKitServerTimingEnabledPreferenceKey);
2255     return S_OK;
2256 }
2257
2258 HRESULT WebPreferences::setServerTimingEnabled(BOOL enabled)
2259 {
2260     setBoolValue(WebKitServerTimingEnabledPreferenceKey, enabled);
2261     return S_OK;
2262 }