6f1f13a82ad6df071cf6ca87a9b1a1503489a7d0
[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_cachedPDFImageEnabled(settings.isCachedPDFImageEnabled())
84     , m_minimumTimerInterval(settings.minimumDOMTimerInterval())
85 #if ENABLE(VIDEO_TRACK)
86     , m_shouldDisplaySubtitles(settings.shouldDisplaySubtitles())
87     , m_shouldDisplayCaptions(settings.shouldDisplayCaptions())
88     , m_shouldDisplayTextDescriptions(settings.shouldDisplayTextDescriptions())
89 #endif
90     , m_defaultVideoPosterURL(settings.defaultVideoPosterURL())
91     , m_forcePendingWebGLPolicy(settings.isForcePendingWebGLPolicy())
92     , m_originalTimeWithoutMouseMovementBeforeHidingControls(settings.timeWithoutMouseMovementBeforeHidingControls())
93     , m_useLegacyBackgroundSizeShorthandBehavior(settings.useLegacyBackgroundSizeShorthandBehavior())
94     , m_autoscrollForDragAndDropEnabled(settings.autoscrollForDragAndDropEnabled())
95     , m_pluginReplacementEnabled(RuntimeEnabledFeatures::sharedFeatures().pluginReplacementEnabled())
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_allowsInlineMediaPlaybackWithPlaysInlineAttribute(settings.allowsInlineMediaPlaybackWithPlaysInlineAttribute())
111     , m_allowsInlineMediaPlaybackWithWebKitPlaysInlineAttribute(settings.allowsInlineMediaPlaybackWithWebKitPlaysInlineAttribute())
112 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
113     , m_indexedDBWorkersEnabled(RuntimeEnabledFeatures::sharedFeatures().indexedDBWorkersEnabled())
114 #endif
115     , m_userInterfaceDirectionPolicy(settings.userInterfaceDirectionPolicy())
116     , m_systemLayoutDirection(settings.systemLayoutDirection())
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.setCachedPDFImageEnabled(m_cachedPDFImageEnabled);
165     settings.setMinimumDOMTimerInterval(m_minimumTimerInterval);
166 #if ENABLE(VIDEO_TRACK)
167     settings.setShouldDisplaySubtitles(m_shouldDisplaySubtitles);
168     settings.setShouldDisplayCaptions(m_shouldDisplayCaptions);
169     settings.setShouldDisplayTextDescriptions(m_shouldDisplayTextDescriptions);
170 #endif
171     settings.setDefaultVideoPosterURL(m_defaultVideoPosterURL);
172     settings.setForcePendingWebGLPolicy(m_forcePendingWebGLPolicy);
173     settings.setTimeWithoutMouseMovementBeforeHidingControls(m_originalTimeWithoutMouseMovementBeforeHidingControls);
174     settings.setUseLegacyBackgroundSizeShorthandBehavior(m_useLegacyBackgroundSizeShorthandBehavior);
175     settings.setAutoscrollForDragAndDropEnabled(m_autoscrollForDragAndDropEnabled);
176     settings.setShouldConvertPositionStyleOnCopy(m_shouldConvertPositionStyleOnCopy);
177     settings.setFontFallbackPrefersPictographs(m_fontFallbackPrefersPictographs);
178     settings.setWebFontsAlwaysFallBack(m_webFontsAlwaysFallBack);
179     settings.setBackgroundShouldExtendBeyondPage(m_backgroundShouldExtendBeyondPage);
180     settings.setStorageBlockingPolicy(m_storageBlockingPolicy);
181     settings.setScrollingTreeIncludesFrames(m_scrollingTreeIncludesFrames);
182 #if ENABLE(TOUCH_EVENTS)
183     settings.setTouchEventEmulationEnabled(m_touchEventEmulationEnabled);
184 #endif
185     settings.setAllowsInlineMediaPlayback(m_allowsInlineMediaPlayback);
186     settings.setAllowsInlineMediaPlaybackAfterFullscreen(m_allowsInlineMediaPlaybackAfterFullscreen);
187     settings.setAllowsInlineMediaPlaybackWithPlaysInlineAttribute(m_allowsInlineMediaPlaybackWithPlaysInlineAttribute);
188     settings.setAllowsInlineMediaPlaybackWithWebKitPlaysInlineAttribute(m_allowsInlineMediaPlaybackWithWebKitPlaysInlineAttribute);
189     RuntimeEnabledFeatures::sharedFeatures().setPluginReplacementEnabled(m_pluginReplacementEnabled);
190 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
191     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(m_indexedDBWorkersEnabled);
192 #endif
193     settings.setUserInterfaceDirectionPolicy(m_userInterfaceDirectionPolicy);
194     settings.setSystemLayoutDirection(m_systemLayoutDirection);
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::setCachedPDFImageEnabled(bool enabled, ExceptionCode& ec)
491 {
492     InternalSettingsGuardForSettings();
493     settings()->setCachedPDFImageEnabled(enabled);
494 }
495
496 void InternalSettings::setMinimumTimerInterval(double intervalInSeconds, ExceptionCode& ec)
497 {
498     InternalSettingsGuardForSettings();
499     settings()->setMinimumDOMTimerInterval(std::chrono::milliseconds((std::chrono::milliseconds::rep)(intervalInSeconds * 1000)));
500 }
501
502 void InternalSettings::setDefaultVideoPosterURL(const String& url, ExceptionCode& ec)
503 {
504     InternalSettingsGuardForSettings();
505     settings()->setDefaultVideoPosterURL(url);
506 }
507
508 void InternalSettings::setForcePendingWebGLPolicy(bool forced, ExceptionCode& ec)
509 {
510     InternalSettingsGuardForSettings();
511     settings()->setForcePendingWebGLPolicy(forced);
512 }
513
514 void InternalSettings::setTimeWithoutMouseMovementBeforeHidingControls(double time, ExceptionCode& ec)
515 {
516     InternalSettingsGuardForSettings();
517     settings()->setTimeWithoutMouseMovementBeforeHidingControls(time);
518 }
519
520 void InternalSettings::setUseLegacyBackgroundSizeShorthandBehavior(bool enabled, ExceptionCode& ec)
521 {
522     InternalSettingsGuardForSettings();
523     settings()->setUseLegacyBackgroundSizeShorthandBehavior(enabled);
524 }
525
526 void InternalSettings::setAutoscrollForDragAndDropEnabled(bool enabled, ExceptionCode& ec)
527 {
528     InternalSettingsGuardForSettings();
529     settings()->setAutoscrollForDragAndDropEnabled(enabled);
530 }
531
532 void InternalSettings::setFontFallbackPrefersPictographs(bool preferPictographs, ExceptionCode& ec)
533 {
534     InternalSettingsGuardForSettings();
535     settings()->setFontFallbackPrefersPictographs(preferPictographs);
536 }
537
538 void InternalSettings::setWebFontsAlwaysFallBack(bool enable, ExceptionCode& ec)
539 {
540     InternalSettingsGuardForSettings();
541     settings()->setWebFontsAlwaysFallBack(enable);
542 }
543
544 void InternalSettings::setPluginReplacementEnabled(bool enabled)
545 {
546     RuntimeEnabledFeatures::sharedFeatures().setPluginReplacementEnabled(enabled);
547 }
548
549 void InternalSettings::setBackgroundShouldExtendBeyondPage(bool hasExtendedBackground, ExceptionCode& ec)
550 {
551     InternalSettingsGuardForSettings();
552     settings()->setBackgroundShouldExtendBeyondPage(hasExtendedBackground);
553 }
554
555 void InternalSettings::setShouldConvertPositionStyleOnCopy(bool convert, ExceptionCode& ec)
556 {
557     InternalSettingsGuardForSettings();
558     settings()->setShouldConvertPositionStyleOnCopy(convert);
559 }
560
561 void InternalSettings::setScrollingTreeIncludesFrames(bool enabled, ExceptionCode& ec)
562 {
563     InternalSettingsGuardForSettings();
564     settings()->setScrollingTreeIncludesFrames(enabled);
565 }
566
567 void InternalSettings::setAllowsInlineMediaPlayback(bool allows, ExceptionCode& ec)
568 {
569     InternalSettingsGuardForSettings();
570     settings()->setAllowsInlineMediaPlayback(allows);
571 }
572
573 void InternalSettings::setAllowsInlineMediaPlaybackAfterFullscreen(bool allows, ExceptionCode& ec)
574 {
575     InternalSettingsGuardForSettings();
576     settings()->setAllowsInlineMediaPlaybackAfterFullscreen(allows);
577 }
578
579 void InternalSettings::setAllowsInlineMediaPlaybackWithPlaysInlineAttribute(bool requires, ExceptionCode& ec)
580 {
581     InternalSettingsGuardForSettings();
582     settings()->setAllowsInlineMediaPlaybackWithPlaysInlineAttribute(requires);
583 }
584
585 void InternalSettings::setAllowsInlineMediaPlaybackWithWebKitPlaysInlineAttribute(bool requires, ExceptionCode& ec)
586 {
587     InternalSettingsGuardForSettings();
588     settings()->setAllowsInlineMediaPlaybackWithWebKitPlaysInlineAttribute(requires);
589 }
590
591 void InternalSettings::setIndexedDBWorkersEnabled(bool enabled, ExceptionCode&)
592 {
593 #if ENABLE(INDEXED_DATABASE_IN_WORKERS)
594     RuntimeEnabledFeatures::sharedFeatures().setIndexedDBWorkersEnabled(enabled);
595 #else
596     UNUSED_PARAM(enabled);
597 #endif
598 }
599
600 String InternalSettings::userInterfaceDirectionPolicy(ExceptionCode& ec)
601 {
602     InternalSettingsGuardForSettingsReturn("");
603     switch (settings()->userInterfaceDirectionPolicy()) {
604     case UserInterfaceDirectionPolicy::Content:
605         return ASCIILiteral("Content");
606     case UserInterfaceDirectionPolicy::System:
607         return ASCIILiteral("View");
608     }
609     ASSERT_NOT_REACHED();
610     return String();
611 }
612
613 void InternalSettings::setUserInterfaceDirectionPolicy(const String& policy, ExceptionCode& ec)
614 {
615     InternalSettingsGuardForSettings();
616     if (equalLettersIgnoringASCIICase(policy, "content")) {
617         settings()->setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::Content);
618         return;
619     }
620     if (equalLettersIgnoringASCIICase(policy, "view")) {
621         settings()->setUserInterfaceDirectionPolicy(UserInterfaceDirectionPolicy::System);
622         return;
623     }
624     ec = INVALID_ACCESS_ERR;
625 }
626
627 String InternalSettings::systemLayoutDirection(ExceptionCode& ec)
628 {
629     InternalSettingsGuardForSettingsReturn("");
630     switch (settings()->systemLayoutDirection()) {
631     case LTR:
632         return ASCIILiteral("LTR");
633     case RTL:
634         return ASCIILiteral("RTL");
635     }
636     ASSERT_NOT_REACHED();
637     return String();
638 }
639
640 void InternalSettings::setSystemLayoutDirection(const String& direction, ExceptionCode& ec)
641 {
642     InternalSettingsGuardForSettings();
643     if (equalLettersIgnoringASCIICase(direction, "ltr")) {
644         settings()->setSystemLayoutDirection(LTR);
645         return;
646     }
647     if (equalLettersIgnoringASCIICase(direction, "rtl")) {
648         settings()->setSystemLayoutDirection(RTL);
649         return;
650     }
651     ec = INVALID_ACCESS_ERR;
652 }
653
654 void InternalSettings::setAllowsAnySSLCertificate(bool allowsAnyCertificate)
655 {
656     Settings::setAllowsAnySSLCertificate(allowsAnyCertificate);
657 }
658
659 // If you add to this list, make sure that you update the Backup class for test reproducability!
660
661 }