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