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