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