2 * Copyright (C) 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #include "AudioSession.h"
30 #include "BackForwardController.h"
31 #include "CachedResourceLoader.h"
32 #include "CookieStorage.h"
37 #include "FontGenericFamilies.h"
38 #include "FrameTree.h"
39 #include "FrameView.h"
40 #include "HTMLMediaElement.h"
41 #include "HistoryItem.h"
42 #include "InspectorInstrumentation.h"
43 #include "MainFrame.h"
45 #include "PageCache.h"
46 #include "StorageMap.h"
47 #include "TextAutosizer.h"
49 #include <wtf/NeverDestroyed.h>
54 static void setImageLoadingSettings(Page* page)
56 for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
57 frame->document()->cachedResourceLoader()->setImagesEnabled(page->settings().areImagesEnabled());
58 frame->document()->cachedResourceLoader()->setAutoLoadImages(page->settings().loadsImagesAutomatically());
62 static void invalidateAfterGenericFamilyChange(Page* page)
64 invalidateFontGlyphsCache();
66 page->setNeedsRecalcStyleInAllFrames();
69 double Settings::gDefaultMinDOMTimerInterval = 0.010; // 10 milliseconds
70 double Settings::gDefaultDOMTimerAlignmentInterval = 0;
71 double Settings::gHiddenPageDOMTimerAlignmentInterval = 1.0;
74 bool Settings::gShouldPaintNativeControls = true;
78 bool Settings::gAVFoundationEnabled = false;
82 bool Settings::gQTKitEnabled = true;
85 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
86 bool Settings::gVideoPluginProxyEnabled = true;
89 bool Settings::gMockScrollbarsEnabled = false;
90 bool Settings::gUsesOverlayScrollbars = false;
93 bool Settings::gShouldUseHighResolutionTimers = true;
96 bool Settings::gShouldRespectPriorityInCSSAttributeSetters = false;
97 bool Settings::gLowPowerVideoAudioBufferSizeEnabled = false;
100 bool Settings::gNetworkDataUsageTrackingEnabled = false;
104 // 1) EditingMacBehavior comprises Tiger, Leopard, SnowLeopard and iOS builds, as well as QtWebKit when built on Mac;
105 // 2) EditingWindowsBehavior comprises Win32 and WinCE builds, as well as QtWebKit and Chromium when built on Windows;
106 // 3) EditingUnixBehavior comprises all unix-based systems, but Darwin/MacOS (and then abusing the terminology);
107 // 99) MacEditingBehavior is used as a fallback.
108 static EditingBehaviorType editingBehaviorTypeForPlatform()
114 EditingWindowsBehavior
125 static const bool defaultFixedPositionCreatesStackingContext = true;
126 static const bool defaultMediaPlaybackAllowsInline = false;
127 static const bool defaultMediaPlaybackRequiresUserGesture = true;
128 static const bool defaultShouldRespectImageOrientation = true;
130 static const bool defaultFixedPositionCreatesStackingContext = false;
131 static const bool defaultMediaPlaybackAllowsInline = true;
132 static const bool defaultMediaPlaybackRequiresUserGesture = false;
133 static const bool defaultShouldRespectImageOrientation = false;
136 static const double defaultIncrementalRenderingSuppressionTimeoutInSeconds = 5;
137 #if USE(UNIFIED_TEXT_CHECKING)
138 static const bool defaultUnifiedTextCheckerEnabled = true;
140 static const bool defaultUnifiedTextCheckerEnabled = false;
142 static const bool defaultSmartInsertDeleteEnabled = true;
143 static const bool defaultSelectTrailingWhitespaceEnabled = false;
145 // This amount of time must have elapsed before we will even consider scheduling a layout without a delay.
146 // FIXME: For faster machines this value can really be lowered to 200. 250 is adequate, but a little high
148 static const int layoutScheduleThreshold = 250;
150 Settings::Settings(Page* page)
152 , m_mediaTypeOverride("screen")
153 , m_fontGenericFamilies(std::make_unique<FontGenericFamilies>())
154 , m_storageBlockingPolicy(SecurityOrigin::AllowAllStorage)
155 , m_layoutInterval(layoutScheduleThreshold)
157 , m_maxParseDuration(-1)
159 #if ENABLE(TEXT_AUTOSIZING)
160 , m_textAutosizingFontScaleFactor(1)
161 #if HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP
162 , m_textAutosizingWindowSizeOverride(320, 480)
163 , m_textAutosizingEnabled(true)
165 , m_textAutosizingEnabled(false)
168 SETTINGS_INITIALIZER_LIST
169 , m_screenFontSubstitutionEnabled(shouldEnableScreenFontSubstitutionByDefault())
170 , m_isJavaEnabled(false)
171 , m_isJavaEnabledForLocalFiles(true)
172 , m_loadsImagesAutomatically(false)
173 , m_privateBrowsingEnabled(false)
174 , m_areImagesEnabled(true)
175 , m_arePluginsEnabled(false)
176 , m_isScriptEnabled(false)
177 , m_needsAdobeFrameReloadingQuirk(false)
178 , m_usesPageCache(false)
179 , m_fontRenderingMode(0)
180 , m_isCSSCustomFilterEnabled(false)
182 , m_standalone(false)
183 , m_telephoneNumberParsingEnabled(false)
184 , m_mediaDataLoadsAutomatically(false)
185 , m_shouldTransformsAffectOverflow(true)
186 , m_shouldDispatchJavaScriptWindowOnErrorEvents(false)
187 , m_alwaysUseBaselineOfPrimaryFont(false)
188 , m_alwaysUseAcceleratedOverflowScroll(false)
190 #if ENABLE(CSS_STICKY_POSITION)
191 , m_cssStickyPositionEnabled(true)
193 , m_showTiledScrollingIndicator(false)
194 , m_tiledBackingStoreEnabled(false)
195 , m_dnsPrefetchingEnabled(false)
196 #if ENABLE(TOUCH_EVENTS)
197 , m_touchEventEmulationEnabled(false)
199 , m_scrollingPerformanceLoggingEnabled(false)
200 , m_aggressiveTileRetentionEnabled(false)
201 , m_timeWithoutMouseMovementBeforeHidingControls(3)
202 , m_setImageLoadingSettingsTimer(this, &Settings::imageLoadingSettingsTimerFired)
203 #if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
204 , m_hiddenPageDOMTimerThrottlingEnabled(false)
206 #if ENABLE(PAGE_VISIBILITY_API)
207 , m_hiddenPageCSSAnimationSuspensionEnabled(false)
209 , m_fontFallbackPrefersPictographs(false)
211 // A Frame may not have been created yet, so we initialize the AtomicString
212 // hash before trying to use it.
213 AtomicString::init();
214 initializeDefaultFontFamilies();
215 m_page = page; // Page is not yet fully initialized wen constructing Settings, so keeping m_page null over initializeDefaultFontFamilies() call.
218 Settings::~Settings()
222 PassRefPtr<Settings> Settings::create(Page* page)
224 return adoptRef(new Settings(page));
227 SETTINGS_SETTER_BODIES
229 void Settings::setHiddenPageDOMTimerAlignmentInterval(double hiddenPageDOMTimerAlignmentinterval)
231 gHiddenPageDOMTimerAlignmentInterval = hiddenPageDOMTimerAlignmentinterval;
234 double Settings::hiddenPageDOMTimerAlignmentInterval()
236 return gHiddenPageDOMTimerAlignmentInterval;
240 bool Settings::shouldEnableScreenFontSubstitutionByDefault()
247 void Settings::initializeDefaultFontFamilies()
249 // Other platforms can set up fonts from a client, but on Mac, we want it in WebCore to share code between WebKit1 and WebKit2.
253 const AtomicString& Settings::standardFontFamily(UScriptCode script) const
255 return m_fontGenericFamilies->standardFontFamily(script);
258 void Settings::setStandardFontFamily(const AtomicString& family, UScriptCode script)
260 bool changes = m_fontGenericFamilies->setStandardFontFamily(family, script);
262 invalidateAfterGenericFamilyChange(m_page);
265 const AtomicString& Settings::fixedFontFamily(UScriptCode script) const
267 return m_fontGenericFamilies->fixedFontFamily(script);
270 void Settings::setFixedFontFamily(const AtomicString& family, UScriptCode script)
272 bool changes = m_fontGenericFamilies->setFixedFontFamily(family, script);
274 invalidateAfterGenericFamilyChange(m_page);
277 const AtomicString& Settings::serifFontFamily(UScriptCode script) const
279 return m_fontGenericFamilies->serifFontFamily(script);
282 void Settings::setSerifFontFamily(const AtomicString& family, UScriptCode script)
284 bool changes = m_fontGenericFamilies->setSerifFontFamily(family, script);
286 invalidateAfterGenericFamilyChange(m_page);
289 const AtomicString& Settings::sansSerifFontFamily(UScriptCode script) const
291 return m_fontGenericFamilies->sansSerifFontFamily(script);
294 void Settings::setSansSerifFontFamily(const AtomicString& family, UScriptCode script)
296 bool changes = m_fontGenericFamilies->setSansSerifFontFamily(family, script);
298 invalidateAfterGenericFamilyChange(m_page);
301 const AtomicString& Settings::cursiveFontFamily(UScriptCode script) const
303 return m_fontGenericFamilies->cursiveFontFamily(script);
306 void Settings::setCursiveFontFamily(const AtomicString& family, UScriptCode script)
308 bool changes = m_fontGenericFamilies->setCursiveFontFamily(family, script);
310 invalidateAfterGenericFamilyChange(m_page);
313 const AtomicString& Settings::fantasyFontFamily(UScriptCode script) const
315 return m_fontGenericFamilies->fantasyFontFamily(script);
318 void Settings::setFantasyFontFamily(const AtomicString& family, UScriptCode script)
320 bool changes = m_fontGenericFamilies->setFantasyFontFamily(family, script);
322 invalidateAfterGenericFamilyChange(m_page);
325 const AtomicString& Settings::pictographFontFamily(UScriptCode script) const
327 return m_fontGenericFamilies->pictographFontFamily(script);
330 void Settings::setPictographFontFamily(const AtomicString& family, UScriptCode script)
332 bool changes = m_fontGenericFamilies->setPictographFontFamily(family, script);
334 invalidateAfterGenericFamilyChange(m_page);
337 #if ENABLE(TEXT_AUTOSIZING)
338 void Settings::setTextAutosizingEnabled(bool textAutosizingEnabled)
340 if (m_textAutosizingEnabled == textAutosizingEnabled)
343 m_textAutosizingEnabled = textAutosizingEnabled;
344 m_page->setNeedsRecalcStyleInAllFrames();
347 void Settings::setTextAutosizingWindowSizeOverride(const IntSize& textAutosizingWindowSizeOverride)
349 if (m_textAutosizingWindowSizeOverride == textAutosizingWindowSizeOverride)
352 m_textAutosizingWindowSizeOverride = textAutosizingWindowSizeOverride;
353 m_page->setNeedsRecalcStyleInAllFrames();
356 void Settings::setTextAutosizingFontScaleFactor(float fontScaleFactor)
358 m_textAutosizingFontScaleFactor = fontScaleFactor;
360 // FIXME: I wonder if this needs to traverse frames like in WebViewImpl::resize, or whether there is only one document per Settings instance?
361 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traverseNext())
362 frame->document()->textAutosizer()->recalculateMultipliers();
364 m_page->setNeedsRecalcStyleInAllFrames();
369 void Settings::setMediaTypeOverride(const String& mediaTypeOverride)
371 if (m_mediaTypeOverride == mediaTypeOverride)
374 m_mediaTypeOverride = mediaTypeOverride;
376 FrameView* view = m_page->mainFrame().view();
379 view->setMediaType(mediaTypeOverride);
380 m_page->setNeedsRecalcStyleInAllFrames();
383 void Settings::setLoadsImagesAutomatically(bool loadsImagesAutomatically)
385 m_loadsImagesAutomatically = loadsImagesAutomatically;
387 // Changing this setting to true might immediately start new loads for images that had previously had loading disabled.
388 // If this happens while a WebView is being dealloc'ed, and we don't know the WebView is being dealloc'ed, these new loads
389 // can cause crashes downstream when the WebView memory has actually been free'd.
390 // One example where this can happen is in Mac apps that subclass WebView then do work in their overridden dealloc methods.
391 // Starting these loads synchronously is not important. By putting it on a 0-delay, properly closing the Page cancels them
392 // before they have a chance to really start.
393 // See http://webkit.org/b/60572 for more discussion.
394 m_setImageLoadingSettingsTimer.startOneShot(0);
397 void Settings::imageLoadingSettingsTimerFired(Timer<Settings>*)
399 setImageLoadingSettings(m_page);
402 void Settings::setScriptEnabled(bool isScriptEnabled)
405 if (m_isScriptEnabled == isScriptEnabled)
409 m_isScriptEnabled = isScriptEnabled;
411 m_page->setNeedsRecalcStyleInAllFrames();
413 InspectorInstrumentation::scriptsEnabled(m_page, m_isScriptEnabled);
416 void Settings::setJavaEnabled(bool isJavaEnabled)
418 m_isJavaEnabled = isJavaEnabled;
421 void Settings::setJavaEnabledForLocalFiles(bool isJavaEnabledForLocalFiles)
423 m_isJavaEnabledForLocalFiles = isJavaEnabledForLocalFiles;
426 void Settings::setImagesEnabled(bool areImagesEnabled)
428 m_areImagesEnabled = areImagesEnabled;
430 // See comment in setLoadsImagesAutomatically.
431 m_setImageLoadingSettingsTimer.startOneShot(0);
434 void Settings::setPluginsEnabled(bool arePluginsEnabled)
436 if (m_arePluginsEnabled == arePluginsEnabled)
439 m_arePluginsEnabled = arePluginsEnabled;
440 Page::refreshPlugins(false);
443 void Settings::setPrivateBrowsingEnabled(bool privateBrowsingEnabled)
445 if (m_privateBrowsingEnabled == privateBrowsingEnabled)
448 m_privateBrowsingEnabled = privateBrowsingEnabled;
449 m_page->privateBrowsingStateChanged();
452 void Settings::setUserStyleSheetLocation(const URL& userStyleSheetLocation)
454 if (m_userStyleSheetLocation == userStyleSheetLocation)
457 m_userStyleSheetLocation = userStyleSheetLocation;
459 m_page->userStyleSheetLocationChanged();
462 // FIXME: This quirk is needed because of Radar 4674537 and 5211271. We need to phase it out once Adobe
463 // can fix the bug from their end.
464 void Settings::setNeedsAdobeFrameReloadingQuirk(bool shouldNotReloadIFramesForUnchangedSRC)
466 m_needsAdobeFrameReloadingQuirk = shouldNotReloadIFramesForUnchangedSRC;
469 void Settings::setDefaultMinDOMTimerInterval(double interval)
471 gDefaultMinDOMTimerInterval = interval;
474 double Settings::defaultMinDOMTimerInterval()
476 return gDefaultMinDOMTimerInterval;
479 void Settings::setMinDOMTimerInterval(double interval)
481 m_page->setMinimumTimerInterval(interval);
484 double Settings::minDOMTimerInterval()
486 return m_page->minimumTimerInterval();
489 void Settings::setDefaultDOMTimerAlignmentInterval(double interval)
491 gDefaultDOMTimerAlignmentInterval = interval;
494 double Settings::defaultDOMTimerAlignmentInterval()
496 return gDefaultDOMTimerAlignmentInterval;
499 void Settings::setDOMTimerAlignmentInterval(double interval)
501 m_page->setTimerAlignmentInterval(interval);
504 double Settings::domTimerAlignmentInterval() const
506 return m_page->timerAlignmentInterval();
509 void Settings::setLayoutInterval(int layoutInterval)
511 // FIXME: It seems weird that this function may disregard the specified layout interval.
512 // We should either expose layoutScheduleThreshold or better communicate this invariant.
513 m_layoutInterval = std::max(layoutInterval, layoutScheduleThreshold);
516 void Settings::setUsesPageCache(bool usesPageCache)
518 if (m_usesPageCache == usesPageCache)
521 m_usesPageCache = usesPageCache;
522 if (!m_usesPageCache) {
523 int first = -m_page->backForward().backCount();
524 int last = m_page->backForward().forwardCount();
525 for (int i = first; i <= last; i++)
526 pageCache()->remove(m_page->backForward().itemAtIndex(i));
530 void Settings::setScreenFontSubstitutionEnabled(bool enabled)
532 if (m_screenFontSubstitutionEnabled == enabled)
534 m_screenFontSubstitutionEnabled = enabled;
535 m_page->setNeedsRecalcStyleInAllFrames();
538 void Settings::setFontRenderingMode(FontRenderingMode mode)
540 if (fontRenderingMode() == mode)
542 m_fontRenderingMode = mode;
543 m_page->setNeedsRecalcStyleInAllFrames();
546 FontRenderingMode Settings::fontRenderingMode() const
548 return static_cast<FontRenderingMode>(m_fontRenderingMode);
551 #if USE(SAFARI_THEME)
552 void Settings::setShouldPaintNativeControls(bool shouldPaintNativeControls)
554 gShouldPaintNativeControls = shouldPaintNativeControls;
558 void Settings::setDNSPrefetchingEnabled(bool dnsPrefetchingEnabled)
560 if (m_dnsPrefetchingEnabled == dnsPrefetchingEnabled)
563 m_dnsPrefetchingEnabled = dnsPrefetchingEnabled;
564 m_page->dnsPrefetchingStateChanged();
567 void Settings::setShowTiledScrollingIndicator(bool enabled)
569 if (m_showTiledScrollingIndicator == enabled)
572 m_showTiledScrollingIndicator = enabled;
576 void Settings::setShouldUseHighResolutionTimers(bool shouldUseHighResolutionTimers)
578 gShouldUseHighResolutionTimers = shouldUseHighResolutionTimers;
582 void Settings::setStorageBlockingPolicy(SecurityOrigin::StorageBlockingPolicy enabled)
584 if (m_storageBlockingPolicy == enabled)
587 m_storageBlockingPolicy = enabled;
588 m_page->storageBlockingStateChanged();
591 void Settings::setTiledBackingStoreEnabled(bool enabled)
593 m_tiledBackingStoreEnabled = enabled;
594 #if USE(TILED_BACKING_STORE)
595 m_page->mainFrame().setTiledBackingStoreEnabled(enabled);
599 #if USE(AVFOUNDATION)
600 void Settings::setAVFoundationEnabled(bool enabled)
602 if (gAVFoundationEnabled == enabled)
605 gAVFoundationEnabled = enabled;
606 HTMLMediaElement::resetMediaEngines();
611 void Settings::setQTKitEnabled(bool enabled)
613 if (gQTKitEnabled == enabled)
616 gQTKitEnabled = enabled;
617 HTMLMediaElement::resetMediaEngines();
621 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
622 void Settings::setVideoPluginProxyEnabled(bool enabled)
624 if (gVideoPluginProxyEnabled == enabled)
627 gVideoPluginProxyEnabled = enabled;
628 HTMLMediaElement::resetMediaEngines();
632 void Settings::setScrollingPerformanceLoggingEnabled(bool enabled)
634 m_scrollingPerformanceLoggingEnabled = enabled;
636 if (m_page->mainFrame().view())
637 m_page->mainFrame().view()->setScrollingPerformanceLoggingEnabled(enabled);
640 void Settings::setAggressiveTileRetentionEnabled(bool enabled)
642 m_aggressiveTileRetentionEnabled = enabled;
645 void Settings::setMockScrollbarsEnabled(bool flag)
647 gMockScrollbarsEnabled = flag;
648 // FIXME: This should update scroll bars in existing pages.
651 bool Settings::mockScrollbarsEnabled()
653 return gMockScrollbarsEnabled;
656 void Settings::setUsesOverlayScrollbars(bool flag)
658 gUsesOverlayScrollbars = flag;
659 // FIXME: This should update scroll bars in existing pages.
662 bool Settings::usesOverlayScrollbars()
664 return gUsesOverlayScrollbars;
667 void Settings::setShouldRespectPriorityInCSSAttributeSetters(bool flag)
669 gShouldRespectPriorityInCSSAttributeSetters = flag;
672 bool Settings::shouldRespectPriorityInCSSAttributeSetters()
674 return gShouldRespectPriorityInCSSAttributeSetters;
677 #if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
678 void Settings::setHiddenPageDOMTimerThrottlingEnabled(bool flag)
680 if (m_hiddenPageDOMTimerThrottlingEnabled == flag)
682 m_hiddenPageDOMTimerThrottlingEnabled = flag;
683 m_page->hiddenPageDOMTimerThrottlingStateChanged();
687 #if ENABLE(PAGE_VISIBILITY_API)
688 void Settings::setHiddenPageCSSAnimationSuspensionEnabled(bool flag)
690 if (m_hiddenPageCSSAnimationSuspensionEnabled == flag)
692 m_hiddenPageCSSAnimationSuspensionEnabled = flag;
693 m_page->hiddenPageCSSAnimationSuspensionStateChanged();
697 void Settings::setFontFallbackPrefersPictographs(bool preferPictographs)
699 if (m_fontFallbackPrefersPictographs == preferPictographs)
702 m_fontFallbackPrefersPictographs = preferPictographs;
703 m_page->setNeedsRecalcStyleInAllFrames();
706 void Settings::setLowPowerVideoAudioBufferSizeEnabled(bool flag)
708 gLowPowerVideoAudioBufferSizeEnabled = flag;
712 void Settings::setStandalone(bool standalone)
714 m_standalone = standalone;
717 void Settings::setAudioSessionCategoryOverride(unsigned sessionCategory)
719 AudioSession::sharedSession().setCategoryOverride(static_cast<AudioSession::CategoryType>(sessionCategory));
722 unsigned Settings::audioSessionCategoryOverride()
724 return AudioSession::sharedSession().categoryOverride();
727 void Settings::setNetworkDataUsageTrackingEnabled(bool trackingEnabled)
729 gNetworkDataUsageTrackingEnabled = trackingEnabled;
732 bool Settings::networkDataUsageTrackingEnabled()
734 return gNetworkDataUsageTrackingEnabled;
737 static String& sharedNetworkInterfaceNameGlobal()
739 static NeverDestroyed<String> networkInterfaceName;
740 return networkInterfaceName;
743 void Settings::setNetworkInterfaceName(const String& networkInterfaceName)
745 sharedNetworkInterfaceNameGlobal() = networkInterfaceName;
748 const String& Settings::networkInterfaceName()
750 return sharedNetworkInterfaceNameGlobal();
754 } // namespace WebCore