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