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