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