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