WebPreferencesStore.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * Copyright (C) 2010, 2011, 2012 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. #ifndef WebPreferencesStore_h
  26. #define WebPreferencesStore_h
  27. #include "ArgumentDecoder.h"
  28. #include "ArgumentEncoder.h"
  29. #include <wtf/HashMap.h>
  30. #include <wtf/text/StringHash.h>
  31. #include <wtf/text/WTFString.h>
  32. namespace WebKit {
  33. // macro(KeyUpper, KeyLower, TypeNameUpper, TypeName, DefaultValue)
  34. #if PLATFORM(GTK)
  35. #define DEFAULT_WEBKIT_TABSTOLINKS_ENABLED true
  36. #else
  37. #define DEFAULT_WEBKIT_TABSTOLINKS_ENABLED false
  38. #endif
  39. #if ENABLE(SMOOTH_SCROLLING) && !PLATFORM(QT)
  40. #define DEFAULT_WEBKIT_SCROLL_ANIMATOR_ENABLED true
  41. #else
  42. #define DEFAULT_WEBKIT_SCROLL_ANIMATOR_ENABLED false
  43. #endif
  44. #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
  45. #define DEFAULT_SCREEN_FONT_SUBSTITUTION_ENABLED false
  46. #else
  47. #define DEFAULT_SCREEN_FONT_SUBSTITUTION_ENABLED true
  48. #endif
  49. #if PLATFORM(MAC)
  50. #define DEFAULT_HIDDEN_PAGE_DOM_TIMER_THROTTLING_ENABLED true
  51. #define DEFAULT_HIDDEN_PAGE_CSS_ANIMATION_SUSPENSION_ENABLED true
  52. #else
  53. #define DEFAULT_HIDDEN_PAGE_DOM_TIMER_THROTTLING_ENABLED false
  54. #define DEFAULT_HIDDEN_PAGE_CSS_ANIMATION_SUSPENSION_ENABLED false
  55. #endif
  56. #define FOR_EACH_WEBKIT_BOOL_PREFERENCE(macro) \
  57. macro(JavaScriptEnabled, javaScriptEnabled, Bool, bool, true) \
  58. macro(JavaScriptMarkupEnabled, javaScriptMarkupEnabled, Bool, bool, true) \
  59. macro(LoadsImagesAutomatically, loadsImagesAutomatically, Bool, bool, true) \
  60. macro(LoadsSiteIconsIgnoringImageLoadingPreference, loadsSiteIconsIgnoringImageLoadingPreference, Bool, bool, false) \
  61. macro(PluginsEnabled, pluginsEnabled, Bool, bool, true) \
  62. macro(JavaEnabled, javaEnabled, Bool, bool, true) \
  63. macro(JavaEnabledForLocalFiles, javaEnabledForLocalFiles, Bool, bool, true) \
  64. macro(OfflineWebApplicationCacheEnabled, offlineWebApplicationCacheEnabled, Bool, bool, false) \
  65. macro(LocalStorageEnabled, localStorageEnabled, Bool, bool, true) \
  66. macro(DatabasesEnabled, databasesEnabled, Bool, bool, true) \
  67. macro(XSSAuditorEnabled, xssAuditorEnabled, Bool, bool, true) \
  68. macro(FrameFlatteningEnabled, frameFlatteningEnabled, Bool, bool, false) \
  69. macro(DeveloperExtrasEnabled, developerExtrasEnabled, Bool, bool, false) \
  70. macro(JavaScriptExperimentsEnabled, javaScriptExperimentsEnabled, Bool, bool, false) \
  71. macro(PrivateBrowsingEnabled, privateBrowsingEnabled, Bool, bool, false) \
  72. macro(TextAreasAreResizable, textAreasAreResizable, Bool, bool, true) \
  73. macro(JavaScriptCanOpenWindowsAutomatically, javaScriptCanOpenWindowsAutomatically, Bool, bool, true) \
  74. macro(HyperlinkAuditingEnabled, hyperlinkAuditingEnabled, Bool, bool, true) \
  75. macro(NeedsSiteSpecificQuirks, needsSiteSpecificQuirks, Bool, bool, false) \
  76. macro(AcceleratedCompositingEnabled, acceleratedCompositingEnabled, Bool, bool, true) \
  77. macro(ForceCompositingMode, forceCompositingMode, Bool, bool, false) \
  78. macro(AcceleratedDrawingEnabled, acceleratedDrawingEnabled, Bool, bool, false) \
  79. macro(CanvasUsesAcceleratedDrawing, canvasUsesAcceleratedDrawing, Bool, bool, true) \
  80. macro(CompositingBordersVisible, compositingBordersVisible, Bool, bool, false) \
  81. macro(CompositingRepaintCountersVisible, compositingRepaintCountersVisible, Bool, bool, false) \
  82. macro(TiledScrollingIndicatorVisible, tiledScrollingIndicatorVisible, Bool, bool, false) \
  83. macro(CSSCustomFilterEnabled, cssCustomFilterEnabled, Bool, bool, true) \
  84. macro(WebGLEnabled, webGLEnabled, Bool, bool, false) \
  85. macro(Accelerated2dCanvasEnabled, accelerated2dCanvasEnabled, Bool, bool, false) \
  86. macro(CSSRegionsEnabled, cssRegionsEnabled, Bool, bool, true) \
  87. macro(CSSCompositingEnabled, cssCompositingEnabled, Bool, bool, true) \
  88. macro(CSSGridLayoutEnabled, cssGridLayoutEnabled, Bool, bool, false) \
  89. macro(RegionBasedColumnsEnabled, regionBasedColumnsEnabled, Bool, bool, false) \
  90. macro(ForceFTPDirectoryListings, forceFTPDirectoryListings, Bool, bool, false) \
  91. macro(TabsToLinks, tabsToLinks, Bool, bool, DEFAULT_WEBKIT_TABSTOLINKS_ENABLED) \
  92. macro(DNSPrefetchingEnabled, dnsPrefetchingEnabled, Bool, bool, false) \
  93. macro(WebArchiveDebugModeEnabled, webArchiveDebugModeEnabled, Bool, bool, false) \
  94. macro(LocalFileContentSniffingEnabled, localFileContentSniffingEnabled, Bool, bool, false) \
  95. macro(UsesPageCache, usesPageCache, Bool, bool, true) \
  96. macro(PageCacheSupportsPlugins, pageCacheSupportsPlugins, Bool, bool, true) \
  97. macro(AuthorAndUserStylesEnabled, authorAndUserStylesEnabled, Bool, bool, true) \
  98. macro(PaginateDuringLayoutEnabled, paginateDuringLayoutEnabled, Bool, bool, false) \
  99. macro(DOMPasteAllowed, domPasteAllowed, Bool, bool, false) \
  100. macro(JavaScriptCanAccessClipboard, javaScriptCanAccessClipboard, Bool, bool, false) \
  101. macro(ShouldPrintBackgrounds, shouldPrintBackgrounds, Bool, bool, false) \
  102. macro(FullScreenEnabled, fullScreenEnabled, Bool, bool, false) \
  103. macro(AsynchronousSpellCheckingEnabled, asynchronousSpellCheckingEnabled, Bool, bool, false) \
  104. macro(WebSecurityEnabled, webSecurityEnabled, Bool, bool, true) \
  105. macro(AllowUniversalAccessFromFileURLs, allowUniversalAccessFromFileURLs, Bool, bool, false) \
  106. macro(AllowFileAccessFromFileURLs, allowFileAccessFromFileURLs, Bool, bool, false) \
  107. macro(AVFoundationEnabled, isAVFoundationEnabled, Bool, bool, true) \
  108. macro(MediaPlaybackRequiresUserGesture, mediaPlaybackRequiresUserGesture, Bool, bool, false) \
  109. macro(MediaPlaybackAllowsInline, mediaPlaybackAllowsInline, Bool, bool, true) \
  110. macro(InspectorStartsAttached, inspectorStartsAttached, Bool, bool, true) \
  111. macro(InspectorUsesWebKitUserInterface, inspectorUsesWebKitUserInterface, Bool, bool, false) \
  112. macro(ShowsToolTipOverTruncatedText, showsToolTipOverTruncatedText, Bool, bool, false) \
  113. macro(MockScrollbarsEnabled, mockScrollbarsEnabled, Bool, bool, false) \
  114. macro(WebAudioEnabled, webAudioEnabled, Bool, bool, false) \
  115. macro(ApplicationChromeModeEnabled, applicationChromeMode, Bool, bool, false) \
  116. macro(SuppressesIncrementalRendering, suppressesIncrementalRendering, Bool, bool, false) \
  117. macro(BackspaceKeyNavigationEnabled, backspaceKeyNavigationEnabled, Bool, bool, true) \
  118. macro(CaretBrowsingEnabled, caretBrowsingEnabled, Bool, bool, false) \
  119. macro(ShouldDisplaySubtitles, shouldDisplaySubtitles, Bool, bool, false) \
  120. macro(ShouldDisplayCaptions, shouldDisplayCaptions, Bool, bool, false) \
  121. macro(ShouldDisplayTextDescriptions, shouldDisplayTextDescriptions, Bool, bool, false) \
  122. macro(NotificationsEnabled, notificationsEnabled, Bool, bool, true) \
  123. macro(ShouldRespectImageOrientation, shouldRespectImageOrientation, Bool, bool, false) \
  124. macro(WantsBalancedSetDefersLoadingBehavior, wantsBalancedSetDefersLoadingBehavior, Bool, bool, false) \
  125. macro(RequestAnimationFrameEnabled, requestAnimationFrameEnabled, Bool, bool, true) \
  126. macro(DiagnosticLoggingEnabled, diagnosticLoggingEnabled, Bool, bool, false) \
  127. macro(AsynchronousPluginInitializationEnabled, asynchronousPluginInitializationEnabled, Bool, bool, false) \
  128. macro(AsynchronousPluginInitializationEnabledForAllPlugins, asynchronousPluginInitializationEnabledForAllPlugins, Bool, bool, false) \
  129. macro(ArtificialPluginInitializationDelayEnabled, artificialPluginInitializationDelayEnabled, Bool, bool, false) \
  130. macro(TabToLinksEnabled, tabToLinksEnabled, Bool, bool, false) \
  131. macro(InteractiveFormValidationEnabled, interactiveFormValidationEnabled, Bool, bool, false) \
  132. macro(ScrollingPerformanceLoggingEnabled, scrollingPerformanceLoggingEnabled, Bool, bool, false) \
  133. macro(StorageBlockingPolicy, storageBlockingPolicy, UInt32, uint32_t, 0) \
  134. macro(ScrollAnimatorEnabled, scrollAnimatorEnabled, Bool, bool, DEFAULT_WEBKIT_SCROLL_ANIMATOR_ENABLED) \
  135. macro(ScreenFontSubstitutionEnabled, screenFontSubstitutionEnabled, Bool, bool, DEFAULT_SCREEN_FONT_SUBSTITUTION_ENABLED) \
  136. macro(CookieEnabled, cookieEnabled, Bool, bool, true) \
  137. macro(PlugInSnapshottingEnabled, plugInSnapshottingEnabled, Bool, bool, false) \
  138. macro(SnapshotAllPlugIns, snapshotAllPlugIns, Bool, bool, false) \
  139. macro(AutostartOriginPlugInSnapshottingEnabled, autostartOriginPlugInSnapshottingEnabled, Bool, bool, true) \
  140. macro(PrimaryPlugInSnapshotDetectionEnabled, primaryPlugInSnapshotDetectionEnabled, Bool, bool, true) \
  141. macro(PDFPluginEnabled, pdfPluginEnabled, Bool, bool, false) \
  142. macro(UsesEncodingDetector, usesEncodingDetector, Bool, bool, false) \
  143. macro(TextAutosizingEnabled, textAutosizingEnabled, Bool, bool, false) \
  144. macro(AggressiveTileRetentionEnabled, aggressiveTileRetentionEnabled, Bool, bool, false) \
  145. macro(QTKitEnabled, isQTKitEnabled, Bool, bool, true) \
  146. macro(LogsPageMessagesToSystemConsoleEnabled, logsPageMessagesToSystemConsoleEnabled, Bool, bool, false) \
  147. macro(PageVisibilityBasedProcessSuppressionEnabled, pageVisibilityBasedProcessSuppressionEnabled, Bool, bool, false) \
  148. macro(SmartInsertDeleteEnabled, smartInsertDeleteEnabled, Bool, bool, true) \
  149. macro(SelectTrailingWhitespaceEnabled, selectTrailingWhitespaceEnabled, Bool, bool, false) \
  150. macro(ShowsURLsInToolTipsEnabled, showsURLsInToolTipsEnabled, Bool, bool, false) \
  151. macro(AcceleratedCompositingForOverflowScrollEnabled, acceleratedCompositingForOverflowScrollEnabled, Bool, bool, false) \
  152. macro(HiddenPageDOMTimerThrottlingEnabled, hiddenPageDOMTimerThrottlingEnabled, Bool, bool, DEFAULT_HIDDEN_PAGE_DOM_TIMER_THROTTLING_ENABLED) \
  153. macro(HiddenPageCSSAnimationSuspensionEnabled, hiddenPageCSSAnimationSuspensionEnabled, Bool, bool, DEFAULT_HIDDEN_PAGE_CSS_ANIMATION_SUSPENSION_ENABLED) \
  154. macro(LowPowerVideoAudioBufferSizeEnabled, lowPowerVideoAudioBufferSizeEnabled, Bool, bool, false) \
  155. \
  156. #define FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \
  157. macro(PDFScaleFactor, pdfScaleFactor, Double, double, 0) \
  158. macro(IncrementalRenderingSuppressionTimeout, incrementalRenderingSuppressionTimeout, Double, double, 5) \
  159. \
  160. #define FOR_EACH_WEBKIT_FLOAT_PREFERENCE(macro) \
  161. \
  162. #define FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \
  163. macro(FontSmoothingLevel, fontSmoothingLevel, UInt32, uint32_t, FontSmoothingLevelMedium) \
  164. macro(MinimumFontSize, minimumFontSize, UInt32, uint32_t, 0) \
  165. macro(MinimumLogicalFontSize, minimumLogicalFontSize, UInt32, uint32_t, 9) \
  166. macro(DefaultFontSize, defaultFontSize, UInt32, uint32_t, 16) \
  167. macro(DefaultFixedFontSize, defaultFixedFontSize, UInt32, uint32_t, 13) \
  168. macro(LayoutFallbackWidth, layoutFallbackWidth, UInt32, uint32_t, 980) \
  169. macro(DeviceWidth, deviceWidth, UInt32, uint32_t, 0) \
  170. macro(DeviceHeight, deviceHeight, UInt32, uint32_t, 0) \
  171. macro(PDFDisplayMode, pdfDisplayMode, UInt32, uint32_t, 1) \
  172. macro(EditableLinkBehavior, editableLinkBehavior, UInt32, uint32_t, WebCore::EditableLinkNeverLive) \
  173. macro(InspectorAttachedHeight, inspectorAttachedHeight, UInt32, uint32_t, 300) \
  174. macro(InspectorAttachedWidth, inspectorAttachedWidth, UInt32, uint32_t, 750) \
  175. macro(InspectorAttachmentSide, inspectorAttachmentSide, UInt32, uint32_t, 0) \
  176. \
  177. #if PLATFORM(MAC)
  178. #define FOR_EACH_WEBKIT_FONT_FAMILY_PREFERENCE(macro) \
  179. macro(StandardFontFamily, standardFontFamily, String, String, "Times") \
  180. macro(CursiveFontFamily, cursiveFontFamily, String, String, "Apple Chancery") \
  181. macro(FantasyFontFamily, fantasyFontFamily, String, String, "Papyrus") \
  182. macro(FixedFontFamily, fixedFontFamily, String, String, "Courier") \
  183. macro(SansSerifFontFamily, sansSerifFontFamily, String, String, "Helvetica") \
  184. macro(SerifFontFamily, serifFontFamily, String, String, "Times") \
  185. macro(PictographFontFamily, pictographFontFamily, String, String, "Apple Color Emoji") \
  186. \
  187. #elif PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(MANX)
  188. #define FOR_EACH_WEBKIT_FONT_FAMILY_PREFERENCE(macro) \
  189. macro(StandardFontFamily, standardFontFamily, String, String, "Times") \
  190. macro(CursiveFontFamily, cursiveFontFamily, String, String, "Comic Sans MS") \
  191. macro(FantasyFontFamily, fantasyFontFamily, String, String, "Impact") \
  192. macro(FixedFontFamily, fixedFontFamily, String, String, "Courier New") \
  193. macro(SansSerifFontFamily, sansSerifFontFamily, String, String, "Helvetica") \
  194. macro(SerifFontFamily, serifFontFamily, String, String, "Times") \
  195. macro(PictographFontFamily, pictographFontFamily, String, String, "Times") \
  196. \
  197. #endif
  198. #define FOR_EACH_WEBKIT_STRING_PREFERENCE(macro) \
  199. FOR_EACH_WEBKIT_FONT_FAMILY_PREFERENCE(macro) \
  200. macro(DefaultTextEncodingName, defaultTextEncodingName, String, String, "ISO-8859-1") \
  201. macro(FTPDirectoryTemplatePath, ftpDirectoryTemplatePath, String, String, "") \
  202. \
  203. #define FOR_EACH_WEBKIT_STRING_PREFERENCE_NOT_IN_WEBCORE(macro) \
  204. macro(InspectorWindowFrame, inspectorWindowFrame, String, String, "") \
  205. \
  206. #define FOR_EACH_WEBKIT_PREFERENCE(macro) \
  207. FOR_EACH_WEBKIT_BOOL_PREFERENCE(macro) \
  208. FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \
  209. FOR_EACH_WEBKIT_FLOAT_PREFERENCE(macro) \
  210. FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \
  211. FOR_EACH_WEBKIT_STRING_PREFERENCE(macro) \
  212. FOR_EACH_WEBKIT_STRING_PREFERENCE_NOT_IN_WEBCORE(macro) \
  213. \
  214. namespace WebPreferencesKey {
  215. #define DECLARE_KEY_GETTERS(KeyUpper, KeyLower, TypeName, Type, DefaultValue) const String& KeyLower##Key();
  216. FOR_EACH_WEBKIT_PREFERENCE(DECLARE_KEY_GETTERS)
  217. #undef DECLARE_KEY_GETTERS
  218. } // namespace WebPreferencesKey
  219. struct WebPreferencesStore {
  220. WebPreferencesStore();
  221. void encode(CoreIPC::ArgumentEncoder&) const;
  222. static bool decode(CoreIPC::ArgumentDecoder&, WebPreferencesStore&);
  223. // NOTE: The getters in this class have non-standard names to aid in the use of the preference macros.
  224. bool setStringValueForKey(const String& key, const String& value);
  225. String getStringValueForKey(const String& key) const;
  226. bool setBoolValueForKey(const String& key, bool value);
  227. bool getBoolValueForKey(const String& key) const;
  228. bool setUInt32ValueForKey(const String& key, uint32_t value);
  229. uint32_t getUInt32ValueForKey(const String& key) const;
  230. bool setDoubleValueForKey(const String& key, double value);
  231. double getDoubleValueForKey(const String& key) const;
  232. bool setFloatValueForKey(const String& key, float value);
  233. float getFloatValueForKey(const String& key) const;
  234. // For WebKitTestRunner usage.
  235. static void overrideBoolValueForKey(const String& key, bool value);
  236. static void removeTestRunnerOverrides();
  237. HashMap<String, String> m_stringValues;
  238. HashMap<String, bool> m_boolValues;
  239. HashMap<String, uint32_t> m_uint32Values;
  240. HashMap<String, double> m_doubleValues;
  241. HashMap<String, float> m_floatValues;
  242. };
  243. } // namespace WebKit
  244. #endif // WebPreferencesStore_h