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