1/* 2 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2011, 2012, 2013 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 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 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 "URL.h" 34#include "SecurityOrigin.h" 35#include "SettingsMacros.h" 36#include "Timer.h" 37#include <chrono> 38#include <unicode/uscript.h> 39#include <wtf/HashMap.h> 40#include <wtf/RefCounted.h> 41#include <wtf/text/AtomicString.h> 42#include <wtf/text/AtomicStringHash.h> 43 44namespace WebCore { 45 46class FontGenericFamilies; 47class Page; 48 49enum EditableLinkBehavior { 50 EditableLinkDefaultBehavior, 51 EditableLinkAlwaysLive, 52 EditableLinkOnlyLiveWithShiftKey, 53 EditableLinkLiveWhenNotFocused, 54 EditableLinkNeverLive 55}; 56 57enum TextDirectionSubmenuInclusionBehavior { 58 TextDirectionSubmenuNeverIncluded, 59 TextDirectionSubmenuAutomaticallyIncluded, 60 TextDirectionSubmenuAlwaysIncluded 61}; 62 63class Settings : public RefCounted<Settings> { 64 WTF_MAKE_NONCOPYABLE(Settings); WTF_MAKE_FAST_ALLOCATED; 65public: 66 static PassRefPtr<Settings> create(Page*); 67 ~Settings(); 68 69 void setStandardFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 70 const AtomicString& standardFontFamily(UScriptCode = USCRIPT_COMMON) const; 71 72 void setFixedFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 73 const AtomicString& fixedFontFamily(UScriptCode = USCRIPT_COMMON) const; 74 75 void setSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 76 const AtomicString& serifFontFamily(UScriptCode = USCRIPT_COMMON) const; 77 78 void setSansSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 79 const AtomicString& sansSerifFontFamily(UScriptCode = USCRIPT_COMMON) const; 80 81 void setCursiveFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 82 const AtomicString& cursiveFontFamily(UScriptCode = USCRIPT_COMMON) const; 83 84 void setFantasyFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 85 const AtomicString& fantasyFontFamily(UScriptCode = USCRIPT_COMMON) const; 86 87 void setPictographFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON); 88 const AtomicString& pictographFontFamily(UScriptCode = USCRIPT_COMMON) const; 89 90#if ENABLE(TEXT_AUTOSIZING) 91 void setTextAutosizingEnabled(bool); 92 bool textAutosizingEnabled() const { return m_textAutosizingEnabled; } 93 94 void setTextAutosizingFontScaleFactor(float); 95 float textAutosizingFontScaleFactor() const { return m_textAutosizingFontScaleFactor; } 96 97 // Only set by Layout Tests, and only used if textAutosizingEnabled() returns true. 98 void setTextAutosizingWindowSizeOverride(const IntSize&); 99 const IntSize& textAutosizingWindowSizeOverride() const { return m_textAutosizingWindowSizeOverride; } 100#endif 101 102 // Only set by Layout Tests. 103 void setMediaTypeOverride(const String&); 104 const String& mediaTypeOverride() const { return m_mediaTypeOverride; } 105 106 // Unlike areImagesEnabled, this only suppresses the network load of 107 // the image URL. A cached image will still be rendered if requested. 108 void setLoadsImagesAutomatically(bool); 109 bool loadsImagesAutomatically() const { return m_loadsImagesAutomatically; } 110 111 // Clients that execute script should call ScriptController::canExecuteScripts() 112 // instead of this function. ScriptController::canExecuteScripts() checks the 113 // HTML sandbox, plug-in sandboxing, and other important details. 114 bool isScriptEnabled() const { return m_isScriptEnabled; } 115 void setScriptEnabled(bool); 116 117 SETTINGS_GETTERS_AND_SETTERS 118 119 void setScreenFontSubstitutionEnabled(bool); 120 bool screenFontSubstitutionEnabled() const { return m_screenFontSubstitutionEnabled; } 121 122 void setJavaEnabled(bool); 123 bool isJavaEnabled() const { return m_isJavaEnabled; } 124 125 // This settings is only consulted if isJavaEnabled() returns true; 126 void setJavaEnabledForLocalFiles(bool); 127 bool isJavaEnabledForLocalFiles() const { return m_isJavaEnabledForLocalFiles; } 128 129 void setImagesEnabled(bool); 130 bool areImagesEnabled() const { return m_areImagesEnabled; } 131 132 void setPluginsEnabled(bool); 133 bool arePluginsEnabled() const { return m_arePluginsEnabled; } 134 135 // When this option is set, WebCore will avoid storing any record of browsing activity 136 // that may persist on disk or remain displayed when the option is reset. 137 // This option does not affect the storage of such information in RAM. 138 // The following functions respect this setting: 139 // - HTML5/DOM Storage 140 // - Icon Database 141 // - Console Messages 142 // - MemoryCache 143 // - Application Cache 144 // - Back/Forward Page History 145 // - Page Search Results 146 // - HTTP Cookies 147 // - Plug-ins (that support NPNVprivateModeBool) 148 void setPrivateBrowsingEnabled(bool); 149 150 void setDNSPrefetchingEnabled(bool); 151 bool dnsPrefetchingEnabled() const { return m_dnsPrefetchingEnabled; } 152 153 void setUserStyleSheetLocation(const URL&); 154 const URL& 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 double domTimerAlignmentInterval() const; 172 173 void setLayoutInterval(std::chrono::milliseconds); 174 std::chrono::milliseconds layoutInterval() const { return m_layoutInterval; } 175 176#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING) 177 bool hiddenPageDOMTimerThrottlingEnabled() const { return m_hiddenPageDOMTimerThrottlingEnabled; } 178 void setHiddenPageDOMTimerThrottlingEnabled(bool); 179#endif 180 181 void setUsesPageCache(bool); 182 bool usesPageCache() const { return m_usesPageCache; } 183 184 void setFontRenderingMode(FontRenderingMode mode); 185 FontRenderingMode fontRenderingMode() const; 186 187 void setShowTiledScrollingIndicator(bool); 188 bool showTiledScrollingIndicator() const { return m_showTiledScrollingIndicator; } 189 190#if PLATFORM(WIN) 191 static void setShouldUseHighResolutionTimers(bool); 192 static bool shouldUseHighResolutionTimers() { return gShouldUseHighResolutionTimers; } 193#endif 194 195 void setBackgroundShouldExtendBeyondPage(bool); 196 bool backgroundShouldExtendBeyondPage() const { return m_backgroundShouldExtendBeyondPage; } 197 198#if USE(AVFOUNDATION) 199 static void setAVFoundationEnabled(bool flag); 200 static bool isAVFoundationEnabled() { return gAVFoundationEnabled; } 201#endif 202 203#if PLATFORM(COCOA) 204 static void setQTKitEnabled(bool flag); 205 static bool isQTKitEnabled() { return gQTKitEnabled; } 206#endif 207 208 static const unsigned defaultMaximumHTMLParserDOMTreeDepth = 512; 209 210#if USE(SAFARI_THEME) 211 // Windows debugging pref (global) for switching between the Aqua look and a native windows look. 212 static void setShouldPaintNativeControls(bool); 213 static bool shouldPaintNativeControls() { return gShouldPaintNativeControls; } 214#endif 215 216 static void setMockScrollbarsEnabled(bool flag); 217 static bool mockScrollbarsEnabled(); 218 219 static void setUsesOverlayScrollbars(bool flag); 220 static bool usesOverlayScrollbars(); 221 222#if ENABLE(TOUCH_EVENTS) 223 void setTouchEventEmulationEnabled(bool enabled) { m_touchEventEmulationEnabled = enabled; } 224 bool isTouchEventEmulationEnabled() const { return m_touchEventEmulationEnabled; } 225#endif 226 227 void setStorageBlockingPolicy(SecurityOrigin::StorageBlockingPolicy); 228 SecurityOrigin::StorageBlockingPolicy storageBlockingPolicy() const { return m_storageBlockingPolicy; } 229 230 void setScrollingPerformanceLoggingEnabled(bool); 231 bool scrollingPerformanceLoggingEnabled() { return m_scrollingPerformanceLoggingEnabled; } 232 233 static void setShouldRespectPriorityInCSSAttributeSetters(bool); 234 static bool shouldRespectPriorityInCSSAttributeSetters(); 235 236 void setTimeWithoutMouseMovementBeforeHidingControls(double time) { m_timeWithoutMouseMovementBeforeHidingControls = time; } 237 double timeWithoutMouseMovementBeforeHidingControls() const { return m_timeWithoutMouseMovementBeforeHidingControls; } 238 239 bool hiddenPageCSSAnimationSuspensionEnabled() const { return m_hiddenPageCSSAnimationSuspensionEnabled; } 240 void setHiddenPageCSSAnimationSuspensionEnabled(bool); 241 242 void setFontFallbackPrefersPictographs(bool); 243 bool fontFallbackPrefersPictographs() const { return m_fontFallbackPrefersPictographs; } 244 245 static bool lowPowerVideoAudioBufferSizeEnabled() { return gLowPowerVideoAudioBufferSizeEnabled; } 246 static void setLowPowerVideoAudioBufferSizeEnabled(bool); 247 248#if PLATFORM(IOS) 249 static void setAudioSessionCategoryOverride(unsigned); 250 static unsigned audioSessionCategoryOverride(); 251 252 static void setNetworkDataUsageTrackingEnabled(bool); 253 static bool networkDataUsageTrackingEnabled(); 254 255 static void setNetworkInterfaceName(const String&); 256 static const String& networkInterfaceName(); 257 258 static void setAVKitEnabled(bool flag) { gAVKitEnabled = flag; } 259 static bool avKitEnabled() { return gAVKitEnabled; } 260 261 static void setShouldOptOutOfNetworkStateObservation(bool flag) { gShouldOptOutOfNetworkStateObservation = flag; } 262 static bool shouldOptOutOfNetworkStateObservation() { return gShouldOptOutOfNetworkStateObservation; } 263 264 static void setShouldManageAudioSessionCategory(bool flag) { gManageAudioSession = flag; } 265 static bool shouldManageAudioSessionCategory() { return gManageAudioSession; } 266#endif 267 268private: 269 explicit Settings(Page*); 270 271 void initializeDefaultFontFamilies(); 272 static bool shouldEnableScreenFontSubstitutionByDefault(); 273 274 Page* m_page; 275 276 String m_mediaTypeOverride; 277 URL m_userStyleSheetLocation; 278 const std::unique_ptr<FontGenericFamilies> m_fontGenericFamilies; 279 SecurityOrigin::StorageBlockingPolicy m_storageBlockingPolicy; 280 std::chrono::milliseconds m_layoutInterval; 281#if ENABLE(TEXT_AUTOSIZING) 282 float m_textAutosizingFontScaleFactor; 283 IntSize m_textAutosizingWindowSizeOverride; 284 bool m_textAutosizingEnabled : 1; 285#endif 286 287 SETTINGS_MEMBER_VARIABLES 288 289 bool m_screenFontSubstitutionEnabled : 1; 290 bool m_isJavaEnabled : 1; 291 bool m_isJavaEnabledForLocalFiles : 1; 292 bool m_loadsImagesAutomatically : 1; 293 bool m_areImagesEnabled : 1; 294 bool m_arePluginsEnabled : 1; 295 bool m_isScriptEnabled : 1; 296 bool m_needsAdobeFrameReloadingQuirk : 1; 297 bool m_usesPageCache : 1; 298 unsigned m_fontRenderingMode : 1; 299 bool m_showTiledScrollingIndicator : 1; 300 bool m_backgroundShouldExtendBeyondPage : 1; 301 bool m_dnsPrefetchingEnabled : 1; 302 303#if ENABLE(TOUCH_EVENTS) 304 bool m_touchEventEmulationEnabled : 1; 305#endif 306 bool m_scrollingPerformanceLoggingEnabled : 1; 307 308 double m_timeWithoutMouseMovementBeforeHidingControls; 309 310 Timer<Settings> m_setImageLoadingSettingsTimer; 311 void imageLoadingSettingsTimerFired(Timer<Settings>*); 312 313#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING) 314 bool m_hiddenPageDOMTimerThrottlingEnabled : 1; 315#endif 316 bool m_hiddenPageCSSAnimationSuspensionEnabled : 1; 317 bool m_fontFallbackPrefersPictographs : 1; 318 319 static double gDefaultMinDOMTimerInterval; 320 static double gDefaultDOMTimerAlignmentInterval; 321 322#if USE(AVFOUNDATION) 323 static bool gAVFoundationEnabled; 324#endif 325 326#if PLATFORM(COCOA) 327 static bool gQTKitEnabled; 328#endif 329 330 static bool gMockScrollbarsEnabled; 331 static bool gUsesOverlayScrollbars; 332 333#if USE(SAFARI_THEME) 334 static bool gShouldPaintNativeControls; 335#endif 336#if PLATFORM(WIN) 337 static bool gShouldUseHighResolutionTimers; 338#endif 339 static bool gShouldRespectPriorityInCSSAttributeSetters; 340#if PLATFORM(IOS) 341 static bool gNetworkDataUsageTrackingEnabled; 342 static bool gAVKitEnabled; 343 static bool gShouldOptOutOfNetworkStateObservation; 344 static bool gManageAudioSession; 345#endif 346 347 static double gHiddenPageDOMTimerAlignmentInterval; 348 349 static bool gLowPowerVideoAudioBufferSizeEnabled; 350}; 351 352} // namespace WebCore 353 354#endif 355