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