1f407032b85a9198d8129c18b7e007c0a8f8641d
[WebKit-https.git] / Source / WebKitLegacy / win / WebPreferences.cpp
1 /*
2  * Copyright (C) 2006-2011, 2014-2015 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 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 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 "WebKit.h"
27 #include "WebKitDLL.h"
28 #include "WebPreferences.h"
29
30 #include "WebNotificationCenter.h"
31 #include "WebPreferenceKeysPrivate.h"
32
33 #if USE(CG)
34 #include <CoreGraphics/CoreGraphics.h>
35 #include <WebCore/CACFLayerTreeHost.h>
36 #include <WebKitSystemInterface/WebKitSystemInterface.h>
37 #endif
38
39 #include <CoreFoundation/CoreFoundation.h>
40 #include <WebCore/COMPtr.h>
41 #include <WebCore/FileSystem.h>
42 #include <WebCore/FontCascade.h>
43 #include <WebCore/LocalizedStrings.h>
44 #include <WebCore/NetworkStorageSession.h>
45 #include <WebCore/PlatformCookieJar.h>
46 #include <limits>
47 #include <shlobj.h>
48 #include <wchar.h>
49 #include <wtf/HashMap.h>
50 #include <wtf/NeverDestroyed.h>
51 #include <wtf/StdLibExtras.h>
52 #include <wtf/text/CString.h>
53 #include <wtf/text/StringHash.h>
54 #include <wtf/text/WTFString.h>
55
56 using namespace WebCore;
57 using std::numeric_limits;
58
59 static const String& oldPreferencesPath()
60 {
61     static String path = FileSystem::pathByAppendingComponent(FileSystem::roamingUserSpecificStorageDirectory(), "WebKitPreferences.plist");
62     return path;
63 }
64
65 template<typename NumberType> struct CFNumberTraits { static const unsigned Type; };
66 template<> struct CFNumberTraits<int> { static const unsigned Type = kCFNumberSInt32Type; };
67 template<> struct CFNumberTraits<LONGLONG> { static const unsigned Type = kCFNumberLongLongType; };
68 template<> struct CFNumberTraits<float> { static const unsigned Type = kCFNumberFloat32Type; };
69
70 template<typename NumberType>
71 static NumberType numberValueForPreferencesValue(CFPropertyListRef value)
72 {
73     if (!value)
74         return 0;
75
76     CFTypeID cfType = CFGetTypeID(value);
77     if (cfType == CFStringGetTypeID())
78         return static_cast<NumberType>(CFStringGetIntValue(static_cast<CFStringRef>(value)));
79     else if (cfType == CFBooleanGetTypeID()) {
80         Boolean boolVal = CFBooleanGetValue(static_cast<CFBooleanRef>(value));
81         return boolVal ? 1 : 0;
82     } else if (cfType == CFNumberGetTypeID()) {
83         NumberType val = 0;
84         CFNumberGetValue(static_cast<CFNumberRef>(value), CFNumberTraits<NumberType>::Type, &val);
85         return val;
86     }
87
88     return 0;
89 }
90
91 template<typename NumberType>
92 static RetainPtr<CFNumberRef> cfNumber(NumberType value)
93 {
94     return adoptCF(CFNumberCreate(0, CFNumberTraits<NumberType>::Type, &value));
95 }
96
97 static bool booleanValueForPreferencesValue(CFPropertyListRef value)
98 {
99     return numberValueForPreferencesValue<int>(value);
100 }
101
102 // WebPreferences ----------------------------------------------------------------
103
104 static CFDictionaryRef defaultSettings;
105
106 RetainPtr<CFStringRef> WebPreferences::m_applicationId = kCFPreferencesCurrentApplication;
107
108 static HashMap<WTF::String, COMPtr<WebPreferences>>& webPreferencesInstances()
109 {
110     static NeverDestroyed<HashMap<WTF::String, COMPtr<WebPreferences>>> webPreferencesInstances;
111     return webPreferencesInstances;
112 }
113
114 WebPreferences* WebPreferences::sharedStandardPreferences()
115 {
116     static WebPreferences* standardPreferences;
117     if (!standardPreferences) {
118         standardPreferences = WebPreferences::createInstance();
119         standardPreferences->setAutosaves(TRUE);
120         standardPreferences->load();
121     }
122
123     return standardPreferences;
124 }
125
126 WebPreferences::WebPreferences()
127 {
128     gClassCount++;
129     gClassNameCount().add("WebPreferences");
130 }
131
132 WebPreferences::~WebPreferences()
133 {
134     gClassCount--;
135     gClassNameCount().remove("WebPreferences");
136 }
137
138 WebPreferences* WebPreferences::createInstance()
139 {
140     WebPreferences* instance = new WebPreferences();
141     instance->AddRef();
142     return instance;
143 }
144
145 HRESULT WebPreferences::postPreferencesChangesNotification()
146 {
147     IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
148     HRESULT hr = nc->postNotificationName(webPreferencesChangedNotification(), static_cast<IWebPreferences*>(this), 0);
149     if (FAILED(hr))
150         return hr;
151
152     return S_OK;
153 }
154
155 WebPreferences* WebPreferences::getInstanceForIdentifier(BSTR identifier)
156 {
157     if (!identifier)
158         return sharedStandardPreferences();
159
160     WTF::String identifierString(identifier, SysStringLen(identifier));
161     if (identifierString.isEmpty())
162         return sharedStandardPreferences();
163
164     return webPreferencesInstances().get(identifierString);
165 }
166
167 void WebPreferences::setInstance(WebPreferences* instance, BSTR identifier)
168 {
169     if (!identifier || !instance)
170         return;
171     WTF::String identifierString(identifier, SysStringLen(identifier));
172     if (identifierString.isEmpty())
173         return;
174     webPreferencesInstances().add(identifierString, instance);
175 }
176
177 void WebPreferences::removeReferenceForIdentifier(BSTR identifier)
178 {
179     if (!identifier || webPreferencesInstances().isEmpty())
180         return;
181
182     WTF::String identifierString(identifier, SysStringLen(identifier));
183     if (identifierString.isEmpty())
184         return;
185     WebPreferences* webPreference = webPreferencesInstances().get(identifierString);
186     if (webPreference && webPreference->m_refCount == 1)
187         webPreferencesInstances().remove(identifierString);
188 }
189
190 CFStringRef WebPreferences::applicationId()
191 {
192     return m_applicationId.get();
193 }
194
195 void WebPreferences::initializeDefaultSettings()
196 {
197     if (defaultSettings)
198         return;
199
200     CFMutableDictionaryRef defaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
201
202     CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman"));
203     CFDictionaryAddValue(defaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New"));
204     CFDictionaryAddValue(defaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman"));
205     CFDictionaryAddValue(defaults, CFSTR(WebKitSansSerifFontPreferenceKey), CFSTR("Arial"));
206     CFDictionaryAddValue(defaults, CFSTR(WebKitCursiveFontPreferenceKey), CFSTR("Comic Sans MS"));
207     CFDictionaryAddValue(defaults, CFSTR(WebKitFantasyFontPreferenceKey), CFSTR("Comic Sans MS"));
208     CFDictionaryAddValue(defaults, CFSTR(WebKitPictographFontPreferenceKey), CFSTR("Segoe UI Symbol"));
209     CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumFontSizePreferenceKey), CFSTR("0"));
210     CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), CFSTR("9"));
211     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFontSizePreferenceKey), CFSTR("16"));
212     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFixedFontSizePreferenceKey), CFSTR("13"));
213
214     String defaultDefaultEncoding(WEB_UI_STRING("ISO-8859-1", "The default, default character encoding on Windows"));
215     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), defaultDefaultEncoding.createCFString().get());
216
217     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), kCFBooleanFalse);
218     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetLocationPreferenceKey), CFSTR(""));
219     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), kCFBooleanFalse);
220     CFDictionaryAddValue(defaults, CFSTR(WebKitTextAreasAreResizablePreferenceKey), kCFBooleanFalse);
221     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaEnabledPreferenceKey), kCFBooleanTrue);
222     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptEnabledPreferenceKey), kCFBooleanTrue);
223     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptRuntimeFlagsPreferenceKey), CFSTR("0"));
224     CFDictionaryAddValue(defaults, CFSTR(WebKitWebSecurityEnabledPreferenceKey), kCFBooleanTrue);
225     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowUniversalAccessFromFileURLsPreferenceKey), kCFBooleanFalse);
226     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowFileAccessFromFileURLsPreferenceKey), kCFBooleanTrue);
227     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanAccessClipboardPreferenceKey), kCFBooleanFalse);
228     CFDictionaryAddValue(defaults, CFSTR(WebKitXSSAuditorEnabledPreferenceKey), kCFBooleanTrue);
229     CFDictionaryAddValue(defaults, CFSTR(WebKitFrameFlatteningEnabledPreferenceKey), kCFBooleanFalse);
230     CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), kCFBooleanTrue);
231     CFDictionaryAddValue(defaults, CFSTR(WebKitPluginsEnabledPreferenceKey), kCFBooleanTrue);
232     CFDictionaryAddValue(defaults, CFSTR(WebKitCSSRegionsEnabledPreferenceKey), kCFBooleanTrue);
233     CFDictionaryAddValue(defaults, CFSTR(WebKitDatabasesEnabledPreferenceKey), kCFBooleanTrue);
234     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageEnabledPreferenceKey), kCFBooleanTrue);
235     CFDictionaryAddValue(defaults, CFSTR(WebKitExperimentalNotificationsEnabledPreferenceKey), kCFBooleanFalse);
236     CFDictionaryAddValue(defaults, CFSTR(WebKitZoomsTextOnlyPreferenceKey), kCFBooleanTrue);
237     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImagesPreferenceKey), kCFBooleanTrue);
238     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), kCFBooleanTrue);
239     CFDictionaryAddValue(defaults, CFSTR(WebKitDisplayImagesKey), kCFBooleanTrue);
240     CFDictionaryAddValue(defaults, CFSTR(WebKitLoadSiteIconsKey), kCFBooleanFalse);
241     CFDictionaryAddValue(defaults, CFSTR(WebKitBackForwardCacheExpirationIntervalKey), CFSTR("1800"));
242     CFDictionaryAddValue(defaults, CFSTR(WebKitTabToLinksPreferenceKey), kCFBooleanFalse);
243     CFDictionaryAddValue(defaults, CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), kCFBooleanFalse);
244     CFDictionaryAddValue(defaults, CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey), kCFBooleanFalse);
245     CFDictionaryAddValue(defaults, CFSTR(WebKitShowsURLsInToolTipsPreferenceKey), kCFBooleanFalse);
246     CFDictionaryAddValue(defaults, CFSTR(WebKitShowsToolTipOverTruncatedTextPreferenceKey), kCFBooleanFalse);
247     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFDisplayModePreferenceKey), CFSTR("1"));
248     CFDictionaryAddValue(defaults, CFSTR(WebKitPDFScaleFactorPreferenceKey), CFSTR("0"));
249     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplaySubtitlesPreferenceKey), kCFBooleanFalse);
250     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplayCaptionsPreferenceKey), kCFBooleanFalse);
251     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldDisplayTextDescriptionsPreferenceKey), kCFBooleanFalse);
252     CFDictionaryAddValue(defaults, CFSTR(WebKitCrossOriginOptionsSupportEnabledPreferenceKey), kCFBooleanFalse);
253
254     RetainPtr<CFStringRef> linkBehaviorStringRef = adoptCF(CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior));
255     CFDictionaryAddValue(defaults, CFSTR(WebKitEditableLinkBehaviorPreferenceKey), linkBehaviorStringRef.get());
256
257     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryItemLimitKey), CFSTR("1000"));
258     CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryAgeInDaysLimitKey), CFSTR("7"));
259     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseLocationKey), CFSTR(""));
260     CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseEnabledPreferenceKey), kCFBooleanTrue);
261     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingTypePreferenceKey), CFSTR("2"));
262     CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmoothingContrastPreferenceKey), CFSTR("2"));
263     CFDictionaryAddValue(defaults, CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), CFSTR("2"));
264     CFDictionaryAddValue(defaults, CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), kCFBooleanFalse);
265     CFDictionaryAddValue(defaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse);
266     CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
267     CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
268     CFDictionaryAddValue(defaults, CFSTR(WebKitLocalStorageDatabasePathPreferenceKey), CFSTR(""));
269
270     RetainPtr<CFStringRef> cacheModelRef = adoptCF(CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebCacheModelDocumentViewer));
271     CFDictionaryAddValue(defaults, CFSTR(WebKitCacheModelPreferenceKey), cacheModelRef.get());
272
273     CFDictionaryAddValue(defaults, CFSTR(WebKitAuthorAndUserStylesEnabledPreferenceKey), kCFBooleanTrue);
274
275     CFDictionaryAddValue(defaults, CFSTR(WebKitOfflineWebApplicationCacheEnabledPreferenceKey), kCFBooleanFalse);
276
277     CFDictionaryAddValue(defaults, CFSTR(WebKitPaintNativeControlsPreferenceKey), kCFBooleanTrue);
278
279     CFDictionaryAddValue(defaults, CFSTR(WebKitUseHighResolutionTimersPreferenceKey), kCFBooleanTrue);
280
281 #if USE(CG)
282     CFDictionaryAddValue(defaults, CFSTR(WebKitAcceleratedCompositingEnabledPreferenceKey), kCFBooleanTrue);
283 #else
284     CFDictionaryAddValue(defaults, CFSTR(WebKitAcceleratedCompositingEnabledPreferenceKey), kCFBooleanFalse);
285 #endif
286
287     CFDictionaryAddValue(defaults, CFSTR(WebKitShowDebugBordersPreferenceKey), kCFBooleanFalse);
288
289     CFDictionaryAddValue(defaults, CFSTR(WebKitSpatialNavigationEnabledPreferenceKey), kCFBooleanFalse);
290
291     CFDictionaryAddValue(defaults, CFSTR(WebKitDNSPrefetchingEnabledPreferenceKey), kCFBooleanFalse);
292
293     CFDictionaryAddValue(defaults, CFSTR(WebKitHyperlinkAuditingEnabledPreferenceKey), kCFBooleanTrue);
294
295     CFDictionaryAddValue(defaults, CFSTR(WebKitMediaPlaybackRequiresUserGesturePreferenceKey), kCFBooleanFalse);
296     CFDictionaryAddValue(defaults, CFSTR(WebKitMediaPlaybackAllowsInlinePreferenceKey), kCFBooleanTrue);
297
298     CFDictionaryAddValue(defaults, CFSTR(WebKitRequestAnimationFrameEnabledPreferenceKey), kCFBooleanTrue);
299
300     CFDictionaryAddValue(defaults, CFSTR(WebKitFullScreenEnabledPreferenceKey), kCFBooleanFalse);
301
302     CFDictionaryAddValue(defaults, CFSTR(WebKitRequestAnimationFrameEnabledPreferenceKey), kCFBooleanFalse);
303
304     CFDictionaryAddValue(defaults, CFSTR(WebKitAllowDisplayAndRunningOfInsecureContentPreferenceKey), kCFBooleanTrue);
305
306     CFDictionaryAddValue(defaults, CFSTR(WebKitFetchAPIEnabledPreferenceKey), kCFBooleanFalse);
307
308     CFDictionaryAddValue(defaults, CFSTR(WebKitShadowDOMEnabledPreferenceKey), kCFBooleanFalse);
309
310     CFDictionaryAddValue(defaults, CFSTR(WebKitCustomElementsEnabledPreferenceKey), kCFBooleanFalse);
311
312     CFDictionaryAddValue(defaults, CFSTR(WebKitWebAnimationsEnabledPreferenceKey), kCFBooleanFalse);
313
314     CFDictionaryAddValue(defaults, CFSTR(WebKitUserTimingEnabledPreferenceKey), kCFBooleanFalse);
315
316     CFDictionaryAddValue(defaults, CFSTR(WebKitResourceTimingEnabledPreferenceKey), kCFBooleanFalse);
317
318     CFDictionaryAddValue(defaults, CFSTR(WebKitLinkPreloadEnabledPreferenceKey), kCFBooleanFalse);
319
320     CFDictionaryAddValue(defaults, CFSTR(WebKitMediaPreloadingEnabledPreferenceKey), kCFBooleanFalse);
321
322     CFDictionaryAddValue(defaults, CFSTR(WebKitIsSecureContextAttributeEnabledPreferenceKey), kCFBooleanFalse);
323
324     CFDictionaryAddValue(defaults, CFSTR(WebKitDataTransferItemsEnabledPreferenceKey), kCFBooleanFalse);
325
326     CFDictionaryAddValue(defaults, CFSTR(WebKitInspectorAdditionsEnabledPreferenceKey), kCFBooleanFalse);
327
328     CFDictionaryAddValue(defaults, CFSTR(WebKitVisualViewportAPIEnabledPreferenceKey), kCFBooleanFalse);
329
330     defaultSettings = defaults;
331 }
332
333 RetainPtr<CFPropertyListRef> WebPreferences::valueForKey(CFStringRef key)
334 {
335     RetainPtr<CFPropertyListRef> value = CFDictionaryGetValue(m_privatePrefs.get(), key);
336     if (value)
337         return value;
338
339     value = adoptCF(CFPreferencesCopyAppValue(key, applicationId()));
340     if (value)
341         return value;
342
343     return CFDictionaryGetValue(defaultSettings, key);
344 }
345
346 void WebPreferences::setValueForKey(CFStringRef key, CFPropertyListRef value)
347 {
348     CFDictionarySetValue(m_privatePrefs.get(), key, value);
349     if (m_autoSaves) {
350         CFPreferencesSetAppValue(key, value, applicationId());
351         save();
352     }
353 }
354
355 void WebPreferences::setValueForKey(const char* key, CFPropertyListRef value)
356 {
357     RetainPtr<CFStringRef> cfKey = adoptCF(CFStringCreateWithCString(0, key, kCFStringEncodingASCII));
358     setValueForKey(cfKey.get(), value);
359 }
360
361 RetainPtr<CFPropertyListRef> WebPreferences::valueForKey(const char* key)
362 {
363     RetainPtr<CFStringRef> cfKey = adoptCF(CFStringCreateWithCString(0, key, kCFStringEncodingASCII));
364     return valueForKey(cfKey.get());
365 }
366
367 BSTR WebPreferences::stringValueForKey(const char* key)
368 {
369     RetainPtr<CFPropertyListRef> value = valueForKey(key);
370     
371     if (!value || (CFGetTypeID(value.get()) != CFStringGetTypeID()))
372         return 0;
373
374     CFStringRef str = static_cast<CFStringRef>(value.get());
375
376     CFIndex length = CFStringGetLength(str);
377     const UniChar* uniChars = CFStringGetCharactersPtr(str);
378     if (uniChars)
379         return SysAllocStringLen((LPCTSTR)uniChars, length);
380
381     BSTR bstr = SysAllocStringLen(0, length);
382     if (!bstr)
383         return 0;
384
385     if (!CFStringGetCString(str, (char*)bstr, (length+1)*sizeof(WCHAR), kCFStringEncodingUTF16)) {
386         SysFreeString(bstr);
387         return 0;
388     }
389         
390     bstr[length] = 0;
391     return bstr;
392 }
393
394 int WebPreferences::integerValueForKey(const char* key)
395 {
396     return numberValueForPreferencesValue<int>(valueForKey(key).get());
397 }
398
399 BOOL WebPreferences::boolValueForKey(const char* key)
400 {
401     return booleanValueForPreferencesValue(valueForKey(key).get());
402 }
403
404 float WebPreferences::floatValueForKey(const char* key)
405 {
406     return numberValueForPreferencesValue<float>(valueForKey(key).get());
407 }
408
409 LONGLONG WebPreferences::longlongValueForKey(const char* key)
410 {
411     return numberValueForPreferencesValue<LONGLONG>(valueForKey(key).get());
412 }
413
414 void WebPreferences::setStringValue(const char* key, BSTR value)
415 {
416     BString val;
417     val.adoptBSTR(stringValueForKey(key));
418     if (val && !wcscmp(val, value))
419         return;
420     
421     RetainPtr<CFStringRef> valueRef = adoptCF(CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(value), static_cast<CFIndex>(wcslen(value))));
422     setValueForKey(key, valueRef.get());
423
424     postPreferencesChangesNotification();
425 }
426
427 void WebPreferences::setIntegerValue(const char* key, int value)
428 {
429     if (integerValueForKey(key) == value)
430         return;
431
432     setValueForKey(key, cfNumber(value).get());
433
434     postPreferencesChangesNotification();
435 }
436
437 void WebPreferences::setFloatValue(const char* key, float value)
438 {
439     if (floatValueForKey(key) == value)
440         return;
441
442     setValueForKey(key, cfNumber(value).get());
443
444     postPreferencesChangesNotification();
445 }
446
447 void WebPreferences::setBoolValue(const char* key, BOOL value)
448 {
449     if (boolValueForKey(key) == value)
450         return;
451
452     setValueForKey(key, value ? kCFBooleanTrue : kCFBooleanFalse);
453
454     postPreferencesChangesNotification();
455 }
456
457 void WebPreferences::setLongLongValue(const char* key, LONGLONG value)
458 {
459     if (longlongValueForKey(key) == value)
460         return;
461
462     setValueForKey(key, cfNumber(value).get());
463
464     postPreferencesChangesNotification();
465 }
466
467 BSTR WebPreferences::webPreferencesChangedNotification()
468 {
469     static BSTR webPreferencesChangedNotification = SysAllocString(WebPreferencesChangedNotification);
470     return webPreferencesChangedNotification;
471 }
472
473 BSTR WebPreferences::webPreferencesRemovedNotification()
474 {
475     static BSTR webPreferencesRemovedNotification = SysAllocString(WebPreferencesRemovedNotification);
476     return webPreferencesRemovedNotification;
477 }
478
479 void WebPreferences::save()
480 {
481     CFPreferencesAppSynchronize(applicationId());
482 }
483
484 void WebPreferences::load()
485 {
486     initializeDefaultSettings();
487
488     m_privatePrefs = adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
489
490     migrateWebKitPreferencesToCFPreferences();
491 }
492
493 void WebPreferences::migrateWebKitPreferencesToCFPreferences()
494 {
495     if (boolValueForKey(WebKitDidMigrateWebKitPreferencesToCFPreferencesPreferenceKey))
496         return;
497     bool oldValue = m_autoSaves;
498     m_autoSaves = true;
499     setBoolValue(WebKitDidMigrateWebKitPreferencesToCFPreferencesPreferenceKey, TRUE);
500     m_autoSaves = oldValue;
501
502     WTF::CString path = oldPreferencesPath().utf8();
503
504     RetainPtr<CFURLRef> urlRef = adoptCF(CFURLCreateFromFileSystemRepresentation(0, reinterpret_cast<const UInt8*>(path.data()), path.length(), false));
505     if (!urlRef)
506         return;
507
508     RetainPtr<CFReadStreamRef> stream = adoptCF(CFReadStreamCreateWithFile(0, urlRef.get()));
509     if (!stream)
510         return;
511
512     if (!CFReadStreamOpen(stream.get()))
513         return;
514
515     CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0;
516     RetainPtr<CFPropertyListRef> plist = adoptCF(CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0));
517     CFReadStreamClose(stream.get());
518
519     if (!plist || CFGetTypeID(plist.get()) != CFDictionaryGetTypeID())
520         return;
521
522     copyWebKitPreferencesToCFPreferences(static_cast<CFDictionaryRef>(plist.get()));
523
524     FileSystem::deleteFile(oldPreferencesPath());
525 }
526
527 void WebPreferences::copyWebKitPreferencesToCFPreferences(CFDictionaryRef dict)
528 {
529     ASSERT_ARG(dict, dict);
530
531     int count = CFDictionaryGetCount(dict);
532     if (count <= 0)
533         return;
534
535     CFStringRef didRemoveDefaultsKey = CFSTR(WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey);
536     bool omitDefaults = !booleanValueForPreferencesValue(CFDictionaryGetValue(dict, didRemoveDefaultsKey));
537
538     Vector<CFTypeRef> keys(count);
539     Vector<CFTypeRef> values(count);
540     CFDictionaryGetKeysAndValues(dict, keys.data(), values.data());
541
542     for (int i = 0; i < count; ++i) {
543         if (!keys[i] || !values[i] || CFGetTypeID(keys[i]) != CFStringGetTypeID())
544             continue;
545
546         if (omitDefaults) {
547             CFTypeRef defaultValue = CFDictionaryGetValue(defaultSettings, keys[i]);
548             if (defaultValue && CFEqual(defaultValue, values[i]))
549                 continue;
550         }
551
552         setValueForKey(static_cast<CFStringRef>(keys[i]), values[i]);
553     }
554 }
555
556 // IUnknown -------------------------------------------------------------------
557
558 HRESULT WebPreferences::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
559 {
560     if (!ppvObject)
561         return E_POINTER;
562     *ppvObject = nullptr;
563     if (IsEqualGUID(riid, IID_IUnknown))
564         *ppvObject = static_cast<IWebPreferences*>(this);
565     else if (IsEqualGUID(riid, IID_IWebPreferences))
566         *ppvObject = static_cast<IWebPreferences*>(this);
567     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate))
568         *ppvObject = static_cast<IWebPreferencesPrivate*>(this);
569     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate2))
570         *ppvObject = static_cast<IWebPreferencesPrivate2*>(this);
571     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate3))
572         *ppvObject = static_cast<IWebPreferencesPrivate3*>(this);
573     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate4))
574         *ppvObject = static_cast<IWebPreferencesPrivate4*>(this);
575     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate5))
576         *ppvObject = static_cast<IWebPreferencesPrivate5*>(this);
577     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate6))
578         *ppvObject = static_cast<IWebPreferencesPrivate6*>(this);
579     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate7))
580         *ppvObject = static_cast<IWebPreferencesPrivate7*>(this);
581     else if (IsEqualGUID(riid, CLSID_WebPreferences))
582         *ppvObject = this;
583     else
584         return E_NOINTERFACE;
585
586     AddRef();
587     return S_OK;
588 }
589
590 ULONG WebPreferences::AddRef()
591 {
592     return ++m_refCount;
593 }
594
595 ULONG WebPreferences::Release()
596 {
597     ULONG newRef = --m_refCount;
598     if (!newRef)
599         delete(this);
600
601     return newRef;
602 }
603
604 // IWebPreferences ------------------------------------------------------------
605
606 HRESULT WebPreferences::standardPreferences(_COM_Outptr_opt_ IWebPreferences** standardPreferences)
607 {
608     if (!standardPreferences)
609         return E_POINTER;
610     *standardPreferences = sharedStandardPreferences();
611     (*standardPreferences)->AddRef();
612     return S_OK;
613 }
614
615 HRESULT WebPreferences::initWithIdentifier(_In_ BSTR anIdentifier, _COM_Outptr_opt_ IWebPreferences** preferences)
616 {
617     WebPreferences *instance = getInstanceForIdentifier(anIdentifier);
618     if (instance) {
619         *preferences = instance;
620         instance->AddRef();
621         return S_OK;
622     }
623
624     load();
625
626     *preferences = this;
627     AddRef();
628
629     if (anIdentifier) {
630         m_identifier = anIdentifier;
631         setInstance(this, m_identifier);
632     }
633
634     this->postPreferencesChangesNotification();
635
636     return S_OK;
637 }
638
639 HRESULT WebPreferences::identifier(__deref_opt_out BSTR* ident)
640 {
641     if (!ident)
642         return E_POINTER;
643     *ident = m_identifier ? SysAllocString(m_identifier) : nullptr;
644     return S_OK;
645 }
646
647 HRESULT WebPreferences::standardFontFamily(__deref_opt_out BSTR* family)
648 {
649     if (!family)
650         return E_POINTER;
651     *family = stringValueForKey(WebKitStandardFontPreferenceKey);
652     return (*family) ? S_OK : E_FAIL;
653 }
654
655 HRESULT WebPreferences::setStandardFontFamily(_In_ BSTR family)
656 {
657     setStringValue(WebKitStandardFontPreferenceKey, family);
658     return S_OK;
659 }
660
661 HRESULT WebPreferences::fixedFontFamily(__deref_opt_out BSTR* family)
662 {
663     if (!family)
664         return E_POINTER;
665     *family = stringValueForKey(WebKitFixedFontPreferenceKey);
666     return (*family) ? S_OK : E_FAIL;
667 }
668
669 HRESULT WebPreferences::setFixedFontFamily(_In_ BSTR family)
670 {
671     setStringValue(WebKitFixedFontPreferenceKey, family);
672     return S_OK;
673 }
674
675 HRESULT WebPreferences::serifFontFamily(__deref_opt_out BSTR* fontFamily)
676 {
677     if (!fontFamily)
678         return E_POINTER;
679     *fontFamily = stringValueForKey(WebKitSerifFontPreferenceKey);
680     return (*fontFamily) ? S_OK : E_FAIL;
681 }
682
683 HRESULT WebPreferences::setSerifFontFamily(_In_ BSTR family)
684 {
685     setStringValue(WebKitSerifFontPreferenceKey, family);
686     return S_OK;
687 }
688
689 HRESULT WebPreferences::sansSerifFontFamily(__deref_opt_out BSTR* family)
690 {
691     if (!family)
692         return E_POINTER;
693     *family = stringValueForKey(WebKitSansSerifFontPreferenceKey);
694     return (*family) ? S_OK : E_FAIL;
695 }
696
697 HRESULT WebPreferences::setSansSerifFontFamily(_In_ BSTR family)
698 {
699     setStringValue(WebKitSansSerifFontPreferenceKey, family);
700     return S_OK;
701 }
702
703 HRESULT WebPreferences::cursiveFontFamily(__deref_opt_out BSTR* family)
704 {
705     if (!family)
706         return E_POINTER;
707     *family = stringValueForKey(WebKitCursiveFontPreferenceKey);
708     return (*family) ? S_OK : E_FAIL;
709 }
710
711 HRESULT WebPreferences::setCursiveFontFamily(_In_ BSTR family)
712 {
713     setStringValue(WebKitCursiveFontPreferenceKey, family);
714     return S_OK;
715 }
716
717 HRESULT WebPreferences::fantasyFontFamily(__deref_opt_out BSTR* family)
718 {
719     if (!family)
720         return E_POINTER;
721     *family = stringValueForKey(WebKitFantasyFontPreferenceKey);
722     return (*family) ? S_OK : E_FAIL;
723 }
724
725 HRESULT WebPreferences::setFantasyFontFamily(_In_ BSTR family)
726 {
727     setStringValue(WebKitFantasyFontPreferenceKey, family);
728     return S_OK;
729 }
730
731 HRESULT WebPreferences::pictographFontFamily(__deref_opt_out BSTR* family)
732 {
733     if (!family)
734         return E_POINTER;
735     *family = stringValueForKey(WebKitPictographFontPreferenceKey);
736     return (*family) ? S_OK : E_FAIL;
737 }
738
739 HRESULT WebPreferences::setPictographFontFamily(_In_ BSTR family)
740 {
741     setStringValue(WebKitPictographFontPreferenceKey, family);
742     return S_OK;
743 }
744
745 HRESULT WebPreferences::defaultFontSize(_Out_  int* fontSize)
746 {
747     if (!fontSize)
748         return E_POINTER;
749     *fontSize = integerValueForKey(WebKitDefaultFontSizePreferenceKey);
750     return S_OK;
751 }
752
753 HRESULT WebPreferences::setDefaultFontSize(int fontSize)
754 {
755     setIntegerValue(WebKitDefaultFontSizePreferenceKey, fontSize);
756     return S_OK;
757 }
758
759 HRESULT WebPreferences::defaultFixedFontSize(_Out_ int* fontSize)
760 {
761     if (!fontSize)
762         return E_POINTER;
763     *fontSize = integerValueForKey(WebKitDefaultFixedFontSizePreferenceKey);
764     return S_OK;
765 }
766
767 HRESULT WebPreferences::setDefaultFixedFontSize(int fontSize)
768 {
769     setIntegerValue(WebKitDefaultFixedFontSizePreferenceKey, fontSize);
770     return S_OK;
771 }
772
773 HRESULT WebPreferences::minimumFontSize(_Out_ int* fontSize)
774 {
775     if (!fontSize)
776         return E_POINTER;
777     *fontSize = integerValueForKey(WebKitMinimumFontSizePreferenceKey);
778     return S_OK;
779 }
780
781 HRESULT WebPreferences::setMinimumFontSize(int fontSize)
782 {
783     setIntegerValue(WebKitMinimumFontSizePreferenceKey, fontSize);
784     return S_OK;
785 }
786
787 HRESULT WebPreferences::minimumLogicalFontSize(_Out_ int* fontSize)
788 {
789     if (!fontSize)
790         return E_POINTER;
791     *fontSize = integerValueForKey(WebKitMinimumLogicalFontSizePreferenceKey);
792     return S_OK;
793 }
794
795 HRESULT WebPreferences::setMinimumLogicalFontSize(int fontSize)
796 {
797     setIntegerValue(WebKitMinimumLogicalFontSizePreferenceKey, fontSize);
798     return S_OK;
799 }
800
801 HRESULT WebPreferences::defaultTextEncodingName(__deref_opt_out BSTR* name)
802 {
803     if (!name)
804         return E_POINTER;
805     *name = stringValueForKey(WebKitDefaultTextEncodingNamePreferenceKey);
806     return (*name) ? S_OK : E_FAIL;
807 }
808
809 HRESULT WebPreferences::setDefaultTextEncodingName(_In_ BSTR name)
810 {
811     setStringValue(WebKitDefaultTextEncodingNamePreferenceKey, name);
812     return S_OK;
813 }
814
815 HRESULT WebPreferences::userStyleSheetEnabled(_Out_ BOOL* enabled)
816 {
817     if (!enabled)
818         return E_POINTER;
819     *enabled = boolValueForKey(WebKitUserStyleSheetEnabledPreferenceKey);
820     return S_OK;
821 }
822
823 HRESULT WebPreferences::setUserStyleSheetEnabled(BOOL enabled)
824 {
825     setBoolValue(WebKitUserStyleSheetEnabledPreferenceKey, enabled);
826     return S_OK;
827 }
828
829 HRESULT WebPreferences::userStyleSheetLocation(__deref_opt_out BSTR* location)
830 {
831     if (!location)
832         return E_POINTER;
833     *location = stringValueForKey(WebKitUserStyleSheetLocationPreferenceKey);
834     return (*location) ? S_OK : E_FAIL;
835 }
836
837 HRESULT WebPreferences::setUserStyleSheetLocation(_In_ BSTR location)
838 {
839     setStringValue(WebKitUserStyleSheetLocationPreferenceKey, location);
840     return S_OK;
841 }
842
843 HRESULT WebPreferences::isJavaEnabled(_Out_ BOOL* enabled)
844 {
845     if (!enabled)
846         return E_POINTER;
847     *enabled = boolValueForKey(WebKitJavaEnabledPreferenceKey);
848     return S_OK;
849 }
850
851 HRESULT WebPreferences::setJavaEnabled(BOOL enabled)
852 {
853     setBoolValue(WebKitJavaEnabledPreferenceKey, enabled);
854     return S_OK;
855 }
856
857 HRESULT WebPreferences::isJavaScriptEnabled(_Out_ BOOL* enabled)
858 {
859     if (!enabled)
860         return E_POINTER;
861     *enabled = boolValueForKey(WebKitJavaScriptEnabledPreferenceKey);
862     return S_OK;
863 }
864
865 HRESULT WebPreferences::setJavaScriptEnabled(BOOL enabled)
866 {
867     setBoolValue(WebKitJavaScriptEnabledPreferenceKey, enabled);
868     return S_OK;
869 }
870
871 HRESULT WebPreferences::javaScriptRuntimeFlags(_Out_ unsigned* flags)
872 {
873     if (!flags)
874         return E_POINTER;
875     *flags = static_cast<unsigned>(integerValueForKey(WebKitJavaScriptRuntimeFlagsPreferenceKey));
876     return S_OK;
877 }
878
879 HRESULT WebPreferences::setJavaScriptRuntimeFlags(unsigned flags)
880 {
881     setIntegerValue(WebKitJavaScriptRuntimeFlagsPreferenceKey, static_cast<int>(flags));
882     return S_OK;
883 }
884
885 HRESULT WebPreferences::isWebSecurityEnabled(_Out_ BOOL* enabled)
886 {
887     if (!enabled)
888         return E_POINTER;
889     *enabled = boolValueForKey(WebKitWebSecurityEnabledPreferenceKey);
890     return S_OK;
891 }
892
893 HRESULT WebPreferences::setWebSecurityEnabled(BOOL enabled)
894 {
895     setBoolValue(WebKitWebSecurityEnabledPreferenceKey, enabled);
896     return S_OK;
897 }
898
899 HRESULT WebPreferences::allowUniversalAccessFromFileURLs(_Out_ BOOL* allowAccess)
900 {
901     if (!allowAccess)
902         return E_POINTER;
903     *allowAccess = boolValueForKey(WebKitAllowUniversalAccessFromFileURLsPreferenceKey);
904     return S_OK;
905 }
906
907 HRESULT WebPreferences::setAllowUniversalAccessFromFileURLs(BOOL allowAccess)
908 {
909     setBoolValue(WebKitAllowUniversalAccessFromFileURLsPreferenceKey, allowAccess);
910     return S_OK;
911 }
912
913 HRESULT WebPreferences::allowFileAccessFromFileURLs(_Out_ BOOL* allowAccess)
914 {
915     if (!allowAccess)
916         return E_POINTER;
917     *allowAccess = boolValueForKey(WebKitAllowFileAccessFromFileURLsPreferenceKey);
918     return S_OK;
919 }
920
921 HRESULT WebPreferences::setAllowFileAccessFromFileURLs(BOOL allowAccess)
922 {
923     setBoolValue(WebKitAllowFileAccessFromFileURLsPreferenceKey, allowAccess);
924     return S_OK;
925 }
926
927 HRESULT WebPreferences::javaScriptCanAccessClipboard(_Out_ BOOL* enabled)
928 {
929     if (!enabled)
930         return E_POINTER;
931     *enabled = boolValueForKey(WebKitJavaScriptCanAccessClipboardPreferenceKey);
932     return S_OK;
933 }
934
935 HRESULT WebPreferences::setJavaScriptCanAccessClipboard(BOOL enabled)
936 {
937     setBoolValue(WebKitJavaScriptCanAccessClipboardPreferenceKey, enabled);
938     return S_OK;
939 }
940
941 HRESULT WebPreferences::isXSSAuditorEnabled(_Out_ BOOL* enabled)
942 {
943     if (!enabled)
944         return E_POINTER;
945     *enabled = boolValueForKey(WebKitXSSAuditorEnabledPreferenceKey);
946     return S_OK;
947 }
948
949 HRESULT WebPreferences::setXSSAuditorEnabled(BOOL enabled)
950 {
951     setBoolValue(WebKitXSSAuditorEnabledPreferenceKey, enabled);
952     return S_OK;
953 }
954
955 HRESULT WebPreferences::isFrameFlatteningEnabled(_Out_ BOOL* enabled)
956 {
957     if (!enabled)
958         return E_POINTER;
959     *enabled = boolValueForKey(WebKitFrameFlatteningEnabledPreferenceKey);
960     return S_OK;
961 }
962
963 HRESULT WebPreferences::setFrameFlatteningEnabled(BOOL enabled)
964 {
965     setBoolValue(WebKitFrameFlatteningEnabledPreferenceKey, enabled);
966     return S_OK;
967 }
968
969 HRESULT WebPreferences::javaScriptCanOpenWindowsAutomatically(_Out_ BOOL* enabled)
970 {
971     if (!enabled)
972         return E_POINTER;
973     *enabled = boolValueForKey(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey);
974     return S_OK;
975 }
976
977 HRESULT WebPreferences::setJavaScriptCanOpenWindowsAutomatically(BOOL enabled)
978 {
979     setBoolValue(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey, enabled);
980     return S_OK;
981 }
982
983 HRESULT WebPreferences::arePlugInsEnabled(_Out_ BOOL* enabled)
984 {
985     if (!enabled)
986         return E_POINTER;
987     *enabled = boolValueForKey(WebKitPluginsEnabledPreferenceKey);
988     return S_OK;
989 }
990
991 HRESULT WebPreferences::setPlugInsEnabled(BOOL enabled)
992 {
993     setBoolValue(WebKitPluginsEnabledPreferenceKey, enabled);
994     return S_OK;
995 }
996
997 HRESULT WebPreferences::isCSSRegionsEnabled(_Out_ BOOL* enabled)
998 {
999     if (!enabled)
1000         return E_POINTER;
1001     *enabled = boolValueForKey(WebKitCSSRegionsEnabledPreferenceKey);
1002     return S_OK;
1003 }
1004
1005 HRESULT WebPreferences::setCSSRegionsEnabled(BOOL enabled)
1006 {
1007     setBoolValue(WebKitCSSRegionsEnabledPreferenceKey, enabled);
1008     return S_OK;
1009 }
1010
1011 HRESULT WebPreferences::allowsAnimatedImages(_Out_ BOOL* enabled)
1012 {
1013     if (!enabled)
1014         return E_POINTER;
1015     *enabled = boolValueForKey(WebKitAllowAnimatedImagesPreferenceKey);
1016     return S_OK;
1017 }
1018
1019 HRESULT WebPreferences::setAllowsAnimatedImages(BOOL enabled)
1020 {
1021     setBoolValue(WebKitAllowAnimatedImagesPreferenceKey, enabled);
1022     return S_OK;
1023 }
1024
1025 HRESULT WebPreferences::allowAnimatedImageLooping(_Out_ BOOL* enabled)
1026 {
1027     if (!enabled)
1028         return E_POINTER;
1029     *enabled = boolValueForKey(WebKitAllowAnimatedImageLoopingPreferenceKey);
1030     return S_OK;
1031 }
1032
1033 HRESULT WebPreferences::setAllowAnimatedImageLooping(BOOL enabled)
1034 {
1035     setBoolValue(WebKitAllowAnimatedImageLoopingPreferenceKey, enabled);
1036     return S_OK;
1037 }
1038
1039 HRESULT WebPreferences::setLoadsImagesAutomatically(BOOL enabled)
1040 {
1041     setBoolValue(WebKitDisplayImagesKey, enabled);
1042     return S_OK;
1043 }
1044
1045 HRESULT WebPreferences::loadsImagesAutomatically(_Out_ BOOL* enabled)
1046 {
1047     if (!enabled)
1048         return E_POINTER;
1049     *enabled = boolValueForKey(WebKitDisplayImagesKey);
1050     return S_OK;
1051 }
1052
1053 HRESULT WebPreferences::setLoadsSiteIconsIgnoringImageLoadingPreference(BOOL enabled)
1054 {
1055     setBoolValue(WebKitLoadSiteIconsKey, enabled);
1056     return S_OK;
1057 }
1058
1059 HRESULT WebPreferences::loadsSiteIconsIgnoringImageLoadingPreference(_Out_ BOOL* enabled)
1060 {
1061     if (!enabled)
1062         return E_POINTER;
1063     *enabled = boolValueForKey(WebKitLoadSiteIconsKey);
1064     return S_OK;
1065 }
1066
1067 HRESULT WebPreferences::setHixie76WebSocketProtocolEnabled(BOOL enabled)
1068 {
1069     return S_OK;
1070 }
1071
1072 HRESULT WebPreferences::hixie76WebSocketProtocolEnabled(_Out_ BOOL* enabled)
1073 {
1074     if (!enabled)
1075         return E_POINTER;
1076     *enabled = false;
1077     return S_OK;
1078 }
1079
1080 HRESULT WebPreferences::setMediaPlaybackRequiresUserGesture(BOOL enabled)
1081 {
1082     setBoolValue(WebKitMediaPlaybackRequiresUserGesturePreferenceKey, enabled);
1083     return S_OK;
1084 }
1085
1086 HRESULT WebPreferences::mediaPlaybackRequiresUserGesture(_Out_ BOOL* enabled)
1087 {
1088     if (!enabled)
1089         return E_POINTER;
1090     *enabled = boolValueForKey(WebKitMediaPlaybackRequiresUserGesturePreferenceKey);
1091     return S_OK;
1092 }
1093
1094 HRESULT WebPreferences::setMediaPlaybackAllowsInline(BOOL enabled)
1095 {
1096     setBoolValue(WebKitMediaPlaybackAllowsInlinePreferenceKey, enabled);
1097     return S_OK;
1098 }
1099
1100 HRESULT WebPreferences::mediaPlaybackAllowsInline(_Out_ BOOL* enabled)
1101 {
1102     if (!enabled)
1103         return E_POINTER;
1104     *enabled = boolValueForKey(WebKitMediaPlaybackAllowsInlinePreferenceKey);
1105     return S_OK;
1106 }
1107
1108 HRESULT WebPreferences::setAutosaves(BOOL enabled)
1109 {
1110     m_autoSaves = !!enabled;
1111     return S_OK;
1112 }
1113
1114 HRESULT WebPreferences::autosaves(_Out_ BOOL* enabled)
1115 {
1116     if (!enabled)
1117         return E_POINTER;
1118     *enabled = m_autoSaves ? TRUE : FALSE;
1119     return S_OK;
1120 }
1121
1122 HRESULT WebPreferences::setShouldPrintBackgrounds(BOOL enabled)
1123 {
1124     setBoolValue(WebKitShouldPrintBackgroundsPreferenceKey, enabled);
1125     return S_OK;
1126 }
1127
1128 HRESULT WebPreferences::shouldPrintBackgrounds(_Out_ BOOL* enabled)
1129 {
1130     if (!enabled)
1131         return E_POINTER;
1132     *enabled = boolValueForKey(WebKitShouldPrintBackgroundsPreferenceKey);
1133     return S_OK;
1134 }
1135
1136 HRESULT WebPreferences::setPrivateBrowsingEnabled(BOOL enabled)
1137 {
1138     setBoolValue(WebKitPrivateBrowsingEnabledPreferenceKey, enabled);
1139     return S_OK;
1140 }
1141
1142 HRESULT WebPreferences::privateBrowsingEnabled(_Out_ BOOL* enabled)
1143 {
1144     if (!enabled)
1145         return E_POINTER;
1146     *enabled = boolValueForKey(WebKitPrivateBrowsingEnabledPreferenceKey);
1147     return S_OK;
1148 }
1149
1150 HRESULT WebPreferences::setTabsToLinks(BOOL enabled)
1151 {
1152     setBoolValue(WebKitTabToLinksPreferenceKey, enabled);
1153     return S_OK;
1154 }
1155
1156 HRESULT WebPreferences::tabsToLinks(_Out_ BOOL* enabled)
1157 {
1158     *enabled = boolValueForKey(WebKitTabToLinksPreferenceKey);
1159     return S_OK;
1160 }
1161
1162 HRESULT WebPreferences::setUsesPageCache(BOOL usesPageCache)
1163 {
1164     setBoolValue(WebKitUsesPageCachePreferenceKey, usesPageCache);
1165     return S_OK;
1166 }
1167
1168 HRESULT WebPreferences::usesPageCache(_Out_ BOOL* usesPageCache)
1169 {
1170     if (!usesPageCache)
1171         return E_POINTER;
1172     *usesPageCache = boolValueForKey(WebKitUsesPageCachePreferenceKey);
1173     return S_OK;
1174 }
1175
1176 HRESULT WebPreferences::textAreasAreResizable(_Out_ BOOL* enabled)
1177 {
1178     if (!enabled)
1179         return E_POINTER;
1180     *enabled = boolValueForKey(WebKitTextAreasAreResizablePreferenceKey);
1181     return S_OK;
1182 }
1183
1184 HRESULT WebPreferences::setTextAreasAreResizable(BOOL enabled)
1185 {
1186     setBoolValue(WebKitTextAreasAreResizablePreferenceKey, enabled);
1187     return S_OK;
1188 }
1189
1190 HRESULT WebPreferences::historyItemLimit(_Out_ int* limit)
1191 {
1192     if (!limit)
1193         return E_POINTER;
1194     *limit = integerValueForKey(WebKitHistoryItemLimitKey);
1195     return S_OK;
1196 }
1197
1198 HRESULT WebPreferences::setHistoryItemLimit(int limit)
1199 {
1200     setIntegerValue(WebKitHistoryItemLimitKey, limit);
1201     return S_OK;
1202 }
1203
1204 HRESULT WebPreferences::historyAgeInDaysLimit(_Out_ int* limit)
1205 {
1206     if (!limit)
1207         return E_POINTER;
1208     *limit = integerValueForKey(WebKitHistoryAgeInDaysLimitKey);
1209     return S_OK;
1210 }
1211
1212 HRESULT WebPreferences::setHistoryAgeInDaysLimit(int limit)
1213 {
1214     setIntegerValue(WebKitHistoryAgeInDaysLimitKey, limit);
1215     return S_OK;
1216 }
1217
1218 HRESULT WebPreferences::unused1()
1219 {
1220     ASSERT_NOT_REACHED();
1221     return E_FAIL;
1222 }
1223
1224 HRESULT WebPreferences::unused2()
1225 {
1226     ASSERT_NOT_REACHED();
1227     return E_FAIL;
1228 }
1229
1230 HRESULT WebPreferences::iconDatabaseLocation(__deref_opt_out BSTR* location)
1231 {
1232     if (!location)
1233         return E_POINTER;
1234     *location = stringValueForKey(WebKitIconDatabaseLocationKey);
1235     return (*location) ? S_OK : E_FAIL;
1236 }
1237
1238 HRESULT WebPreferences::setIconDatabaseLocation(_In_ BSTR location)
1239 {
1240     setStringValue(WebKitIconDatabaseLocationKey, location);
1241     return S_OK;
1242 }
1243
1244 HRESULT WebPreferences::iconDatabaseEnabled(_Out_ BOOL* enabled)
1245 {
1246     if (!enabled)
1247         return E_POINTER;
1248     *enabled = boolValueForKey(WebKitIconDatabaseEnabledPreferenceKey);
1249     return S_OK;
1250 }
1251
1252 HRESULT WebPreferences::setIconDatabaseEnabled(BOOL enabled)
1253 {
1254     setBoolValue(WebKitIconDatabaseEnabledPreferenceKey, enabled);
1255     return S_OK;
1256 }
1257
1258 HRESULT WebPreferences::fontSmoothing(_Out_ FontSmoothingType* smoothingType)
1259 {
1260     if (!smoothingType)
1261         return E_POINTER;
1262     *smoothingType = static_cast<FontSmoothingType>(integerValueForKey(WebKitFontSmoothingTypePreferenceKey));
1263     return S_OK;
1264 }
1265
1266 HRESULT WebPreferences::setFontSmoothing(FontSmoothingType smoothingType)
1267 {
1268     setIntegerValue(WebKitFontSmoothingTypePreferenceKey, smoothingType);
1269     if (smoothingType == FontSmoothingTypeWindows)
1270         smoothingType = FontSmoothingTypeMedium;
1271 #if USE(CG)
1272     wkSetFontSmoothingLevel((int)smoothingType);
1273 #endif
1274     return S_OK;
1275 }
1276
1277 HRESULT WebPreferences::fontSmoothingContrast(_Out_ float* contrast)
1278 {
1279     if (!contrast)
1280         return E_POINTER;
1281     *contrast = floatValueForKey(WebKitFontSmoothingContrastPreferenceKey);
1282     return S_OK;
1283 }
1284
1285 HRESULT WebPreferences::setFontSmoothingContrast(float contrast)
1286 {
1287     setFloatValue(WebKitFontSmoothingContrastPreferenceKey, contrast);
1288 #if USE(CG)
1289     wkSetFontSmoothingContrast(contrast);
1290 #endif
1291     return S_OK;
1292 }
1293
1294 HRESULT WebPreferences::editableLinkBehavior(_Out_ WebKitEditableLinkBehavior* editableLinkBehavior)
1295 {
1296     if (!editableLinkBehavior)
1297         return E_POINTER;
1298     WebKitEditableLinkBehavior value = static_cast<WebKitEditableLinkBehavior>(integerValueForKey(WebKitEditableLinkBehaviorPreferenceKey));
1299     switch (value) {
1300         case WebKitEditableLinkDefaultBehavior:
1301         case WebKitEditableLinkAlwaysLive:
1302         case WebKitEditableLinkOnlyLiveWithShiftKey:
1303         case WebKitEditableLinkLiveWhenNotFocused:
1304         case WebKitEditableLinkNeverLive:
1305             *editableLinkBehavior = value;
1306             break;
1307         default: // ensure that a valid result is returned
1308             *editableLinkBehavior = WebKitEditableLinkDefaultBehavior;
1309             break;
1310     }
1311     return S_OK;
1312 }
1313
1314 HRESULT WebPreferences::setEditableLinkBehavior(WebKitEditableLinkBehavior behavior)
1315 {
1316     setIntegerValue(WebKitEditableLinkBehaviorPreferenceKey, behavior);
1317     return S_OK;
1318 }
1319
1320 HRESULT WebPreferences::unused5()
1321 {
1322     ASSERT_NOT_REACHED();
1323     return E_FAIL;
1324 }
1325
1326 HRESULT WebPreferences::unused6()
1327 {
1328     ASSERT_NOT_REACHED();
1329     return E_FAIL;
1330 }
1331
1332 HRESULT WebPreferences::mockScrollbarsEnabled(_Out_ BOOL* enabled)
1333 {
1334     if (!enabled)
1335         return E_POINTER;
1336     *enabled = boolValueForKey(WebKitMockScrollbarsEnabledPreferenceKey);
1337     return S_OK;
1338 }
1339
1340 HRESULT WebPreferences::setMockScrollbarsEnabled(BOOL enabled)
1341 {
1342     setBoolValue(WebKitMockScrollbarsEnabledPreferenceKey, enabled);
1343     return S_OK;
1344 }
1345
1346 // These two methods are no-ops, and only retained to keep
1347 // the Interface consistent. DO NOT USE THEM.
1348 HRESULT WebPreferences::screenFontSubstitutionEnabled(_Out_ BOOL* enabled)
1349 {
1350     if (!enabled)
1351         return E_POINTER;
1352     enabled = false;
1353     return S_OK;
1354 }
1355
1356 HRESULT WebPreferences::setScreenFontSubstitutionEnabled(BOOL)
1357 {
1358     return S_OK;
1359 }
1360
1361 HRESULT WebPreferences::hyperlinkAuditingEnabled(_Out_ BOOL* enabled)
1362 {
1363     if (!enabled)
1364         return E_POINTER;
1365     *enabled = boolValueForKey(WebKitHyperlinkAuditingEnabledPreferenceKey);
1366     return S_OK;
1367 }
1368
1369 HRESULT WebPreferences::setHyperlinkAuditingEnabled(BOOL enabled)
1370 {
1371     setBoolValue(WebKitHyperlinkAuditingEnabledPreferenceKey, enabled);
1372     return S_OK;
1373 }
1374
1375 HRESULT WebPreferences::cookieStorageAcceptPolicy(_Out_ WebKitCookieStorageAcceptPolicy* acceptPolicy)
1376 {
1377     if (!acceptPolicy)
1378         return E_POINTER;
1379
1380     *acceptPolicy = static_cast<WebKitCookieStorageAcceptPolicy>(integerValueForKey(WebKitCookieStorageAcceptPolicyPreferenceKey));
1381     return S_OK;
1382 }
1383
1384 HRESULT WebPreferences::setCookieStorageAcceptPolicy(WebKitCookieStorageAcceptPolicy acceptPolicy)
1385 {
1386     setIntegerValue(WebKitCookieStorageAcceptPolicyPreferenceKey, acceptPolicy);
1387     return S_OK;
1388 }
1389
1390
1391 HRESULT WebPreferences::continuousSpellCheckingEnabled(_Out_ BOOL* enabled)
1392 {
1393     if (!enabled)
1394         return E_POINTER;
1395     *enabled = boolValueForKey(WebContinuousSpellCheckingEnabledPreferenceKey);
1396     return S_OK;
1397 }
1398
1399 HRESULT WebPreferences::setContinuousSpellCheckingEnabled(BOOL enabled)
1400 {
1401     setBoolValue(WebContinuousSpellCheckingEnabledPreferenceKey, enabled);
1402     return S_OK;
1403 }
1404
1405 HRESULT WebPreferences::grammarCheckingEnabled(_Out_ BOOL* enabled)
1406 {
1407     if (!enabled)
1408         return E_POINTER;
1409     *enabled = boolValueForKey(WebGrammarCheckingEnabledPreferenceKey);
1410     return S_OK;
1411 }
1412
1413 HRESULT WebPreferences::setGrammarCheckingEnabled(BOOL enabled)
1414 {
1415     setBoolValue(WebGrammarCheckingEnabledPreferenceKey, enabled);
1416     return S_OK;
1417 }
1418
1419 HRESULT WebPreferences::allowContinuousSpellChecking(_Out_ BOOL* enabled)
1420 {
1421     if (!enabled)
1422         return E_POINTER;
1423     *enabled = boolValueForKey(AllowContinuousSpellCheckingPreferenceKey);
1424     return S_OK;
1425 }
1426
1427 HRESULT WebPreferences::setAllowContinuousSpellChecking(BOOL enabled)
1428 {
1429     setBoolValue(AllowContinuousSpellCheckingPreferenceKey, enabled);
1430     return S_OK;
1431 }
1432
1433 HRESULT WebPreferences::unused7()
1434 {
1435     ASSERT_NOT_REACHED();
1436     return E_FAIL;
1437 }
1438
1439 HRESULT WebPreferences::unused8()
1440 {
1441     ASSERT_NOT_REACHED();
1442     return E_FAIL;
1443 }
1444
1445 HRESULT WebPreferences::isDOMPasteAllowed(_Out_ BOOL* enabled)
1446 {
1447     if (!enabled)
1448         return E_POINTER;
1449     *enabled = boolValueForKey(WebKitDOMPasteAllowedPreferenceKey);
1450     return S_OK;
1451 }
1452     
1453 HRESULT WebPreferences::setDOMPasteAllowed(BOOL enabled)
1454 {
1455     setBoolValue(WebKitDOMPasteAllowedPreferenceKey, enabled);
1456     return S_OK;
1457 }
1458
1459 HRESULT WebPreferences::cacheModel(_Out_ WebCacheModel* cacheModel)
1460 {
1461     if (!cacheModel)
1462         return E_POINTER;
1463
1464     *cacheModel = static_cast<WebCacheModel>(integerValueForKey(WebKitCacheModelPreferenceKey));
1465     return S_OK;
1466 }
1467
1468 HRESULT WebPreferences::setCacheModel(WebCacheModel cacheModel)
1469 {
1470     setIntegerValue(WebKitCacheModelPreferenceKey, cacheModel);
1471     return S_OK;
1472 }
1473
1474 HRESULT WebPreferences::unused3()
1475 {
1476     ASSERT_NOT_REACHED();
1477     return E_FAIL;
1478 }
1479
1480 HRESULT WebPreferences::unused4()
1481 {
1482     ASSERT_NOT_REACHED();
1483     return E_FAIL;
1484 }
1485
1486 // These two methods are no-ops, and only retained to keep
1487 // the Interface consistent. DO NOT USE THEM.
1488 HRESULT WebPreferences::shouldPaintNativeControls(_Out_ BOOL* enable)
1489 {
1490     if (!enable)
1491         return E_POINTER;
1492     *enable = FALSE;
1493     return S_OK;
1494 }
1495
1496 HRESULT WebPreferences::setShouldPaintNativeControls(BOOL)
1497 {
1498     return S_OK;
1499 }
1500
1501 HRESULT WebPreferences::setDeveloperExtrasEnabled(BOOL enabled)
1502 {
1503     setBoolValue(WebKitDeveloperExtrasEnabledPreferenceKey, enabled);
1504     return S_OK;
1505 }
1506
1507 HRESULT WebPreferences::developerExtrasEnabled(_Out_ BOOL* enabled)
1508 {
1509     if (!enabled)
1510         return E_POINTER;
1511
1512     *enabled = boolValueForKey(WebKitDeveloperExtrasEnabledPreferenceKey);
1513     return S_OK;
1514 }
1515
1516 bool WebPreferences::developerExtrasDisabledByOverride()
1517 {
1518     return !!boolValueForKey(DisableWebKitDeveloperExtrasPreferenceKey);
1519 }
1520
1521 HRESULT WebPreferences::setAutomaticallyDetectsCacheModel(BOOL automaticallyDetectsCacheModel)
1522 {
1523     m_automaticallyDetectsCacheModel = !!automaticallyDetectsCacheModel;
1524     return S_OK;
1525 }
1526
1527 HRESULT WebPreferences::automaticallyDetectsCacheModel(_Out_ BOOL* automaticallyDetectsCacheModel)
1528 {
1529     if (!automaticallyDetectsCacheModel)
1530         return E_POINTER;
1531
1532     *automaticallyDetectsCacheModel = m_automaticallyDetectsCacheModel;
1533     return S_OK;
1534 }
1535
1536 HRESULT WebPreferences::setAuthorAndUserStylesEnabled(BOOL enabled)
1537 {
1538     setBoolValue(WebKitAuthorAndUserStylesEnabledPreferenceKey, enabled);
1539     return S_OK;
1540 }
1541
1542 HRESULT WebPreferences::authorAndUserStylesEnabled(_Out_ BOOL* enabled)
1543 {
1544     if (!enabled)
1545         return E_POINTER;
1546
1547     *enabled = boolValueForKey(WebKitAuthorAndUserStylesEnabledPreferenceKey);
1548     return S_OK;
1549 }
1550
1551 // These two methods are no-ops, and only retained to keep
1552 // the Interface consistent. DO NOT USE THEM.
1553 HRESULT WebPreferences::inApplicationChromeMode(_Out_ BOOL* enabled)
1554 {
1555     if (!enabled)
1556         return E_POINTER;
1557     *enabled = FALSE;
1558     return S_OK;
1559 }
1560
1561 HRESULT WebPreferences::setApplicationChromeMode(BOOL)
1562 {
1563     return S_OK;
1564 }
1565
1566 HRESULT WebPreferences::setOfflineWebApplicationCacheEnabled(BOOL enabled)
1567 {
1568     setBoolValue(WebKitOfflineWebApplicationCacheEnabledPreferenceKey, enabled);
1569     return S_OK;
1570 }
1571
1572 HRESULT WebPreferences::offlineWebApplicationCacheEnabled(_Out_ BOOL* enabled)
1573 {
1574     if (!enabled)
1575         return E_POINTER;
1576     *enabled = boolValueForKey(WebKitOfflineWebApplicationCacheEnabledPreferenceKey);
1577     return S_OK;
1578 }
1579
1580 HRESULT WebPreferences::setDatabasesEnabled(BOOL enabled)
1581 {
1582     setBoolValue(WebKitDatabasesEnabledPreferenceKey, enabled);
1583     return S_OK;
1584 }
1585
1586 HRESULT WebPreferences::databasesEnabled(_Out_ BOOL* enabled)
1587 {
1588     if (!enabled)
1589         return E_POINTER;
1590     *enabled = boolValueForKey(WebKitDatabasesEnabledPreferenceKey);
1591     return S_OK;
1592 }
1593
1594 HRESULT WebPreferences::setLocalStorageEnabled(BOOL enabled)
1595 {
1596     setBoolValue(WebKitLocalStorageEnabledPreferenceKey, enabled);
1597     return S_OK;
1598 }
1599
1600 HRESULT WebPreferences::localStorageEnabled(_Out_ BOOL* enabled)
1601 {
1602     if (!enabled)
1603         return E_POINTER;
1604     *enabled = boolValueForKey(WebKitLocalStorageEnabledPreferenceKey);
1605     return S_OK;
1606 }
1607
1608 HRESULT WebPreferences::localStorageDatabasePath(__deref_opt_out BSTR* location)
1609 {
1610     if (!location)
1611         return E_POINTER;
1612     *location = stringValueForKey(WebKitLocalStorageDatabasePathPreferenceKey);
1613     return (*location) ? S_OK : E_FAIL;
1614 }
1615
1616 HRESULT WebPreferences::setLocalStorageDatabasePath(_In_ BSTR location)
1617 {
1618     setStringValue(WebKitLocalStorageDatabasePathPreferenceKey, location);
1619     return S_OK;
1620 }
1621
1622 HRESULT WebPreferences::setExperimentalNotificationsEnabled(BOOL enabled)
1623 {
1624     setBoolValue(WebKitExperimentalNotificationsEnabledPreferenceKey, enabled);
1625     return S_OK;
1626 }
1627
1628 HRESULT WebPreferences::experimentalNotificationsEnabled(_Out_ BOOL* enabled)
1629 {
1630     if (!enabled)
1631         return E_POINTER;
1632     *enabled = boolValueForKey(WebKitExperimentalNotificationsEnabledPreferenceKey);
1633     return S_OK;
1634 }
1635
1636 HRESULT WebPreferences::setZoomsTextOnly(BOOL zoomsTextOnly)
1637 {
1638     setBoolValue(WebKitZoomsTextOnlyPreferenceKey, zoomsTextOnly);
1639     return S_OK;
1640 }
1641
1642 HRESULT WebPreferences::zoomsTextOnly(_Out_ BOOL* zoomsTextOnly)
1643 {
1644     if (!zoomsTextOnly)
1645         return E_POINTER;
1646     *zoomsTextOnly = boolValueForKey(WebKitZoomsTextOnlyPreferenceKey);
1647     return S_OK;
1648 }
1649
1650 HRESULT WebPreferences::setShouldUseHighResolutionTimers(BOOL useHighResolutionTimers)
1651 {
1652     setBoolValue(WebKitUseHighResolutionTimersPreferenceKey, useHighResolutionTimers);
1653     return S_OK;
1654 }
1655
1656 HRESULT WebPreferences::shouldUseHighResolutionTimers(_Out_ BOOL* useHighResolutionTimers)
1657 {
1658     if (!useHighResolutionTimers)
1659         return E_POINTER;
1660     *useHighResolutionTimers = boolValueForKey(WebKitUseHighResolutionTimersPreferenceKey);
1661     return S_OK;
1662 }
1663
1664 HRESULT WebPreferences::setPreferenceForTest(_In_ BSTR key, _In_ BSTR value)
1665 {
1666     if (!SysStringLen(key) || !SysStringLen(value))
1667         return E_FAIL;
1668     RetainPtr<CFStringRef> keyString = adoptCF(CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(key), SysStringLen(key)));
1669     RetainPtr<CFStringRef> valueString = adoptCF(CFStringCreateWithCharacters(0, reinterpret_cast<UniChar*>(value), SysStringLen(value)));
1670     setValueForKey(keyString.get(), valueString.get());
1671     postPreferencesChangesNotification();
1672     return S_OK;
1673 }
1674
1675 HRESULT WebPreferences::setAcceleratedCompositingEnabled(BOOL enabled)
1676 {
1677     setBoolValue(WebKitAcceleratedCompositingEnabledPreferenceKey, enabled);
1678     return S_OK;
1679 }
1680
1681 HRESULT WebPreferences::acceleratedCompositingEnabled(_Out_ BOOL* enabled)
1682 {
1683     if (!enabled)
1684         return E_POINTER;
1685 #if USE(CA)
1686     *enabled = CACFLayerTreeHost::acceleratedCompositingAvailable() && boolValueForKey(WebKitAcceleratedCompositingEnabledPreferenceKey);
1687 #else
1688     *enabled = TRUE;
1689 #endif
1690
1691     return S_OK;
1692 }
1693
1694 HRESULT WebPreferences::showDebugBorders(_Out_ BOOL* enabled)
1695 {
1696     if (!enabled)
1697         return E_POINTER;
1698     *enabled = boolValueForKey(WebKitShowDebugBordersPreferenceKey);
1699     return S_OK;
1700 }
1701
1702 HRESULT WebPreferences::setShowDebugBorders(BOOL enabled)
1703 {
1704     setBoolValue(WebKitShowDebugBordersPreferenceKey, enabled);
1705     return S_OK;
1706 }
1707
1708 HRESULT WebPreferences::showRepaintCounter(_Out_ BOOL* enabled)
1709 {
1710     if (!enabled)
1711         return E_POINTER;
1712     *enabled = boolValueForKey(WebKitShowRepaintCounterPreferenceKey);
1713     return S_OK;
1714 }
1715
1716 HRESULT WebPreferences::setShowRepaintCounter(BOOL enabled)
1717 {
1718     setBoolValue(WebKitShowRepaintCounterPreferenceKey, enabled);
1719     return S_OK;
1720 }
1721
1722 HRESULT WebPreferences::setCustomDragCursorsEnabled(BOOL enabled)
1723 {
1724     setBoolValue(WebKitCustomDragCursorsEnabledPreferenceKey, enabled);
1725     return S_OK;
1726 }
1727
1728 HRESULT WebPreferences::customDragCursorsEnabled(_Out_ BOOL* enabled)
1729 {
1730     if (!enabled)
1731         return E_POINTER;
1732     *enabled = boolValueForKey(WebKitCustomDragCursorsEnabledPreferenceKey);
1733     return S_OK;
1734 }
1735
1736 HRESULT WebPreferences::spatialNavigationEnabled(_Out_ BOOL* enabled)
1737 {
1738     if (!enabled)
1739         return E_POINTER;
1740     *enabled = boolValueForKey(WebKitSpatialNavigationEnabledPreferenceKey);
1741     return S_OK;
1742 }
1743
1744 HRESULT WebPreferences::setSpatialNavigationEnabled(BOOL enabled)
1745 {
1746     setBoolValue(WebKitSpatialNavigationEnabledPreferenceKey, enabled);
1747     return S_OK;
1748 }
1749
1750 HRESULT WebPreferences::setDNSPrefetchingEnabled(BOOL enabled)
1751 {
1752     setBoolValue(WebKitDNSPrefetchingEnabledPreferenceKey, enabled);
1753     return S_OK;
1754 }
1755
1756 HRESULT WebPreferences::isDNSPrefetchingEnabled(_Out_ BOOL* enabled)
1757 {
1758     if (!enabled)
1759         return E_POINTER;
1760     *enabled = boolValueForKey(WebKitDNSPrefetchingEnabledPreferenceKey);
1761     return S_OK;
1762 }
1763
1764 HRESULT WebPreferences::isFullScreenEnabled(_Out_ BOOL* enabled)
1765 {
1766 #if ENABLE(FULLSCREEN_API)
1767     if (!enabled)
1768         return E_POINTER;
1769
1770     *enabled = boolValueForKey(WebKitFullScreenEnabledPreferenceKey);
1771     return S_OK;
1772 #else
1773     return E_NOTIMPL;
1774 #endif
1775 }
1776
1777 HRESULT WebPreferences::setFullScreenEnabled(BOOL enabled)
1778 {
1779 #if ENABLE(FULLSCREEN_API)
1780     setBoolValue(WebKitFullScreenEnabledPreferenceKey, enabled);
1781     return S_OK;
1782 #else
1783     return E_NOTIMPL;
1784 #endif
1785 }
1786
1787 HRESULT WebPreferences::avFoundationEnabled(_Out_ BOOL* enabled)
1788 {
1789 #if USE(AVFOUNDATION)
1790     if (!enabled)
1791         return E_POINTER;
1792
1793     *enabled = boolValueForKey(WebKitAVFoundationEnabledPreferenceKey);
1794     return S_OK;
1795 #else
1796     return E_NOTIMPL;
1797 #endif
1798 }
1799
1800 HRESULT WebPreferences::setAVFoundationEnabled(BOOL enabled)
1801 {
1802 #if USE(AVFOUNDATION)
1803     setBoolValue(WebKitAVFoundationEnabledPreferenceKey, enabled);
1804     return S_OK;
1805 #else
1806     return E_NOTIMPL;
1807 #endif
1808 }
1809
1810 HRESULT WebPreferences::showsToolTipOverTruncatedText(_Out_ BOOL* showsToolTip)
1811 {
1812     if (!showsToolTip)
1813         return E_POINTER;
1814
1815     *showsToolTip = boolValueForKey(WebKitShowsToolTipOverTruncatedTextPreferenceKey);
1816     return S_OK;
1817 }
1818
1819 HRESULT WebPreferences::setShowsToolTipOverTruncatedText(BOOL showsToolTip)
1820 {
1821     setBoolValue(WebKitShowsToolTipOverTruncatedTextPreferenceKey, showsToolTip);
1822     return S_OK;
1823 }
1824
1825 HRESULT WebPreferences::shouldInvertColors(_Out_ BOOL* shouldInvertColors)
1826 {
1827     if (!shouldInvertColors)
1828         return E_POINTER;
1829
1830     *shouldInvertColors = boolValueForKey(WebKitShouldInvertColorsPreferenceKey);
1831     return S_OK;
1832 }
1833
1834 HRESULT WebPreferences::setShouldInvertColors(BOOL shouldInvertColors)
1835 {
1836     setBoolValue(WebKitShouldInvertColorsPreferenceKey, shouldInvertColors);
1837     return S_OK;
1838 }
1839
1840 void WebPreferences::willAddToWebView()
1841 {
1842     ++m_numWebViews;
1843 }
1844
1845 void WebPreferences::didRemoveFromWebView()
1846 {
1847     ASSERT(m_numWebViews);
1848     if (--m_numWebViews == 0) {
1849         IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
1850         nc->postNotificationName(webPreferencesRemovedNotification(), static_cast<IWebPreferences*>(this), 0);
1851     }
1852 }
1853
1854 HRESULT WebPreferences::shouldDisplaySubtitles(_Out_ BOOL* enabled)
1855 {
1856 #if ENABLE(VIDEO_TRACK)
1857     if (!enabled)
1858         return E_POINTER;
1859
1860     *enabled = boolValueForKey(WebKitShouldDisplaySubtitlesPreferenceKey);
1861     return S_OK;
1862 #else
1863     return E_NOTIMPL;
1864 #endif
1865 }
1866
1867 HRESULT WebPreferences::setShouldDisplaySubtitles(BOOL enabled)
1868 {
1869 #if ENABLE(VIDEO_TRACK)
1870     setBoolValue(WebKitShouldDisplaySubtitlesPreferenceKey, enabled);
1871     return S_OK;
1872 #else
1873     return E_NOTIMPL;
1874 #endif
1875 }
1876
1877 HRESULT WebPreferences::shouldDisplayCaptions(_Out_ BOOL* enabled)
1878 {
1879 #if ENABLE(VIDEO_TRACK)
1880     if (!enabled)
1881         return E_POINTER;
1882
1883     *enabled = boolValueForKey(WebKitShouldDisplayCaptionsPreferenceKey);
1884     return S_OK;
1885 #else
1886     return E_NOTIMPL;
1887 #endif
1888 }
1889
1890 HRESULT WebPreferences::setShouldDisplayCaptions(BOOL enabled)
1891 {
1892 #if ENABLE(VIDEO_TRACK)
1893     setBoolValue(WebKitShouldDisplayCaptionsPreferenceKey, enabled);
1894     return S_OK;
1895 #else
1896     return E_NOTIMPL;
1897 #endif
1898 }
1899
1900 HRESULT WebPreferences::shouldDisplayTextDescriptions(_Out_ BOOL* enabled)
1901 {
1902 #if ENABLE(VIDEO_TRACK)
1903     if (!enabled)
1904         return E_POINTER;
1905
1906     *enabled = boolValueForKey(WebKitShouldDisplayTextDescriptionsPreferenceKey);
1907     return S_OK;
1908 #else
1909     return E_NOTIMPL;
1910 #endif
1911 }
1912
1913 HRESULT WebPreferences::setShouldDisplayTextDescriptions(BOOL enabled)
1914 {
1915 #if ENABLE(VIDEO_TRACK)
1916     setBoolValue(WebKitShouldDisplayTextDescriptionsPreferenceKey, enabled);
1917     return S_OK;
1918 #else
1919     return E_NOTIMPL;
1920 #endif
1921 }
1922
1923 HRESULT WebPreferences::setRequestAnimationFrameEnabled(BOOL enabled)
1924 {
1925     setBoolValue(WebKitRequestAnimationFrameEnabledPreferenceKey, enabled);
1926     return S_OK;
1927 }
1928
1929 HRESULT WebPreferences::requestAnimationFrameEnabled(_Out_ BOOL* enabled)
1930 {
1931     if (!enabled)
1932         return E_POINTER;
1933     *enabled = boolValueForKey(WebKitRequestAnimationFrameEnabledPreferenceKey);
1934     return S_OK;
1935 }
1936
1937 HRESULT WebPreferences::isInheritURIQueryComponentEnabled(_Out_ BOOL* enabled)
1938 {
1939     if (!enabled)
1940         return E_POINTER;
1941     *enabled = boolValueForKey(WebKitEnableInheritURIQueryComponentPreferenceKey);
1942     return S_OK;
1943 }
1944
1945 HRESULT WebPreferences::setEnableInheritURIQueryComponent(BOOL enabled)
1946 {
1947     setBoolValue(WebKitEnableInheritURIQueryComponentPreferenceKey, enabled);
1948     return S_OK;
1949 }
1950
1951 HRESULT WebPreferences::allowDisplayAndRunningOfInsecureContent(_Out_ BOOL* enabled)
1952 {
1953     if (!enabled)
1954         return E_POINTER;
1955     *enabled = boolValueForKey(WebKitAllowDisplayAndRunningOfInsecureContentPreferenceKey);
1956     return S_OK;
1957 }
1958
1959 HRESULT WebPreferences::setAllowDisplayAndRunningOfInsecureContent(BOOL enabled)
1960 {
1961     setBoolValue(WebKitAllowDisplayAndRunningOfInsecureContentPreferenceKey, enabled);
1962     return S_OK;
1963 }
1964
1965 HRESULT WebPreferences::showTiledScrollingIndicator(_Out_ BOOL* enabled)
1966 {
1967     if (!enabled)
1968         return E_POINTER;
1969     *enabled = boolValueForKey(WebKitShowTiledScrollingIndicatorPreferenceKey);
1970     return S_OK;
1971 }
1972
1973 HRESULT WebPreferences::setShowTiledScrollingIndicator(BOOL enabled)
1974 {
1975     setBoolValue(WebKitShowTiledScrollingIndicatorPreferenceKey, enabled);
1976     return S_OK;
1977 }
1978
1979 HRESULT WebPreferences::fetchAPIEnabled(_Out_ BOOL* enabled)
1980 {
1981     if (!enabled)
1982         return E_POINTER;
1983     *enabled = boolValueForKey(WebKitFetchAPIEnabledPreferenceKey);
1984     return S_OK;
1985 }
1986
1987 HRESULT WebPreferences::setFetchAPIEnabled(BOOL enabled)
1988 {
1989     setBoolValue(WebKitFetchAPIEnabledPreferenceKey, enabled);
1990     return S_OK;
1991 }
1992
1993 HRESULT WebPreferences::shadowDOMEnabled(_Out_ BOOL* enabled)
1994 {
1995     if (!enabled)
1996         return E_POINTER;
1997     *enabled = boolValueForKey(WebKitShadowDOMEnabledPreferenceKey);
1998     return S_OK;
1999 }
2000
2001 HRESULT WebPreferences::setShadowDOMEnabled(BOOL enabled)
2002 {
2003     setBoolValue(WebKitShadowDOMEnabledPreferenceKey, enabled);
2004     return S_OK;
2005 }
2006
2007 HRESULT WebPreferences::customElementsEnabled(_Out_ BOOL* enabled)
2008 {
2009     if (!enabled)
2010         return E_POINTER;
2011     *enabled = boolValueForKey(WebKitCustomElementsEnabledPreferenceKey);
2012     return S_OK;
2013 }
2014
2015 HRESULT WebPreferences::setCustomElementsEnabled(BOOL enabled)
2016 {
2017     setBoolValue(WebKitCustomElementsEnabledPreferenceKey, enabled);
2018     return S_OK;
2019 }
2020
2021 HRESULT WebPreferences::menuItemElementEnabled(_Out_ BOOL* enabled)
2022 {
2023     if (!enabled)
2024         return E_POINTER;
2025     *enabled = boolValueForKey(WebKitMenuItemElementEnabledPreferenceKey);
2026     return S_OK;
2027 }
2028
2029 HRESULT WebPreferences::setMenuItemElementEnabled(BOOL enabled)
2030 {
2031     setBoolValue(WebKitMenuItemElementEnabledPreferenceKey, enabled);
2032     return S_OK;
2033 }
2034
2035 HRESULT WebPreferences::crossOriginOptionsSupportEnabled(_Out_ BOOL* enabled)
2036 {
2037     if (!enabled)
2038         return E_POINTER;
2039     *enabled = boolValueForKey(WebKitCrossOriginOptionsSupportEnabledPreferenceKey);
2040     return S_OK;
2041 }
2042
2043 HRESULT WebPreferences::setCrossOriginOptionsSupportEnabled(BOOL enabled)
2044 {
2045     setBoolValue(WebKitCrossOriginOptionsSupportEnabledPreferenceKey, enabled);
2046     return S_OK;
2047 }
2048
2049 HRESULT WebPreferences::setModernMediaControlsEnabled(BOOL enabled)
2050 {
2051     setBoolValue(WebKitModernMediaControlsEnabledPreferenceKey, enabled);
2052     return S_OK;
2053 }
2054
2055 HRESULT WebPreferences::modernMediaControlsEnabled(_Out_ BOOL* enabled)
2056 {
2057     if (!enabled)
2058         return E_POINTER;
2059     *enabled = boolValueForKey(WebKitModernMediaControlsEnabledPreferenceKey);
2060     return S_OK;
2061 }
2062
2063 HRESULT WebPreferences::cssAnimationsAndCSSTransitionsBackedByWebAnimationsEnabled(_Out_ BOOL* enabled)
2064 {
2065     if (!enabled)
2066         return E_POINTER;
2067     *enabled = boolValueForKey(WebKitCSSAnimationsAndCSSTransitionsBackedByWebAnimationsEnabledPreferenceKey);
2068     return S_OK;
2069 }
2070
2071 HRESULT WebPreferences::setCSSAnimationsAndCSSTransitionsBackedByWebAnimationsEnabled(BOOL enabled)
2072 {
2073     setBoolValue(WebKitCSSAnimationsAndCSSTransitionsBackedByWebAnimationsEnabledPreferenceKey, enabled);
2074     return S_OK;
2075 }
2076
2077 HRESULT WebPreferences::fetchAPIKeepAliveEnabled(_Out_ BOOL* enabled)
2078 {
2079     if (!enabled)
2080         return E_POINTER;
2081     *enabled = boolValueForKey(WebKitFetchAPIKeepAliveEnabledPreferenceKey);
2082     return S_OK;
2083 }
2084
2085 HRESULT WebPreferences::setFetchAPIKeepAliveEnabled(BOOL enabled)
2086 {
2087     setBoolValue(WebKitFetchAPIKeepAliveEnabledPreferenceKey, enabled);
2088     return S_OK;
2089 }
2090
2091 HRESULT WebPreferences::setLinkPreloadEnabled(BOOL enabled)
2092 {
2093     setBoolValue(WebKitLinkPreloadEnabledPreferenceKey, enabled);
2094     return S_OK;
2095 }
2096
2097 HRESULT WebPreferences::linkPreloadEnabled(_Out_ BOOL* enabled)
2098 {
2099     if (!enabled)
2100         return E_POINTER;
2101     *enabled = boolValueForKey(WebKitLinkPreloadEnabledPreferenceKey);
2102     return S_OK;
2103 }
2104
2105 HRESULT WebPreferences::setMediaPreloadingEnabled(BOOL enabled)
2106 {
2107     setBoolValue(WebKitMediaPreloadingEnabledPreferenceKey, enabled);
2108     return S_OK;
2109 }
2110
2111 HRESULT WebPreferences::mediaPreloadingEnabled(_Out_ BOOL* enabled)
2112 {
2113     if (!enabled)
2114         return E_POINTER;
2115     *enabled = boolValueForKey(WebKitMediaPreloadingEnabledPreferenceKey);
2116     return S_OK;
2117 }
2118
2119 HRESULT WebPreferences::clearNetworkLoaderSession()
2120 {
2121     WebCore::deleteAllCookies(NetworkStorageSession::defaultStorageSession());
2122     return S_OK;
2123 }
2124
2125 HRESULT WebPreferences::switchNetworkLoaderToNewTestingSession()
2126 {
2127     NetworkStorageSession::switchToNewTestingSession();
2128     return S_OK;
2129 }
2130
2131 HRESULT WebPreferences::setIsSecureContextAttributeEnabled(BOOL enabled)
2132 {
2133     setBoolValue(WebKitIsSecureContextAttributeEnabledPreferenceKey, enabled);
2134     return S_OK;
2135 }
2136
2137 HRESULT WebPreferences::isSecureContextAttributeEnabled(_Out_ BOOL* enabled)
2138 {
2139     if (!enabled)
2140         return E_POINTER;
2141     *enabled = boolValueForKey(WebKitIsSecureContextAttributeEnabledPreferenceKey);
2142     return S_OK;
2143 }
2144
2145 HRESULT WebPreferences::dataTransferItemsEnabled(_Out_ BOOL* enabled)
2146 {
2147     if (!enabled)
2148         return E_POINTER;
2149     *enabled = boolValueForKey(WebKitDataTransferItemsEnabledPreferenceKey);
2150     return S_OK;
2151 }
2152
2153 HRESULT WebPreferences::setDataTransferItemsEnabled(BOOL enabled)
2154 {
2155     setBoolValue(WebKitDataTransferItemsEnabledPreferenceKey, enabled);
2156     return S_OK;
2157 }
2158
2159 HRESULT WebPreferences::inspectorAdditionsEnabled(_Out_ BOOL* enabled)
2160 {
2161     if (!enabled)
2162         return E_POINTER;
2163     *enabled = boolValueForKey(WebKitInspectorAdditionsEnabledPreferenceKey);
2164     return S_OK;
2165 }
2166
2167 HRESULT WebPreferences::setInspectorAdditionsEnabled(BOOL enabled)
2168 {
2169     setBoolValue(WebKitInspectorAdditionsEnabledPreferenceKey, enabled);
2170     return S_OK;
2171 }
2172
2173 HRESULT WebPreferences::visualViewportAPIEnabled(_Out_ BOOL* enabled)
2174 {
2175     if (!enabled)
2176         return E_POINTER;
2177     *enabled = boolValueForKey(WebKitVisualViewportAPIEnabledPreferenceKey);
2178     return S_OK;
2179 }
2180
2181 HRESULT WebPreferences::setVisualViewportAPIEnabled(BOOL enabled)
2182 {
2183     setBoolValue(WebKitVisualViewportAPIEnabledPreferenceKey, enabled);
2184     return S_OK;
2185 }
2186
2187 HRESULT WebPreferences::setApplicationId(BSTR applicationId)
2188 {
2189     m_applicationId = String(applicationId).createCFString();
2190     return S_OK;
2191 }
2192
2193 HRESULT WebPreferences::setWebAnimationsEnabled(BOOL enabled)
2194 {
2195     setBoolValue(WebKitWebAnimationsEnabledPreferenceKey, enabled);
2196     return S_OK;
2197 }
2198
2199 HRESULT WebPreferences::webAnimationsEnabled(_Out_ BOOL* enabled)
2200 {
2201     if (!enabled)
2202         return E_POINTER;
2203     *enabled = boolValueForKey(WebKitWebAnimationsEnabledPreferenceKey);
2204     return S_OK;
2205 }
2206
2207 HRESULT WebPreferences::setUserTimingEnabled(BOOL enabled)
2208 {
2209     setBoolValue(WebKitUserTimingEnabledPreferenceKey, enabled);
2210     return S_OK;
2211 }
2212
2213 HRESULT WebPreferences::userTimingEnabled(_Out_ BOOL* enabled)
2214 {
2215     if (!enabled)
2216         return E_POINTER;
2217     *enabled = boolValueForKey(WebKitUserTimingEnabledPreferenceKey);
2218     return S_OK;
2219 }
2220
2221 HRESULT WebPreferences::setResourceTimingEnabled(BOOL enabled)
2222 {
2223     setBoolValue(WebKitResourceTimingEnabledPreferenceKey, enabled);
2224     return S_OK;
2225 }
2226
2227 HRESULT WebPreferences::resourceTimingEnabled(_Out_ BOOL* enabled)
2228 {
2229     if (!enabled)
2230         return E_POINTER;
2231     *enabled = boolValueForKey(WebKitResourceTimingEnabledPreferenceKey);
2232     return S_OK;
2233 }
2234
2235 HRESULT WebPreferences::serverTimingEnabled(_Out_ BOOL* enabled)
2236 {
2237     if (!enabled)
2238         return E_POINTER;
2239     *enabled = boolValueForKey(WebKitServerTimingEnabledPreferenceKey);
2240     return S_OK;
2241 }
2242
2243 HRESULT WebPreferences::setServerTimingEnabled(BOOL enabled)
2244 {
2245     setBoolValue(WebKitServerTimingEnabledPreferenceKey, enabled);
2246     return S_OK;
2247 }