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