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