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