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