1/*
2 * Copyright (C) 2010, 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 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.
24 */
25
26#ifndef WebPreferencesStore_h
27#define WebPreferencesStore_h
28
29#include "ArgumentDecoder.h"
30#include "ArgumentEncoder.h"
31#include <wtf/HashMap.h>
32#include <wtf/text/StringHash.h>
33#include <wtf/text/WTFString.h>
34
35namespace WebKit {
36
37// macro(KeyUpper, KeyLower, TypeNameUpper, TypeName, DefaultValue)
38
39#define FOR_EACH_WEBKIT_BOOL_PREFERENCE(macro) \
40    macro(JavaScriptEnabled, javaScriptEnabled, Bool, bool, true) \
41    macro(LoadsImagesAutomatically, loadsImagesAutomatically, Bool, bool, true) \
42    macro(LoadsSiteIconsIgnoringImageLoadingPreference, loadsSiteIconsIgnoringImageLoadingPreference, Bool, bool, false) \
43    macro(PluginsEnabled, pluginsEnabled, Bool, bool, true) \
44    macro(JavaEnabled, javaEnabled, Bool, bool, true) \
45    macro(OfflineWebApplicationCacheEnabled, offlineWebApplicationCacheEnabled, Bool, bool, false) \
46    macro(LocalStorageEnabled, localStorageEnabled, Bool, bool, true) \
47    macro(DatabasesEnabled, databasesEnabled, Bool, bool, true) \
48    macro(XSSAuditorEnabled, xssAuditorEnabled, Bool, bool, true) \
49    macro(FrameFlatteningEnabled, frameFlatteningEnabled, Bool, bool, false) \
50    macro(DeveloperExtrasEnabled, developerExtrasEnabled, Bool, bool, false) \
51    macro(PrivateBrowsingEnabled, privateBrowsingEnabled, Bool, bool, false) \
52    macro(TextAreasAreResizable, textAreasAreResizable, Bool, bool, true) \
53    macro(JavaScriptCanOpenWindowsAutomatically, javaScriptCanOpenWindowsAutomatically, Bool, bool, true) \
54    macro(HyperlinkAuditingEnabled, hyperlinkAuditingEnabled, Bool, bool, true) \
55    macro(NeedsSiteSpecificQuirks, needsSiteSpecificQuirks, Bool, bool, false) \
56    macro(AcceleratedCompositingEnabled, acceleratedCompositingEnabled, Bool, bool, true) \
57    macro(AcceleratedDrawingEnabled, acceleratedDrawingEnabled, Bool, bool, false) \
58    macro(CanvasUsesAcceleratedDrawing, canvasUsesAcceleratedDrawing, Bool, bool, true) \
59    macro(CompositingBordersVisible, compositingBordersVisible, Bool, bool, false) \
60    macro(CompositingRepaintCountersVisible, compositingRepaintCountersVisible, Bool, bool, false) \
61    macro(WebGLEnabled, webGLEnabled, Bool, bool, false) \
62    macro(ForceFTPDirectoryListings, forceFTPDirectoryListings, Bool, bool, false) \
63    macro(TabsToLinks, tabsToLinks, Bool, bool, false) \
64    macro(DNSPrefetchingEnabled, dnsPrefetchingEnabled, Bool, bool, false) \
65    macro(WebArchiveDebugModeEnabled, webArchiveDebugModeEnabled, Bool, bool, false) \
66    macro(LocalFileContentSniffingEnabled, localFileContentSniffingEnabled, Bool, bool, false) \
67    macro(UsesPageCache, usesPageCache, Bool, bool, true) \
68    macro(AuthorAndUserStylesEnabled, authorAndUserStylesEnabled, Bool, bool, true) \
69    macro(PaginateDuringLayoutEnabled, paginateDuringLayoutEnabled, Bool, bool, false) \
70    macro(DOMPasteAllowed, domPasteAllowed, Bool, bool, false) \
71    macro(JavaScriptCanAccessClipboard, javaScriptCanAccessClipboard, Bool, bool, false) \
72    macro(ShouldPrintBackgrounds, shouldPrintBackgrounds, Bool, bool, false) \
73    macro(FullScreenEnabled, fullScreenEnabled, Bool, bool, true) \
74    macro(WebSecurityEnabled, webSecurityEnabled, Bool, bool, true) \
75    macro(AllowUniversalAccessFromFileURLs, allowUniversalAccessFromFileURLs, Bool, bool, false) \
76    macro(AllowFileAccessFromFileURLs, allowFileAccessFromFileURLs, Bool, bool, false) \
77    \
78
79#define FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \
80    macro(PDFScaleFactor, pdfScaleFactor, Double, double, 0) \
81    \
82
83#define FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \
84    macro(FontSmoothingLevel, fontSmoothingLevel, UInt32, uint32_t, FontSmoothingLevelMedium) \
85    macro(MinimumFontSize, minimumFontSize, UInt32, uint32_t, 0) \
86    macro(MinimumLogicalFontSize, minimumLogicalFontSize, UInt32, uint32_t, 9) \
87    macro(DefaultFontSize, defaultFontSize, UInt32, uint32_t, 16) \
88    macro(DefaultFixedFontSize, defaultFixedFontSize, UInt32, uint32_t, 13) \
89    macro(PDFDisplayMode, pdfDisplayMode, UInt32, uint32_t, 1) \
90    macro(EditableLinkBehavior, editableLinkBehavior, UInt32, uint32_t, WebCore::EditableLinkNeverLive) \
91    \
92
93#if PLATFORM(WIN)
94
95#define FOR_EACH_WEBKIT_FONT_FAMILY_PREFERENCE(macro) \
96    macro(StandardFontFamily, standardFontFamily, String, String, "Times New Roman") \
97    macro(CursiveFontFamily, cursiveFontFamily, String, String, "Comic Sans MS") \
98    macro(FantasyFontFamily, fantasyFontFamily, String, String, "Comic Sans MS") \
99    macro(FixedFontFamily, fixedFontFamily, String, String, "Courier New") \
100    macro(SansSerifFontFamily, sansSerifFontFamily, String, String, "Arial") \
101    macro(SerifFontFamily, serifFontFamily, String, String, "Times New Roman") \
102    \
103
104#elif PLATFORM(MAC)
105
106#define FOR_EACH_WEBKIT_FONT_FAMILY_PREFERENCE(macro) \
107    macro(StandardFontFamily, standardFontFamily, String, String, "Times") \
108    macro(CursiveFontFamily, cursiveFontFamily, String, String, "Apple Chancery") \
109    macro(FantasyFontFamily, fantasyFontFamily, String, String, "Papyrus") \
110    macro(FixedFontFamily, fixedFontFamily, String, String, "Courier") \
111    macro(SansSerifFontFamily, sansSerifFontFamily, String, String, "Helvetica") \
112    macro(SerifFontFamily, serifFontFamily, String, String, "Times") \
113    \
114
115#elif PLATFORM(QT) || PLATFORM(GTK)
116
117#define FOR_EACH_WEBKIT_FONT_FAMILY_PREFERENCE(macro) \
118    macro(StandardFontFamily, standardFontFamily, String, String, "Times") \
119    macro(CursiveFontFamily, cursiveFontFamily, String, String, "Comic Sans MS") \
120    macro(FantasyFontFamily, fantasyFontFamily, String, String, "Impact") \
121    macro(FixedFontFamily, fixedFontFamily, String, String, "Courier New") \
122    macro(SansSerifFontFamily, sansSerifFontFamily, String, String, "Helvetica") \
123    macro(SerifFontFamily, serifFontFamily, String, String, "Times") \
124    \
125
126#endif
127
128#define FOR_EACH_WEBKIT_STRING_PREFERENCE(macro) \
129    FOR_EACH_WEBKIT_FONT_FAMILY_PREFERENCE(macro) \
130    macro(DefaultTextEncodingName, defaultTextEncodingName, String, String, "ISO-8859-1") \
131    macro(FTPDirectoryTemplatePath, ftpDirectoryTemplatePath, String, String, "") \
132    \
133
134
135#define FOR_EACH_WEBKIT_PREFERENCE(macro) \
136    FOR_EACH_WEBKIT_BOOL_PREFERENCE(macro) \
137    FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \
138    FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \
139    FOR_EACH_WEBKIT_STRING_PREFERENCE(macro) \
140    \
141
142namespace WebPreferencesKey {
143
144#define DECLARE_KEY_GETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) const String& KeyLower##Key();
145
146    FOR_EACH_WEBKIT_PREFERENCE(DECLARE_KEY_GETTERS)
147
148#undef DECLARE_KEY_GETTERS
149
150} // namespace WebPreferencesKey
151
152struct WebPreferencesStore {
153    WebPreferencesStore();
154
155    void encode(CoreIPC::ArgumentEncoder* encoder) const;
156    static bool decode(CoreIPC::ArgumentDecoder*, WebPreferencesStore&);
157
158    // NOTE: The getters in this class have non-standard names to aid in the use of the preference macros.
159
160    bool setStringValueForKey(const String& key, const String& value);
161    String getStringValueForKey(const String& key) const;
162
163    bool setBoolValueForKey(const String& key, bool value);
164    bool getBoolValueForKey(const String& key) const;
165
166    bool setUInt32ValueForKey(const String& key, uint32_t value);
167    uint32_t getUInt32ValueForKey(const String& key) const;
168
169    bool setDoubleValueForKey(const String& key, double value);
170    double getDoubleValueForKey(const String& key) const;
171
172    static void overrideXSSAuditorEnabledForTestRunner(bool);
173    static void overrideAllowUniversalAccessFromFileURLsForTestRunner(bool);
174    static void overrideAllowFileAccessFromFileURLsForTestRunner(bool);
175    static void removeTestRunnerOverrides();
176
177    HashMap<String, String> m_stringValues;
178    HashMap<String, bool> m_boolValues;
179    HashMap<String, uint32_t> m_uint32Values;
180    HashMap<String, double> m_doubleValues;
181};
182
183} // namespace WebKit
184
185#endif // WebPreferencesStore_h
186