#include "config.h"
#include "SettingsBase.h"
#include "AudioSession.h"
#include "BackForwardController.h"
#include "CachedResourceLoader.h"
#include "CookieStorage.h"
#include "DOMTimer.h"
#include "Database.h"
#include "Document.h"
#include "FontCascade.h"
#include "FontGenericFamilies.h"
#include "Frame.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "HistoryItem.h"
#include "Page.h"
#include "PageCache.h"
#include "RenderWidget.h"
#include "RuntimeApplicationChecks.h"
#include "Settings.h"
#include "StorageMap.h"
#include <limits>
#include <wtf/StdLibExtras.h>
namespace WebCore {
static void invalidateAfterGenericFamilyChange(Page* page)
{
invalidateFontCascadeCache();
if (page)
page->setNeedsRecalcStyleInAllFrames();
}
static const Seconds layoutScheduleThreshold = 250_ms;
SettingsBase::SettingsBase(Page* page)
: m_page(nullptr)
, m_fontGenericFamilies(std::make_unique<FontGenericFamilies>())
, m_layoutInterval(layoutScheduleThreshold)
, m_minimumDOMTimerInterval(DOMTimer::defaultMinimumInterval())
, m_setImageLoadingSettingsTimer(*this, &SettingsBase::imageLoadingSettingsTimerFired)
{
AtomicString::init();
initializeDefaultFontFamilies();
m_page = page; }
SettingsBase::~SettingsBase() = default;
float SettingsBase::defaultMinimumZoomFontSize()
{
#if PLATFORM(WATCHOS)
return 30;
#else
return 15;
#endif
}
#if !PLATFORM(IOS_FAMILY)
bool SettingsBase::defaultTextAutosizingEnabled()
{
return false;
}
#endif
bool SettingsBase::defaultDownloadableBinaryFontsEnabled()
{
#if PLATFORM(WATCHOS)
return false;
#else
return true;
#endif
}
#if !PLATFORM(COCOA)
const String& SettingsBase::defaultMediaContentTypesRequiringHardwareSupport()
{
return emptyString();
}
#endif
#if !PLATFORM(COCOA)
void SettingsBase::initializeDefaultFontFamilies()
{
}
#endif
const AtomicString& SettingsBase::standardFontFamily(UScriptCode script) const
{
return m_fontGenericFamilies->standardFontFamily(script);
}
void SettingsBase::setStandardFontFamily(const AtomicString& family, UScriptCode script)
{
bool changes = m_fontGenericFamilies->setStandardFontFamily(family, script);
if (changes)
invalidateAfterGenericFamilyChange(m_page);
}
const AtomicString& SettingsBase::fixedFontFamily(UScriptCode script) const
{
return m_fontGenericFamilies->fixedFontFamily(script);
}
void SettingsBase::setFixedFontFamily(const AtomicString& family, UScriptCode script)
{
bool changes = m_fontGenericFamilies->setFixedFontFamily(family, script);
if (changes)
invalidateAfterGenericFamilyChange(m_page);
}
const AtomicString& SettingsBase::serifFontFamily(UScriptCode script) const
{
return m_fontGenericFamilies->serifFontFamily(script);
}
void SettingsBase::setSerifFontFamily(const AtomicString& family, UScriptCode script)
{
bool changes = m_fontGenericFamilies->setSerifFontFamily(family, script);
if (changes)
invalidateAfterGenericFamilyChange(m_page);
}
const AtomicString& SettingsBase::sansSerifFontFamily(UScriptCode script) const
{
return m_fontGenericFamilies->sansSerifFontFamily(script);
}
void SettingsBase::setSansSerifFontFamily(const AtomicString& family, UScriptCode script)
{
bool changes = m_fontGenericFamilies->setSansSerifFontFamily(family, script);
if (changes)
invalidateAfterGenericFamilyChange(m_page);
}
const AtomicString& SettingsBase::cursiveFontFamily(UScriptCode script) const
{
return m_fontGenericFamilies->cursiveFontFamily(script);
}
void SettingsBase::setCursiveFontFamily(const AtomicString& family, UScriptCode script)
{
bool changes = m_fontGenericFamilies->setCursiveFontFamily(family, script);
if (changes)
invalidateAfterGenericFamilyChange(m_page);
}
const AtomicString& SettingsBase::fantasyFontFamily(UScriptCode script) const
{
return m_fontGenericFamilies->fantasyFontFamily(script);
}
void SettingsBase::setFantasyFontFamily(const AtomicString& family, UScriptCode script)
{
bool changes = m_fontGenericFamilies->setFantasyFontFamily(family, script);
if (changes)
invalidateAfterGenericFamilyChange(m_page);
}
const AtomicString& SettingsBase::pictographFontFamily(UScriptCode script) const
{
return m_fontGenericFamilies->pictographFontFamily(script);
}
void SettingsBase::setPictographFontFamily(const AtomicString& family, UScriptCode script)
{
bool changes = m_fontGenericFamilies->setPictographFontFamily(family, script);
if (changes)
invalidateAfterGenericFamilyChange(m_page);
}
void SettingsBase::setMinimumDOMTimerInterval(Seconds interval)
{
auto oldTimerInterval = std::exchange(m_minimumDOMTimerInterval, interval);
if (!m_page)
return;
for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (frame->document())
frame->document()->adjustMinimumDOMTimerInterval(oldTimerInterval);
}
}
void SettingsBase::setLayoutInterval(Seconds layoutInterval)
{
m_layoutInterval = std::max(layoutInterval, layoutScheduleThreshold);
}
void SettingsBase::setMediaContentTypesRequiringHardwareSupport(const String& contentTypes)
{
m_mediaContentTypesRequiringHardwareSupport.shrink(0);
for (auto type : StringView(contentTypes).split(':'))
m_mediaContentTypesRequiringHardwareSupport.append(ContentType { type.toString() });
}
void SettingsBase::setMediaContentTypesRequiringHardwareSupport(const Vector<ContentType>& contentTypes)
{
m_mediaContentTypesRequiringHardwareSupport = contentTypes;
}
void SettingsBase::setNeedsRecalcStyleInAllFrames()
{
if (m_page)
m_page->setNeedsRecalcStyleInAllFrames();
}
void SettingsBase::setNeedsRelayoutAllFrames()
{
if (!m_page)
return;
for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (!frame->ownerRenderer())
continue;
frame->ownerRenderer()->setNeedsLayoutAndPrefWidthsRecalc();
}
}
void SettingsBase::mediaTypeOverrideChanged()
{
if (!m_page)
return;
FrameView* view = m_page->mainFrame().view();
if (view)
view->setMediaType(m_page->settings().mediaTypeOverride());
m_page->setNeedsRecalcStyleInAllFrames();
}
void SettingsBase::imagesEnabledChanged()
{
m_setImageLoadingSettingsTimer.startOneShot(0_s);
}
void SettingsBase::imageLoadingSettingsTimerFired()
{
if (!m_page)
return;
for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (!frame->document())
continue;
frame->document()->cachedResourceLoader().setImagesEnabled(m_page->settings().areImagesEnabled());
frame->document()->cachedResourceLoader().setAutoLoadImages(m_page->settings().loadsImagesAutomatically());
}
}
void SettingsBase::pluginsEnabledChanged()
{
Page::refreshPlugins(false);
}
#if ENABLE(TEXT_AUTOSIZING)
void SettingsBase::shouldEnableTextAutosizingBoostChanged()
{
if (!m_page)
return;
bool boostAutosizing = m_page->settings().shouldEnableTextAutosizingBoost();
m_oneLineTextMultiplierCoefficient = boostAutosizing ? boostedOneLineTextMultiplierCoefficient : defaultOneLineTextMultiplierCoefficient;
m_multiLineTextMultiplierCoefficient = boostAutosizing ? boostedMultiLineTextMultiplierCoefficient : defaultMultiLineTextMultiplierCoefficient;
m_maxTextAutosizingScaleIncrease = boostAutosizing ? boostedMaxTextAutosizingScaleIncrease : defaultMaxTextAutosizingScaleIncrease;
setNeedsRecalcStyleInAllFrames();
}
#endif
void SettingsBase::userStyleSheetLocationChanged()
{
if (m_page)
m_page->userStyleSheetLocationChanged();
}
void SettingsBase::usesPageCacheChanged()
{
if (!m_page)
return;
if (!m_page->settings().usesPageCache())
PageCache::singleton().pruneToSizeNow(0, PruningReason::None);
}
void SettingsBase::dnsPrefetchingEnabledChanged()
{
if (m_page)
m_page->dnsPrefetchingStateChanged();
}
void SettingsBase::storageBlockingPolicyChanged()
{
if (m_page)
m_page->storageBlockingStateChanged();
}
void SettingsBase::backgroundShouldExtendBeyondPageChanged()
{
if (m_page)
m_page->mainFrame().view()->updateExtendBackgroundIfNecessary();
}
void SettingsBase::scrollingPerformanceLoggingEnabledChanged()
{
if (m_page && m_page->mainFrame().view())
m_page->mainFrame().view()->setScrollingPerformanceLoggingEnabled(m_page->settings().scrollingPerformanceLoggingEnabled());
}
void SettingsBase::hiddenPageDOMTimerThrottlingStateChanged()
{
if (m_page)
m_page->hiddenPageDOMTimerThrottlingStateChanged();
}
void SettingsBase::hiddenPageCSSAnimationSuspensionEnabledChanged()
{
if (m_page)
m_page->hiddenPageCSSAnimationSuspensionStateChanged();
}
void SettingsBase::resourceUsageOverlayVisibleChanged()
{
#if ENABLE(RESOURCE_USAGE)
if (m_page)
m_page->setResourceUsageOverlayVisible(m_page->settings().resourceUsageOverlayVisible());
#endif
}
}