c9fcab92a40d357b01a857e9177b76e03ad3028e
[WebKit-https.git] / Source / WebCore / testing / InternalSettings.cpp
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  * Copyright (C) 2013 Apple Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "InternalSettings.h"
29
30 #include "CaptionUserPreferences.h"
31 #include "Document.h"
32 #include "ExceptionCode.h"
33 #include "FontCache.h"
34 #include "FrameView.h"
35 #include "Language.h"
36 #include "LocaleToScriptMapping.h"
37 #include "MainFrame.h"
38 #include "Page.h"
39 #include "PageGroup.h"
40 #include "RenderTheme.h"
41 #include "RuntimeEnabledFeatures.h"
42 #include "Settings.h"
43 #include "Supplementable.h"
44 #include "TextRun.h"
45
46 #if ENABLE(INPUT_TYPE_COLOR)
47 #include "ColorChooser.h"
48 #endif
49
50 #if USE(SOUP)
51 #include "SoupNetworkSession.h"
52 #endif
53
54 namespace WebCore {
55
56 InternalSettings::Backup::Backup(Settings& settings)
57     : m_originalEditingBehavior(settings.editingBehaviorType())
58 #if ENABLE(TEXT_AUTOSIZING)
59     , m_originalTextAutosizingEnabled(settings.textAutosizingEnabled())
60     , m_originalTextAutosizingWindowSizeOverride(settings.textAutosizingWindowSizeOverride())
61 #endif
62     , m_originalMediaTypeOverride(settings.mediaTypeOverride())
63     , m_originalCanvasUsesAcceleratedDrawing(settings.canvasUsesAcceleratedDrawing())
64     , m_originalMockScrollbarsEnabled(settings.mockScrollbarsEnabled())
65     , m_imagesEnabled(settings.areImagesEnabled())
66     , m_preferMIMETypeForImages(settings.preferMIMETypeForImages())
67     , m_minimumDOMTimerInterval(settings.minimumDOMTimerInterval())
68 #if ENABLE(VIDEO_TRACK)
69     , m_shouldDisplaySubtitles(settings.shouldDisplaySubtitles())
70     , m_shouldDisplayCaptions(settings.shouldDisplayCaptions())
71     , m_shouldDisplayTextDescriptions(settings.shouldDisplayTextDescriptions())
72 #endif
73     , m_defaultVideoPosterURL(settings.defaultVideoPosterURL())
74     , m_forcePendingWebGLPolicy(settings.isForcePendingWebGLPolicy())
75     , m_originalTimeWithoutMouseMovementBeforeHidingControls(settings.timeWithoutMouseMovementBeforeHidingControls())
76     , m_useLegacyBackgroundSizeShorthandBehavior(settings.useLegacyBackgroundSizeShorthandBehavior())
77     , m_autoscrollForDragAndDropEnabled(settings.autoscrollForDragAndDropEnabled())
78     , m_quickTimePluginReplacementEnabled(settings.quickTimePluginReplacementEnabled())
79     , m_youTubeFlashPluginReplacementEnabled(settings.youTubeFlashPluginReplacementEnabled())
80     , m_shouldConvertPositionStyleOnCopy(settings.shouldConvertPositionStyleOnCopy())
81     , m_fontFallbackPrefersPictographs(settings.fontFallbackPrefersPictographs())
82     , m_webFontsAlwaysFallBack(settings.webFontsAlwaysFallBack())
83     , m_backgroundShouldExtendBeyondPage(settings.backgroundShouldExtendBeyondPage())
84     , m_storageBlockingPolicy(settings.storageBlockingPolicy())
85     , m_scrollingTreeIncludesFrames(settings.scrollingTreeIncludesFrames())
86 #if ENABLE(TOUCH_EVENTS)
87     , m_touchEventEmulationEnabled(settings.isTouchEventEmulationEnabled())
88 #endif
89 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
90     , m_allowsAirPlayForMediaPlayback(settings.allowsAirPlayForMediaPlayback())
91 #endif
92     , m_allowsInlineMediaPlayback(settings.allowsInlineMediaPlayback())
93     , m_allowsInlineMediaPlaybackAfterFullscreen(settings.allowsInlineMediaPlaybackAfterFullscreen())
94     , m_inlineMediaPlaybackRequiresPlaysInlineAttribute(settings.inlineMediaPlaybackRequiresPlaysInlineAttribute())
95     , m_deferredCSSParserEnabled(settings.deferredCSSParserEnabled())
96     , m_inputEventsEnabled(settings.inputEventsEnabled())
97     , m_userInterfaceDirectionPolicy(settings.userInterfaceDirectionPolicy())
98     , m_systemLayoutDirection(settings.systemLayoutDirection())
99     , m_pdfImageCachingPolicy(settings.pdfImageCachingPolicy())
100     , m_forcedColorsAreInvertedAccessibilityValue(settings.forcedColorsAreInvertedAccessibilityValue())
101     , m_forcedDisplayIsMonochromeAccessibilityValue(settings.forcedDisplayIsMonochromeAccessibilityValue())
102     , m_forcedPrefersReducedMotionAccessibilityValue(settings.forcedPrefersReducedMotionAccessibilityValue())
103 #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 {
115 }
116
117 void InternalSettings::Backup::restoreTo(Settings& settings)
118 {
119     settings.setEditingBehaviorType(m_originalEditingBehavior);
120
121     for (const auto& standardFont : m_standardFontFamilies)
122         settings.setStandardFontFamily(standardFont.value, static_cast<UScriptCode>(standardFont.key));
123     m_standardFontFamilies.clear();
124
125     for (const auto& fixedFont : m_fixedFontFamilies)
126         settings.setFixedFontFamily(fixedFont.value, static_cast<UScriptCode>(fixedFont.key));
127     m_fixedFontFamilies.clear();
128
129     for (const auto& serifFont : m_serifFontFamilies)
130         settings.setSerifFontFamily(serifFont.value, static_cast<UScriptCode>(serifFont.key));
131     m_serifFontFamilies.clear();
132
133     for (const auto& sansSerifFont : m_sansSerifFontFamilies)
134         settings.setSansSerifFontFamily(sansSerifFont.value, static_cast<UScriptCode>(sansSerifFont.key));
135     m_sansSerifFontFamilies.clear();
136
137     for (const auto& cursiveFont : m_cursiveFontFamilies)
138         settings.setCursiveFontFamily(cursiveFont.value, static_cast<UScriptCode>(cursiveFont.key));
139     m_cursiveFontFamilies.clear();
140
141     for (const auto& fantasyFont : m_fantasyFontFamilies)
142         settings.setFantasyFontFamily(fantasyFont.value, static_cast<UScriptCode>(fantasyFont.key));
143     m_fantasyFontFamilies.clear();
144
145     for (const auto& pictographFont : m_pictographFontFamilies)
146         settings.setPictographFontFamily(pictographFont.value, static_cast<UScriptCode>(pictographFont.key));
147     m_pictographFontFamilies.clear();
148
149 #if ENABLE(TEXT_AUTOSIZING)
150     settings.setTextAutosizingEnabled(m_originalTextAutosizingEnabled);
151     settings.setTextAutosizingWindowSizeOverride(m_originalTextAutosizingWindowSizeOverride);
152 #endif
153     settings.setMediaTypeOverride(m_originalMediaTypeOverride);
154     settings.setCanvasUsesAcceleratedDrawing(m_originalCanvasUsesAcceleratedDrawing);
155     settings.setImagesEnabled(m_imagesEnabled);
156     settings.setPreferMIMETypeForImages(m_preferMIMETypeForImages);
157     settings.setMinimumDOMTimerInterval(m_minimumDOMTimerInterval);
158 #if ENABLE(VIDEO_TRACK)
159     settings.setShouldDisplaySubtitles(m_shouldDisplaySubtitles);
160     settings.setShouldDisplayCaptions(m_shouldDisplayCaptions);
161     settings.setShouldDisplayTextDescriptions(m_shouldDisplayTextDescriptions);
162 #endif
163     settings.setDefaultVideoPosterURL(m_defaultVideoPosterURL);
164     settings.setForcePendingWebGLPolicy(m_forcePendingWebGLPolicy);
165     settings.setTimeWithoutMouseMovementBeforeHidingControls(m_originalTimeWithoutMouseMovementBeforeHidingControls);
166     settings.setUseLegacyBackgroundSizeShorthandBehavior(m_useLegacyBackgroundSizeShorthandBehavior);
167     settings.setAutoscrollForDragAndDropEnabled(m_autoscrollForDragAndDropEnabled);
168     settings.setShouldConvertPositionStyleOnCopy(m_shouldConvertPositionStyleOnCopy);
169     settings.setFontFallbackPrefersPictographs(m_fontFallbackPrefersPictographs);
170     settings.setWebFontsAlwaysFallBack(m_webFontsAlwaysFallBack);
171     settings.setBackgroundShouldExtendBeyondPage(m_backgroundShouldExtendBeyondPage);
172     settings.setStorageBlockingPolicy(m_storageBlockingPolicy);
173     settings.setScrollingTreeIncludesFrames(m_scrollingTreeIncludesFrames);
174 #if ENABLE(TOUCH_EVENTS)
175     settings.setTouchEventEmulationEnabled(m_touchEventEmulationEnabled);
176 #endif
177     settings.setAllowsInlineMediaPlayback(m_allowsInlineMediaPlayback);
178     settings.setAllowsInlineMediaPlaybackAfterFullscreen(m_allowsInlineMediaPlaybackAfterFullscreen);
179     settings.setInlineMediaPlaybackRequiresPlaysInlineAttribute(m_inlineMediaPlaybackRequiresPlaysInlineAttribute);
180     settings.setQuickTimePluginReplacementEnabled(m_quickTimePluginReplacementEnabled);
181     settings.setYouTubeFlashPluginReplacementEnabled(m_youTubeFlashPluginReplacementEnabled);
182     settings.setDeferredCSSParserEnabled(m_deferredCSSParserEnabled);
183     settings.setInputEventsEnabled(m_inputEventsEnabled);
184     settings.setUserInterfaceDirectionPolicy(m_userInterfaceDirectionPolicy);
185     settings.setSystemLayoutDirection(m_systemLayoutDirection);
186     settings.setPdfImageCachingPolicy(m_pdfImageCachingPolicy);
187     settings.setForcedColorsAreInvertedAccessibilityValue(m_forcedColorsAreInvertedAccessibilityValue);
188     settings.setForcedDisplayIsMonochromeAccessibilityValue(m_forcedDisplayIsMonochromeAccessibilityValue);
189     settings.setForcedPrefersReducedMotionAccessibilityValue(m_forcedPrefersReducedMotionAccessibilityValue);
190     Settings::setAllowsAnySSLCertificate(false);
191     RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
192     FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(m_shouldMockBoldSystemFontForAccessibility);
193
194 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
195     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(m_indexedDBWorkersEnabled);
196 #endif
197     RuntimeEnabledFeatures::sharedFeatures().setCSSGridLayoutEnabled(m_cssGridLayoutEnabled);
198 #if ENABLE(WEBGL2)
199     RuntimeEnabledFeatures::sharedFeatures().setWebGL2Enabled(m_webGL2Enabled);
200 #endif
201 #if ENABLE(WEBGPU)
202     RuntimeEnabledFeatures::sharedFeatures().setWebGPUEnabled(m_webGPUEnabled);
203 #endif
204 }
205
206 class InternalSettingsWrapper : public Supplement<Page> {
207 public:
208     explicit InternalSettingsWrapper(Page* page)
209         : m_internalSettings(InternalSettings::create(page)) { }
210     virtual ~InternalSettingsWrapper() { m_internalSettings->hostDestroyed(); }
211 #if !ASSERT_DISABLED
212     bool isRefCountedWrapper() const override { return true; }
213 #endif
214     InternalSettings* internalSettings() const { return m_internalSettings.get(); }
215
216 private:
217     RefPtr<InternalSettings> m_internalSettings;
218 };
219
220 const char* InternalSettings::supplementName()
221 {
222     return "InternalSettings";
223 }
224
225 InternalSettings* InternalSettings::from(Page* page)
226 {
227     if (!Supplement<Page>::from(page, supplementName()))
228         Supplement<Page>::provideTo(page, supplementName(), std::make_unique<InternalSettingsWrapper>(page));
229     return static_cast<InternalSettingsWrapper*>(Supplement<Page>::from(page, supplementName()))->internalSettings();
230 }
231
232 void InternalSettings::hostDestroyed()
233 {
234     m_page = nullptr;
235 }
236
237 InternalSettings::InternalSettings(Page* page)
238     : InternalSettingsGenerated(page)
239     , m_page(page)
240     , m_backup(page->settings())
241 {
242 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
243     setAllowsAirPlayForMediaPlayback(false);
244 #endif
245 #if ENABLE(MEDIA_STREAM)
246     setMediaCaptureRequiresSecureConnection(false);
247 #endif
248 }
249
250 Ref<InternalSettings> InternalSettings::create(Page* page)
251 {
252     return adoptRef(*new InternalSettings(page));
253 }
254
255 void InternalSettings::resetToConsistentState()
256 {
257     m_page->setPageScaleFactor(1, { 0, 0 });
258     m_page->mainFrame().setPageAndTextZoomFactors(1, 1);
259     m_page->setCanStartMedia(true);
260
261     settings().setForcePendingWebGLPolicy(false);
262 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
263     settings().setAllowsAirPlayForMediaPlayback(false);
264 #endif
265 #if ENABLE(MEDIA_STREAM)
266     setMediaCaptureRequiresSecureConnection(false);
267 #endif
268
269     m_backup.restoreTo(settings());
270     m_backup = Backup { settings() };
271
272     InternalSettingsGenerated::resetToConsistentState();
273 }
274
275 Settings& InternalSettings::settings() const
276 {
277     ASSERT(m_page);
278     return m_page->settings();
279 }
280
281 ExceptionOr<void> InternalSettings::setTouchEventEmulationEnabled(bool enabled)
282 {
283     if (!m_page)
284         return Exception { INVALID_ACCESS_ERR };
285 #if ENABLE(TOUCH_EVENTS)
286     settings().setTouchEventEmulationEnabled(enabled);
287 #else
288     UNUSED_PARAM(enabled);
289 #endif
290     return { };
291 }
292
293 ExceptionOr<void> InternalSettings::setStandardFontFamily(const String& family, const String& script)
294 {
295     if (!m_page)
296         return Exception { INVALID_ACCESS_ERR };
297     UScriptCode code = scriptNameToCode(script);
298     if (code == USCRIPT_INVALID_CODE)
299         return { };
300     m_backup.m_standardFontFamilies.add(code, settings().standardFontFamily(code));
301     settings().setStandardFontFamily(family, code);
302     return { };
303 }
304
305 ExceptionOr<void> InternalSettings::setSerifFontFamily(const String& family, const String& script)
306 {
307     if (!m_page)
308         return Exception { INVALID_ACCESS_ERR };
309     UScriptCode code = scriptNameToCode(script);
310     if (code == USCRIPT_INVALID_CODE)
311         return { };
312     m_backup.m_serifFontFamilies.add(code, settings().serifFontFamily(code));
313     settings().setSerifFontFamily(family, code);
314     return { };
315 }
316
317 ExceptionOr<void> InternalSettings::setSansSerifFontFamily(const String& family, const String& script)
318 {
319     if (!m_page)
320         return Exception { INVALID_ACCESS_ERR };
321     UScriptCode code = scriptNameToCode(script);
322     if (code == USCRIPT_INVALID_CODE)
323         return { };
324     m_backup.m_sansSerifFontFamilies.add(code, settings().sansSerifFontFamily(code));
325     settings().setSansSerifFontFamily(family, code);
326     return { };
327 }
328
329 ExceptionOr<void> InternalSettings::setFixedFontFamily(const String& family, const String& script)
330 {
331     if (!m_page)
332         return Exception { INVALID_ACCESS_ERR };
333     UScriptCode code = scriptNameToCode(script);
334     if (code == USCRIPT_INVALID_CODE)
335         return { };
336     m_backup.m_fixedFontFamilies.add(code, settings().fixedFontFamily(code));
337     settings().setFixedFontFamily(family, code);
338     return { };
339 }
340
341 ExceptionOr<void> InternalSettings::setCursiveFontFamily(const String& family, const String& script)
342 {
343     if (!m_page)
344         return Exception { INVALID_ACCESS_ERR };
345     UScriptCode code = scriptNameToCode(script);
346     if (code == USCRIPT_INVALID_CODE)
347         return { };
348     m_backup.m_cursiveFontFamilies.add(code, settings().cursiveFontFamily(code));
349     settings().setCursiveFontFamily(family, code);
350     return { };
351 }
352
353 ExceptionOr<void> InternalSettings::setFantasyFontFamily(const String& family, const String& script)
354 {
355     if (!m_page)
356         return Exception { INVALID_ACCESS_ERR };
357     UScriptCode code = scriptNameToCode(script);
358     if (code == USCRIPT_INVALID_CODE)
359         return { };
360     m_backup.m_fantasyFontFamilies.add(code, settings().fantasyFontFamily(code));
361     settings().setFantasyFontFamily(family, code);
362     return { };
363 }
364
365 ExceptionOr<void> InternalSettings::setPictographFontFamily(const String& family, const String& script)
366 {
367     if (!m_page)
368         return Exception { INVALID_ACCESS_ERR };
369     UScriptCode code = scriptNameToCode(script);
370     if (code == USCRIPT_INVALID_CODE)
371         return { };
372     m_backup.m_pictographFontFamilies.add(code, settings().pictographFontFamily(code));
373     settings().setPictographFontFamily(family, code);
374     return { };
375 }
376
377 ExceptionOr<void> InternalSettings::setTextAutosizingEnabled(bool enabled)
378 {
379     if (!m_page)
380         return Exception { INVALID_ACCESS_ERR };
381 #if ENABLE(TEXT_AUTOSIZING)
382     settings().setTextAutosizingEnabled(enabled);
383 #else
384     UNUSED_PARAM(enabled);
385 #endif
386     return { };
387 }
388
389 ExceptionOr<void> InternalSettings::setTextAutosizingWindowSizeOverride(int width, int height)
390 {
391     if (!m_page)
392         return Exception { INVALID_ACCESS_ERR };
393 #if ENABLE(TEXT_AUTOSIZING)
394     settings().setTextAutosizingWindowSizeOverride(IntSize(width, height));
395 #else
396     UNUSED_PARAM(width);
397     UNUSED_PARAM(height);
398 #endif
399     return { };
400 }
401
402 ExceptionOr<void> InternalSettings::setMediaTypeOverride(const String& mediaType)
403 {
404     if (!m_page)
405         return Exception { INVALID_ACCESS_ERR };
406     settings().setMediaTypeOverride(mediaType);
407     return { };
408 }
409
410 ExceptionOr<void> InternalSettings::setCanStartMedia(bool enabled)
411 {
412     if (!m_page)
413         return Exception { INVALID_ACCESS_ERR };
414     m_page->setCanStartMedia(enabled);
415     return { };
416 }
417
418 ExceptionOr<void> InternalSettings::setAllowsAirPlayForMediaPlayback(bool allows)
419 {
420     if (!m_page)
421         return Exception { INVALID_ACCESS_ERR };
422 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
423     settings().setAllowsAirPlayForMediaPlayback(allows);
424 #else
425     UNUSED_PARAM(allows);
426 #endif
427     return { };
428 }
429
430 ExceptionOr<void> InternalSettings::setMediaCaptureRequiresSecureConnection(bool requires)
431 {
432     if (!m_page)
433         return Exception { INVALID_ACCESS_ERR };
434 #if ENABLE(MEDIA_STREAM)
435     settings().setMediaCaptureRequiresSecureConnection(requires);
436 #else
437     UNUSED_PARAM(requires);
438 #endif
439     return { };
440 }
441
442 ExceptionOr<void> InternalSettings::setEditingBehavior(const String& editingBehavior)
443 {
444     if (!m_page)
445         return Exception { INVALID_ACCESS_ERR };
446     if (equalLettersIgnoringASCIICase(editingBehavior, "win"))
447         settings().setEditingBehaviorType(EditingWindowsBehavior);
448     else if (equalLettersIgnoringASCIICase(editingBehavior, "mac"))
449         settings().setEditingBehaviorType(EditingMacBehavior);
450     else if (equalLettersIgnoringASCIICase(editingBehavior, "unix"))
451         settings().setEditingBehaviorType(EditingUnixBehavior);
452     else if (equalLettersIgnoringASCIICase(editingBehavior, "ios"))
453         settings().setEditingBehaviorType(EditingIOSBehavior);
454     else
455         return Exception { SYNTAX_ERR };
456     return { };
457 }
458
459 ExceptionOr<void> InternalSettings::setShouldDisplayTrackKind(const String& kind, bool enabled)
460 {
461     if (!m_page)
462         return Exception { INVALID_ACCESS_ERR };
463 #if ENABLE(VIDEO_TRACK)
464     auto& captionPreferences = m_page->group().captionPreferences();
465     if (equalLettersIgnoringASCIICase(kind, "subtitles"))
466         captionPreferences.setUserPrefersSubtitles(enabled);
467     else if (equalLettersIgnoringASCIICase(kind, "captions"))
468         captionPreferences.setUserPrefersCaptions(enabled);
469     else if (equalLettersIgnoringASCIICase(kind, "textdescriptions"))
470         captionPreferences.setUserPrefersTextDescriptions(enabled);
471     else
472         return Exception { SYNTAX_ERR };
473 #else
474     UNUSED_PARAM(kind);
475     UNUSED_PARAM(enabled);
476 #endif
477     return { };
478 }
479
480 ExceptionOr<bool> InternalSettings::shouldDisplayTrackKind(const String& kind)
481 {
482     if (!m_page)
483         return Exception { INVALID_ACCESS_ERR };
484 #if ENABLE(VIDEO_TRACK)
485     auto& captionPreferences = m_page->group().captionPreferences();
486     if (equalLettersIgnoringASCIICase(kind, "subtitles"))
487         return captionPreferences.userPrefersSubtitles();
488     if (equalLettersIgnoringASCIICase(kind, "captions"))
489         return captionPreferences.userPrefersCaptions();
490     if (equalLettersIgnoringASCIICase(kind, "textdescriptions"))
491         return captionPreferences.userPrefersTextDescriptions();
492
493     return Exception { SYNTAX_ERR };
494 #else
495     UNUSED_PARAM(kind);
496     return false;
497 #endif
498 }
499
500 ExceptionOr<void> InternalSettings::setStorageBlockingPolicy(const String& mode)
501 {
502     if (!m_page)
503         return Exception { INVALID_ACCESS_ERR };
504     if (mode == "AllowAll")
505         settings().setStorageBlockingPolicy(SecurityOrigin::AllowAllStorage);
506     else if (mode == "BlockThirdParty")
507         settings().setStorageBlockingPolicy(SecurityOrigin::BlockThirdPartyStorage);
508     else if (mode == "BlockAll")
509         settings().setStorageBlockingPolicy(SecurityOrigin::BlockAllStorage);
510     else
511         return Exception { SYNTAX_ERR };
512     return { };
513 }
514
515 ExceptionOr<void> InternalSettings::setPreferMIMETypeForImages(bool preferMIMETypeForImages)
516 {
517     if (!m_page)
518         return Exception { INVALID_ACCESS_ERR };
519     settings().setPreferMIMETypeForImages(preferMIMETypeForImages);
520     return { };
521 }
522
523 ExceptionOr<void> InternalSettings::setImagesEnabled(bool enabled)
524 {
525     if (!m_page)
526         return Exception { INVALID_ACCESS_ERR };
527     settings().setImagesEnabled(enabled);
528     return { };
529 }
530
531 ExceptionOr<void> InternalSettings::setPDFImageCachingPolicy(const String& policy)
532 {
533     if (!m_page)
534         return Exception { INVALID_ACCESS_ERR };
535     if (equalLettersIgnoringASCIICase(policy, "disabled"))
536         settings().setPdfImageCachingPolicy(PDFImageCachingDisabled);
537     else if (equalLettersIgnoringASCIICase(policy, "belowmemorylimit"))
538         settings().setPdfImageCachingPolicy(PDFImageCachingBelowMemoryLimit);
539     else if (equalLettersIgnoringASCIICase(policy, "clipboundsonly"))
540         settings().setPdfImageCachingPolicy(PDFImageCachingClipBoundsOnly);
541     else if (equalLettersIgnoringASCIICase(policy, "enabled"))
542         settings().setPdfImageCachingPolicy(PDFImageCachingEnabled);
543     else
544         return Exception { SYNTAX_ERR };
545     return { };
546 }
547
548 ExceptionOr<void> InternalSettings::setMinimumTimerInterval(double intervalInSeconds)
549 {
550     if (!m_page)
551         return Exception { INVALID_ACCESS_ERR };
552     settings().setMinimumDOMTimerInterval(Seconds { intervalInSeconds });
553     return { };
554 }
555
556 ExceptionOr<void> InternalSettings::setDefaultVideoPosterURL(const String& url)
557 {
558     if (!m_page)
559         return Exception { INVALID_ACCESS_ERR };
560     settings().setDefaultVideoPosterURL(url);
561     return { };
562 }
563
564 ExceptionOr<void> InternalSettings::setForcePendingWebGLPolicy(bool forced)
565 {
566     if (!m_page)
567         return Exception { INVALID_ACCESS_ERR };
568     settings().setForcePendingWebGLPolicy(forced);
569     return { };
570 }
571
572 ExceptionOr<void> InternalSettings::setTimeWithoutMouseMovementBeforeHidingControls(double time)
573 {
574     if (!m_page)
575         return Exception { INVALID_ACCESS_ERR };
576     settings().setTimeWithoutMouseMovementBeforeHidingControls(Seconds { time });
577     return { };
578 }
579
580 ExceptionOr<void> InternalSettings::setUseLegacyBackgroundSizeShorthandBehavior(bool enabled)
581 {
582     if (!m_page)
583         return Exception { INVALID_ACCESS_ERR };
584     settings().setUseLegacyBackgroundSizeShorthandBehavior(enabled);
585     return { };
586 }
587
588 ExceptionOr<void> InternalSettings::setAutoscrollForDragAndDropEnabled(bool enabled)
589 {
590     if (!m_page)
591         return Exception { INVALID_ACCESS_ERR };
592     settings().setAutoscrollForDragAndDropEnabled(enabled);
593     return { };
594 }
595
596 ExceptionOr<void> InternalSettings::setFontFallbackPrefersPictographs(bool preferPictographs)
597 {
598     if (!m_page)
599         return Exception { INVALID_ACCESS_ERR };
600     settings().setFontFallbackPrefersPictographs(preferPictographs);
601     return { };
602 }
603
604 ExceptionOr<void> InternalSettings::setWebFontsAlwaysFallBack(bool enable)
605 {
606     if (!m_page)
607         return Exception { INVALID_ACCESS_ERR };
608     settings().setWebFontsAlwaysFallBack(enable);
609     return { };
610 }
611
612 ExceptionOr<void> InternalSettings::setQuickTimePluginReplacementEnabled(bool enabled)
613 {
614     if (!m_page)
615         return Exception { INVALID_ACCESS_ERR };
616     settings().setQuickTimePluginReplacementEnabled(enabled);
617     return { };
618 }
619
620 ExceptionOr<void> InternalSettings::setYouTubeFlashPluginReplacementEnabled(bool enabled)
621 {
622     if (!m_page)
623         return Exception { INVALID_ACCESS_ERR };
624     settings().setYouTubeFlashPluginReplacementEnabled(enabled);
625     return { };
626 }
627
628 ExceptionOr<void> InternalSettings::setBackgroundShouldExtendBeyondPage(bool hasExtendedBackground)
629 {
630     if (!m_page)
631         return Exception { INVALID_ACCESS_ERR };
632     settings().setBackgroundShouldExtendBeyondPage(hasExtendedBackground);
633     return { };
634 }
635
636 ExceptionOr<void> InternalSettings::setShouldConvertPositionStyleOnCopy(bool convert)
637 {
638     if (!m_page)
639         return Exception { INVALID_ACCESS_ERR };
640     settings().setShouldConvertPositionStyleOnCopy(convert);
641     return { };
642 }
643
644 ExceptionOr<void> InternalSettings::setScrollingTreeIncludesFrames(bool enabled)
645 {
646     if (!m_page)
647         return Exception { INVALID_ACCESS_ERR };
648     settings().setScrollingTreeIncludesFrames(enabled);
649     return { };
650 }
651
652 ExceptionOr<void> InternalSettings::setAllowUnclampedScrollPosition(bool allowUnclamped)
653 {
654     if (!m_page || !m_page->mainFrame().view())
655         return Exception { INVALID_ACCESS_ERR };
656
657     m_page->mainFrame().view()->setAllowsUnclampedScrollPositionForTesting(allowUnclamped);
658     return { };
659 }
660
661 ExceptionOr<void> InternalSettings::setAllowsInlineMediaPlayback(bool allows)
662 {
663     if (!m_page)
664         return Exception { INVALID_ACCESS_ERR };
665     settings().setAllowsInlineMediaPlayback(allows);
666     return { };
667 }
668
669 ExceptionOr<void> InternalSettings::setAllowsInlineMediaPlaybackAfterFullscreen(bool allows)
670 {
671     if (!m_page)
672         return Exception { INVALID_ACCESS_ERR };
673     settings().setAllowsInlineMediaPlaybackAfterFullscreen(allows);
674     return { };
675 }
676
677 ExceptionOr<void> InternalSettings::setInlineMediaPlaybackRequiresPlaysInlineAttribute(bool requires)
678 {
679     if (!m_page)
680         return Exception { INVALID_ACCESS_ERR };
681     settings().setInlineMediaPlaybackRequiresPlaysInlineAttribute(requires);
682     return { };
683 }
684
685 ExceptionOr<void> InternalSettings::setShouldMockBoldSystemFontForAccessibility(bool requires)
686 {
687     if (!m_page)
688         return Exception { INVALID_ACCESS_ERR };
689     RenderTheme::singleton().setShouldMockBoldSystemFontForAccessibility(requires);
690     FontCache::singleton().setShouldMockBoldSystemFontForAccessibility(requires);
691     return { };
692 }
693
694 void InternalSettings::setIndexedDBWorkersEnabled(bool enabled)
695 {
696 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
697     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(enabled);
698 #else
699     UNUSED_PARAM(enabled);
700 #endif
701 }
702
703 void InternalSettings::setCSSGridLayoutEnabled(bool enabled)
704 {
705     RuntimeEnabledFeatures::sharedFeatures().setCSSGridLayoutEnabled(enabled);
706 }
707
708 void InternalSettings::setWebGL2Enabled(bool enabled)
709 {
710 #if ENABLE(WEBGL2)
711     RuntimeEnabledFeatures::sharedFeatures().setWebGL2Enabled(enabled);
712 #else
713     UNUSED_PARAM(enabled);
714 #endif
715 }
716
717 void InternalSettings::setWebGPUEnabled(bool enabled)
718 {
719 #if ENABLE(WEBGPU)
720     RuntimeEnabledFeatures::sharedFeatures().setWebGPUEnabled(enabled);
721 #else
722     UNUSED_PARAM(enabled);
723 #endif
724 }
725
726 ExceptionOr<String> InternalSettings::userInterfaceDirectionPolicy()
727 {
728     if (!m_page)
729         return Exception { INVALID_ACCESS_ERR };
730     switch (settings().userInterfaceDirectionPolicy()) {
731     case UserInterfaceDirectionPolicy::Content:
732         return String { ASCIILiteral { "Content" } };
733     case UserInterfaceDirectionPolicy::System:
734         return String { ASCIILiteral { "View" } };
735     }
736     ASSERT_NOT_REACHED();
737     return Exception { INVALID_ACCESS_ERR };
738 }
739
740 ExceptionOr<void> InternalSettings::setUserInterfaceDirectionPolicy(const String& policy)
741 {
742     if (!m_page)
743         return Exception { INVALID_ACCESS_ERR };
744     if (equalLettersIgnoringASCIICase(policy, "content")) {
745         settings().setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::Content);
746         return { };
747     }
748     if (equalLettersIgnoringASCIICase(policy, "view")) {
749         settings().setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::System);
750         return { };
751     }
752     return Exception { INVALID_ACCESS_ERR };
753 }
754
755 ExceptionOr<String> InternalSettings::systemLayoutDirection()
756 {
757     if (!m_page)
758         return Exception { INVALID_ACCESS_ERR };
759     switch (settings().systemLayoutDirection()) {
760     case LTR:
761         return String { ASCIILiteral { "LTR" } };
762     case RTL:
763         return String { ASCIILiteral { "RTL" } };
764     }
765     ASSERT_NOT_REACHED();
766     return Exception { INVALID_ACCESS_ERR };
767 }
768
769 ExceptionOr<void> InternalSettings::setSystemLayoutDirection(const String& direction)
770 {
771     if (!m_page)
772         return Exception { INVALID_ACCESS_ERR };
773     if (equalLettersIgnoringASCIICase(direction, "ltr")) {
774         settings().setSystemLayoutDirection(LTR);
775         return { };
776     }
777     if (equalLettersIgnoringASCIICase(direction, "rtl")) {
778         settings().setSystemLayoutDirection(RTL);
779         return { };
780     }
781     return Exception { INVALID_ACCESS_ERR };
782 }
783
784 void InternalSettings::setAllowsAnySSLCertificate(bool allowsAnyCertificate)
785 {
786     Settings::setAllowsAnySSLCertificate(allowsAnyCertificate);
787 #if USE(SOUP)
788     SoupNetworkSession::setShouldIgnoreTLSErrors(allowsAnyCertificate);
789 #endif
790 }
791
792 ExceptionOr<bool> InternalSettings::deferredCSSParserEnabled()
793 {
794     if (!m_page)
795         return Exception { INVALID_ACCESS_ERR };
796     return settings().deferredCSSParserEnabled();
797 }
798
799 ExceptionOr<void> InternalSettings::setDeferredCSSParserEnabled(bool enabled)
800 {
801     if (!m_page)
802         return Exception { INVALID_ACCESS_ERR };
803     settings().setDeferredCSSParserEnabled(enabled);
804     return { };
805 }
806
807 static InternalSettings::ForcedAccessibilityValue settingsToInternalSettingsValue(Settings::ForcedAccessibilityValue value)
808 {
809     switch (value) {
810     case Settings::ForcedAccessibilityValue::System:
811         return InternalSettings::ForcedAccessibilityValue::System;
812     case Settings::ForcedAccessibilityValue::On:
813         return InternalSettings::ForcedAccessibilityValue::On;
814     case Settings::ForcedAccessibilityValue::Off:
815         return InternalSettings::ForcedAccessibilityValue::Off;
816     }
817
818     ASSERT_NOT_REACHED();
819     return InternalSettings::ForcedAccessibilityValue::Off;
820 }
821
822 static Settings::ForcedAccessibilityValue internalSettingsToSettingsValue(InternalSettings::ForcedAccessibilityValue value)
823 {
824     switch (value) {
825     case InternalSettings::ForcedAccessibilityValue::System:
826         return Settings::ForcedAccessibilityValue::System;
827     case InternalSettings::ForcedAccessibilityValue::On:
828         return Settings::ForcedAccessibilityValue::On;
829     case InternalSettings::ForcedAccessibilityValue::Off:
830         return Settings::ForcedAccessibilityValue::Off;
831     }
832
833     ASSERT_NOT_REACHED();
834     return Settings::ForcedAccessibilityValue::Off;
835 }
836
837 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedColorsAreInvertedAccessibilityValue() const
838 {
839     return settingsToInternalSettingsValue(settings().forcedColorsAreInvertedAccessibilityValue());
840 }
841
842 void InternalSettings::setForcedColorsAreInvertedAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
843 {
844     settings().setForcedColorsAreInvertedAccessibilityValue(internalSettingsToSettingsValue(value));
845 }
846
847 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedDisplayIsMonochromeAccessibilityValue() const
848 {
849     return settingsToInternalSettingsValue(settings().forcedDisplayIsMonochromeAccessibilityValue());
850 }
851
852 void InternalSettings::setForcedDisplayIsMonochromeAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
853 {
854     settings().setForcedDisplayIsMonochromeAccessibilityValue(internalSettingsToSettingsValue(value));
855 }
856
857 InternalSettings::ForcedAccessibilityValue InternalSettings::forcedPrefersReducedMotionAccessibilityValue() const
858 {
859     return settingsToInternalSettingsValue(settings().forcedPrefersReducedMotionAccessibilityValue());
860 }
861
862 void InternalSettings::setForcedPrefersReducedMotionAccessibilityValue(InternalSettings::ForcedAccessibilityValue value)
863 {
864     settings().setForcedPrefersReducedMotionAccessibilityValue(internalSettingsToSettingsValue(value));
865 }
866
867 // If you add to this class, make sure that you update the Backup class for test reproducability!
868
869 }