Implement save and restore for a bunch of InternalSettings state
[WebKit-https.git] / Source / WebCore / testing / InternalSettings.cpp
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "InternalSettings.h"
28
29 #include "Chrome.h"
30 #include "ChromeClient.h"
31 #include "Document.h"
32 #include "ExceptionCode.h"
33 #include "Frame.h"
34 #include "FrameView.h"
35 #include "Language.h"
36 #include "LocaleToScriptMapping.h"
37 #include "MockPagePopupDriver.h"
38 #include "Page.h"
39 #include "RuntimeEnabledFeatures.h"
40 #include "Settings.h"
41 #include "TextRun.h"
42
43 #if ENABLE(INPUT_TYPE_COLOR)
44 #include "ColorChooser.h"
45 #endif
46
47 #define InternalSettingsGuardForSettingsReturn(returnValue) \
48     if (!settings()) { \
49         ec = INVALID_ACCESS_ERR; \
50         return returnValue; \
51     }
52
53 #define InternalSettingsGuardForSettings()  \
54     if (!settings()) { \
55         ec = INVALID_ACCESS_ERR; \
56         return; \
57     }
58
59 #define InternalSettingsGuardForPage() \
60     if (!page()) { \
61         ec = INVALID_ACCESS_ERR; \
62         return; \
63     }
64
65 namespace WebCore {
66
67 InternalSettings::Backup::Backup(Page* page, Settings* settings)
68     : m_originalPasswordEchoDurationInSeconds(settings->passwordEchoDurationInSeconds())
69     , m_originalPasswordEchoEnabled(settings->passwordEchoEnabled())
70     , m_originalFixedElementsLayoutRelativeToFrame(settings->fixedElementsLayoutRelativeToFrame())
71     , m_originalCSSExclusionsEnabled(RuntimeEnabledFeatures::cssExclusionsEnabled())
72     , m_originalCSSVariablesEnabled(settings->cssVariablesEnabled())
73 #if ENABLE(SHADOW_DOM)
74     , m_originalShadowDOMEnabled(RuntimeEnabledFeatures::shadowDOMEnabled())
75     , m_originalAuthorShadowDOMForAnyElementEnabled(RuntimeEnabledFeatures::authorShadowDOMForAnyElementEnabled())
76 #endif
77 #if ENABLE(STYLE_SCOPED)
78     , m_originalStyleScoped(RuntimeEnabledFeatures::styleScopedEnabled())
79 #endif
80     , m_originalEditingBehavior(settings->editingBehaviorType())
81     , m_originalUnifiedSpellCheckerEnabled(settings->unifiedTextCheckerEnabled())
82     , m_originalFixedPositionCreatesStackingContext(settings->fixedPositionCreatesStackingContext())
83     , m_originalSyncXHRInDocumentsEnabled(settings->syncXHRInDocumentsEnabled())
84     , m_originalWindowFocusRestricted(settings->windowFocusRestricted())
85     , m_originalDeviceSupportsTouch(settings->deviceSupportsTouch())
86     , m_originalDeviceSupportsMouse(settings->deviceSupportsMouse())
87 #if ENABLE(TEXT_AUTOSIZING)
88     , m_originalTextAutosizingEnabled(settings->textAutosizingEnabled())
89     , m_originalTextAutosizingWindowSizeOverride(settings->textAutosizingWindowSizeOverride())
90     , m_originalTextAutosizingFontScaleFactor(settings->textAutosizingFontScaleFactor())
91 #endif
92     , m_originalResolutionOverride(settings->resolutionOverride())
93     , m_originalMediaTypeOverride(settings->mediaTypeOverride())
94 #if ENABLE(DIALOG_ELEMENT)
95     , m_originalDialogElementEnabled(RuntimeEnabledFeatures::dialogElementEnabled())
96 #endif
97     , m_canStartMedia(page->canStartMedia())
98     , m_originalForceCompositingMode(settings->forceCompositingMode())
99     , m_originalCompositingForFixedPositionEnabled(settings->acceleratedCompositingForFixedPositionEnabled())
100     , m_originalCompositingForScrollableFramesEnabled(settings->acceleratedCompositingForScrollableFramesEnabled())
101     , m_originalAcceleratedDrawingEnabled(settings->acceleratedDrawingEnabled())
102     , m_originalMockScrollbarsEnabled(settings->mockScrollbarsEnabled())
103     , m_langAttributeAwareFormControlUIEnabled(RuntimeEnabledFeatures::langAttributeAwareFormControlUIEnabled())
104     , m_imagesEnabled(settings->areImagesEnabled())
105 #if ENABLE(VIDEO_TRACK)
106     , m_shouldDisplaySubtitles(settings->shouldDisplaySubtitles())
107     , m_shouldDisplayCaptions(settings->shouldDisplayCaptions())
108     , m_shouldDisplayTextDescriptions(settings->shouldDisplayTextDescriptions())
109 #endif
110 {
111 }
112
113
114 void InternalSettings::Backup::restoreTo(Page* page, Settings* settings)
115 {
116     settings->setPasswordEchoDurationInSeconds(m_originalPasswordEchoDurationInSeconds);
117     settings->setPasswordEchoEnabled(m_originalPasswordEchoEnabled);
118     settings->setFixedElementsLayoutRelativeToFrame(m_originalFixedElementsLayoutRelativeToFrame);
119     RuntimeEnabledFeatures::setCSSExclusionsEnabled(m_originalCSSExclusionsEnabled);
120     settings->setCSSVariablesEnabled(m_originalCSSVariablesEnabled);
121 #if ENABLE(SHADOW_DOM)
122     RuntimeEnabledFeatures::setShadowDOMEnabled(m_originalShadowDOMEnabled);
123     RuntimeEnabledFeatures::setAuthorShadowDOMForAnyElementEnabled(m_originalAuthorShadowDOMForAnyElementEnabled);
124 #endif
125 #if ENABLE(STYLE_SCOPED)
126     RuntimeEnabledFeatures::setStyleScopedEnabled(m_originalStyleScoped);
127 #endif
128     settings->setEditingBehaviorType(m_originalEditingBehavior);
129     settings->setUnifiedTextCheckerEnabled(m_originalUnifiedSpellCheckerEnabled);
130     settings->setFixedPositionCreatesStackingContext(m_originalFixedPositionCreatesStackingContext);
131     settings->setSyncXHRInDocumentsEnabled(m_originalSyncXHRInDocumentsEnabled);
132     settings->setWindowFocusRestricted(m_originalWindowFocusRestricted);
133     settings->setDeviceSupportsTouch(m_originalDeviceSupportsTouch);
134     settings->setDeviceSupportsMouse(m_originalDeviceSupportsMouse);
135 #if ENABLE(TEXT_AUTOSIZING)
136     settings->setTextAutosizingEnabled(m_originalTextAutosizingEnabled);
137     settings->setTextAutosizingWindowSizeOverride(m_originalTextAutosizingWindowSizeOverride);
138     settings->setTextAutosizingFontScaleFactor(m_originalTextAutosizingFontScaleFactor);
139 #endif
140     settings->setResolutionOverride(m_originalResolutionOverride);
141     settings->setMediaTypeOverride(m_originalMediaTypeOverride);
142 #if ENABLE(DIALOG_ELEMENT)
143     RuntimeEnabledFeatures::setDialogElementEnabled(m_originalDialogElementEnabled);
144 #endif
145     page->setCanStartMedia(m_canStartMedia);
146     settings->setForceCompositingMode(m_originalForceCompositingMode);
147     settings->setAcceleratedCompositingForFixedPositionEnabled(m_originalCompositingForFixedPositionEnabled);
148     settings->setAcceleratedCompositingForScrollableFramesEnabled(m_originalCompositingForScrollableFramesEnabled);
149     settings->setAcceleratedDrawingEnabled(m_originalAcceleratedDrawingEnabled);
150     settings->setMockScrollbarsEnabled(m_originalMockScrollbarsEnabled);
151     RuntimeEnabledFeatures::setLangAttributeAwareFormControlUIEnabled(m_langAttributeAwareFormControlUIEnabled);
152     settings->setImagesEnabled(m_imagesEnabled);
153 #if ENABLE(VIDEO_TRACK)
154     settings->setShouldDisplaySubtitles(m_shouldDisplaySubtitles);
155     settings->setShouldDisplayCaptions(m_shouldDisplayCaptions);
156     settings->setShouldDisplayTextDescriptions(m_shouldDisplayTextDescriptions);
157 #endif
158 }
159
160 InternalSettings* InternalSettings::from(Page* page)
161 {
162     DEFINE_STATIC_LOCAL(AtomicString, name, ("InternalSettings"));
163     if (!SuperType::from(page, name))
164         SuperType::provideTo(page, name, adoptRef(new InternalSettings(page)));
165     return static_cast<InternalSettings*>(SuperType::from(page, name));
166 }
167
168 InternalSettings::~InternalSettings()
169 {
170 }
171
172 InternalSettings::InternalSettings(Page* page)
173     : m_page(page)
174     , m_backup(page, page->settings())
175 {
176 }
177
178 #if ENABLE(PAGE_POPUP)
179 PagePopupController* InternalSettings::pagePopupController()
180 {
181     return m_pagePopupDriver ? m_pagePopupDriver->pagePopupController() : 0;
182 }
183 #endif
184
185 void InternalSettings::reset()
186 {
187     TextRun::setAllowsRoundingHacks(false);
188     setUserPreferredLanguages(Vector<String>());
189     page()->setPagination(Pagination());
190     page()->setPageScaleFactor(1, IntPoint(0, 0));
191     setUsesOverlayScrollbars(false);
192 #if ENABLE(PAGE_POPUP)
193     m_pagePopupDriver.clear();
194     if (page()->chrome())
195         page()->chrome()->client()->resetPagePopupDriver();
196 #endif
197
198     m_backup.restoreTo(page(), settings());
199     m_backup = Backup(page(), settings());
200 }
201
202 Settings* InternalSettings::settings() const
203 {
204     if (!page())
205         return 0;
206     return page()->settings();
207 }
208
209 void InternalSettings::setForceCompositingMode(bool enabled, ExceptionCode& ec)
210 {
211     InternalSettingsGuardForSettings();
212     settings()->setForceCompositingMode(enabled);
213 }
214
215 void InternalSettings::setAcceleratedFiltersEnabled(bool enabled, ExceptionCode& ec)
216 {
217     InternalSettingsGuardForSettings();
218     settings()->setAcceleratedFiltersEnabled(enabled);
219 }
220
221 void InternalSettings::setEnableCompositingForFixedPosition(bool enabled, ExceptionCode& ec)
222 {
223     InternalSettingsGuardForSettings();
224     settings()->setAcceleratedCompositingForFixedPositionEnabled(enabled);
225 }
226
227 void InternalSettings::setEnableCompositingForScrollableFrames(bool enabled, ExceptionCode& ec)
228 {
229     InternalSettingsGuardForSettings();
230     settings()->setAcceleratedCompositingForScrollableFramesEnabled(enabled);
231 }
232
233 void InternalSettings::setAcceleratedDrawingEnabled(bool enabled, ExceptionCode& ec)
234 {
235     InternalSettingsGuardForSettings();
236     settings()->setAcceleratedDrawingEnabled(enabled);
237 }
238
239 void InternalSettings::setMockScrollbarsEnabled(bool enabled, ExceptionCode& ec)
240 {
241     InternalSettingsGuardForSettings();
242     settings()->setMockScrollbarsEnabled(enabled);
243 }
244
245 void InternalSettings::setUsesOverlayScrollbars(bool flag)
246 {
247     settings()->setUsesOverlayScrollbars(flag);
248 }
249
250 void InternalSettings::setPasswordEchoEnabled(bool enabled, ExceptionCode& ec)
251 {
252     InternalSettingsGuardForSettings();
253     settings()->setPasswordEchoEnabled(enabled);
254 }
255
256 void InternalSettings::setPasswordEchoDurationInSeconds(double durationInSeconds, ExceptionCode& ec)
257 {
258     InternalSettingsGuardForSettings();
259     settings()->setPasswordEchoDurationInSeconds(durationInSeconds);
260 }
261
262 void InternalSettings::setFixedElementsLayoutRelativeToFrame(bool enabled, ExceptionCode& ec)
263 {
264     InternalSettingsGuardForSettings();
265     settings()->setFixedElementsLayoutRelativeToFrame(enabled);
266 }
267
268 void InternalSettings::setUnifiedTextCheckingEnabled(bool enabled, ExceptionCode& ec)
269 {
270     InternalSettingsGuardForSettings();
271     settings()->setUnifiedTextCheckerEnabled(enabled);
272 }
273
274 bool InternalSettings::unifiedTextCheckingEnabled(ExceptionCode& ec)
275 {
276     InternalSettingsGuardForSettingsReturn(false);
277     return settings()->unifiedTextCheckerEnabled();
278 }
279
280 void InternalSettings::setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode& ec)
281 {
282     InternalSettingsGuardForPage();
283     page()->setPageScaleFactor(scaleFactor, IntPoint(x, y));
284 }
285
286 void InternalSettings::setShadowDOMEnabled(bool enabled, ExceptionCode& ec)
287 {
288 #if ENABLE(SHADOW_DOM)
289     UNUSED_PARAM(ec);
290     RuntimeEnabledFeatures::setShadowDOMEnabled(enabled);
291 #else
292     // Even SHADOW_DOM is off, InternalSettings allows setShadowDOMEnabled(false) to
293     // have broader test coverage. But it cannot be setShadowDOMEnabled(true).
294     if (enabled)
295         ec = INVALID_ACCESS_ERR;
296 #endif
297 }
298
299 void InternalSettings::setAuthorShadowDOMForAnyElementEnabled(bool isEnabled)
300 {
301 #if ENABLE(SHADOW_DOM)
302     RuntimeEnabledFeatures::setAuthorShadowDOMForAnyElementEnabled(isEnabled);
303 #else
304     UNUSED_PARAM(isEnabled);
305 #endif
306 }
307
308 void InternalSettings::setStyleScopedEnabled(bool enabled)
309 {
310 #if ENABLE(STYLE_SCOPED)
311     RuntimeEnabledFeatures::setStyleScopedEnabled(enabled);
312 #else
313     UNUSED_PARAM(enabled);
314 #endif
315 }
316
317 void InternalSettings::setTouchEventEmulationEnabled(bool enabled, ExceptionCode& ec)
318 {
319 #if ENABLE(TOUCH_EVENTS)
320     InternalSettingsGuardForSettings();
321     settings()->setTouchEventEmulationEnabled(enabled);
322 #else
323     UNUSED_PARAM(enabled);
324     UNUSED_PARAM(ec);
325 #endif
326 }
327
328 void InternalSettings::setDeviceSupportsTouch(bool enabled, ExceptionCode& ec)
329 {
330     InternalSettingsGuardForSettings();
331     settings()->setDeviceSupportsTouch(enabled);
332 }
333
334 void InternalSettings::setDeviceSupportsMouse(bool enabled, ExceptionCode& ec)
335 {
336     InternalSettingsGuardForSettings();
337     settings()->setDeviceSupportsMouse(enabled);
338 }
339
340 typedef void (Settings::*SetFontFamilyFunction)(const AtomicString&, UScriptCode);
341 static void setFontFamily(Settings* settings, const String& family, const String& script, SetFontFamilyFunction setter)
342 {
343     UScriptCode code = scriptNameToCode(script);
344     if (code != USCRIPT_INVALID_CODE)
345         (settings->*setter)(family, code);
346 }
347
348 void InternalSettings::setStandardFontFamily(const String& family, const String& script, ExceptionCode& ec)
349 {
350     InternalSettingsGuardForSettings();
351     setFontFamily(settings(), family, script, &Settings::setStandardFontFamily);
352 }
353
354 void InternalSettings::setSerifFontFamily(const String& family, const String& script, ExceptionCode& ec)
355 {
356     InternalSettingsGuardForSettings();
357     setFontFamily(settings(), family, script, &Settings::setSerifFontFamily);
358 }
359
360 void InternalSettings::setSansSerifFontFamily(const String& family, const String& script, ExceptionCode& ec)
361 {
362     InternalSettingsGuardForSettings();
363     setFontFamily(settings(), family, script, &Settings::setSansSerifFontFamily);
364 }
365
366 void InternalSettings::setFixedFontFamily(const String& family, const String& script, ExceptionCode& ec)
367 {
368     InternalSettingsGuardForSettings();
369     setFontFamily(settings(), family, script, &Settings::setFixedFontFamily);
370 }
371
372 void InternalSettings::setCursiveFontFamily(const String& family, const String& script, ExceptionCode& ec)
373 {
374     InternalSettingsGuardForSettings();
375     setFontFamily(settings(), family, script, &Settings::setCursiveFontFamily);
376 }
377
378 void InternalSettings::setFantasyFontFamily(const String& family, const String& script, ExceptionCode& ec)
379 {
380     InternalSettingsGuardForSettings();
381     setFontFamily(settings(), family, script, &Settings::setFantasyFontFamily);
382 }
383
384 void InternalSettings::setPictographFontFamily(const String& family, const String& script, ExceptionCode& ec)
385 {
386     InternalSettingsGuardForSettings();
387     setFontFamily(settings(), family, script, &Settings::setPictographFontFamily);
388 }
389
390 void InternalSettings::setTextAutosizingEnabled(bool enabled, ExceptionCode& ec)
391 {
392 #if ENABLE(TEXT_AUTOSIZING)
393     InternalSettingsGuardForSettings();
394     settings()->setTextAutosizingEnabled(enabled);
395 #else
396     UNUSED_PARAM(enabled);
397     UNUSED_PARAM(ec);
398 #endif
399 }
400
401 void InternalSettings::setTextAutosizingWindowSizeOverride(int width, int height, ExceptionCode& ec)
402 {
403 #if ENABLE(TEXT_AUTOSIZING)
404     InternalSettingsGuardForSettings();
405     settings()->setTextAutosizingWindowSizeOverride(IntSize(width, height));
406 #else
407     UNUSED_PARAM(width);
408     UNUSED_PARAM(height);
409     UNUSED_PARAM(ec);
410 #endif
411 }
412
413 void InternalSettings::setResolutionOverride(int dotsPerCSSInchHorizontally, int dotsPerCSSInchVertically, ExceptionCode& ec)
414 {
415     InternalSettingsGuardForSettings();
416     // An empty size resets the override.
417     settings()->setResolutionOverride(IntSize(dotsPerCSSInchHorizontally, dotsPerCSSInchVertically));
418 }
419
420 void InternalSettings::setMediaTypeOverride(const String& mediaType, ExceptionCode& ec)
421 {
422     InternalSettingsGuardForSettings();
423     settings()->setMediaTypeOverride(mediaType);
424 }
425
426 void InternalSettings::setTextAutosizingFontScaleFactor(float fontScaleFactor, ExceptionCode& ec)
427 {
428 #if ENABLE(TEXT_AUTOSIZING)
429     InternalSettingsGuardForSettings();
430     settings()->setTextAutosizingFontScaleFactor(fontScaleFactor);
431 #else
432     UNUSED_PARAM(fontScaleFactor);
433     UNUSED_PARAM(ec);
434 #endif
435 }
436
437 void InternalSettings::setEnableScrollAnimator(bool enabled, ExceptionCode& ec)
438 {
439 #if ENABLE(SMOOTH_SCROLLING)
440     InternalSettingsGuardForSettings();
441     settings()->setEnableScrollAnimator(enabled);
442 #else
443     UNUSED_PARAM(enabled);
444     UNUSED_PARAM(ec);
445 #endif
446 }
447
448 bool InternalSettings::scrollAnimatorEnabled(ExceptionCode& ec)
449 {
450 #if ENABLE(SMOOTH_SCROLLING)
451     InternalSettingsGuardForSettingsReturn(false);
452     return settings()->scrollAnimatorEnabled();
453 #else
454     UNUSED_PARAM(ec);
455     return false;
456 #endif
457 }
458
459 void InternalSettings::setCSSExclusionsEnabled(bool enabled, ExceptionCode& ec)
460 {
461     UNUSED_PARAM(ec);
462     RuntimeEnabledFeatures::setCSSExclusionsEnabled(enabled);
463 }
464
465 void InternalSettings::setCSSVariablesEnabled(bool enabled, ExceptionCode& ec)
466 {
467     InternalSettingsGuardForSettings();
468     settings()->setCSSVariablesEnabled(enabled);
469 }
470
471 bool InternalSettings::cssVariablesEnabled(ExceptionCode& ec)
472 {
473     InternalSettingsGuardForSettingsReturn(false);
474     return settings()->cssVariablesEnabled();
475 }
476
477 void InternalSettings::setCanStartMedia(bool enabled, ExceptionCode& ec)
478 {
479     InternalSettingsGuardForSettings();
480     m_page->setCanStartMedia(enabled);
481 }
482
483 void InternalSettings::setMediaPlaybackRequiresUserGesture(bool enabled, ExceptionCode& ec)
484 {
485     InternalSettingsGuardForSettings();
486     settings()->setMediaPlaybackRequiresUserGesture(enabled);
487 }
488
489 void InternalSettings::setEditingBehavior(const String& editingBehavior, ExceptionCode& ec)
490 {
491     InternalSettingsGuardForSettings();
492     if (equalIgnoringCase(editingBehavior, "win"))
493         settings()->setEditingBehaviorType(EditingWindowsBehavior);
494     else if (equalIgnoringCase(editingBehavior, "mac"))
495         settings()->setEditingBehaviorType(EditingMacBehavior);
496     else if (equalIgnoringCase(editingBehavior, "unix"))
497         settings()->setEditingBehaviorType(EditingUnixBehavior);
498     else
499         ec = SYNTAX_ERR;
500 }
501
502 void InternalSettings::setFixedPositionCreatesStackingContext(bool creates, ExceptionCode& ec)
503 {
504     InternalSettingsGuardForSettings();
505     settings()->setFixedPositionCreatesStackingContext(creates);
506 }
507
508 void InternalSettings::setSyncXHRInDocumentsEnabled(bool enabled, ExceptionCode& ec)
509 {
510     InternalSettingsGuardForSettings();
511     settings()->setSyncXHRInDocumentsEnabled(enabled);
512 }
513
514 void InternalSettings::setWindowFocusRestricted(bool restricted, ExceptionCode& ec)
515 {
516     InternalSettingsGuardForSettings();
517     settings()->setWindowFocusRestricted(restricted);
518 }
519
520 void InternalSettings::setDialogElementEnabled(bool enabled, ExceptionCode& ec)
521 {
522     UNUSED_PARAM(ec);
523 #if ENABLE(DIALOG_ELEMENT)
524     RuntimeEnabledFeatures::setDialogElementEnabled(enabled);
525 #else
526     UNUSED_PARAM(enabled);
527 #endif
528 }
529
530 void InternalSettings::allowRoundingHacks() const
531 {
532     TextRun::setAllowsRoundingHacks(true);
533 }
534
535 Vector<String> InternalSettings::userPreferredLanguages() const
536 {
537     return WebCore::userPreferredLanguages();
538 }
539
540 void InternalSettings::setUserPreferredLanguages(const Vector<String>& languages)
541 {
542     WebCore::overrideUserPreferredLanguages(languages);
543 }
544
545 void InternalSettings::setShouldDisplayTrackKind(const String& kind, bool enabled, ExceptionCode& ec)
546 {
547     InternalSettingsGuardForSettings();
548
549 #if ENABLE(VIDEO_TRACK)
550     if (equalIgnoringCase(kind, "Subtitles"))
551         settings()->setShouldDisplaySubtitles(enabled);
552     else if (equalIgnoringCase(kind, "Captions"))
553         settings()->setShouldDisplayCaptions(enabled);
554     else if (equalIgnoringCase(kind, "TextDescriptions"))
555         settings()->setShouldDisplayTextDescriptions(enabled);
556     else
557         ec = SYNTAX_ERR;
558 #else
559     UNUSED_PARAM(kind);
560     UNUSED_PARAM(enabled);
561 #endif
562 }
563
564 bool InternalSettings::shouldDisplayTrackKind(const String& kind, ExceptionCode& ec)
565 {
566     InternalSettingsGuardForSettingsReturn(false);
567
568 #if ENABLE(VIDEO_TRACK)
569     if (equalIgnoringCase(kind, "Subtitles"))
570         return settings()->shouldDisplaySubtitles();
571     if (equalIgnoringCase(kind, "Captions"))
572         return settings()->shouldDisplayCaptions();
573     if (equalIgnoringCase(kind, "TextDescriptions"))
574         return settings()->shouldDisplayTextDescriptions();
575
576     ec = SYNTAX_ERR;
577     return false;
578 #else
579     UNUSED_PARAM(kind);
580     return false;
581 #endif
582 }
583
584 void InternalSettings::setPagination(const String& mode, int gap, int pageLength, ExceptionCode& ec)
585 {
586     if (!page()) {
587         ec = INVALID_ACCESS_ERR;
588         return;
589     }
590
591     Pagination pagination;
592     if (mode == "Unpaginated")
593         pagination.mode = Pagination::Unpaginated;
594     else if (mode == "LeftToRightPaginated")
595         pagination.mode = Pagination::LeftToRightPaginated;
596     else if (mode == "RightToLeftPaginated")
597         pagination.mode = Pagination::RightToLeftPaginated;
598     else if (mode == "TopToBottomPaginated")
599         pagination.mode = Pagination::TopToBottomPaginated;
600     else if (mode == "BottomToTopPaginated")
601         pagination.mode = Pagination::BottomToTopPaginated;
602     else {
603         ec = SYNTAX_ERR;
604         return;
605     }
606
607     pagination.gap = gap;
608     pagination.pageLength = pageLength;
609     page()->setPagination(pagination);
610 }
611
612 void InternalSettings::setEnableMockPagePopup(bool enabled, ExceptionCode& ec)
613 {
614 #if ENABLE(PAGE_POPUP)
615     InternalSettingsGuardForPage();
616     if (!page()->chrome())
617         return;
618     if (!enabled) {
619         page()->chrome()->client()->resetPagePopupDriver();
620         return;
621     }
622     if (!m_pagePopupDriver)
623         m_pagePopupDriver = MockPagePopupDriver::create(page()->mainFrame());
624     page()->chrome()->client()->setPagePopupDriver(m_pagePopupDriver.get());
625 #else
626     UNUSED_PARAM(enabled);
627     UNUSED_PARAM(ec);
628 #endif
629 }
630
631 String InternalSettings::configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode& ec)
632 {
633     if (!page()) {
634         ec = INVALID_ACCESS_ERR;
635         return String();
636     }
637
638     const int defaultLayoutWidthForNonMobilePages = 980;
639
640     ViewportArguments arguments = page()->viewportArguments();
641     ViewportAttributes attributes = computeViewportAttributes(arguments, defaultLayoutWidthForNonMobilePages, deviceWidth, deviceHeight, devicePixelRatio, IntSize(availableWidth, availableHeight));
642     restrictMinimumScaleFactorToViewportSize(attributes, IntSize(availableWidth, availableHeight), devicePixelRatio);
643     restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
644
645     return "viewport size " + String::number(attributes.layoutSize.width()) + "x" + String::number(attributes.layoutSize.height()) + " scale " + String::number(attributes.initialScale) + " with limits [" + String::number(attributes.minimumScale) + ", " + String::number(attributes.maximumScale) + "] and userScalable " + (attributes.userScalable ? "true" : "false");
646 }
647
648 void InternalSettings::setMemoryInfoEnabled(bool enabled, ExceptionCode& ec)
649 {
650     InternalSettingsGuardForSettings();
651     settings()->setMemoryInfoEnabled(enabled);
652 }
653
654 void InternalSettings::setStorageBlockingPolicy(const String& mode, ExceptionCode& ec)
655 {
656     InternalSettingsGuardForSettings();
657
658     if (mode == "AllowAll")
659         settings()->setStorageBlockingPolicy(SecurityOrigin::AllowAllStorage);
660     else if (mode == "BlockThirdParty")
661         settings()->setStorageBlockingPolicy(SecurityOrigin::BlockThirdPartyStorage);
662     else if (mode == "BlockAll")
663         settings()->setStorageBlockingPolicy(SecurityOrigin::BlockAllStorage);
664     else
665         ec = SYNTAX_ERR;
666 }
667
668 void InternalSettings::setLangAttributeAwareFormControlUIEnabled(bool enabled)
669 {
670     RuntimeEnabledFeatures::setLangAttributeAwareFormControlUIEnabled(enabled);
671 }
672
673 void InternalSettings::setImagesEnabled(bool enabled, ExceptionCode& ec)
674 {
675     InternalSettingsGuardForSettings();
676     settings()->setImagesEnabled(enabled);
677 }
678
679 }