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