1/*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
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 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29// FIXME (121927): This include should not be needed.
30#include <wtf/text/AtomStringHash.h>
31
32#include "EditingBehaviorTypes.h"
33#include "ExceptionOr.h"
34#include "FontGenericFamilies.h"
35#include "IntSize.h"
36#include "InternalSettingsGenerated.h"
37#include "SecurityOrigin.h"
38#include "Settings.h"
39#include "WritingMode.h"
40
41namespace WebCore {
42
43class Page;
44class Settings;
45
46class InternalSettings : public InternalSettingsGenerated {
47public:
48 static Ref<InternalSettings> create(Page*);
49 static InternalSettings* from(Page*);
50 void hostDestroyed();
51 void resetToConsistentState();
52
53 ExceptionOr<void> setUsesOverlayScrollbars(bool);
54 ExceptionOr<void> setTouchEventEmulationEnabled(bool);
55 ExceptionOr<void> setStandardFontFamily(const String& family, const String& script);
56 ExceptionOr<void> setSerifFontFamily(const String& family, const String& script);
57 ExceptionOr<void> setSansSerifFontFamily(const String& family, const String& script);
58 ExceptionOr<void> setFixedFontFamily(const String& family, const String& script);
59 ExceptionOr<void> setCursiveFontFamily(const String& family, const String& script);
60 ExceptionOr<void> setFantasyFontFamily(const String& family, const String& script);
61 ExceptionOr<void> setPictographFontFamily(const String& family, const String& script);
62 ExceptionOr<void> setTextAutosizingEnabled(bool);
63 ExceptionOr<void> setTextAutosizingWindowSizeOverride(int width, int height);
64 ExceptionOr<void> setTextAutosizingUsesIdempotentMode(bool);
65 ExceptionOr<void> setTextAutosizingFontScaleFactor(float);
66 ExceptionOr<void> setMediaTypeOverride(const String&);
67 ExceptionOr<void> setCanStartMedia(bool);
68 ExceptionOr<void> setAllowsAirPlayForMediaPlayback(bool);
69 ExceptionOr<void> setMediaCaptureRequiresSecureConnection(bool);
70
71 ExceptionOr<void> setEditingBehavior(const String&);
72 ExceptionOr<void> setPreferMIMETypeForImages(bool);
73 ExceptionOr<void> setPDFImageCachingPolicy(const String&);
74 ExceptionOr<void> setShouldDisplayTrackKind(const String& kind, bool enabled);
75 ExceptionOr<bool> shouldDisplayTrackKind(const String& kind);
76 ExceptionOr<void> setUseDarkAppearance(bool);
77 ExceptionOr<void> setStorageBlockingPolicy(const String&);
78 ExceptionOr<void> setImagesEnabled(bool);
79 ExceptionOr<void> setMinimumTimerInterval(double intervalInSeconds);
80 ExceptionOr<void> setDefaultVideoPosterURL(const String&);
81 ExceptionOr<void> setForcePendingWebGLPolicy(bool);
82 ExceptionOr<void> setTimeWithoutMouseMovementBeforeHidingControls(double);
83 ExceptionOr<void> setUseLegacyBackgroundSizeShorthandBehavior(bool);
84 ExceptionOr<void> setAutoscrollForDragAndDropEnabled(bool);
85 ExceptionOr<void> setFontFallbackPrefersPictographs(bool);
86 enum class FontLoadTimingOverride { Block, Swap, Failure };
87 ExceptionOr<void> setFontLoadTimingOverride(const FontLoadTimingOverride&);
88 ExceptionOr<void> setShouldIgnoreFontLoadCompletions(bool);
89 ExceptionOr<void> setQuickTimePluginReplacementEnabled(bool);
90 ExceptionOr<void> setYouTubeFlashPluginReplacementEnabled(bool);
91 ExceptionOr<void> setBackgroundShouldExtendBeyondPage(bool);
92 ExceptionOr<void> setShouldConvertPositionStyleOnCopy(bool);
93 ExceptionOr<void> setScrollingTreeIncludesFrames(bool);
94 ExceptionOr<void> setAllowUnclampedScrollPosition(bool);
95 ExceptionOr<void> setAllowsInlineMediaPlayback(bool);
96 ExceptionOr<void> setAllowsInlineMediaPlaybackAfterFullscreen(bool);
97 ExceptionOr<void> setInlineMediaPlaybackRequiresPlaysInlineAttribute(bool);
98 ExceptionOr<String> userInterfaceDirectionPolicy();
99 ExceptionOr<void> setUserInterfaceDirectionPolicy(const String&);
100 ExceptionOr<String> systemLayoutDirection();
101 ExceptionOr<void> setSystemLayoutDirection(const String&);
102 ExceptionOr<void> setShouldMockBoldSystemFontForAccessibility(bool);
103 ExceptionOr<void> setShouldManageAudioSessionCategory(bool);
104 ExceptionOr<void> setCustomPasteboardDataEnabled(bool);
105 ExceptionOr<void> setIncompleteImageBorderEnabled(bool);
106 ExceptionOr<void> setShouldDispatchSyntheticMouseEventsWhenModifyingSelection(bool);
107
108 using FrameFlatteningValue = FrameFlattening;
109 ExceptionOr<void> setFrameFlattening(FrameFlatteningValue);
110
111 static void setAllowsAnySSLCertificate(bool);
112
113 ExceptionOr<bool> deferredCSSParserEnabled();
114 ExceptionOr<void> setDeferredCSSParserEnabled(bool);
115
116 enum class ForcedAccessibilityValue { System, On, Off };
117 ForcedAccessibilityValue forcedColorsAreInvertedAccessibilityValue() const;
118 void setForcedColorsAreInvertedAccessibilityValue(ForcedAccessibilityValue);
119 ForcedAccessibilityValue forcedDisplayIsMonochromeAccessibilityValue() const;
120 void setForcedDisplayIsMonochromeAccessibilityValue(ForcedAccessibilityValue);
121 ForcedAccessibilityValue forcedPrefersReducedMotionAccessibilityValue() const;
122 void setForcedPrefersReducedMotionAccessibilityValue(ForcedAccessibilityValue);
123
124 // RuntimeEnabledFeatures.
125 static void setIndexedDBWorkersEnabled(bool);
126 static void setWebGL2Enabled(bool);
127 static void setWebGPUEnabled(bool);
128 static void setWebVREnabled(bool);
129 static void setScreenCaptureEnabled(bool);
130
131 static bool webAnimationsCSSIntegrationEnabled();
132
133 void setShouldDeactivateAudioSession(bool);
134
135private:
136 explicit InternalSettings(Page*);
137
138 Settings& settings() const;
139 static const char* supplementName();
140
141 void setUseDarkAppearanceInternal(bool);
142
143 class Backup {
144 public:
145 explicit Backup(Settings&);
146 void restoreTo(Settings&);
147
148 EditingBehaviorType m_originalEditingBehavior;
149
150 // Initially empty, only used if changed by a test.
151 ScriptFontFamilyMap m_standardFontFamilies;
152 ScriptFontFamilyMap m_fixedFontFamilies;
153 ScriptFontFamilyMap m_serifFontFamilies;
154 ScriptFontFamilyMap m_sansSerifFontFamilies;
155 ScriptFontFamilyMap m_cursiveFontFamilies;
156 ScriptFontFamilyMap m_fantasyFontFamilies;
157 ScriptFontFamilyMap m_pictographFontFamilies;
158
159#if ENABLE(TEXT_AUTOSIZING)
160 bool m_originalTextAutosizingEnabled;
161 IntSize m_originalTextAutosizingWindowSizeOverride;
162 bool m_originalTextAutosizingUsesIdempotentMode;
163#endif
164
165 String m_originalMediaTypeOverride;
166 bool m_originalCanvasUsesAcceleratedDrawing;
167 bool m_originalMockScrollbarsEnabled;
168 bool m_originalUsesOverlayScrollbars;
169 bool m_imagesEnabled;
170 bool m_preferMIMETypeForImages;
171 Seconds m_minimumDOMTimerInterval;
172#if ENABLE(VIDEO_TRACK)
173 bool m_shouldDisplaySubtitles;
174 bool m_shouldDisplayCaptions;
175 bool m_shouldDisplayTextDescriptions;
176#endif
177 String m_defaultVideoPosterURL;
178 bool m_forcePendingWebGLPolicy;
179 Seconds m_originalTimeWithoutMouseMovementBeforeHidingControls;
180 bool m_useLegacyBackgroundSizeShorthandBehavior;
181 bool m_autoscrollForDragAndDropEnabled;
182 bool m_quickTimePluginReplacementEnabled;
183 bool m_youTubeFlashPluginReplacementEnabled;
184 bool m_shouldConvertPositionStyleOnCopy;
185 bool m_fontFallbackPrefersPictographs;
186 bool m_shouldIgnoreFontLoadCompletions;
187 bool m_backgroundShouldExtendBeyondPage;
188 SecurityOrigin::StorageBlockingPolicy m_storageBlockingPolicy;
189 bool m_scrollingTreeIncludesFrames;
190#if ENABLE(TOUCH_EVENTS)
191 bool m_touchEventEmulationEnabled;
192#endif
193#if ENABLE(WIRELESS_PLAYBACK_TARGET)
194 bool m_allowsAirPlayForMediaPlayback;
195#endif
196 bool m_allowsInlineMediaPlayback;
197 bool m_allowsInlineMediaPlaybackAfterFullscreen;
198 bool m_inlineMediaPlaybackRequiresPlaysInlineAttribute;
199 bool m_deferredCSSParserEnabled;
200 bool m_inputEventsEnabled;
201 bool m_incompleteImageBorderEnabled;
202 bool m_shouldDispatchSyntheticMouseEventsWhenModifyingSelection;
203 bool m_shouldDeactivateAudioSession;
204 UserInterfaceDirectionPolicy m_userInterfaceDirectionPolicy;
205 TextDirection m_systemLayoutDirection;
206 PDFImageCachingPolicy m_pdfImageCachingPolicy;
207 Settings::ForcedAccessibilityValue m_forcedColorsAreInvertedAccessibilityValue;
208 Settings::ForcedAccessibilityValue m_forcedDisplayIsMonochromeAccessibilityValue;
209 Settings::ForcedAccessibilityValue m_forcedPrefersReducedMotionAccessibilityValue;
210 Settings::FontLoadTimingOverride m_fontLoadTimingOverride;
211 FrameFlattening m_frameFlattening;
212
213 // Runtime enabled settings.
214 bool m_indexedDBWorkersEnabled;
215 bool m_webGL2Enabled;
216 bool m_webVREnabled;
217 bool m_setScreenCaptureEnabled;
218
219 bool m_shouldMockBoldSystemFontForAccessibility;
220#if USE(AUDIO_SESSION)
221 bool m_shouldManageAudioSessionCategory;
222#endif
223 bool m_customPasteboardDataEnabled;
224 };
225
226 Page* m_page;
227 Backup m_backup;
228};
229
230} // namespace WebCore
231