66175e059589e9af0070a28c2298bffc8b8b0103
[WebKit-https.git] / Source / WebKit / win / WebPreferences.cpp
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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 COMPUTER, 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 COMPUTER, 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 "config.h"
27 #include "WebKit.h"
28 #include "WebKitDLL.h"
29 #include "WebPreferences.h"
30
31 #include "WebNotificationCenter.h"
32 #include "WebPreferenceKeysPrivate.h"
33
34 #include <CoreFoundation/CoreFoundation.h>
35 #include <WebCore/CACFLayerTreeHost.h>
36 #include <WebCore/COMPtr.h>
37 #include <WebCore/FileSystem.h>
38 #include <WebCore/Font.h>
39 #include <WebCore/LocalizedStrings.h>
40 #include <limits>
41 #include <shlobj.h>
42 #include <wchar.h>
43 #include <wtf/HashMap.h>
44 #include <wtf/OwnArrayPtr.h>
45 #include <wtf/text/CString.h>
46 #include <wtf/text/StringHash.h>
47 #include <wtf/text/WTFString.h>
48
49 #if USE(CG)
50 #include <CoreGraphics/CoreGraphics.h>
51 #include <WebKitSystemInterface/WebKitSystemInterface.h>
52 #endif
53
54 using namespace WebCore;
55 using std::numeric_limits;
56
57 static const String& oldPreferencesPath()
58 {
59     static String path = pathByAppendingComponent(roamingUserSpecificStorageDirectory(), "WebKitPreferences.plist");
60     return path;
61 }
62
63 template<typename NumberType> struct CFNumberTraits { static const unsigned Type; };
64 template<> struct CFNumberTraits<int> { static const unsigned Type = kCFNumberSInt32Type; };
65 template<> struct CFNumberTraits<LONGLONG> { static const unsigned Type = kCFNumberLongLongType; };
66 template<> struct CFNumberTraits<float> { static const unsigned Type = kCFNumberFloat32Type; };
67
68 template<typename NumberType>
69 static NumberType numberValueForPreferencesValue(CFPropertyListRef value)
70 {
71     if (!value)
72         return 0;
73
74     CFTypeID cfType = CFGetTypeID(value);
75     if (cfType == CFStringGetTypeID())
76         return static_cast<NumberType>(CFStringGetIntValue(static_cast<CFStringRef>(value)));
77     else if (cfType == CFBooleanGetTypeID()) {
78         Boolean boolVal = CFBooleanGetValue(static_cast<CFBooleanRef>(value));
79         return boolVal ? 1 : 0;
80     } else if (cfType == CFNumberGetTypeID()) {
81         NumberType val = 0;
82         CFNumberGetValue(static_cast<CFNumberRef>(value), CFNumberTraits<NumberType>::Type, &val);
83         return val;
84     }
85
86     return 0;
87 }
88
89 template<typename NumberType>
90 static RetainPtr<CFNumberRef> cfNumber(NumberType value)
91 {
92     return RetainPtr<CFNumberRef>(AdoptCF, CFNumberCreate(0, CFNumberTraits<NumberType>::Type, &value));
93 }
94
95 static bool booleanValueForPreferencesValue(CFPropertyListRef value)
96 {
97     return numberValueForPreferencesValue<int>(value);
98 }
99
100 // WebPreferences ----------------------------------------------------------------
101
102 static CFDictionaryRef defaultSettings;
103
104 static HashMap<WTF::String, COMPtr<WebPreferences> > webPreferencesInstances;
105
106 WebPreferences* WebPreferences::sharedStandardPreferences()
107 {
108     static WebPreferences* standardPreferences;
109     if (!standardPreferences) {
110         standardPreferences = WebPreferences::createInstance();
111         standardPreferences->setAutosaves(TRUE);
112         standardPreferences->load();
113     }
114
115     return standardPreferences;
116 }
117
118 WebPreferences::WebPreferences()
119     : m_refCount(0)
120     , m_autoSaves(0)
121     , m_automaticallyDetectsCacheModel(true)
122     , m_numWebViews(0)
123 {
124     gClassCount++;
125     gClassNameCount.add("WebPreferences");
126 }
127
128 WebPreferences::~WebPreferences()
129 {
130     gClassCount--;
131     gClassNameCount.remove("WebPreferences");
132 }
133
134 WebPreferences* WebPreferences::createInstance()
135 {
136     WebPreferences* instance = new WebPreferences();
137     instance->AddRef();
138     return instance;
139 }
140
141 HRESULT WebPreferences::postPreferencesChangesNotification()
142 {
143     IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
144     HRESULT hr = nc->postNotificationName(webPreferencesChangedNotification(), static_cast<IWebPreferences*>(this), 0);
145     if (FAILED(hr))
146         return hr;
147
148     return S_OK;
149 }
150
151 WebPreferences* WebPreferences::getInstanceForIdentifier(BSTR identifier)
152 {
153     if (!identifier)
154         return sharedStandardPreferences();
155
156     WTF::String identifierString(identifier, SysStringLen(identifier));
157     return webPreferencesInstances.get(identifierString).get();
158 }
159
160 void WebPreferences::setInstance(WebPreferences* instance, BSTR identifier)
161 {
162     if (!identifier || !instance)
163         return;
164     WTF::String identifierString(identifier, SysStringLen(identifier));
165     webPreferencesInstances.add(identifierString, instance);
166 }
167
168 void WebPreferences::removeReferenceForIdentifier(BSTR identifier)
169 {
170     if (!identifier || webPreferencesInstances.isEmpty())
171         return;
172
173     WTF::String identifierString(identifier, SysStringLen(identifier));
174     WebPreferences* webPreference = webPreferencesInstances.get(identifierString).get();
175     if (webPreference && webPreference->m_refCount == 1)
176         webPreferencesInstances.remove(identifierString);
177 }
178
179 void WebPreferences::initializeDefaultSettings()
180 {
181     if (defaultSettings)
182         return;
183
184     CFMutableDictionaryRef defaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
185
186     CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman"));
187     CFDictionaryAddValue(defaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New"));
188     CFDictionaryAddValue(defaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman"));
189     CFDictionaryAddValue(defaults, CFSTR(WebKitSansSerifFontPreferenceKey), CFSTR("Arial"));
190     CFDictionaryAddValue(defaults, CFSTR(WebKitCursiveFontPreferenceKey), CFSTR("Comic Sans MS"));
191     CFDictionaryAddValue(defaults, CFSTR(WebKitFantasyFontPreferenceKey), CFSTR("Comic Sans MS"));
192     CFDictionaryAddValue(defaults, CFSTR(WebKitPictographFontPreferenceKey), CFSTR("Times New Roman"));
193     CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumFontSizePreferenceKey), CFSTR("0"));
194     CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), CFSTR("9"));
195     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFontSizePreferenceKey), CFSTR("16"));
196     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFixedFontSizePreferenceKey), CFSTR("13"));
197
198     String defaultDefaultEncoding(WEB_UI_STRING("ISO-8859-1", "The default, default character encoding"));
199     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), defaultDefaultEncoding.createCFString());
200
201     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), kCFBooleanFalse);
202     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetLocationPreferenceKey), CFSTR(""));
203     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), kCFBooleanFalse);
204     CFDictionaryAddValue(defaults, CFSTR(WebKitTextAreasAreResizablePreferenceKey), kCFBooleanFalse);
205     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaEnabledPreferenceKey), kCFBooleanTrue);
206     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptEnabledPreferenceKey), kCFBooleanTrue);
207     CFDictionaryAddValue(defaults, CFSTR(WebKitWebSecurityEnabledPreferenceKey), kCFBooleanTrue);
208     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowUniversalAccessFromFileURLsPreferenceKey), kCFBooleanFalse);
209     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowFileAccessFromFileURLsPreferenceKey), kCFBooleanTrue);
210     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanAccessClipboardPreferenceKey), kCFBooleanFalse);
211     CFDictionaryAddValue(defaults, CFSTR(WebKitXSSAuditorEnabledPreferenceKey), kCFBooleanTrue);
212     CFDictionaryAddValue(defaults, CFSTR(WebKitFrameFlatteningEnabledPreferenceKey), kCFBooleanFalse);
213     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), kCFBooleanTrue);
214     CFDictionaryAddValue(defaults, CFSTR(WebKitPluginsEnabledPreferenceKey), kCFBooleanTrue);
215     CFDictionaryAddValue(defaults, CFSTR(WebKitDatabasesEnabledPreferenceKey), kCFBooleanTrue);
216     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageEnabledPreferenceKey), kCFBooleanTrue);
217     CFDictionaryAddValue(defaults, CFSTR(WebKitExperimentalNotificationsEnabledPreferenceKey), kCFBooleanFalse);
218     CFDictionaryAddValue(defaults, CFSTR(WebKitZoomsTextOnlyPreferenceKey), kCFBooleanTrue);
219     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImagesPreferenceKey), kCFBooleanTrue);
220     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), kCFBooleanTrue);
221     CFDictionaryAddValue(defaults, CFSTR(WebKitDisplayImagesKey), kCFBooleanTrue);
222     CFDictionaryAddValue(defaults, CFSTR(WebKitLoadSiteIconsKey), kCFBooleanFalse);
223     CFDictionaryAddValue(defaults, CFSTR(WebKitBackForwardCacheExpirationIntervalKey), CFSTR("1800"));
224     CFDictionaryAddValue(defaults, CFSTR(WebKitTabToLinksPreferenceKey), kCFBooleanFalse);
225     CFDictionaryAddValue(defaults, CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), kCFBooleanFalse);
226     CFDictionaryAddValue(defaults, CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey), kCFBooleanFalse);
227     CFDictionaryAddValue(defaults, CFSTR(WebKitShowsURLsInToolTipsPreferenceKey), kCFBooleanFalse);
228     CFDictionaryAddValue(defaults, CFSTR(WebKitShowsToolTipOverTruncatedTextPreferenceKey), kCFBooleanFalse);
229     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFDisplayModePreferenceKey), CFSTR("1"));
230     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFScaleFactorPreferenceKey), CFSTR("0"));
231     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplaySubtitlesPreferenceKey), kCFBooleanFalse);
232     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplayCaptionsPreferenceKey), kCFBooleanFalse);
233     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplayTextDescriptionsPreferenceKey), kCFBooleanFalse);
234
235     RetainPtr<CFStringRef> linkBehaviorStringRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior));
236     CFDictionaryAddValue(defaults, CFSTR(WebKitEditableLinkBehaviorPreferenceKey), linkBehaviorStringRef.get());
237
238     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryItemLimitKey), CFSTR("1000"));
239     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryAgeInDaysLimitKey), CFSTR("7"));
240     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseLocationKey), CFSTR(""));
241     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseEnabledPreferenceKey), kCFBooleanTrue);
242     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingTypePreferenceKey), CFSTR("2"));
243     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingContrastPreferenceKey), CFSTR("2"));
244     CFDictionaryAddValue(defaults, CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), CFSTR("2"));
245     CFDictionaryAddValue(defaults, CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), kCFBooleanFalse);
246     CFDictionaryAddValue(defaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse);
247     CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
248     CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
249     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageDatabasePathPreferenceKey), CFSTR(""));
250
251     RetainPtr<CFStringRef> cacheModelRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebCacheModelDocumentViewer));
252     CFDictionaryAddValue(defaults, CFSTR(WebKitCacheModelPreferenceKey), cacheModelRef.get());
253
254     CFDictionaryAddValue(defaults, CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey), kCFBooleanTrue);
255     CFDictionaryAddValue(defaults, CFSTR(WebKitApplicationChromeModePreferenceKey), kCFBooleanFalse);
256
257     CFDictionaryAddValue(defaults, CFSTR(WebKitOfflineWebApplicationCacheEnabledPreferenceKey), kCFBooleanFalse);
258
259     CFDictionaryAddValue(defaults, CFSTR(WebKitPaintNativeControlsPreferenceKey), kCFBooleanTrue);
260
261     CFDictionaryAddValue(defaults, CFSTR(WebKitUseHighResolutionTimersPreferenceKey), kCFBooleanTrue);
262
263     CFDictionaryAddValue(defaults, CFSTR(WebKitAcceleratedCompositingEnabledPreferenceKey), kCFBooleanFalse);
264     
265     CFDictionaryAddValue(defaults, CFSTR(WebKitShowDebugBordersPreferenceKey), kCFBooleanFalse);
266
267     CFDictionaryAddValue(defaults, CFSTR(WebKitDNSPrefetchingEnabledPreferenceKey), kCFBooleanFalse);
268
269     CFDictionaryAddValue(defaults, CFSTR(WebKitMemoryInfoEnabledPreferenceKey), kCFBooleanFalse);
270     CFDictionaryAddValue(defaults, CFSTR(WebKitHyperlinkAuditingEnabledPreferenceKey), kCFBooleanTrue);
271     CFDictionaryAddValue(defaults, CFSTR(WebKitHixie76WebSocketProtocolEnabledPreferenceKey), kCFBooleanTrue);
272
273     CFDictionaryAddValue(defaults, CFSTR(WebKitMediaPlaybackRequiresUserGesturePreferenceKey), kCFBooleanFalse);
274     CFDictionaryAddValue(defaults, CFSTR(WebKitMediaPlaybackAllowsInlinePreferenceKey), kCFBooleanTrue);
275
276     defaultSettings = defaults;
277 }
278
279 RetainPtr<CFPropertyListRef> WebPreferences::valueForKey(CFStringRef key)
280 {
281     RetainPtr<CFPropertyListRef> value = CFDictionaryGetValue(m_privatePrefs.get(), key);
282     if (value)
283         return value;
284
285     value.adoptCF(CFPreferencesCopyAppValue(key, kCFPreferencesCurrentApplication));
286     if (value)
287         return value;
288
289     return CFDictionaryGetValue(defaultSettings, key);
290 }
291
292 void WebPreferences::setValueForKey(CFStringRef key, CFPropertyListRef value)
293 {
294     CFDictionarySetValue(m_privatePrefs.get(), key, value);
295     if (m_autoSaves) {
296         CFPreferencesSetAppValue(key, value, kCFPreferencesCurrentApplication);
297         save();
298     }
299 }
300
301 BSTR WebPreferences::stringValueForKey(CFStringRef key)
302 {
303     RetainPtr<CFPropertyListRef> value = valueForKey(key);
304     
305     if (!value || (CFGetTypeID(value.get()) != CFStringGetTypeID()))
306         return 0;
307
308     CFStringRef str = static_cast<CFStringRef>(value.get());
309
310     CFIndex length = CFStringGetLength(str);
311     const UniChar* uniChars = CFStringGetCharactersPtr(str);
312     if (uniChars)
313         return SysAllocStringLen((LPCTSTR)uniChars, length);
314
315     BSTR bstr = SysAllocStringLen(0, length);
316     if (!bstr)
317         return 0;
318
319     if (!CFStringGetCString(str, (char*)bstr, (length+1)*sizeof(WCHAR), kCFStringEncodingUTF16)) {
320         SysFreeString(bstr);
321         return 0;
322     }
323         
324     bstr[length] = 0;
325     return bstr;
326 }
327
328 int WebPreferences::integerValueForKey(CFStringRef key)
329 {
330     return numberValueForPreferencesValue<int>(valueForKey(key).get());
331 }
332
333 BOOL WebPreferences::boolValueForKey(CFStringRef key)
334 {
335     return booleanValueForPreferencesValue(valueForKey(key).get());
336 }
337
338 float WebPreferences::floatValueForKey(CFStringRef key)
339 {
340     return numberValueForPreferencesValue<float>(valueForKey(key).get());
341 }
342
343 LONGLONG WebPreferences::longlongValueForKey(CFStringRef key)
344 {
345     return numberValueForPreferencesValue<LONGLONG>(valueForKey(key).get());
346 }
347
348 void WebPreferences::setStringValue(CFStringRef key, LPCTSTR value)
349 {
350     BSTR val = stringValueForKey(key);
351     if (val && !wcscmp(val, value))
352         return;
353     SysFreeString(val);
354     
355     RetainPtr<CFStringRef> valueRef(AdoptCF,
356         CFStringCreateWithCharactersNoCopy(0, (UniChar*)_wcsdup(value), (CFIndex)wcslen(value), kCFAllocatorMalloc));
357     setValueForKey(key, valueRef.get());
358
359     postPreferencesChangesNotification();
360 }
361
362 void WebPreferences::setIntegerValue(CFStringRef key, int value)
363 {
364     if (integerValueForKey(key) == value)
365         return;
366
367     setValueForKey(key, cfNumber(value).get());
368
369     postPreferencesChangesNotification();
370 }
371
372 void WebPreferences::setFloatValue(CFStringRef key, float value)
373 {
374     if (floatValueForKey(key) == value)
375         return;
376
377     setValueForKey(key, cfNumber(value).get());
378
379     postPreferencesChangesNotification();
380 }
381
382 void WebPreferences::setBoolValue(CFStringRef key, BOOL value)
383 {
384     if (boolValueForKey(key) == value)
385         return;
386
387     setValueForKey(key, value ? kCFBooleanTrue : kCFBooleanFalse);
388
389     postPreferencesChangesNotification();
390 }
391
392 void WebPreferences::setLongLongValue(CFStringRef key, LONGLONG value)
393 {
394     if (longlongValueForKey(key) == value)
395         return;
396
397     setValueForKey(key, cfNumber(value).get());
398
399     postPreferencesChangesNotification();
400 }
401
402 BSTR WebPreferences::webPreferencesChangedNotification()
403 {
404     static BSTR webPreferencesChangedNotification = SysAllocString(WebPreferencesChangedNotification);
405     return webPreferencesChangedNotification;
406 }
407
408 BSTR WebPreferences::webPreferencesRemovedNotification()
409 {
410     static BSTR webPreferencesRemovedNotification = SysAllocString(WebPreferencesRemovedNotification);
411     return webPreferencesRemovedNotification;
412 }
413
414 void WebPreferences::save()
415 {
416     CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
417 }
418
419 void WebPreferences::load()
420 {
421     initializeDefaultSettings();
422
423     m_privatePrefs.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
424
425     migrateWebKitPreferencesToCFPreferences();
426 }
427
428 void WebPreferences::migrateWebKitPreferencesToCFPreferences()
429 {
430     CFStringRef didMigrateKey = CFSTR(WebKitDidMigrateWebKitPreferencesToCFPreferencesPreferenceKey);
431     if (boolValueForKey(didMigrateKey))
432         return;
433     bool oldValue = m_autoSaves;
434     m_autoSaves = true;
435     setBoolValue(didMigrateKey, TRUE);
436     m_autoSaves = oldValue;
437
438     WTF::CString path = oldPreferencesPath().utf8();
439
440     RetainPtr<CFURLRef> urlRef(AdoptCF, CFURLCreateFromFileSystemRepresentation(0, reinterpret_cast<const UInt8*>(path.data()), path.length(), false));
441     if (!urlRef)
442         return;
443
444     RetainPtr<CFReadStreamRef> stream(AdoptCF, CFReadStreamCreateWithFile(0, urlRef.get()));
445     if (!stream)
446         return;
447
448     if (!CFReadStreamOpen(stream.get()))
449         return;
450
451     CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0;
452     RetainPtr<CFPropertyListRef> plist(AdoptCF, CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0));
453     CFReadStreamClose(stream.get());
454
455     if (!plist || CFGetTypeID(plist.get()) != CFDictionaryGetTypeID())
456         return;
457
458     copyWebKitPreferencesToCFPreferences(static_cast<CFDictionaryRef>(plist.get()));
459
460     deleteFile(oldPreferencesPath());
461 }
462
463 void WebPreferences::copyWebKitPreferencesToCFPreferences(CFDictionaryRef dict)
464 {
465     ASSERT_ARG(dict, dict);
466
467     int count = CFDictionaryGetCount(dict);
468     if (count <= 0)
469         return;
470
471     CFStringRef didRemoveDefaultsKey = CFSTR(WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey);
472     bool omitDefaults = !booleanValueForPreferencesValue(CFDictionaryGetValue(dict, didRemoveDefaultsKey));
473
474     OwnArrayPtr<CFTypeRef> keys = adoptArrayPtr(new CFTypeRef[count]);
475     OwnArrayPtr<CFTypeRef> values = adoptArrayPtr(new CFTypeRef[count]);
476     CFDictionaryGetKeysAndValues(dict, keys.get(), values.get());
477
478     for (int i = 0; i < count; ++i) {
479         if (!keys[i] || !values[i] || CFGetTypeID(keys[i]) != CFStringGetTypeID())
480             continue;
481
482         if (omitDefaults) {
483             CFTypeRef defaultValue = CFDictionaryGetValue(defaultSettings, keys[i]);
484             if (defaultValue && CFEqual(defaultValue, values[i]))
485                 continue;
486         }
487
488         setValueForKey(static_cast<CFStringRef>(keys[i]), values[i]);
489     }
490 }
491
492 // IUnknown -------------------------------------------------------------------
493
494 HRESULT STDMETHODCALLTYPE WebPreferences::QueryInterface(REFIID riid, void** ppvObject)
495 {
496     *ppvObject = 0;
497     if (IsEqualGUID(riid, IID_IUnknown))
498         *ppvObject = static_cast<IWebPreferences*>(this);
499     else if (IsEqualGUID(riid, IID_IWebPreferences))
500         *ppvObject = static_cast<IWebPreferences*>(this);
501     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate))
502         *ppvObject = static_cast<IWebPreferencesPrivate*>(this);
503     else if (IsEqualGUID(riid, CLSID_WebPreferences))
504         *ppvObject = this;
505     else
506         return E_NOINTERFACE;
507
508     AddRef();
509     return S_OK;
510 }
511
512 ULONG STDMETHODCALLTYPE WebPreferences::AddRef(void)
513 {
514     return ++m_refCount;
515 }
516
517 ULONG STDMETHODCALLTYPE WebPreferences::Release(void)
518 {
519     ULONG newRef = --m_refCount;
520     if (!newRef)
521         delete(this);
522
523     return newRef;
524 }
525
526 // IWebPreferences ------------------------------------------------------------
527
528 HRESULT STDMETHODCALLTYPE WebPreferences::standardPreferences( 
529     /* [retval][out] */ IWebPreferences** standardPreferences)
530 {
531     if (!standardPreferences)
532         return E_POINTER;
533     *standardPreferences = sharedStandardPreferences();
534     (*standardPreferences)->AddRef();
535     return S_OK;
536 }
537
538 HRESULT STDMETHODCALLTYPE WebPreferences::initWithIdentifier( 
539         /* [in] */ BSTR anIdentifier,
540         /* [retval][out] */ IWebPreferences** preferences)
541 {
542     WebPreferences *instance = getInstanceForIdentifier(anIdentifier);
543     if (instance) {
544         *preferences = instance;
545         instance->AddRef();
546         return S_OK;
547     }
548
549     load();
550
551     *preferences = this;
552     AddRef();
553
554     if (anIdentifier) {
555         m_identifier = anIdentifier;
556         setInstance(this, m_identifier);
557     }
558
559     this->postPreferencesChangesNotification();
560
561     return S_OK;
562 }
563
564 HRESULT STDMETHODCALLTYPE WebPreferences::identifier( 
565     /* [retval][out] */ BSTR* ident)
566 {
567     if (!ident)
568         return E_POINTER;
569     *ident = m_identifier ? SysAllocString(m_identifier) : 0;
570     return S_OK;
571 }
572
573 HRESULT STDMETHODCALLTYPE WebPreferences::standardFontFamily( 
574     /* [retval][out] */ BSTR* family)
575 {
576     *family = stringValueForKey(CFSTR(WebKitStandardFontPreferenceKey));
577     return (*family) ? S_OK : E_FAIL;
578 }
579
580 HRESULT STDMETHODCALLTYPE WebPreferences::setStandardFontFamily( 
581     /* [in] */ BSTR family)
582 {
583     setStringValue(CFSTR(WebKitStandardFontPreferenceKey), family);
584     return S_OK;
585 }
586
587 HRESULT STDMETHODCALLTYPE WebPreferences::fixedFontFamily( 
588     /* [retval][out] */ BSTR* family)
589 {
590     *family = stringValueForKey(CFSTR(WebKitFixedFontPreferenceKey));
591     return (*family) ? S_OK : E_FAIL;
592 }
593
594 HRESULT STDMETHODCALLTYPE WebPreferences::setFixedFontFamily( 
595     /* [in] */ BSTR family)
596 {
597     setStringValue(CFSTR(WebKitFixedFontPreferenceKey), family);
598     return S_OK;
599 }
600
601 HRESULT STDMETHODCALLTYPE WebPreferences::serifFontFamily( 
602     /* [retval][out] */ BSTR* fontFamily)
603 {
604     *fontFamily = stringValueForKey(CFSTR(WebKitSerifFontPreferenceKey));
605     return (*fontFamily) ? S_OK : E_FAIL;
606 }
607
608 HRESULT STDMETHODCALLTYPE WebPreferences::setSerifFontFamily( 
609     /* [in] */ BSTR family)
610 {
611     setStringValue(CFSTR(WebKitSerifFontPreferenceKey), family);
612     return S_OK;
613 }
614
615 HRESULT STDMETHODCALLTYPE WebPreferences::sansSerifFontFamily( 
616     /* [retval][out] */ BSTR* family)
617 {
618     *family = stringValueForKey(CFSTR(WebKitSansSerifFontPreferenceKey));
619     return (*family) ? S_OK : E_FAIL;
620 }
621
622 HRESULT STDMETHODCALLTYPE WebPreferences::setSansSerifFontFamily( 
623     /* [in] */ BSTR family)
624 {
625     setStringValue(CFSTR(WebKitSansSerifFontPreferenceKey), family);
626     return S_OK;
627 }
628
629 HRESULT STDMETHODCALLTYPE WebPreferences::cursiveFontFamily( 
630     /* [retval][out] */ BSTR* family)
631 {
632     *family = stringValueForKey(CFSTR(WebKitCursiveFontPreferenceKey));
633     return (*family) ? S_OK : E_FAIL;
634 }
635
636 HRESULT STDMETHODCALLTYPE WebPreferences::setCursiveFontFamily( 
637     /* [in] */ BSTR family)
638 {
639     setStringValue(CFSTR(WebKitCursiveFontPreferenceKey), family);
640     return S_OK;
641 }
642
643 HRESULT STDMETHODCALLTYPE WebPreferences::fantasyFontFamily( 
644     /* [retval][out] */ BSTR* family)
645 {
646     *family = stringValueForKey(CFSTR(WebKitFantasyFontPreferenceKey));
647     return (*family) ? S_OK : E_FAIL;
648 }
649
650 HRESULT STDMETHODCALLTYPE WebPreferences::setFantasyFontFamily( 
651     /* [in] */ BSTR family)
652 {
653     setStringValue(CFSTR(WebKitFantasyFontPreferenceKey), family);
654     return S_OK;
655 }
656
657 HRESULT STDMETHODCALLTYPE WebPreferences::pictographFontFamily( 
658     /* [retval][out] */ BSTR* family)
659 {
660     *family = stringValueForKey(CFSTR(WebKitPictographFontPreferenceKey));
661     return (*family) ? S_OK : E_FAIL;
662 }
663
664 HRESULT STDMETHODCALLTYPE WebPreferences::setPictographFontFamily( 
665     /* [in] */ BSTR family)
666 {
667     setStringValue(CFSTR(WebKitPictographFontPreferenceKey), family);
668     return S_OK;
669 }
670
671 HRESULT STDMETHODCALLTYPE WebPreferences::defaultFontSize( 
672     /* [retval][out] */ int* fontSize)
673 {
674     *fontSize = integerValueForKey(CFSTR(WebKitDefaultFontSizePreferenceKey));
675     return S_OK;
676 }
677
678 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultFontSize( 
679     /* [in] */ int fontSize)
680 {
681     setIntegerValue(CFSTR(WebKitDefaultFontSizePreferenceKey), fontSize);
682     return S_OK;
683 }
684
685 HRESULT STDMETHODCALLTYPE WebPreferences::defaultFixedFontSize( 
686     /* [retval][out] */ int* fontSize)
687 {
688     *fontSize = integerValueForKey(CFSTR(WebKitDefaultFixedFontSizePreferenceKey));
689     return S_OK;
690 }
691
692 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultFixedFontSize( 
693     /* [in] */ int fontSize)
694 {
695     setIntegerValue(CFSTR(WebKitDefaultFixedFontSizePreferenceKey), fontSize);
696     return S_OK;
697 }
698
699 HRESULT STDMETHODCALLTYPE WebPreferences::minimumFontSize( 
700     /* [retval][out] */ int* fontSize)
701 {
702     *fontSize = integerValueForKey(CFSTR(WebKitMinimumFontSizePreferenceKey));
703     return S_OK;
704 }
705
706 HRESULT STDMETHODCALLTYPE WebPreferences::setMinimumFontSize( 
707     /* [in] */ int fontSize)
708 {
709     setIntegerValue(CFSTR(WebKitMinimumFontSizePreferenceKey), fontSize);
710     return S_OK;
711 }
712
713 HRESULT STDMETHODCALLTYPE WebPreferences::minimumLogicalFontSize( 
714     /* [retval][out] */ int* fontSize)
715 {
716     *fontSize = integerValueForKey(CFSTR(WebKitMinimumLogicalFontSizePreferenceKey));
717     return S_OK;
718 }
719
720 HRESULT STDMETHODCALLTYPE WebPreferences::setMinimumLogicalFontSize( 
721     /* [in] */ int fontSize)
722 {
723     setIntegerValue(CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), fontSize);
724     return S_OK;
725 }
726
727 HRESULT STDMETHODCALLTYPE WebPreferences::defaultTextEncodingName( 
728     /* [retval][out] */ BSTR* name)
729 {
730     *name = stringValueForKey(CFSTR(WebKitDefaultTextEncodingNamePreferenceKey));
731     return (*name) ? S_OK : E_FAIL;
732 }
733
734 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultTextEncodingName( 
735     /* [in] */ BSTR name)
736 {
737     setStringValue(CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), name);
738     return S_OK;
739 }
740
741 HRESULT STDMETHODCALLTYPE WebPreferences::userStyleSheetEnabled( 
742     /* [retval][out] */ BOOL* enabled)
743 {
744     *enabled = boolValueForKey(CFSTR(WebKitUserStyleSheetEnabledPreferenceKey));
745     return S_OK;
746 }
747
748 HRESULT STDMETHODCALLTYPE WebPreferences::setUserStyleSheetEnabled( 
749     /* [in] */ BOOL enabled)
750 {
751     setBoolValue(CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), enabled);
752     return S_OK;
753 }
754
755 HRESULT STDMETHODCALLTYPE WebPreferences::userStyleSheetLocation( 
756     /* [retval][out] */ BSTR* location)
757 {
758     *location = stringValueForKey(CFSTR(WebKitUserStyleSheetLocationPreferenceKey));
759     return (*location) ? S_OK : E_FAIL;
760 }
761
762 HRESULT STDMETHODCALLTYPE WebPreferences::setUserStyleSheetLocation( 
763     /* [in] */ BSTR location)
764 {
765     setStringValue(CFSTR(WebKitUserStyleSheetLocationPreferenceKey), location);
766     return S_OK;
767 }
768
769 HRESULT STDMETHODCALLTYPE WebPreferences::isJavaEnabled( 
770     /* [retval][out] */ BOOL* enabled)
771 {
772     *enabled = boolValueForKey(CFSTR(WebKitJavaEnabledPreferenceKey));
773     return S_OK;
774 }
775
776 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaEnabled( 
777     /* [in] */ BOOL enabled)
778 {
779     setBoolValue(CFSTR(WebKitJavaEnabledPreferenceKey), enabled);
780     return S_OK;
781 }
782
783 HRESULT STDMETHODCALLTYPE WebPreferences::isJavaScriptEnabled( 
784     /* [retval][out] */ BOOL* enabled)
785 {
786     *enabled = boolValueForKey(CFSTR(WebKitJavaScriptEnabledPreferenceKey));
787     return S_OK;
788 }
789
790 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptEnabled( 
791     /* [in] */ BOOL enabled)
792 {
793     setBoolValue(CFSTR(WebKitJavaScriptEnabledPreferenceKey), enabled);
794     return S_OK;
795 }
796
797 HRESULT STDMETHODCALLTYPE WebPreferences::isWebSecurityEnabled( 
798     /* [retval][out] */ BOOL* enabled)
799 {
800     *enabled = boolValueForKey(CFSTR(WebKitWebSecurityEnabledPreferenceKey));
801     return S_OK;
802 }
803
804 HRESULT STDMETHODCALLTYPE WebPreferences::setWebSecurityEnabled( 
805     /* [in] */ BOOL enabled)
806 {
807     setBoolValue(CFSTR(WebKitWebSecurityEnabledPreferenceKey), enabled);
808     return S_OK;
809 }
810
811 HRESULT STDMETHODCALLTYPE WebPreferences::allowUniversalAccessFromFileURLs(
812     /* [retval][out] */ BOOL* allowAccess)
813 {
814     *allowAccess = boolValueForKey(CFSTR(WebKitAllowUniversalAccessFromFileURLsPreferenceKey));
815     return S_OK;
816 }
817
818 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowUniversalAccessFromFileURLs(
819     /* [in] */ BOOL allowAccess)
820 {
821     setBoolValue(CFSTR(WebKitAllowUniversalAccessFromFileURLsPreferenceKey), allowAccess);
822     return S_OK;
823 }
824
825 HRESULT STDMETHODCALLTYPE WebPreferences::allowFileAccessFromFileURLs(
826     /* [retval][out] */ BOOL* allowAccess)
827 {
828     *allowAccess = boolValueForKey(CFSTR(WebKitAllowFileAccessFromFileURLsPreferenceKey));
829     return S_OK;
830 }
831
832 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowFileAccessFromFileURLs(
833     /* [in] */ BOOL allowAccess)
834 {
835     setBoolValue(CFSTR(WebKitAllowFileAccessFromFileURLsPreferenceKey), allowAccess);
836     return S_OK;
837 }
838
839 HRESULT STDMETHODCALLTYPE WebPreferences::javaScriptCanAccessClipboard(
840     /* [retval][out] */ BOOL* enabled)
841 {
842     *enabled = boolValueForKey(CFSTR(WebKitJavaScriptCanAccessClipboardPreferenceKey));
843     return S_OK;
844 }
845
846 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptCanAccessClipboard(
847     /* [in] */ BOOL enabled)
848 {
849     setBoolValue(CFSTR(WebKitJavaScriptCanAccessClipboardPreferenceKey), enabled);
850     return S_OK;
851 }
852
853 HRESULT STDMETHODCALLTYPE WebPreferences::isXSSAuditorEnabled(
854     /* [retval][out] */ BOOL* enabled)
855 {
856     *enabled = boolValueForKey(CFSTR(WebKitXSSAuditorEnabledPreferenceKey));
857     return S_OK;
858 }
859
860 HRESULT STDMETHODCALLTYPE WebPreferences::setXSSAuditorEnabled(
861     /* [in] */ BOOL enabled)
862 {
863     setBoolValue(CFSTR(WebKitXSSAuditorEnabledPreferenceKey), enabled);
864     return S_OK;
865 }
866
867 HRESULT STDMETHODCALLTYPE WebPreferences::isFrameFlatteningEnabled(
868     /* [retval][out] */ BOOL* enabled)
869 {
870     *enabled = boolValueForKey(CFSTR(WebKitFrameFlatteningEnabledPreferenceKey));
871     return S_OK;
872 }
873
874 HRESULT STDMETHODCALLTYPE WebPreferences::setFrameFlatteningEnabled(
875     /* [in] */ BOOL enabled)
876 {
877     setBoolValue(CFSTR(WebKitFrameFlatteningEnabledPreferenceKey), enabled);
878     return S_OK;
879 }
880
881 HRESULT STDMETHODCALLTYPE WebPreferences::javaScriptCanOpenWindowsAutomatically( 
882     /* [retval][out] */ BOOL* enabled)
883 {
884     *enabled = boolValueForKey(CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey));
885     return S_OK;
886 }
887
888 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptCanOpenWindowsAutomatically( 
889     /* [in] */ BOOL enabled)
890 {
891     setBoolValue(CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), enabled);
892     return S_OK;
893 }
894
895 HRESULT STDMETHODCALLTYPE WebPreferences::arePlugInsEnabled( 
896     /* [retval][out] */ BOOL* enabled)
897 {
898     *enabled = boolValueForKey(CFSTR(WebKitPluginsEnabledPreferenceKey));
899     return S_OK;
900 }
901
902 HRESULT STDMETHODCALLTYPE WebPreferences::setPlugInsEnabled( 
903     /* [in] */ BOOL enabled)
904 {
905     setBoolValue(CFSTR(WebKitPluginsEnabledPreferenceKey), enabled);
906     return S_OK;
907 }
908
909 HRESULT STDMETHODCALLTYPE WebPreferences::allowsAnimatedImages( 
910     /* [retval][out] */ BOOL* enabled)
911 {
912     *enabled = boolValueForKey(CFSTR(WebKitAllowAnimatedImagesPreferenceKey));
913     return S_OK;
914 }
915
916 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowsAnimatedImages( 
917     /* [in] */ BOOL enabled)
918 {
919     setBoolValue(CFSTR(WebKitAllowAnimatedImagesPreferenceKey), enabled);
920     return S_OK;
921 }
922
923 HRESULT STDMETHODCALLTYPE WebPreferences::allowAnimatedImageLooping( 
924     /* [retval][out] */ BOOL* enabled)
925 {
926     *enabled = boolValueForKey(CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey));
927     return S_OK;
928 }
929
930 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowAnimatedImageLooping( 
931     /* [in] */ BOOL enabled)
932 {
933     setBoolValue(CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), enabled);
934     return S_OK;
935 }
936
937 HRESULT STDMETHODCALLTYPE WebPreferences::setLoadsImagesAutomatically( 
938     /* [in] */ BOOL enabled)
939 {
940     setBoolValue(CFSTR(WebKitDisplayImagesKey), enabled);
941     return S_OK;
942 }
943
944 HRESULT STDMETHODCALLTYPE WebPreferences::loadsImagesAutomatically( 
945     /* [retval][out] */ BOOL* enabled)
946 {
947     *enabled = boolValueForKey(CFSTR(WebKitDisplayImagesKey));
948     return S_OK;
949 }
950
951 HRESULT STDMETHODCALLTYPE WebPreferences::setLoadsSiteIconsIgnoringImageLoadingPreference(
952     /* [in] */ BOOL enabled)
953 {
954     setBoolValue(CFSTR(WebKitLoadSiteIconsKey), enabled);
955     return S_OK;
956 }
957
958 HRESULT STDMETHODCALLTYPE WebPreferences::loadsSiteIconsIgnoringImageLoadingPreference(
959     /* [retval][out] */ BOOL* enabled)
960 {
961     *enabled = boolValueForKey(CFSTR(WebKitLoadSiteIconsKey));
962     return S_OK;
963 }
964
965 HRESULT STDMETHODCALLTYPE WebPreferences::setHixie76WebSocketProtocolEnabled(
966     /* [in] */ BOOL enabled)
967 {
968     setBoolValue(CFSTR(WebKitHixie76WebSocketProtocolEnabledPreferenceKey), enabled);
969     return S_OK;
970 }
971
972 HRESULT STDMETHODCALLTYPE WebPreferences::hixie76WebSocketProtocolEnabled(
973     /* [retval][out] */ BOOL* enabled)
974 {
975     *enabled = boolValueForKey(CFSTR(WebKitHixie76WebSocketProtocolEnabledPreferenceKey));
976     return S_OK;
977 }
978
979 HRESULT STDMETHODCALLTYPE WebPreferences::setMediaPlaybackRequiresUserGesture(
980     /* [in] */ BOOL enabled)
981 {
982     setBoolValue(CFSTR(WebKitMediaPlaybackRequiresUserGesturePreferenceKey), enabled);
983     return S_OK;
984 }
985
986 HRESULT STDMETHODCALLTYPE WebPreferences::mediaPlaybackRequiresUserGesture(
987     /* [retval][out] */ BOOL* enabled)
988 {
989     *enabled = boolValueForKey(CFSTR(WebKitMediaPlaybackRequiresUserGesturePreferenceKey));
990     return S_OK;
991 }
992
993 HRESULT STDMETHODCALLTYPE WebPreferences::setMediaPlaybackAllowsInline(
994     /* [in] */ BOOL enabled)
995 {
996     setBoolValue(CFSTR(WebKitMediaPlaybackAllowsInlinePreferenceKey), enabled);
997     return S_OK;
998 }
999
1000 HRESULT STDMETHODCALLTYPE WebPreferences::mediaPlaybackAllowsInline(
1001     /* [retval][out] */ BOOL* enabled)
1002 {
1003     *enabled = boolValueForKey(CFSTR(WebKitMediaPlaybackAllowsInlinePreferenceKey));
1004     return S_OK;
1005 }
1006
1007 HRESULT STDMETHODCALLTYPE WebPreferences::setAutosaves( 
1008     /* [in] */ BOOL enabled)
1009 {
1010     m_autoSaves = !!enabled;
1011     return S_OK;
1012 }
1013
1014 HRESULT STDMETHODCALLTYPE WebPreferences::autosaves( 
1015     /* [retval][out] */ BOOL* enabled)
1016 {
1017     *enabled = m_autoSaves ? TRUE : FALSE;
1018     return S_OK;
1019 }
1020
1021 HRESULT STDMETHODCALLTYPE WebPreferences::setShouldPrintBackgrounds( 
1022     /* [in] */ BOOL enabled)
1023 {
1024     setBoolValue(CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), enabled);
1025     return S_OK;
1026 }
1027
1028 HRESULT STDMETHODCALLTYPE WebPreferences::shouldPrintBackgrounds( 
1029     /* [retval][out] */ BOOL* enabled)
1030 {
1031     *enabled = boolValueForKey(CFSTR(WebKitShouldPrintBackgroundsPreferenceKey));
1032     return S_OK;
1033 }
1034
1035 HRESULT STDMETHODCALLTYPE WebPreferences::setPrivateBrowsingEnabled( 
1036     /* [in] */ BOOL enabled)
1037 {
1038     setBoolValue(CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), enabled);
1039     return S_OK;
1040 }
1041
1042 HRESULT STDMETHODCALLTYPE WebPreferences::privateBrowsingEnabled( 
1043     /* [retval][out] */ BOOL* enabled)
1044 {
1045     *enabled = boolValueForKey(CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey));
1046     return S_OK;
1047 }
1048
1049 HRESULT STDMETHODCALLTYPE WebPreferences::setTabsToLinks( 
1050     /* [in] */ BOOL enabled)
1051 {
1052     setBoolValue(CFSTR(WebKitTabToLinksPreferenceKey), enabled);
1053     return S_OK;
1054 }
1055
1056 HRESULT STDMETHODCALLTYPE WebPreferences::tabsToLinks( 
1057     /* [retval][out] */ BOOL* enabled)
1058 {
1059     *enabled = boolValueForKey(CFSTR(WebKitTabToLinksPreferenceKey));
1060     return S_OK;
1061 }
1062
1063 HRESULT STDMETHODCALLTYPE WebPreferences::setUsesPageCache( 
1064         /* [in] */ BOOL usesPageCache)
1065 {
1066     setBoolValue(CFSTR(WebKitUsesPageCachePreferenceKey), usesPageCache);
1067     return S_OK;
1068 }
1069
1070 HRESULT STDMETHODCALLTYPE WebPreferences::usesPageCache( 
1071     /* [retval][out] */ BOOL* usesPageCache)
1072 {
1073     *usesPageCache = boolValueForKey(CFSTR(WebKitUsesPageCachePreferenceKey));
1074     return S_OK;
1075 }
1076
1077 HRESULT STDMETHODCALLTYPE WebPreferences::textAreasAreResizable( 
1078     /* [retval][out] */ BOOL* enabled)
1079 {
1080     *enabled = boolValueForKey(CFSTR(WebKitTextAreasAreResizablePreferenceKey));
1081     return S_OK;
1082 }
1083
1084 HRESULT STDMETHODCALLTYPE WebPreferences::setTextAreasAreResizable( 
1085     /* [in] */ BOOL enabled)
1086 {
1087     setBoolValue(CFSTR(WebKitTextAreasAreResizablePreferenceKey), enabled);
1088     return S_OK;
1089 }
1090
1091 HRESULT WebPreferences::historyItemLimit(int* limit)
1092 {
1093     *limit = integerValueForKey(CFSTR(WebKitHistoryItemLimitKey));
1094     return S_OK;
1095 }
1096
1097 HRESULT WebPreferences::setHistoryItemLimit(int limit)
1098 {
1099     setIntegerValue(CFSTR(WebKitHistoryItemLimitKey), limit);
1100     return S_OK;
1101 }
1102
1103 HRESULT WebPreferences::historyAgeInDaysLimit(int* limit)
1104 {
1105     *limit = integerValueForKey(CFSTR(WebKitHistoryAgeInDaysLimitKey));
1106     return S_OK;
1107 }
1108
1109 HRESULT WebPreferences::setHistoryAgeInDaysLimit(int limit)
1110 {
1111     setIntegerValue(CFSTR(WebKitHistoryAgeInDaysLimitKey), limit);
1112     return S_OK;
1113 }
1114
1115 HRESULT WebPreferences::unused1()
1116 {
1117     ASSERT_NOT_REACHED();
1118     return E_FAIL;
1119 }
1120
1121 HRESULT WebPreferences::unused2()
1122 {
1123     ASSERT_NOT_REACHED();
1124     return E_FAIL;
1125 }
1126
1127 HRESULT WebPreferences::iconDatabaseLocation(
1128     /* [out] */ BSTR* location)
1129 {
1130     *location = stringValueForKey(CFSTR(WebKitIconDatabaseLocationKey));
1131     return (*location) ? S_OK : E_FAIL;
1132 }
1133
1134 HRESULT WebPreferences::setIconDatabaseLocation(
1135     /* [in] */ BSTR location)
1136 {
1137     setStringValue(CFSTR(WebKitIconDatabaseLocationKey), location);
1138     return S_OK;
1139 }
1140
1141 HRESULT WebPreferences::iconDatabaseEnabled(BOOL* enabled)//location)
1142 {
1143     *enabled = boolValueForKey(CFSTR(WebKitIconDatabaseEnabledPreferenceKey));
1144     return S_OK;
1145 }
1146
1147 HRESULT WebPreferences::setIconDatabaseEnabled(BOOL enabled )//location)
1148 {
1149     setBoolValue(CFSTR(WebKitIconDatabaseEnabledPreferenceKey), enabled);
1150     return S_OK;
1151 }
1152
1153 HRESULT STDMETHODCALLTYPE WebPreferences::fontSmoothing( 
1154     /* [retval][out] */ FontSmoothingType* smoothingType)
1155 {
1156     *smoothingType = (FontSmoothingType) integerValueForKey(CFSTR(WebKitFontSmoothingTypePreferenceKey));
1157     return S_OK;
1158 }
1159
1160 HRESULT STDMETHODCALLTYPE WebPreferences::setFontSmoothing( 
1161     /* [in] */ FontSmoothingType smoothingType)
1162 {
1163     setIntegerValue(CFSTR(WebKitFontSmoothingTypePreferenceKey), smoothingType);
1164     if (smoothingType == FontSmoothingTypeWindows)
1165         smoothingType = FontSmoothingTypeMedium;
1166 #if USE(CG)
1167     wkSetFontSmoothingLevel((int)smoothingType);
1168 #endif
1169     return S_OK;
1170 }
1171
1172 HRESULT STDMETHODCALLTYPE WebPreferences::fontSmoothingContrast( 
1173     /* [retval][out] */ float* contrast)
1174 {
1175     *contrast = floatValueForKey(CFSTR(WebKitFontSmoothingContrastPreferenceKey));
1176     return S_OK;
1177 }
1178
1179 HRESULT STDMETHODCALLTYPE WebPreferences::setFontSmoothingContrast( 
1180     /* [in] */ float contrast)
1181 {
1182     setFloatValue(CFSTR(WebKitFontSmoothingContrastPreferenceKey), contrast);
1183 #if USE(CG)
1184     wkSetFontSmoothingContrast(contrast);
1185 #endif
1186     return S_OK;
1187 }
1188
1189 HRESULT STDMETHODCALLTYPE WebPreferences::editableLinkBehavior(
1190     /* [out, retval] */ WebKitEditableLinkBehavior* editableLinkBehavior)
1191 {
1192     WebKitEditableLinkBehavior value = (WebKitEditableLinkBehavior) integerValueForKey(CFSTR(WebKitEditableLinkBehaviorPreferenceKey));
1193     switch (value) {
1194         case WebKitEditableLinkDefaultBehavior:
1195         case WebKitEditableLinkAlwaysLive:
1196         case WebKitEditableLinkOnlyLiveWithShiftKey:
1197         case WebKitEditableLinkLiveWhenNotFocused:
1198         case WebKitEditableLinkNeverLive:
1199             *editableLinkBehavior = value;
1200             break;
1201         default: // ensure that a valid result is returned
1202             *editableLinkBehavior = WebKitEditableLinkDefaultBehavior;
1203             break;
1204     }
1205     return S_OK;
1206 }
1207
1208 HRESULT STDMETHODCALLTYPE WebPreferences::setEditableLinkBehavior(
1209     /* [in] */ WebKitEditableLinkBehavior behavior)
1210 {
1211     setIntegerValue(CFSTR(WebKitEditableLinkBehaviorPreferenceKey), behavior);
1212     return S_OK;
1213 }
1214
1215 HRESULT STDMETHODCALLTYPE WebPreferences::editingBehavior(
1216     /* [out, retval] */ WebKitEditingBehavior* editingBehavior)
1217 {
1218     *editingBehavior = (WebKitEditingBehavior) integerValueForKey(CFSTR(WebKitEditingBehaviorPreferenceKey));
1219     return S_OK;
1220 }
1221
1222 HRESULT STDMETHODCALLTYPE WebPreferences::setEditingBehavior(
1223     /* [in] */ WebKitEditingBehavior behavior)
1224 {
1225     setIntegerValue(CFSTR(WebKitEditingBehaviorPreferenceKey), behavior);
1226     return S_OK;
1227 }
1228
1229 HRESULT STDMETHODCALLTYPE WebPreferences::hyperlinkAuditingEnabled(
1230     /* [in] */ BOOL* enabled)
1231 {
1232     *enabled = boolValueForKey(CFSTR(WebKitHyperlinkAuditingEnabledPreferenceKey));
1233     return S_OK;
1234 }
1235
1236 HRESULT STDMETHODCALLTYPE WebPreferences::setHyperlinkAuditingEnabled(
1237     /* [retval][out] */ BOOL enabled)
1238 {
1239     setBoolValue(CFSTR(WebKitHyperlinkAuditingEnabledPreferenceKey), enabled);
1240     return S_OK;
1241 }
1242
1243 HRESULT STDMETHODCALLTYPE WebPreferences::cookieStorageAcceptPolicy( 
1244         /* [retval][out] */ WebKitCookieStorageAcceptPolicy *acceptPolicy )
1245 {
1246     if (!acceptPolicy)
1247         return E_POINTER;
1248
1249     *acceptPolicy = (WebKitCookieStorageAcceptPolicy)integerValueForKey(CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey));
1250     return S_OK;
1251 }
1252
1253 HRESULT STDMETHODCALLTYPE WebPreferences::setCookieStorageAcceptPolicy( 
1254         /* [in] */ WebKitCookieStorageAcceptPolicy acceptPolicy)
1255 {
1256     setIntegerValue(CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), acceptPolicy);
1257     return S_OK;
1258 }
1259
1260
1261 HRESULT WebPreferences::continuousSpellCheckingEnabled(BOOL* enabled)
1262 {
1263     *enabled = boolValueForKey(CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey));
1264     return S_OK;
1265 }
1266
1267 HRESULT WebPreferences::setContinuousSpellCheckingEnabled(BOOL enabled)
1268 {
1269     setBoolValue(CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), enabled);
1270     return S_OK;
1271 }
1272
1273 HRESULT WebPreferences::grammarCheckingEnabled(BOOL* enabled)
1274 {
1275     *enabled = boolValueForKey(CFSTR(WebGrammarCheckingEnabledPreferenceKey));
1276     return S_OK;
1277 }
1278
1279 HRESULT WebPreferences::setGrammarCheckingEnabled(BOOL enabled)
1280 {
1281     setBoolValue(CFSTR(WebGrammarCheckingEnabledPreferenceKey), enabled);
1282     return S_OK;
1283 }
1284
1285 HRESULT WebPreferences::allowContinuousSpellChecking(BOOL* enabled)
1286 {
1287     *enabled = boolValueForKey(CFSTR(AllowContinuousSpellCheckingPreferenceKey));
1288     return S_OK;
1289 }
1290
1291 HRESULT WebPreferences::setAllowContinuousSpellChecking(BOOL enabled)
1292 {
1293     setBoolValue(CFSTR(AllowContinuousSpellCheckingPreferenceKey), enabled);
1294     return S_OK;
1295 }
1296
1297 HRESULT WebPreferences::isDOMPasteAllowed(BOOL* enabled)
1298 {
1299     *enabled = boolValueForKey(CFSTR(WebKitDOMPasteAllowedPreferenceKey));
1300     return S_OK;
1301 }
1302     
1303 HRESULT WebPreferences::setDOMPasteAllowed(BOOL enabled)
1304 {
1305     setBoolValue(CFSTR(WebKitDOMPasteAllowedPreferenceKey), enabled);
1306     return S_OK;
1307 }
1308
1309 HRESULT WebPreferences::cacheModel(WebCacheModel* cacheModel)
1310 {
1311     if (!cacheModel)
1312         return E_POINTER;
1313
1314     *cacheModel = (WebCacheModel)integerValueForKey(CFSTR(WebKitCacheModelPreferenceKey));
1315     return S_OK;
1316 }
1317
1318 HRESULT WebPreferences::setCacheModel(WebCacheModel cacheModel)
1319 {
1320     setIntegerValue(CFSTR(WebKitCacheModelPreferenceKey), cacheModel);
1321     return S_OK;
1322 }
1323
1324 HRESULT WebPreferences::unused3()
1325 {
1326     ASSERT_NOT_REACHED();
1327     return E_FAIL;
1328 }
1329
1330 HRESULT WebPreferences::unused4()
1331 {
1332     ASSERT_NOT_REACHED();
1333     return E_FAIL;
1334 }
1335
1336 HRESULT WebPreferences::shouldPaintNativeControls(BOOL* shouldPaint)
1337 {
1338     *shouldPaint = boolValueForKey(CFSTR(WebKitPaintNativeControlsPreferenceKey));
1339     return S_OK;
1340 }
1341
1342 HRESULT WebPreferences::setShouldPaintNativeControls(BOOL shouldPaint)
1343 {
1344     setBoolValue(CFSTR(WebKitPaintNativeControlsPreferenceKey), shouldPaint);
1345     return S_OK;
1346 }
1347
1348 HRESULT WebPreferences::setDeveloperExtrasEnabled(BOOL enabled)
1349 {
1350     setBoolValue(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey), enabled);
1351     return S_OK;
1352 }
1353
1354 HRESULT WebPreferences::developerExtrasEnabled(BOOL* enabled)
1355 {
1356     if (!enabled)
1357         return E_POINTER;
1358
1359     *enabled = boolValueForKey(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey));
1360     return S_OK;
1361 }
1362
1363 bool WebPreferences::developerExtrasDisabledByOverride()
1364 {
1365     return !!boolValueForKey(CFSTR(DisableWebKitDeveloperExtrasPreferenceKey));
1366 }
1367
1368 HRESULT WebPreferences::setAutomaticallyDetectsCacheModel(BOOL automaticallyDetectsCacheModel)
1369 {
1370     m_automaticallyDetectsCacheModel = !!automaticallyDetectsCacheModel;
1371     return S_OK;
1372 }
1373
1374 HRESULT WebPreferences::automaticallyDetectsCacheModel(BOOL* automaticallyDetectsCacheModel)
1375 {
1376     if (!automaticallyDetectsCacheModel)
1377         return E_POINTER;
1378
1379     *automaticallyDetectsCacheModel = m_automaticallyDetectsCacheModel;
1380     return S_OK;
1381 }
1382
1383 HRESULT STDMETHODCALLTYPE WebPreferences::setAuthorAndUserStylesEnabled(BOOL enabled)
1384 {
1385     setBoolValue(CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey), enabled);
1386     return S_OK;
1387 }
1388
1389 HRESULT STDMETHODCALLTYPE WebPreferences::authorAndUserStylesEnabled(BOOL* enabled)
1390 {
1391     if (!enabled)
1392         return E_POINTER;
1393
1394     *enabled = boolValueForKey(CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey));
1395     return S_OK;
1396 }
1397
1398 HRESULT WebPreferences::inApplicationChromeMode(BOOL* enabled)
1399 {
1400     *enabled = boolValueForKey(CFSTR(WebKitApplicationChromeModePreferenceKey));
1401     return S_OK;
1402 }
1403     
1404 HRESULT WebPreferences::setApplicationChromeMode(BOOL enabled)
1405 {
1406     setBoolValue(CFSTR(WebKitApplicationChromeModePreferenceKey), enabled);
1407     return S_OK;
1408 }
1409
1410 HRESULT STDMETHODCALLTYPE WebPreferences::setOfflineWebApplicationCacheEnabled(BOOL enabled)
1411 {
1412     setBoolValue(CFSTR(WebKitOfflineWebApplicationCacheEnabledPreferenceKey), enabled);
1413     return S_OK;
1414 }
1415
1416 HRESULT STDMETHODCALLTYPE WebPreferences::offlineWebApplicationCacheEnabled(BOOL* enabled)
1417 {
1418     *enabled = boolValueForKey(CFSTR(WebKitOfflineWebApplicationCacheEnabledPreferenceKey));
1419     return S_OK;
1420 }
1421
1422 HRESULT STDMETHODCALLTYPE WebPreferences::setDatabasesEnabled(BOOL enabled)
1423 {
1424     setBoolValue(CFSTR(WebKitDatabasesEnabledPreferenceKey), enabled);
1425     return S_OK;
1426 }
1427
1428 HRESULT STDMETHODCALLTYPE WebPreferences::databasesEnabled(BOOL* enabled)
1429 {
1430     *enabled = boolValueForKey(CFSTR(WebKitDatabasesEnabledPreferenceKey));
1431     return S_OK;
1432 }
1433
1434 HRESULT STDMETHODCALLTYPE WebPreferences::setLocalStorageEnabled(BOOL enabled)
1435 {
1436     setBoolValue(CFSTR(WebKitLocalStorageEnabledPreferenceKey), enabled);
1437     return S_OK;
1438 }
1439
1440 HRESULT STDMETHODCALLTYPE WebPreferences::localStorageEnabled(BOOL* enabled)
1441 {
1442     *enabled = boolValueForKey(CFSTR(WebKitLocalStorageEnabledPreferenceKey));
1443     return S_OK;
1444 }
1445
1446 HRESULT STDMETHODCALLTYPE WebPreferences::localStorageDatabasePath(BSTR* location)
1447 {
1448     *location = stringValueForKey(CFSTR(WebKitLocalStorageDatabasePathPreferenceKey));
1449     return (*location) ? S_OK : E_FAIL;
1450 }
1451
1452 HRESULT STDMETHODCALLTYPE WebPreferences::setLocalStorageDatabasePath(BSTR location)
1453 {
1454     setStringValue(CFSTR(WebKitLocalStorageDatabasePathPreferenceKey), location);
1455     return S_OK;
1456 }
1457
1458 HRESULT STDMETHODCALLTYPE WebPreferences::setExperimentalNotificationsEnabled(BOOL enabled)
1459 {
1460     setBoolValue(CFSTR(WebKitExperimentalNotificationsEnabledPreferenceKey), enabled);
1461     return S_OK;
1462 }
1463
1464 HRESULT STDMETHODCALLTYPE WebPreferences::experimentalNotificationsEnabled(BOOL* enabled)
1465 {
1466     *enabled = boolValueForKey(CFSTR(WebKitExperimentalNotificationsEnabledPreferenceKey));
1467     return S_OK;
1468 }
1469
1470 HRESULT WebPreferences::setZoomsTextOnly(BOOL zoomsTextOnly)
1471 {
1472     setBoolValue(CFSTR(WebKitZoomsTextOnlyPreferenceKey), zoomsTextOnly);
1473     return S_OK;
1474 }
1475
1476 HRESULT WebPreferences::zoomsTextOnly(BOOL* zoomsTextOnly)
1477 {
1478     *zoomsTextOnly = boolValueForKey(CFSTR(WebKitZoomsTextOnlyPreferenceKey));
1479     return S_OK;
1480 }
1481
1482 HRESULT STDMETHODCALLTYPE WebPreferences::setShouldUseHighResolutionTimers(BOOL useHighResolutionTimers)
1483 {
1484     setBoolValue(CFSTR(WebKitUseHighResolutionTimersPreferenceKey), useHighResolutionTimers);
1485     return S_OK;
1486 }
1487
1488 HRESULT STDMETHODCALLTYPE WebPreferences::shouldUseHighResolutionTimers(BOOL* useHighResolutionTimers)
1489 {
1490     *useHighResolutionTimers = boolValueForKey(CFSTR(WebKitUseHighResolutionTimersPreferenceKey));
1491     return S_OK;
1492 }
1493
1494 HRESULT WebPreferences::setPreferenceForTest(BSTR key, BSTR value)
1495 {
1496     if (!SysStringLen(key) || !SysStringLen(value))
1497         return E_FAIL;
1498     RetainPtr<CFStringRef> keyString(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(key), SysStringLen(key)));
1499     RetainPtr<CFStringRef> valueString(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(value), SysStringLen(value)));
1500     setValueForKey(keyString.get(), valueString.get());
1501     postPreferencesChangesNotification();
1502     return S_OK;
1503 }
1504
1505 HRESULT WebPreferences::setAcceleratedCompositingEnabled(BOOL enabled)
1506 {
1507     setBoolValue(CFSTR(WebKitAcceleratedCompositingEnabledPreferenceKey), enabled);
1508     return S_OK;
1509 }
1510
1511 HRESULT WebPreferences::acceleratedCompositingEnabled(BOOL* enabled)
1512 {
1513 #if USE(ACCELERATED_COMPOSITING)
1514     *enabled = CACFLayerTreeHost::acceleratedCompositingAvailable() && boolValueForKey(CFSTR(WebKitAcceleratedCompositingEnabledPreferenceKey));
1515 #else
1516     *enabled = FALSE;
1517 #endif
1518     return S_OK;
1519 }
1520
1521 HRESULT WebPreferences::showDebugBorders(BOOL* enabled)
1522 {
1523     *enabled = boolValueForKey(CFSTR(WebKitShowDebugBordersPreferenceKey));
1524     return S_OK;
1525 }
1526
1527 HRESULT WebPreferences::setShowDebugBorders(BOOL enabled)
1528 {
1529     setBoolValue(CFSTR(WebKitShowDebugBordersPreferenceKey), enabled);
1530     return S_OK;
1531 }
1532
1533 HRESULT WebPreferences::showRepaintCounter(BOOL* enabled)
1534 {
1535     *enabled = boolValueForKey(CFSTR(WebKitShowRepaintCounterPreferenceKey));
1536     return S_OK;
1537 }
1538
1539 HRESULT WebPreferences::setShowRepaintCounter(BOOL enabled)
1540 {
1541     setBoolValue(CFSTR(WebKitShowRepaintCounterPreferenceKey), enabled);
1542     return S_OK;
1543 }
1544
1545 HRESULT WebPreferences::setCustomDragCursorsEnabled(BOOL enabled)
1546 {
1547     setBoolValue(CFSTR(WebKitCustomDragCursorsEnabledPreferenceKey), enabled);
1548     return S_OK;
1549 }
1550
1551 HRESULT WebPreferences::customDragCursorsEnabled(BOOL* enabled)
1552 {
1553     *enabled = boolValueForKey(CFSTR(WebKitCustomDragCursorsEnabledPreferenceKey));
1554     return S_OK;
1555 }
1556
1557 HRESULT WebPreferences::setDNSPrefetchingEnabled(BOOL enabled)
1558 {
1559     setBoolValue(CFSTR(WebKitDNSPrefetchingEnabledPreferenceKey), enabled);
1560     return S_OK;
1561 }
1562
1563 HRESULT WebPreferences::isDNSPrefetchingEnabled(BOOL* enabled)
1564 {
1565     *enabled = boolValueForKey(CFSTR(WebKitDNSPrefetchingEnabledPreferenceKey));
1566     return S_OK;
1567 }
1568
1569 HRESULT WebPreferences::memoryInfoEnabled(BOOL* enabled)
1570 {
1571     *enabled = boolValueForKey(CFSTR(WebKitMemoryInfoEnabledPreferenceKey));
1572     return S_OK;
1573 }
1574
1575 HRESULT WebPreferences::setMemoryInfoEnabled(BOOL enabled)
1576 {
1577     setBoolValue(CFSTR(WebKitMemoryInfoEnabledPreferenceKey), enabled);
1578     return S_OK;
1579 }
1580
1581 HRESULT WebPreferences::isFullScreenEnabled(BOOL* enabled)
1582 {
1583 #if ENABLE(FULLSCREEN_API)
1584     if (!enabled)
1585         return E_POINTER;
1586
1587     *enabled = boolValueForKey(CFSTR(WebKitFullScreenEnabledPreferenceKey));
1588     return S_OK;
1589 #else
1590     return E_NOTIMPL;
1591 #endif
1592 }
1593
1594 HRESULT WebPreferences::setFullScreenEnabled(BOOL enabled)
1595 {
1596 #if ENABLE(FULLSCREEN_API)
1597     setBoolValue(CFSTR(WebKitFullScreenEnabledPreferenceKey), enabled);
1598     return S_OK;
1599 #else
1600     return E_NOTIMPL;
1601 #endif
1602 }
1603
1604 HRESULT WebPreferences::avFoundationEnabled(BOOL* enabled)
1605 {
1606 #if USE(AVFOUNDATION)
1607     if (!enabled)
1608         return E_POINTER;
1609
1610     *enabled = boolValueForKey(CFSTR(WebKitAVFoundationEnabledPreferenceKey));
1611     return S_OK;
1612 #else
1613     return E_NOTIMPL;
1614 #endif
1615 }
1616
1617 HRESULT WebPreferences::setAVFoundationEnabled(BOOL enabled)
1618 {
1619 #if USE(AVFOUNDATION)
1620     setBoolValue(CFSTR(WebKitAVFoundationEnabledPreferenceKey), enabled);
1621     return S_OK;
1622 #else
1623     return E_NOTIMPL;
1624 #endif
1625 }
1626
1627 HRESULT WebPreferences::showsToolTipOverTruncatedText(BOOL* showsToolTip)
1628 {
1629     if (!showsToolTip)
1630         return E_POINTER;
1631
1632     *showsToolTip = boolValueForKey(CFSTR(WebKitShowsToolTipOverTruncatedTextPreferenceKey));
1633     return S_OK;
1634 }
1635
1636 HRESULT WebPreferences::setShowsToolTipOverTruncatedText(BOOL showsToolTip)
1637 {
1638     setBoolValue(CFSTR(WebKitShowsToolTipOverTruncatedTextPreferenceKey), showsToolTip);
1639     return S_OK;
1640 }
1641
1642 HRESULT WebPreferences::shouldInvertColors(BOOL* shouldInvertColors)
1643 {
1644     if (!shouldInvertColors)
1645         return E_POINTER;
1646
1647     *shouldInvertColors = boolValueForKey(CFSTR(WebKitShouldInvertColorsPreferenceKey));
1648     return S_OK;
1649 }
1650
1651 HRESULT WebPreferences::setShouldInvertColors(BOOL shouldInvertColors)
1652 {
1653     setBoolValue(CFSTR(WebKitShouldInvertColorsPreferenceKey), shouldInvertColors);
1654     return S_OK;
1655 }
1656
1657 void WebPreferences::willAddToWebView()
1658 {
1659     ++m_numWebViews;
1660 }
1661
1662 void WebPreferences::didRemoveFromWebView()
1663 {
1664     ASSERT(m_numWebViews);
1665     if (--m_numWebViews == 0) {
1666         IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
1667         nc->postNotificationName(webPreferencesRemovedNotification(), static_cast<IWebPreferences*>(this), 0);
1668     }
1669 }
1670
1671 HRESULT WebPreferences::shouldDisplaySubtitles(BOOL* enabled)
1672 {
1673 #if ENABLE(VIDEO_TRACK)
1674     if (!enabled)
1675         return E_POINTER;
1676
1677     *enabled = boolValueForKey(CFSTR(WebKitShouldDisplaySubtitlesPreferenceKey));
1678     return S_OK;
1679 #else
1680     return E_NOTIMPL;
1681 #endif
1682 }
1683
1684 HRESULT WebPreferences::setShouldDisplaySubtitles(BOOL enabled)
1685 {
1686 #if ENABLE(VIDEO_TRACK)
1687     setBoolValue(CFSTR(WebKitShouldDisplaySubtitlesPreferenceKey), enabled);
1688     return S_OK;
1689 #else
1690     return E_NOTIMPL;
1691 #endif
1692 }
1693
1694 HRESULT WebPreferences::shouldDisplayCaptions(BOOL* enabled)
1695 {
1696 #if ENABLE(VIDEO_TRACK)
1697     if (!enabled)
1698         return E_POINTER;
1699
1700     *enabled = boolValueForKey(CFSTR(WebKitShouldDisplayCaptionsPreferenceKey));
1701     return S_OK;
1702 #else
1703     return E_NOTIMPL;
1704 #endif
1705 }
1706
1707 HRESULT WebPreferences::setShouldDisplayCaptions(BOOL enabled)
1708 {
1709 #if ENABLE(VIDEO_TRACK)
1710     setBoolValue(CFSTR(WebKitShouldDisplayCaptionsPreferenceKey), enabled);
1711     return S_OK;
1712 #else
1713     return E_NOTIMPL;
1714 #endif
1715 }
1716
1717 HRESULT WebPreferences::shouldDisplayTextDescriptions(BOOL* enabled)
1718 {
1719 #if ENABLE(VIDEO_TRACK)
1720     if (!enabled)
1721         return E_POINTER;
1722
1723     *enabled = boolValueForKey(CFSTR(WebKitShouldDisplayTextDescriptionsPreferenceKey));
1724     return S_OK;
1725 #else
1726     return E_NOTIMPL;
1727 #endif
1728 }
1729
1730 HRESULT WebPreferences::setShouldDisplayTextDescriptions(BOOL enabled)
1731 {
1732 #if ENABLE(VIDEO_TRACK)
1733     setBoolValue(CFSTR(WebKitShouldDisplayTextDescriptionsPreferenceKey), enabled);
1734     return S_OK;
1735 #else
1736     return E_NOTIMPL;
1737 #endif
1738 }