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