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