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