Move non-Settings Inspector methods from internals.settings to internals
[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 "Language.h"
36 #include "LocaleToScriptMapping.h"
37 #include "MockPagePopupDriver.h"
38 #include "Page.h"
39 #include "RuntimeEnabledFeatures.h"
40 #include "Settings.h"
41 #include "TextRun.h"
42
43 #if ENABLE(INPUT_TYPE_COLOR)
44 #include "ColorChooser.h"
45 #endif
46
47 #define InternalSettingsGuardForSettingsReturn(returnValue) \
48     if (!settings()) { \
49         ec = INVALID_ACCESS_ERR; \
50         return returnValue; \
51     }
52
53 #define InternalSettingsGuardForSettings()  \
54     if (!settings()) { \
55         ec = INVALID_ACCESS_ERR; \
56         return; \
57     }
58
59 #define InternalSettingsGuardForPage() \
60     if (!page()) { \
61         ec = INVALID_ACCESS_ERR; \
62         return; \
63     }
64
65 namespace WebCore {
66
67 InternalSettings::Backup::Backup(Page* page, Settings* settings)
68     : m_originalPasswordEchoDurationInSeconds(settings->passwordEchoDurationInSeconds())
69     , m_originalPasswordEchoEnabled(settings->passwordEchoEnabled())
70     , m_originalCSSExclusionsEnabled(RuntimeEnabledFeatures::cssExclusionsEnabled())
71 #if ENABLE(SHADOW_DOM)
72     , m_originalShadowDOMEnabled(RuntimeEnabledFeatures::shadowDOMEnabled())
73     , m_originalAuthorShadowDOMForAnyElementEnabled(RuntimeEnabledFeatures::authorShadowDOMForAnyElementEnabled())
74 #endif
75 #if ENABLE(STYLE_SCOPED)
76     , m_originalStyleScoped(RuntimeEnabledFeatures::styleScopedEnabled())
77 #endif
78     , m_originalEditingBehavior(settings->editingBehaviorType())
79     , m_originalUnifiedSpellCheckerEnabled(settings->unifiedTextCheckerEnabled())
80     , m_originalFixedPositionCreatesStackingContext(settings->fixedPositionCreatesStackingContext())
81     , m_originalSyncXHRInDocumentsEnabled(settings->syncXHRInDocumentsEnabled())
82     , m_originalWindowFocusRestricted(settings->windowFocusRestricted())
83     , m_originalDeviceSupportsTouch(settings->deviceSupportsTouch())
84     , m_originalDeviceSupportsMouse(settings->deviceSupportsMouse())
85 #if ENABLE(TEXT_AUTOSIZING)
86     , m_originalTextAutosizingEnabled(settings->textAutosizingEnabled())
87     , m_originalTextAutosizingWindowSizeOverride(settings->textAutosizingWindowSizeOverride())
88     , m_originalTextAutosizingFontScaleFactor(settings->textAutosizingFontScaleFactor())
89 #endif
90     , m_originalResolutionOverride(settings->resolutionOverride())
91     , m_originalMediaTypeOverride(settings->mediaTypeOverride())
92 #if ENABLE(DIALOG_ELEMENT)
93     , m_originalDialogElementEnabled(RuntimeEnabledFeatures::dialogElementEnabled())
94 #endif
95     , m_canStartMedia(page->canStartMedia())
96     , m_originalMockScrollbarsEnabled(settings->mockScrollbarsEnabled())
97     , m_langAttributeAwareFormControlUIEnabled(RuntimeEnabledFeatures::langAttributeAwareFormControlUIEnabled())
98     , m_imagesEnabled(settings->areImagesEnabled())
99 {
100 }
101
102
103 void InternalSettings::Backup::restoreTo(Page* page, Settings* settings)
104 {
105     settings->setPasswordEchoDurationInSeconds(m_originalPasswordEchoDurationInSeconds);
106     settings->setPasswordEchoEnabled(m_originalPasswordEchoEnabled);
107     RuntimeEnabledFeatures::setCSSExclusionsEnabled(m_originalCSSExclusionsEnabled);
108 #if ENABLE(SHADOW_DOM)
109     RuntimeEnabledFeatures::setShadowDOMEnabled(m_originalShadowDOMEnabled);
110     RuntimeEnabledFeatures::setAuthorShadowDOMForAnyElementEnabled(m_originalAuthorShadowDOMForAnyElementEnabled);
111 #endif
112 #if ENABLE(STYLE_SCOPED)
113     RuntimeEnabledFeatures::setStyleScopedEnabled(m_originalStyleScoped);
114 #endif
115     settings->setEditingBehaviorType(m_originalEditingBehavior);
116     settings->setUnifiedTextCheckerEnabled(m_originalUnifiedSpellCheckerEnabled);
117     settings->setFixedPositionCreatesStackingContext(m_originalFixedPositionCreatesStackingContext);
118     settings->setSyncXHRInDocumentsEnabled(m_originalSyncXHRInDocumentsEnabled);
119     settings->setWindowFocusRestricted(m_originalWindowFocusRestricted);
120     settings->setDeviceSupportsTouch(m_originalDeviceSupportsTouch);
121     settings->setDeviceSupportsMouse(m_originalDeviceSupportsMouse);
122 #if ENABLE(TEXT_AUTOSIZING)
123     settings->setTextAutosizingEnabled(m_originalTextAutosizingEnabled);
124     settings->setTextAutosizingWindowSizeOverride(m_originalTextAutosizingWindowSizeOverride);
125     settings->setTextAutosizingFontScaleFactor(m_originalTextAutosizingFontScaleFactor);
126 #endif
127     settings->setResolutionOverride(m_originalResolutionOverride);
128     settings->setMediaTypeOverride(m_originalMediaTypeOverride);
129 #if ENABLE(DIALOG_ELEMENT)
130     RuntimeEnabledFeatures::setDialogElementEnabled(m_originalDialogElementEnabled);
131 #endif
132     page->setCanStartMedia(m_canStartMedia);
133     settings->setMockScrollbarsEnabled(m_originalMockScrollbarsEnabled);
134     RuntimeEnabledFeatures::setLangAttributeAwareFormControlUIEnabled(m_langAttributeAwareFormControlUIEnabled);
135     settings->setImagesEnabled(m_imagesEnabled);
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     setUsesOverlayScrollbars(false);
170 #if ENABLE(PAGE_POPUP)
171     m_pagePopupDriver.clear();
172     if (page()->chrome())
173         page()->chrome()->client()->resetPagePopupDriver();
174 #endif
175
176     m_backup.restoreTo(page(), settings());
177     m_backup = Backup(page(), settings());
178 }
179
180 Settings* InternalSettings::settings() const
181 {
182     if (!page())
183         return 0;
184     return page()->settings();
185 }
186
187 void InternalSettings::setForceCompositingMode(bool enabled, ExceptionCode& ec)
188 {
189     InternalSettingsGuardForSettings();
190     settings()->setForceCompositingMode(enabled);
191 }
192
193 void InternalSettings::setAcceleratedFiltersEnabled(bool enabled, ExceptionCode& ec)
194 {
195     InternalSettingsGuardForSettings();
196     settings()->setAcceleratedFiltersEnabled(enabled);
197 }
198
199 void InternalSettings::setEnableCompositingForFixedPosition(bool enabled, ExceptionCode& ec)
200 {
201     InternalSettingsGuardForSettings();
202     settings()->setAcceleratedCompositingForFixedPositionEnabled(enabled);
203 }
204
205 void InternalSettings::setEnableCompositingForScrollableFrames(bool enabled, ExceptionCode& ec)
206 {
207     InternalSettingsGuardForSettings();
208     settings()->setAcceleratedCompositingForScrollableFramesEnabled(enabled);
209 }
210
211 void InternalSettings::setAcceleratedDrawingEnabled(bool enabled, ExceptionCode& ec)
212 {
213     InternalSettingsGuardForSettings();
214     settings()->setAcceleratedDrawingEnabled(enabled);
215 }
216
217 void InternalSettings::setMockScrollbarsEnabled(bool enabled, ExceptionCode& ec)
218 {
219     InternalSettingsGuardForSettings();
220     settings()->setMockScrollbarsEnabled(enabled);
221 }
222
223 void InternalSettings::setUsesOverlayScrollbars(bool flag)
224 {
225     settings()->setUsesOverlayScrollbars(flag);
226 }
227
228 void InternalSettings::setPasswordEchoEnabled(bool enabled, ExceptionCode& ec)
229 {
230     InternalSettingsGuardForSettings();
231     settings()->setPasswordEchoEnabled(enabled);
232 }
233
234 void InternalSettings::setPasswordEchoDurationInSeconds(double durationInSeconds, ExceptionCode& ec)
235 {
236     InternalSettingsGuardForSettings();
237     settings()->setPasswordEchoDurationInSeconds(durationInSeconds);
238 }
239
240 void InternalSettings::setFixedElementsLayoutRelativeToFrame(bool enabled, ExceptionCode& ec)
241 {
242     InternalSettingsGuardForSettings();
243     settings()->setFixedElementsLayoutRelativeToFrame(enabled);
244 }
245
246 void InternalSettings::setUnifiedTextCheckingEnabled(bool enabled, ExceptionCode& ec)
247 {
248     InternalSettingsGuardForSettings();
249     settings()->setUnifiedTextCheckerEnabled(enabled);
250 }
251
252 bool InternalSettings::unifiedTextCheckingEnabled(ExceptionCode& ec)
253 {
254     InternalSettingsGuardForSettingsReturn(false);
255     return settings()->unifiedTextCheckerEnabled();
256 }
257
258 void InternalSettings::setPageScaleFactor(float scaleFactor, int x, int y, ExceptionCode& ec)
259 {
260     InternalSettingsGuardForPage();
261     page()->setPageScaleFactor(scaleFactor, IntPoint(x, y));
262 }
263
264 void InternalSettings::setShadowDOMEnabled(bool enabled, ExceptionCode& ec)
265 {
266 #if ENABLE(SHADOW_DOM)
267     UNUSED_PARAM(ec);
268     RuntimeEnabledFeatures::setShadowDOMEnabled(enabled);
269 #else
270     // Even SHADOW_DOM is off, InternalSettings allows setShadowDOMEnabled(false) to
271     // have broader test coverage. But it cannot be setShadowDOMEnabled(true).
272     if (enabled)
273         ec = INVALID_ACCESS_ERR;
274 #endif
275 }
276
277 void InternalSettings::setAuthorShadowDOMForAnyElementEnabled(bool isEnabled)
278 {
279 #if ENABLE(SHADOW_DOM)
280     RuntimeEnabledFeatures::setAuthorShadowDOMForAnyElementEnabled(isEnabled);
281 #else
282     UNUSED_PARAM(isEnabled);
283 #endif
284 }
285
286 void InternalSettings::setStyleScopedEnabled(bool enabled)
287 {
288 #if ENABLE(STYLE_SCOPED)
289     RuntimeEnabledFeatures::setStyleScopedEnabled(enabled);
290 #else
291     UNUSED_PARAM(enabled);
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::setResolutionOverride(int dotsPerCSSInchHorizontally, int dotsPerCSSInchVertically, ExceptionCode& ec)
392 {
393     InternalSettingsGuardForSettings();
394     // An empty size resets the override.
395     settings()->setResolutionOverride(IntSize(dotsPerCSSInchHorizontally, dotsPerCSSInchVertically));
396 }
397
398 void InternalSettings::setMediaTypeOverride(const String& mediaType, ExceptionCode& ec)
399 {
400     InternalSettingsGuardForSettings();
401     settings()->setMediaTypeOverride(mediaType);
402 }
403
404 void InternalSettings::setTextAutosizingFontScaleFactor(float fontScaleFactor, ExceptionCode& ec)
405 {
406 #if ENABLE(TEXT_AUTOSIZING)
407     InternalSettingsGuardForSettings();
408     settings()->setTextAutosizingFontScaleFactor(fontScaleFactor);
409 #else
410     UNUSED_PARAM(fontScaleFactor);
411     UNUSED_PARAM(ec);
412 #endif
413 }
414
415 void InternalSettings::setEnableScrollAnimator(bool enabled, ExceptionCode& ec)
416 {
417 #if ENABLE(SMOOTH_SCROLLING)
418     InternalSettingsGuardForSettings();
419     settings()->setEnableScrollAnimator(enabled);
420 #else
421     UNUSED_PARAM(enabled);
422     UNUSED_PARAM(ec);
423 #endif
424 }
425
426 bool InternalSettings::scrollAnimatorEnabled(ExceptionCode& ec)
427 {
428 #if ENABLE(SMOOTH_SCROLLING)
429     InternalSettingsGuardForSettingsReturn(false);
430     return settings()->scrollAnimatorEnabled();
431 #else
432     UNUSED_PARAM(ec);
433     return false;
434 #endif
435 }
436
437 void InternalSettings::setCSSExclusionsEnabled(bool enabled, ExceptionCode& ec)
438 {
439     UNUSED_PARAM(ec);
440     RuntimeEnabledFeatures::setCSSExclusionsEnabled(enabled);
441 }
442
443 void InternalSettings::setCSSVariablesEnabled(bool enabled, ExceptionCode& ec)
444 {
445     InternalSettingsGuardForSettings();
446     settings()->setCSSVariablesEnabled(enabled);
447 }
448
449 bool InternalSettings::cssVariablesEnabled(ExceptionCode& ec)
450 {
451     InternalSettingsGuardForSettingsReturn(false);
452     return settings()->cssVariablesEnabled();
453 }
454
455 void InternalSettings::setCanStartMedia(bool enabled, ExceptionCode& ec)
456 {
457     InternalSettingsGuardForSettings();
458     m_page->setCanStartMedia(enabled);
459 }
460
461 void InternalSettings::setMediaPlaybackRequiresUserGesture(bool enabled, ExceptionCode& ec)
462 {
463     InternalSettingsGuardForSettings();
464     settings()->setMediaPlaybackRequiresUserGesture(enabled);
465 }
466
467 void InternalSettings::setEditingBehavior(const String& editingBehavior, ExceptionCode& ec)
468 {
469     InternalSettingsGuardForSettings();
470     if (equalIgnoringCase(editingBehavior, "win"))
471         settings()->setEditingBehaviorType(EditingWindowsBehavior);
472     else if (equalIgnoringCase(editingBehavior, "mac"))
473         settings()->setEditingBehaviorType(EditingMacBehavior);
474     else if (equalIgnoringCase(editingBehavior, "unix"))
475         settings()->setEditingBehaviorType(EditingUnixBehavior);
476     else
477         ec = SYNTAX_ERR;
478 }
479
480 void InternalSettings::setFixedPositionCreatesStackingContext(bool creates, ExceptionCode& ec)
481 {
482     InternalSettingsGuardForSettings();
483     settings()->setFixedPositionCreatesStackingContext(creates);
484 }
485
486 void InternalSettings::setSyncXHRInDocumentsEnabled(bool enabled, ExceptionCode& ec)
487 {
488     InternalSettingsGuardForSettings();
489     settings()->setSyncXHRInDocumentsEnabled(enabled);
490 }
491
492 void InternalSettings::setWindowFocusRestricted(bool restricted, ExceptionCode& ec)
493 {
494     InternalSettingsGuardForSettings();
495     settings()->setWindowFocusRestricted(restricted);
496 }
497
498 void InternalSettings::setDialogElementEnabled(bool enabled, ExceptionCode& ec)
499 {
500     UNUSED_PARAM(ec);
501 #if ENABLE(DIALOG_ELEMENT)
502     RuntimeEnabledFeatures::setDialogElementEnabled(enabled);
503 #else
504     UNUSED_PARAM(enabled);
505 #endif
506 }
507
508 void InternalSettings::allowRoundingHacks() const
509 {
510     TextRun::setAllowsRoundingHacks(true);
511 }
512
513 Vector<String> InternalSettings::userPreferredLanguages() const
514 {
515     return WebCore::userPreferredLanguages();
516 }
517
518 void InternalSettings::setUserPreferredLanguages(const Vector<String>& languages)
519 {
520     WebCore::overrideUserPreferredLanguages(languages);
521 }
522
523 void InternalSettings::setShouldDisplayTrackKind(const String& kind, bool enabled, ExceptionCode& ec)
524 {
525     InternalSettingsGuardForSettings();
526
527 #if ENABLE(VIDEO_TRACK)
528     if (equalIgnoringCase(kind, "Subtitles"))
529         settings()->setShouldDisplaySubtitles(enabled);
530     else if (equalIgnoringCase(kind, "Captions"))
531         settings()->setShouldDisplayCaptions(enabled);
532     else if (equalIgnoringCase(kind, "TextDescriptions"))
533         settings()->setShouldDisplayTextDescriptions(enabled);
534     else
535         ec = SYNTAX_ERR;
536 #else
537     UNUSED_PARAM(kind);
538     UNUSED_PARAM(enabled);
539 #endif
540 }
541
542 bool InternalSettings::shouldDisplayTrackKind(const String& kind, ExceptionCode& ec)
543 {
544     InternalSettingsGuardForSettingsReturn(false);
545
546 #if ENABLE(VIDEO_TRACK)
547     if (equalIgnoringCase(kind, "Subtitles"))
548         return settings()->shouldDisplaySubtitles();
549     if (equalIgnoringCase(kind, "Captions"))
550         return settings()->shouldDisplayCaptions();
551     if (equalIgnoringCase(kind, "TextDescriptions"))
552         return settings()->shouldDisplayTextDescriptions();
553
554     ec = SYNTAX_ERR;
555     return false;
556 #else
557     UNUSED_PARAM(kind);
558     return false;
559 #endif
560 }
561
562 void InternalSettings::setPagination(const String& mode, int gap, int pageLength, ExceptionCode& ec)
563 {
564     if (!page()) {
565         ec = INVALID_ACCESS_ERR;
566         return;
567     }
568
569     Pagination pagination;
570     if (mode == "Unpaginated")
571         pagination.mode = Pagination::Unpaginated;
572     else if (mode == "LeftToRightPaginated")
573         pagination.mode = Pagination::LeftToRightPaginated;
574     else if (mode == "RightToLeftPaginated")
575         pagination.mode = Pagination::RightToLeftPaginated;
576     else if (mode == "TopToBottomPaginated")
577         pagination.mode = Pagination::TopToBottomPaginated;
578     else if (mode == "BottomToTopPaginated")
579         pagination.mode = Pagination::BottomToTopPaginated;
580     else {
581         ec = SYNTAX_ERR;
582         return;
583     }
584
585     pagination.gap = gap;
586     pagination.pageLength = pageLength;
587     page()->setPagination(pagination);
588 }
589
590 void InternalSettings::setEnableMockPagePopup(bool enabled, ExceptionCode& ec)
591 {
592 #if ENABLE(PAGE_POPUP)
593     InternalSettingsGuardForPage();
594     if (!page()->chrome())
595         return;
596     if (!enabled) {
597         page()->chrome()->client()->resetPagePopupDriver();
598         return;
599     }
600     if (!m_pagePopupDriver)
601         m_pagePopupDriver = MockPagePopupDriver::create(page()->mainFrame());
602     page()->chrome()->client()->setPagePopupDriver(m_pagePopupDriver.get());
603 #else
604     UNUSED_PARAM(enabled);
605     UNUSED_PARAM(ec);
606 #endif
607 }
608
609 String InternalSettings::configurationForViewport(float devicePixelRatio, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight, ExceptionCode& ec)
610 {
611     if (!page()) {
612         ec = INVALID_ACCESS_ERR;
613         return String();
614     }
615
616     const int defaultLayoutWidthForNonMobilePages = 980;
617
618     ViewportArguments arguments = page()->viewportArguments();
619     ViewportAttributes attributes = computeViewportAttributes(arguments, defaultLayoutWidthForNonMobilePages, deviceWidth, deviceHeight, devicePixelRatio, IntSize(availableWidth, availableHeight));
620     restrictMinimumScaleFactorToViewportSize(attributes, IntSize(availableWidth, availableHeight), devicePixelRatio);
621     restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
622
623     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");
624 }
625
626 void InternalSettings::setMemoryInfoEnabled(bool enabled, ExceptionCode& ec)
627 {
628     InternalSettingsGuardForSettings();
629     settings()->setMemoryInfoEnabled(enabled);
630 }
631
632 void InternalSettings::setStorageBlockingPolicy(const String& mode, ExceptionCode& ec)
633 {
634     InternalSettingsGuardForSettings();
635
636     if (mode == "AllowAll")
637         settings()->setStorageBlockingPolicy(SecurityOrigin::AllowAllStorage);
638     else if (mode == "BlockThirdParty")
639         settings()->setStorageBlockingPolicy(SecurityOrigin::BlockThirdPartyStorage);
640     else if (mode == "BlockAll")
641         settings()->setStorageBlockingPolicy(SecurityOrigin::BlockAllStorage);
642     else
643         ec = SYNTAX_ERR;
644 }
645
646 void InternalSettings::setLangAttributeAwareFormControlUIEnabled(bool enabled)
647 {
648     RuntimeEnabledFeatures::setLangAttributeAwareFormControlUIEnabled(enabled);
649 }
650
651 void InternalSettings::setImagesEnabled(bool enabled, ExceptionCode& ec)
652 {
653     InternalSettingsGuardForSettings();
654     settings()->setImagesEnabled(enabled);
655 }
656
657 }