[WebVR] Add IDLs and stubs
[WebKit-https.git] / Source / WebCore / testing / InternalSettings.cpp
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  * Copyright (C) 2013 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "InternalSettings.h"
29
30 #include "CaptionUserPreferences.h"
31 #include "Document.h"
32 #include "FontCache.h"
33 #include "FrameView.h"
34 #include "LocaleToScriptMapping.h"
35 #include "MainFrame.h"
36 #include "Page.h"
37 #include "PageGroup.h"
38 #include "RenderTheme.h"
39 #include "RuntimeEnabledFeatures.h"
40 #include "Settings.h"
41 #include "Supplementable.h"
42 #include "TextRun.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(settings.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_webFontsAlwaysFallBack(settings.webFontsAlwaysFallBack())
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_frameFlattening(settings.frameFlattening())
103 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
104     , m_indexedDBWorkersEnabled(RuntimeEnabledFeatures::sharedFeatures().indexedDBWorkersEnabled())
105 #endif
106     , m_cssGridLayoutEnabled(RuntimeEnabledFeatures::sharedFeatures().isCSSGridLayoutEnabled())
107 #if ENABLE(WEBGL2)
108     , m_webGL2Enabled(RuntimeEnabledFeatures::sharedFeatures().webGL2Enabled())
109 #endif
110 #if ENABLE(WEBGPU)
111     , m_webGPUEnabled(RuntimeEnabledFeatures::sharedFeatures().webGPUEnabled())
112 #endif
113     , m_shouldMockBoldSystemFontForAccessibility(RenderTheme::singleton().shouldMockBoldSystemFontForAccessibility())
114 #if USE(AUDIO_SESSION)
115     , m_shouldManageAudioSessionCategory(Settings::shouldManageAudioSessionCategory())
116 #endif
117 {
118 }
119
120 void InternalSettings::Backup::restoreTo(Settings& settings)
121 {
122     settings.setEditingBehaviorType(m_originalEditingBehavior);
123
124     for (const auto& standardFont : m_standardFontFamilies)
125         settings.setStandardFontFamily(standardFont.value, static_cast<UScriptCode>(standardFont.key));
126     m_standardFontFamilies.clear();
127
128     for (const auto& fixedFont : m_fixedFontFamilies)
129         settings.setFixedFontFamily(fixedFont.value, static_cast<UScriptCode>(fixedFont.key));
130     m_fixedFontFamilies.clear();
131
132     for (const auto& serifFont : m_serifFontFamilies)
133         settings.setSerifFontFamily(serifFont.value, static_cast<UScriptCode>(serifFont.key));
134     m_serifFontFamilies.clear();
135
136     for (const auto& sansSerifFont : m_sansSerifFontFamilies)
137         settings.setSansSerifFontFamily(sansSerifFont.value, static_cast<UScriptCode>(sansSerifFont.key));
138     m_sansSerifFontFamilies.clear();
139
140     for (const auto& cursiveFont : m_cursiveFontFamilies)
141         settings.setCursiveFontFamily(cursiveFont.value, static_cast<UScriptCode>(cursiveFont.key));
142     m_cursiveFontFamilies.clear();
143
144     for (const auto& fantasyFont : m_fantasyFontFamilies)
145         settings.setFantasyFontFamily(fantasyFont.value, static_cast<UScriptCode>(fantasyFont.key));
146     m_fantasyFontFamilies.clear();
147
148     for (const auto& pictographFont : m_pictographFontFamilies)
149         settings.setPictographFontFamily(pictographFont.value, static_cast<UScriptCode>(pictographFont.key));
150     m_pictographFontFamilies.clear();
151
152 #if ENABLE(TEXT_AUTOSIZING)
153     settings.setTextAutosizingEnabled(m_originalTextAutosizingEnabled);
154     settings.setTextAutosizingWindowSizeOverride(m_originalTextAutosizingWindowSizeOverride);
155 #endif
156     settings.setMediaTypeOverride(m_originalMediaTypeOverride);
157     settings.setCanvasUsesAcceleratedDrawing(m_originalCanvasUsesAcceleratedDrawing);
158     settings.setImagesEnabled(m_imagesEnabled);
159     settings.setPreferMIMETypeForImages(m_preferMIMETypeForImages);
160     settings.setMinimumDOMTimerInterval(m_minimumDOMTimerInterval);
161 #if ENABLE(VIDEO_TRACK)
162     settings.setShouldDisplaySubtitles(m_shouldDisplaySubtitles);
163     settings.setShouldDisplayCaptions(m_shouldDisplayCaptions);
164     settings.setShouldDisplayTextDescriptions(m_shouldDisplayTextDescriptions);
165 #endif
166     settings.setDefaultVideoPosterURL(m_defaultVideoPosterURL);
167     settings.setForcePendingWebGLPolicy(m_forcePendingWebGLPolicy);
168     settings.setTimeWithoutMouseMovementBeforeHidingControls(m_originalTimeWithoutMouseMovementBeforeHidingControls);
169     settings.setUseLegacyBackgroundSizeShorthandBehavior(m_useLegacyBackgroundSizeShorthandBehavior);
170     settings.setAutoscrollForDragAndDropEnabled(m_autoscrollForDragAndDropEnabled);
171     settings.setShouldConvertPositionStyleOnCopy(m_shouldConvertPositionStyleOnCopy);
172     settings.setFontFallbackPrefersPictographs(m_fontFallbackPrefersPictographs);
173     settings.setWebFontsAlwaysFallBack(m_webFontsAlwaysFallBack);
174     settings.setBackgroundShouldExtendBeyondPage(m_backgroundShouldExtendBeyondPage);
175     settings.setStorageBlockingPolicy(m_storageBlockingPolicy);
176     settings.setScrollingTreeIncludesFrames(m_scrollingTreeIncludesFrames);
177 #if ENABLE(TOUCH_EVENTS)
178     settings.setTouchEventEmulationEnabled(m_touchEventEmulationEnabled);
179 #endif
180     settings.setAllowsInlineMediaPlayback(m_allowsInlineMediaPlayback);
181     settings.setAllowsInlineMediaPlaybackAfterFullscreen(m_allowsInlineMediaPlaybackAfterFullscreen);
182     settings.setInlineMediaPlaybackRequiresPlaysInlineAttribute(m_inlineMediaPlaybackRequiresPlaysInlineAttribute);
183     settings.setQuickTimePluginReplacementEnabled(m_quickTimePluginReplacementEnabled);
184     settings.setYouTubeFlashPluginReplacementEnabled(m_youTubeFlashPluginReplacementEnabled);
185     settings.setDeferredCSSParserEnabled(m_deferredCSSParserEnabled);
186     settings.setInputEventsEnabled(m_inputEventsEnabled);
187     settings.setUserInterfaceDirectionPolicy(m_userInterfaceDirectionPolicy);
188     settings.setSystemLayoutDirection(m_systemLayoutDirection);
189     settings.setPdfImageCachingPolicy(m_pdfImageCachingPolicy);
190     settings.setForcedColorsAreInvertedAccessibilityValue(m_forcedColorsAreInvertedAccessibilityValue);
191     settings.setForcedDisplayIsMonochromeAccessibilityValue(m_forcedDisplayIsMonochromeAccessibilityValue);
192     settings.setForcedPrefersReducedMotionAccessibilityValue(m_forcedPrefersReducedMotionAccessibilityValue);
193     Settings::setAllowsAnySSLCertificate(false);
194     RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
195     FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
196     settings.setFrameFlattening(m_frameFlattening);
197
198 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
199     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(m_indexedDBWorkersEnabled);
200 #endif
201     RuntimeEnabledFeatures::sharedFeatures().setCSSGridLayoutEnabled(m_cssGridLayoutEnabled);
202 #if ENABLE(WEBGL2)
203     RuntimeEnabledFeatures::sharedFeatures().setWebGL2Enabled(m_webGL2Enabled);
204 #endif
205 #if ENABLE(WEBGPU)
206     RuntimeEnabledFeatures::sharedFeatures().setWebGPUEnabled(m_webGPUEnabled);
207 #endif
208     RuntimeEnabledFeatures::sharedFeatures().setWebVREnabled(m_webVREnabled);
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
415     settings().setMediaTypeOverride(mediaType);
416     return { };
417 }
418
419 ExceptionOr<void> InternalSettings::setCanStartMedia(bool enabled)
420 {
421     if (!m_page)
422         return Exception { InvalidAccessError };
423     m_page->setCanStartMedia(enabled);
424     return { };
425 }
426
427 ExceptionOr<void> InternalSettings::setAllowsAirPlayForMediaPlayback(bool allows)
428 {
429     if (!m_page)
430         return Exception { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
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 { SyntaxError };
465     return { };
466 }
467
468 ExceptionOr<void> InternalSettings::setShouldDisplayTrackKind(const String& kind, bool enabled)
469 {
470     if (!m_page)
471         return Exception { InvalidAccessError };
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 { SyntaxError };
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 { InvalidAccessError };
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 { SyntaxError };
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 { InvalidAccessError };
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 { SyntaxError };
521     return { };
522 }
523
524 ExceptionOr<void> InternalSettings::setPreferMIMETypeForImages(bool preferMIMETypeForImages)
525 {
526     if (!m_page)
527         return Exception { InvalidAccessError };
528     settings().setPreferMIMETypeForImages(preferMIMETypeForImages);
529     return { };
530 }
531
532 ExceptionOr<void> InternalSettings::setImagesEnabled(bool enabled)
533 {
534     if (!m_page)
535         return Exception { InvalidAccessError };
536     settings().setImagesEnabled(enabled);
537     return { };
538 }
539
540 ExceptionOr<void> InternalSettings::setPDFImageCachingPolicy(const String& policy)
541 {
542     if (!m_page)
543         return Exception { InvalidAccessError };
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 { SyntaxError };
554     return { };
555 }
556
557 ExceptionOr<void> InternalSettings::setMinimumTimerInterval(double intervalInSeconds)
558 {
559     if (!m_page)
560         return Exception { InvalidAccessError };
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 { InvalidAccessError };
569     settings().setDefaultVideoPosterURL(url);
570     return { };
571 }
572
573 ExceptionOr<void> InternalSettings::setForcePendingWebGLPolicy(bool forced)
574 {
575     if (!m_page)
576         return Exception { InvalidAccessError };
577     settings().setForcePendingWebGLPolicy(forced);
578     return { };
579 }
580
581 ExceptionOr<void> InternalSettings::setTimeWithoutMouseMovementBeforeHidingControls(double time)
582 {
583     if (!m_page)
584         return Exception { InvalidAccessError };
585     settings().setTimeWithoutMouseMovementBeforeHidingControls(Seconds { time });
586     return { };
587 }
588
589 ExceptionOr<void> InternalSettings::setUseLegacyBackgroundSizeShorthandBehavior(bool enabled)
590 {
591     if (!m_page)
592         return Exception { InvalidAccessError };
593     settings().setUseLegacyBackgroundSizeShorthandBehavior(enabled);
594     return { };
595 }
596
597 ExceptionOr<void> InternalSettings::setAutoscrollForDragAndDropEnabled(bool enabled)
598 {
599     if (!m_page)
600         return Exception { InvalidAccessError };
601     settings().setAutoscrollForDragAndDropEnabled(enabled);
602     return { };
603 }
604
605 ExceptionOr<void> InternalSettings::setFontFallbackPrefersPictographs(bool preferPictographs)
606 {
607     if (!m_page)
608         return Exception { InvalidAccessError };
609     settings().setFontFallbackPrefersPictographs(preferPictographs);
610     return { };
611 }
612
613 ExceptionOr<void> InternalSettings::setWebFontsAlwaysFallBack(bool enable)
614 {
615     if (!m_page)
616         return Exception { InvalidAccessError };
617     settings().setWebFontsAlwaysFallBack(enable);
618     return { };
619 }
620
621 ExceptionOr<void> InternalSettings::setQuickTimePluginReplacementEnabled(bool enabled)
622 {
623     if (!m_page)
624         return Exception { InvalidAccessError };
625     settings().setQuickTimePluginReplacementEnabled(enabled);
626     return { };
627 }
628
629 ExceptionOr<void> InternalSettings::setYouTubeFlashPluginReplacementEnabled(bool enabled)
630 {
631     if (!m_page)
632         return Exception { InvalidAccessError };
633     settings().setYouTubeFlashPluginReplacementEnabled(enabled);
634     return { };
635 }
636
637 ExceptionOr<void> InternalSettings::setBackgroundShouldExtendBeyondPage(bool hasExtendedBackground)
638 {
639     if (!m_page)
640         return Exception { InvalidAccessError };
641     settings().setBackgroundShouldExtendBeyondPage(hasExtendedBackground);
642     return { };
643 }
644
645 ExceptionOr<void> InternalSettings::setShouldConvertPositionStyleOnCopy(bool convert)
646 {
647     if (!m_page)
648         return Exception { InvalidAccessError };
649     settings().setShouldConvertPositionStyleOnCopy(convert);
650     return { };
651 }
652
653 ExceptionOr<void> InternalSettings::setScrollingTreeIncludesFrames(bool enabled)
654 {
655     if (!m_page)
656         return Exception { InvalidAccessError };
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 { InvalidAccessError };
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 { InvalidAccessError };
674     settings().setAllowsInlineMediaPlayback(allows);
675     return { };
676 }
677
678 ExceptionOr<void> InternalSettings::setAllowsInlineMediaPlaybackAfterFullscreen(bool allows)
679 {
680     if (!m_page)
681         return Exception { InvalidAccessError };
682     settings().setAllowsInlineMediaPlaybackAfterFullscreen(allows);
683     return { };
684 }
685
686 ExceptionOr<void> InternalSettings::setInlineMediaPlaybackRequiresPlaysInlineAttribute(bool requires)
687 {
688     if (!m_page)
689         return Exception { InvalidAccessError };
690     settings().setInlineMediaPlaybackRequiresPlaysInlineAttribute(requires);
691     return { };
692 }
693
694 ExceptionOr<void> InternalSettings::setShouldMockBoldSystemFontForAccessibility(bool requires)
695 {
696     if (!m_page)
697         return Exception { InvalidAccessError };
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 void InternalSettings::setWebVREnabled(bool enabled)
736 {
737     RuntimeEnabledFeatures::sharedFeatures().setWebVREnabled(enabled);
738 }
739
740 ExceptionOr<String> InternalSettings::userInterfaceDirectionPolicy()
741 {
742     if (!m_page)
743         return Exception { InvalidAccessError };
744     switch (settings().userInterfaceDirectionPolicy()) {
745     case UserInterfaceDirectionPolicy::Content:
746         return String { ASCIILiteral { "Content" } };
747     case UserInterfaceDirectionPolicy::System:
748         return String { ASCIILiteral { "View" } };
749     }
750     ASSERT_NOT_REACHED();
751     return Exception { InvalidAccessError };
752 }
753
754 ExceptionOr<void> InternalSettings::setUserInterfaceDirectionPolicy(const String& policy)
755 {
756     if (!m_page)
757         return Exception { InvalidAccessError };
758     if (equalLettersIgnoringASCIICase(policy, "content")) {
759         settings().setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::Content);
760         return { };
761     }
762     if (equalLettersIgnoringASCIICase(policy, "view")) {
763         settings().setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::System);
764         return { };
765     }
766     return Exception { InvalidAccessError };
767 }
768
769 ExceptionOr<String> InternalSettings::systemLayoutDirection()
770 {
771     if (!m_page)
772         return Exception { InvalidAccessError };
773     switch (settings().systemLayoutDirection()) {
774     case LTR:
775         return String { ASCIILiteral { "LTR" } };
776     case RTL:
777         return String { ASCIILiteral { "RTL" } };
778     }
779     ASSERT_NOT_REACHED();
780     return Exception { InvalidAccessError };
781 }
782
783 ExceptionOr<void> InternalSettings::setSystemLayoutDirection(const String& direction)
784 {
785     if (!m_page)
786         return Exception { InvalidAccessError };
787     if (equalLettersIgnoringASCIICase(direction, "ltr")) {
788         settings().setSystemLayoutDirection(LTR);
789         return { };
790     }
791     if (equalLettersIgnoringASCIICase(direction, "rtl")) {
792         settings().setSystemLayoutDirection(RTL);
793         return { };
794     }
795     return Exception { InvalidAccessError };
796 }
797
798 static FrameFlattening internalSettingsToWebCoreValue(InternalSettings::FrameFlatteningValue value)
799 {
800     switch (value) {
801     case InternalSettings::FrameFlatteningValue::Disabled:
802         return FrameFlatteningDisabled;
803     case InternalSettings::FrameFlatteningValue::EnabledForNonFullScreenIFrames:
804         return FrameFlatteningEnabledForNonFullScreenIFrames;
805     case InternalSettings::FrameFlatteningValue::FullyEnabled:
806         return FrameFlatteningFullyEnabled;
807     }
808
809     ASSERT_NOT_REACHED();
810     return FrameFlatteningDisabled;
811 }
812
813 ExceptionOr<void> InternalSettings::setFrameFlattening(const FrameFlatteningValue& frameFlattening)
814 {
815     if (!m_page)
816         return Exception { InvalidAccessError };
817     settings().setFrameFlattening(internalSettingsToWebCoreValue(frameFlattening));
818     return { };
819 }
820
821 void InternalSettings::setAllowsAnySSLCertificate(bool allowsAnyCertificate)
822 {
823     Settings::setAllowsAnySSLCertificate(allowsAnyCertificate);
824 #if USE(SOUP)
825     SoupNetworkSession::setShouldIgnoreTLSErrors(allowsAnyCertificate);
826 #endif
827 }
828
829 ExceptionOr<bool> InternalSettings::deferredCSSParserEnabled()
830 {
831     if (!m_page)
832         return Exception { InvalidAccessError };
833     return settings().deferredCSSParserEnabled();
834 }
835
836 ExceptionOr<void> InternalSettings::setDeferredCSSParserEnabled(bool enabled)
837 {
838     if (!m_page)
839         return Exception { InvalidAccessError };
840     settings().setDeferredCSSParserEnabled(enabled);
841     return { };
842 }
843
844 ExceptionOr<void> InternalSettings::setShouldManageAudioSessionCategory(bool should)
845 {
846 #if USE(AUDIO_SESSION)
847     Settings::setShouldManageAudioSessionCategory(should);
848     return { };
849 #else
850     UNUSED_PARAM(should);
851     return Exception { InvalidAccessError };
852 #endif
853 }
854
855 static InternalSettings::ForcedAccessibilityValue settingsToInternalSettingsValue(Settings::ForcedAccessibilityValue value)
856 {
857     switch (value) {
858     case Settings::ForcedAccessibilityValue::System:
859         return InternalSettings::ForcedAccessibilityValue::System;
860     case Settings::ForcedAccessibilityValue::On:
861         return InternalSettings::ForcedAccessibilityValue::On;
862     case Settings::ForcedAccessibilityValue::Off:
863         return InternalSettings::ForcedAccessibilityValue::Off;
864     }
865
866     ASSERT_NOT_REACHED();
867     return InternalSettings::ForcedAccessibilityValue::Off;
868 }
869
870 static Settings::ForcedAccessibilityValue internalSettingsToSettingsValue(InternalSettings::ForcedAccessibilityValue value)
871 {
872     switch (value) {
873     case InternalSettings::ForcedAccessibilityValue::System:
874         return Settings::ForcedAccessibilityValue::System;
875     case InternalSettings::ForcedAccessibilityValue::On:
876         return Settings::ForcedAccessibilityValue::On;
877     case InternalSettings::ForcedAccessibilityValue::Off:
878         return Settings::ForcedAccessibilityValue::Off;
879     }
880
881     ASSERT_NOT_REACHED();
882     return Settings::ForcedAccessibilityValue::Off;
883 }
884
885 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedColorsAreInvertedAccessibilityValue() const
886 {
887     return settingsToInternalSettingsValue(settings().forcedColorsAreInvertedAccessibilityValue());
888 }
889
890 void InternalSettings::setForcedColorsAreInvertedAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
891 {
892     settings().setForcedColorsAreInvertedAccessibilityValue(internalSettingsToSettingsValue(value));
893 }
894
895 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedDisplayIsMonochromeAccessibilityValue() const
896 {
897     return settingsToInternalSettingsValue(settings().forcedDisplayIsMonochromeAccessibilityValue());
898 }
899
900 void InternalSettings::setForcedDisplayIsMonochromeAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
901 {
902     settings().setForcedDisplayIsMonochromeAccessibilityValue(internalSettingsToSettingsValue(value));
903 }
904
905 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedPrefersReducedMotionAccessibilityValue() const
906 {
907     return settingsToInternalSettingsValue(settings().forcedPrefersReducedMotionAccessibilityValue());
908 }
909
910 void InternalSettings::setForcedPrefersReducedMotionAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
911 {
912     settings().setForcedPrefersReducedMotionAccessibilityValue(internalSettingsToSettingsValue(value));
913 }
914
915 // If you add to this class, make sure that you update the Backup class for test reproducability!
916
917 }