Remove devicePixelRatio from ViewportAttributes
[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 "InspectorController.h"
36 #include "Language.h"
37 #include "LocaleToScriptMapping.h"
38 #include "MockPagePopupDriver.h"
39 #include "Page.h"
40 #include "RuntimeEnabledFeatures.h"
41 #include "Settings.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 InternalSettingsGuardForPageReturn(returnValue) \
61     if (!page()) { \
62         ec = INVALID_ACCESS_ERR; \
63         return returnValue; \
64     }
65
66 #define InternalSettingsGuardForPage() \
67     if (!page()) { \
68         ec = INVALID_ACCESS_ERR; \
69         return; \
70     }
71
72 namespace WebCore {
73
74 InternalSettings::Backup::Backup(Page* page, Settings* settings)
75     : m_originalPasswordEchoDurationInSeconds(settings->passwordEchoDurationInSeconds())
76     , m_originalPasswordEchoEnabled(settings->passwordEchoEnabled())
77     , m_originalCSSExclusionsEnabled(RuntimeEnabledFeatures::cssExclusionsEnabled())
78 #if ENABLE(SHADOW_DOM)
79     , m_originalShadowDOMEnabled(RuntimeEnabledFeatures::shadowDOMEnabled())
80     , m_originalAuthorShadowDOMForAnyElementEnabled(RuntimeEnabledFeatures::authorShadowDOMForAnyElementEnabled())
81 #endif
82 #if ENABLE(STYLE_SCOPED)
83     , m_originalStyleScoped(RuntimeEnabledFeatures::styleScopedEnabled())
84 #endif
85     , m_originalEditingBehavior(settings->editingBehaviorType())
86     , m_originalUnifiedSpellCheckerEnabled(settings->unifiedTextCheckerEnabled())
87     , m_originalFixedPositionCreatesStackingContext(settings->fixedPositionCreatesStackingContext())
88     , m_originalSyncXHRInDocumentsEnabled(settings->syncXHRInDocumentsEnabled())
89 #if ENABLE(INSPECTOR) && ENABLE(JAVASCRIPT_DEBUGGER)
90     , m_originalJavaScriptProfilingEnabled(page->inspectorController() && page->inspectorController()->profilerEnabled())
91 #endif
92     , m_originalWindowFocusRestricted(settings->windowFocusRestricted())
93     , m_originalDeviceSupportsTouch(settings->deviceSupportsTouch())
94     , m_originalDeviceSupportsMouse(settings->deviceSupportsMouse())
95 #if ENABLE(TEXT_AUTOSIZING)
96     , m_originalTextAutosizingEnabled(settings->textAutosizingEnabled())
97     , m_originalTextAutosizingWindowSizeOverride(settings->textAutosizingWindowSizeOverride())
98     , m_originalTextAutosizingFontScaleFactor(settings->textAutosizingFontScaleFactor())
99 #endif
100 #if ENABLE(DIALOG_ELEMENT)
101     , m_originalDialogElementEnabled(RuntimeEnabledFeatures::dialogElementEnabled())
102 #endif
103     , m_canStartMedia(page->canStartMedia())
104     , m_originalMockScrollbarsEnabled(settings->mockScrollbarsEnabled())
105     , m_langAttributeAwareFormControlUIEnabled(RuntimeEnabledFeatures::langAttributeAwareFormControlUIEnabled())
106     , m_imagesEnabled(settings->areImagesEnabled())
107 {
108 }
109
110
111 void InternalSettings::Backup::restoreTo(Page* page, Settings* settings)
112 {
113     settings->setPasswordEchoDurationInSeconds(m_originalPasswordEchoDurationInSeconds);
114     settings->setPasswordEchoEnabled(m_originalPasswordEchoEnabled);
115     RuntimeEnabledFeatures::setCSSExclusionsEnabled(m_originalCSSExclusionsEnabled);
116 #if ENABLE(SHADOW_DOM)
117     RuntimeEnabledFeatures::setShadowDOMEnabled(m_originalShadowDOMEnabled);
118     RuntimeEnabledFeatures::setAuthorShadowDOMForAnyElementEnabled(m_originalAuthorShadowDOMForAnyElementEnabled);
119 #endif
120 #if ENABLE(STYLE_SCOPED)
121     RuntimeEnabledFeatures::setStyleScopedEnabled(m_originalStyleScoped);
122 #endif
123     settings->setEditingBehaviorType(m_originalEditingBehavior);
124     settings->setUnifiedTextCheckerEnabled(m_originalUnifiedSpellCheckerEnabled);
125     settings->setFixedPositionCreatesStackingContext(m_originalFixedPositionCreatesStackingContext);
126     settings->setSyncXHRInDocumentsEnabled(m_originalSyncXHRInDocumentsEnabled);
127 #if ENABLE(INSPECTOR) && ENABLE(JAVASCRIPT_DEBUGGER)
128     if (page->inspectorController())
129         page->inspectorController()->setProfilerEnabled(m_originalJavaScriptProfilingEnabled);
130 #endif
131     settings->setWindowFocusRestricted(m_originalWindowFocusRestricted);
132     settings->setDeviceSupportsTouch(m_originalDeviceSupportsTouch);
133     settings->setDeviceSupportsMouse(m_originalDeviceSupportsMouse);
134 #if ENABLE(TEXT_AUTOSIZING)
135     settings->setTextAutosizingEnabled(m_originalTextAutosizingEnabled);
136     settings->setTextAutosizingWindowSizeOverride(m_originalTextAutosizingWindowSizeOverride);
137     settings->setTextAutosizingFontScaleFactor(m_originalTextAutosizingFontScaleFactor);
138 #endif
139 #if ENABLE(DIALOG_ELEMENT)
140     RuntimeEnabledFeatures::setDialogElementEnabled(m_originalDialogElementEnabled);
141 #endif
142     page->setCanStartMedia(m_canStartMedia);
143     settings->setMockScrollbarsEnabled(m_originalMockScrollbarsEnabled);
144     RuntimeEnabledFeatures::setLangAttributeAwareFormControlUIEnabled(m_langAttributeAwareFormControlUIEnabled);
145     settings->setImagesEnabled(m_imagesEnabled);
146 }
147
148 InternalSettings* InternalSettings::from(Page* page)
149 {
150     DEFINE_STATIC_LOCAL(AtomicString, name, ("InternalSettings"));
151     if (!SuperType::from(page, name))
152         SuperType::provideTo(page, name, adoptRef(new InternalSettings(page)));
153     return static_cast<InternalSettings*>(SuperType::from(page, name));
154 }
155
156 InternalSettings::~InternalSettings()
157 {
158 }
159
160 InternalSettings::InternalSettings(Page* page)
161     : m_page(page)
162     , m_backup(page, page->settings())
163 {
164 }
165
166 #if ENABLE(PAGE_POPUP)
167 PagePopupController* InternalSettings::pagePopupController()
168 {
169     return m_pagePopupDriver ? m_pagePopupDriver->pagePopupController() : 0;
170 }
171 #endif
172
173 void InternalSettings::reset()
174 {
175     TextRun::setAllowsRoundingHacks(false);
176     setUserPreferredLanguages(Vector<String>());
177     page()->setPagination(Pagination());
178     page()->setPageScaleFactor(1, IntPoint(0, 0));
179     setUsesOverlayScrollbars(false);
180 #if ENABLE(PAGE_POPUP)
181     m_pagePopupDriver.clear();
182     if (page()->chrome())
183         page()->chrome()->client()->resetPagePopupDriver();
184 #endif
185
186     m_backup.restoreTo(page(), settings());
187     m_backup = Backup(page(), settings());
188 }
189
190 Settings* InternalSettings::settings() const
191 {
192     if (!page())
193         return 0;
194     return page()->settings();
195 }
196
197 void InternalSettings::setInspectorResourcesDataSizeLimits(int maximumResourcesContentSize, int maximumSingleResourceContentSize, ExceptionCode& ec)
198 {
199 #if ENABLE(INSPECTOR)
200     if (!page() || !page()->inspectorController()) {
201         ec = INVALID_ACCESS_ERR;
202         return;
203     }
204     page()->inspectorController()->setResourcesDataSizeLimitsFromInternals(maximumResourcesContentSize, maximumSingleResourceContentSize);
205 #else
206     UNUSED_PARAM(maximumResourcesContentSize);
207     UNUSED_PARAM(maximumSingleResourceContentSize);
208     UNUSED_PARAM(ec);
209 #endif
210 }
211
212 void InternalSettings::setForceCompositingMode(bool enabled, ExceptionCode& ec)
213 {
214     InternalSettingsGuardForSettings();
215     settings()->setForceCompositingMode(enabled);
216 }
217
218 void InternalSettings::setAcceleratedFiltersEnabled(bool enabled, ExceptionCode& ec)
219 {
220     InternalSettingsGuardForSettings();
221     settings()->setAcceleratedFiltersEnabled(enabled);
222 }
223
224 void InternalSettings::setEnableCompositingForFixedPosition(bool enabled, ExceptionCode& ec)
225 {
226     InternalSettingsGuardForSettings();
227     settings()->setAcceleratedCompositingForFixedPositionEnabled(enabled);
228 }
229
230 void InternalSettings::setEnableCompositingForScrollableFrames(bool enabled, ExceptionCode& ec)
231 {
232     InternalSettingsGuardForSettings();
233     settings()->setAcceleratedCompositingForScrollableFramesEnabled(enabled);
234 }
235
236 void InternalSettings::setAcceleratedDrawingEnabled(bool enabled, ExceptionCode& ec)
237 {
238     InternalSettingsGuardForSettings();
239     settings()->setAcceleratedDrawingEnabled(enabled);
240 }
241
242 void InternalSettings::setMockScrollbarsEnabled(bool enabled, ExceptionCode& ec)
243 {
244     InternalSettingsGuardForSettings();
245     settings()->setMockScrollbarsEnabled(enabled);
246 }
247
248 void InternalSettings::setUsesOverlayScrollbars(bool flag)
249 {
250     settings()->setUsesOverlayScrollbars(flag);
251 }
252
253 void InternalSettings::setPasswordEchoEnabled(bool enabled, ExceptionCode& ec)
254 {
255     InternalSettingsGuardForSettings();
256     settings()->setPasswordEchoEnabled(enabled);
257 }
258
259 void InternalSettings::setPasswordEchoDurationInSeconds(double durationInSeconds, ExceptionCode& ec)
260 {
261     InternalSettingsGuardForSettings();
262     settings()->setPasswordEchoDurationInSeconds(durationInSeconds);
263 }
264
265 void InternalSettings::setFixedElementsLayoutRelativeToFrame(bool enabled, ExceptionCode& ec)
266 {
267     InternalSettingsGuardForSettings();
268     settings()->setFixedElementsLayoutRelativeToFrame(enabled);
269 }
270
271 void InternalSettings::setUnifiedTextCheckingEnabled(bool enabled, ExceptionCode& ec)
272 {
273     InternalSettingsGuardForSettings();
274     settings()->setUnifiedTextCheckerEnabled(enabled);
275 }
276
277 bool InternalSettings::unifiedTextCheckingEnabled(ExceptionCode& ec)
278 {
279     InternalSettingsGuardForSettingsReturn(false);
280     return settings()->unifiedTextCheckerEnabled();
281 }
282
283 void InternalSettings::setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode& ec)
284 {
285     InternalSettingsGuardForPage();
286     page()->setPageScaleFactor(scaleFactor, IntPoint(x, y));
287 }
288
289 void InternalSettings::setShadowDOMEnabled(bool enabled, ExceptionCode& ec)
290 {
291 #if ENABLE(SHADOW_DOM)
292     UNUSED_PARAM(ec);
293     RuntimeEnabledFeatures::setShadowDOMEnabled(enabled);
294 #else
295     // Even SHADOW_DOM is off, InternalSettings allows setShadowDOMEnabled(false) to
296     // have broader test coverage. But it cannot be setShadowDOMEnabled(true).
297     if (enabled)
298         ec = INVALID_ACCESS_ERR;
299 #endif
300 }
301
302 void InternalSettings::setAuthorShadowDOMForAnyElementEnabled(bool isEnabled)
303 {
304 #if ENABLE(SHADOW_DOM)
305     RuntimeEnabledFeatures::setAuthorShadowDOMForAnyElementEnabled(isEnabled);
306 #else
307     UNUSED_PARAM(isEnabled);
308 #endif
309 }
310
311 void InternalSettings::setStyleScopedEnabled(bool enabled)
312 {
313 #if ENABLE(STYLE_SCOPED)
314     RuntimeEnabledFeatures::setStyleScopedEnabled(enabled);
315 #else
316     UNUSED_PARAM(enabled);
317 #endif
318 }
319
320 void InternalSettings::setTouchEventEmulationEnabled(bool enabled, ExceptionCode& ec)
321 {
322 #if ENABLE(TOUCH_EVENTS)
323     InternalSettingsGuardForSettings();
324     settings()->setTouchEventEmulationEnabled(enabled);
325 #else
326     UNUSED_PARAM(enabled);
327     UNUSED_PARAM(ec);
328 #endif
329 }
330
331 void InternalSettings::setDeviceSupportsTouch(bool enabled, ExceptionCode& ec)
332 {
333     InternalSettingsGuardForSettings();
334     settings()->setDeviceSupportsTouch(enabled);
335 }
336
337 void InternalSettings::setDeviceSupportsMouse(bool enabled, ExceptionCode& ec)
338 {
339     InternalSettingsGuardForSettings();
340     settings()->setDeviceSupportsMouse(enabled);
341 }
342
343 typedef void (Settings::*SetFontFamilyFunction)(const AtomicString&, UScriptCode);
344 static void setFontFamily(Settings* settings, const String& family, const String& script, SetFontFamilyFunction setter)
345 {
346     UScriptCode code = scriptNameToCode(script);
347     if (code != USCRIPT_INVALID_CODE)
348         (settings->*setter)(family, code);
349 }
350
351 void InternalSettings::setStandardFontFamily(const String& family, const String& script, ExceptionCode& ec)
352 {
353     InternalSettingsGuardForSettings();
354     setFontFamily(settings(), family, script, &Settings::setStandardFontFamily);
355 }
356
357 void InternalSettings::setSerifFontFamily(const String& family, const String& script, ExceptionCode& ec)
358 {
359     InternalSettingsGuardForSettings();
360     setFontFamily(settings(), family, script, &Settings::setSerifFontFamily);
361 }
362
363 void InternalSettings::setSansSerifFontFamily(const String& family, const String& script, ExceptionCode& ec)
364 {
365     InternalSettingsGuardForSettings();
366     setFontFamily(settings(), family, script, &Settings::setSansSerifFontFamily);
367 }
368
369 void InternalSettings::setFixedFontFamily(const String& family, const String& script, ExceptionCode& ec)
370 {
371     InternalSettingsGuardForSettings();
372     setFontFamily(settings(), family, script, &Settings::setFixedFontFamily);
373 }
374
375 void InternalSettings::setCursiveFontFamily(const String& family, const String& script, ExceptionCode& ec)
376 {
377     InternalSettingsGuardForSettings();
378     setFontFamily(settings(), family, script, &Settings::setCursiveFontFamily);
379 }
380
381 void InternalSettings::setFantasyFontFamily(const String& family, const String& script, ExceptionCode& ec)
382 {
383     InternalSettingsGuardForSettings();
384     setFontFamily(settings(), family, script, &Settings::setFantasyFontFamily);
385 }
386
387 void InternalSettings::setPictographFontFamily(const String& family, const String& script, ExceptionCode& ec)
388 {
389     InternalSettingsGuardForSettings();
390     setFontFamily(settings(), family, script, &Settings::setPictographFontFamily);
391 }
392
393 void InternalSettings::setTextAutosizingEnabled(bool enabled, ExceptionCode& ec)
394 {
395 #if ENABLE(TEXT_AUTOSIZING)
396     InternalSettingsGuardForSettings();
397     settings()->setTextAutosizingEnabled(enabled);
398 #else
399     UNUSED_PARAM(enabled);
400     UNUSED_PARAM(ec);
401 #endif
402 }
403
404 void InternalSettings::setTextAutosizingWindowSizeOverride(int width, int height, ExceptionCode& ec)
405 {
406 #if ENABLE(TEXT_AUTOSIZING)
407     InternalSettingsGuardForSettings();
408     settings()->setTextAutosizingWindowSizeOverride(IntSize(width, height));
409 #else
410     UNUSED_PARAM(width);
411     UNUSED_PARAM(height);
412     UNUSED_PARAM(ec);
413 #endif
414 }
415
416 void InternalSettings::setTextAutosizingFontScaleFactor(float fontScaleFactor, ExceptionCode& ec)
417 {
418 #if ENABLE(TEXT_AUTOSIZING)
419     InternalSettingsGuardForSettings();
420     settings()->setTextAutosizingFontScaleFactor(fontScaleFactor);
421 #else
422     UNUSED_PARAM(fontScaleFactor);
423     UNUSED_PARAM(ec);
424 #endif
425 }
426
427 void InternalSettings::setEnableScrollAnimator(bool enabled, ExceptionCode& ec)
428 {
429 #if ENABLE(SMOOTH_SCROLLING)
430     InternalSettingsGuardForSettings();
431     settings()->setEnableScrollAnimator(enabled);
432 #else
433     UNUSED_PARAM(enabled);
434     UNUSED_PARAM(ec);
435 #endif
436 }
437
438 bool InternalSettings::scrollAnimatorEnabled(ExceptionCode& ec)
439 {
440 #if ENABLE(SMOOTH_SCROLLING)
441     InternalSettingsGuardForSettingsReturn(false);
442     return settings()->scrollAnimatorEnabled();
443 #else
444     UNUSED_PARAM(ec);
445     return false;
446 #endif
447 }
448
449 void InternalSettings::setCSSExclusionsEnabled(bool enabled, ExceptionCode& ec)
450 {
451     UNUSED_PARAM(ec);
452     RuntimeEnabledFeatures::setCSSExclusionsEnabled(enabled);
453 }
454
455 void InternalSettings::setCSSVariablesEnabled(bool enabled, ExceptionCode& ec)
456 {
457     InternalSettingsGuardForSettings();
458     settings()->setCSSVariablesEnabled(enabled);
459 }
460
461 bool InternalSettings::cssVariablesEnabled(ExceptionCode& ec)
462 {
463     InternalSettingsGuardForSettingsReturn(false);
464     return settings()->cssVariablesEnabled();
465 }
466
467 void InternalSettings::setCanStartMedia(bool enabled, ExceptionCode& ec)
468 {
469     InternalSettingsGuardForSettings();
470     m_page->setCanStartMedia(enabled);
471 }
472
473 void InternalSettings::setMediaPlaybackRequiresUserGesture(bool enabled, ExceptionCode& ec)
474 {
475     InternalSettingsGuardForSettings();
476     settings()->setMediaPlaybackRequiresUserGesture(enabled);
477 }
478
479 void InternalSettings::setEditingBehavior(const String& editingBehavior, ExceptionCode& ec)
480 {
481     InternalSettingsGuardForSettings();
482     if (equalIgnoringCase(editingBehavior, "win"))
483         settings()->setEditingBehaviorType(EditingWindowsBehavior);
484     else if (equalIgnoringCase(editingBehavior, "mac"))
485         settings()->setEditingBehaviorType(EditingMacBehavior);
486     else if (equalIgnoringCase(editingBehavior, "unix"))
487         settings()->setEditingBehaviorType(EditingUnixBehavior);
488     else
489         ec = SYNTAX_ERR;
490 }
491
492 void InternalSettings::setFixedPositionCreatesStackingContext(bool creates, ExceptionCode& ec)
493 {
494     InternalSettingsGuardForSettings();
495     settings()->setFixedPositionCreatesStackingContext(creates);
496 }
497
498 void InternalSettings::setSyncXHRInDocumentsEnabled(bool enabled, ExceptionCode& ec)
499 {
500     InternalSettingsGuardForSettings();
501     settings()->setSyncXHRInDocumentsEnabled(enabled);
502 }
503
504 void InternalSettings::setJavaScriptProfilingEnabled(bool enabled, ExceptionCode& ec)
505 {
506 #if ENABLE(INSPECTOR)
507     if (!page() || !page()->inspectorController()) {
508         ec = INVALID_ACCESS_ERR;
509         return;
510     }
511
512     page()->inspectorController()->setProfilerEnabled(enabled);
513 #else
514     UNUSED_PARAM(enabled);
515     UNUSED_PARAM(ec);
516     return;
517 #endif
518 }
519
520 void InternalSettings::setWindowFocusRestricted(bool restricted, ExceptionCode& ec)
521 {
522     InternalSettingsGuardForSettings();
523     settings()->setWindowFocusRestricted(restricted);
524 }
525
526 void InternalSettings::setDialogElementEnabled(bool enabled, ExceptionCode& ec)
527 {
528     UNUSED_PARAM(ec);
529 #if ENABLE(DIALOG_ELEMENT)
530     RuntimeEnabledFeatures::setDialogElementEnabled(enabled);
531 #else
532     UNUSED_PARAM(enabled);
533 #endif
534 }
535
536 void InternalSettings::allowRoundingHacks() const
537 {
538     TextRun::setAllowsRoundingHacks(true);
539 }
540
541 Vector<String> InternalSettings::userPreferredLanguages() const
542 {
543     return WebCore::userPreferredLanguages();
544 }
545
546 void InternalSettings::setUserPreferredLanguages(const Vector<String>& languages)
547 {
548     WebCore::overrideUserPreferredLanguages(languages);
549 }
550
551 void InternalSettings::setShouldDisplayTrackKind(const String& kind, bool enabled, ExceptionCode& ec)
552 {
553     InternalSettingsGuardForSettings();
554
555 #if ENABLE(VIDEO_TRACK)
556     if (equalIgnoringCase(kind, "Subtitles"))
557         settings()->setShouldDisplaySubtitles(enabled);
558     else if (equalIgnoringCase(kind, "Captions"))
559         settings()->setShouldDisplayCaptions(enabled);
560     else if (equalIgnoringCase(kind, "TextDescriptions"))
561         settings()->setShouldDisplayTextDescriptions(enabled);
562     else
563         ec = SYNTAX_ERR;
564 #else
565     UNUSED_PARAM(kind);
566     UNUSED_PARAM(enabled);
567 #endif
568 }
569
570 bool InternalSettings::shouldDisplayTrackKind(const String& kind, ExceptionCode& ec)
571 {
572     InternalSettingsGuardForSettingsReturn(false);
573
574 #if ENABLE(VIDEO_TRACK)
575     if (equalIgnoringCase(kind, "Subtitles"))
576         return settings()->shouldDisplaySubtitles();
577     if (equalIgnoringCase(kind, "Captions"))
578         return settings()->shouldDisplayCaptions();
579     if (equalIgnoringCase(kind, "TextDescriptions"))
580         return settings()->shouldDisplayTextDescriptions();
581
582     ec = SYNTAX_ERR;
583     return false;
584 #else
585     UNUSED_PARAM(kind);
586     return false;
587 #endif
588 }
589
590 void InternalSettings::setPagination(const String& mode, int gap, int pageLength, ExceptionCode& ec)
591 {
592     if (!page()) {
593         ec = INVALID_ACCESS_ERR;
594         return;
595     }
596
597     Pagination pagination;
598     if (mode == "Unpaginated")
599         pagination.mode = Pagination::Unpaginated;
600     else if (mode == "LeftToRightPaginated")
601         pagination.mode = Pagination::LeftToRightPaginated;
602     else if (mode == "RightToLeftPaginated")
603         pagination.mode = Pagination::RightToLeftPaginated;
604     else if (mode == "TopToBottomPaginated")
605         pagination.mode = Pagination::TopToBottomPaginated;
606     else if (mode == "BottomToTopPaginated")
607         pagination.mode = Pagination::BottomToTopPaginated;
608     else {
609         ec = SYNTAX_ERR;
610         return;
611     }
612
613     pagination.gap = gap;
614     pagination.pageLength = pageLength;
615     page()->setPagination(pagination);
616 }
617
618 void InternalSettings::setEnableMockPagePopup(bool enabled, ExceptionCode& ec)
619 {
620 #if ENABLE(PAGE_POPUP)
621     InternalSettingsGuardForPage();
622     if (!page()->chrome())
623         return;
624     if (!enabled) {
625         page()->chrome()->client()->resetPagePopupDriver();
626         return;
627     }
628     if (!m_pagePopupDriver)
629         m_pagePopupDriver = MockPagePopupDriver::create(page()->mainFrame());
630     page()->chrome()->client()->setPagePopupDriver(m_pagePopupDriver.get());
631 #else
632     UNUSED_PARAM(enabled);
633     UNUSED_PARAM(ec);
634 #endif
635 }
636
637 String InternalSettings::configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode& ec)
638 {
639     if (!page()) {
640         ec = INVALID_ACCESS_ERR;
641         return String();
642     }
643
644     const int defaultLayoutWidthForNonMobilePages = 980;
645
646     ViewportArguments arguments = page()->viewportArguments();
647     ViewportAttributes attributes = computeViewportAttributes(arguments, defaultLayoutWidthForNonMobilePages, deviceWidth, deviceHeight, devicePixelRatio, IntSize(availableWidth, availableHeight));
648     restrictMinimumScaleFactorToViewportSize(attributes, IntSize(availableWidth, availableHeight), devicePixelRatio);
649     restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
650
651     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");
652 }
653
654 void InternalSettings::setMemoryInfoEnabled(bool enabled, ExceptionCode& ec)
655 {
656     InternalSettingsGuardForSettings();
657     settings()->setMemoryInfoEnabled(enabled);
658 }
659
660 void InternalSettings::setStorageBlockingPolicy(const String& mode, ExceptionCode& ec)
661 {
662     InternalSettingsGuardForSettings();
663
664     if (mode == "AllowAll")
665         settings()->setStorageBlockingPolicy(SecurityOrigin::AllowAllStorage);
666     else if (mode == "BlockThirdParty")
667         settings()->setStorageBlockingPolicy(SecurityOrigin::BlockThirdPartyStorage);
668     else if (mode == "BlockAll")
669         settings()->setStorageBlockingPolicy(SecurityOrigin::BlockAllStorage);
670     else
671         ec = SYNTAX_ERR;
672 }
673
674 void InternalSettings::setLangAttributeAwareFormControlUIEnabled(bool enabled)
675 {
676     RuntimeEnabledFeatures::setLangAttributeAwareFormControlUIEnabled(enabled);
677 }
678
679 void InternalSettings::setImagesEnabled(bool enabled, ExceptionCode& ec)
680 {
681     InternalSettingsGuardForSettings();
682     settings()->setImagesEnabled(enabled);
683 }
684
685 }