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