2 * Copyright (C) 2003-2016 Apple Inc. All rights reserved.
3 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include "ClipboardAccessPolicy.h"
30 #include "ContentType.h"
31 #include "EditingBehaviorTypes.h"
33 #include "SecurityOrigin.h"
34 #include "SettingsMacros.h"
35 #include "TextFlags.h"
38 #include "WritingMode.h"
39 #include <runtime/RuntimeFlags.h>
40 #include <unicode/uscript.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/RefCounted.h>
43 #include <wtf/text/AtomicString.h>
44 #include <wtf/text/AtomicStringHash.h>
46 #if ENABLE(DATA_DETECTION)
47 #include "DataDetection.h"
52 class FontGenericFamilies;
55 enum EditableLinkBehavior {
56 EditableLinkDefaultBehavior,
57 EditableLinkAlwaysLive,
58 EditableLinkOnlyLiveWithShiftKey,
59 EditableLinkLiveWhenNotFocused,
63 enum TextDirectionSubmenuInclusionBehavior {
64 TextDirectionSubmenuNeverIncluded,
65 TextDirectionSubmenuAutomaticallyIncluded,
66 TextDirectionSubmenuAlwaysIncluded
69 enum DebugOverlayRegionFlags {
70 NonFastScrollableRegion = 1 << 0,
71 WheelEventHandlerRegion = 1 << 1,
74 enum class UserInterfaceDirectionPolicy {
79 enum PDFImageCachingPolicy {
80 PDFImageCachingEnabled,
81 PDFImageCachingBelowMemoryLimit,
82 PDFImageCachingDisabled,
83 PDFImageCachingClipBoundsOnly,
85 PDFImageCachingDefault = PDFImageCachingBelowMemoryLimit
87 PDFImageCachingDefault = PDFImageCachingEnabled
91 typedef unsigned DebugOverlayRegions;
93 class Settings : public RefCounted<Settings> {
94 WTF_MAKE_NONCOPYABLE(Settings); WTF_MAKE_FAST_ALLOCATED;
96 static Ref<Settings> create(Page*);
99 void pageDestroyed() { m_page = nullptr; }
101 enum class ForcedAccessibilityValue { System, On, Off };
102 static const Settings::ForcedAccessibilityValue defaultForcedColorsAreInvertedAccessibilityValue = ForcedAccessibilityValue::System;
103 static const Settings::ForcedAccessibilityValue defaultForcedDisplayIsMonochromeAccessibilityValue = ForcedAccessibilityValue::System;
104 static const Settings::ForcedAccessibilityValue defaultForcedPrefersReducedMotionAccessibilityValue = ForcedAccessibilityValue::System;
106 WEBCORE_EXPORT void setStandardFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
107 WEBCORE_EXPORT const AtomicString& standardFontFamily(UScriptCode = USCRIPT_COMMON) const;
109 WEBCORE_EXPORT void setFixedFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
110 WEBCORE_EXPORT const AtomicString& fixedFontFamily(UScriptCode = USCRIPT_COMMON) const;
112 WEBCORE_EXPORT void setSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
113 WEBCORE_EXPORT const AtomicString& serifFontFamily(UScriptCode = USCRIPT_COMMON) const;
115 WEBCORE_EXPORT void setSansSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
116 WEBCORE_EXPORT const AtomicString& sansSerifFontFamily(UScriptCode = USCRIPT_COMMON) const;
118 WEBCORE_EXPORT void setCursiveFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
119 WEBCORE_EXPORT const AtomicString& cursiveFontFamily(UScriptCode = USCRIPT_COMMON) const;
121 WEBCORE_EXPORT void setFantasyFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
122 WEBCORE_EXPORT const AtomicString& fantasyFontFamily(UScriptCode = USCRIPT_COMMON) const;
124 WEBCORE_EXPORT void setPictographFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
125 WEBCORE_EXPORT const AtomicString& pictographFontFamily(UScriptCode = USCRIPT_COMMON) const;
127 WEBCORE_EXPORT static bool defaultTextAutosizingEnabled();
128 WEBCORE_EXPORT static float defaultMinimumZoomFontSize();
130 // Only set by Layout Tests.
131 WEBCORE_EXPORT void setMediaTypeOverride(const String&);
132 const String& mediaTypeOverride() const { return m_mediaTypeOverride; }
134 // Unlike areImagesEnabled, this only suppresses the network load of
135 // the image URL. A cached image will still be rendered if requested.
136 WEBCORE_EXPORT void setLoadsImagesAutomatically(bool);
137 bool loadsImagesAutomatically() const { return m_loadsImagesAutomatically; }
139 // Clients that execute script should call ScriptController::canExecuteScripts()
140 // instead of this function. ScriptController::canExecuteScripts() checks the
141 // HTML sandbox, plug-in sandboxing, and other important details.
142 bool isScriptEnabled() const { return m_isScriptEnabled; }
143 WEBCORE_EXPORT void setScriptEnabled(bool);
145 SETTINGS_GETTERS_AND_SETTERS
147 WEBCORE_EXPORT void setJavaEnabled(bool);
148 bool isJavaEnabled() const { return m_isJavaEnabled; }
150 // This settings is only consulted if isJavaEnabled() returns true;
151 WEBCORE_EXPORT void setJavaEnabledForLocalFiles(bool);
152 bool isJavaEnabledForLocalFiles() const { return m_isJavaEnabledForLocalFiles; }
154 WEBCORE_EXPORT void setImagesEnabled(bool);
155 bool areImagesEnabled() const { return m_areImagesEnabled; }
157 WEBCORE_EXPORT void setPreferMIMETypeForImages(bool);
158 bool preferMIMETypeForImages() const { return m_preferMIMETypeForImages; }
160 WEBCORE_EXPORT void setPluginsEnabled(bool);
161 bool arePluginsEnabled() const { return m_arePluginsEnabled; }
163 WEBCORE_EXPORT void setDNSPrefetchingEnabled(bool);
164 bool dnsPrefetchingEnabled() const { return m_dnsPrefetchingEnabled; }
166 WEBCORE_EXPORT void setUserStyleSheetLocation(const URL&);
167 const URL& userStyleSheetLocation() const { return m_userStyleSheetLocation; }
169 WEBCORE_EXPORT void setNeedsAdobeFrameReloadingQuirk(bool);
170 bool needsAcrobatFrameReloadingQuirk() const { return m_needsAdobeFrameReloadingQuirk; }
172 WEBCORE_EXPORT void setMinimumDOMTimerInterval(Seconds); // Initialized to DOMTimer::defaultMinimumInterval().
173 Seconds minimumDOMTimerInterval() const { return m_minimumDOMTimerInterval; }
175 WEBCORE_EXPORT void setLayoutInterval(Seconds);
176 Seconds layoutInterval() const { return m_layoutInterval; }
178 bool hiddenPageDOMTimerThrottlingEnabled() const { return m_hiddenPageDOMTimerThrottlingEnabled; }
179 WEBCORE_EXPORT void setHiddenPageDOMTimerThrottlingEnabled(bool);
180 bool hiddenPageDOMTimerThrottlingAutoIncreases() const { return m_hiddenPageDOMTimerThrottlingAutoIncreases; }
181 WEBCORE_EXPORT void setHiddenPageDOMTimerThrottlingAutoIncreases(bool);
183 WEBCORE_EXPORT void setUsesPageCache(bool);
184 bool usesPageCache() const { return m_usesPageCache; }
186 void setFontRenderingMode(FontRenderingMode mode);
187 FontRenderingMode fontRenderingMode() const;
189 WEBCORE_EXPORT void setShowTiledScrollingIndicator(bool);
190 bool showTiledScrollingIndicator() const { return m_showTiledScrollingIndicator; }
192 #if ENABLE(RESOURCE_USAGE)
193 bool resourceUsageOverlayVisible() const { return m_resourceUsageOverlayVisible; }
194 WEBCORE_EXPORT void setResourceUsageOverlayVisible(bool);
198 static void setShouldUseHighResolutionTimers(bool);
199 static bool shouldUseHighResolutionTimers() { return gShouldUseHighResolutionTimers; }
202 static bool isPostLoadCPUUsageMeasurementEnabled();
203 static bool isPostBackgroundingCPUUsageMeasurementEnabled();
204 static bool isPerActivityStateCPUUsageMeasurementEnabled();
206 static bool isPostLoadMemoryUsageMeasurementEnabled();
207 static bool isPostBackgroundingMemoryUsageMeasurementEnabled();
209 static bool globalConstRedeclarationShouldThrow();
211 WEBCORE_EXPORT void setBackgroundShouldExtendBeyondPage(bool);
212 bool backgroundShouldExtendBeyondPage() const { return m_backgroundShouldExtendBeyondPage; }
214 #if USE(AVFOUNDATION)
215 WEBCORE_EXPORT static void setAVFoundationEnabled(bool flag);
216 static bool isAVFoundationEnabled() { return gAVFoundationEnabled; }
217 WEBCORE_EXPORT static void setAVFoundationNSURLSessionEnabled(bool flag);
218 static bool isAVFoundationNSURLSessionEnabled() { return gAVFoundationNSURLSessionEnabled; }
222 WEBCORE_EXPORT static void setQTKitEnabled(bool flag);
223 static bool isQTKitEnabled() { return gQTKitEnabled; }
225 static bool isQTKitEnabled() { return false; }
229 WEBCORE_EXPORT static void setGStreamerEnabled(bool flag);
230 static bool isGStreamerEnabled() { return gGStreamerEnabled; }
233 static const unsigned defaultMaximumHTMLParserDOMTreeDepth = 512;
234 static const unsigned defaultMaximumRenderTreeDepth = 512;
236 WEBCORE_EXPORT static void setMockScrollbarsEnabled(bool flag);
237 WEBCORE_EXPORT static bool mockScrollbarsEnabled();
239 WEBCORE_EXPORT static void setUsesOverlayScrollbars(bool flag);
240 static bool usesOverlayScrollbars();
242 WEBCORE_EXPORT static void setUsesMockScrollAnimator(bool);
243 static bool usesMockScrollAnimator();
245 #if ENABLE(TOUCH_EVENTS)
246 void setTouchEventEmulationEnabled(bool enabled) { m_touchEventEmulationEnabled = enabled; }
247 bool isTouchEventEmulationEnabled() const { return m_touchEventEmulationEnabled; }
250 WEBCORE_EXPORT void setStorageBlockingPolicy(SecurityOrigin::StorageBlockingPolicy);
251 SecurityOrigin::StorageBlockingPolicy storageBlockingPolicy() const { return m_storageBlockingPolicy; }
253 WEBCORE_EXPORT void setScrollingPerformanceLoggingEnabled(bool);
254 bool scrollingPerformanceLoggingEnabled() { return m_scrollingPerformanceLoggingEnabled; }
256 WEBCORE_EXPORT static void setShouldRespectPriorityInCSSAttributeSetters(bool);
257 static bool shouldRespectPriorityInCSSAttributeSetters();
259 void setTimeWithoutMouseMovementBeforeHidingControls(Seconds time) { m_timeWithoutMouseMovementBeforeHidingControls = time; }
260 Seconds timeWithoutMouseMovementBeforeHidingControls() const { return m_timeWithoutMouseMovementBeforeHidingControls; }
262 bool hiddenPageCSSAnimationSuspensionEnabled() const { return m_hiddenPageCSSAnimationSuspensionEnabled; }
263 WEBCORE_EXPORT void setHiddenPageCSSAnimationSuspensionEnabled(bool);
265 WEBCORE_EXPORT void setFontFallbackPrefersPictographs(bool);
266 bool fontFallbackPrefersPictographs() const { return m_fontFallbackPrefersPictographs; }
268 WEBCORE_EXPORT void setWebFontsAlwaysFallBack(bool);
269 bool webFontsAlwaysFallBack() const { return m_webFontsAlwaysFallBack; }
271 static bool lowPowerVideoAudioBufferSizeEnabled() { return gLowPowerVideoAudioBufferSizeEnabled; }
272 WEBCORE_EXPORT static void setLowPowerVideoAudioBufferSizeEnabled(bool);
274 static bool resourceLoadStatisticsEnabled() { return gResourceLoadStatisticsEnabledEnabled; }
275 WEBCORE_EXPORT static void setResourceLoadStatisticsEnabled(bool);
278 WEBCORE_EXPORT static void setAudioSessionCategoryOverride(unsigned);
279 static unsigned audioSessionCategoryOverride();
281 WEBCORE_EXPORT static void setNetworkDataUsageTrackingEnabled(bool);
282 static bool networkDataUsageTrackingEnabled();
284 WEBCORE_EXPORT static void setNetworkInterfaceName(const String&);
285 static const String& networkInterfaceName();
288 static void setAVKitEnabled(bool flag) { gAVKitEnabled = flag; }
290 static bool avKitEnabled() { return gAVKitEnabled; }
292 static void setShouldOptOutOfNetworkStateObservation(bool flag) { gShouldOptOutOfNetworkStateObservation = flag; }
293 static bool shouldOptOutOfNetworkStateObservation() { return gShouldOptOutOfNetworkStateObservation; }
296 #if USE(AUDIO_SESSION)
297 static void setShouldManageAudioSessionCategory(bool flag) { gManageAudioSession = flag; }
298 static bool shouldManageAudioSessionCategory() { return gManageAudioSession; }
301 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
302 void setMediaKeysStorageDirectory(const String& directory) { m_mediaKeysStorageDirectory = directory; }
303 const String& mediaKeysStorageDirectory() const { return m_mediaKeysStorageDirectory; }
306 #if ENABLE(MEDIA_STREAM)
307 void setMediaDeviceIdentifierStorageDirectory(const String& directory) { m_mediaDeviceIdentifierStorageDirectory = directory; }
308 const String& mediaDeviceIdentifierStorageDirectory() const { return m_mediaDeviceIdentifierStorageDirectory; }
310 static bool mockCaptureDevicesEnabled();
311 WEBCORE_EXPORT static void setMockCaptureDevicesEnabled(bool);
313 bool mediaCaptureRequiresSecureConnection() const;
314 WEBCORE_EXPORT static void setMediaCaptureRequiresSecureConnection(bool);
317 #if ENABLE(APPLE_PAY)
318 bool applePayEnabled() const { return m_applePayEnabled; }
319 void setApplePayEnabled(bool applePayEnabled) { m_applePayEnabled = applePayEnabled; }
321 bool applePayCapabilityDisclosureAllowed() const { return m_applePayCapabilityDisclosureAllowed; }
322 void setApplePayCapabilityDisclosureAllowed(bool applePayCapabilityDisclosureAllowed) { m_applePayCapabilityDisclosureAllowed = applePayCapabilityDisclosureAllowed; }
325 WEBCORE_EXPORT void setForcePendingWebGLPolicy(bool);
326 bool isForcePendingWebGLPolicy() const { return m_forcePendingWebGLPolicy; }
328 WEBCORE_EXPORT static void setAllowsAnySSLCertificate(bool);
329 static bool allowsAnySSLCertificate();
331 WEBCORE_EXPORT static const String& defaultMediaContentTypesRequiringHardwareSupport();
332 WEBCORE_EXPORT void setMediaContentTypesRequiringHardwareSupport(const Vector<ContentType>&);
333 WEBCORE_EXPORT void setMediaContentTypesRequiringHardwareSupport(const String&);
334 const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const { return m_mediaContentTypesRequiringHardwareSupport; }
337 explicit Settings(Page*);
339 void initializeDefaultFontFamilies();
343 String m_mediaTypeOverride;
344 URL m_userStyleSheetLocation;
345 const std::unique_ptr<FontGenericFamilies> m_fontGenericFamilies;
346 SecurityOrigin::StorageBlockingPolicy m_storageBlockingPolicy;
347 Seconds m_layoutInterval;
348 Seconds m_minimumDOMTimerInterval;
350 SETTINGS_MEMBER_VARIABLES
352 bool m_isJavaEnabled : 1;
353 bool m_isJavaEnabledForLocalFiles : 1;
354 bool m_loadsImagesAutomatically : 1;
355 bool m_areImagesEnabled : 1;
356 bool m_preferMIMETypeForImages : 1;
357 bool m_arePluginsEnabled : 1;
358 bool m_isScriptEnabled : 1;
359 bool m_needsAdobeFrameReloadingQuirk : 1;
360 bool m_usesPageCache : 1;
361 unsigned m_fontRenderingMode : 1;
362 bool m_showTiledScrollingIndicator : 1;
363 bool m_backgroundShouldExtendBeyondPage : 1;
364 bool m_dnsPrefetchingEnabled : 1;
366 #if ENABLE(TOUCH_EVENTS)
367 bool m_touchEventEmulationEnabled : 1;
369 bool m_scrollingPerformanceLoggingEnabled : 1;
371 Seconds m_timeWithoutMouseMovementBeforeHidingControls;
373 Timer m_setImageLoadingSettingsTimer;
374 void imageLoadingSettingsTimerFired();
376 bool m_hiddenPageDOMTimerThrottlingEnabled : 1;
377 bool m_hiddenPageCSSAnimationSuspensionEnabled : 1;
378 bool m_fontFallbackPrefersPictographs : 1;
379 bool m_webFontsAlwaysFallBack : 1;
381 bool m_forcePendingWebGLPolicy : 1;
383 #if ENABLE(RESOURCE_USAGE)
384 bool m_resourceUsageOverlayVisible { false };
387 bool m_hiddenPageDOMTimerThrottlingAutoIncreases { false };
389 #if USE(AVFOUNDATION)
390 WEBCORE_EXPORT static bool gAVFoundationEnabled;
391 WEBCORE_EXPORT static bool gAVFoundationNSURLSessionEnabled;
395 WEBCORE_EXPORT static bool gQTKitEnabled;
399 WEBCORE_EXPORT static bool gGStreamerEnabled;
402 static bool gMockScrollbarsEnabled;
403 static bool gUsesOverlayScrollbars;
404 static bool gMockScrollAnimatorEnabled;
407 static bool gShouldUseHighResolutionTimers;
409 static bool gShouldRespectPriorityInCSSAttributeSetters;
411 static bool gNetworkDataUsageTrackingEnabled;
412 WEBCORE_EXPORT static bool gAVKitEnabled;
413 WEBCORE_EXPORT static bool gShouldOptOutOfNetworkStateObservation;
415 WEBCORE_EXPORT static bool gManageAudioSession;
417 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
418 String m_mediaKeysStorageDirectory;
421 #if ENABLE(MEDIA_STREAM)
422 String m_mediaDeviceIdentifierStorageDirectory;
423 static bool gMockCaptureDevicesEnabled;
424 static bool gMediaCaptureRequiresSecureConnection;
427 #if ENABLE(APPLE_PAY)
428 bool m_applePayEnabled { false };
429 bool m_applePayCapabilityDisclosureAllowed { true };
432 static bool gLowPowerVideoAudioBufferSizeEnabled;
433 static bool gResourceLoadStatisticsEnabledEnabled;
434 static bool gAllowsAnySSLCertificate;
436 Vector<ContentType> m_mediaContentTypesRequiringHardwareSupport;
439 inline bool Settings::isPostLoadCPUUsageMeasurementEnabled()
448 inline bool Settings::isPostBackgroundingCPUUsageMeasurementEnabled()
457 inline bool Settings::isPerActivityStateCPUUsageMeasurementEnabled()
466 inline bool Settings::isPostLoadMemoryUsageMeasurementEnabled()
475 inline bool Settings::isPostBackgroundingMemoryUsageMeasurementEnabled()
484 } // namespace WebCore