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