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