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