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