• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2009, 2011 Apple 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  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "Settings.h"
28 
29 #include "BackForwardController.h"
30 #include "CachedResourceLoader.h"
31 #include "CookieStorage.h"
32 #include "DOMTimer.h"
33 #include "Database.h"
34 #include "Frame.h"
35 #include "FrameTree.h"
36 #include "FrameView.h"
37 #include "HistoryItem.h"
38 #include "Page.h"
39 #include "PageCache.h"
40 #include "ResourceHandle.h"
41 #include "StorageMap.h"
42 #include <limits>
43 
44 using namespace std;
45 
46 namespace WebCore {
47 
setLoadsImagesAutomaticallyInAllFrames(Page * page)48 static void setLoadsImagesAutomaticallyInAllFrames(Page* page)
49 {
50     for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext())
51         frame->document()->cachedResourceLoader()->setAutoLoadImages(page->settings()->loadsImagesAutomatically());
52 }
53 
54 #if USE(SAFARI_THEME)
55 bool Settings::gShouldPaintNativeControls = true;
56 #endif
57 
58 #if PLATFORM(WIN) || (OS(WINDOWS) && PLATFORM(WX))
59 bool Settings::gShouldUseHighResolutionTimers = true;
60 #endif
61 
62 // NOTEs
63 //  1) EditingMacBehavior comprises Tiger, Leopard, SnowLeopard and iOS builds, as well QtWebKit and Chromium when built on Mac;
64 //  2) EditingWindowsBehavior comprises Win32 and WinCE builds, as well as QtWebKit and Chromium when built on Windows;
65 //  3) EditingUnixBehavior comprises all unix-based systems, but Darwin/MacOS (and then abusing the terminology);
66 // 99) MacEditingBehavior is used a fallback.
editingBehaviorTypeForPlatform()67 static EditingBehaviorType editingBehaviorTypeForPlatform()
68 {
69     return
70 #if OS(DARWIN)
71     EditingMacBehavior
72 #elif OS(WINDOWS)
73     EditingWindowsBehavior
74 #elif OS(UNIX)
75     EditingUnixBehavior
76 #else
77     // Fallback
78     EditingMacBehavior
79 #endif
80     ;
81 }
82 
Settings(Page * page)83 Settings::Settings(Page* page)
84     : m_page(page)
85     , m_editableLinkBehavior(EditableLinkDefaultBehavior)
86     , m_textDirectionSubmenuInclusionBehavior(TextDirectionSubmenuAutomaticallyIncluded)
87     , m_minimumFontSize(0)
88     , m_minimumLogicalFontSize(0)
89     , m_defaultFontSize(0)
90     , m_defaultFixedFontSize(0)
91     , m_validationMessageTimerMagnification(50)
92     , m_maximumDecodedImageSize(numeric_limits<size_t>::max())
93 #if ENABLE(DOM_STORAGE)
94     , m_sessionStorageQuota(StorageMap::noQuota)
95 #endif
96     , m_pluginAllowedRunTime(numeric_limits<unsigned>::max())
97     , m_editingBehaviorType(editingBehaviorTypeForPlatform())
98 #ifdef ANDROID_LAYOUT
99     , m_layoutAlgorithm(kLayoutFitColumnToScreen)
100 #endif
101     , m_isSpatialNavigationEnabled(false)
102     , m_isJavaEnabled(false)
103     , m_loadsImagesAutomatically(false)
104     , m_loadsSiteIconsIgnoringImageLoadingSetting(false)
105     , m_privateBrowsingEnabled(false)
106     , m_caretBrowsingEnabled(false)
107     , m_areImagesEnabled(true)
108     , m_isMediaEnabled(true)
109     , m_arePluginsEnabled(false)
110     , m_localStorageEnabled(false)
111     , m_isJavaScriptEnabled(false)
112     , m_isWebSecurityEnabled(true)
113     , m_allowUniversalAccessFromFileURLs(true)
114     , m_allowFileAccessFromFileURLs(true)
115     , m_javaScriptCanOpenWindowsAutomatically(false)
116     , m_javaScriptCanAccessClipboard(false)
117     , m_shouldPrintBackgrounds(false)
118     , m_textAreasAreResizable(false)
119 #if ENABLE(DASHBOARD_SUPPORT)
120     , m_usesDashboardBackwardCompatibilityMode(false)
121 #endif
122     , m_needsAdobeFrameReloadingQuirk(false)
123     , m_needsKeyboardEventDisambiguationQuirks(false)
124     , m_treatsAnyTextCSSLinkAsStylesheet(false)
125     , m_needsLeopardMailQuirks(false)
126     , m_needsTigerMailQuirks(false)
127     , m_isDOMPasteAllowed(false)
128     , m_shrinksStandaloneImagesToFit(true)
129     , m_usesPageCache(false)
130     , m_showsURLsInToolTips(false)
131     , m_forceFTPDirectoryListings(false)
132     , m_developerExtrasEnabled(false)
133     , m_authorAndUserStylesEnabled(true)
134     , m_needsSiteSpecificQuirks(false)
135     , m_fontRenderingMode(0)
136     , m_frameFlatteningEnabled(false)
137     , m_webArchiveDebugModeEnabled(false)
138     , m_localFileContentSniffingEnabled(false)
139     , m_inApplicationChromeMode(false)
140     , m_offlineWebApplicationCacheEnabled(false)
141     , m_shouldPaintCustomScrollbars(false)
142     , m_enforceCSSMIMETypeInNoQuirksMode(true)
143     , m_usesEncodingDetector(false)
144     , m_allowScriptsToCloseWindows(false)
145     , m_canvasUsesAcceleratedDrawing(false)
146     , m_acceleratedDrawingEnabled(false)
147     // FIXME: This should really be disabled by default as it makes platforms that don't support the feature download files
148     // they can't use by. Leaving enabled for now to not change existing behavior.
149     , m_downloadableBinaryFontsEnabled(true)
150     , m_xssAuditorEnabled(false)
151     , m_acceleratedCompositingEnabled(true)
152     , m_acceleratedCompositingFor3DTransformsEnabled(true)
153     , m_acceleratedCompositingForVideoEnabled(true)
154     , m_acceleratedCompositingForPluginsEnabled(true)
155     , m_acceleratedCompositingForCanvasEnabled(true)
156     , m_acceleratedCompositingForAnimationEnabled(true)
157     , m_showDebugBorders(false)
158     , m_showRepaintCounter(false)
159     , m_experimentalNotificationsEnabled(false)
160     , m_webGLEnabled(false)
161     , m_openGLMultisamplingEnabled(true)
162     , m_webAudioEnabled(false)
163     , m_acceleratedCanvas2dEnabled(false)
164     , m_loadDeferringEnabled(true)
165     , m_tiledBackingStoreEnabled(false)
166     , m_paginateDuringLayoutEnabled(false)
167     , m_dnsPrefetchingEnabled(true)
168 #if ENABLE(FULLSCREEN_API)
169     , m_fullScreenAPIEnabled(false)
170 #endif
171     , m_asynchronousSpellCheckingEnabled(false)
172     , m_memoryInfoEnabled(false)
173     , m_interactiveFormValidation(false)
174     , m_usePreHTML5ParserQuirks(false)
175     , m_hyperlinkAuditingEnabled(false)
176     , m_crossOriginCheckInGetMatchedCSSRulesDisabled(false)
177     , m_useQuickLookResourceCachingQuirks(false)
178     , m_forceCompositingMode(false)
179     , m_shouldInjectUserScriptsInInitialEmptyDocument(false)
180 #ifdef ANDROID_LAYOUT
181     , m_useWideViewport(false)
182 #endif
183 #ifdef ANDROID_MULTIPLE_WINDOWS
184     , m_supportMultipleWindows(true)
185 #endif
186 #ifdef ANDROID_BLOCK_NETWORK_IMAGE
187     , m_blockNetworkImage(false)
188 #endif
189 #if ENABLE(WEB_AUTOFILL)
190     , m_autoFillEnabled(false)
191 #endif
192 #ifdef ANDROID_PLUGINS
193     , m_pluginsOnDemand(false)
194 #endif
195 {
196     // A Frame may not have been created yet, so we initialize the AtomicString
197     // hash before trying to use it.
198     AtomicString::init();
199 #ifdef ANDROID_META_SUPPORT
200     m_default_format_detection = true;
201     resetMetadataSettings();
202 #endif
203 }
204 
setStandardFontFamily(const AtomicString & standardFontFamily)205 void Settings::setStandardFontFamily(const AtomicString& standardFontFamily)
206 {
207     if (standardFontFamily == m_standardFontFamily)
208         return;
209 
210     m_standardFontFamily = standardFontFamily;
211     m_page->setNeedsRecalcStyleInAllFrames();
212 }
213 
setFixedFontFamily(const AtomicString & fixedFontFamily)214 void Settings::setFixedFontFamily(const AtomicString& fixedFontFamily)
215 {
216     if (m_fixedFontFamily == fixedFontFamily)
217         return;
218 
219     m_fixedFontFamily = fixedFontFamily;
220     m_page->setNeedsRecalcStyleInAllFrames();
221 }
222 
setSerifFontFamily(const AtomicString & serifFontFamily)223 void Settings::setSerifFontFamily(const AtomicString& serifFontFamily)
224 {
225     if (m_serifFontFamily == serifFontFamily)
226         return;
227 
228     m_serifFontFamily = serifFontFamily;
229     m_page->setNeedsRecalcStyleInAllFrames();
230 }
231 
setSansSerifFontFamily(const AtomicString & sansSerifFontFamily)232 void Settings::setSansSerifFontFamily(const AtomicString& sansSerifFontFamily)
233 {
234     if (m_sansSerifFontFamily == sansSerifFontFamily)
235         return;
236 
237     m_sansSerifFontFamily = sansSerifFontFamily;
238     m_page->setNeedsRecalcStyleInAllFrames();
239 }
240 
setCursiveFontFamily(const AtomicString & cursiveFontFamily)241 void Settings::setCursiveFontFamily(const AtomicString& cursiveFontFamily)
242 {
243     if (m_cursiveFontFamily == cursiveFontFamily)
244         return;
245 
246     m_cursiveFontFamily = cursiveFontFamily;
247     m_page->setNeedsRecalcStyleInAllFrames();
248 }
249 
setFantasyFontFamily(const AtomicString & fantasyFontFamily)250 void Settings::setFantasyFontFamily(const AtomicString& fantasyFontFamily)
251 {
252     if (m_fantasyFontFamily == fantasyFontFamily)
253         return;
254 
255     m_fantasyFontFamily = fantasyFontFamily;
256     m_page->setNeedsRecalcStyleInAllFrames();
257 }
258 
setMinimumFontSize(int minimumFontSize)259 void Settings::setMinimumFontSize(int minimumFontSize)
260 {
261     if (m_minimumFontSize == minimumFontSize)
262         return;
263 
264     m_minimumFontSize = minimumFontSize;
265     m_page->setNeedsRecalcStyleInAllFrames();
266 }
267 
setMinimumLogicalFontSize(int minimumLogicalFontSize)268 void Settings::setMinimumLogicalFontSize(int minimumLogicalFontSize)
269 {
270     if (m_minimumLogicalFontSize == minimumLogicalFontSize)
271         return;
272 
273     m_minimumLogicalFontSize = minimumLogicalFontSize;
274     m_page->setNeedsRecalcStyleInAllFrames();
275 }
276 
setDefaultFontSize(int defaultFontSize)277 void Settings::setDefaultFontSize(int defaultFontSize)
278 {
279     if (m_defaultFontSize == defaultFontSize)
280         return;
281 
282     m_defaultFontSize = defaultFontSize;
283     m_page->setNeedsRecalcStyleInAllFrames();
284 }
285 
setDefaultFixedFontSize(int defaultFontSize)286 void Settings::setDefaultFixedFontSize(int defaultFontSize)
287 {
288     if (m_defaultFixedFontSize == defaultFontSize)
289         return;
290 
291     m_defaultFixedFontSize = defaultFontSize;
292     m_page->setNeedsRecalcStyleInAllFrames();
293 }
294 
295 #ifdef ANDROID_BLOCK_NETWORK_IMAGE
setBlockNetworkImage(bool blockNetworkImage)296 void Settings::setBlockNetworkImage(bool blockNetworkImage)
297 {
298     m_blockNetworkImage = blockNetworkImage;
299 }
300 #endif
301 
setLoadsImagesAutomatically(bool loadsImagesAutomatically)302 void Settings::setLoadsImagesAutomatically(bool loadsImagesAutomatically)
303 {
304     m_loadsImagesAutomatically = loadsImagesAutomatically;
305     setLoadsImagesAutomaticallyInAllFrames(m_page);
306 }
307 
setLoadsSiteIconsIgnoringImageLoadingSetting(bool loadsSiteIcons)308 void Settings::setLoadsSiteIconsIgnoringImageLoadingSetting(bool loadsSiteIcons)
309 {
310     m_loadsSiteIconsIgnoringImageLoadingSetting = loadsSiteIcons;
311 }
312 
setJavaScriptEnabled(bool isJavaScriptEnabled)313 void Settings::setJavaScriptEnabled(bool isJavaScriptEnabled)
314 {
315     m_isJavaScriptEnabled = isJavaScriptEnabled;
316 }
317 
setWebSecurityEnabled(bool isWebSecurityEnabled)318 void Settings::setWebSecurityEnabled(bool isWebSecurityEnabled)
319 {
320     m_isWebSecurityEnabled = isWebSecurityEnabled;
321 }
322 
setAllowUniversalAccessFromFileURLs(bool allowUniversalAccessFromFileURLs)323 void Settings::setAllowUniversalAccessFromFileURLs(bool allowUniversalAccessFromFileURLs)
324 {
325     m_allowUniversalAccessFromFileURLs = allowUniversalAccessFromFileURLs;
326 }
327 
setAllowFileAccessFromFileURLs(bool allowFileAccessFromFileURLs)328 void Settings::setAllowFileAccessFromFileURLs(bool allowFileAccessFromFileURLs)
329 {
330     m_allowFileAccessFromFileURLs = allowFileAccessFromFileURLs;
331 }
332 
setSpatialNavigationEnabled(bool isSpatialNavigationEnabled)333 void Settings::setSpatialNavigationEnabled(bool isSpatialNavigationEnabled)
334 {
335     m_isSpatialNavigationEnabled = isSpatialNavigationEnabled;
336 }
337 
setJavaEnabled(bool isJavaEnabled)338 void Settings::setJavaEnabled(bool isJavaEnabled)
339 {
340     m_isJavaEnabled = isJavaEnabled;
341 }
342 
setImagesEnabled(bool areImagesEnabled)343 void Settings::setImagesEnabled(bool areImagesEnabled)
344 {
345     m_areImagesEnabled = areImagesEnabled;
346 }
347 
setMediaEnabled(bool isMediaEnabled)348 void Settings::setMediaEnabled(bool isMediaEnabled)
349 {
350     m_isMediaEnabled = isMediaEnabled;
351 }
352 
setPluginsEnabled(bool arePluginsEnabled)353 void Settings::setPluginsEnabled(bool arePluginsEnabled)
354 {
355     m_arePluginsEnabled = arePluginsEnabled;
356 }
357 
setLocalStorageEnabled(bool localStorageEnabled)358 void Settings::setLocalStorageEnabled(bool localStorageEnabled)
359 {
360     m_localStorageEnabled = localStorageEnabled;
361 }
362 
363 #if ENABLE(DOM_STORAGE)
setSessionStorageQuota(unsigned sessionStorageQuota)364 void Settings::setSessionStorageQuota(unsigned sessionStorageQuota)
365 {
366     m_sessionStorageQuota = sessionStorageQuota;
367 }
368 #endif
369 
setPrivateBrowsingEnabled(bool privateBrowsingEnabled)370 void Settings::setPrivateBrowsingEnabled(bool privateBrowsingEnabled)
371 {
372     if (m_privateBrowsingEnabled == privateBrowsingEnabled)
373         return;
374 
375 #if USE(CFURLSTORAGESESSIONS)
376     ResourceHandle::setPrivateBrowsingEnabled(privateBrowsingEnabled);
377 #endif
378 
379     // FIXME: We can only enable cookie private browsing mode globally, so it's misleading to have it as a per-page setting.
380     setCookieStoragePrivateBrowsingEnabled(privateBrowsingEnabled);
381 
382     m_privateBrowsingEnabled = privateBrowsingEnabled;
383     m_page->privateBrowsingStateChanged();
384 }
385 
setJavaScriptCanOpenWindowsAutomatically(bool javaScriptCanOpenWindowsAutomatically)386 void Settings::setJavaScriptCanOpenWindowsAutomatically(bool javaScriptCanOpenWindowsAutomatically)
387 {
388     m_javaScriptCanOpenWindowsAutomatically = javaScriptCanOpenWindowsAutomatically;
389 }
390 
setJavaScriptCanAccessClipboard(bool javaScriptCanAccessClipboard)391 void Settings::setJavaScriptCanAccessClipboard(bool javaScriptCanAccessClipboard)
392 {
393     m_javaScriptCanAccessClipboard = javaScriptCanAccessClipboard;
394 }
395 
setDefaultTextEncodingName(const String & defaultTextEncodingName)396 void Settings::setDefaultTextEncodingName(const String& defaultTextEncodingName)
397 {
398     m_defaultTextEncodingName = defaultTextEncodingName;
399 }
400 
setUserStyleSheetLocation(const KURL & userStyleSheetLocation)401 void Settings::setUserStyleSheetLocation(const KURL& userStyleSheetLocation)
402 {
403     if (m_userStyleSheetLocation == userStyleSheetLocation)
404         return;
405 
406     m_userStyleSheetLocation = userStyleSheetLocation;
407 
408     m_page->userStyleSheetLocationChanged();
409 }
410 
setShouldPrintBackgrounds(bool shouldPrintBackgrounds)411 void Settings::setShouldPrintBackgrounds(bool shouldPrintBackgrounds)
412 {
413     m_shouldPrintBackgrounds = shouldPrintBackgrounds;
414 }
415 
setTextAreasAreResizable(bool textAreasAreResizable)416 void Settings::setTextAreasAreResizable(bool textAreasAreResizable)
417 {
418     if (m_textAreasAreResizable == textAreasAreResizable)
419         return;
420 
421     m_textAreasAreResizable = textAreasAreResizable;
422     m_page->setNeedsRecalcStyleInAllFrames();
423 }
424 
setEditableLinkBehavior(EditableLinkBehavior editableLinkBehavior)425 void Settings::setEditableLinkBehavior(EditableLinkBehavior editableLinkBehavior)
426 {
427     m_editableLinkBehavior = editableLinkBehavior;
428 }
429 
setTextDirectionSubmenuInclusionBehavior(TextDirectionSubmenuInclusionBehavior behavior)430 void Settings::setTextDirectionSubmenuInclusionBehavior(TextDirectionSubmenuInclusionBehavior behavior)
431 {
432     m_textDirectionSubmenuInclusionBehavior = behavior;
433 }
434 
435 #if ENABLE(DASHBOARD_SUPPORT)
setUsesDashboardBackwardCompatibilityMode(bool usesDashboardBackwardCompatibilityMode)436 void Settings::setUsesDashboardBackwardCompatibilityMode(bool usesDashboardBackwardCompatibilityMode)
437 {
438     m_usesDashboardBackwardCompatibilityMode = usesDashboardBackwardCompatibilityMode;
439 }
440 #endif
441 
442 // FIXME: This quirk is needed because of Radar 4674537 and 5211271. We need to phase it out once Adobe
443 // can fix the bug from their end.
setNeedsAdobeFrameReloadingQuirk(bool shouldNotReloadIFramesForUnchangedSRC)444 void Settings::setNeedsAdobeFrameReloadingQuirk(bool shouldNotReloadIFramesForUnchangedSRC)
445 {
446     m_needsAdobeFrameReloadingQuirk = shouldNotReloadIFramesForUnchangedSRC;
447 }
448 
449 // This is a quirk we are pro-actively applying to old applications. It changes keyboard event dispatching,
450 // making keyIdentifier available on keypress events, making charCode available on keydown/keyup events,
451 // and getting keypress dispatched in more cases.
setNeedsKeyboardEventDisambiguationQuirks(bool needsQuirks)452 void Settings::setNeedsKeyboardEventDisambiguationQuirks(bool needsQuirks)
453 {
454     m_needsKeyboardEventDisambiguationQuirks = needsQuirks;
455 }
456 
setTreatsAnyTextCSSLinkAsStylesheet(bool treatsAnyTextCSSLinkAsStylesheet)457 void Settings::setTreatsAnyTextCSSLinkAsStylesheet(bool treatsAnyTextCSSLinkAsStylesheet)
458 {
459     m_treatsAnyTextCSSLinkAsStylesheet = treatsAnyTextCSSLinkAsStylesheet;
460 }
461 
setNeedsLeopardMailQuirks(bool needsQuirks)462 void Settings::setNeedsLeopardMailQuirks(bool needsQuirks)
463 {
464     m_needsLeopardMailQuirks = needsQuirks;
465 }
466 
setNeedsTigerMailQuirks(bool needsQuirks)467 void Settings::setNeedsTigerMailQuirks(bool needsQuirks)
468 {
469     m_needsTigerMailQuirks = needsQuirks;
470 }
471 
setDOMPasteAllowed(bool DOMPasteAllowed)472 void Settings::setDOMPasteAllowed(bool DOMPasteAllowed)
473 {
474     m_isDOMPasteAllowed = DOMPasteAllowed;
475 }
476 
setDefaultMinDOMTimerInterval(double interval)477 void Settings::setDefaultMinDOMTimerInterval(double interval)
478 {
479     DOMTimer::setDefaultMinTimerInterval(interval);
480 }
481 
defaultMinDOMTimerInterval()482 double Settings::defaultMinDOMTimerInterval()
483 {
484     return DOMTimer::defaultMinTimerInterval();
485 }
486 
setMinDOMTimerInterval(double interval)487 void Settings::setMinDOMTimerInterval(double interval)
488 {
489     m_page->setMinimumTimerInterval(interval);
490 }
491 
minDOMTimerInterval()492 double Settings::minDOMTimerInterval()
493 {
494     return m_page->minimumTimerInterval();
495 }
496 
setUsesPageCache(bool usesPageCache)497 void Settings::setUsesPageCache(bool usesPageCache)
498 {
499     if (m_usesPageCache == usesPageCache)
500         return;
501 
502     m_usesPageCache = usesPageCache;
503     if (!m_usesPageCache) {
504         int first = -m_page->backForward()->backCount();
505         int last = m_page->backForward()->forwardCount();
506         for (int i = first; i <= last; i++)
507             pageCache()->remove(m_page->backForward()->itemAtIndex(i));
508         pageCache()->releaseAutoreleasedPagesNow();
509     }
510 }
511 
setShrinksStandaloneImagesToFit(bool shrinksStandaloneImagesToFit)512 void Settings::setShrinksStandaloneImagesToFit(bool shrinksStandaloneImagesToFit)
513 {
514     m_shrinksStandaloneImagesToFit = shrinksStandaloneImagesToFit;
515 }
516 
setShowsURLsInToolTips(bool showsURLsInToolTips)517 void Settings::setShowsURLsInToolTips(bool showsURLsInToolTips)
518 {
519     m_showsURLsInToolTips = showsURLsInToolTips;
520 }
521 
setFTPDirectoryTemplatePath(const String & path)522 void Settings::setFTPDirectoryTemplatePath(const String& path)
523 {
524     m_ftpDirectoryTemplatePath = path;
525 }
526 
setForceFTPDirectoryListings(bool force)527 void Settings::setForceFTPDirectoryListings(bool force)
528 {
529     m_forceFTPDirectoryListings = force;
530 }
531 
setDeveloperExtrasEnabled(bool developerExtrasEnabled)532 void Settings::setDeveloperExtrasEnabled(bool developerExtrasEnabled)
533 {
534     m_developerExtrasEnabled = developerExtrasEnabled;
535 }
536 
537 #ifdef ANDROID_META_SUPPORT
resetMetadataSettings()538 void Settings::resetMetadataSettings()
539 {
540     m_viewport_width = -1;
541     m_viewport_height = -1;
542     m_viewport_initial_scale = 0;
543     m_viewport_minimum_scale = 0;
544     m_viewport_maximum_scale = 0;
545     m_viewport_user_scalable = true;
546     m_viewport_target_densitydpi = -1;
547     m_format_detection_telephone = m_default_format_detection;
548     m_format_detection_address = m_default_format_detection;
549     m_format_detection_email = m_default_format_detection;
550 }
551 
setMetadataSettings(const String & key,const String & value)552 void Settings::setMetadataSettings(const String& key, const String& value)
553 {
554     if (key == "width") {
555         if (value == "device-width") {
556             m_viewport_width = 0;
557         } else {
558             int width = value.toInt();
559             if (width <= 10000) {
560                 if (width <= 320) {
561                     // This is a hack to accommodate the pages designed for the
562                     // original iPhone. The new version, since 10/2007, is to
563                     // use device-width which works for both portrait and
564                     // landscape modes.
565                     m_viewport_width = 0;
566                 } else {
567                     m_viewport_width = width;
568                 }
569             }
570         }
571     } else if (key == "height") {
572         if (value == "device-height") {
573             m_viewport_height = 0;
574         } else {
575             int height = value.toInt();
576             if (height >= 200 && height <= 10000) {
577                 m_viewport_height = height;
578             }
579         }
580     } else if (key == "initial-scale") {
581         int scale = int(value.toFloat() * 100);
582         if (scale >= 1 && scale <= 1000) {
583             m_viewport_initial_scale = scale;
584         }
585     } else if (key == "minimum-scale") {
586         int scale = int(value.toFloat() * 100);
587         if (scale >= 1 && scale <= 1000) {
588             m_viewport_minimum_scale = scale;
589         }
590     } else if (key == "maximum-scale") {
591         int scale = int(value.toFloat() * 100);
592         if (scale >= 1 && scale <= 1000) {
593             m_viewport_maximum_scale = scale;
594         }
595     } else if (key == "user-scalable") {
596         // even Apple doc says using "no", "0" is common in the real world, and
597         // some sites, e.g. gomoviesapp.com, use "false".
598         if (value == "no" || value == "0" || value == "false") {
599             m_viewport_user_scalable = false;
600         }
601     } else if (key == "target-densitydpi") {
602         if (value == "device-dpi") {
603             m_viewport_target_densitydpi = 0;
604         } else if (value == "low-dpi") {
605             m_viewport_target_densitydpi = 120;
606         } else if (value == "medium-dpi") {
607             m_viewport_target_densitydpi = 160;
608         } else if (value == "high-dpi") {
609             m_viewport_target_densitydpi = 240;
610         } else {
611             int dpi = value.toInt();
612             if (dpi >= 70 && dpi <= 400) {
613                 m_viewport_target_densitydpi = dpi;
614             }
615         }
616     } else if (key == "telephone") {
617         if (value == "no") {
618             m_format_detection_telephone = false;
619         }
620     } else if (key == "address") {
621         if (value == "no") {
622             m_format_detection_address = false;
623         }
624     } else if (key == "email") {
625         if (value == "no") {
626             m_format_detection_email = false;
627         }
628     } else if (key == "format-detection") {
629         // even Apple doc says "format-detection" should be the name of the
630         // <meta> tag. In the real world, e.g. amazon.com, use
631         // "format-detection=no" in the "viewport" <meta> tag to disable all
632         // format detection.
633         if (value == "no") {
634             m_format_detection_telephone = false;
635             m_format_detection_address = false;
636             m_format_detection_email = false;
637         }
638     }
639 }
640 
setViewportWidth(int width)641 void Settings::setViewportWidth(int width)
642 {
643     if (width < 0 || width > 10000)
644         m_viewport_width = -1;
645     else
646         m_viewport_width = width;
647 }
648 
setViewportHeight(int height)649 void Settings::setViewportHeight(int height)
650 {
651     if (height < 0 || height > 10000)
652         m_viewport_height = -1;
653     else
654         m_viewport_height = height;
655 }
656 
setViewportInitialScale(int scale)657 void Settings::setViewportInitialScale(int scale)
658 {
659     if (scale < 1 || scale > 1000)
660         m_viewport_initial_scale = 0;
661     else
662         m_viewport_initial_scale = scale;
663 }
664 
setViewportMinimumScale(int scale)665 void Settings::setViewportMinimumScale(int scale)
666 {
667     if (scale < 1 || scale > 1000)
668         m_viewport_minimum_scale = 0;
669     else
670         m_viewport_minimum_scale = scale;
671 }
672 
setViewportMaximumScale(int scale)673 void Settings::setViewportMaximumScale(int scale)
674 {
675     if (scale < 1 || scale > 1000)
676         m_viewport_maximum_scale = 0;
677     else
678         m_viewport_maximum_scale = scale;
679 }
680 
setViewportUserScalable(bool scalable)681 void Settings::setViewportUserScalable(bool scalable)
682 {
683     m_viewport_user_scalable = scalable;
684 }
685 
setViewportTargetDensityDpi(int dpi)686 void Settings::setViewportTargetDensityDpi(int dpi)
687 {
688     if (dpi < 0 || dpi > 400)
689         m_viewport_target_densitydpi = -1;
690     else
691         m_viewport_target_densitydpi = dpi;
692 }
693 
setFormatDetectionAddress(bool detect)694 void Settings::setFormatDetectionAddress(bool detect)
695 {
696     m_format_detection_address = detect;
697 }
698 
setFormatDetectionEmail(bool detect)699 void Settings::setFormatDetectionEmail(bool detect)
700 {
701     m_format_detection_email = detect;
702 }
703 
setFormatDetectionTelephone(bool detect)704 void Settings::setFormatDetectionTelephone(bool detect)
705 {
706     m_format_detection_telephone = detect;
707 }
708 #endif
709 
setAuthorAndUserStylesEnabled(bool authorAndUserStylesEnabled)710 void Settings::setAuthorAndUserStylesEnabled(bool authorAndUserStylesEnabled)
711 {
712     if (m_authorAndUserStylesEnabled == authorAndUserStylesEnabled)
713         return;
714 
715     m_authorAndUserStylesEnabled = authorAndUserStylesEnabled;
716     m_page->setNeedsRecalcStyleInAllFrames();
717 }
718 
setFontRenderingMode(FontRenderingMode mode)719 void Settings::setFontRenderingMode(FontRenderingMode mode)
720 {
721     if (fontRenderingMode() == mode)
722         return;
723     m_fontRenderingMode = mode;
724     m_page->setNeedsRecalcStyleInAllFrames();
725 }
726 
fontRenderingMode() const727 FontRenderingMode Settings::fontRenderingMode() const
728 {
729     return static_cast<FontRenderingMode>(m_fontRenderingMode);
730 }
731 
setNeedsSiteSpecificQuirks(bool needsQuirks)732 void Settings::setNeedsSiteSpecificQuirks(bool needsQuirks)
733 {
734     m_needsSiteSpecificQuirks = needsQuirks;
735 }
736 
setFrameFlatteningEnabled(bool frameFlatteningEnabled)737 void Settings::setFrameFlatteningEnabled(bool frameFlatteningEnabled)
738 {
739     m_frameFlatteningEnabled = frameFlatteningEnabled;
740 }
741 
742 #if ENABLE(WEB_ARCHIVE)
setWebArchiveDebugModeEnabled(bool enabled)743 void Settings::setWebArchiveDebugModeEnabled(bool enabled)
744 {
745     m_webArchiveDebugModeEnabled = enabled;
746 }
747 #endif
748 
setLocalFileContentSniffingEnabled(bool enabled)749 void Settings::setLocalFileContentSniffingEnabled(bool enabled)
750 {
751     m_localFileContentSniffingEnabled = enabled;
752 }
753 
setLocalStorageDatabasePath(const String & path)754 void Settings::setLocalStorageDatabasePath(const String& path)
755 {
756     m_localStorageDatabasePath = path;
757 }
758 
setApplicationChromeMode(bool mode)759 void Settings::setApplicationChromeMode(bool mode)
760 {
761     m_inApplicationChromeMode = mode;
762 }
763 
setOfflineWebApplicationCacheEnabled(bool enabled)764 void Settings::setOfflineWebApplicationCacheEnabled(bool enabled)
765 {
766     m_offlineWebApplicationCacheEnabled = enabled;
767 }
768 
setShouldPaintCustomScrollbars(bool shouldPaintCustomScrollbars)769 void Settings::setShouldPaintCustomScrollbars(bool shouldPaintCustomScrollbars)
770 {
771     m_shouldPaintCustomScrollbars = shouldPaintCustomScrollbars;
772 }
773 
setEnforceCSSMIMETypeInNoQuirksMode(bool enforceCSSMIMETypeInNoQuirksMode)774 void Settings::setEnforceCSSMIMETypeInNoQuirksMode(bool enforceCSSMIMETypeInNoQuirksMode)
775 {
776     m_enforceCSSMIMETypeInNoQuirksMode = enforceCSSMIMETypeInNoQuirksMode;
777 }
778 
779 #if USE(SAFARI_THEME)
setShouldPaintNativeControls(bool shouldPaintNativeControls)780 void Settings::setShouldPaintNativeControls(bool shouldPaintNativeControls)
781 {
782     gShouldPaintNativeControls = shouldPaintNativeControls;
783 }
784 #endif
785 
setUsesEncodingDetector(bool usesEncodingDetector)786 void Settings::setUsesEncodingDetector(bool usesEncodingDetector)
787 {
788     m_usesEncodingDetector = usesEncodingDetector;
789 }
790 
setDNSPrefetchingEnabled(bool dnsPrefetchingEnabled)791 void Settings::setDNSPrefetchingEnabled(bool dnsPrefetchingEnabled)
792 {
793     if (m_dnsPrefetchingEnabled == dnsPrefetchingEnabled)
794         return;
795 
796     m_dnsPrefetchingEnabled = dnsPrefetchingEnabled;
797     m_page->dnsPrefetchingStateChanged();
798 }
799 
setAllowScriptsToCloseWindows(bool allowScriptsToCloseWindows)800 void Settings::setAllowScriptsToCloseWindows(bool allowScriptsToCloseWindows)
801 {
802     m_allowScriptsToCloseWindows = allowScriptsToCloseWindows;
803 }
804 
setCaretBrowsingEnabled(bool caretBrowsingEnabled)805 void Settings::setCaretBrowsingEnabled(bool caretBrowsingEnabled)
806 {
807     m_caretBrowsingEnabled = caretBrowsingEnabled;
808 }
809 
setDownloadableBinaryFontsEnabled(bool downloadableBinaryFontsEnabled)810 void Settings::setDownloadableBinaryFontsEnabled(bool downloadableBinaryFontsEnabled)
811 {
812     m_downloadableBinaryFontsEnabled = downloadableBinaryFontsEnabled;
813 }
814 
setXSSAuditorEnabled(bool xssAuditorEnabled)815 void Settings::setXSSAuditorEnabled(bool xssAuditorEnabled)
816 {
817     m_xssAuditorEnabled = xssAuditorEnabled;
818 }
819 
setAcceleratedCompositingEnabled(bool enabled)820 void Settings::setAcceleratedCompositingEnabled(bool enabled)
821 {
822     if (m_acceleratedCompositingEnabled == enabled)
823         return;
824 
825     m_acceleratedCompositingEnabled = enabled;
826     m_page->setNeedsRecalcStyleInAllFrames();
827 }
828 
setCanvasUsesAcceleratedDrawing(bool enabled)829 void Settings::setCanvasUsesAcceleratedDrawing(bool enabled)
830 {
831     m_canvasUsesAcceleratedDrawing = enabled;
832 }
833 
setAcceleratedDrawingEnabled(bool enabled)834 void Settings::setAcceleratedDrawingEnabled(bool enabled)
835 {
836     m_acceleratedDrawingEnabled = enabled;
837 }
838 
setAcceleratedCompositingFor3DTransformsEnabled(bool enabled)839 void Settings::setAcceleratedCompositingFor3DTransformsEnabled(bool enabled)
840 {
841     m_acceleratedCompositingFor3DTransformsEnabled = enabled;
842 }
843 
setAcceleratedCompositingForVideoEnabled(bool enabled)844 void Settings::setAcceleratedCompositingForVideoEnabled(bool enabled)
845 {
846     m_acceleratedCompositingForVideoEnabled = enabled;
847 }
848 
setAcceleratedCompositingForPluginsEnabled(bool enabled)849 void Settings::setAcceleratedCompositingForPluginsEnabled(bool enabled)
850 {
851     m_acceleratedCompositingForPluginsEnabled = enabled;
852 }
853 
setAcceleratedCompositingForCanvasEnabled(bool enabled)854 void Settings::setAcceleratedCompositingForCanvasEnabled(bool enabled)
855 {
856     m_acceleratedCompositingForCanvasEnabled = enabled;
857 }
858 
setAcceleratedCompositingForAnimationEnabled(bool enabled)859 void Settings::setAcceleratedCompositingForAnimationEnabled(bool enabled)
860 {
861     m_acceleratedCompositingForAnimationEnabled = enabled;
862 }
863 
setShowDebugBorders(bool enabled)864 void Settings::setShowDebugBorders(bool enabled)
865 {
866     if (m_showDebugBorders == enabled)
867         return;
868 
869     m_showDebugBorders = enabled;
870     m_page->setNeedsRecalcStyleInAllFrames();
871 }
872 
setShowRepaintCounter(bool enabled)873 void Settings::setShowRepaintCounter(bool enabled)
874 {
875     if (m_showRepaintCounter == enabled)
876         return;
877 
878     m_showRepaintCounter = enabled;
879     m_page->setNeedsRecalcStyleInAllFrames();
880 }
881 
setExperimentalNotificationsEnabled(bool enabled)882 void Settings::setExperimentalNotificationsEnabled(bool enabled)
883 {
884     m_experimentalNotificationsEnabled = enabled;
885 }
886 
setPluginAllowedRunTime(unsigned runTime)887 void Settings::setPluginAllowedRunTime(unsigned runTime)
888 {
889     m_pluginAllowedRunTime = runTime;
890     m_page->pluginAllowedRunTimeChanged();
891 }
892 
893 #if PLATFORM(WIN) || (OS(WINDOWS) && PLATFORM(WX))
setShouldUseHighResolutionTimers(bool shouldUseHighResolutionTimers)894 void Settings::setShouldUseHighResolutionTimers(bool shouldUseHighResolutionTimers)
895 {
896     gShouldUseHighResolutionTimers = shouldUseHighResolutionTimers;
897 }
898 #endif
899 
setWebAudioEnabled(bool enabled)900 void Settings::setWebAudioEnabled(bool enabled)
901 {
902     m_webAudioEnabled = enabled;
903 }
904 
setWebGLEnabled(bool enabled)905 void Settings::setWebGLEnabled(bool enabled)
906 {
907     m_webGLEnabled = enabled;
908 }
909 
setOpenGLMultisamplingEnabled(bool enabled)910 void Settings::setOpenGLMultisamplingEnabled(bool enabled)
911 {
912     m_openGLMultisamplingEnabled = enabled;
913 }
914 
setAccelerated2dCanvasEnabled(bool enabled)915 void Settings::setAccelerated2dCanvasEnabled(bool enabled)
916 {
917     m_acceleratedCanvas2dEnabled = enabled;
918 }
919 
setLoadDeferringEnabled(bool enabled)920 void Settings::setLoadDeferringEnabled(bool enabled)
921 {
922     m_loadDeferringEnabled = enabled;
923 }
924 
setTiledBackingStoreEnabled(bool enabled)925 void Settings::setTiledBackingStoreEnabled(bool enabled)
926 {
927     m_tiledBackingStoreEnabled = enabled;
928 #if ENABLE(TILED_BACKING_STORE)
929     if (m_page->mainFrame())
930         m_page->mainFrame()->setTiledBackingStoreEnabled(enabled);
931 #endif
932 }
933 
934 } // namespace WebCore
935