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