Refactor value <-> CFNumber conversions into some helper functions
[WebKit-https.git] / WebKit / win / WebPreferences.cpp
1 /*
2  * Copyright (C) 2006, 2007 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 #include "WebKit.h"
31
32 #include "WebNotificationCenter.h"
33 #include "WebPreferenceKeysPrivate.h"
34
35 #pragma warning( push, 0 )
36 #include <WebCore/CString.h>
37 #include <WebCore/FileSystem.h>
38 #include <WebCore/Font.h>
39 #include <WebCore/PlatformString.h>
40 #include <WebCore/StringHash.h>
41 #include "WebLocalizableStrings.h"
42 #pragma warning( pop )
43
44 #include <CoreFoundation/CoreFoundation.h>
45 #include <CoreGraphics/CoreGraphics.h>
46 #include <shlobj.h>
47 #include <shfolder.h>
48 #include <tchar.h>
49 #include <WebKitSystemInterface/WebKitSystemInterface.h>
50 #include <wtf/HashMap.h>
51 #include <wtf/OwnPtr.h>
52 #include <wtf/Vector.h>
53
54 using namespace WebCore;
55
56 static const String& preferencesPath()
57 {
58     static String path = pathByAppendingComponent(roamingUserSpecificStorageDirectory(), "WebKitPreferences.plist");
59     return path;
60 }
61
62 template<typename NumberType> struct CFNumberTraits { static const unsigned Type; };
63 template<> struct CFNumberTraits<int> { static const unsigned Type = kCFNumberSInt32Type; };
64 template<> struct CFNumberTraits<LONGLONG> { static const unsigned Type = kCFNumberLongLongType; };
65 template<> struct CFNumberTraits<float> { static const unsigned Type = kCFNumberFloat32Type; };
66
67 template<typename NumberType>
68 static NumberType numberValueForPreferencesValue(CFPropertyListRef value)
69 {
70     if (!value)
71         return 0;
72
73     CFTypeID cfType = CFGetTypeID(value);
74     if (cfType == CFStringGetTypeID())
75         return static_cast<NumberType>(CFStringGetIntValue(static_cast<CFStringRef>(value)));
76     else if (cfType == CFBooleanGetTypeID()) {
77         Boolean boolVal = CFBooleanGetValue(static_cast<CFBooleanRef>(value));
78         return boolVal ? 1 : 0;
79     } else if (cfType == CFNumberGetTypeID()) {
80         NumberType val = 0;
81         CFNumberGetValue(static_cast<CFNumberRef>(value), CFNumberTraits<NumberType>::Type, &val);
82         return val;
83     }
84
85     return 0;
86 }
87
88 template<typename NumberType>
89 static RetainPtr<CFNumberRef> cfNumber(NumberType value)
90 {
91     return RetainPtr<CFNumberRef>(AdoptCF, CFNumberCreate(0, CFNumberTraits<NumberType>::Type, &value));
92 }
93
94 static bool booleanValueForPreferencesValue(CFPropertyListRef value)
95 {
96     return numberValueForPreferencesValue<int>(value);
97 }
98
99 // WebPreferences ----------------------------------------------------------------
100
101 static CFDictionaryRef defaultSettings;
102
103 static HashMap<WebCore::String, WebPreferences*> webPreferencesInstances;
104
105 WebPreferences* WebPreferences::sharedStandardPreferences()
106 {
107     static WebPreferences* standardPreferences;
108     if (!standardPreferences) {
109         standardPreferences = WebPreferences::createInstance();
110         standardPreferences->load();
111         standardPreferences->setAutosaves(TRUE);
112     }
113
114     return standardPreferences;
115 }
116
117 WebPreferences::WebPreferences()
118     : m_refCount(0)
119     , m_autoSaves(0)
120     , m_automaticallyDetectsCacheModel(true)
121     , m_numWebViews(0)
122 {
123     gClassCount++;
124 }
125
126 WebPreferences::~WebPreferences()
127 {
128     gClassCount--;
129 }
130
131 WebPreferences* WebPreferences::createInstance()
132 {
133     WebPreferences* instance = new WebPreferences();
134     instance->AddRef();
135     return instance;
136 }
137
138 HRESULT WebPreferences::postPreferencesChangesNotification()
139 {
140     IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
141     HRESULT hr = nc->postNotificationName(webPreferencesChangedNotification(), static_cast<IWebPreferences*>(this), 0);
142     if (FAILED(hr))
143         return hr;
144
145     return S_OK;
146 }
147
148 WebPreferences* WebPreferences::getInstanceForIdentifier(BSTR identifier)
149 {
150     if (!identifier)
151         return sharedStandardPreferences();
152
153     WebCore::String identifierString(identifier, SysStringLen(identifier));
154     return webPreferencesInstances.get(identifierString);
155 }
156
157 void WebPreferences::setInstance(WebPreferences* instance, BSTR identifier)
158 {
159     if (!identifier || !instance)
160         return;
161     WebCore::String identifierString(identifier, SysStringLen(identifier));
162     webPreferencesInstances.add(identifierString, instance);
163 }
164
165 void WebPreferences::removeReferenceForIdentifier(BSTR identifier)
166 {
167     if (!identifier || webPreferencesInstances.isEmpty())
168         return;
169
170     WebCore::String identifierString(identifier, SysStringLen(identifier));
171     WebPreferences* webPreference = webPreferencesInstances.get(identifierString);
172     if (webPreference && webPreference->m_refCount == 1)
173         webPreferencesInstances.remove(identifierString);
174 }
175
176 void WebPreferences::initializeDefaultSettings()
177 {
178     if (defaultSettings)
179         return;
180
181     CFMutableDictionaryRef defaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
182
183     CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman"));
184     CFDictionaryAddValue(defaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New"));
185     CFDictionaryAddValue(defaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman"));
186     CFDictionaryAddValue(defaults, CFSTR(WebKitSansSerifFontPreferenceKey), CFSTR("Arial"));
187     CFDictionaryAddValue(defaults, CFSTR(WebKitCursiveFontPreferenceKey), CFSTR("Comic Sans MS"));
188     CFDictionaryAddValue(defaults, CFSTR(WebKitFantasyFontPreferenceKey), CFSTR("Comic Sans MS"));
189     CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumFontSizePreferenceKey), CFSTR("1"));
190     CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), CFSTR("9"));
191     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFontSizePreferenceKey), CFSTR("16"));
192     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFixedFontSizePreferenceKey), CFSTR("13"));
193     WebCore::String defaultDefaultEncoding(LPCTSTR_UI_STRING("ISO-8859-1", "The default, default character encoding"));
194     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), defaultDefaultEncoding.createCFString());
195
196     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), kCFBooleanFalse);
197     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetLocationPreferenceKey), CFSTR(""));
198     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), kCFBooleanFalse);
199     CFDictionaryAddValue(defaults, CFSTR(WebKitTextAreasAreResizablePreferenceKey), kCFBooleanFalse);
200     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaEnabledPreferenceKey), kCFBooleanTrue);
201     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptEnabledPreferenceKey), kCFBooleanTrue);
202     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), kCFBooleanTrue);
203     CFDictionaryAddValue(defaults, CFSTR(WebKitPluginsEnabledPreferenceKey), kCFBooleanTrue);
204     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImagesPreferenceKey), kCFBooleanTrue);
205     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), kCFBooleanTrue);
206     CFDictionaryAddValue(defaults, CFSTR(WebKitDisplayImagesKey), kCFBooleanTrue);
207     CFDictionaryAddValue(defaults, CFSTR(WebKitBackForwardCacheExpirationIntervalKey), CFSTR("1800"));
208     CFDictionaryAddValue(defaults, CFSTR(WebKitTabToLinksPreferenceKey), kCFBooleanFalse);
209     CFDictionaryAddValue(defaults, CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), kCFBooleanFalse);
210     CFDictionaryAddValue(defaults, CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey), kCFBooleanFalse);
211     CFDictionaryAddValue(defaults, CFSTR(WebKitShowsURLsInToolTipsPreferenceKey), kCFBooleanFalse);
212     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFDisplayModePreferenceKey), CFSTR("1"));
213     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFScaleFactorPreferenceKey), CFSTR("0"));
214
215     RetainPtr<CFStringRef> linkBehaviorStringRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior));
216     CFDictionaryAddValue(defaults, CFSTR(WebKitEditableLinkBehaviorPreferenceKey), linkBehaviorStringRef.get());
217
218     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryItemLimitKey), CFSTR("1000"));
219     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryAgeInDaysLimitKey), CFSTR("7"));
220     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseLocationKey), CFSTR(""));
221     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseEnabledPreferenceKey), kCFBooleanTrue);
222     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingTypePreferenceKey), CFSTR("2"));
223     CFDictionaryAddValue(defaults, CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), CFSTR("2"));
224     CFDictionaryAddValue(defaults, CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), kCFBooleanFalse);
225     CFDictionaryAddValue(defaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse);
226     CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
227     CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
228
229     RetainPtr<CFStringRef> cacheModelRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebCacheModelDocumentViewer));
230     CFDictionaryAddValue(defaults, CFSTR(WebKitCacheModelPreferenceKey), cacheModelRef.get());
231
232     CFDictionaryAddValue(defaults, CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey), kCFBooleanTrue);
233
234     defaultSettings = defaults;
235 }
236
237 const void* WebPreferences::valueForKey(CFStringRef key)
238 {
239     const void* value = CFDictionaryGetValue(m_privatePrefs.get(), key);
240     if (!value)
241         value = CFDictionaryGetValue(defaultSettings, key);
242
243     return value;
244 }
245
246 void WebPreferences::setValueForKey(CFStringRef key, CFPropertyListRef value)
247 {
248     CFDictionarySetValue(m_privatePrefs.get(), key, value);
249     if (m_autoSaves)
250         save();
251 }
252
253 BSTR WebPreferences::stringValueForKey(CFStringRef key)
254 {
255     CFStringRef str = (CFStringRef)valueForKey(key);
256     
257     if (!str || (CFGetTypeID(str) != CFStringGetTypeID()))
258         return 0;
259
260     CFIndex length = CFStringGetLength(str);
261     const UniChar* uniChars = CFStringGetCharactersPtr(str);
262     if (uniChars)
263         return SysAllocStringLen((LPCTSTR)uniChars, length);
264
265     BSTR bstr = SysAllocStringLen(0, length);
266     if (!bstr)
267         return 0;
268
269     if (!CFStringGetCString(str, (char*)bstr, (length+1)*sizeof(WCHAR), kCFStringEncodingUTF16)) {
270         SysFreeString(bstr);
271         return 0;
272     }
273         
274     bstr[length] = 0;
275     return bstr;
276 }
277
278 int WebPreferences::integerValueForKey(CFStringRef key)
279 {
280     return numberValueForPreferencesValue<int>(valueForKey(key));
281 }
282
283 BOOL WebPreferences::boolValueForKey(CFStringRef key)
284 {
285     return booleanValueForPreferencesValue(valueForKey(key));
286 }
287
288 float WebPreferences::floatValueForKey(CFStringRef key)
289 {
290     return numberValueForPreferencesValue<float>(valueForKey(key));
291 }
292
293 LONGLONG WebPreferences::longlongValueForKey(CFStringRef key)
294 {
295     return numberValueForPreferencesValue<LONGLONG>(valueForKey(key));
296 }
297
298 void WebPreferences::setStringValue(CFStringRef key, LPCTSTR value)
299 {
300     BSTR val = stringValueForKey(key);
301     if (val && !_tcscmp(val, value))
302         return;
303     SysFreeString(val);
304     
305     RetainPtr<CFStringRef> valueRef(AdoptCF,
306         CFStringCreateWithCharactersNoCopy(0, (UniChar*)_wcsdup(value), (CFIndex)_tcslen(value), kCFAllocatorMalloc));
307     setValueForKey(key, valueRef.get());
308
309     postPreferencesChangesNotification();
310 }
311
312 void WebPreferences::setIntegerValue(CFStringRef key, int value)
313 {
314     if (integerValueForKey(key) == value)
315         return;
316
317     setValueForKey(key, cfNumber(value).get());
318
319     postPreferencesChangesNotification();
320 }
321
322 void WebPreferences::setBoolValue(CFStringRef key, BOOL value)
323 {
324     if (boolValueForKey(key) == value)
325         return;
326
327     setValueForKey(key, value ? kCFBooleanTrue : kCFBooleanFalse);
328
329     postPreferencesChangesNotification();
330 }
331
332 void WebPreferences::setLongLongValue(CFStringRef key, LONGLONG value)
333 {
334     if (longlongValueForKey(key) == value)
335         return;
336
337     setValueForKey(key, cfNumber(value).get());
338
339     postPreferencesChangesNotification();
340 }
341
342 BSTR WebPreferences::webPreferencesChangedNotification()
343 {
344     static BSTR webPreferencesChangedNotification = SysAllocString(WebPreferencesChangedNotification);
345     return webPreferencesChangedNotification;
346 }
347
348 BSTR WebPreferences::webPreferencesRemovedNotification()
349 {
350     static BSTR webPreferencesRemovedNotification = SysAllocString(WebPreferencesRemovedNotification);
351     return webPreferencesRemovedNotification;
352 }
353 void WebPreferences::save()
354 {
355     RetainPtr<CFWriteStreamRef> stream(AdoptCF,
356         CFWriteStreamCreateWithAllocatedBuffers(kCFAllocatorDefault, kCFAllocatorDefault)); 
357     if (!stream)
358         return;
359
360     if (!CFWriteStreamOpen(stream.get()))
361         return;
362
363     if (!CFPropertyListWriteToStream(m_privatePrefs.get(), stream.get(), kCFPropertyListXMLFormat_v1_0, 0)) {
364         CFWriteStreamClose(stream.get());
365         return;
366     }
367     CFWriteStreamClose(stream.get());
368
369     RetainPtr<CFDataRef> dataRef(AdoptCF,
370         (CFDataRef)CFWriteStreamCopyProperty(stream.get(), kCFStreamPropertyDataWritten));
371     if (!dataRef)
372         return;
373
374     safeCreateFile(preferencesPath(), dataRef.get());
375 }
376
377 void WebPreferences::load()
378 {
379     initializeDefaultSettings();
380
381     CString path = preferencesPath().utf8();
382
383     RetainPtr<CFURLRef> urlRef(AdoptCF, CFURLCreateFromFileSystemRepresentation(0, reinterpret_cast<const UInt8*>(path.data()), path.length(), false));
384     if (!urlRef)
385         return;
386
387     RetainPtr<CFReadStreamRef> stream(AdoptCF, CFReadStreamCreateWithFile(0, urlRef.get()));
388     if (!stream) 
389         return;
390
391     if (CFReadStreamOpen(stream.get())) {
392         CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0;
393         RetainPtr<CFPropertyListRef> plist(AdoptCF, CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0));
394         CFReadStreamClose(stream.get());
395
396         if (CFGetTypeID(plist.get()) == CFDictionaryGetTypeID())
397             m_privatePrefs.adoptCF(const_cast<CFMutableDictionaryRef>(reinterpret_cast<CFDictionaryRef>(plist.releaseRef())));
398     }
399
400     if (!m_privatePrefs)
401         m_privatePrefs.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
402
403     migrateDefaultSettingsFromSafari3Beta();
404 }
405
406 void WebPreferences::migrateDefaultSettingsFromSafari3Beta()
407 {
408     // The "migration" happening here is a one-time removal of any default values
409     // that were stored in the user's preferences due to <rdar://problem/5214504>.
410
411     ASSERT(defaultSettings);
412     if (!m_privatePrefs)
413         return;
414
415     CFStringRef didMigrateKey = CFSTR(WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey);
416     if (boolValueForKey(didMigrateKey))
417         return;
418
419     removeValuesMatchingDefaultSettings();
420
421     bool oldValue = m_autoSaves;
422     m_autoSaves = true;
423     setBoolValue(didMigrateKey, TRUE);
424     m_autoSaves = oldValue;
425 }
426
427 void WebPreferences::removeValuesMatchingDefaultSettings()
428 {
429     ASSERT(m_privatePrefs);
430
431     int count = CFDictionaryGetCount(m_privatePrefs.get());
432     if (count <= 0)
433         return;
434
435     Vector<CFTypeRef> keys(count);
436     Vector<CFTypeRef> values(count);
437     CFDictionaryGetKeysAndValues(m_privatePrefs.get(), keys.data(), values.data());
438
439     for (int i = 0; i < count; ++i) {
440         if (!values[i])
441             continue;
442
443         CFTypeRef defaultValue = CFDictionaryGetValue(defaultSettings, keys[i]);
444         if (!defaultValue)
445             continue;
446
447         if (CFEqual(values[i], defaultValue))
448             CFDictionaryRemoveValue(m_privatePrefs.get(), keys[i]);
449     }
450 }
451
452 // IUnknown -------------------------------------------------------------------
453
454 HRESULT STDMETHODCALLTYPE WebPreferences::QueryInterface(REFIID riid, void** ppvObject)
455 {
456     *ppvObject = 0;
457     if (IsEqualGUID(riid, IID_IUnknown))
458         *ppvObject = static_cast<IWebPreferences*>(this);
459     else if (IsEqualGUID(riid, IID_IWebPreferences))
460         *ppvObject = static_cast<IWebPreferences*>(this);
461     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate))
462         *ppvObject = static_cast<IWebPreferencesPrivate*>(this);
463     else if (IsEqualGUID(riid, CLSID_WebPreferences))
464         *ppvObject = this;
465     else
466         return E_NOINTERFACE;
467
468     AddRef();
469     return S_OK;
470 }
471
472 ULONG STDMETHODCALLTYPE WebPreferences::AddRef(void)
473 {
474     return ++m_refCount;
475 }
476
477 ULONG STDMETHODCALLTYPE WebPreferences::Release(void)
478 {
479     ULONG newRef = --m_refCount;
480     if (!newRef)
481         delete(this);
482
483     return newRef;
484 }
485
486 // IWebPreferences ------------------------------------------------------------
487
488 HRESULT STDMETHODCALLTYPE WebPreferences::standardPreferences( 
489     /* [retval][out] */ IWebPreferences** standardPreferences)
490 {
491     if (!standardPreferences)
492         return E_POINTER;
493     *standardPreferences = sharedStandardPreferences();
494     (*standardPreferences)->AddRef();
495     return S_OK;
496 }
497
498 HRESULT STDMETHODCALLTYPE WebPreferences::initWithIdentifier( 
499         /* [in] */ BSTR anIdentifier,
500         /* [retval][out] */ IWebPreferences** preferences)
501 {
502     WebPreferences *instance = getInstanceForIdentifier(anIdentifier);
503     if (instance) {
504         *preferences = instance;
505         instance->AddRef();
506         return S_OK;
507     }
508
509     load();
510
511     *preferences = this;
512     AddRef();
513
514     if (anIdentifier) {
515         m_identifier = anIdentifier;
516         setInstance(this, m_identifier);
517     }
518
519     this->postPreferencesChangesNotification();
520
521     return S_OK;
522 }
523
524 HRESULT STDMETHODCALLTYPE WebPreferences::identifier( 
525     /* [retval][out] */ BSTR* ident)
526 {
527     if (!ident)
528         return E_POINTER;
529     *ident = m_identifier ? SysAllocString(m_identifier) : 0;
530     return S_OK;
531 }
532
533 HRESULT STDMETHODCALLTYPE WebPreferences::standardFontFamily( 
534     /* [retval][out] */ BSTR* family)
535 {
536     *family = stringValueForKey(CFSTR(WebKitStandardFontPreferenceKey));
537     return (*family) ? S_OK : E_FAIL;
538 }
539
540 HRESULT STDMETHODCALLTYPE WebPreferences::setStandardFontFamily( 
541     /* [in] */ BSTR family)
542 {
543     setStringValue(CFSTR(WebKitStandardFontPreferenceKey), family);
544     return S_OK;
545 }
546
547 HRESULT STDMETHODCALLTYPE WebPreferences::fixedFontFamily( 
548     /* [retval][out] */ BSTR* family)
549 {
550     *family = stringValueForKey(CFSTR(WebKitFixedFontPreferenceKey));
551     return (*family) ? S_OK : E_FAIL;
552 }
553
554 HRESULT STDMETHODCALLTYPE WebPreferences::setFixedFontFamily( 
555     /* [in] */ BSTR family)
556 {
557     setStringValue(CFSTR(WebKitFixedFontPreferenceKey), family);
558     return S_OK;
559 }
560
561 HRESULT STDMETHODCALLTYPE WebPreferences::serifFontFamily( 
562     /* [retval][out] */ BSTR* fontFamily)
563 {
564     *fontFamily = stringValueForKey(CFSTR(WebKitSerifFontPreferenceKey));
565     return (*fontFamily) ? S_OK : E_FAIL;
566 }
567
568 HRESULT STDMETHODCALLTYPE WebPreferences::setSerifFontFamily( 
569     /* [in] */ BSTR family)
570 {
571     setStringValue(CFSTR(WebKitSerifFontPreferenceKey), family);
572     return S_OK;
573 }
574
575 HRESULT STDMETHODCALLTYPE WebPreferences::sansSerifFontFamily( 
576     /* [retval][out] */ BSTR* family)
577 {
578     *family = stringValueForKey(CFSTR(WebKitSansSerifFontPreferenceKey));
579     return (*family) ? S_OK : E_FAIL;
580 }
581
582 HRESULT STDMETHODCALLTYPE WebPreferences::setSansSerifFontFamily( 
583     /* [in] */ BSTR family)
584 {
585     setStringValue(CFSTR(WebKitSansSerifFontPreferenceKey), family);
586     return S_OK;
587 }
588
589 HRESULT STDMETHODCALLTYPE WebPreferences::cursiveFontFamily( 
590     /* [retval][out] */ BSTR* family)
591 {
592     *family = stringValueForKey(CFSTR(WebKitCursiveFontPreferenceKey));
593     return (*family) ? S_OK : E_FAIL;
594 }
595
596 HRESULT STDMETHODCALLTYPE WebPreferences::setCursiveFontFamily( 
597     /* [in] */ BSTR family)
598 {
599     setStringValue(CFSTR(WebKitCursiveFontPreferenceKey), family);
600     return S_OK;
601 }
602
603 HRESULT STDMETHODCALLTYPE WebPreferences::fantasyFontFamily( 
604     /* [retval][out] */ BSTR* family)
605 {
606     *family = stringValueForKey(CFSTR(WebKitFantasyFontPreferenceKey));
607     return (*family) ? S_OK : E_FAIL;
608 }
609
610 HRESULT STDMETHODCALLTYPE WebPreferences::setFantasyFontFamily( 
611     /* [in] */ BSTR family)
612 {
613     setStringValue(CFSTR(WebKitFantasyFontPreferenceKey), family);
614     return S_OK;
615 }
616
617 HRESULT STDMETHODCALLTYPE WebPreferences::defaultFontSize( 
618     /* [retval][out] */ int* fontSize)
619 {
620     *fontSize = integerValueForKey(CFSTR(WebKitDefaultFontSizePreferenceKey));
621     return S_OK;
622 }
623
624 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultFontSize( 
625     /* [in] */ int fontSize)
626 {
627     setIntegerValue(CFSTR(WebKitDefaultFontSizePreferenceKey), fontSize);
628     return S_OK;
629 }
630
631 HRESULT STDMETHODCALLTYPE WebPreferences::defaultFixedFontSize( 
632     /* [retval][out] */ int* fontSize)
633 {
634     *fontSize = integerValueForKey(CFSTR(WebKitDefaultFixedFontSizePreferenceKey));
635     return S_OK;
636 }
637
638 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultFixedFontSize( 
639     /* [in] */ int fontSize)
640 {
641     setIntegerValue(CFSTR(WebKitDefaultFixedFontSizePreferenceKey), fontSize);
642     return S_OK;
643 }
644
645 HRESULT STDMETHODCALLTYPE WebPreferences::minimumFontSize( 
646     /* [retval][out] */ int* fontSize)
647 {
648     *fontSize = integerValueForKey(CFSTR(WebKitMinimumFontSizePreferenceKey));
649     return S_OK;
650 }
651
652 HRESULT STDMETHODCALLTYPE WebPreferences::setMinimumFontSize( 
653     /* [in] */ int fontSize)
654 {
655     setIntegerValue(CFSTR(WebKitMinimumFontSizePreferenceKey), fontSize);
656     return S_OK;
657 }
658
659 HRESULT STDMETHODCALLTYPE WebPreferences::minimumLogicalFontSize( 
660     /* [retval][out] */ int* fontSize)
661 {
662     *fontSize = integerValueForKey(CFSTR(WebKitMinimumLogicalFontSizePreferenceKey));
663     return S_OK;
664 }
665
666 HRESULT STDMETHODCALLTYPE WebPreferences::setMinimumLogicalFontSize( 
667     /* [in] */ int fontSize)
668 {
669     setIntegerValue(CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), fontSize);
670     return S_OK;
671 }
672
673 HRESULT STDMETHODCALLTYPE WebPreferences::defaultTextEncodingName( 
674     /* [retval][out] */ BSTR* name)
675 {
676     *name = stringValueForKey(CFSTR(WebKitDefaultTextEncodingNamePreferenceKey));
677     return (*name) ? S_OK : E_FAIL;
678 }
679
680 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultTextEncodingName( 
681     /* [in] */ BSTR name)
682 {
683     setStringValue(CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), name);
684     return S_OK;
685 }
686
687 HRESULT STDMETHODCALLTYPE WebPreferences::userStyleSheetEnabled( 
688     /* [retval][out] */ BOOL* enabled)
689 {
690     *enabled = boolValueForKey(CFSTR(WebKitUserStyleSheetEnabledPreferenceKey));
691     return S_OK;
692 }
693
694 HRESULT STDMETHODCALLTYPE WebPreferences::setUserStyleSheetEnabled( 
695     /* [in] */ BOOL enabled)
696 {
697     setBoolValue(CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), enabled);
698     return S_OK;
699 }
700
701 HRESULT STDMETHODCALLTYPE WebPreferences::userStyleSheetLocation( 
702     /* [retval][out] */ BSTR* location)
703 {
704     *location = stringValueForKey(CFSTR(WebKitUserStyleSheetLocationPreferenceKey));
705     return (*location) ? S_OK : E_FAIL;
706 }
707
708 HRESULT STDMETHODCALLTYPE WebPreferences::setUserStyleSheetLocation( 
709     /* [in] */ BSTR location)
710 {
711     setStringValue(CFSTR(WebKitUserStyleSheetLocationPreferenceKey), location);
712     return S_OK;
713 }
714
715 HRESULT STDMETHODCALLTYPE WebPreferences::isJavaEnabled( 
716     /* [retval][out] */ BOOL* enabled)
717 {
718     *enabled = boolValueForKey(CFSTR(WebKitJavaEnabledPreferenceKey));
719     return S_OK;
720 }
721
722 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaEnabled( 
723     /* [in] */ BOOL enabled)
724 {
725     setBoolValue(CFSTR(WebKitJavaEnabledPreferenceKey), enabled);
726     return S_OK;
727 }
728
729 HRESULT STDMETHODCALLTYPE WebPreferences::isJavaScriptEnabled( 
730     /* [retval][out] */ BOOL* enabled)
731 {
732     *enabled = boolValueForKey(CFSTR(WebKitJavaScriptEnabledPreferenceKey));
733     return S_OK;
734 }
735
736 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptEnabled( 
737     /* [in] */ BOOL enabled)
738 {
739     setBoolValue(CFSTR(WebKitJavaScriptEnabledPreferenceKey), enabled);
740     return S_OK;
741 }
742
743 HRESULT STDMETHODCALLTYPE WebPreferences::javaScriptCanOpenWindowsAutomatically( 
744     /* [retval][out] */ BOOL* enabled)
745 {
746     *enabled = boolValueForKey(CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey));
747     return S_OK;
748 }
749
750 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptCanOpenWindowsAutomatically( 
751     /* [in] */ BOOL enabled)
752 {
753     setBoolValue(CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), enabled);
754     return S_OK;
755 }
756
757 HRESULT STDMETHODCALLTYPE WebPreferences::arePlugInsEnabled( 
758     /* [retval][out] */ BOOL* enabled)
759 {
760     *enabled = boolValueForKey(CFSTR(WebKitPluginsEnabledPreferenceKey));
761     return S_OK;
762 }
763
764 HRESULT STDMETHODCALLTYPE WebPreferences::setPlugInsEnabled( 
765     /* [in] */ BOOL enabled)
766 {
767     setBoolValue(CFSTR(WebKitPluginsEnabledPreferenceKey), enabled);
768     return S_OK;
769 }
770
771 HRESULT STDMETHODCALLTYPE WebPreferences::allowsAnimatedImages( 
772     /* [retval][out] */ BOOL* enabled)
773 {
774     *enabled = boolValueForKey(CFSTR(WebKitAllowAnimatedImagesPreferenceKey));
775     return S_OK;
776 }
777
778 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowsAnimatedImages( 
779     /* [in] */ BOOL enabled)
780 {
781     setBoolValue(CFSTR(WebKitAllowAnimatedImagesPreferenceKey), enabled);
782     return S_OK;
783 }
784
785 HRESULT STDMETHODCALLTYPE WebPreferences::allowAnimatedImageLooping( 
786     /* [retval][out] */ BOOL* enabled)
787 {
788     *enabled = boolValueForKey(CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey));
789     return S_OK;
790 }
791
792 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowAnimatedImageLooping( 
793     /* [in] */ BOOL enabled)
794 {
795     setBoolValue(CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), enabled);
796     return S_OK;
797 }
798
799 HRESULT STDMETHODCALLTYPE WebPreferences::setLoadsImagesAutomatically( 
800     /* [in] */ BOOL enabled)
801 {
802     setBoolValue(CFSTR(WebKitDisplayImagesKey), enabled);
803     return S_OK;
804 }
805
806 HRESULT STDMETHODCALLTYPE WebPreferences::loadsImagesAutomatically( 
807     /* [retval][out] */ BOOL* enabled)
808 {
809     *enabled = boolValueForKey(CFSTR(WebKitDisplayImagesKey));
810     return S_OK;
811 }
812
813 HRESULT STDMETHODCALLTYPE WebPreferences::setAutosaves( 
814     /* [in] */ BOOL enabled)
815 {
816     m_autoSaves = !!enabled;
817     return S_OK;
818 }
819
820 HRESULT STDMETHODCALLTYPE WebPreferences::autosaves( 
821     /* [retval][out] */ BOOL* enabled)
822 {
823     *enabled = m_autoSaves ? TRUE : FALSE;
824     return S_OK;
825 }
826
827 HRESULT STDMETHODCALLTYPE WebPreferences::setShouldPrintBackgrounds( 
828     /* [in] */ BOOL enabled)
829 {
830     setBoolValue(CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), enabled);
831     return S_OK;
832 }
833
834 HRESULT STDMETHODCALLTYPE WebPreferences::shouldPrintBackgrounds( 
835     /* [retval][out] */ BOOL* enabled)
836 {
837     *enabled = boolValueForKey(CFSTR(WebKitShouldPrintBackgroundsPreferenceKey));
838     return S_OK;
839 }
840
841 HRESULT STDMETHODCALLTYPE WebPreferences::setPrivateBrowsingEnabled( 
842     /* [in] */ BOOL enabled)
843 {
844     setBoolValue(CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), enabled);
845     return S_OK;
846 }
847
848 HRESULT STDMETHODCALLTYPE WebPreferences::privateBrowsingEnabled( 
849     /* [retval][out] */ BOOL* enabled)
850 {
851     *enabled = boolValueForKey(CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey));
852     return S_OK;
853 }
854
855 HRESULT STDMETHODCALLTYPE WebPreferences::setTabsToLinks( 
856     /* [in] */ BOOL enabled)
857 {
858     setBoolValue(CFSTR(WebKitTabToLinksPreferenceKey), enabled);
859     return S_OK;
860 }
861
862 HRESULT STDMETHODCALLTYPE WebPreferences::tabsToLinks( 
863     /* [retval][out] */ BOOL* enabled)
864 {
865     *enabled = boolValueForKey(CFSTR(WebKitTabToLinksPreferenceKey));
866     return S_OK;
867 }
868
869 HRESULT STDMETHODCALLTYPE WebPreferences::setUsesPageCache( 
870         /* [in] */ BOOL usesPageCache)
871 {
872     setBoolValue(CFSTR(WebKitUsesPageCachePreferenceKey), usesPageCache);
873     return S_OK;
874 }
875
876 HRESULT STDMETHODCALLTYPE WebPreferences::usesPageCache( 
877     /* [retval][out] */ BOOL* usesPageCache)
878 {
879     *usesPageCache = boolValueForKey(CFSTR(WebKitUsesPageCachePreferenceKey));
880     return S_OK;
881 }
882
883 HRESULT STDMETHODCALLTYPE WebPreferences::textAreasAreResizable( 
884     /* [retval][out] */ BOOL* enabled)
885 {
886     *enabled = boolValueForKey(CFSTR(WebKitTextAreasAreResizablePreferenceKey));
887     return S_OK;
888 }
889
890 HRESULT STDMETHODCALLTYPE WebPreferences::setTextAreasAreResizable( 
891     /* [in] */ BOOL enabled)
892 {
893     setBoolValue(CFSTR(WebKitTextAreasAreResizablePreferenceKey), enabled);
894     return S_OK;
895 }
896
897 HRESULT WebPreferences::historyItemLimit(int* limit)
898 {
899     *limit = integerValueForKey(CFSTR(WebKitHistoryItemLimitKey));
900     return S_OK;
901 }
902
903 HRESULT WebPreferences::setHistoryItemLimit(int limit)
904 {
905     setIntegerValue(CFSTR(WebKitHistoryItemLimitKey), limit);
906     return S_OK;
907 }
908
909 HRESULT WebPreferences::historyAgeInDaysLimit(int* limit)
910 {
911     *limit = integerValueForKey(CFSTR(WebKitHistoryAgeInDaysLimitKey));
912     return S_OK;
913 }
914
915 HRESULT WebPreferences::setHistoryAgeInDaysLimit(int limit)
916 {
917     setIntegerValue(CFSTR(WebKitHistoryAgeInDaysLimitKey), limit);
918     return S_OK;
919 }
920
921 HRESULT WebPreferences::unused1()
922 {
923     ASSERT_NOT_REACHED();
924     return E_FAIL;
925 }
926
927 HRESULT WebPreferences::unused2()
928 {
929     ASSERT_NOT_REACHED();
930     return E_FAIL;
931 }
932
933 HRESULT WebPreferences::iconDatabaseLocation(
934     /* [out] */ BSTR* location)
935 {
936     *location = stringValueForKey(CFSTR(WebKitIconDatabaseLocationKey));
937     return (*location) ? S_OK : E_FAIL;
938 }
939
940 HRESULT WebPreferences::setIconDatabaseLocation(
941     /* [in] */ BSTR location)
942 {
943     setStringValue(CFSTR(WebKitIconDatabaseLocationKey), location);
944     return S_OK;
945 }
946
947 HRESULT WebPreferences::iconDatabaseEnabled(BOOL* enabled)//location)
948 {
949     *enabled = boolValueForKey(CFSTR(WebKitIconDatabaseEnabledPreferenceKey));
950     return S_OK;
951 }
952
953 HRESULT WebPreferences::setIconDatabaseEnabled(BOOL enabled )//location)
954 {
955     setBoolValue(CFSTR(WebKitIconDatabaseEnabledPreferenceKey), enabled);
956     return S_OK;
957 }
958
959 HRESULT STDMETHODCALLTYPE WebPreferences::fontSmoothing( 
960     /* [retval][out] */ FontSmoothingType* smoothingType)
961 {
962     *smoothingType = (FontSmoothingType) integerValueForKey(CFSTR(WebKitFontSmoothingTypePreferenceKey));
963     return S_OK;
964 }
965
966 HRESULT STDMETHODCALLTYPE WebPreferences::setFontSmoothing( 
967     /* [in] */ FontSmoothingType smoothingType)
968 {
969     setIntegerValue(CFSTR(WebKitFontSmoothingTypePreferenceKey), smoothingType);
970     if (smoothingType == FontSmoothingTypeWindows)
971         smoothingType = FontSmoothingTypeStandard;
972     wkSetFontSmoothingLevel((int)smoothingType);
973     return S_OK;
974 }
975
976 HRESULT STDMETHODCALLTYPE WebPreferences::editableLinkBehavior(
977     /* [out, retval] */ WebKitEditableLinkBehavior* editableLinkBehavior)
978 {
979     WebKitEditableLinkBehavior value = (WebKitEditableLinkBehavior) integerValueForKey(CFSTR(WebKitEditableLinkBehaviorPreferenceKey));
980     switch (value) {
981         case WebKitEditableLinkDefaultBehavior:
982         case WebKitEditableLinkAlwaysLive:
983         case WebKitEditableLinkOnlyLiveWithShiftKey:
984         case WebKitEditableLinkLiveWhenNotFocused:
985         case WebKitEditableLinkNeverLive:
986             *editableLinkBehavior = value;
987             break;
988         default: // ensure that a valid result is returned
989             *editableLinkBehavior = WebKitEditableLinkDefaultBehavior;
990             break;
991     }
992     return S_OK;
993 }
994
995 HRESULT STDMETHODCALLTYPE WebPreferences::setEditableLinkBehavior(
996     /* [in] */ WebKitEditableLinkBehavior behavior)
997 {
998     setIntegerValue(CFSTR(WebKitEditableLinkBehaviorPreferenceKey), behavior);
999     return S_OK;
1000 }
1001
1002 HRESULT STDMETHODCALLTYPE WebPreferences::cookieStorageAcceptPolicy( 
1003         /* [retval][out] */ WebKitCookieStorageAcceptPolicy *acceptPolicy )
1004 {
1005     if (!acceptPolicy)
1006         return E_POINTER;
1007
1008     *acceptPolicy = (WebKitCookieStorageAcceptPolicy)integerValueForKey(CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey));
1009     return S_OK;
1010 }
1011
1012 HRESULT STDMETHODCALLTYPE WebPreferences::setCookieStorageAcceptPolicy( 
1013         /* [in] */ WebKitCookieStorageAcceptPolicy acceptPolicy)
1014 {
1015     setIntegerValue(CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), acceptPolicy);
1016     return S_OK;
1017 }
1018
1019
1020 HRESULT WebPreferences::continuousSpellCheckingEnabled(BOOL* enabled)
1021 {
1022     *enabled = boolValueForKey(CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey));
1023     return S_OK;
1024 }
1025
1026 HRESULT WebPreferences::setContinuousSpellCheckingEnabled(BOOL enabled)
1027 {
1028     setBoolValue(CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), enabled);
1029     return S_OK;
1030 }
1031
1032 HRESULT WebPreferences::grammarCheckingEnabled(BOOL* enabled)
1033 {
1034     *enabled = boolValueForKey(CFSTR(WebGrammarCheckingEnabledPreferenceKey));
1035     return S_OK;
1036 }
1037
1038 HRESULT WebPreferences::setGrammarCheckingEnabled(BOOL enabled)
1039 {
1040     setBoolValue(CFSTR(WebGrammarCheckingEnabledPreferenceKey), enabled);
1041     return S_OK;
1042 }
1043
1044 HRESULT WebPreferences::allowContinuousSpellChecking(BOOL* enabled)
1045 {
1046     *enabled = boolValueForKey(CFSTR(AllowContinuousSpellCheckingPreferenceKey));
1047     return S_OK;
1048 }
1049
1050 HRESULT WebPreferences::setAllowContinuousSpellChecking(BOOL enabled)
1051 {
1052     setBoolValue(CFSTR(AllowContinuousSpellCheckingPreferenceKey), enabled);
1053     return S_OK;
1054 }
1055
1056 HRESULT WebPreferences::isDOMPasteAllowed(BOOL* enabled)
1057 {
1058     *enabled = boolValueForKey(CFSTR(WebKitDOMPasteAllowedPreferenceKey));
1059     return S_OK;
1060 }
1061     
1062 HRESULT WebPreferences::setDOMPasteAllowed(BOOL enabled)
1063 {
1064     setBoolValue(CFSTR(WebKitDOMPasteAllowedPreferenceKey), enabled);
1065     return S_OK;
1066 }
1067
1068 HRESULT WebPreferences::cacheModel(WebCacheModel* cacheModel)
1069 {
1070     if (!cacheModel)
1071         return E_POINTER;
1072
1073     *cacheModel = (WebCacheModel)integerValueForKey(CFSTR(WebKitCacheModelPreferenceKey));
1074     return S_OK;
1075 }
1076
1077 HRESULT WebPreferences::setCacheModel(WebCacheModel cacheModel)
1078 {
1079     setIntegerValue(CFSTR(WebKitCacheModelPreferenceKey), cacheModel);
1080     return S_OK;
1081 }
1082
1083 HRESULT WebPreferences::setDeveloperExtrasEnabled(BOOL enabled)
1084 {
1085     setBoolValue(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey), enabled);
1086     return S_OK;
1087 }
1088
1089 HRESULT WebPreferences::developerExtrasEnabled(BOOL* enabled)
1090 {
1091     if (!enabled)
1092         return E_POINTER;
1093
1094     *enabled = boolValueForKey(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey));
1095     return S_OK;
1096 }
1097
1098 bool WebPreferences::developerExtrasDisabledByOverride()
1099 {
1100     return !!boolValueForKey(CFSTR(DisableWebKitDeveloperExtrasPreferenceKey));
1101 }
1102
1103 HRESULT WebPreferences::setAutomaticallyDetectsCacheModel(BOOL automaticallyDetectsCacheModel)
1104 {
1105     m_automaticallyDetectsCacheModel = !!automaticallyDetectsCacheModel;
1106     return S_OK;
1107 }
1108
1109 HRESULT WebPreferences::automaticallyDetectsCacheModel(BOOL* automaticallyDetectsCacheModel)
1110 {
1111     if (!automaticallyDetectsCacheModel)
1112         return E_POINTER;
1113
1114     *automaticallyDetectsCacheModel = m_automaticallyDetectsCacheModel;
1115     return S_OK;
1116 }
1117
1118 HRESULT STDMETHODCALLTYPE WebPreferences::setAuthorAndUserStylesEnabled(BOOL enabled)
1119 {
1120     setBoolValue(CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey), enabled);
1121     return S_OK;
1122 }
1123
1124 HRESULT STDMETHODCALLTYPE WebPreferences::authorAndUserStylesEnabled(BOOL* enabled)
1125 {
1126     if (!enabled)
1127         return E_POINTER;
1128
1129     *enabled = boolValueForKey(CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey));
1130     return S_OK;
1131 }
1132
1133 void WebPreferences::willAddToWebView()
1134 {
1135     ++m_numWebViews;
1136 }
1137
1138 void WebPreferences::didRemoveFromWebView()
1139 {
1140     ASSERT(m_numWebViews);
1141     if (--m_numWebViews == 0) {
1142         IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
1143         nc->postNotificationName(webPreferencesRemovedNotification(), static_cast<IWebPreferences*>(this), 0);
1144     }
1145 }