Break pluginReplacementEnabled into youTubeFlashPluginReplacementEnabled and quickTim...
[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 #define InternalSettingsGuardForSettingsReturn(returnValue) \
49     if (!settings()) { \
50         ec = INVALID_ACCESS_ERR; \
51         return returnValue; \
52     }
53
54 #define InternalSettingsGuardForSettings()  \
55     if (!settings()) { \
56         ec = INVALID_ACCESS_ERR; \
57         return; \
58     }
59
60 #define InternalSettingsGuardForPage() \
61     if (!page()) { \
62         ec = INVALID_ACCESS_ERR; \
63         return; \
64     }
65
66 namespace WebCore {
67
68 InternalSettings::Backup::Backup(Settings& settings)
69     : m_originalEditingBehavior(settings.editingBehaviorType())
70 #if ENABLE(TEXT_AUTOSIZING) || ENABLE(IOS_TEXT_AUTOSIZING)
71     , m_originalTextAutosizingEnabled(settings.textAutosizingEnabled())
72     , m_originalTextAutosizingWindowSizeOverride(settings.textAutosizingWindowSizeOverride())
73 #endif
74 #if ENABLE(TEXT_AUTOSIZING)
75     , m_originalTextAutosizingFontScaleFactor(settings.textAutosizingFontScaleFactor())
76 #endif
77     , m_originalMediaTypeOverride(settings.mediaTypeOverride())
78     , m_originalCanvasUsesAcceleratedDrawing(settings.canvasUsesAcceleratedDrawing())
79     , m_originalMockScrollbarsEnabled(settings.mockScrollbarsEnabled())
80     , m_langAttributeAwareFormControlUIEnabled(RuntimeEnabledFeatures::sharedFeatures().langAttributeAwareFormControlUIEnabled())
81     , m_imagesEnabled(settings.areImagesEnabled())
82     , m_preferMIMETypeForImages(settings.preferMIMETypeForImages())
83     , m_minimumTimerInterval(settings.minimumDOMTimerInterval())
84 #if ENABLE(VIDEO_TRACK)
85     , m_shouldDisplaySubtitles(settings.shouldDisplaySubtitles())
86     , m_shouldDisplayCaptions(settings.shouldDisplayCaptions())
87     , m_shouldDisplayTextDescriptions(settings.shouldDisplayTextDescriptions())
88 #endif
89     , m_defaultVideoPosterURL(settings.defaultVideoPosterURL())
90     , m_forcePendingWebGLPolicy(settings.isForcePendingWebGLPolicy())
91     , m_originalTimeWithoutMouseMovementBeforeHidingControls(settings.timeWithoutMouseMovementBeforeHidingControls())
92     , m_useLegacyBackgroundSizeShorthandBehavior(settings.useLegacyBackgroundSizeShorthandBehavior())
93     , m_autoscrollForDragAndDropEnabled(settings.autoscrollForDragAndDropEnabled())
94     , m_quickTimePluginReplacementEnabled(settings.quickTimePluginReplacementEnabled())
95     , m_youTubeFlashPluginReplacementEnabled(settings.youTubeFlashPluginReplacementEnabled())
96     , m_shouldConvertPositionStyleOnCopy(settings.shouldConvertPositionStyleOnCopy())
97     , m_fontFallbackPrefersPictographs(settings.fontFallbackPrefersPictographs())
98     , m_webFontsAlwaysFallBack(settings.webFontsAlwaysFallBack())
99     , m_backgroundShouldExtendBeyondPage(settings.backgroundShouldExtendBeyondPage())
100     , m_storageBlockingPolicy(settings.storageBlockingPolicy())
101     , m_scrollingTreeIncludesFrames(settings.scrollingTreeIncludesFrames())
102 #if ENABLE(TOUCH_EVENTS)
103     , m_touchEventEmulationEnabled(settings.isTouchEventEmulationEnabled())
104 #endif
105 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
106     , m_allowsAirPlayForMediaPlayback(settings.allowsAirPlayForMediaPlayback())
107 #endif
108     , m_allowsInlineMediaPlayback(settings.allowsInlineMediaPlayback())
109     , m_allowsInlineMediaPlaybackAfterFullscreen(settings.allowsInlineMediaPlaybackAfterFullscreen())
110     , m_inlineMediaPlaybackRequiresPlaysInlineAttribute(settings.inlineMediaPlaybackRequiresPlaysInlineAttribute())
111 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
112     , m_indexedDBWorkersEnabled(RuntimeEnabledFeatures::sharedFeatures().indexedDBWorkersEnabled())
113 #endif
114     , m_userInterfaceDirectionPolicy(settings.userInterfaceDirectionPolicy())
115     , m_systemLayoutDirection(settings.systemLayoutDirection())
116     , m_pdfImageCachingPolicy(settings.pdfImageCachingPolicy())
117 {
118 }
119
120 void InternalSettings::Backup::restoreTo(Settings& settings)
121 {
122     settings.setEditingBehaviorType(m_originalEditingBehavior);
123
124     for (const auto& standardFont : m_standardFontFamilies)
125         settings.setStandardFontFamily(standardFont.value, static_cast<UScriptCode>(standardFont.key));
126     m_standardFontFamilies.clear();
127
128     for (const auto& fixedFont : m_fixedFontFamilies)
129         settings.setFixedFontFamily(fixedFont.value, static_cast<UScriptCode>(fixedFont.key));
130     m_fixedFontFamilies.clear();
131
132     for (const auto& serifFont : m_serifFontFamilies)
133         settings.setSerifFontFamily(serifFont.value, static_cast<UScriptCode>(serifFont.key));
134     m_serifFontFamilies.clear();
135
136     for (const auto& sansSerifFont : m_sansSerifFontFamilies)
137         settings.setSansSerifFontFamily(sansSerifFont.value, static_cast<UScriptCode>(sansSerifFont.key));
138     m_sansSerifFontFamilies.clear();
139
140     for (const auto& cursiveFont : m_cursiveFontFamilies)
141         settings.setCursiveFontFamily(cursiveFont.value, static_cast<UScriptCode>(cursiveFont.key));
142     m_cursiveFontFamilies.clear();
143
144     for (const auto& fantasyFont : m_fantasyFontFamilies)
145         settings.setFantasyFontFamily(fantasyFont.value, static_cast<UScriptCode>(fantasyFont.key));
146     m_fantasyFontFamilies.clear();
147
148     for (const auto& pictographFont : m_pictographFontFamilies)
149         settings.setPictographFontFamily(pictographFont.value, static_cast<UScriptCode>(pictographFont.key));
150     m_pictographFontFamilies.clear();
151
152 #if ENABLE(TEXT_AUTOSIZING) || ENABLE(IOS_TEXT_AUTOSIZING)
153     settings.setTextAutosizingEnabled(m_originalTextAutosizingEnabled);
154     settings.setTextAutosizingWindowSizeOverride(m_originalTextAutosizingWindowSizeOverride);
155 #endif
156 #if ENABLE(TEXT_AUTOSIZING)
157     settings.setTextAutosizingFontScaleFactor(m_originalTextAutosizingFontScaleFactor);
158 #endif
159     settings.setMediaTypeOverride(m_originalMediaTypeOverride);
160     settings.setCanvasUsesAcceleratedDrawing(m_originalCanvasUsesAcceleratedDrawing);
161     RuntimeEnabledFeatures::sharedFeatures().setLangAttributeAwareFormControlUIEnabled(m_langAttributeAwareFormControlUIEnabled);
162     settings.setImagesEnabled(m_imagesEnabled);
163     settings.setPreferMIMETypeForImages(m_preferMIMETypeForImages);
164     settings.setMinimumDOMTimerInterval(m_minimumTimerInterval);
165 #if ENABLE(VIDEO_TRACK)
166     settings.setShouldDisplaySubtitles(m_shouldDisplaySubtitles);
167     settings.setShouldDisplayCaptions(m_shouldDisplayCaptions);
168     settings.setShouldDisplayTextDescriptions(m_shouldDisplayTextDescriptions);
169 #endif
170     settings.setDefaultVideoPosterURL(m_defaultVideoPosterURL);
171     settings.setForcePendingWebGLPolicy(m_forcePendingWebGLPolicy);
172     settings.setTimeWithoutMouseMovementBeforeHidingControls(m_originalTimeWithoutMouseMovementBeforeHidingControls);
173     settings.setUseLegacyBackgroundSizeShorthandBehavior(m_useLegacyBackgroundSizeShorthandBehavior);
174     settings.setAutoscrollForDragAndDropEnabled(m_autoscrollForDragAndDropEnabled);
175     settings.setShouldConvertPositionStyleOnCopy(m_shouldConvertPositionStyleOnCopy);
176     settings.setFontFallbackPrefersPictographs(m_fontFallbackPrefersPictographs);
177     settings.setWebFontsAlwaysFallBack(m_webFontsAlwaysFallBack);
178     settings.setBackgroundShouldExtendBeyondPage(m_backgroundShouldExtendBeyondPage);
179     settings.setStorageBlockingPolicy(m_storageBlockingPolicy);
180     settings.setScrollingTreeIncludesFrames(m_scrollingTreeIncludesFrames);
181 #if ENABLE(TOUCH_EVENTS)
182     settings.setTouchEventEmulationEnabled(m_touchEventEmulationEnabled);
183 #endif
184     settings.setAllowsInlineMediaPlayback(m_allowsInlineMediaPlayback);
185     settings.setAllowsInlineMediaPlaybackAfterFullscreen(m_allowsInlineMediaPlaybackAfterFullscreen);
186     settings.setInlineMediaPlaybackRequiresPlaysInlineAttribute(m_inlineMediaPlaybackRequiresPlaysInlineAttribute);
187     settings.setQuickTimePluginReplacementEnabled(m_quickTimePluginReplacementEnabled);
188     settings.setYouTubeFlashPluginReplacementEnabled(m_youTubeFlashPluginReplacementEnabled);
189 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
190     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(m_indexedDBWorkersEnabled);
191 #endif
192     settings.setUserInterfaceDirectionPolicy(m_userInterfaceDirectionPolicy);
193     settings.setSystemLayoutDirection(m_systemLayoutDirection);
194     settings.setPdfImageCachingPolicy(m_pdfImageCachingPolicy);
195     Settings::setAllowsAnySSLCertificate(false);
196 }
197
198 class InternalSettingsWrapper : public Supplement<Page> {
199 public:
200     explicit InternalSettingsWrapper(Page* page)
201         : m_internalSettings(InternalSettings::create(page)) { }
202     virtual ~InternalSettingsWrapper() { m_internalSettings->hostDestroyed(); }
203 #if !ASSERT_DISABLED
204     bool isRefCountedWrapper() const override { return true; }
205 #endif
206     InternalSettings* internalSettings() const { return m_internalSettings.get(); }
207
208 private:
209     RefPtr<InternalSettings> m_internalSettings;
210 };
211
212 const char* InternalSettings::supplementName()
213 {
214     return "InternalSettings";
215 }
216
217 InternalSettings* InternalSettings::from(Page* page)
218 {
219     if (!Supplement<Page>::from(page, supplementName()))
220         Supplement<Page>::provideTo(page, supplementName(), std::make_unique<InternalSettingsWrapper>(page));
221     return static_cast<InternalSettingsWrapper*>(Supplement<Page>::from(page, supplementName()))->internalSettings();
222 }
223
224 InternalSettings::~InternalSettings()
225 {
226 }
227
228 InternalSettings::InternalSettings(Page* page)
229     : InternalSettingsGenerated(page)
230     , m_page(page)
231     , m_backup(page->settings())
232 {
233 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
234     setAllowsAirPlayForMediaPlayback(false);
235 #endif
236 }
237
238 void InternalSettings::resetToConsistentState()
239 {
240     page()->setPageScaleFactor(1, { 0, 0 });
241     page()->mainFrame().setPageAndTextZoomFactors(1, 1);
242     page()->setCanStartMedia(true);
243     page()->settings().setForcePendingWebGLPolicy(false);
244 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
245     setAllowsAirPlayForMediaPlayback(false);
246 #endif
247
248     m_backup.restoreTo(*settings());
249     m_backup = Backup(*settings());
250
251     InternalSettingsGenerated::resetToConsistentState();
252 }
253
254 Settings* InternalSettings::settings() const
255 {
256     if (!page())
257         return 0;
258     return &page()->settings();
259 }
260
261 void InternalSettings::setTouchEventEmulationEnabled(bool enabled, ExceptionCode& ec)
262 {
263 #if ENABLE(TOUCH_EVENTS)
264     InternalSettingsGuardForSettings();
265     settings()->setTouchEventEmulationEnabled(enabled);
266 #else
267     UNUSED_PARAM(enabled);
268     UNUSED_PARAM(ec);
269 #endif
270 }
271
272 void InternalSettings::setStandardFontFamily(const String& family, const String& script, ExceptionCode& ec)
273 {
274     InternalSettingsGuardForSettings();
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 }
281
282 void InternalSettings::setSerifFontFamily(const String& family, const String& script, ExceptionCode& ec)
283 {
284     InternalSettingsGuardForSettings();
285     UScriptCode code = scriptNameToCode(script);
286     if (code == USCRIPT_INVALID_CODE)
287         return;
288     m_backup.m_serifFontFamilies.add(code, settings()->serifFontFamily(code));
289     settings()->setSerifFontFamily(family, code);
290 }
291
292 void InternalSettings::setSansSerifFontFamily(const String& family, const String& script, ExceptionCode& ec)
293 {
294     InternalSettingsGuardForSettings();
295     UScriptCode code = scriptNameToCode(script);
296     if (code == USCRIPT_INVALID_CODE)
297         return;
298     m_backup.m_sansSerifFontFamilies.add(code, settings()->sansSerifFontFamily(code));
299     settings()->setSansSerifFontFamily(family, code);
300 }
301
302 void InternalSettings::setFixedFontFamily(const String& family, const String& script, ExceptionCode& ec)
303 {
304     InternalSettingsGuardForSettings();
305     UScriptCode code = scriptNameToCode(script);
306     if (code == USCRIPT_INVALID_CODE)
307         return;
308     m_backup.m_fixedFontFamilies.add(code, settings()->fixedFontFamily(code));
309     settings()->setFixedFontFamily(family, code);
310 }
311
312 void InternalSettings::setCursiveFontFamily(const String& family, const String& script, ExceptionCode& ec)
313 {
314     InternalSettingsGuardForSettings();
315     UScriptCode code = scriptNameToCode(script);
316     if (code == USCRIPT_INVALID_CODE)
317         return;
318     m_backup.m_cursiveFontFamilies.add(code, settings()->cursiveFontFamily(code));
319     settings()->setCursiveFontFamily(family, code);
320 }
321
322 void InternalSettings::setFantasyFontFamily(const String& family, const String& script, ExceptionCode& ec)
323 {
324     InternalSettingsGuardForSettings();
325     UScriptCode code = scriptNameToCode(script);
326     if (code == USCRIPT_INVALID_CODE)
327         return;
328     m_backup.m_fantasyFontFamilies.add(code, settings()->fantasyFontFamily(code));
329     settings()->setFantasyFontFamily(family, code);
330 }
331
332 void InternalSettings::setPictographFontFamily(const String& family, const String& script, ExceptionCode& ec)
333 {
334     InternalSettingsGuardForSettings();
335     UScriptCode code = scriptNameToCode(script);
336     if (code == USCRIPT_INVALID_CODE)
337         return;
338     m_backup.m_pictographFontFamilies.add(code, settings()->pictographFontFamily(code));
339     settings()->setPictographFontFamily(family, code);
340 }
341
342 void InternalSettings::setTextAutosizingEnabled(bool enabled, ExceptionCode& ec)
343 {
344 #if ENABLE(TEXT_AUTOSIZING) || ENABLE(IOS_TEXT_AUTOSIZING)
345     InternalSettingsGuardForSettings();
346     settings()->setTextAutosizingEnabled(enabled);
347 #else
348     UNUSED_PARAM(enabled);
349     UNUSED_PARAM(ec);
350 #endif
351 }
352
353 void InternalSettings::setTextAutosizingWindowSizeOverride(int width, int height, ExceptionCode& ec)
354 {
355 #if ENABLE(TEXT_AUTOSIZING) || ENABLE(IOS_TEXT_AUTOSIZING)
356     InternalSettingsGuardForSettings();
357     settings()->setTextAutosizingWindowSizeOverride(IntSize(width, height));
358 #else
359     UNUSED_PARAM(width);
360     UNUSED_PARAM(height);
361     UNUSED_PARAM(ec);
362 #endif
363 }
364
365 void InternalSettings::setMediaTypeOverride(const String& mediaType, ExceptionCode& ec)
366 {
367     InternalSettingsGuardForSettings();
368     settings()->setMediaTypeOverride(mediaType);
369 }
370
371 void InternalSettings::setTextAutosizingFontScaleFactor(float fontScaleFactor, ExceptionCode& ec)
372 {
373 #if ENABLE(TEXT_AUTOSIZING)
374     InternalSettingsGuardForSettings();
375     settings()->setTextAutosizingFontScaleFactor(fontScaleFactor);
376 #else
377     UNUSED_PARAM(fontScaleFactor);
378     UNUSED_PARAM(ec);
379 #endif
380 }
381
382 void InternalSettings::setCanStartMedia(bool enabled, ExceptionCode& ec)
383 {
384     InternalSettingsGuardForSettings();
385     m_page->setCanStartMedia(enabled);
386 }
387
388 void InternalSettings::setAllowsAirPlayForMediaPlayback(bool allows)
389 {
390 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
391     m_page->settings().setAllowsAirPlayForMediaPlayback(allows);
392 #else
393     UNUSED_PARAM(allows);
394 #endif
395 }
396
397 void InternalSettings::setEditingBehavior(const String& editingBehavior, ExceptionCode& ec)
398 {
399     InternalSettingsGuardForSettings();
400     if (equalLettersIgnoringASCIICase(editingBehavior, "win"))
401         settings()->setEditingBehaviorType(EditingWindowsBehavior);
402     else if (equalLettersIgnoringASCIICase(editingBehavior, "mac"))
403         settings()->setEditingBehaviorType(EditingMacBehavior);
404     else if (equalLettersIgnoringASCIICase(editingBehavior, "unix"))
405         settings()->setEditingBehaviorType(EditingUnixBehavior);
406     else if (equalLettersIgnoringASCIICase(editingBehavior, "ios"))
407         settings()->setEditingBehaviorType(EditingIOSBehavior);
408     else
409         ec = SYNTAX_ERR;
410 }
411
412 void InternalSettings::setShouldDisplayTrackKind(const String& kind, bool enabled, ExceptionCode& ec)
413 {
414     InternalSettingsGuardForSettings();
415
416 #if ENABLE(VIDEO_TRACK)
417     if (!page())
418         return;
419
420     auto& captionPreferences = page()->group().captionPreferences();
421     if (equalLettersIgnoringASCIICase(kind, "subtitles"))
422         captionPreferences.setUserPrefersSubtitles(enabled);
423     else if (equalLettersIgnoringASCIICase(kind, "captions"))
424         captionPreferences.setUserPrefersCaptions(enabled);
425     else if (equalLettersIgnoringASCIICase(kind, "textdescriptions"))
426         captionPreferences.setUserPrefersTextDescriptions(enabled);
427     else
428         ec = SYNTAX_ERR;
429 #else
430     UNUSED_PARAM(kind);
431     UNUSED_PARAM(enabled);
432 #endif
433 }
434
435 bool InternalSettings::shouldDisplayTrackKind(const String& kind, ExceptionCode& ec)
436 {
437     InternalSettingsGuardForSettingsReturn(false);
438
439 #if ENABLE(VIDEO_TRACK)
440     if (!page())
441         return false;
442
443     auto& captionPreferences = page()->group().captionPreferences();
444     if (equalLettersIgnoringASCIICase(kind, "subtitles"))
445         return captionPreferences.userPrefersSubtitles();
446     if (equalLettersIgnoringASCIICase(kind, "captions"))
447         return captionPreferences.userPrefersCaptions();
448     if (equalLettersIgnoringASCIICase(kind, "textdescriptions"))
449         return captionPreferences.userPrefersTextDescriptions();
450
451     ec = SYNTAX_ERR;
452     return false;
453 #else
454     UNUSED_PARAM(kind);
455     return false;
456 #endif
457 }
458
459 void InternalSettings::setStorageBlockingPolicy(const String& mode, ExceptionCode& ec)
460 {
461     InternalSettingsGuardForSettings();
462
463     if (mode == "AllowAll")
464         settings()->setStorageBlockingPolicy(SecurityOrigin::AllowAllStorage);
465     else if (mode == "BlockThirdParty")
466         settings()->setStorageBlockingPolicy(SecurityOrigin::BlockThirdPartyStorage);
467     else if (mode == "BlockAll")
468         settings()->setStorageBlockingPolicy(SecurityOrigin::BlockAllStorage);
469     else
470         ec = SYNTAX_ERR;
471 }
472
473 void InternalSettings::setLangAttributeAwareFormControlUIEnabled(bool enabled)
474 {
475     RuntimeEnabledFeatures::sharedFeatures().setLangAttributeAwareFormControlUIEnabled(enabled);
476 }
477
478 void InternalSettings::setPreferMIMETypeForImages(bool preferMIMETypeForImages, ExceptionCode &ec)
479 {
480     InternalSettingsGuardForSettings();
481     settings()->setPreferMIMETypeForImages(preferMIMETypeForImages);
482 }
483
484 void InternalSettings::setImagesEnabled(bool enabled, ExceptionCode& ec)
485 {
486     InternalSettingsGuardForSettings();
487     settings()->setImagesEnabled(enabled);
488 }
489
490 void InternalSettings::setPDFImageCachingPolicy(const String& policy, ExceptionCode& ec)
491 {
492     InternalSettingsGuardForSettings();
493     if (equalLettersIgnoringASCIICase(policy, "disabled"))
494         settings()->setPdfImageCachingPolicy(PDFImageCachingDisabled);
495     else if (equalLettersIgnoringASCIICase(policy, "belowmemorylimit"))
496         settings()->setPdfImageCachingPolicy(PDFImageCachingBelowMemoryLimit);
497     else if (equalLettersIgnoringASCIICase(policy, "clipboundsonly"))
498         settings()->setPdfImageCachingPolicy(PDFImageCachingClipBoundsOnly);
499     else if (equalLettersIgnoringASCIICase(policy, "enabled"))
500         settings()->setPdfImageCachingPolicy(PDFImageCachingEnabled);
501     else
502         ec = SYNTAX_ERR;
503 }
504
505 void InternalSettings::setMinimumTimerInterval(double intervalInSeconds, ExceptionCode& ec)
506 {
507     InternalSettingsGuardForSettings();
508     settings()->setMinimumDOMTimerInterval(std::chrono::milliseconds((std::chrono::milliseconds::rep)(intervalInSeconds * 1000)));
509 }
510
511 void InternalSettings::setDefaultVideoPosterURL(const String& url, ExceptionCode& ec)
512 {
513     InternalSettingsGuardForSettings();
514     settings()->setDefaultVideoPosterURL(url);
515 }
516
517 void InternalSettings::setForcePendingWebGLPolicy(bool forced, ExceptionCode& ec)
518 {
519     InternalSettingsGuardForSettings();
520     settings()->setForcePendingWebGLPolicy(forced);
521 }
522
523 void InternalSettings::setTimeWithoutMouseMovementBeforeHidingControls(double time, ExceptionCode& ec)
524 {
525     InternalSettingsGuardForSettings();
526     settings()->setTimeWithoutMouseMovementBeforeHidingControls(time);
527 }
528
529 void InternalSettings::setUseLegacyBackgroundSizeShorthandBehavior(bool enabled, ExceptionCode& ec)
530 {
531     InternalSettingsGuardForSettings();
532     settings()->setUseLegacyBackgroundSizeShorthandBehavior(enabled);
533 }
534
535 void InternalSettings::setAutoscrollForDragAndDropEnabled(bool enabled, ExceptionCode& ec)
536 {
537     InternalSettingsGuardForSettings();
538     settings()->setAutoscrollForDragAndDropEnabled(enabled);
539 }
540
541 void InternalSettings::setFontFallbackPrefersPictographs(bool preferPictographs, ExceptionCode& ec)
542 {
543     InternalSettingsGuardForSettings();
544     settings()->setFontFallbackPrefersPictographs(preferPictographs);
545 }
546
547 void InternalSettings::setWebFontsAlwaysFallBack(bool enable, ExceptionCode& ec)
548 {
549     InternalSettingsGuardForSettings();
550     settings()->setWebFontsAlwaysFallBack(enable);
551 }
552
553 void InternalSettings::setQuickTimePluginReplacementEnabled(bool enabled, ExceptionCode& ec)
554 {
555     InternalSettingsGuardForSettings();
556     settings()->setQuickTimePluginReplacementEnabled(enabled);
557 }
558
559 void InternalSettings::setYouTubeFlashPluginReplacementEnabled(bool enabled, ExceptionCode& ec)
560 {
561     InternalSettingsGuardForSettings();
562     settings()->setYouTubeFlashPluginReplacementEnabled(enabled);
563 }
564
565 void InternalSettings::setBackgroundShouldExtendBeyondPage(bool hasExtendedBackground, ExceptionCode& ec)
566 {
567     InternalSettingsGuardForSettings();
568     settings()->setBackgroundShouldExtendBeyondPage(hasExtendedBackground);
569 }
570
571 void InternalSettings::setShouldConvertPositionStyleOnCopy(bool convert, ExceptionCode& ec)
572 {
573     InternalSettingsGuardForSettings();
574     settings()->setShouldConvertPositionStyleOnCopy(convert);
575 }
576
577 void InternalSettings::setScrollingTreeIncludesFrames(bool enabled, ExceptionCode& ec)
578 {
579     InternalSettingsGuardForSettings();
580     settings()->setScrollingTreeIncludesFrames(enabled);
581 }
582
583 void InternalSettings::setAllowsInlineMediaPlayback(bool allows, ExceptionCode& ec)
584 {
585     InternalSettingsGuardForSettings();
586     settings()->setAllowsInlineMediaPlayback(allows);
587 }
588
589 void InternalSettings::setAllowsInlineMediaPlaybackAfterFullscreen(bool allows, ExceptionCode& ec)
590 {
591     InternalSettingsGuardForSettings();
592     settings()->setAllowsInlineMediaPlaybackAfterFullscreen(allows);
593 }
594
595 void InternalSettings::setInlineMediaPlaybackRequiresPlaysInlineAttribute(bool requires, ExceptionCode& ec)
596 {
597     InternalSettingsGuardForSettings();
598     settings()->setInlineMediaPlaybackRequiresPlaysInlineAttribute(requires);
599 }
600
601 void InternalSettings::setIndexedDBWorkersEnabled(bool enabled, ExceptionCode&)
602 {
603 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
604     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(enabled);
605 #else
606     UNUSED_PARAM(enabled);
607 #endif
608 }
609
610 String InternalSettings::userInterfaceDirectionPolicy(ExceptionCode& ec)
611 {
612     InternalSettingsGuardForSettingsReturn("");
613     switch (settings()->userInterfaceDirectionPolicy()) {
614     case UserInterfaceDirectionPolicy::Content:
615         return ASCIILiteral("Content");
616     case UserInterfaceDirectionPolicy::System:
617         return ASCIILiteral("View");
618     }
619     ASSERT_NOT_REACHED();
620     return String();
621 }
622
623 void InternalSettings::setUserInterfaceDirectionPolicy(const String& policy, ExceptionCode& ec)
624 {
625     InternalSettingsGuardForSettings();
626     if (equalLettersIgnoringASCIICase(policy, "content")) {
627         settings()->setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::Content);
628         return;
629     }
630     if (equalLettersIgnoringASCIICase(policy, "view")) {
631         settings()->setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::System);
632         return;
633     }
634     ec = INVALID_ACCESS_ERR;
635 }
636
637 String InternalSettings::systemLayoutDirection(ExceptionCode& ec)
638 {
639     InternalSettingsGuardForSettingsReturn("");
640     switch (settings()->systemLayoutDirection()) {
641     case LTR:
642         return ASCIILiteral("LTR");
643     case RTL:
644         return ASCIILiteral("RTL");
645     }
646     ASSERT_NOT_REACHED();
647     return String();
648 }
649
650 void InternalSettings::setSystemLayoutDirection(const String& direction, ExceptionCode& ec)
651 {
652     InternalSettingsGuardForSettings();
653     if (equalLettersIgnoringASCIICase(direction, "ltr")) {
654         settings()->setSystemLayoutDirection(LTR);
655         return;
656     }
657     if (equalLettersIgnoringASCIICase(direction, "rtl")) {
658         settings()->setSystemLayoutDirection(RTL);
659         return;
660     }
661     ec = INVALID_ACCESS_ERR;
662 }
663
664 void InternalSettings::setAllowsAnySSLCertificate(bool allowsAnyCertificate)
665 {
666     Settings::setAllowsAnySSLCertificate(allowsAnyCertificate);
667 }
668
669 // If you add to this list, make sure that you update the Backup class for test reproducability!
670
671 }