1/* 2 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved. 3 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#ifndef Settings_h 28#define Settings_h 29 30#include "EditingBehaviorTypes.h" 31#include "FontRenderingMode.h" 32#include "IntSize.h" 33#include "KURL.h" 34#include "SecurityOrigin.h" 35#include "SettingsMacros.h" 36#include "Timer.h" 37#include <wtf/HashMap.h> 38#include <wtf/text/AtomicString.h> 39#include <wtf/text/AtomicStringHash.h> 40#include <wtf/unicode/Unicode.h> 41 42namespace WebCore { 43 44 class FontGenericFamilies; 45 class Page; 46 47 enum EditableLinkBehavior { 48 EditableLinkDefaultBehavior, 49 EditableLinkAlwaysLive, 50 EditableLinkOnlyLiveWithShiftKey, 51 EditableLinkLiveWhenNotFocused, 52 EditableLinkNeverLive 53 }; 54 55 enum TextDirectionSubmenuInclusionBehavior { 56 TextDirectionSubmenuNeverIncluded, 57 TextDirectionSubmenuAutomaticallyIncluded, 58 TextDirectionSubmenuAlwaysIncluded 59 }; 60 61 class Settings { 62 WTF_MAKE_NONCOPYABLE(Settings); WTF_MAKE_FAST_ALLOCATED; 63 public: 64 static PassOwnPtr<Settings> create(Page*); 65 66 ~Settings(); 67 68 void setStandardFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 69 const AtomicString& standardFontFamily(UScriptCode = USCRIPT_COMMON) const; 70 71 void setFixedFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 72 const AtomicString& fixedFontFamily(UScriptCode = USCRIPT_COMMON) const; 73 74 void setSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 75 const AtomicString& serifFontFamily(UScriptCode = USCRIPT_COMMON) const; 76 77 void setSansSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 78 const AtomicString& sansSerifFontFamily(UScriptCode = USCRIPT_COMMON) const; 79 80 void setCursiveFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 81 const AtomicString& cursiveFontFamily(UScriptCode = USCRIPT_COMMON) const; 82 83 void setFantasyFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 84 const AtomicString& fantasyFontFamily(UScriptCode = USCRIPT_COMMON) const; 85 86 void setPictographFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 87 const AtomicString& pictographFontFamily(UScriptCode = USCRIPT_COMMON) const; 88 89#if ENABLE(TEXT_AUTOSIZING) 90 void setTextAutosizingEnabled(bool); 91 bool textAutosizingEnabled() const { return m_textAutosizingEnabled; } 92 93 void setTextAutosizingFontScaleFactor(float); 94 float textAutosizingFontScaleFactor() const { return m_textAutosizingFontScaleFactor; } 95 96 // Only set by Layout Tests, and only used if textAutosizingEnabled() returns true. 97 void setTextAutosizingWindowSizeOverride(const IntSize&); 98 const IntSize& textAutosizingWindowSizeOverride() const { return m_textAutosizingWindowSizeOverride; } 99#endif 100 101 // Only set by Layout Tests. 102 void setMediaTypeOverride(const String&); 103 const String& mediaTypeOverride() const { return m_mediaTypeOverride; } 104 105 // Unlike areImagesEnabled, this only suppresses the network load of 106 // the image URL. A cached image will still be rendered if requested. 107 void setLoadsImagesAutomatically(bool); 108 bool loadsImagesAutomatically() const { return m_loadsImagesAutomatically; } 109 110 // Clients that execute script should call ScriptController::canExecuteScripts() 111 // instead of this function. ScriptController::canExecuteScripts() checks the 112 // HTML sandbox, plug-in sandboxing, and other important details. 113 bool isScriptEnabled() const { return m_isScriptEnabled; } 114 void setScriptEnabled(bool); 115 116 SETTINGS_GETTERS_AND_SETTERS 117 118 void setScreenFontSubstitutionEnabled(bool); 119 bool screenFontSubstitutionEnabled() const { return m_screenFontSubstitutionEnabled; } 120 121 void setJavaEnabled(bool); 122 bool isJavaEnabled() const { return m_isJavaEnabled; } 123 124 // This settings is only consulted if isJavaEnabled() returns true; 125 void setJavaEnabledForLocalFiles(bool); 126 bool isJavaEnabledForLocalFiles() const { return m_isJavaEnabledForLocalFiles; } 127 128 void setImagesEnabled(bool); 129 bool areImagesEnabled() const { return m_areImagesEnabled; } 130 131 void setPluginsEnabled(bool); 132 bool arePluginsEnabled() const { return m_arePluginsEnabled; } 133 134 // When this option is set, WebCore will avoid storing any record of browsing activity 135 // that may persist on disk or remain displayed when the option is reset. 136 // This option does not affect the storage of such information in RAM. 137 // The following functions respect this setting: 138 // - HTML5/DOM Storage 139 // - Icon Database 140 // - Console Messages 141 // - MemoryCache 142 // - Application Cache 143 // - Back/Forward Page History 144 // - Page Search Results 145 // - HTTP Cookies 146 // - Plug-ins (that support NPNVprivateModeBool) 147 void setPrivateBrowsingEnabled(bool); 148 bool privateBrowsingEnabled() const { return m_privateBrowsingEnabled; } 149 150 void setDNSPrefetchingEnabled(bool); 151 bool dnsPrefetchingEnabled() const { return m_dnsPrefetchingEnabled; } 152 153 void setUserStyleSheetLocation(const KURL&); 154 const KURL& userStyleSheetLocation() const { return m_userStyleSheetLocation; } 155 156 void setNeedsAdobeFrameReloadingQuirk(bool); 157 bool needsAcrobatFrameReloadingQuirk() const { return m_needsAdobeFrameReloadingQuirk; } 158 159 static void setDefaultMinDOMTimerInterval(double); // Interval specified in seconds. 160 static double defaultMinDOMTimerInterval(); 161 162 static void setHiddenPageDOMTimerAlignmentInterval(double); // Interval specified in seconds. 163 static double hiddenPageDOMTimerAlignmentInterval(); 164 165 void setMinDOMTimerInterval(double); // Per-page; initialized to default value. 166 double minDOMTimerInterval(); 167 168 static void setDefaultDOMTimerAlignmentInterval(double); 169 static double defaultDOMTimerAlignmentInterval(); 170 171 void setDOMTimerAlignmentInterval(double); 172 double domTimerAlignmentInterval() const; 173 174#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING) 175 bool hiddenPageDOMTimerThrottlingEnabled() const { return m_hiddenPageDOMTimerThrottlingEnabled; } 176 void setHiddenPageDOMTimerThrottlingEnabled(bool); 177#endif 178 179 void setUsesPageCache(bool); 180 bool usesPageCache() const { return m_usesPageCache; } 181 182 void setFontRenderingMode(FontRenderingMode mode); 183 FontRenderingMode fontRenderingMode() const; 184 185 void setCSSCustomFilterEnabled(bool enabled) { m_isCSSCustomFilterEnabled = enabled; } 186 bool isCSSCustomFilterEnabled() const { return m_isCSSCustomFilterEnabled; } 187 188#if ENABLE(CSS_STICKY_POSITION) 189 void setCSSStickyPositionEnabled(bool enabled) { m_cssStickyPositionEnabled = enabled; } 190 bool cssStickyPositionEnabled() const { return m_cssStickyPositionEnabled; } 191#else 192 void setCSSStickyPositionEnabled(bool) { } 193 bool cssStickyPositionEnabled() const { return false; } 194#endif 195 196#if ENABLE(CSS_VARIABLES) 197 void setCSSVariablesEnabled(bool enabled) { m_cssVariablesEnabled = enabled; } 198 bool cssVariablesEnabled() const { return m_cssVariablesEnabled; } 199#else 200 void setCSSVariablesEnabled(bool) { } 201 bool cssVariablesEnabled() const { return false; } 202#endif 203 204 void setShowTiledScrollingIndicator(bool); 205 bool showTiledScrollingIndicator() const { return m_showTiledScrollingIndicator; } 206 207#if PLATFORM(WIN) 208 static void setShouldUseHighResolutionTimers(bool); 209 static bool shouldUseHighResolutionTimers() { return gShouldUseHighResolutionTimers; } 210#endif 211 212 void setTiledBackingStoreEnabled(bool); 213 bool tiledBackingStoreEnabled() const { return m_tiledBackingStoreEnabled; } 214 215#if USE(AVFOUNDATION) 216 static void setAVFoundationEnabled(bool flag); 217 static bool isAVFoundationEnabled() { return gAVFoundationEnabled; } 218#endif 219 220#if PLATFORM(MAC) 221 static void setQTKitEnabled(bool flag); 222 static bool isQTKitEnabled() { return gQTKitEnabled; } 223#endif 224 225 static const unsigned defaultMaximumHTMLParserDOMTreeDepth = 512; 226 227#if USE(SAFARI_THEME) 228 // Windows debugging pref (global) for switching between the Aqua look and a native windows look. 229 static void setShouldPaintNativeControls(bool); 230 static bool shouldPaintNativeControls() { return gShouldPaintNativeControls; } 231#endif 232 233 static void setMockScrollbarsEnabled(bool flag); 234 static bool mockScrollbarsEnabled(); 235 236 static void setUsesOverlayScrollbars(bool flag); 237 static bool usesOverlayScrollbars(); 238 239#if ENABLE(TOUCH_EVENTS) 240 void setTouchEventEmulationEnabled(bool enabled) { m_touchEventEmulationEnabled = enabled; } 241 bool isTouchEventEmulationEnabled() const { return m_touchEventEmulationEnabled; } 242#endif 243 244 void setStorageBlockingPolicy(SecurityOrigin::StorageBlockingPolicy); 245 SecurityOrigin::StorageBlockingPolicy storageBlockingPolicy() const { return m_storageBlockingPolicy; } 246 247 void setScrollingPerformanceLoggingEnabled(bool); 248 bool scrollingPerformanceLoggingEnabled() { return m_scrollingPerformanceLoggingEnabled; } 249 250 void setAggressiveTileRetentionEnabled(bool); 251 bool aggressiveTileRetentionEnabled() { return m_aggressiveTileRetentionEnabled; } 252 253 static void setShouldRespectPriorityInCSSAttributeSetters(bool); 254 static bool shouldRespectPriorityInCSSAttributeSetters(); 255 256 void setTimeWithoutMouseMovementBeforeHidingControls(double time) { m_timeWithoutMouseMovementBeforeHidingControls = time; } 257 double timeWithoutMouseMovementBeforeHidingControls() const { return m_timeWithoutMouseMovementBeforeHidingControls; } 258 259#if ENABLE(PAGE_VISIBILITY_API) 260 bool hiddenPageCSSAnimationSuspensionEnabled() const { return m_hiddenPageCSSAnimationSuspensionEnabled; } 261 void setHiddenPageCSSAnimationSuspensionEnabled(bool); 262#endif 263 264 static bool lowPowerVideoAudioBufferSizeEnabled() { return gLowPowerVideoAudioBufferSizeEnabled; } 265 static void setLowPowerVideoAudioBufferSizeEnabled(bool); 266 267 private: 268 explicit Settings(Page*); 269 270 void initializeDefaultFontFamilies(); 271 static bool shouldEnableScreenFontSubstitutionByDefault(); 272 273 Page* m_page; 274 275 String m_mediaTypeOverride; 276 KURL m_userStyleSheetLocation; 277 RefPtr<FontGenericFamilies> m_fontGenericFamilies; 278 SecurityOrigin::StorageBlockingPolicy m_storageBlockingPolicy; 279#if ENABLE(TEXT_AUTOSIZING) 280 float m_textAutosizingFontScaleFactor; 281 IntSize m_textAutosizingWindowSizeOverride; 282 bool m_textAutosizingEnabled : 1; 283#endif 284 285 SETTINGS_MEMBER_VARIABLES 286 287 bool m_screenFontSubstitutionEnabled : 1; 288 bool m_isJavaEnabled : 1; 289 bool m_isJavaEnabledForLocalFiles : 1; 290 bool m_loadsImagesAutomatically : 1; 291 bool m_privateBrowsingEnabled : 1; 292 bool m_areImagesEnabled : 1; 293 bool m_arePluginsEnabled : 1; 294 bool m_isScriptEnabled : 1; 295 bool m_needsAdobeFrameReloadingQuirk : 1; 296 bool m_usesPageCache : 1; 297 unsigned m_fontRenderingMode : 1; 298 bool m_isCSSCustomFilterEnabled : 1; 299#if ENABLE(CSS_STICKY_POSITION) 300 bool m_cssStickyPositionEnabled : 1; 301#endif 302#if ENABLE(CSS_VARIABLES) 303 bool m_cssVariablesEnabled : 1; 304#endif 305 bool m_showTiledScrollingIndicator : 1; 306 bool m_tiledBackingStoreEnabled : 1; 307 bool m_dnsPrefetchingEnabled : 1; 308 309#if ENABLE(TOUCH_EVENTS) 310 bool m_touchEventEmulationEnabled : 1; 311#endif 312 bool m_scrollingPerformanceLoggingEnabled : 1; 313 bool m_aggressiveTileRetentionEnabled : 1; 314 315 double m_timeWithoutMouseMovementBeforeHidingControls; 316 317 Timer<Settings> m_setImageLoadingSettingsTimer; 318 void imageLoadingSettingsTimerFired(Timer<Settings>*); 319 320#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING) 321 bool m_hiddenPageDOMTimerThrottlingEnabled : 1; 322#endif 323#if ENABLE(PAGE_VISIBILITY_API) 324 bool m_hiddenPageCSSAnimationSuspensionEnabled : 1; 325#endif 326 static double gDefaultMinDOMTimerInterval; 327 static double gDefaultDOMTimerAlignmentInterval; 328 329#if USE(AVFOUNDATION) 330 static bool gAVFoundationEnabled; 331#endif 332 333#if PLATFORM(MAC) 334 static bool gQTKitEnabled; 335#endif 336 337 static bool gMockScrollbarsEnabled; 338 static bool gUsesOverlayScrollbars; 339 340#if USE(SAFARI_THEME) 341 static bool gShouldPaintNativeControls; 342#endif 343#if PLATFORM(WIN) 344 static bool gShouldUseHighResolutionTimers; 345#endif 346 static bool gShouldRespectPriorityInCSSAttributeSetters; 347 348 static double gHiddenPageDOMTimerAlignmentInterval; 349 350 static bool gLowPowerVideoAudioBufferSizeEnabled; 351 }; 352 353} // namespace WebCore 354 355#endif // Settings_h 356