1/* 2 * Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19#ifndef WebSettings_h 20#define WebSettings_h 21 22#include "BlackBerryGlobal.h" 23#include "BlackBerryPlatformMisc.h" 24 25namespace BlackBerry { 26namespace WebKit { 27 28class WebSettings; 29class WebSettingsPrivate; 30 31/*! 32 @struct WebSettingsDelegate 33 Defines the methods that must be implemented by a delegate of WebSettings. 34*/ 35struct BLACKBERRY_EXPORT WebSettingsDelegate { 36 virtual ~WebSettingsDelegate() { } 37 38 /*! 39 Sent when the value of a setting changed as well as on instantiation of a WebSettings object. 40 @param settings The WebSettings object that sent the message. 41 */ 42 virtual void didChangeSettings(WebSettings*) = 0; 43}; 44 45/*! 46 @class WebSettings 47*/ 48class BLACKBERRY_EXPORT WebSettings { 49public: 50 static WebSettings* createFromStandardSettings(WebSettingsDelegate* = 0); 51 ~WebSettings(); 52 53 static WebSettings* standardSettings(); 54 55 void setDelegate(WebSettingsDelegate*); 56 WebSettingsDelegate* delegate(); 57 58 static void addSupportedObjectPluginMIMEType(const BlackBerry::Platform::String&); 59 static bool isSupportedObjectMIMEType(const BlackBerry::Platform::String&); 60 61 bool xssAuditorEnabled() const; 62 void setXSSAuditorEnabled(bool); 63 64 bool loadsImagesAutomatically() const; 65 void setLoadsImagesAutomatically(bool); 66 67 bool shouldDrawBorderWhileLoadingImages() const; 68 void setShouldDrawBorderWhileLoadingImages(bool); 69 70 bool isJavaScriptEnabled() const; 71 void setJavaScriptEnabled(bool); 72 73 bool isPrivateBrowsingEnabled() const; 74 void setPrivateBrowsingEnabled(bool); 75 76 void setDeviceSupportsMouse(bool); 77 bool deviceSupportsMouse() const; 78 79 int defaultFixedFontSize() const; 80 void setDefaultFixedFontSize(int); 81 82 int defaultFontSize() const; 83 void setDefaultFontSize(int); 84 85 int minimumFontSize() const; 86 void setMinimumFontSize(int); 87 88 BlackBerry::Platform::String serifFontFamily() const; 89 void setSerifFontFamily(const BlackBerry::Platform::String&); 90 BlackBerry::Platform::String fixedFontFamily() const; 91 void setFixedFontFamily(const BlackBerry::Platform::String&); 92 BlackBerry::Platform::String sansSerifFontFamily() const; 93 void setSansSerifFontFamily(const BlackBerry::Platform::String&); 94 BlackBerry::Platform::String standardFontFamily() const; 95 void setStandardFontFamily(const BlackBerry::Platform::String&); 96 97 void setDownloadableBinaryFontsEnabled(bool); 98 bool downloadableBinaryFontsEnabled() const; 99 100 BlackBerry::Platform::String userAgentString() const; 101 void setUserAgentString(const BlackBerry::Platform::String&); 102 103 BlackBerry::Platform::String defaultTextEncodingName() const; 104 void setDefaultTextEncodingName(const BlackBerry::Platform::String&); 105 106 bool isZoomToFitOnLoad() const; 107 void setZoomToFitOnLoad(bool); 108 109 enum TextReflowMode { TextReflowDisabled, TextReflowEnabled, TextReflowEnabledOnlyForBlockZoom }; 110 TextReflowMode textReflowMode() const; 111 void setTextReflowMode(TextReflowMode); 112 113 bool isScrollbarsEnabled() const; 114 void setScrollbarsEnabled(bool); 115 116 // FIXME: Consider renaming this method upstream, where it is called javaScriptCanOpenWindowsAutomatically. 117 bool canJavaScriptOpenWindowsAutomatically() const; 118 void setJavaScriptOpenWindowsAutomatically(bool); 119 120 bool arePluginsEnabled() const; 121 void setPluginsEnabled(bool); 122 123 bool isGeolocationEnabled() const; 124 void setGeolocationEnabled(bool); 125 126 // Context info 127 bool doesGetFocusNodeContext() const; 128 void setGetFocusNodeContext(bool); 129 130 BlackBerry::Platform::String userStyleSheetLocation(); 131 void setUserStyleSheetLocation(const BlackBerry::Platform::String&); 132 133 // External link handlers 134 bool areLinksHandledExternally() const; 135 void setAreLinksHandledExternally(bool); 136 137 // BrowserField2 settings 138 void setAllowCrossSiteRequests(bool); 139 bool allowCrossSiteRequests() const; 140 bool isUserScalable() const; 141 void setUserScalable(bool); 142 int viewportWidth() const; 143 void setViewportWidth(int); 144 double initialScale() const; 145 void setInitialScale(double); 146 147 int firstScheduledLayoutDelay() const; 148 void setFirstScheduledLayoutDelay(int); 149 150 // Whether to include pattern: in the list of string patterns. 151 bool shouldHandlePatternUrls() const; 152 void setShouldHandlePatternUrls(bool); 153 154 bool areCookiesEnabled() const; 155 void setAreCookiesEnabled(bool); 156 157 // Web storage settings 158 bool isLocalStorageEnabled() const; 159 void setIsLocalStorageEnabled(bool); 160 161 bool isDatabasesEnabled() const; 162 void setIsDatabasesEnabled(bool); 163 164 bool isAppCacheEnabled() const; 165 void setIsAppCacheEnabled(bool); 166 167 unsigned long long localStorageQuota() const; 168 void setLocalStorageQuota(unsigned long long); 169 unsigned long long sessionStorageQuota() const; 170 void setSessionStorageQuota(unsigned long long); 171 172 // Page cache 173 void setMaximumPagesInCache(int); 174 int maximumPagesInCache() const; 175 176 BlackBerry::Platform::String localStoragePath() const; 177 void setLocalStoragePath(const BlackBerry::Platform::String&); 178 179 BlackBerry::Platform::String indexedDataBasePath() const; 180 void setIndexedDataBasePath(const BlackBerry::Platform::String&); 181 182 BlackBerry::Platform::String databasePath() const; 183 void setDatabasePath(const BlackBerry::Platform::String&); 184 185 BlackBerry::Platform::String appCachePath() const; 186 void setAppCachePath(const BlackBerry::Platform::String&); 187 188 BlackBerry::Platform::String pageGroupName() const; 189 void setPageGroupName(const BlackBerry::Platform::String&); 190 191 // FIXME: We shouldn't have an email mode. Instead, we should expose all email-related settings 192 // so that the email client can toggle them directly. 193 bool isEmailMode() const; 194 void setEmailMode(bool enable); 195 196 bool shouldRenderAnimationsOnScrollOrZoom() const; 197 void setShouldRenderAnimationsOnScrollOrZoom(bool enable); 198 199 unsigned overScrollColor() const; 200 void setOverScrollColor(unsigned); 201 202 bool isEnableDefaultOverScrollBackground() const; 203 void setEnableDefaultOverScrollBackground(bool); 204 205 unsigned backgroundColor() const; 206 void setBackgroundColor(unsigned); 207 208 bool isWritingDirectionRTL() const; 209 void setWritingDirectionRTL(bool); 210 211 bool useWebKitCache() const; 212 void setUseWebKitCache(bool); 213 214 bool isFrameFlatteningEnabled() const; 215 void setFrameFlatteningEnabled(bool); 216 217 unsigned maxPluginInstances() const; 218 void setMaxPluginInstances(unsigned num); 219 220 bool areWebSocketsEnabled() const; 221 void setWebSocketsEnabled(bool); 222 223 bool isSpatialNavigationEnabled() const; 224 void setSpatialNavigationEnabled(bool); 225 226 bool isAsynchronousSpellCheckingEnabled() const; 227 void setAsynchronousSpellCheckingEnabled(bool) const; 228 229 bool fullScreenVideoCapable() const; 230 void setFullScreenVideoCapable(bool); 231 232 bool isCredentialAutofillEnabled() const; 233 void setCredentialAutofillEnabled(bool); 234 235 bool isFormAutofillEnabled() const; 236 void setFormAutofillEnabled(bool); 237 238 double devicePixelRatio() const; 239 void setDevicePixelRatio(double); 240 241 bool isBackingStoreEnabled() const; 242 void setBackingStoreEnabled(bool); 243 244 bool applyDeviceScaleFactorInCompositor() const; 245 void setApplyDeviceScaleFactorInCompositor(bool); 246 247 bool isTextAutosizingEnabled() const; 248 void setTextAutosizingEnabled(bool); 249 250private: 251 WebSettingsPrivate* m_private; 252 WebSettings(); 253 DISABLE_COPY(WebSettings); 254}; 255 256/*! 257 @class WebSettingsTransaction 258 Defines a scope guard that suppresses didChangeSettings messages within its scope. 259 On destruction the guarded WebSettings object will dispatch exactly one didChangeSettings message. 260*/ 261class BLACKBERRY_EXPORT WebSettingsTransaction { 262public: 263 WebSettingsTransaction(WebSettings* settings) 264 : m_settings(settings) 265 , m_savedDelegate(0) 266 { 267 if (!settings) 268 return; 269 m_savedDelegate = settings->delegate(); 270 settings->setDelegate(0); 271 } 272 273 ~WebSettingsTransaction() 274 { 275 if (!m_settings || !m_savedDelegate) 276 return; 277 m_settings->setDelegate(m_savedDelegate); 278 m_savedDelegate->didChangeSettings(m_settings); 279 } 280 281private: 282 WebSettingsTransaction(const WebSettingsTransaction&); 283 WebSettingsTransaction& operator=(const WebSettingsTransaction&); 284 285 WebSettings* m_settings; 286 WebSettingsDelegate* m_savedDelegate; 287}; 288 289} // namespace WebKit 290} // namespace BlackBerry 291 292#endif // WebSettings_h 293