1/*
2 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef Settings_h
28#define Settings_h
29
30#include "AtomicString.h"
31#include "FontRenderingMode.h"
32#include "KURL.h"
33
34namespace WebCore {
35
36    class Page;
37
38    enum EditableLinkBehavior {
39        EditableLinkDefaultBehavior,
40        EditableLinkAlwaysLive,
41        EditableLinkOnlyLiveWithShiftKey,
42        EditableLinkLiveWhenNotFocused,
43        EditableLinkNeverLive
44    };
45
46    enum TextDirectionSubmenuInclusionBehavior {
47        TextDirectionSubmenuNeverIncluded,
48        TextDirectionSubmenuAutomaticallyIncluded,
49        TextDirectionSubmenuAlwaysIncluded
50    };
51
52    // There are multiple editing details that are different on Windows than Macintosh.
53    // We use a single switch for all of them. Some examples:
54    //
55    //    1) Clicking below the last line of an editable area puts the caret at the end
56    //       of the last line on Mac, but in the middle of the last line on Windows.
57    //    2) Pushing the down arrow key on the last line puts the caret at the end of the
58    //       last line on Mac, but does nothing on Windows. A similar case exists on the
59    //       top line.
60    //
61    // This setting is intended to control these sorts of behaviors. There are some other
62    // behaviors with individual function calls on EditorClient (smart copy and paste and
63    // selecting the space after a double click) that could be combined with this if
64    // if possible in the future.
65    enum EditingBehavior { EditingMacBehavior, EditingWindowsBehavior };
66
67    class Settings : public Noncopyable {
68    public:
69        Settings(Page*);
70
71#ifdef ANDROID_LAYOUT
72        // FIXME: How do we determine the margins other than guessing?
73        #define ANDROID_SSR_MARGIN_PADDING  3
74        #define ANDROID_FCTS_MARGIN_PADDING  10
75
76        enum LayoutAlgorithm {
77            kLayoutNormal,
78            kLayoutSSR,
79            kLayoutFitColumnToScreen
80        };
81#endif
82        void setStandardFontFamily(const AtomicString&);
83        const AtomicString& standardFontFamily() const { return m_standardFontFamily; }
84
85        void setFixedFontFamily(const AtomicString&);
86        const AtomicString& fixedFontFamily() const { return m_fixedFontFamily; }
87
88#ifdef ANDROID_LAYOUT
89        LayoutAlgorithm layoutAlgorithm() const { return m_layoutAlgorithm; }
90        void setLayoutAlgorithm(LayoutAlgorithm algorithm) { m_layoutAlgorithm = algorithm; }
91
92        bool useWideViewport() const { return m_useWideViewport; }
93        void setUseWideViewport(bool use) { m_useWideViewport = use; }
94#endif
95
96        void setSerifFontFamily(const AtomicString&);
97        const AtomicString& serifFontFamily() const { return m_serifFontFamily; }
98
99        void setSansSerifFontFamily(const AtomicString&);
100        const AtomicString& sansSerifFontFamily() const { return m_sansSerifFontFamily; }
101
102        void setCursiveFontFamily(const AtomicString&);
103        const AtomicString& cursiveFontFamily() const { return m_cursiveFontFamily; }
104
105        void setFantasyFontFamily(const AtomicString&);
106        const AtomicString& fantasyFontFamily() const { return m_fantasyFontFamily; }
107
108        void setMinimumFontSize(int);
109        int minimumFontSize() const { return m_minimumFontSize; }
110
111        void setMinimumLogicalFontSize(int);
112        int minimumLogicalFontSize() const { return m_minimumLogicalFontSize; }
113
114        void setDefaultFontSize(int);
115        int defaultFontSize() const { return m_defaultFontSize; }
116
117        void setDefaultFixedFontSize(int);
118        int defaultFixedFontSize() const { return m_defaultFixedFontSize; }
119
120        // Unlike areImagesEnabled, this only suppresses the network load of
121        // the image URL.  A cached image will still be rendered if requested.
122        void setLoadsImagesAutomatically(bool);
123        bool loadsImagesAutomatically() const { return m_loadsImagesAutomatically; }
124
125#ifdef ANDROID_BLOCK_NETWORK_IMAGE
126        void setBlockNetworkImage(bool);
127        bool blockNetworkImage() const { return m_blockNetworkImage; }
128#endif
129        void setJavaScriptEnabled(bool);
130        bool isJavaScriptEnabled() const { return m_isJavaScriptEnabled; }
131
132        void setWebSecurityEnabled(bool);
133        bool isWebSecurityEnabled() const { return m_isWebSecurityEnabled; }
134
135        void setAllowUniversalAccessFromFileURLs(bool);
136        bool allowUniversalAccessFromFileURLs() const { return m_allowUniversalAccessFromFileURLs; }
137
138        void setJavaScriptCanOpenWindowsAutomatically(bool);
139        bool javaScriptCanOpenWindowsAutomatically() const { return m_javaScriptCanOpenWindowsAutomatically; }
140
141        void setJavaEnabled(bool);
142        bool isJavaEnabled() const { return m_isJavaEnabled; }
143
144        void setImagesEnabled(bool);
145        bool areImagesEnabled() const { return m_areImagesEnabled; }
146
147        void setPluginsEnabled(bool);
148        bool arePluginsEnabled() const { return m_arePluginsEnabled; }
149
150#ifdef ANDROID_PLUGINS
151        void setPluginsOnDemand(bool onDemand) { m_pluginsOnDemand = onDemand; }
152        bool arePluginsOnDemand() const { return m_pluginsOnDemand; }
153#endif
154
155        void setDatabasesEnabled(bool);
156        bool databasesEnabled() const { return m_databasesEnabled; }
157
158        void setLocalStorageEnabled(bool);
159        bool localStorageEnabled() const { return m_localStorageEnabled; }
160
161        void setLocalStorageQuota(unsigned);
162        unsigned localStorageQuota() const { return m_localStorageQuota; }
163
164        void setPrivateBrowsingEnabled(bool);
165        bool privateBrowsingEnabled() const { return m_privateBrowsingEnabled; }
166
167        void setCaretBrowsingEnabled(bool);
168        bool caretBrowsingEnabled() const { return m_caretBrowsingEnabled; }
169
170        void setDefaultTextEncodingName(const String&);
171        const String& defaultTextEncodingName() const { return m_defaultTextEncodingName; }
172
173        void setUsesEncodingDetector(bool);
174        bool usesEncodingDetector() const { return m_usesEncodingDetector; }
175
176        void setUserStyleSheetLocation(const KURL&);
177        const KURL& userStyleSheetLocation() const { return m_userStyleSheetLocation; }
178
179        void setShouldPrintBackgrounds(bool);
180        bool shouldPrintBackgrounds() const { return m_shouldPrintBackgrounds; }
181
182        void setTextAreasAreResizable(bool);
183        bool textAreasAreResizable() const { return m_textAreasAreResizable; }
184
185        void setEditableLinkBehavior(EditableLinkBehavior);
186        EditableLinkBehavior editableLinkBehavior() const { return m_editableLinkBehavior; }
187
188        void setTextDirectionSubmenuInclusionBehavior(TextDirectionSubmenuInclusionBehavior);
189        TextDirectionSubmenuInclusionBehavior textDirectionSubmenuInclusionBehavior() const { return m_textDirectionSubmenuInclusionBehavior; }
190
191#if ENABLE(DASHBOARD_SUPPORT)
192        void setUsesDashboardBackwardCompatibilityMode(bool);
193        bool usesDashboardBackwardCompatibilityMode() const { return m_usesDashboardBackwardCompatibilityMode; }
194#endif
195
196        void setNeedsAdobeFrameReloadingQuirk(bool);
197        bool needsAcrobatFrameReloadingQuirk() const { return m_needsAdobeFrameReloadingQuirk; }
198
199        void setNeedsKeyboardEventDisambiguationQuirks(bool);
200        bool needsKeyboardEventDisambiguationQuirks() const { return m_needsKeyboardEventDisambiguationQuirks; }
201
202        void setTreatsAnyTextCSSLinkAsStylesheet(bool);
203        bool treatsAnyTextCSSLinkAsStylesheet() const { return m_treatsAnyTextCSSLinkAsStylesheet; }
204
205        void setNeedsLeopardMailQuirks(bool);
206        bool needsLeopardMailQuirks() const { return m_needsLeopardMailQuirks; }
207
208        void setNeedsTigerMailQuirks(bool);
209        bool needsTigerMailQuirks() const { return m_needsTigerMailQuirks; }
210
211        void setDOMPasteAllowed(bool);
212        bool isDOMPasteAllowed() const { return m_isDOMPasteAllowed; }
213
214        void setUsesPageCache(bool);
215        bool usesPageCache() const { return m_usesPageCache; }
216
217        void setShrinksStandaloneImagesToFit(bool);
218        bool shrinksStandaloneImagesToFit() const { return m_shrinksStandaloneImagesToFit; }
219
220        void setShowsURLsInToolTips(bool);
221        bool showsURLsInToolTips() const { return m_showsURLsInToolTips; }
222
223        void setFTPDirectoryTemplatePath(const String&);
224        const String& ftpDirectoryTemplatePath() const { return m_ftpDirectoryTemplatePath; }
225
226        void setForceFTPDirectoryListings(bool);
227        bool forceFTPDirectoryListings() const { return m_forceFTPDirectoryListings; }
228
229        void setDeveloperExtrasEnabled(bool);
230        bool developerExtrasEnabled() const { return m_developerExtrasEnabled; }
231
232        void setFrameSetFlatteningEnabled(bool);
233        bool frameSetFlatteningEnabled() const { return m_frameSetFlatteningEnabled; }
234
235#ifdef ANDROID_META_SUPPORT
236        void resetMetadataSettings();
237        void setMetadataSettings(const String& key, const String& value);
238
239        void setViewportWidth(int);
240        int viewportWidth() const { return m_viewport_width; }
241
242        void setViewportHeight(int);
243        int viewportHeight() const { return m_viewport_height; }
244
245        void setViewportInitialScale(int);
246        int viewportInitialScale() const { return m_viewport_initial_scale; }
247
248        void setViewportMinimumScale(int);
249        int viewportMinimumScale() const { return m_viewport_minimum_scale; }
250
251        void setViewportMaximumScale(int);
252        int viewportMaximumScale() const { return m_viewport_maximum_scale; }
253
254        void setViewportUserScalable(bool);
255        bool viewportUserScalable() const { return m_viewport_user_scalable; }
256
257        void setViewportTargetDensityDpi(int);
258        int viewportTargetDensityDpi() const { return m_viewport_target_densitydpi; }
259
260        void setFormatDetectionAddress(bool);
261        bool formatDetectionAddress() const { return m_format_detection_address; }
262
263        void setFormatDetectionEmail(bool);
264        bool formatDetectionEmail() const { return m_format_detection_email; }
265
266        void setFormatDetectionTelephone(bool);
267        bool formatDetectionTelephone() const { return m_format_detection_telephone; }
268#endif
269#ifdef ANDROID_MULTIPLE_WINDOWS
270        bool supportMultipleWindows() const { return m_supportMultipleWindows; }
271        void setSupportMultipleWindows(bool support) { m_supportMultipleWindows = support; }
272#endif
273        void setAuthorAndUserStylesEnabled(bool);
274        bool authorAndUserStylesEnabled() const { return m_authorAndUserStylesEnabled; }
275
276        void setFontRenderingMode(FontRenderingMode mode);
277        FontRenderingMode fontRenderingMode() const;
278
279        void setNeedsSiteSpecificQuirks(bool);
280        bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }
281
282        void setWebArchiveDebugModeEnabled(bool);
283        bool webArchiveDebugModeEnabled() const { return m_webArchiveDebugModeEnabled; }
284
285        void setLocalFileContentSniffingEnabled(bool);
286        bool localFileContentSniffingEnabled() const { return m_localFileContentSniffingEnabled; }
287
288        void setLocalStorageDatabasePath(const String&);
289        const String& localStorageDatabasePath() const { return m_localStorageDatabasePath; }
290
291        void setApplicationChromeMode(bool);
292        bool inApplicationChromeMode() const { return m_inApplicationChromeMode; }
293
294        void setOfflineWebApplicationCacheEnabled(bool);
295        bool offlineWebApplicationCacheEnabled() const { return m_offlineWebApplicationCacheEnabled; }
296
297        void setShouldPaintCustomScrollbars(bool);
298        bool shouldPaintCustomScrollbars() const { return m_shouldPaintCustomScrollbars; }
299
300        void setZoomsTextOnly(bool);
301        bool zoomsTextOnly() const { return m_zoomsTextOnly; }
302
303        void setEnforceCSSMIMETypeInStrictMode(bool);
304        bool enforceCSSMIMETypeInStrictMode() { return m_enforceCSSMIMETypeInStrictMode; }
305
306        void setMaximumDecodedImageSize(size_t size) { m_maximumDecodedImageSize = size; }
307        size_t maximumDecodedImageSize() const { return m_maximumDecodedImageSize; }
308
309#if USE(SAFARI_THEME)
310        // Windows debugging pref (global) for switching between the Aqua look and a native windows look.
311        static void setShouldPaintNativeControls(bool);
312        static bool shouldPaintNativeControls() { return gShouldPaintNativeControls; }
313#endif
314
315        void setAllowScriptsToCloseWindows(bool);
316        bool allowScriptsToCloseWindows() const { return m_allowScriptsToCloseWindows; }
317
318        void setEditingBehavior(EditingBehavior behavior) { m_editingBehavior = behavior; }
319        EditingBehavior editingBehavior() const { return static_cast<EditingBehavior>(m_editingBehavior); }
320
321        void setDownloadableBinaryFontsEnabled(bool);
322        bool downloadableBinaryFontsEnabled() const { return m_downloadableBinaryFontsEnabled; }
323
324        void setXSSAuditorEnabled(bool);
325        bool xssAuditorEnabled() const { return m_xssAuditorEnabled; }
326
327        void setAcceleratedCompositingEnabled(bool);
328        bool acceleratedCompositingEnabled() const { return m_acceleratedCompositingEnabled; }
329
330        void setShowDebugBorders(bool);
331        bool showDebugBorders() const { return m_showDebugBorders; }
332
333        void setShowRepaintCounter(bool);
334        bool showRepaintCounter() const { return m_showRepaintCounter; }
335
336        void setExperimentalNotificationsEnabled(bool);
337        bool experimentalNotificationsEnabled() const { return m_experimentalNotificationsEnabled; }
338
339#if PLATFORM(WIN) || (OS(WINDOWS) && PLATFORM(WX))
340        static void setShouldUseHighResolutionTimers(bool);
341        static bool shouldUseHighResolutionTimers() { return gShouldUseHighResolutionTimers; }
342#endif
343
344        void setPluginAllowedRunTime(unsigned);
345        unsigned pluginAllowedRunTime() const { return m_pluginAllowedRunTime; }
346
347        void setWebGLEnabled(bool);
348        bool webGLEnabled() const { return m_webGLEnabled; }
349
350        void setGeolocationEnabled(bool);
351        bool geolocationEnabled() const { return m_geolocationEnabled; }
352
353        void setLoadDeferringEnabled(bool);
354        bool loadDeferringEnabled() const { return m_loadDeferringEnabled; }
355
356    private:
357        Page* m_page;
358
359        String m_defaultTextEncodingName;
360        String m_ftpDirectoryTemplatePath;
361        String m_localStorageDatabasePath;
362        KURL m_userStyleSheetLocation;
363        AtomicString m_standardFontFamily;
364        AtomicString m_fixedFontFamily;
365        AtomicString m_serifFontFamily;
366        AtomicString m_sansSerifFontFamily;
367        AtomicString m_cursiveFontFamily;
368        AtomicString m_fantasyFontFamily;
369#ifdef ANDROID_LAYOUT
370        LayoutAlgorithm m_layoutAlgorithm;
371#endif
372        EditableLinkBehavior m_editableLinkBehavior;
373        TextDirectionSubmenuInclusionBehavior m_textDirectionSubmenuInclusionBehavior;
374        int m_minimumFontSize;
375        int m_minimumLogicalFontSize;
376        int m_defaultFontSize;
377        int m_defaultFixedFontSize;
378#ifdef ANDROID_META_SUPPORT
379        // range is from 200 to 10,000. 0 is a special value means device-width.
380        // default is -1, which means undefined.
381        int m_viewport_width;
382        // range is from 223 to 10,000. 0 is a special value means device-height
383        // default is -1, which means undefined.
384        int m_viewport_height;
385        // range is from 1 to 1000 in percent. default is 0, which means undefined.
386        int m_viewport_initial_scale;
387        // range is from 1 to 1000 in percent. default is 0, which means undefined.
388        int m_viewport_minimum_scale;
389        // range is from 1 to 1000 in percent. default is 0, which means undefined.
390        int m_viewport_maximum_scale;
391        // default is yes
392        bool m_viewport_user_scalable : 1;
393        // range is from 70 to 400. 0 is a special value means device-dpi
394        // default is -1, which means undefined.
395        int m_viewport_target_densitydpi;
396        // default is yes
397        bool m_format_detection_telephone : 1;
398        // default is yes
399        bool m_format_detection_address : 1;
400        // default is yes
401        bool m_format_detection_email : 1;
402#endif
403#ifdef ANDROID_LAYOUT
404        bool m_useWideViewport : 1;
405#endif
406#ifdef ANDROID_MULTIPLE_WINDOWS
407        bool m_supportMultipleWindows : 1;
408#endif
409#ifdef ANDROID_BLOCK_NETWORK_IMAGE
410        bool m_blockNetworkImage : 1;
411#endif
412        size_t m_maximumDecodedImageSize;
413        unsigned m_localStorageQuota;
414        unsigned m_pluginAllowedRunTime;
415        bool m_isJavaEnabled : 1;
416        bool m_loadsImagesAutomatically : 1;
417        bool m_privateBrowsingEnabled : 1;
418        bool m_caretBrowsingEnabled : 1;
419        bool m_areImagesEnabled : 1;
420        bool m_arePluginsEnabled : 1;
421        bool m_databasesEnabled : 1;
422        bool m_localStorageEnabled : 1;
423        bool m_isJavaScriptEnabled : 1;
424        bool m_isWebSecurityEnabled : 1;
425        bool m_allowUniversalAccessFromFileURLs: 1;
426        bool m_javaScriptCanOpenWindowsAutomatically : 1;
427        bool m_shouldPrintBackgrounds : 1;
428        bool m_textAreasAreResizable : 1;
429#if ENABLE(DASHBOARD_SUPPORT)
430        bool m_usesDashboardBackwardCompatibilityMode : 1;
431#endif
432        bool m_needsAdobeFrameReloadingQuirk : 1;
433        bool m_needsKeyboardEventDisambiguationQuirks : 1;
434        bool m_treatsAnyTextCSSLinkAsStylesheet : 1;
435        bool m_needsLeopardMailQuirks : 1;
436        bool m_needsTigerMailQuirks : 1;
437        bool m_isDOMPasteAllowed : 1;
438        bool m_shrinksStandaloneImagesToFit : 1;
439        bool m_usesPageCache: 1;
440        bool m_showsURLsInToolTips : 1;
441        bool m_forceFTPDirectoryListings : 1;
442        bool m_developerExtrasEnabled : 1;
443        bool m_authorAndUserStylesEnabled : 1;
444        bool m_needsSiteSpecificQuirks : 1;
445        unsigned m_fontRenderingMode : 1;
446        bool m_frameSetFlatteningEnabled : 1;
447        bool m_webArchiveDebugModeEnabled : 1;
448        bool m_localFileContentSniffingEnabled : 1;
449        bool m_inApplicationChromeMode : 1;
450        bool m_offlineWebApplicationCacheEnabled : 1;
451        bool m_shouldPaintCustomScrollbars : 1;
452        bool m_zoomsTextOnly : 1;
453        bool m_enforceCSSMIMETypeInStrictMode : 1;
454        bool m_usesEncodingDetector : 1;
455        bool m_allowScriptsToCloseWindows : 1;
456        unsigned m_editingBehavior : 1;
457        bool m_downloadableBinaryFontsEnabled : 1;
458        bool m_xssAuditorEnabled : 1;
459        bool m_acceleratedCompositingEnabled : 1;
460        bool m_showDebugBorders : 1;
461        bool m_showRepaintCounter : 1;
462        bool m_experimentalNotificationsEnabled : 1;
463        bool m_webGLEnabled : 1;
464        bool m_geolocationEnabled : 1;
465        bool m_loadDeferringEnabled : 1;
466#ifdef ANDROID_PLUGINS
467        bool m_pluginsOnDemand : 1;
468#endif
469
470#if USE(SAFARI_THEME)
471        static bool gShouldPaintNativeControls;
472#endif
473#if PLATFORM(WIN) || (OS(WINDOWS) && PLATFORM(WX))
474        static bool gShouldUseHighResolutionTimers;
475#endif
476    };
477
478} // namespace WebCore
479
480#endif // Settings_h
481