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