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