Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebCore / page / SettingsBase.h
1 /*
2  * Copyright (C) 2003-2016 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 #pragma once
28
29 #include "ClipboardAccessPolicy.h"
30 #include "ContentType.h"
31 #include "EditingBehaviorTypes.h"
32 #include "IntSize.h"
33 #include "SecurityOrigin.h"
34 #include "StorageMap.h"
35 #include "TextFlags.h"
36 #include "Timer.h"
37 #include <wtf/URL.h>
38 #include "WritingMode.h"
39 #include <JavaScriptCore/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>
45
46 #if ENABLE(DATA_DETECTION)
47 #include "DataDetection.h"
48 #endif
49
50 namespace WebCore {
51
52 class FontGenericFamilies;
53 class Page;
54
55 enum EditableLinkBehavior {
56     EditableLinkDefaultBehavior,
57     EditableLinkAlwaysLive,
58     EditableLinkOnlyLiveWithShiftKey,
59     EditableLinkLiveWhenNotFocused,
60     EditableLinkNeverLive
61 };
62
63 enum TextDirectionSubmenuInclusionBehavior {
64     TextDirectionSubmenuNeverIncluded,
65     TextDirectionSubmenuAutomaticallyIncluded,
66     TextDirectionSubmenuAlwaysIncluded
67 };
68
69 enum DebugOverlayRegionFlags {
70     NonFastScrollableRegion = 1 << 0,
71     WheelEventHandlerRegion = 1 << 1,
72 };
73
74 enum class UserInterfaceDirectionPolicy {
75     Content,
76     System
77 };
78
79 enum PDFImageCachingPolicy {
80     PDFImageCachingEnabled,
81     PDFImageCachingBelowMemoryLimit,
82     PDFImageCachingDisabled,
83     PDFImageCachingClipBoundsOnly,
84 #if PLATFORM(IOS_FAMILY)
85     PDFImageCachingDefault = PDFImageCachingBelowMemoryLimit
86 #else
87     PDFImageCachingDefault = PDFImageCachingEnabled
88 #endif
89 };
90
91 enum class FrameFlattening {
92     Disabled,
93     EnabledForNonFullScreenIFrames,
94     FullyEnabled
95 };
96
97 typedef unsigned DebugOverlayRegions;
98
99 class SettingsBase {
100     WTF_MAKE_NONCOPYABLE(SettingsBase); WTF_MAKE_FAST_ALLOCATED;
101 public:
102     ~SettingsBase();
103
104     void pageDestroyed() { m_page = nullptr; }
105
106     enum class FontLoadTimingOverride { None, Block, Swap, Failure };
107
108     // FIXME: Move these default values to SettingsDefaultValues.h
109
110     enum class ForcedAccessibilityValue { System, On, Off };
111     static const SettingsBase::ForcedAccessibilityValue defaultForcedColorsAreInvertedAccessibilityValue = ForcedAccessibilityValue::System;
112     static const SettingsBase::ForcedAccessibilityValue defaultForcedDisplayIsMonochromeAccessibilityValue = ForcedAccessibilityValue::System;
113     static const SettingsBase::ForcedAccessibilityValue defaultForcedPrefersReducedMotionAccessibilityValue = ForcedAccessibilityValue::System;
114
115     WEBCORE_EXPORT static bool defaultTextAutosizingEnabled();
116     WEBCORE_EXPORT static float defaultMinimumZoomFontSize();
117     WEBCORE_EXPORT static bool defaultDownloadableBinaryFontsEnabled();
118
119     static const unsigned defaultMaximumHTMLParserDOMTreeDepth = 512;
120     static const unsigned defaultMaximumRenderTreeDepth = 512;
121
122 #if ENABLE(TEXT_AUTOSIZING)
123     constexpr static const float boostedOneLineTextMultiplierCoefficient = 2.23125f;
124     constexpr static const float boostedMultiLineTextMultiplierCoefficient = 2.48125f;
125     constexpr static const float boostedMaxTextAutosizingScaleIncrease = 5.0f;
126     constexpr static const float defaultOneLineTextMultiplierCoefficient = 1.7f;
127     constexpr static const float defaultMultiLineTextMultiplierCoefficient = 1.95f;
128     constexpr static const float defaultMaxTextAutosizingScaleIncrease = 1.7f;
129 #endif
130
131     WEBCORE_EXPORT void setStandardFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
132     WEBCORE_EXPORT const AtomicString& standardFontFamily(UScriptCode = USCRIPT_COMMON) const;
133
134     WEBCORE_EXPORT void setFixedFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
135     WEBCORE_EXPORT const AtomicString& fixedFontFamily(UScriptCode = USCRIPT_COMMON) const;
136
137     WEBCORE_EXPORT void setSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
138     WEBCORE_EXPORT const AtomicString& serifFontFamily(UScriptCode = USCRIPT_COMMON) const;
139
140     WEBCORE_EXPORT void setSansSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
141     WEBCORE_EXPORT const AtomicString& sansSerifFontFamily(UScriptCode = USCRIPT_COMMON) const;
142
143     WEBCORE_EXPORT void setCursiveFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
144     WEBCORE_EXPORT const AtomicString& cursiveFontFamily(UScriptCode = USCRIPT_COMMON) const;
145
146     WEBCORE_EXPORT void setFantasyFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
147     WEBCORE_EXPORT const AtomicString& fantasyFontFamily(UScriptCode = USCRIPT_COMMON) const;
148
149     WEBCORE_EXPORT void setPictographFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
150     WEBCORE_EXPORT const AtomicString& pictographFontFamily(UScriptCode = USCRIPT_COMMON) const;
151
152     WEBCORE_EXPORT void setMinimumDOMTimerInterval(Seconds); // Initialized to DOMTimer::defaultMinimumInterval().
153     Seconds minimumDOMTimerInterval() const { return m_minimumDOMTimerInterval; }
154
155     WEBCORE_EXPORT void setLayoutInterval(Seconds);
156     Seconds layoutInterval() const { return m_layoutInterval; }
157
158 #if ENABLE(TEXT_AUTOSIZING)
159     float oneLineTextMultiplierCoefficient() const { return m_oneLineTextMultiplierCoefficient; }
160     float multiLineTextMultiplierCoefficient() const { return m_multiLineTextMultiplierCoefficient; }
161     float maxTextAutosizingScaleIncrease() const { return m_maxTextAutosizingScaleIncrease; }
162 #endif
163
164     WEBCORE_EXPORT static const String& defaultMediaContentTypesRequiringHardwareSupport();
165     WEBCORE_EXPORT void setMediaContentTypesRequiringHardwareSupport(const Vector<ContentType>&);
166     WEBCORE_EXPORT void setMediaContentTypesRequiringHardwareSupport(const String&);
167     const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const { return m_mediaContentTypesRequiringHardwareSupport; }
168
169 protected:
170     explicit SettingsBase(Page*);
171
172     void initializeDefaultFontFamilies();
173
174     void imageLoadingSettingsTimerFired();
175
176     // Helpers used by generated Settings.cpp.
177     void setNeedsRecalcStyleInAllFrames();
178     void setNeedsRelayoutAllFrames();
179     void mediaTypeOverrideChanged();
180     void imagesEnabledChanged();
181     void pluginsEnabledChanged();
182     void userStyleSheetLocationChanged();
183     void usesPageCacheChanged();
184     void dnsPrefetchingEnabledChanged();
185     void storageBlockingPolicyChanged();
186     void backgroundShouldExtendBeyondPageChanged();
187     void scrollingPerformanceLoggingEnabledChanged();
188     void hiddenPageDOMTimerThrottlingStateChanged();
189     void hiddenPageCSSAnimationSuspensionEnabledChanged();
190     void resourceUsageOverlayVisibleChanged();
191 #if ENABLE(TEXT_AUTOSIZING)
192     void shouldEnableTextAutosizingBoostChanged();
193 #endif
194
195     Page* m_page;
196
197     const std::unique_ptr<FontGenericFamilies> m_fontGenericFamilies;
198     Seconds m_layoutInterval;
199     Seconds m_minimumDOMTimerInterval;
200
201     Timer m_setImageLoadingSettingsTimer;
202
203     Vector<ContentType> m_mediaContentTypesRequiringHardwareSupport;
204
205 #if ENABLE(TEXT_AUTOSIZING)
206     float m_oneLineTextMultiplierCoefficient { defaultOneLineTextMultiplierCoefficient };
207     float m_multiLineTextMultiplierCoefficient { defaultMultiLineTextMultiplierCoefficient };
208     float m_maxTextAutosizingScaleIncrease { defaultMaxTextAutosizingScaleIncrease };
209 #endif
210
211 #if USE(APPLE_INTERNAL_SDK)
212 #include <WebKitAdditions/SettingsAdditions.h>
213 #endif
214 };
215
216 } // namespace WebCore