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