8b491b716d7e3dbe0a6892ffb38cad2475dd8ea5
[WebKit-https.git] / Source / WebCore / testing / InternalSettings.h
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/AtomicStringHash.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
41 namespace WebCore {
42
43 class Page;
44 class Settings;
45
46 class InternalSettings : public InternalSettingsGenerated {
47 public:
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> setTextAutosizingFontScaleFactor(float);
65     ExceptionOr<void> setMediaTypeOverride(const String&);
66     ExceptionOr<void> setCanStartMedia(bool);
67     ExceptionOr<void> setAllowsAirPlayForMediaPlayback(bool);
68     ExceptionOr<void> setMediaCaptureRequiresSecureConnection(bool);
69
70     ExceptionOr<void> setEditingBehavior(const String&);
71     ExceptionOr<void> setPreferMIMETypeForImages(bool);
72     ExceptionOr<void> setPDFImageCachingPolicy(const String&);
73     ExceptionOr<void> setShouldDisplayTrackKind(const String& kind, bool enabled);
74     ExceptionOr<bool> shouldDisplayTrackKind(const String& kind);
75     ExceptionOr<void> setStorageBlockingPolicy(const String&);
76     ExceptionOr<void> setImagesEnabled(bool);
77     ExceptionOr<void> setMinimumTimerInterval(double intervalInSeconds);
78     ExceptionOr<void> setDefaultVideoPosterURL(const String&);
79     ExceptionOr<void> setForcePendingWebGLPolicy(bool);
80     ExceptionOr<void> setTimeWithoutMouseMovementBeforeHidingControls(double);
81     ExceptionOr<void> setUseLegacyBackgroundSizeShorthandBehavior(bool);
82     ExceptionOr<void> setAutoscrollForDragAndDropEnabled(bool);
83     ExceptionOr<void> setFontFallbackPrefersPictographs(bool);
84     enum class FontLoadTimingOverride { Block, Swap, Failure };
85     ExceptionOr<void> setFontLoadTimingOverride(const FontLoadTimingOverride&);
86     ExceptionOr<void> setShouldIgnoreFontLoadCompletions(bool);
87     ExceptionOr<void> setQuickTimePluginReplacementEnabled(bool);
88     ExceptionOr<void> setYouTubeFlashPluginReplacementEnabled(bool);
89     ExceptionOr<void> setBackgroundShouldExtendBeyondPage(bool);
90     ExceptionOr<void> setShouldConvertPositionStyleOnCopy(bool);
91     ExceptionOr<void> setScrollingTreeIncludesFrames(bool);
92     ExceptionOr<void> setAllowUnclampedScrollPosition(bool);
93     ExceptionOr<void> setAllowsInlineMediaPlayback(bool);
94     ExceptionOr<void> setAllowsInlineMediaPlaybackAfterFullscreen(bool);
95     ExceptionOr<void> setInlineMediaPlaybackRequiresPlaysInlineAttribute(bool);
96     ExceptionOr<String> userInterfaceDirectionPolicy();
97     ExceptionOr<void> setUserInterfaceDirectionPolicy(const String&);
98     ExceptionOr<String> systemLayoutDirection();
99     ExceptionOr<void> setSystemLayoutDirection(const String&);
100     ExceptionOr<void> setShouldMockBoldSystemFontForAccessibility(bool);
101     ExceptionOr<void> setShouldManageAudioSessionCategory(bool);
102     ExceptionOr<void> setCustomPasteboardDataEnabled(bool);
103
104     enum class FrameFlatteningValue { Disabled, EnabledForNonFullScreenIFrames, FullyEnabled };
105     ExceptionOr<void> setFrameFlattening(const FrameFlatteningValue&);
106     
107     static void setAllowsAnySSLCertificate(bool);
108
109     ExceptionOr<bool> deferredCSSParserEnabled();
110     ExceptionOr<void> setDeferredCSSParserEnabled(bool);
111
112     enum class ForcedAccessibilityValue { System, On, Off };
113     ForcedAccessibilityValue forcedColorsAreInvertedAccessibilityValue() const;
114     void setForcedColorsAreInvertedAccessibilityValue(ForcedAccessibilityValue);
115     ForcedAccessibilityValue forcedDisplayIsMonochromeAccessibilityValue() const;
116     void setForcedDisplayIsMonochromeAccessibilityValue(ForcedAccessibilityValue);
117     ForcedAccessibilityValue forcedPrefersReducedMotionAccessibilityValue() const;
118     void setForcedPrefersReducedMotionAccessibilityValue(ForcedAccessibilityValue);
119
120     // RuntimeEnabledFeatures.
121     static void setIndexedDBWorkersEnabled(bool);
122     static void setCSSGridLayoutEnabled(bool);
123     static void setWebGL2Enabled(bool);
124     static void setWebGPUEnabled(bool);
125     static void setWebVREnabled(bool);
126
127 private:
128     explicit InternalSettings(Page*);
129
130     Settings& settings() const;
131     static const char* supplementName();
132
133     class Backup {
134     public:
135         explicit Backup(Settings&);
136         void restoreTo(Settings&);
137
138         EditingBehaviorType m_originalEditingBehavior;
139
140         // Initially empty, only used if changed by a test.
141         ScriptFontFamilyMap m_standardFontFamilies;
142         ScriptFontFamilyMap m_fixedFontFamilies;
143         ScriptFontFamilyMap m_serifFontFamilies;
144         ScriptFontFamilyMap m_sansSerifFontFamilies;
145         ScriptFontFamilyMap m_cursiveFontFamilies;
146         ScriptFontFamilyMap m_fantasyFontFamilies;
147         ScriptFontFamilyMap m_pictographFontFamilies;
148
149 #if ENABLE(TEXT_AUTOSIZING)
150         bool m_originalTextAutosizingEnabled;
151         IntSize m_originalTextAutosizingWindowSizeOverride;
152 #endif
153
154         String m_originalMediaTypeOverride;
155         bool m_originalCanvasUsesAcceleratedDrawing;
156         bool m_originalMockScrollbarsEnabled;
157         bool m_originalUsesOverlayScrollbars;
158         bool m_imagesEnabled;
159         bool m_preferMIMETypeForImages;
160         Seconds m_minimumDOMTimerInterval;
161 #if ENABLE(VIDEO_TRACK)
162         bool m_shouldDisplaySubtitles;
163         bool m_shouldDisplayCaptions;
164         bool m_shouldDisplayTextDescriptions;
165 #endif
166         String m_defaultVideoPosterURL;
167         bool m_forcePendingWebGLPolicy;
168         Seconds m_originalTimeWithoutMouseMovementBeforeHidingControls;
169         bool m_useLegacyBackgroundSizeShorthandBehavior;
170         bool m_autoscrollForDragAndDropEnabled;
171         bool m_quickTimePluginReplacementEnabled;
172         bool m_youTubeFlashPluginReplacementEnabled;
173         bool m_shouldConvertPositionStyleOnCopy;
174         bool m_fontFallbackPrefersPictographs;
175         bool m_shouldIgnoreFontLoadCompletions;
176         bool m_backgroundShouldExtendBeyondPage;
177         SecurityOrigin::StorageBlockingPolicy m_storageBlockingPolicy;
178         bool m_scrollingTreeIncludesFrames;
179 #if ENABLE(TOUCH_EVENTS)
180         bool m_touchEventEmulationEnabled;
181 #endif
182 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
183         bool m_allowsAirPlayForMediaPlayback;
184 #endif
185         bool m_allowsInlineMediaPlayback;
186         bool m_allowsInlineMediaPlaybackAfterFullscreen;
187         bool m_inlineMediaPlaybackRequiresPlaysInlineAttribute;
188         bool m_deferredCSSParserEnabled;
189         bool m_inputEventsEnabled;
190
191         UserInterfaceDirectionPolicy m_userInterfaceDirectionPolicy;
192         TextDirection m_systemLayoutDirection;
193         PDFImageCachingPolicy m_pdfImageCachingPolicy;
194         Settings::ForcedAccessibilityValue m_forcedColorsAreInvertedAccessibilityValue;
195         Settings::ForcedAccessibilityValue m_forcedDisplayIsMonochromeAccessibilityValue;
196         Settings::ForcedAccessibilityValue m_forcedPrefersReducedMotionAccessibilityValue;
197         Settings::FontLoadTimingOverride m_fontLoadTimingOverride;
198         FrameFlattening m_frameFlattening;
199
200         // Runtime enabled settings.
201         bool m_indexedDBWorkersEnabled;
202         bool m_cssGridLayoutEnabled;
203         bool m_webGL2Enabled;
204         bool m_webGPUEnabled;
205         bool m_webVREnabled;
206         
207         bool m_shouldMockBoldSystemFontForAccessibility;
208 #if USE(AUDIO_SESSION)
209         bool m_shouldManageAudioSessionCategory;
210 #endif
211         bool m_customPasteboardDataEnabled;
212     };
213
214     Page* m_page;
215     Backup m_backup;
216 };
217
218 } // namespace WebCore