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