2 * Copyright (C) 2010, 2011 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 INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebPreferencesStore.h"
29 #include "FontSmoothingLevel.h"
30 #include "WebCoreArgumentCoders.h"
31 #include <WebCore/Settings.h>
35 namespace WebPreferencesKey {
37 #define DEFINE_KEY_GETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) \
38 const String& KeyLower##Key() \
40 DEFINE_STATIC_LOCAL(String, key, (#KeyUpper)); \
44 FOR_EACH_WEBKIT_PREFERENCE(DEFINE_KEY_GETTERS)
46 #undef DEFINE_KEY_GETTERS
48 } // namespace WebPreferencesKey
51 static bool hasXSSAuditorEnabledTestRunnerOverride;
52 static bool xssAuditorEnabledTestRunnerOverride;
54 WebPreferencesStore::WebPreferencesStore()
58 void WebPreferencesStore::encode(CoreIPC::ArgumentEncoder* encoder) const
60 encoder->encode(m_stringValues);
61 encoder->encode(m_boolValues);
62 encoder->encode(m_uint32Values);
63 encoder->encode(m_doubleValues);
66 bool WebPreferencesStore::decode(CoreIPC::ArgumentDecoder* decoder, WebPreferencesStore& result)
68 if (!decoder->decode(result.m_stringValues))
70 if (!decoder->decode(result.m_boolValues))
72 if (!decoder->decode(result.m_uint32Values))
74 if (!decoder->decode(result.m_doubleValues))
77 if (hasXSSAuditorEnabledTestRunnerOverride)
78 result.m_boolValues.set(WebPreferencesKey::xssAuditorEnabledKey(), xssAuditorEnabledTestRunnerOverride);
83 void WebPreferencesStore::overrideXSSAuditorEnabledForTestRunner(bool enabled)
85 hasXSSAuditorEnabledTestRunnerOverride = true;
86 xssAuditorEnabledTestRunnerOverride = enabled;
89 void WebPreferencesStore::removeTestRunnerOverrides()
91 hasXSSAuditorEnabledTestRunnerOverride = false;
95 template<typename MappedType>
96 MappedType defaultValueForKey(const String&);
99 String defaultValueForKey(const String& key)
101 static HashMap<String, String>& defaults = *new HashMap<String, String>;
102 if (defaults.isEmpty()) {
103 #define DEFINE_STRING_DEFAULTS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) defaults.set(WebPreferencesKey::KeyLower##Key(), DefaultValue);
104 FOR_EACH_WEBKIT_STRING_PREFERENCE(DEFINE_STRING_DEFAULTS)
105 #undef DEFINE_STRING_DEFAULTS
108 return defaults.get(key);
112 bool defaultValueForKey(const String& key)
114 static HashMap<String, bool>& defaults = *new HashMap<String, bool>;
115 if (defaults.isEmpty()) {
116 #define DEFINE_BOOL_DEFAULTS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) defaults.set(WebPreferencesKey::KeyLower##Key(), DefaultValue);
117 FOR_EACH_WEBKIT_BOOL_PREFERENCE(DEFINE_BOOL_DEFAULTS)
118 #undef DEFINE_BOOL_DEFAULTS
121 return defaults.get(key);
125 uint32_t defaultValueForKey(const String& key)
127 static HashMap<String, uint32_t>& defaults = *new HashMap<String, uint32_t>;
128 if (defaults.isEmpty()) {
129 #define DEFINE_UINT32_DEFAULTS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) defaults.set(WebPreferencesKey::KeyLower##Key(), DefaultValue);
130 FOR_EACH_WEBKIT_UINT32_PREFERENCE(DEFINE_UINT32_DEFAULTS)
131 #undef DEFINE_UINT32_DEFAULTS
134 return defaults.get(key);
138 double defaultValueForKey(const String& key)
140 static HashMap<String, double>& defaults = *new HashMap<String, double>;
141 if (defaults.isEmpty()) {
142 #define DEFINE_DOUBLE_DEFAULTS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) defaults.set(WebPreferencesKey::KeyLower##Key(), DefaultValue);
143 FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(DEFINE_DOUBLE_DEFAULTS)
144 #undef DEFINE_DOUBLE_DEFAULTS
147 return defaults.get(key);
150 template<typename MapType>
151 static typename MapType::MappedType valueForKey(const MapType& map, const typename MapType::KeyType& key)
153 typename MapType::const_iterator it = map.find(key);
157 return defaultValueForKey<typename MapType::MappedType>(key);
160 template<typename MapType>
161 static bool setValueForKey(MapType& map, const typename MapType::KeyType& key, const typename MapType::MappedType& value)
163 typename MapType::MappedType existingValue = valueForKey(map, key);
164 if (existingValue == value)
171 bool WebPreferencesStore::setStringValueForKey(const String& key, const String& value)
173 return setValueForKey(m_stringValues, key, value);
176 String WebPreferencesStore::getStringValueForKey(const String& key) const
178 return valueForKey(m_stringValues, key);
181 bool WebPreferencesStore::setBoolValueForKey(const String& key, bool value)
183 return setValueForKey(m_boolValues, key, value);
186 bool WebPreferencesStore::getBoolValueForKey(const String& key) const
188 return valueForKey(m_boolValues, key);
191 bool WebPreferencesStore::setUInt32ValueForKey(const String& key, uint32_t value)
193 return setValueForKey(m_uint32Values, key, value);
196 uint32_t WebPreferencesStore::getUInt32ValueForKey(const String& key) const
198 return valueForKey(m_uint32Values, key);
201 bool WebPreferencesStore::setDoubleValueForKey(const String& key, double value)
203 return setValueForKey(m_doubleValues, key, value);
206 double WebPreferencesStore::getDoubleValueForKey(const String& key) const
208 return valueForKey(m_doubleValues, key);
211 } // namespace WebKit