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