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