1/* 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef WebPreferences_H 27#define WebPreferences_H 28 29#include "WebKit.h" 30#include <CoreFoundation/CoreFoundation.h> 31#include <WebCore/BString.h> 32#include <wtf/RetainPtr.h> 33 34class WebPreferences : public IWebPreferences, public IWebPreferencesPrivate { 35public: 36 static WebPreferences* createInstance(); 37protected: 38 WebPreferences(); 39 ~WebPreferences(); 40 41public: 42 // IUnknown 43 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); 44 virtual ULONG STDMETHODCALLTYPE AddRef(void); 45 virtual ULONG STDMETHODCALLTYPE Release(void); 46 47 // IWebPreferences 48 virtual HRESULT STDMETHODCALLTYPE standardPreferences( 49 /* [retval][out] */ IWebPreferences** standardPreferences); 50 51 virtual HRESULT STDMETHODCALLTYPE initWithIdentifier( 52 /* [in] */ BSTR anIdentifier, 53 /* [retval][out] */ IWebPreferences** preferences); 54 55 virtual HRESULT STDMETHODCALLTYPE identifier( 56 /* [retval][out] */ BSTR* ident); 57 58 virtual HRESULT STDMETHODCALLTYPE standardFontFamily( 59 /* [retval][out] */ BSTR* family); 60 61 virtual HRESULT STDMETHODCALLTYPE setStandardFontFamily( 62 /* [in] */ BSTR family); 63 64 virtual HRESULT STDMETHODCALLTYPE fixedFontFamily( 65 /* [retval][out] */ BSTR* family); 66 67 virtual HRESULT STDMETHODCALLTYPE setFixedFontFamily( 68 /* [in] */ BSTR family); 69 70 virtual HRESULT STDMETHODCALLTYPE serifFontFamily( 71 /* [retval][out] */ BSTR* fontFamily); 72 73 virtual HRESULT STDMETHODCALLTYPE setSerifFontFamily( 74 /* [in] */ BSTR family); 75 76 virtual HRESULT STDMETHODCALLTYPE sansSerifFontFamily( 77 /* [retval][out] */ BSTR* family); 78 79 virtual HRESULT STDMETHODCALLTYPE setSansSerifFontFamily( 80 /* [in] */ BSTR family); 81 82 virtual HRESULT STDMETHODCALLTYPE cursiveFontFamily( 83 /* [retval][out] */ BSTR* family); 84 85 virtual HRESULT STDMETHODCALLTYPE setCursiveFontFamily( 86 /* [in] */ BSTR family); 87 88 virtual HRESULT STDMETHODCALLTYPE fantasyFontFamily( 89 /* [retval][out] */ BSTR* family); 90 91 virtual HRESULT STDMETHODCALLTYPE setFantasyFontFamily( 92 /* [in] */ BSTR family); 93 94 virtual HRESULT STDMETHODCALLTYPE defaultFontSize( 95 /* [retval][out] */ int* fontSize); 96 97 virtual HRESULT STDMETHODCALLTYPE setDefaultFontSize( 98 /* [in] */ int fontSize); 99 100 virtual HRESULT STDMETHODCALLTYPE defaultFixedFontSize( 101 /* [retval][out] */ int* fontSize); 102 103 virtual HRESULT STDMETHODCALLTYPE setDefaultFixedFontSize( 104 /* [in] */ int fontSize); 105 106 virtual HRESULT STDMETHODCALLTYPE minimumFontSize( 107 /* [retval][out] */ int* fontSize); 108 109 virtual HRESULT STDMETHODCALLTYPE setMinimumFontSize( 110 /* [in] */ int fontSize); 111 112 virtual HRESULT STDMETHODCALLTYPE minimumLogicalFontSize( 113 /* [retval][out] */ int* fontSize); 114 115 virtual HRESULT STDMETHODCALLTYPE setMinimumLogicalFontSize( 116 /* [in] */ int fontSize); 117 118 virtual HRESULT STDMETHODCALLTYPE defaultTextEncodingName( 119 /* [retval][out] */ BSTR* name); 120 121 virtual HRESULT STDMETHODCALLTYPE setDefaultTextEncodingName( 122 /* [in] */ BSTR name); 123 124 virtual HRESULT STDMETHODCALLTYPE userStyleSheetEnabled( 125 /* [retval][out] */ BOOL* enabled); 126 127 virtual HRESULT STDMETHODCALLTYPE setUserStyleSheetEnabled( 128 /* [in] */ BOOL enabled); 129 130 virtual HRESULT STDMETHODCALLTYPE userStyleSheetLocation( 131 /* [retval][out] */ BSTR* location); 132 133 virtual HRESULT STDMETHODCALLTYPE setUserStyleSheetLocation( 134 /* [in] */ BSTR location); 135 136 virtual HRESULT STDMETHODCALLTYPE isJavaEnabled( 137 /* [retval][out] */ BOOL* enabled); 138 139 virtual HRESULT STDMETHODCALLTYPE setJavaEnabled( 140 /* [in] */ BOOL enabled); 141 142 virtual HRESULT STDMETHODCALLTYPE isJavaScriptEnabled( 143 /* [retval][out] */ BOOL* enabled); 144 145 virtual HRESULT STDMETHODCALLTYPE setJavaScriptEnabled( 146 /* [in] */ BOOL enabled); 147 148 virtual HRESULT STDMETHODCALLTYPE javaScriptCanOpenWindowsAutomatically( 149 /* [retval][out] */ BOOL* enabled); 150 151 virtual HRESULT STDMETHODCALLTYPE setJavaScriptCanOpenWindowsAutomatically( 152 /* [in] */ BOOL enabled); 153 154 virtual HRESULT STDMETHODCALLTYPE arePlugInsEnabled( 155 /* [retval][out] */ BOOL* enabled); 156 157 virtual HRESULT STDMETHODCALLTYPE setPlugInsEnabled( 158 /* [in] */ BOOL enabled); 159 160 virtual HRESULT STDMETHODCALLTYPE allowsAnimatedImages( 161 /* [retval][out] */ BOOL* enabled); 162 163 virtual HRESULT STDMETHODCALLTYPE setAllowsAnimatedImages( 164 /* [in] */ BOOL enabled); 165 166 virtual HRESULT STDMETHODCALLTYPE allowAnimatedImageLooping( 167 /* [retval][out] */ BOOL* enabled); 168 169 virtual HRESULT STDMETHODCALLTYPE setAllowAnimatedImageLooping( 170 /* [in] */ BOOL enabled); 171 172 virtual HRESULT STDMETHODCALLTYPE setLoadsImagesAutomatically( 173 /* [in] */ BOOL enabled); 174 175 virtual HRESULT STDMETHODCALLTYPE loadsImagesAutomatically( 176 /* [retval][out] */ BOOL* enabled); 177 178 virtual HRESULT STDMETHODCALLTYPE setAutosaves( 179 /* [in] */ BOOL enabled); 180 181 virtual HRESULT STDMETHODCALLTYPE autosaves( 182 /* [retval][out] */ BOOL* enabled); 183 184 virtual HRESULT STDMETHODCALLTYPE setShouldPrintBackgrounds( 185 /* [in] */ BOOL enabled); 186 187 virtual HRESULT STDMETHODCALLTYPE shouldPrintBackgrounds( 188 /* [retval][out] */ BOOL* enabled); 189 190 virtual HRESULT STDMETHODCALLTYPE setPrivateBrowsingEnabled( 191 /* [in] */ BOOL enabled); 192 193 virtual HRESULT STDMETHODCALLTYPE privateBrowsingEnabled( 194 /* [retval][out] */ BOOL* enabled); 195 196 virtual HRESULT STDMETHODCALLTYPE setTabsToLinks( 197 /* [in] */ BOOL enabled); 198 199 virtual HRESULT STDMETHODCALLTYPE tabsToLinks( 200 /* [retval][out] */ BOOL* enabled); 201 202 virtual HRESULT STDMETHODCALLTYPE textAreasAreResizable( 203 /* [retval][out] */ BOOL *enabled); 204 205 virtual HRESULT STDMETHODCALLTYPE setTextAreasAreResizable( 206 /* [in] */ BOOL enabled); 207 208 virtual HRESULT STDMETHODCALLTYPE usesPageCache( 209 /* [retval][out] */ BOOL *usesPageCache); 210 211 virtual HRESULT STDMETHODCALLTYPE setUsesPageCache( 212 /* [in] */ BOOL usesPageCache); 213 214 virtual HRESULT STDMETHODCALLTYPE unused1(); 215 virtual HRESULT STDMETHODCALLTYPE unused2(); 216 217 virtual HRESULT STDMETHODCALLTYPE iconDatabaseLocation( 218 /* [retval][out] */ BSTR* location); 219 220 virtual HRESULT STDMETHODCALLTYPE setIconDatabaseLocation( 221 /* [in] */ BSTR location); 222 223 virtual HRESULT STDMETHODCALLTYPE iconDatabaseEnabled( 224 /* [retval][out] */ BOOL* enabled); 225 226 virtual HRESULT STDMETHODCALLTYPE setIconDatabaseEnabled( 227 /* [in] */ BOOL enabled); 228 229 virtual HRESULT STDMETHODCALLTYPE fontSmoothing( 230 /* [retval][out] */ FontSmoothingType* smoothingType); 231 232 virtual HRESULT STDMETHODCALLTYPE setFontSmoothing( 233 /* [in] */ FontSmoothingType smoothingType); 234 235 virtual HRESULT STDMETHODCALLTYPE editableLinkBehavior( 236 /* [retval][out] */ WebKitEditableLinkBehavior* behavior); 237 238 virtual HRESULT STDMETHODCALLTYPE setEditableLinkBehavior( 239 /* [in] */ WebKitEditableLinkBehavior behavior); 240 241 virtual HRESULT STDMETHODCALLTYPE cookieStorageAcceptPolicy( 242 /* [retval][out] */ WebKitCookieStorageAcceptPolicy *acceptPolicy); 243 244 virtual HRESULT STDMETHODCALLTYPE setCookieStorageAcceptPolicy( 245 /* [in] */ WebKitCookieStorageAcceptPolicy acceptPolicy); 246 247 virtual HRESULT STDMETHODCALLTYPE continuousSpellCheckingEnabled( 248 /* [retval][out] */ BOOL *enabled); 249 250 virtual HRESULT STDMETHODCALLTYPE setContinuousSpellCheckingEnabled( 251 /* [in] */ BOOL enabled); 252 253 virtual HRESULT STDMETHODCALLTYPE grammarCheckingEnabled( 254 /* [retval][out] */ BOOL *enabled); 255 256 virtual HRESULT STDMETHODCALLTYPE setGrammarCheckingEnabled( 257 /* [in] */ BOOL enabled); 258 259 virtual HRESULT STDMETHODCALLTYPE allowContinuousSpellChecking( 260 /* [retval][out] */ BOOL *enabled); 261 262 virtual HRESULT STDMETHODCALLTYPE setAllowContinuousSpellChecking( 263 /* [in] */ BOOL enabled); 264 265 virtual HRESULT STDMETHODCALLTYPE isDOMPasteAllowed( 266 /* [retval][out] */ BOOL *enabled); 267 268 virtual HRESULT STDMETHODCALLTYPE setDOMPasteAllowed( 269 /* [in] */ BOOL enabled); 270 271 virtual HRESULT STDMETHODCALLTYPE cacheModel( 272 /* [retval][out] */ WebCacheModel* cacheModel); 273 274 virtual HRESULT STDMETHODCALLTYPE setCacheModel( 275 /* [in] */ WebCacheModel cacheModel); 276 277 virtual HRESULT STDMETHODCALLTYPE setShouldPaintCustomScrollbars( 278 /* [in] */ BOOL shouldPaint); 279 280 virtual HRESULT STDMETHODCALLTYPE shouldPaintCustomScrollbars( 281 /* [retval][out] */ BOOL *shouldPaint); 282 283 // IWebPreferencesPrivate 284 virtual HRESULT STDMETHODCALLTYPE setDeveloperExtrasEnabled( 285 /* [in] */ BOOL); 286 287 virtual HRESULT STDMETHODCALLTYPE developerExtrasEnabled( 288 /* [retval][out] */ BOOL*); 289 290 virtual HRESULT STDMETHODCALLTYPE setAutomaticallyDetectsCacheModel( 291 /* [in] */ BOOL automaticallyDetectsCacheModel); 292 293 virtual HRESULT STDMETHODCALLTYPE automaticallyDetectsCacheModel( 294 /* [out, retval] */ BOOL* automaticallyDetectsCacheModel); 295 296 virtual HRESULT STDMETHODCALLTYPE setAuthorAndUserStylesEnabled(BOOL); 297 virtual HRESULT STDMETHODCALLTYPE authorAndUserStylesEnabled(BOOL*); 298 299 virtual HRESULT STDMETHODCALLTYPE inApplicationChromeMode( 300 /* [retval][out] */ BOOL *enabled); 301 302 virtual HRESULT STDMETHODCALLTYPE setApplicationChromeMode( 303 /* [in] */ BOOL enabled); 304 305 virtual HRESULT STDMETHODCALLTYPE setOfflineWebApplicationCacheEnabled( 306 /* [in] */ BOOL enabled); 307 308 virtual HRESULT STDMETHODCALLTYPE offlineWebApplicationCacheEnabled( 309 /* [retval][out] */ BOOL *enabled); 310 311 virtual HRESULT STDMETHODCALLTYPE setDatabasesEnabled( 312 /* [in] */ BOOL enabled); 313 314 virtual HRESULT STDMETHODCALLTYPE databasesEnabled( 315 /* [retval][out] */ BOOL *enabled); 316 317 virtual HRESULT STDMETHODCALLTYPE setLocalStorageEnabled( 318 /* [in] */ BOOL enabled); 319 320 virtual HRESULT STDMETHODCALLTYPE localStorageEnabled( 321 /* [retval][out] */ BOOL *enabled); 322 323 virtual HRESULT STDMETHODCALLTYPE localStorageDatabasePath( 324 /* [out, retval] */ BSTR* location); 325 326 virtual HRESULT STDMETHODCALLTYPE setLocalStorageDatabasePath( 327 /* [in] */ BSTR location); 328 329 virtual HRESULT STDMETHODCALLTYPE experimentalNotificationsEnabled( 330 /* [retval][out] */ BOOL *enabled); 331 332 virtual HRESULT STDMETHODCALLTYPE setExperimentalNotificationsEnabled( 333 /* [in] */ BOOL enabled); 334 335 virtual HRESULT STDMETHODCALLTYPE setShouldPaintNativeControls( 336 /* [in] */ BOOL shouldPaint); 337 338 virtual HRESULT STDMETHODCALLTYPE shouldPaintNativeControls( 339 /* [retval][out] */ BOOL *shouldPaint); 340 341 virtual HRESULT STDMETHODCALLTYPE setZoomsTextOnly( 342 /* [retval][out] */ BOOL zoomsTextOnly); 343 344 virtual HRESULT STDMETHODCALLTYPE zoomsTextOnly( 345 /* [retval][out] */ BOOL *zoomsTextOnly); 346 347 virtual HRESULT STDMETHODCALLTYPE fontSmoothingContrast( 348 /* [retval][out] */ float* contrast); 349 350 virtual HRESULT STDMETHODCALLTYPE setFontSmoothingContrast( 351 /* [in] */ float contrast); 352 353 virtual HRESULT STDMETHODCALLTYPE isWebSecurityEnabled( 354 /* [retval][out] */ BOOL* enabled); 355 356 virtual HRESULT STDMETHODCALLTYPE setWebSecurityEnabled( 357 /* [in] */ BOOL enabled); 358 359 virtual HRESULT STDMETHODCALLTYPE allowUniversalAccessFromFileURLs( 360 /* [retval][out] */ BOOL* allowAccess); 361 362 virtual HRESULT STDMETHODCALLTYPE setAllowUniversalAccessFromFileURLs( 363 /* [in] */ BOOL allowAccess); 364 365 virtual HRESULT STDMETHODCALLTYPE isXSSAuditorEnabled( 366 /* [retval][out] */ BOOL* enabled); 367 368 virtual HRESULT STDMETHODCALLTYPE setXSSAuditorEnabled( 369 /* [in] */ BOOL enabled); 370 371 virtual HRESULT STDMETHODCALLTYPE setShouldUseHighResolutionTimers( 372 /* [in] */ BOOL useHighResolutionTimers); 373 374 virtual HRESULT STDMETHODCALLTYPE shouldUseHighResolutionTimers( 375 /* [retval][out] */ BOOL* useHighResolutionTimers); 376 377 virtual HRESULT STDMETHODCALLTYPE setPluginAllowedRunTime( 378 /* [in] */ UINT allowedRunTime); 379 380 virtual HRESULT STDMETHODCALLTYPE pluginAllowedRunTime( 381 /* [retval][out] */ UINT* allowedRunTime); 382 383 virtual HRESULT STDMETHODCALLTYPE isFrameSetFlatteningEnabled( 384 /* [retval][out] */ BOOL* enabled); 385 386 virtual HRESULT STDMETHODCALLTYPE setFrameSetFlatteningEnabled( 387 /* [in] */ BOOL enabled); 388 389 virtual HRESULT STDMETHODCALLTYPE setPreferenceForTest( 390 /* [in] */ BSTR key, 391 /* [in] */ BSTR value); 392 393 virtual HRESULT STDMETHODCALLTYPE setAcceleratedCompositingEnabled(BOOL); 394 virtual HRESULT STDMETHODCALLTYPE acceleratedCompositingEnabled(BOOL*); 395 396 virtual HRESULT STDMETHODCALLTYPE setCustomDragCursorsEnabled(BOOL); 397 virtual HRESULT STDMETHODCALLTYPE customDragCursorsEnabled(BOOL*); 398 399 // WebPreferences 400 401 // This method accesses a different preference key than developerExtrasEnabled. 402 // See <rdar://5343767> for the justification. 403 bool developerExtrasDisabledByOverride(); 404 405 static BSTR webPreferencesChangedNotification(); 406 static BSTR webPreferencesRemovedNotification(); 407 408 static void setInstance(WebPreferences* instance, BSTR identifier); 409 static void removeReferenceForIdentifier(BSTR identifier); 410 static WebPreferences* sharedStandardPreferences(); 411 412 // From WebHistory.h 413 HRESULT historyItemLimit(int* limit); 414 HRESULT setHistoryItemLimit(int limit); 415 HRESULT historyAgeInDaysLimit(int* limit); 416 HRESULT setHistoryAgeInDaysLimit(int limit); 417 418 void willAddToWebView(); 419 void didRemoveFromWebView(); 420 421 HRESULT postPreferencesChangesNotification(); 422 423protected: 424 void setValueForKey(CFStringRef key, CFPropertyListRef value); 425 RetainPtr<CFPropertyListRef> valueForKey(CFStringRef key); 426 BSTR stringValueForKey(CFStringRef key); 427 int integerValueForKey(CFStringRef key); 428 BOOL boolValueForKey(CFStringRef key); 429 float floatValueForKey(CFStringRef key); 430 LONGLONG longlongValueForKey(CFStringRef key); 431 void setStringValue(CFStringRef key, LPCTSTR value); 432 void setIntegerValue(CFStringRef key, int value); 433 void setBoolValue(CFStringRef key, BOOL value); 434 void setFloatValue(CFStringRef key, float value); 435 void setLongLongValue(CFStringRef key, LONGLONG value); 436 static WebPreferences* getInstanceForIdentifier(BSTR identifier); 437 static void initializeDefaultSettings(); 438 void save(); 439 void load(); 440 void migrateWebKitPreferencesToCFPreferences(); 441 void copyWebKitPreferencesToCFPreferences(CFDictionaryRef); 442 443protected: 444 ULONG m_refCount; 445 RetainPtr<CFMutableDictionaryRef> m_privatePrefs; 446 WebCore::BString m_identifier; 447 bool m_autoSaves; 448 bool m_automaticallyDetectsCacheModel; 449 unsigned m_numWebViews; 450}; 451 452#endif 453