[Web Animations] Expose Web Animations CSS integration as an experimental feature
[WebKit-https.git] / Source / WebCore / testing / InternalSettings.cpp
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  * Copyright (C) 2013 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 #include "config.h"
28 #include "InternalSettings.h"
29
30 #include "CaptionUserPreferences.h"
31 #include "DeprecatedGlobalSettings.h"
32 #include "Document.h"
33 #include "FontCache.h"
34 #include "Frame.h"
35 #include "FrameView.h"
36 #include "LocaleToScriptMapping.h"
37 #include "Page.h"
38 #include "PageGroup.h"
39 #include "RenderTheme.h"
40 #include "RuntimeEnabledFeatures.h"
41 #include "Settings.h"
42 #include "Supplementable.h"
43 #include <wtf/Language.h>
44
45 #if ENABLE(INPUT_TYPE_COLOR)
46 #include "ColorChooser.h"
47 #endif
48
49 #if USE(SOUP)
50 #include "SoupNetworkSession.h"
51 #endif
52
53 namespace WebCore {
54
55 InternalSettings::Backup::Backup(Settings& settings)
56     : m_originalEditingBehavior(settings.editingBehaviorType())
57 #if ENABLE(TEXT_AUTOSIZING)
58     , m_originalTextAutosizingEnabled(settings.textAutosizingEnabled())
59     , m_originalTextAutosizingWindowSizeOverride(settings.textAutosizingWindowSizeOverride())
60 #endif
61     , m_originalMediaTypeOverride(settings.mediaTypeOverride())
62     , m_originalCanvasUsesAcceleratedDrawing(settings.canvasUsesAcceleratedDrawing())
63     , m_originalMockScrollbarsEnabled(DeprecatedGlobalSettings::mockScrollbarsEnabled())
64     , m_imagesEnabled(settings.areImagesEnabled())
65     , m_preferMIMETypeForImages(settings.preferMIMETypeForImages())
66     , m_minimumDOMTimerInterval(settings.minimumDOMTimerInterval())
67 #if ENABLE(VIDEO_TRACK)
68     , m_shouldDisplaySubtitles(settings.shouldDisplaySubtitles())
69     , m_shouldDisplayCaptions(settings.shouldDisplayCaptions())
70     , m_shouldDisplayTextDescriptions(settings.shouldDisplayTextDescriptions())
71 #endif
72     , m_defaultVideoPosterURL(settings.defaultVideoPosterURL())
73     , m_forcePendingWebGLPolicy(settings.isForcePendingWebGLPolicy())
74     , m_originalTimeWithoutMouseMovementBeforeHidingControls(settings.timeWithoutMouseMovementBeforeHidingControls())
75     , m_useLegacyBackgroundSizeShorthandBehavior(settings.useLegacyBackgroundSizeShorthandBehavior())
76     , m_autoscrollForDragAndDropEnabled(settings.autoscrollForDragAndDropEnabled())
77     , m_quickTimePluginReplacementEnabled(settings.quickTimePluginReplacementEnabled())
78     , m_youTubeFlashPluginReplacementEnabled(settings.youTubeFlashPluginReplacementEnabled())
79     , m_shouldConvertPositionStyleOnCopy(settings.shouldConvertPositionStyleOnCopy())
80     , m_fontFallbackPrefersPictographs(settings.fontFallbackPrefersPictographs())
81     , m_shouldIgnoreFontLoadCompletions(settings.shouldIgnoreFontLoadCompletions())
82     , m_backgroundShouldExtendBeyondPage(settings.backgroundShouldExtendBeyondPage())
83     , m_storageBlockingPolicy(settings.storageBlockingPolicy())
84     , m_scrollingTreeIncludesFrames(settings.scrollingTreeIncludesFrames())
85 #if ENABLE(TOUCH_EVENTS)
86     , m_touchEventEmulationEnabled(settings.isTouchEventEmulationEnabled())
87 #endif
88 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
89     , m_allowsAirPlayForMediaPlayback(settings.allowsAirPlayForMediaPlayback())
90 #endif
91     , m_allowsInlineMediaPlayback(settings.allowsInlineMediaPlayback())
92     , m_allowsInlineMediaPlaybackAfterFullscreen(settings.allowsInlineMediaPlaybackAfterFullscreen())
93     , m_inlineMediaPlaybackRequiresPlaysInlineAttribute(settings.inlineMediaPlaybackRequiresPlaysInlineAttribute())
94     , m_deferredCSSParserEnabled(settings.deferredCSSParserEnabled())
95     , m_inputEventsEnabled(settings.inputEventsEnabled())
96 #if ENABLE(ACCESSIBILITY_EVENTS)
97     , m_accessibilityEventsEnabled(settings.accessibilityEventsEnabled())
98 #endif
99     , m_userInterfaceDirectionPolicy(settings.userInterfaceDirectionPolicy())
100     , m_systemLayoutDirection(settings.systemLayoutDirection())
101     , m_pdfImageCachingPolicy(settings.pdfImageCachingPolicy())
102     , m_forcedColorsAreInvertedAccessibilityValue(settings.forcedColorsAreInvertedAccessibilityValue())
103     , m_forcedDisplayIsMonochromeAccessibilityValue(settings.forcedDisplayIsMonochromeAccessibilityValue())
104     , m_forcedPrefersReducedMotionAccessibilityValue(settings.forcedPrefersReducedMotionAccessibilityValue())
105     , m_fontLoadTimingOverride(settings.fontLoadTimingOverride())
106     , m_frameFlattening(settings.frameFlattening())
107 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
108     , m_indexedDBWorkersEnabled(RuntimeEnabledFeatures::sharedFeatures().indexedDBWorkersEnabled())
109 #endif
110 #if ENABLE(WEBGL2)
111     , m_webGL2Enabled(RuntimeEnabledFeatures::sharedFeatures().webGL2Enabled())
112 #endif
113 #if ENABLE(WEBGPU)
114     , m_webGPUEnabled(RuntimeEnabledFeatures::sharedFeatures().webGPUEnabled())
115 #endif
116     , m_webVREnabled(RuntimeEnabledFeatures::sharedFeatures().webVREnabled())
117 #if ENABLE(MEDIA_STREAM)
118     , m_setScreenCaptureEnabled(RuntimeEnabledFeatures::sharedFeatures().screenCaptureEnabled())
119 #endif
120     , m_shouldMockBoldSystemFontForAccessibility(RenderTheme::singleton().shouldMockBoldSystemFontForAccessibility())
121 #if USE(AUDIO_SESSION)
122     , m_shouldManageAudioSessionCategory(DeprecatedGlobalSettings::shouldManageAudioSessionCategory())
123 #endif
124     , m_customPasteboardDataEnabled(RuntimeEnabledFeatures::sharedFeatures().customPasteboardDataEnabled())
125     , m_promptForStorageAccessAPIEnabled(RuntimeEnabledFeatures::sharedFeatures().storageAccessPromptsEnabled())
126 {
127 }
128
129 void InternalSettings::Backup::restoreTo(Settings& settings)
130 {
131     settings.setEditingBehaviorType(m_originalEditingBehavior);
132
133     for (const auto& standardFont : m_standardFontFamilies)
134         settings.setStandardFontFamily(standardFont.value, static_cast<UScriptCode>(standardFont.key));
135     m_standardFontFamilies.clear();
136
137     for (const auto& fixedFont : m_fixedFontFamilies)
138         settings.setFixedFontFamily(fixedFont.value, static_cast<UScriptCode>(fixedFont.key));
139     m_fixedFontFamilies.clear();
140
141     for (const auto& serifFont : m_serifFontFamilies)
142         settings.setSerifFontFamily(serifFont.value, static_cast<UScriptCode>(serifFont.key));
143     m_serifFontFamilies.clear();
144
145     for (const auto& sansSerifFont : m_sansSerifFontFamilies)
146         settings.setSansSerifFontFamily(sansSerifFont.value, static_cast<UScriptCode>(sansSerifFont.key));
147     m_sansSerifFontFamilies.clear();
148
149     for (const auto& cursiveFont : m_cursiveFontFamilies)
150         settings.setCursiveFontFamily(cursiveFont.value, static_cast<UScriptCode>(cursiveFont.key));
151     m_cursiveFontFamilies.clear();
152
153     for (const auto& fantasyFont : m_fantasyFontFamilies)
154         settings.setFantasyFontFamily(fantasyFont.value, static_cast<UScriptCode>(fantasyFont.key));
155     m_fantasyFontFamilies.clear();
156
157     for (const auto& pictographFont : m_pictographFontFamilies)
158         settings.setPictographFontFamily(pictographFont.value, static_cast<UScriptCode>(pictographFont.key));
159     m_pictographFontFamilies.clear();
160
161 #if ENABLE(TEXT_AUTOSIZING)
162     settings.setTextAutosizingEnabled(m_originalTextAutosizingEnabled);
163     settings.setTextAutosizingWindowSizeOverride(m_originalTextAutosizingWindowSizeOverride);
164 #endif
165     settings.setMediaTypeOverride(m_originalMediaTypeOverride);
166     settings.setCanvasUsesAcceleratedDrawing(m_originalCanvasUsesAcceleratedDrawing);
167     settings.setImagesEnabled(m_imagesEnabled);
168     settings.setPreferMIMETypeForImages(m_preferMIMETypeForImages);
169     settings.setMinimumDOMTimerInterval(m_minimumDOMTimerInterval);
170 #if ENABLE(VIDEO_TRACK)
171     settings.setShouldDisplaySubtitles(m_shouldDisplaySubtitles);
172     settings.setShouldDisplayCaptions(m_shouldDisplayCaptions);
173     settings.setShouldDisplayTextDescriptions(m_shouldDisplayTextDescriptions);
174 #endif
175     settings.setDefaultVideoPosterURL(m_defaultVideoPosterURL);
176     settings.setForcePendingWebGLPolicy(m_forcePendingWebGLPolicy);
177     settings.setTimeWithoutMouseMovementBeforeHidingControls(m_originalTimeWithoutMouseMovementBeforeHidingControls);
178     settings.setUseLegacyBackgroundSizeShorthandBehavior(m_useLegacyBackgroundSizeShorthandBehavior);
179     settings.setAutoscrollForDragAndDropEnabled(m_autoscrollForDragAndDropEnabled);
180     settings.setShouldConvertPositionStyleOnCopy(m_shouldConvertPositionStyleOnCopy);
181     settings.setFontFallbackPrefersPictographs(m_fontFallbackPrefersPictographs);
182     settings.setShouldIgnoreFontLoadCompletions(m_shouldIgnoreFontLoadCompletions);
183     settings.setBackgroundShouldExtendBeyondPage(m_backgroundShouldExtendBeyondPage);
184     settings.setStorageBlockingPolicy(m_storageBlockingPolicy);
185     settings.setScrollingTreeIncludesFrames(m_scrollingTreeIncludesFrames);
186 #if ENABLE(TOUCH_EVENTS)
187     settings.setTouchEventEmulationEnabled(m_touchEventEmulationEnabled);
188 #endif
189     settings.setAllowsInlineMediaPlayback(m_allowsInlineMediaPlayback);
190     settings.setAllowsInlineMediaPlaybackAfterFullscreen(m_allowsInlineMediaPlaybackAfterFullscreen);
191     settings.setInlineMediaPlaybackRequiresPlaysInlineAttribute(m_inlineMediaPlaybackRequiresPlaysInlineAttribute);
192     settings.setQuickTimePluginReplacementEnabled(m_quickTimePluginReplacementEnabled);
193     settings.setYouTubeFlashPluginReplacementEnabled(m_youTubeFlashPluginReplacementEnabled);
194     settings.setDeferredCSSParserEnabled(m_deferredCSSParserEnabled);
195     settings.setInputEventsEnabled(m_inputEventsEnabled);
196     settings.setUserInterfaceDirectionPolicy(m_userInterfaceDirectionPolicy);
197     settings.setSystemLayoutDirection(m_systemLayoutDirection);
198     settings.setPdfImageCachingPolicy(m_pdfImageCachingPolicy);
199     settings.setForcedColorsAreInvertedAccessibilityValue(m_forcedColorsAreInvertedAccessibilityValue);
200     settings.setForcedDisplayIsMonochromeAccessibilityValue(m_forcedDisplayIsMonochromeAccessibilityValue);
201     settings.setForcedPrefersReducedMotionAccessibilityValue(m_forcedPrefersReducedMotionAccessibilityValue);
202     settings.setFontLoadTimingOverride(m_fontLoadTimingOverride);
203     DeprecatedGlobalSettings::setAllowsAnySSLCertificate(false);
204     RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
205     FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
206     settings.setFrameFlattening(m_frameFlattening);
207 #if ENABLE(ACCESSIBILITY_EVENTS)
208     settings.setAccessibilityEventsEnabled(m_accessibilityEventsEnabled);
209 #endif
210
211 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
212     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(m_indexedDBWorkersEnabled);
213 #endif
214 #if ENABLE(WEBGL2)
215     RuntimeEnabledFeatures::sharedFeatures().setWebGL2Enabled(m_webGL2Enabled);
216 #endif
217 #if ENABLE(WEBGPU)
218     RuntimeEnabledFeatures::sharedFeatures().setWebGPUEnabled(m_webGPUEnabled);
219 #endif
220     RuntimeEnabledFeatures::sharedFeatures().setWebVREnabled(m_webVREnabled);
221 #if ENABLE(MEDIA_STREAM)
222     RuntimeEnabledFeatures::sharedFeatures().setScreenCaptureEnabled(m_setScreenCaptureEnabled);
223 #endif
224     RuntimeEnabledFeatures::sharedFeatures().setCustomPasteboardDataEnabled(m_customPasteboardDataEnabled);
225
226 #if USE(AUDIO_SESSION)
227     DeprecatedGlobalSettings::setShouldManageAudioSessionCategory(m_shouldManageAudioSessionCategory);
228 #endif
229
230     RuntimeEnabledFeatures::sharedFeatures().setStorageAccessPromptsEnabled(m_promptForStorageAccessAPIEnabled);
231 }
232
233 class InternalSettingsWrapper : public Supplement<Page> {
234 public:
235     explicit InternalSettingsWrapper(Page* page)
236         : m_internalSettings(InternalSettings::create(page)) { }
237     virtual ~InternalSettingsWrapper() { m_internalSettings->hostDestroyed(); }
238 #if !ASSERT_DISABLED
239     bool isRefCountedWrapper() const override { return true; }
240 #endif
241     InternalSettings* internalSettings() const { return m_internalSettings.get(); }
242
243 private:
244     RefPtr<InternalSettings> m_internalSettings;
245 };
246
247 const char* InternalSettings::supplementName()
248 {
249     return "InternalSettings";
250 }
251
252 InternalSettings* InternalSettings::from(Page* page)
253 {
254     if (!Supplement<Page>::from(page, supplementName()))
255         Supplement<Page>::provideTo(page, supplementName(), std::make_unique<InternalSettingsWrapper>(page));
256     return static_cast<InternalSettingsWrapper*>(Supplement<Page>::from(page, supplementName()))->internalSettings();
257 }
258
259 void InternalSettings::hostDestroyed()
260 {
261     m_page = nullptr;
262 }
263
264 InternalSettings::InternalSettings(Page* page)
265     : InternalSettingsGenerated(page)
266     , m_page(page)
267     , m_backup(page->settings())
268 {
269 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
270     setAllowsAirPlayForMediaPlayback(false);
271 #endif
272 #if ENABLE(MEDIA_STREAM)
273     setMediaCaptureRequiresSecureConnection(false);
274 #endif
275 }
276
277 Ref<InternalSettings> InternalSettings::create(Page* page)
278 {
279     return adoptRef(*new InternalSettings(page));
280 }
281
282 void InternalSettings::resetToConsistentState()
283 {
284     m_page->setPageScaleFactor(1, { 0, 0 });
285     m_page->mainFrame().setPageAndTextZoomFactors(1, 1);
286     m_page->setCanStartMedia(true);
287
288     settings().setForcePendingWebGLPolicy(false);
289 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
290     settings().setAllowsAirPlayForMediaPlayback(false);
291 #endif
292 #if ENABLE(MEDIA_STREAM)
293     setMediaCaptureRequiresSecureConnection(false);
294 #endif
295
296     m_backup.restoreTo(settings());
297     m_backup = Backup { settings() };
298
299     InternalSettingsGenerated::resetToConsistentState();
300 }
301
302 Settings& InternalSettings::settings() const
303 {
304     ASSERT(m_page);
305     return m_page->settings();
306 }
307
308 ExceptionOr<void> InternalSettings::setTouchEventEmulationEnabled(bool enabled)
309 {
310     if (!m_page)
311         return Exception { InvalidAccessError };
312 #if ENABLE(TOUCH_EVENTS)
313     settings().setTouchEventEmulationEnabled(enabled);
314 #else
315     UNUSED_PARAM(enabled);
316 #endif
317     return { };
318 }
319
320 ExceptionOr<void> InternalSettings::setStandardFontFamily(const String& family, const String& script)
321 {
322     if (!m_page)
323         return Exception { InvalidAccessError };
324     UScriptCode code = scriptNameToCode(script);
325     if (code == USCRIPT_INVALID_CODE)
326         return { };
327     m_backup.m_standardFontFamilies.add(code, settings().standardFontFamily(code));
328     settings().setStandardFontFamily(family, code);
329     return { };
330 }
331
332 ExceptionOr<void> InternalSettings::setSerifFontFamily(const String& family, const String& script)
333 {
334     if (!m_page)
335         return Exception { InvalidAccessError };
336     UScriptCode code = scriptNameToCode(script);
337     if (code == USCRIPT_INVALID_CODE)
338         return { };
339     m_backup.m_serifFontFamilies.add(code, settings().serifFontFamily(code));
340     settings().setSerifFontFamily(family, code);
341     return { };
342 }
343
344 ExceptionOr<void> InternalSettings::setSansSerifFontFamily(const String& family, const String& script)
345 {
346     if (!m_page)
347         return Exception { InvalidAccessError };
348     UScriptCode code = scriptNameToCode(script);
349     if (code == USCRIPT_INVALID_CODE)
350         return { };
351     m_backup.m_sansSerifFontFamilies.add(code, settings().sansSerifFontFamily(code));
352     settings().setSansSerifFontFamily(family, code);
353     return { };
354 }
355
356 ExceptionOr<void> InternalSettings::setFixedFontFamily(const String& family, const String& script)
357 {
358     if (!m_page)
359         return Exception { InvalidAccessError };
360     UScriptCode code = scriptNameToCode(script);
361     if (code == USCRIPT_INVALID_CODE)
362         return { };
363     m_backup.m_fixedFontFamilies.add(code, settings().fixedFontFamily(code));
364     settings().setFixedFontFamily(family, code);
365     return { };
366 }
367
368 ExceptionOr<void> InternalSettings::setCursiveFontFamily(const String& family, const String& script)
369 {
370     if (!m_page)
371         return Exception { InvalidAccessError };
372     UScriptCode code = scriptNameToCode(script);
373     if (code == USCRIPT_INVALID_CODE)
374         return { };
375     m_backup.m_cursiveFontFamilies.add(code, settings().cursiveFontFamily(code));
376     settings().setCursiveFontFamily(family, code);
377     return { };
378 }
379
380 ExceptionOr<void> InternalSettings::setFantasyFontFamily(const String& family, const String& script)
381 {
382     if (!m_page)
383         return Exception { InvalidAccessError };
384     UScriptCode code = scriptNameToCode(script);
385     if (code == USCRIPT_INVALID_CODE)
386         return { };
387     m_backup.m_fantasyFontFamilies.add(code, settings().fantasyFontFamily(code));
388     settings().setFantasyFontFamily(family, code);
389     return { };
390 }
391
392 ExceptionOr<void> InternalSettings::setPictographFontFamily(const String& family, const String& script)
393 {
394     if (!m_page)
395         return Exception { InvalidAccessError };
396     UScriptCode code = scriptNameToCode(script);
397     if (code == USCRIPT_INVALID_CODE)
398         return { };
399     m_backup.m_pictographFontFamilies.add(code, settings().pictographFontFamily(code));
400     settings().setPictographFontFamily(family, code);
401     return { };
402 }
403
404 ExceptionOr<void> InternalSettings::setTextAutosizingEnabled(bool enabled)
405 {
406     if (!m_page)
407         return Exception { InvalidAccessError };
408 #if ENABLE(TEXT_AUTOSIZING)
409     settings().setTextAutosizingEnabled(enabled);
410 #else
411     UNUSED_PARAM(enabled);
412 #endif
413     return { };
414 }
415
416 ExceptionOr<void> InternalSettings::setTextAutosizingWindowSizeOverride(int width, int height)
417 {
418     if (!m_page)
419         return Exception { InvalidAccessError };
420 #if ENABLE(TEXT_AUTOSIZING)
421     settings().setTextAutosizingWindowSizeOverride(IntSize(width, height));
422 #else
423     UNUSED_PARAM(width);
424     UNUSED_PARAM(height);
425 #endif
426     return { };
427 }
428
429 ExceptionOr<void> InternalSettings::setMediaTypeOverride(const String& mediaType)
430 {
431     if (!m_page)
432         return Exception { InvalidAccessError };
433     settings().setMediaTypeOverride(mediaType);
434     return { };
435 }
436
437 ExceptionOr<void> InternalSettings::setCanStartMedia(bool enabled)
438 {
439     if (!m_page)
440         return Exception { InvalidAccessError };
441     m_page->setCanStartMedia(enabled);
442     return { };
443 }
444
445 ExceptionOr<void> InternalSettings::setAllowsAirPlayForMediaPlayback(bool allows)
446 {
447     if (!m_page)
448         return Exception { InvalidAccessError };
449 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
450     settings().setAllowsAirPlayForMediaPlayback(allows);
451 #else
452     UNUSED_PARAM(allows);
453 #endif
454     return { };
455 }
456
457 ExceptionOr<void> InternalSettings::setMediaCaptureRequiresSecureConnection(bool requires)
458 {
459     if (!m_page)
460         return Exception { InvalidAccessError };
461 #if ENABLE(MEDIA_STREAM)
462     DeprecatedGlobalSettings::setMediaCaptureRequiresSecureConnection(requires);
463 #else
464     UNUSED_PARAM(requires);
465 #endif
466     return { };
467 }
468
469 ExceptionOr<void> InternalSettings::setEditingBehavior(const String& editingBehavior)
470 {
471     if (!m_page)
472         return Exception { InvalidAccessError };
473     if (equalLettersIgnoringASCIICase(editingBehavior, "win"))
474         settings().setEditingBehaviorType(EditingWindowsBehavior);
475     else if (equalLettersIgnoringASCIICase(editingBehavior, "mac"))
476         settings().setEditingBehaviorType(EditingMacBehavior);
477     else if (equalLettersIgnoringASCIICase(editingBehavior, "unix"))
478         settings().setEditingBehaviorType(EditingUnixBehavior);
479     else if (equalLettersIgnoringASCIICase(editingBehavior, "ios"))
480         settings().setEditingBehaviorType(EditingIOSBehavior);
481     else
482         return Exception { SyntaxError };
483     return { };
484 }
485
486 ExceptionOr<void> InternalSettings::setShouldDisplayTrackKind(const String& kind, bool enabled)
487 {
488     if (!m_page)
489         return Exception { InvalidAccessError };
490 #if ENABLE(VIDEO_TRACK)
491     auto& captionPreferences = m_page->group().captionPreferences();
492     if (equalLettersIgnoringASCIICase(kind, "subtitles"))
493         captionPreferences.setUserPrefersSubtitles(enabled);
494     else if (equalLettersIgnoringASCIICase(kind, "captions"))
495         captionPreferences.setUserPrefersCaptions(enabled);
496     else if (equalLettersIgnoringASCIICase(kind, "textdescriptions"))
497         captionPreferences.setUserPrefersTextDescriptions(enabled);
498     else
499         return Exception { SyntaxError };
500 #else
501     UNUSED_PARAM(kind);
502     UNUSED_PARAM(enabled);
503 #endif
504     return { };
505 }
506
507 ExceptionOr<bool> InternalSettings::shouldDisplayTrackKind(const String& kind)
508 {
509     if (!m_page)
510         return Exception { InvalidAccessError };
511 #if ENABLE(VIDEO_TRACK)
512     auto& captionPreferences = m_page->group().captionPreferences();
513     if (equalLettersIgnoringASCIICase(kind, "subtitles"))
514         return captionPreferences.userPrefersSubtitles();
515     if (equalLettersIgnoringASCIICase(kind, "captions"))
516         return captionPreferences.userPrefersCaptions();
517     if (equalLettersIgnoringASCIICase(kind, "textdescriptions"))
518         return captionPreferences.userPrefersTextDescriptions();
519
520     return Exception { SyntaxError };
521 #else
522     UNUSED_PARAM(kind);
523     return false;
524 #endif
525 }
526
527 ExceptionOr<void> InternalSettings::setStorageBlockingPolicy(const String& mode)
528 {
529     if (!m_page)
530         return Exception { InvalidAccessError };
531     if (mode == "AllowAll")
532         settings().setStorageBlockingPolicy(SecurityOrigin::AllowAllStorage);
533     else if (mode == "BlockThirdParty")
534         settings().setStorageBlockingPolicy(SecurityOrigin::BlockThirdPartyStorage);
535     else if (mode == "BlockAll")
536         settings().setStorageBlockingPolicy(SecurityOrigin::BlockAllStorage);
537     else
538         return Exception { SyntaxError };
539     return { };
540 }
541
542 ExceptionOr<void> InternalSettings::setPreferMIMETypeForImages(bool preferMIMETypeForImages)
543 {
544     if (!m_page)
545         return Exception { InvalidAccessError };
546     settings().setPreferMIMETypeForImages(preferMIMETypeForImages);
547     return { };
548 }
549
550 ExceptionOr<void> InternalSettings::setImagesEnabled(bool enabled)
551 {
552     if (!m_page)
553         return Exception { InvalidAccessError };
554     settings().setImagesEnabled(enabled);
555     return { };
556 }
557
558 ExceptionOr<void> InternalSettings::setPDFImageCachingPolicy(const String& policy)
559 {
560     if (!m_page)
561         return Exception { InvalidAccessError };
562     if (equalLettersIgnoringASCIICase(policy, "disabled"))
563         settings().setPdfImageCachingPolicy(PDFImageCachingDisabled);
564     else if (equalLettersIgnoringASCIICase(policy, "belowmemorylimit"))
565         settings().setPdfImageCachingPolicy(PDFImageCachingBelowMemoryLimit);
566     else if (equalLettersIgnoringASCIICase(policy, "clipboundsonly"))
567         settings().setPdfImageCachingPolicy(PDFImageCachingClipBoundsOnly);
568     else if (equalLettersIgnoringASCIICase(policy, "enabled"))
569         settings().setPdfImageCachingPolicy(PDFImageCachingEnabled);
570     else
571         return Exception { SyntaxError };
572     return { };
573 }
574
575 ExceptionOr<void> InternalSettings::setMinimumTimerInterval(double intervalInSeconds)
576 {
577     if (!m_page)
578         return Exception { InvalidAccessError };
579     settings().setMinimumDOMTimerInterval(Seconds { intervalInSeconds });
580     return { };
581 }
582
583 ExceptionOr<void> InternalSettings::setDefaultVideoPosterURL(const String& url)
584 {
585     if (!m_page)
586         return Exception { InvalidAccessError };
587     settings().setDefaultVideoPosterURL(url);
588     return { };
589 }
590
591 ExceptionOr<void> InternalSettings::setForcePendingWebGLPolicy(bool forced)
592 {
593     if (!m_page)
594         return Exception { InvalidAccessError };
595     settings().setForcePendingWebGLPolicy(forced);
596     return { };
597 }
598
599 ExceptionOr<void> InternalSettings::setTimeWithoutMouseMovementBeforeHidingControls(double time)
600 {
601     if (!m_page)
602         return Exception { InvalidAccessError };
603     settings().setTimeWithoutMouseMovementBeforeHidingControls(Seconds { time });
604     return { };
605 }
606
607 ExceptionOr<void> InternalSettings::setUseLegacyBackgroundSizeShorthandBehavior(bool enabled)
608 {
609     if (!m_page)
610         return Exception { InvalidAccessError };
611     settings().setUseLegacyBackgroundSizeShorthandBehavior(enabled);
612     return { };
613 }
614
615 ExceptionOr<void> InternalSettings::setAutoscrollForDragAndDropEnabled(bool enabled)
616 {
617     if (!m_page)
618         return Exception { InvalidAccessError };
619     settings().setAutoscrollForDragAndDropEnabled(enabled);
620     return { };
621 }
622
623 ExceptionOr<void> InternalSettings::setFontFallbackPrefersPictographs(bool preferPictographs)
624 {
625     if (!m_page)
626         return Exception { InvalidAccessError };
627     settings().setFontFallbackPrefersPictographs(preferPictographs);
628     return { };
629 }
630
631 ExceptionOr<void> InternalSettings::setFontLoadTimingOverride(const FontLoadTimingOverride& fontLoadTimingOverride)
632 {
633     if (!m_page)
634         return Exception { InvalidAccessError };
635     auto policy = Settings::FontLoadTimingOverride::None;
636     switch (fontLoadTimingOverride) {
637     case FontLoadTimingOverride::Block:
638         policy = Settings::FontLoadTimingOverride::Block;
639         break;
640     case FontLoadTimingOverride::Swap:
641         policy = Settings::FontLoadTimingOverride::Swap;
642         break;
643     case FontLoadTimingOverride::Failure:
644         policy = Settings::FontLoadTimingOverride::Failure;
645         break;
646     }
647     settings().setFontLoadTimingOverride(policy);
648     return { };
649 }
650
651 ExceptionOr<void> InternalSettings::setShouldIgnoreFontLoadCompletions(bool ignore)
652 {
653     if (!m_page)
654         return Exception { InvalidAccessError };
655     settings().setShouldIgnoreFontLoadCompletions(ignore);
656     return { };
657 }
658
659 ExceptionOr<void> InternalSettings::setQuickTimePluginReplacementEnabled(bool enabled)
660 {
661     if (!m_page)
662         return Exception { InvalidAccessError };
663     settings().setQuickTimePluginReplacementEnabled(enabled);
664     return { };
665 }
666
667 ExceptionOr<void> InternalSettings::setYouTubeFlashPluginReplacementEnabled(bool enabled)
668 {
669     if (!m_page)
670         return Exception { InvalidAccessError };
671     settings().setYouTubeFlashPluginReplacementEnabled(enabled);
672     return { };
673 }
674
675 ExceptionOr<void> InternalSettings::setBackgroundShouldExtendBeyondPage(bool hasExtendedBackground)
676 {
677     if (!m_page)
678         return Exception { InvalidAccessError };
679     settings().setBackgroundShouldExtendBeyondPage(hasExtendedBackground);
680     return { };
681 }
682
683 ExceptionOr<void> InternalSettings::setShouldConvertPositionStyleOnCopy(bool convert)
684 {
685     if (!m_page)
686         return Exception { InvalidAccessError };
687     settings().setShouldConvertPositionStyleOnCopy(convert);
688     return { };
689 }
690
691 ExceptionOr<void> InternalSettings::setScrollingTreeIncludesFrames(bool enabled)
692 {
693     if (!m_page)
694         return Exception { InvalidAccessError };
695     settings().setScrollingTreeIncludesFrames(enabled);
696     return { };
697 }
698
699 ExceptionOr<void> InternalSettings::setAllowUnclampedScrollPosition(bool allowUnclamped)
700 {
701     if (!m_page || !m_page->mainFrame().view())
702         return Exception { InvalidAccessError };
703
704     m_page->mainFrame().view()->setAllowsUnclampedScrollPositionForTesting(allowUnclamped);
705     return { };
706 }
707
708 ExceptionOr<void> InternalSettings::setAllowsInlineMediaPlayback(bool allows)
709 {
710     if (!m_page)
711         return Exception { InvalidAccessError };
712     settings().setAllowsInlineMediaPlayback(allows);
713     return { };
714 }
715
716 ExceptionOr<void> InternalSettings::setAllowsInlineMediaPlaybackAfterFullscreen(bool allows)
717 {
718     if (!m_page)
719         return Exception { InvalidAccessError };
720     settings().setAllowsInlineMediaPlaybackAfterFullscreen(allows);
721     return { };
722 }
723
724 ExceptionOr<void> InternalSettings::setInlineMediaPlaybackRequiresPlaysInlineAttribute(bool requires)
725 {
726     if (!m_page)
727         return Exception { InvalidAccessError };
728     settings().setInlineMediaPlaybackRequiresPlaysInlineAttribute(requires);
729     return { };
730 }
731
732 ExceptionOr<void> InternalSettings::setShouldMockBoldSystemFontForAccessibility(bool requires)
733 {
734     if (!m_page)
735         return Exception { InvalidAccessError };
736     RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(requires);
737     FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(requires);
738     return { };
739 }
740
741 void InternalSettings::setIndexedDBWorkersEnabled(bool enabled)
742 {
743 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
744     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(enabled);
745 #else
746     UNUSED_PARAM(enabled);
747 #endif
748 }
749
750 void InternalSettings::setWebGL2Enabled(bool enabled)
751 {
752 #if ENABLE(WEBGL2)
753     RuntimeEnabledFeatures::sharedFeatures().setWebGL2Enabled(enabled);
754 #else
755     UNUSED_PARAM(enabled);
756 #endif
757 }
758
759 void InternalSettings::setWebGPUEnabled(bool enabled)
760 {
761 #if ENABLE(WEBGPU)
762     RuntimeEnabledFeatures::sharedFeatures().setWebGPUEnabled(enabled);
763 #else
764     UNUSED_PARAM(enabled);
765 #endif
766 }
767
768 void InternalSettings::setWebVREnabled(bool enabled)
769 {
770     RuntimeEnabledFeatures::sharedFeatures().setWebVREnabled(enabled);
771 }
772
773 void InternalSettings::setScreenCaptureEnabled(bool enabled)
774 {
775 #if ENABLE(MEDIA_STREAM)
776     RuntimeEnabledFeatures::sharedFeatures().setScreenCaptureEnabled(enabled);
777 #else
778     UNUSED_PARAM(enabled);
779 #endif
780 }
781
782 void InternalSettings::setStorageAccessPromptsEnabled(bool enabled)
783 {
784     RuntimeEnabledFeatures::sharedFeatures().setStorageAccessPromptsEnabled(enabled);
785 }
786     
787 ExceptionOr<String> InternalSettings::userInterfaceDirectionPolicy()
788 {
789     if (!m_page)
790         return Exception { InvalidAccessError };
791     switch (settings().userInterfaceDirectionPolicy()) {
792     case UserInterfaceDirectionPolicy::Content:
793         return String { ASCIILiteral { "Content" } };
794     case UserInterfaceDirectionPolicy::System:
795         return String { ASCIILiteral { "View" } };
796     }
797     ASSERT_NOT_REACHED();
798     return Exception { InvalidAccessError };
799 }
800
801 ExceptionOr<void> InternalSettings::setUserInterfaceDirectionPolicy(const String& policy)
802 {
803     if (!m_page)
804         return Exception { InvalidAccessError };
805     if (equalLettersIgnoringASCIICase(policy, "content")) {
806         settings().setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::Content);
807         return { };
808     }
809     if (equalLettersIgnoringASCIICase(policy, "view")) {
810         settings().setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::System);
811         return { };
812     }
813     return Exception { InvalidAccessError };
814 }
815
816 ExceptionOr<String> InternalSettings::systemLayoutDirection()
817 {
818     if (!m_page)
819         return Exception { InvalidAccessError };
820     switch (settings().systemLayoutDirection()) {
821     case LTR:
822         return String { ASCIILiteral { "LTR" } };
823     case RTL:
824         return String { ASCIILiteral { "RTL" } };
825     }
826     ASSERT_NOT_REACHED();
827     return Exception { InvalidAccessError };
828 }
829
830 ExceptionOr<void> InternalSettings::setSystemLayoutDirection(const String& direction)
831 {
832     if (!m_page)
833         return Exception { InvalidAccessError };
834     if (equalLettersIgnoringASCIICase(direction, "ltr")) {
835         settings().setSystemLayoutDirection(LTR);
836         return { };
837     }
838     if (equalLettersIgnoringASCIICase(direction, "rtl")) {
839         settings().setSystemLayoutDirection(RTL);
840         return { };
841     }
842     return Exception { InvalidAccessError };
843 }
844
845 ExceptionOr<void> InternalSettings::setFrameFlattening(FrameFlatteningValue frameFlattening)
846 {
847     if (!m_page)
848         return Exception { InvalidAccessError };
849     settings().setFrameFlattening(frameFlattening);
850     return { };
851 }
852
853 void InternalSettings::setAllowsAnySSLCertificate(bool allowsAnyCertificate)
854 {
855     DeprecatedGlobalSettings::setAllowsAnySSLCertificate(allowsAnyCertificate);
856 #if USE(SOUP)
857     SoupNetworkSession::setShouldIgnoreTLSErrors(allowsAnyCertificate);
858 #endif
859 }
860
861 ExceptionOr<bool> InternalSettings::deferredCSSParserEnabled()
862 {
863     if (!m_page)
864         return Exception { InvalidAccessError };
865     return settings().deferredCSSParserEnabled();
866 }
867
868 ExceptionOr<void> InternalSettings::setDeferredCSSParserEnabled(bool enabled)
869 {
870     if (!m_page)
871         return Exception { InvalidAccessError };
872     settings().setDeferredCSSParserEnabled(enabled);
873     return { };
874 }
875
876 ExceptionOr<void> InternalSettings::setShouldManageAudioSessionCategory(bool should)
877 {
878 #if USE(AUDIO_SESSION)
879     DeprecatedGlobalSettings::setShouldManageAudioSessionCategory(should);
880     return { };
881 #else
882     UNUSED_PARAM(should);
883     return Exception { InvalidAccessError };
884 #endif
885 }
886
887 ExceptionOr<void> InternalSettings::setCustomPasteboardDataEnabled(bool enabled)
888 {
889     RuntimeEnabledFeatures::sharedFeatures().setCustomPasteboardDataEnabled(enabled);
890     return { };
891 }
892
893 ExceptionOr<void> InternalSettings::setAccessibilityEventsEnabled(bool enabled)
894 {
895     if (!m_page)
896         return Exception { InvalidAccessError };
897 #if ENABLE(ACCESSIBILITY_EVENTS)
898     settings().setAccessibilityEventsEnabled(enabled);
899 #else
900     UNUSED_PARAM(enabled);
901 #endif
902     return { };
903 }
904
905 static InternalSettings::ForcedAccessibilityValue settingsToInternalSettingsValue(Settings::ForcedAccessibilityValue value)
906 {
907     switch (value) {
908     case Settings::ForcedAccessibilityValue::System:
909         return InternalSettings::ForcedAccessibilityValue::System;
910     case Settings::ForcedAccessibilityValue::On:
911         return InternalSettings::ForcedAccessibilityValue::On;
912     case Settings::ForcedAccessibilityValue::Off:
913         return InternalSettings::ForcedAccessibilityValue::Off;
914     }
915
916     ASSERT_NOT_REACHED();
917     return InternalSettings::ForcedAccessibilityValue::Off;
918 }
919
920 static Settings::ForcedAccessibilityValue internalSettingsToSettingsValue(InternalSettings::ForcedAccessibilityValue value)
921 {
922     switch (value) {
923     case InternalSettings::ForcedAccessibilityValue::System:
924         return Settings::ForcedAccessibilityValue::System;
925     case InternalSettings::ForcedAccessibilityValue::On:
926         return Settings::ForcedAccessibilityValue::On;
927     case InternalSettings::ForcedAccessibilityValue::Off:
928         return Settings::ForcedAccessibilityValue::Off;
929     }
930
931     ASSERT_NOT_REACHED();
932     return Settings::ForcedAccessibilityValue::Off;
933 }
934
935 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedColorsAreInvertedAccessibilityValue() const
936 {
937     return settingsToInternalSettingsValue(settings().forcedColorsAreInvertedAccessibilityValue());
938 }
939
940 void InternalSettings::setForcedColorsAreInvertedAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
941 {
942     settings().setForcedColorsAreInvertedAccessibilityValue(internalSettingsToSettingsValue(value));
943 }
944
945 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedDisplayIsMonochromeAccessibilityValue() const
946 {
947     return settingsToInternalSettingsValue(settings().forcedDisplayIsMonochromeAccessibilityValue());
948 }
949
950 void InternalSettings::setForcedDisplayIsMonochromeAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
951 {
952     settings().setForcedDisplayIsMonochromeAccessibilityValue(internalSettingsToSettingsValue(value));
953 }
954
955 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedPrefersReducedMotionAccessibilityValue() const
956 {
957     return settingsToInternalSettingsValue(settings().forcedPrefersReducedMotionAccessibilityValue());
958 }
959
960 void InternalSettings::setForcedPrefersReducedMotionAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
961 {
962     settings().setForcedPrefersReducedMotionAccessibilityValue(internalSettingsToSettingsValue(value));
963 }
964
965 bool InternalSettings::webAnimationsCSSIntegrationEnabled()
966 {
967     return RuntimeEnabledFeatures::sharedFeatures().webAnimationsCSSIntegrationEnabled();
968 }
969
970 // If you add to this class, make sure that you update the Backup class for test reproducability!
971
972 }