WebPreferences.cpp [plain text]
#include "config.h"
#include "WebPreferences.h"
#include "WebContext.h"
#include "WebPageGroup.h"
#include "WebPreferencesKeys.h"
#include <wtf/ThreadingPrimitives.h>
namespace WebKit {
static unsigned privateBrowsingPageCount;
PassRefPtr<WebPreferences> WebPreferences::create(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix)
{
return adoptRef(new WebPreferences(identifier, keyPrefix, globalDebugKeyPrefix));
}
PassRefPtr<WebPreferences> WebPreferences::createWithLegacyDefaults(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix)
{
RefPtr<WebPreferences> preferences = adoptRef(new WebPreferences(identifier, keyPrefix, globalDebugKeyPrefix));
preferences->m_store.setOverrideDefaultsBoolValueForKey(WebPreferencesKey::javaEnabledKey(), true);
preferences->m_store.setOverrideDefaultsBoolValueForKey(WebPreferencesKey::javaEnabledForLocalFilesKey(), true);
preferences->m_store.setOverrideDefaultsBoolValueForKey(WebPreferencesKey::pluginsEnabledKey(), true);
preferences->m_store.setOverrideDefaultsUInt32ValueForKey(WebPreferencesKey::storageBlockingPolicyKey(), WebCore::SecurityOrigin::AllowAllStorage);
return preferences.release();
}
WebPreferences::WebPreferences(const String& identifier, const String& keyPrefix, const String& globalDebugKeyPrefix)
: m_identifier(identifier)
, m_keyPrefix(keyPrefix)
, m_globalDebugKeyPrefix(globalDebugKeyPrefix)
{
platformInitializeStore();
}
WebPreferences::WebPreferences(const WebPreferences& other)
: m_keyPrefix(other.m_keyPrefix)
, m_globalDebugKeyPrefix(other.m_globalDebugKeyPrefix)
, m_store(other.m_store)
{
platformInitializeStore();
}
WebPreferences::~WebPreferences()
{
ASSERT(m_pages.isEmpty());
}
PassRefPtr<WebPreferences> WebPreferences::copy() const
{
return adoptRef(new WebPreferences(*this));
}
void WebPreferences::addPage(WebPageProxy& webPageProxy)
{
ASSERT(!m_pages.contains(&webPageProxy));
m_pages.add(&webPageProxy);
if (privateBrowsingEnabled()) {
if (!privateBrowsingPageCount)
WebContext::willStartUsingPrivateBrowsing();
++privateBrowsingPageCount;
}
}
void WebPreferences::removePage(WebPageProxy& webPageProxy)
{
ASSERT(m_pages.contains(&webPageProxy));
m_pages.remove(&webPageProxy);
if (privateBrowsingEnabled()) {
--privateBrowsingPageCount;
if (!privateBrowsingPageCount)
WebContext::willStopUsingPrivateBrowsing();
}
}
void WebPreferences::update()
{
for (auto& webPageProxy : m_pages)
webPageProxy->preferencesDidChange();
}
void WebPreferences::updateStringValueForKey(const String& key, const String& value)
{
platformUpdateStringValueForKey(key, value);
update(); }
void WebPreferences::updateBoolValueForKey(const String& key, bool value)
{
if (key == WebPreferencesKey::privateBrowsingEnabledKey()) {
updatePrivateBrowsingValue(value);
return;
}
platformUpdateBoolValueForKey(key, value);
update(); }
void WebPreferences::updateUInt32ValueForKey(const String& key, uint32_t value)
{
platformUpdateUInt32ValueForKey(key, value);
update(); }
void WebPreferences::updateDoubleValueForKey(const String& key, double value)
{
platformUpdateDoubleValueForKey(key, value);
update(); }
void WebPreferences::updateFloatValueForKey(const String& key, float value)
{
platformUpdateFloatValueForKey(key, value);
update(); }
void WebPreferences::updatePrivateBrowsingValue(bool value)
{
platformUpdateBoolValueForKey(WebPreferencesKey::privateBrowsingEnabledKey(), value);
unsigned pagesChanged = m_pages.size();
if (!pagesChanged)
return;
if (value) {
if (!privateBrowsingPageCount)
WebContext::willStartUsingPrivateBrowsing();
privateBrowsingPageCount += pagesChanged;
}
update();
if (!value) {
ASSERT(privateBrowsingPageCount >= pagesChanged);
privateBrowsingPageCount -= pagesChanged;
if (!privateBrowsingPageCount)
WebContext::willStopUsingPrivateBrowsing();
}
}
#define DEFINE_PREFERENCE_GETTER_AND_SETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) \
void WebPreferences::set##KeyUpper(const Type& value) \
{ \
if (!m_store.set##TypeName##ValueForKey(WebPreferencesKey::KeyLower##Key(), value)) \
return; \
update##TypeName##ValueForKey(WebPreferencesKey::KeyLower##Key(), value); \
\
} \
\
Type WebPreferences::KeyLower() const \
{ \
return m_store.get##TypeName##ValueForKey(WebPreferencesKey::KeyLower##Key()); \
} \
FOR_EACH_WEBKIT_PREFERENCE(DEFINE_PREFERENCE_GETTER_AND_SETTERS)
FOR_EACH_WEBKIT_DEBUG_PREFERENCE(DEFINE_PREFERENCE_GETTER_AND_SETTERS)
#undef DEFINE_PREFERENCE_GETTER_AND_SETTERS
bool WebPreferences::anyPagesAreUsingPrivateBrowsing()
{
return privateBrowsingPageCount;
}
}