• 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(WebKitWebSecurityEnabledPreferenceKey), kCFBooleanTrue);
207     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowUniversalAccessFromFileURLsPreferenceKey), kCFBooleanTrue);
208     CFDictionaryAddValue(defaults, CFSTR(WebKitXSSAuditorEnabledPreferenceKey), kCFBooleanTrue);
209     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), kCFBooleanTrue);
210     CFDictionaryAddValue(defaults, CFSTR(WebKitPluginsEnabledPreferenceKey), kCFBooleanTrue);
211     CFDictionaryAddValue(defaults, CFSTR(WebKitDatabasesEnabledPreferenceKey), kCFBooleanTrue);
212     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageEnabledPreferenceKey), kCFBooleanTrue);
213     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImagesPreferenceKey), kCFBooleanTrue);
214     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), kCFBooleanTrue);
215     CFDictionaryAddValue(defaults, CFSTR(WebKitDisplayImagesKey), kCFBooleanTrue);
216     CFDictionaryAddValue(defaults, CFSTR(WebKitBackForwardCacheExpirationIntervalKey), CFSTR("1800"));
217     CFDictionaryAddValue(defaults, CFSTR(WebKitTabToLinksPreferenceKey), kCFBooleanFalse);
218     CFDictionaryAddValue(defaults, CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), kCFBooleanFalse);
219     CFDictionaryAddValue(defaults, CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey), kCFBooleanFalse);
220     CFDictionaryAddValue(defaults, CFSTR(WebKitShowsURLsInToolTipsPreferenceKey), kCFBooleanFalse);
221     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFDisplayModePreferenceKey), CFSTR("1"));
222     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFScaleFactorPreferenceKey), CFSTR("0"));
223 
224     RetainPtr<CFStringRef> linkBehaviorStringRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior));
225     CFDictionaryAddValue(defaults, CFSTR(WebKitEditableLinkBehaviorPreferenceKey), linkBehaviorStringRef.get());
226 
227     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryItemLimitKey), CFSTR("1000"));
228     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryAgeInDaysLimitKey), CFSTR("7"));
229     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseLocationKey), CFSTR(""));
230     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseEnabledPreferenceKey), kCFBooleanTrue);
231     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingTypePreferenceKey), CFSTR("2"));
232     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingContrastPreferenceKey), CFSTR("2"));
233     CFDictionaryAddValue(defaults, CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), CFSTR("2"));
234     CFDictionaryAddValue(defaults, CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), kCFBooleanFalse);
235     CFDictionaryAddValue(defaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse);
236     CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
237     CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
238     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageDatabasePathPreferenceKey), CFSTR(""));
239 
240     RetainPtr<CFStringRef> cacheModelRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebCacheModelDocumentViewer));
241     CFDictionaryAddValue(defaults, CFSTR(WebKitCacheModelPreferenceKey), cacheModelRef.get());
242 
243     CFDictionaryAddValue(defaults, CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey), kCFBooleanTrue);
244     CFDictionaryAddValue(defaults, CFSTR(WebKitApplicationChromeModePreferenceKey), kCFBooleanFalse);
245 
246     CFDictionaryAddValue(defaults, CFSTR(WebKitOfflineWebApplicationCacheEnabledPreferenceKey), kCFBooleanFalse);
247 
248     CFDictionaryAddValue(defaults, CFSTR(WebKitPaintNativeControlsPreferenceKey), kCFBooleanTrue);
249 
250     defaultSettings = defaults;
251 }
252 
valueForKey(CFStringRef key)253 RetainPtr<CFPropertyListRef> WebPreferences::valueForKey(CFStringRef key)
254 {
255     RetainPtr<CFPropertyListRef> value = CFDictionaryGetValue(m_privatePrefs.get(), key);
256     if (value)
257         return value;
258 
259     value.adoptCF(CFPreferencesCopyAppValue(key, kCFPreferencesCurrentApplication));
260     if (value)
261         return value;
262 
263     return CFDictionaryGetValue(defaultSettings, key);
264 }
265 
setValueForKey(CFStringRef key,CFPropertyListRef value)266 void WebPreferences::setValueForKey(CFStringRef key, CFPropertyListRef value)
267 {
268     CFDictionarySetValue(m_privatePrefs.get(), key, value);
269     if (m_autoSaves) {
270         CFPreferencesSetAppValue(key, value, kCFPreferencesCurrentApplication);
271         save();
272     }
273 }
274 
stringValueForKey(CFStringRef key)275 BSTR WebPreferences::stringValueForKey(CFStringRef key)
276 {
277     RetainPtr<CFPropertyListRef> value = valueForKey(key);
278 
279     if (!value || (CFGetTypeID(value.get()) != CFStringGetTypeID()))
280         return 0;
281 
282     CFStringRef str = static_cast<CFStringRef>(value.get());
283 
284     CFIndex length = CFStringGetLength(str);
285     const UniChar* uniChars = CFStringGetCharactersPtr(str);
286     if (uniChars)
287         return SysAllocStringLen((LPCTSTR)uniChars, length);
288 
289     BSTR bstr = SysAllocStringLen(0, length);
290     if (!bstr)
291         return 0;
292 
293     if (!CFStringGetCString(str, (char*)bstr, (length+1)*sizeof(WCHAR), kCFStringEncodingUTF16)) {
294         SysFreeString(bstr);
295         return 0;
296     }
297 
298     bstr[length] = 0;
299     return bstr;
300 }
301 
integerValueForKey(CFStringRef key)302 int WebPreferences::integerValueForKey(CFStringRef key)
303 {
304     return numberValueForPreferencesValue<int>(valueForKey(key).get());
305 }
306 
boolValueForKey(CFStringRef key)307 BOOL WebPreferences::boolValueForKey(CFStringRef key)
308 {
309     return booleanValueForPreferencesValue(valueForKey(key).get());
310 }
311 
floatValueForKey(CFStringRef key)312 float WebPreferences::floatValueForKey(CFStringRef key)
313 {
314     return numberValueForPreferencesValue<float>(valueForKey(key).get());
315 }
316 
longlongValueForKey(CFStringRef key)317 LONGLONG WebPreferences::longlongValueForKey(CFStringRef key)
318 {
319     return numberValueForPreferencesValue<LONGLONG>(valueForKey(key).get());
320 }
321 
setStringValue(CFStringRef key,LPCTSTR value)322 void WebPreferences::setStringValue(CFStringRef key, LPCTSTR value)
323 {
324     BSTR val = stringValueForKey(key);
325     if (val && !_tcscmp(val, value))
326         return;
327     SysFreeString(val);
328 
329     RetainPtr<CFStringRef> valueRef(AdoptCF,
330         CFStringCreateWithCharactersNoCopy(0, (UniChar*)_wcsdup(value), (CFIndex)_tcslen(value), kCFAllocatorMalloc));
331     setValueForKey(key, valueRef.get());
332 
333     postPreferencesChangesNotification();
334 }
335 
setIntegerValue(CFStringRef key,int value)336 void WebPreferences::setIntegerValue(CFStringRef key, int value)
337 {
338     if (integerValueForKey(key) == value)
339         return;
340 
341     setValueForKey(key, cfNumber(value).get());
342 
343     postPreferencesChangesNotification();
344 }
345 
setFloatValue(CFStringRef key,float value)346 void WebPreferences::setFloatValue(CFStringRef key, float value)
347 {
348     if (floatValueForKey(key) == value)
349         return;
350 
351     setValueForKey(key, cfNumber(value).get());
352 
353     postPreferencesChangesNotification();
354 }
355 
setBoolValue(CFStringRef key,BOOL value)356 void WebPreferences::setBoolValue(CFStringRef key, BOOL value)
357 {
358     if (boolValueForKey(key) == value)
359         return;
360 
361     setValueForKey(key, value ? kCFBooleanTrue : kCFBooleanFalse);
362 
363     postPreferencesChangesNotification();
364 }
365 
setLongLongValue(CFStringRef key,LONGLONG value)366 void WebPreferences::setLongLongValue(CFStringRef key, LONGLONG value)
367 {
368     if (longlongValueForKey(key) == value)
369         return;
370 
371     setValueForKey(key, cfNumber(value).get());
372 
373     postPreferencesChangesNotification();
374 }
375 
webPreferencesChangedNotification()376 BSTR WebPreferences::webPreferencesChangedNotification()
377 {
378     static BSTR webPreferencesChangedNotification = SysAllocString(WebPreferencesChangedNotification);
379     return webPreferencesChangedNotification;
380 }
381 
webPreferencesRemovedNotification()382 BSTR WebPreferences::webPreferencesRemovedNotification()
383 {
384     static BSTR webPreferencesRemovedNotification = SysAllocString(WebPreferencesRemovedNotification);
385     return webPreferencesRemovedNotification;
386 }
387 
save()388 void WebPreferences::save()
389 {
390     CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
391 }
392 
load()393 void WebPreferences::load()
394 {
395     initializeDefaultSettings();
396 
397     m_privatePrefs.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
398 
399     migrateWebKitPreferencesToCFPreferences();
400 }
401 
migrateWebKitPreferencesToCFPreferences()402 void WebPreferences::migrateWebKitPreferencesToCFPreferences()
403 {
404     CFStringRef didMigrateKey = CFSTR(WebKitDidMigrateWebKitPreferencesToCFPreferencesPreferenceKey);
405     if (boolValueForKey(didMigrateKey))
406         return;
407     bool oldValue = m_autoSaves;
408     m_autoSaves = true;
409     setBoolValue(didMigrateKey, TRUE);
410     m_autoSaves = oldValue;
411 
412     CString path = oldPreferencesPath().utf8();
413 
414     RetainPtr<CFURLRef> urlRef(AdoptCF, CFURLCreateFromFileSystemRepresentation(0, reinterpret_cast<const UInt8*>(path.data()), path.length(), false));
415     if (!urlRef)
416         return;
417 
418     RetainPtr<CFReadStreamRef> stream(AdoptCF, CFReadStreamCreateWithFile(0, urlRef.get()));
419     if (!stream)
420         return;
421 
422     if (!CFReadStreamOpen(stream.get()))
423         return;
424 
425     CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0;
426     RetainPtr<CFPropertyListRef> plist(AdoptCF, CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0));
427     CFReadStreamClose(stream.get());
428 
429     if (!plist || CFGetTypeID(plist.get()) != CFDictionaryGetTypeID())
430         return;
431 
432     copyWebKitPreferencesToCFPreferences(static_cast<CFDictionaryRef>(plist.get()));
433 
434     deleteFile(oldPreferencesPath());
435 }
436 
copyWebKitPreferencesToCFPreferences(CFDictionaryRef dict)437 void WebPreferences::copyWebKitPreferencesToCFPreferences(CFDictionaryRef dict)
438 {
439     ASSERT_ARG(dict, dict);
440 
441     int count = CFDictionaryGetCount(dict);
442     if (count <= 0)
443         return;
444 
445     CFStringRef didRemoveDefaultsKey = CFSTR(WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey);
446     bool omitDefaults = !booleanValueForPreferencesValue(CFDictionaryGetValue(dict, didRemoveDefaultsKey));
447 
448     OwnArrayPtr<CFTypeRef> keys(new CFTypeRef[count]);
449     OwnArrayPtr<CFTypeRef> values(new CFTypeRef[count]);
450     CFDictionaryGetKeysAndValues(dict, keys.get(), values.get());
451 
452     for (int i = 0; i < count; ++i) {
453         if (!keys[i] || !values[i] || CFGetTypeID(keys[i]) != CFStringGetTypeID())
454             continue;
455 
456         if (omitDefaults) {
457             CFTypeRef defaultValue = CFDictionaryGetValue(defaultSettings, keys[i]);
458             if (defaultValue && CFEqual(defaultValue, values[i]))
459                 continue;
460         }
461 
462         setValueForKey(static_cast<CFStringRef>(keys[i]), values[i]);
463     }
464 }
465 
466 // IUnknown -------------------------------------------------------------------
467 
QueryInterface(REFIID riid,void ** ppvObject)468 HRESULT STDMETHODCALLTYPE WebPreferences::QueryInterface(REFIID riid, void** ppvObject)
469 {
470     *ppvObject = 0;
471     if (IsEqualGUID(riid, IID_IUnknown))
472         *ppvObject = static_cast<IWebPreferences*>(this);
473     else if (IsEqualGUID(riid, IID_IWebPreferences))
474         *ppvObject = static_cast<IWebPreferences*>(this);
475     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate))
476         *ppvObject = static_cast<IWebPreferencesPrivate*>(this);
477     else if (IsEqualGUID(riid, CLSID_WebPreferences))
478         *ppvObject = this;
479     else
480         return E_NOINTERFACE;
481 
482     AddRef();
483     return S_OK;
484 }
485 
AddRef(void)486 ULONG STDMETHODCALLTYPE WebPreferences::AddRef(void)
487 {
488     return ++m_refCount;
489 }
490 
Release(void)491 ULONG STDMETHODCALLTYPE WebPreferences::Release(void)
492 {
493     ULONG newRef = --m_refCount;
494     if (!newRef)
495         delete(this);
496 
497     return newRef;
498 }
499 
500 // IWebPreferences ------------------------------------------------------------
501 
standardPreferences(IWebPreferences ** standardPreferences)502 HRESULT STDMETHODCALLTYPE WebPreferences::standardPreferences(
503     /* [retval][out] */ IWebPreferences** standardPreferences)
504 {
505     if (!standardPreferences)
506         return E_POINTER;
507     *standardPreferences = sharedStandardPreferences();
508     (*standardPreferences)->AddRef();
509     return S_OK;
510 }
511 
initWithIdentifier(BSTR anIdentifier,IWebPreferences ** preferences)512 HRESULT STDMETHODCALLTYPE WebPreferences::initWithIdentifier(
513         /* [in] */ BSTR anIdentifier,
514         /* [retval][out] */ IWebPreferences** preferences)
515 {
516     WebPreferences *instance = getInstanceForIdentifier(anIdentifier);
517     if (instance) {
518         *preferences = instance;
519         instance->AddRef();
520         return S_OK;
521     }
522 
523     load();
524 
525     *preferences = this;
526     AddRef();
527 
528     if (anIdentifier) {
529         m_identifier = anIdentifier;
530         setInstance(this, m_identifier);
531     }
532 
533     this->postPreferencesChangesNotification();
534 
535     return S_OK;
536 }
537 
identifier(BSTR * ident)538 HRESULT STDMETHODCALLTYPE WebPreferences::identifier(
539     /* [retval][out] */ BSTR* ident)
540 {
541     if (!ident)
542         return E_POINTER;
543     *ident = m_identifier ? SysAllocString(m_identifier) : 0;
544     return S_OK;
545 }
546 
standardFontFamily(BSTR * family)547 HRESULT STDMETHODCALLTYPE WebPreferences::standardFontFamily(
548     /* [retval][out] */ BSTR* family)
549 {
550     *family = stringValueForKey(CFSTR(WebKitStandardFontPreferenceKey));
551     return (*family) ? S_OK : E_FAIL;
552 }
553 
setStandardFontFamily(BSTR family)554 HRESULT STDMETHODCALLTYPE WebPreferences::setStandardFontFamily(
555     /* [in] */ BSTR family)
556 {
557     setStringValue(CFSTR(WebKitStandardFontPreferenceKey), family);
558     return S_OK;
559 }
560 
fixedFontFamily(BSTR * family)561 HRESULT STDMETHODCALLTYPE WebPreferences::fixedFontFamily(
562     /* [retval][out] */ BSTR* family)
563 {
564     *family = stringValueForKey(CFSTR(WebKitFixedFontPreferenceKey));
565     return (*family) ? S_OK : E_FAIL;
566 }
567 
setFixedFontFamily(BSTR family)568 HRESULT STDMETHODCALLTYPE WebPreferences::setFixedFontFamily(
569     /* [in] */ BSTR family)
570 {
571     setStringValue(CFSTR(WebKitFixedFontPreferenceKey), family);
572     return S_OK;
573 }
574 
serifFontFamily(BSTR * fontFamily)575 HRESULT STDMETHODCALLTYPE WebPreferences::serifFontFamily(
576     /* [retval][out] */ BSTR* fontFamily)
577 {
578     *fontFamily = stringValueForKey(CFSTR(WebKitSerifFontPreferenceKey));
579     return (*fontFamily) ? S_OK : E_FAIL;
580 }
581 
setSerifFontFamily(BSTR family)582 HRESULT STDMETHODCALLTYPE WebPreferences::setSerifFontFamily(
583     /* [in] */ BSTR family)
584 {
585     setStringValue(CFSTR(WebKitSerifFontPreferenceKey), family);
586     return S_OK;
587 }
588 
sansSerifFontFamily(BSTR * family)589 HRESULT STDMETHODCALLTYPE WebPreferences::sansSerifFontFamily(
590     /* [retval][out] */ BSTR* family)
591 {
592     *family = stringValueForKey(CFSTR(WebKitSansSerifFontPreferenceKey));
593     return (*family) ? S_OK : E_FAIL;
594 }
595 
setSansSerifFontFamily(BSTR family)596 HRESULT STDMETHODCALLTYPE WebPreferences::setSansSerifFontFamily(
597     /* [in] */ BSTR family)
598 {
599     setStringValue(CFSTR(WebKitSansSerifFontPreferenceKey), family);
600     return S_OK;
601 }
602 
cursiveFontFamily(BSTR * family)603 HRESULT STDMETHODCALLTYPE WebPreferences::cursiveFontFamily(
604     /* [retval][out] */ BSTR* family)
605 {
606     *family = stringValueForKey(CFSTR(WebKitCursiveFontPreferenceKey));
607     return (*family) ? S_OK : E_FAIL;
608 }
609 
setCursiveFontFamily(BSTR family)610 HRESULT STDMETHODCALLTYPE WebPreferences::setCursiveFontFamily(
611     /* [in] */ BSTR family)
612 {
613     setStringValue(CFSTR(WebKitCursiveFontPreferenceKey), family);
614     return S_OK;
615 }
616 
fantasyFontFamily(BSTR * family)617 HRESULT STDMETHODCALLTYPE WebPreferences::fantasyFontFamily(
618     /* [retval][out] */ BSTR* family)
619 {
620     *family = stringValueForKey(CFSTR(WebKitFantasyFontPreferenceKey));
621     return (*family) ? S_OK : E_FAIL;
622 }
623 
setFantasyFontFamily(BSTR family)624 HRESULT STDMETHODCALLTYPE WebPreferences::setFantasyFontFamily(
625     /* [in] */ BSTR family)
626 {
627     setStringValue(CFSTR(WebKitFantasyFontPreferenceKey), family);
628     return S_OK;
629 }
630 
defaultFontSize(int * fontSize)631 HRESULT STDMETHODCALLTYPE WebPreferences::defaultFontSize(
632     /* [retval][out] */ int* fontSize)
633 {
634     *fontSize = integerValueForKey(CFSTR(WebKitDefaultFontSizePreferenceKey));
635     return S_OK;
636 }
637 
setDefaultFontSize(int fontSize)638 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultFontSize(
639     /* [in] */ int fontSize)
640 {
641     setIntegerValue(CFSTR(WebKitDefaultFontSizePreferenceKey), fontSize);
642     return S_OK;
643 }
644 
defaultFixedFontSize(int * fontSize)645 HRESULT STDMETHODCALLTYPE WebPreferences::defaultFixedFontSize(
646     /* [retval][out] */ int* fontSize)
647 {
648     *fontSize = integerValueForKey(CFSTR(WebKitDefaultFixedFontSizePreferenceKey));
649     return S_OK;
650 }
651 
setDefaultFixedFontSize(int fontSize)652 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultFixedFontSize(
653     /* [in] */ int fontSize)
654 {
655     setIntegerValue(CFSTR(WebKitDefaultFixedFontSizePreferenceKey), fontSize);
656     return S_OK;
657 }
658 
minimumFontSize(int * fontSize)659 HRESULT STDMETHODCALLTYPE WebPreferences::minimumFontSize(
660     /* [retval][out] */ int* fontSize)
661 {
662     *fontSize = integerValueForKey(CFSTR(WebKitMinimumFontSizePreferenceKey));
663     return S_OK;
664 }
665 
setMinimumFontSize(int fontSize)666 HRESULT STDMETHODCALLTYPE WebPreferences::setMinimumFontSize(
667     /* [in] */ int fontSize)
668 {
669     setIntegerValue(CFSTR(WebKitMinimumFontSizePreferenceKey), fontSize);
670     return S_OK;
671 }
672 
minimumLogicalFontSize(int * fontSize)673 HRESULT STDMETHODCALLTYPE WebPreferences::minimumLogicalFontSize(
674     /* [retval][out] */ int* fontSize)
675 {
676     *fontSize = integerValueForKey(CFSTR(WebKitMinimumLogicalFontSizePreferenceKey));
677     return S_OK;
678 }
679 
setMinimumLogicalFontSize(int fontSize)680 HRESULT STDMETHODCALLTYPE WebPreferences::setMinimumLogicalFontSize(
681     /* [in] */ int fontSize)
682 {
683     setIntegerValue(CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), fontSize);
684     return S_OK;
685 }
686 
defaultTextEncodingName(BSTR * name)687 HRESULT STDMETHODCALLTYPE WebPreferences::defaultTextEncodingName(
688     /* [retval][out] */ BSTR* name)
689 {
690     *name = stringValueForKey(CFSTR(WebKitDefaultTextEncodingNamePreferenceKey));
691     return (*name) ? S_OK : E_FAIL;
692 }
693 
setDefaultTextEncodingName(BSTR name)694 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultTextEncodingName(
695     /* [in] */ BSTR name)
696 {
697     setStringValue(CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), name);
698     return S_OK;
699 }
700 
userStyleSheetEnabled(BOOL * enabled)701 HRESULT STDMETHODCALLTYPE WebPreferences::userStyleSheetEnabled(
702     /* [retval][out] */ BOOL* enabled)
703 {
704     *enabled = boolValueForKey(CFSTR(WebKitUserStyleSheetEnabledPreferenceKey));
705     return S_OK;
706 }
707 
setUserStyleSheetEnabled(BOOL enabled)708 HRESULT STDMETHODCALLTYPE WebPreferences::setUserStyleSheetEnabled(
709     /* [in] */ BOOL enabled)
710 {
711     setBoolValue(CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), enabled);
712     return S_OK;
713 }
714 
userStyleSheetLocation(BSTR * location)715 HRESULT STDMETHODCALLTYPE WebPreferences::userStyleSheetLocation(
716     /* [retval][out] */ BSTR* location)
717 {
718     *location = stringValueForKey(CFSTR(WebKitUserStyleSheetLocationPreferenceKey));
719     return (*location) ? S_OK : E_FAIL;
720 }
721 
setUserStyleSheetLocation(BSTR location)722 HRESULT STDMETHODCALLTYPE WebPreferences::setUserStyleSheetLocation(
723     /* [in] */ BSTR location)
724 {
725     setStringValue(CFSTR(WebKitUserStyleSheetLocationPreferenceKey), location);
726     return S_OK;
727 }
728 
isJavaEnabled(BOOL * enabled)729 HRESULT STDMETHODCALLTYPE WebPreferences::isJavaEnabled(
730     /* [retval][out] */ BOOL* enabled)
731 {
732     *enabled = boolValueForKey(CFSTR(WebKitJavaEnabledPreferenceKey));
733     return S_OK;
734 }
735 
setJavaEnabled(BOOL enabled)736 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaEnabled(
737     /* [in] */ BOOL enabled)
738 {
739     setBoolValue(CFSTR(WebKitJavaEnabledPreferenceKey), enabled);
740     return S_OK;
741 }
742 
isJavaScriptEnabled(BOOL * enabled)743 HRESULT STDMETHODCALLTYPE WebPreferences::isJavaScriptEnabled(
744     /* [retval][out] */ BOOL* enabled)
745 {
746     *enabled = boolValueForKey(CFSTR(WebKitJavaScriptEnabledPreferenceKey));
747     return S_OK;
748 }
749 
setJavaScriptEnabled(BOOL enabled)750 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptEnabled(
751     /* [in] */ BOOL enabled)
752 {
753     setBoolValue(CFSTR(WebKitJavaScriptEnabledPreferenceKey), enabled);
754     return S_OK;
755 }
756 
isWebSecurityEnabled(BOOL * enabled)757 HRESULT STDMETHODCALLTYPE WebPreferences::isWebSecurityEnabled(
758     /* [retval][out] */ BOOL* enabled)
759 {
760     *enabled = boolValueForKey(CFSTR(WebKitWebSecurityEnabledPreferenceKey));
761     return S_OK;
762 }
763 
setWebSecurityEnabled(BOOL enabled)764 HRESULT STDMETHODCALLTYPE WebPreferences::setWebSecurityEnabled(
765     /* [in] */ BOOL enabled)
766 {
767     setBoolValue(CFSTR(WebKitWebSecurityEnabledPreferenceKey), enabled);
768     return S_OK;
769 }
770 
allowUniversalAccessFromFileURLs(BOOL * allowAccess)771 HRESULT STDMETHODCALLTYPE WebPreferences::allowUniversalAccessFromFileURLs(
772     /* [retval][out] */ BOOL* allowAccess)
773 {
774     *allowAccess = boolValueForKey(CFSTR(WebKitAllowUniversalAccessFromFileURLsPreferenceKey));
775     return S_OK;
776 }
777 
setAllowUniversalAccessFromFileURLs(BOOL allowAccess)778 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowUniversalAccessFromFileURLs(
779     /* [in] */ BOOL allowAccess)
780 {
781     setBoolValue(CFSTR(WebKitAllowUniversalAccessFromFileURLsPreferenceKey), allowAccess);
782     return S_OK;
783 }
784 
isXSSAuditorEnabled(BOOL * enabled)785 HRESULT STDMETHODCALLTYPE WebPreferences::isXSSAuditorEnabled(
786     /* [retval][out] */ BOOL* enabled)
787 {
788     *enabled = boolValueForKey(CFSTR(WebKitXSSAuditorEnabledPreferenceKey));
789     return S_OK;
790 }
791 
setXSSAuditorEnabled(BOOL enabled)792 HRESULT STDMETHODCALLTYPE WebPreferences::setXSSAuditorEnabled(
793     /* [in] */ BOOL enabled)
794 {
795     setBoolValue(CFSTR(WebKitXSSAuditorEnabledPreferenceKey), enabled);
796     return S_OK;
797 }
798 
javaScriptCanOpenWindowsAutomatically(BOOL * enabled)799 HRESULT STDMETHODCALLTYPE WebPreferences::javaScriptCanOpenWindowsAutomatically(
800     /* [retval][out] */ BOOL* enabled)
801 {
802     *enabled = boolValueForKey(CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey));
803     return S_OK;
804 }
805 
setJavaScriptCanOpenWindowsAutomatically(BOOL enabled)806 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptCanOpenWindowsAutomatically(
807     /* [in] */ BOOL enabled)
808 {
809     setBoolValue(CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), enabled);
810     return S_OK;
811 }
812 
arePlugInsEnabled(BOOL * enabled)813 HRESULT STDMETHODCALLTYPE WebPreferences::arePlugInsEnabled(
814     /* [retval][out] */ BOOL* enabled)
815 {
816     *enabled = boolValueForKey(CFSTR(WebKitPluginsEnabledPreferenceKey));
817     return S_OK;
818 }
819 
setPlugInsEnabled(BOOL enabled)820 HRESULT STDMETHODCALLTYPE WebPreferences::setPlugInsEnabled(
821     /* [in] */ BOOL enabled)
822 {
823     setBoolValue(CFSTR(WebKitPluginsEnabledPreferenceKey), enabled);
824     return S_OK;
825 }
826 
allowsAnimatedImages(BOOL * enabled)827 HRESULT STDMETHODCALLTYPE WebPreferences::allowsAnimatedImages(
828     /* [retval][out] */ BOOL* enabled)
829 {
830     *enabled = boolValueForKey(CFSTR(WebKitAllowAnimatedImagesPreferenceKey));
831     return S_OK;
832 }
833 
setAllowsAnimatedImages(BOOL enabled)834 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowsAnimatedImages(
835     /* [in] */ BOOL enabled)
836 {
837     setBoolValue(CFSTR(WebKitAllowAnimatedImagesPreferenceKey), enabled);
838     return S_OK;
839 }
840 
allowAnimatedImageLooping(BOOL * enabled)841 HRESULT STDMETHODCALLTYPE WebPreferences::allowAnimatedImageLooping(
842     /* [retval][out] */ BOOL* enabled)
843 {
844     *enabled = boolValueForKey(CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey));
845     return S_OK;
846 }
847 
setAllowAnimatedImageLooping(BOOL enabled)848 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowAnimatedImageLooping(
849     /* [in] */ BOOL enabled)
850 {
851     setBoolValue(CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), enabled);
852     return S_OK;
853 }
854 
setLoadsImagesAutomatically(BOOL enabled)855 HRESULT STDMETHODCALLTYPE WebPreferences::setLoadsImagesAutomatically(
856     /* [in] */ BOOL enabled)
857 {
858     setBoolValue(CFSTR(WebKitDisplayImagesKey), enabled);
859     return S_OK;
860 }
861 
loadsImagesAutomatically(BOOL * enabled)862 HRESULT STDMETHODCALLTYPE WebPreferences::loadsImagesAutomatically(
863     /* [retval][out] */ BOOL* enabled)
864 {
865     *enabled = boolValueForKey(CFSTR(WebKitDisplayImagesKey));
866     return S_OK;
867 }
868 
setAutosaves(BOOL enabled)869 HRESULT STDMETHODCALLTYPE WebPreferences::setAutosaves(
870     /* [in] */ BOOL enabled)
871 {
872     m_autoSaves = !!enabled;
873     return S_OK;
874 }
875 
autosaves(BOOL * enabled)876 HRESULT STDMETHODCALLTYPE WebPreferences::autosaves(
877     /* [retval][out] */ BOOL* enabled)
878 {
879     *enabled = m_autoSaves ? TRUE : FALSE;
880     return S_OK;
881 }
882 
setShouldPrintBackgrounds(BOOL enabled)883 HRESULT STDMETHODCALLTYPE WebPreferences::setShouldPrintBackgrounds(
884     /* [in] */ BOOL enabled)
885 {
886     setBoolValue(CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), enabled);
887     return S_OK;
888 }
889 
shouldPrintBackgrounds(BOOL * enabled)890 HRESULT STDMETHODCALLTYPE WebPreferences::shouldPrintBackgrounds(
891     /* [retval][out] */ BOOL* enabled)
892 {
893     *enabled = boolValueForKey(CFSTR(WebKitShouldPrintBackgroundsPreferenceKey));
894     return S_OK;
895 }
896 
setPrivateBrowsingEnabled(BOOL enabled)897 HRESULT STDMETHODCALLTYPE WebPreferences::setPrivateBrowsingEnabled(
898     /* [in] */ BOOL enabled)
899 {
900     setBoolValue(CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), enabled);
901     return S_OK;
902 }
903 
privateBrowsingEnabled(BOOL * enabled)904 HRESULT STDMETHODCALLTYPE WebPreferences::privateBrowsingEnabled(
905     /* [retval][out] */ BOOL* enabled)
906 {
907     *enabled = boolValueForKey(CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey));
908     return S_OK;
909 }
910 
setTabsToLinks(BOOL enabled)911 HRESULT STDMETHODCALLTYPE WebPreferences::setTabsToLinks(
912     /* [in] */ BOOL enabled)
913 {
914     setBoolValue(CFSTR(WebKitTabToLinksPreferenceKey), enabled);
915     return S_OK;
916 }
917 
tabsToLinks(BOOL * enabled)918 HRESULT STDMETHODCALLTYPE WebPreferences::tabsToLinks(
919     /* [retval][out] */ BOOL* enabled)
920 {
921     *enabled = boolValueForKey(CFSTR(WebKitTabToLinksPreferenceKey));
922     return S_OK;
923 }
924 
setUsesPageCache(BOOL usesPageCache)925 HRESULT STDMETHODCALLTYPE WebPreferences::setUsesPageCache(
926         /* [in] */ BOOL usesPageCache)
927 {
928     setBoolValue(CFSTR(WebKitUsesPageCachePreferenceKey), usesPageCache);
929     return S_OK;
930 }
931 
usesPageCache(BOOL * usesPageCache)932 HRESULT STDMETHODCALLTYPE WebPreferences::usesPageCache(
933     /* [retval][out] */ BOOL* usesPageCache)
934 {
935     *usesPageCache = boolValueForKey(CFSTR(WebKitUsesPageCachePreferenceKey));
936     return S_OK;
937 }
938 
textAreasAreResizable(BOOL * enabled)939 HRESULT STDMETHODCALLTYPE WebPreferences::textAreasAreResizable(
940     /* [retval][out] */ BOOL* enabled)
941 {
942     *enabled = boolValueForKey(CFSTR(WebKitTextAreasAreResizablePreferenceKey));
943     return S_OK;
944 }
945 
setTextAreasAreResizable(BOOL enabled)946 HRESULT STDMETHODCALLTYPE WebPreferences::setTextAreasAreResizable(
947     /* [in] */ BOOL enabled)
948 {
949     setBoolValue(CFSTR(WebKitTextAreasAreResizablePreferenceKey), enabled);
950     return S_OK;
951 }
952 
historyItemLimit(int * limit)953 HRESULT WebPreferences::historyItemLimit(int* limit)
954 {
955     *limit = integerValueForKey(CFSTR(WebKitHistoryItemLimitKey));
956     return S_OK;
957 }
958 
setHistoryItemLimit(int limit)959 HRESULT WebPreferences::setHistoryItemLimit(int limit)
960 {
961     setIntegerValue(CFSTR(WebKitHistoryItemLimitKey), limit);
962     return S_OK;
963 }
964 
historyAgeInDaysLimit(int * limit)965 HRESULT WebPreferences::historyAgeInDaysLimit(int* limit)
966 {
967     *limit = integerValueForKey(CFSTR(WebKitHistoryAgeInDaysLimitKey));
968     return S_OK;
969 }
970 
setHistoryAgeInDaysLimit(int limit)971 HRESULT WebPreferences::setHistoryAgeInDaysLimit(int limit)
972 {
973     setIntegerValue(CFSTR(WebKitHistoryAgeInDaysLimitKey), limit);
974     return S_OK;
975 }
976 
unused1()977 HRESULT WebPreferences::unused1()
978 {
979     ASSERT_NOT_REACHED();
980     return E_FAIL;
981 }
982 
unused2()983 HRESULT WebPreferences::unused2()
984 {
985     ASSERT_NOT_REACHED();
986     return E_FAIL;
987 }
988 
iconDatabaseLocation(BSTR * location)989 HRESULT WebPreferences::iconDatabaseLocation(
990     /* [out] */ BSTR* location)
991 {
992     *location = stringValueForKey(CFSTR(WebKitIconDatabaseLocationKey));
993     return (*location) ? S_OK : E_FAIL;
994 }
995 
setIconDatabaseLocation(BSTR location)996 HRESULT WebPreferences::setIconDatabaseLocation(
997     /* [in] */ BSTR location)
998 {
999     setStringValue(CFSTR(WebKitIconDatabaseLocationKey), location);
1000     return S_OK;
1001 }
1002 
iconDatabaseEnabled(BOOL * enabled)1003 HRESULT WebPreferences::iconDatabaseEnabled(BOOL* enabled)//location)
1004 {
1005     *enabled = boolValueForKey(CFSTR(WebKitIconDatabaseEnabledPreferenceKey));
1006     return S_OK;
1007 }
1008 
setIconDatabaseEnabled(BOOL enabled)1009 HRESULT WebPreferences::setIconDatabaseEnabled(BOOL enabled )//location)
1010 {
1011     setBoolValue(CFSTR(WebKitIconDatabaseEnabledPreferenceKey), enabled);
1012     return S_OK;
1013 }
1014 
fontSmoothing(FontSmoothingType * smoothingType)1015 HRESULT STDMETHODCALLTYPE WebPreferences::fontSmoothing(
1016     /* [retval][out] */ FontSmoothingType* smoothingType)
1017 {
1018     *smoothingType = (FontSmoothingType) integerValueForKey(CFSTR(WebKitFontSmoothingTypePreferenceKey));
1019     return S_OK;
1020 }
1021 
setFontSmoothing(FontSmoothingType smoothingType)1022 HRESULT STDMETHODCALLTYPE WebPreferences::setFontSmoothing(
1023     /* [in] */ FontSmoothingType smoothingType)
1024 {
1025     setIntegerValue(CFSTR(WebKitFontSmoothingTypePreferenceKey), smoothingType);
1026     if (smoothingType == FontSmoothingTypeWindows)
1027         smoothingType = FontSmoothingTypeMedium;
1028 #if PLATFORM(CG)
1029     wkSetFontSmoothingLevel((int)smoothingType);
1030 #endif
1031     return S_OK;
1032 }
1033 
fontSmoothingContrast(float * contrast)1034 HRESULT STDMETHODCALLTYPE WebPreferences::fontSmoothingContrast(
1035     /* [retval][out] */ float* contrast)
1036 {
1037     *contrast = floatValueForKey(CFSTR(WebKitFontSmoothingContrastPreferenceKey));
1038     return S_OK;
1039 }
1040 
setFontSmoothingContrast(float contrast)1041 HRESULT STDMETHODCALLTYPE WebPreferences::setFontSmoothingContrast(
1042     /* [in] */ float contrast)
1043 {
1044     setFloatValue(CFSTR(WebKitFontSmoothingContrastPreferenceKey), contrast);
1045 #if PLATFORM(CG)
1046     wkSetFontSmoothingContrast(contrast);
1047 #endif
1048     return S_OK;
1049 }
1050 
editableLinkBehavior(WebKitEditableLinkBehavior * editableLinkBehavior)1051 HRESULT STDMETHODCALLTYPE WebPreferences::editableLinkBehavior(
1052     /* [out, retval] */ WebKitEditableLinkBehavior* editableLinkBehavior)
1053 {
1054     WebKitEditableLinkBehavior value = (WebKitEditableLinkBehavior) integerValueForKey(CFSTR(WebKitEditableLinkBehaviorPreferenceKey));
1055     switch (value) {
1056         case WebKitEditableLinkDefaultBehavior:
1057         case WebKitEditableLinkAlwaysLive:
1058         case WebKitEditableLinkOnlyLiveWithShiftKey:
1059         case WebKitEditableLinkLiveWhenNotFocused:
1060         case WebKitEditableLinkNeverLive:
1061             *editableLinkBehavior = value;
1062             break;
1063         default: // ensure that a valid result is returned
1064             *editableLinkBehavior = WebKitEditableLinkDefaultBehavior;
1065             break;
1066     }
1067     return S_OK;
1068 }
1069 
setEditableLinkBehavior(WebKitEditableLinkBehavior behavior)1070 HRESULT STDMETHODCALLTYPE WebPreferences::setEditableLinkBehavior(
1071     /* [in] */ WebKitEditableLinkBehavior behavior)
1072 {
1073     setIntegerValue(CFSTR(WebKitEditableLinkBehaviorPreferenceKey), behavior);
1074     return S_OK;
1075 }
1076 
cookieStorageAcceptPolicy(WebKitCookieStorageAcceptPolicy * acceptPolicy)1077 HRESULT STDMETHODCALLTYPE WebPreferences::cookieStorageAcceptPolicy(
1078         /* [retval][out] */ WebKitCookieStorageAcceptPolicy *acceptPolicy )
1079 {
1080     if (!acceptPolicy)
1081         return E_POINTER;
1082 
1083     *acceptPolicy = (WebKitCookieStorageAcceptPolicy)integerValueForKey(CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey));
1084     return S_OK;
1085 }
1086 
setCookieStorageAcceptPolicy(WebKitCookieStorageAcceptPolicy acceptPolicy)1087 HRESULT STDMETHODCALLTYPE WebPreferences::setCookieStorageAcceptPolicy(
1088         /* [in] */ WebKitCookieStorageAcceptPolicy acceptPolicy)
1089 {
1090     setIntegerValue(CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), acceptPolicy);
1091     return S_OK;
1092 }
1093 
1094 
continuousSpellCheckingEnabled(BOOL * enabled)1095 HRESULT WebPreferences::continuousSpellCheckingEnabled(BOOL* enabled)
1096 {
1097     *enabled = boolValueForKey(CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey));
1098     return S_OK;
1099 }
1100 
setContinuousSpellCheckingEnabled(BOOL enabled)1101 HRESULT WebPreferences::setContinuousSpellCheckingEnabled(BOOL enabled)
1102 {
1103     setBoolValue(CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), enabled);
1104     return S_OK;
1105 }
1106 
grammarCheckingEnabled(BOOL * enabled)1107 HRESULT WebPreferences::grammarCheckingEnabled(BOOL* enabled)
1108 {
1109     *enabled = boolValueForKey(CFSTR(WebGrammarCheckingEnabledPreferenceKey));
1110     return S_OK;
1111 }
1112 
setGrammarCheckingEnabled(BOOL enabled)1113 HRESULT WebPreferences::setGrammarCheckingEnabled(BOOL enabled)
1114 {
1115     setBoolValue(CFSTR(WebGrammarCheckingEnabledPreferenceKey), enabled);
1116     return S_OK;
1117 }
1118 
allowContinuousSpellChecking(BOOL * enabled)1119 HRESULT WebPreferences::allowContinuousSpellChecking(BOOL* enabled)
1120 {
1121     *enabled = boolValueForKey(CFSTR(AllowContinuousSpellCheckingPreferenceKey));
1122     return S_OK;
1123 }
1124 
setAllowContinuousSpellChecking(BOOL enabled)1125 HRESULT WebPreferences::setAllowContinuousSpellChecking(BOOL enabled)
1126 {
1127     setBoolValue(CFSTR(AllowContinuousSpellCheckingPreferenceKey), enabled);
1128     return S_OK;
1129 }
1130 
isDOMPasteAllowed(BOOL * enabled)1131 HRESULT WebPreferences::isDOMPasteAllowed(BOOL* enabled)
1132 {
1133     *enabled = boolValueForKey(CFSTR(WebKitDOMPasteAllowedPreferenceKey));
1134     return S_OK;
1135 }
1136 
setDOMPasteAllowed(BOOL enabled)1137 HRESULT WebPreferences::setDOMPasteAllowed(BOOL enabled)
1138 {
1139     setBoolValue(CFSTR(WebKitDOMPasteAllowedPreferenceKey), enabled);
1140     return S_OK;
1141 }
1142 
cacheModel(WebCacheModel * cacheModel)1143 HRESULT WebPreferences::cacheModel(WebCacheModel* cacheModel)
1144 {
1145     if (!cacheModel)
1146         return E_POINTER;
1147 
1148     *cacheModel = (WebCacheModel)integerValueForKey(CFSTR(WebKitCacheModelPreferenceKey));
1149     return S_OK;
1150 }
1151 
setCacheModel(WebCacheModel cacheModel)1152 HRESULT WebPreferences::setCacheModel(WebCacheModel cacheModel)
1153 {
1154     setIntegerValue(CFSTR(WebKitCacheModelPreferenceKey), cacheModel);
1155     return S_OK;
1156 }
1157 
setShouldPaintCustomScrollbars(BOOL shouldPaint)1158 HRESULT WebPreferences::setShouldPaintCustomScrollbars(BOOL shouldPaint)
1159 {
1160     setBoolValue(CFSTR(WebKitPaintCustomScrollbarsPreferenceKey), shouldPaint);
1161     return S_OK;
1162 }
1163 
shouldPaintCustomScrollbars(BOOL * shouldPaint)1164 HRESULT WebPreferences::shouldPaintCustomScrollbars(BOOL* shouldPaint)
1165 {
1166     *shouldPaint = boolValueForKey(CFSTR(WebKitPaintCustomScrollbarsPreferenceKey));
1167     return S_OK;
1168 }
1169 
shouldPaintNativeControls(BOOL * shouldPaint)1170 HRESULT WebPreferences::shouldPaintNativeControls(BOOL* shouldPaint)
1171 {
1172     *shouldPaint = boolValueForKey(CFSTR(WebKitPaintNativeControlsPreferenceKey));
1173     return S_OK;
1174 }
1175 
setShouldPaintNativeControls(BOOL shouldPaint)1176 HRESULT WebPreferences::setShouldPaintNativeControls(BOOL shouldPaint)
1177 {
1178     setBoolValue(CFSTR(WebKitPaintNativeControlsPreferenceKey), shouldPaint);
1179     return S_OK;
1180 }
1181 
setDeveloperExtrasEnabled(BOOL enabled)1182 HRESULT WebPreferences::setDeveloperExtrasEnabled(BOOL enabled)
1183 {
1184     setBoolValue(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey), enabled);
1185     return S_OK;
1186 }
1187 
developerExtrasEnabled(BOOL * enabled)1188 HRESULT WebPreferences::developerExtrasEnabled(BOOL* enabled)
1189 {
1190     if (!enabled)
1191         return E_POINTER;
1192 
1193     *enabled = boolValueForKey(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey));
1194     return S_OK;
1195 }
1196 
developerExtrasDisabledByOverride()1197 bool WebPreferences::developerExtrasDisabledByOverride()
1198 {
1199     return !!boolValueForKey(CFSTR(DisableWebKitDeveloperExtrasPreferenceKey));
1200 }
1201 
setAutomaticallyDetectsCacheModel(BOOL automaticallyDetectsCacheModel)1202 HRESULT WebPreferences::setAutomaticallyDetectsCacheModel(BOOL automaticallyDetectsCacheModel)
1203 {
1204     m_automaticallyDetectsCacheModel = !!automaticallyDetectsCacheModel;
1205     return S_OK;
1206 }
1207 
automaticallyDetectsCacheModel(BOOL * automaticallyDetectsCacheModel)1208 HRESULT WebPreferences::automaticallyDetectsCacheModel(BOOL* automaticallyDetectsCacheModel)
1209 {
1210     if (!automaticallyDetectsCacheModel)
1211         return E_POINTER;
1212 
1213     *automaticallyDetectsCacheModel = m_automaticallyDetectsCacheModel;
1214     return S_OK;
1215 }
1216 
setAuthorAndUserStylesEnabled(BOOL enabled)1217 HRESULT STDMETHODCALLTYPE WebPreferences::setAuthorAndUserStylesEnabled(BOOL enabled)
1218 {
1219     setBoolValue(CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey), enabled);
1220     return S_OK;
1221 }
1222 
authorAndUserStylesEnabled(BOOL * enabled)1223 HRESULT STDMETHODCALLTYPE WebPreferences::authorAndUserStylesEnabled(BOOL* enabled)
1224 {
1225     if (!enabled)
1226         return E_POINTER;
1227 
1228     *enabled = boolValueForKey(CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey));
1229     return S_OK;
1230 }
1231 
inApplicationChromeMode(BOOL * enabled)1232 HRESULT WebPreferences::inApplicationChromeMode(BOOL* enabled)
1233 {
1234     *enabled = boolValueForKey(CFSTR(WebKitApplicationChromeModePreferenceKey));
1235     return S_OK;
1236 }
1237 
setApplicationChromeMode(BOOL enabled)1238 HRESULT WebPreferences::setApplicationChromeMode(BOOL enabled)
1239 {
1240     setBoolValue(CFSTR(WebKitApplicationChromeModePreferenceKey), enabled);
1241     return S_OK;
1242 }
1243 
setOfflineWebApplicationCacheEnabled(BOOL enabled)1244 HRESULT STDMETHODCALLTYPE WebPreferences::setOfflineWebApplicationCacheEnabled(BOOL enabled)
1245 {
1246     setBoolValue(CFSTR(WebKitOfflineWebApplicationCacheEnabledPreferenceKey), enabled);
1247     return S_OK;
1248 }
1249 
offlineWebApplicationCacheEnabled(BOOL * enabled)1250 HRESULT STDMETHODCALLTYPE WebPreferences::offlineWebApplicationCacheEnabled(BOOL* enabled)
1251 {
1252     *enabled = boolValueForKey(CFSTR(WebKitOfflineWebApplicationCacheEnabledPreferenceKey));
1253     return S_OK;
1254 }
1255 
setDatabasesEnabled(BOOL enabled)1256 HRESULT STDMETHODCALLTYPE WebPreferences::setDatabasesEnabled(BOOL enabled)
1257 {
1258     setBoolValue(CFSTR(WebKitDatabasesEnabledPreferenceKey), enabled);
1259     return S_OK;
1260 }
1261 
databasesEnabled(BOOL * enabled)1262 HRESULT STDMETHODCALLTYPE WebPreferences::databasesEnabled(BOOL* enabled)
1263 {
1264     *enabled = boolValueForKey(CFSTR(WebKitDatabasesEnabledPreferenceKey));
1265     return S_OK;
1266 }
1267 
setLocalStorageEnabled(BOOL enabled)1268 HRESULT STDMETHODCALLTYPE WebPreferences::setLocalStorageEnabled(BOOL enabled)
1269 {
1270     setBoolValue(CFSTR(WebKitLocalStorageEnabledPreferenceKey), enabled);
1271     return S_OK;
1272 }
1273 
localStorageEnabled(BOOL * enabled)1274 HRESULT STDMETHODCALLTYPE WebPreferences::localStorageEnabled(BOOL* enabled)
1275 {
1276     *enabled = boolValueForKey(CFSTR(WebKitLocalStorageEnabledPreferenceKey));
1277     return S_OK;
1278 }
1279 
localStorageDatabasePath(BSTR * location)1280 HRESULT STDMETHODCALLTYPE WebPreferences::localStorageDatabasePath(BSTR* location)
1281 {
1282     *location = stringValueForKey(CFSTR(WebKitLocalStorageDatabasePathPreferenceKey));
1283     return (*location) ? S_OK : E_FAIL;
1284 }
1285 
setLocalStorageDatabasePath(BSTR location)1286 HRESULT STDMETHODCALLTYPE WebPreferences::setLocalStorageDatabasePath(BSTR location)
1287 {
1288     setStringValue(CFSTR(WebKitLocalStorageDatabasePathPreferenceKey), location);
1289     return S_OK;
1290 }
1291 
setZoomsTextOnly(BOOL zoomsTextOnly)1292 HRESULT WebPreferences::setZoomsTextOnly(BOOL zoomsTextOnly)
1293 {
1294     setBoolValue(CFSTR(WebKitZoomsTextOnlyPreferenceKey), zoomsTextOnly);
1295     return S_OK;
1296 }
1297 
zoomsTextOnly(BOOL * zoomsTextOnly)1298 HRESULT WebPreferences::zoomsTextOnly(BOOL* zoomsTextOnly)
1299 {
1300     *zoomsTextOnly = boolValueForKey(CFSTR(WebKitZoomsTextOnlyPreferenceKey));
1301     return S_OK;
1302 }
1303 
willAddToWebView()1304 void WebPreferences::willAddToWebView()
1305 {
1306     ++m_numWebViews;
1307 }
1308 
didRemoveFromWebView()1309 void WebPreferences::didRemoveFromWebView()
1310 {
1311     ASSERT(m_numWebViews);
1312     if (--m_numWebViews == 0) {
1313         IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
1314         nc->postNotificationName(webPreferencesRemovedNotification(), static_cast<IWebPreferences*>(this), 0);
1315     }
1316 }
1317