47b7fe51a05d7255d28b4043be11badd041ce1aa
[WebKit-https.git] / Source / WebCore / page / SettingsBase.h
1 /*
2  * Copyright (C) 2003-2016 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 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 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 #pragma once
28
29 #include "ClipboardAccessPolicy.h"
30 #include "ContentType.h"
31 #include "EditingBehaviorTypes.h"
32 #include "IntSize.h"
33 #include "SecurityOrigin.h"
34 #include "StorageMap.h"
35 #include "TextFlags.h"
36 #include "Timer.h"
37 #include "URL.h"
38 #include "WritingMode.h"
39 #include <runtime/RuntimeFlags.h>
40 #include <unicode/uscript.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/RefCounted.h>
43 #include <wtf/text/AtomicString.h>
44 #include <wtf/text/AtomicStringHash.h>
45
46 #if ENABLE(DATA_DETECTION)
47 #include "DataDetection.h"
48 #endif
49
50 namespace WebCore {
51
52 class FontGenericFamilies;
53 class Page;
54
55 enum EditableLinkBehavior {
56     EditableLinkDefaultBehavior,
57     EditableLinkAlwaysLive,
58     EditableLinkOnlyLiveWithShiftKey,
59     EditableLinkLiveWhenNotFocused,
60     EditableLinkNeverLive
61 };
62
63 enum TextDirectionSubmenuInclusionBehavior {
64     TextDirectionSubmenuNeverIncluded,
65     TextDirectionSubmenuAutomaticallyIncluded,
66     TextDirectionSubmenuAlwaysIncluded
67 };
68
69 enum DebugOverlayRegionFlags {
70     NonFastScrollableRegion = 1 << 0,
71     WheelEventHandlerRegion = 1 << 1,
72 };
73
74 enum class UserInterfaceDirectionPolicy {
75     Content,
76     System
77 };
78
79 enum PDFImageCachingPolicy {
80     PDFImageCachingEnabled,
81     PDFImageCachingBelowMemoryLimit,
82     PDFImageCachingDisabled,
83     PDFImageCachingClipBoundsOnly,
84 #if PLATFORM(IOS)
85     PDFImageCachingDefault = PDFImageCachingBelowMemoryLimit
86 #else
87     PDFImageCachingDefault = PDFImageCachingEnabled
88 #endif
89 };
90
91 enum class FrameFlattening {
92     Disabled,
93     EnabledForNonFullScreenIFrames,
94     FullyEnabled
95 };
96
97 typedef unsigned DebugOverlayRegions;
98
99 class SettingsBase {
100     WTF_MAKE_NONCOPYABLE(SettingsBase); WTF_MAKE_FAST_ALLOCATED;
101 public:
102     ~SettingsBase();
103
104     void pageDestroyed() { m_page = nullptr; }
105
106     enum class FontLoadTimingOverride { None, Block, Swap, Failure };
107
108     enum class ForcedAccessibilityValue { System, On, Off };
109     static const SettingsBase::ForcedAccessibilityValue defaultForcedColorsAreInvertedAccessibilityValue = ForcedAccessibilityValue::System;
110     static const SettingsBase::ForcedAccessibilityValue defaultForcedDisplayIsMonochromeAccessibilityValue = ForcedAccessibilityValue::System;
111     static const SettingsBase::ForcedAccessibilityValue defaultForcedPrefersReducedMotionAccessibilityValue = ForcedAccessibilityValue::System;
112
113     WEBCORE_EXPORT void setStandardFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
114     WEBCORE_EXPORT const AtomicString& standardFontFamily(UScriptCode = USCRIPT_COMMON) const;
115
116     WEBCORE_EXPORT void setFixedFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
117     WEBCORE_EXPORT const AtomicString& fixedFontFamily(UScriptCode = USCRIPT_COMMON) const;
118
119     WEBCORE_EXPORT void setSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
120     WEBCORE_EXPORT const AtomicString& serifFontFamily(UScriptCode = USCRIPT_COMMON) const;
121
122     WEBCORE_EXPORT void setSansSerifFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
123     WEBCORE_EXPORT const AtomicString& sansSerifFontFamily(UScriptCode = USCRIPT_COMMON) const;
124
125     WEBCORE_EXPORT void setCursiveFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
126     WEBCORE_EXPORT const AtomicString& cursiveFontFamily(UScriptCode = USCRIPT_COMMON) const;
127
128     WEBCORE_EXPORT void setFantasyFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
129     WEBCORE_EXPORT const AtomicString& fantasyFontFamily(UScriptCode = USCRIPT_COMMON) const;
130
131     WEBCORE_EXPORT void setPictographFontFamily(const AtomicString&, UScriptCode = USCRIPT_COMMON);
132     WEBCORE_EXPORT const AtomicString& pictographFontFamily(UScriptCode = USCRIPT_COMMON) const;
133
134     WEBCORE_EXPORT static bool defaultTextAutosizingEnabled();
135     WEBCORE_EXPORT static float defaultMinimumZoomFontSize();
136
137     // Only set by Layout Tests.
138     WEBCORE_EXPORT void setMediaTypeOverride(const String&);
139     const String& mediaTypeOverride() const { return m_mediaTypeOverride; }
140
141     // Unlike areImagesEnabled, this only suppresses the network load of
142     // the image URL.  A cached image will still be rendered if requested.
143     WEBCORE_EXPORT void setLoadsImagesAutomatically(bool);
144     bool loadsImagesAutomatically() const { return m_loadsImagesAutomatically; }
145
146     // Clients that execute script should call ScriptController::canExecuteScripts()
147     // instead of this function. ScriptController::canExecuteScripts() checks the
148     // HTML sandbox, plug-in sandboxing, and other important details.
149     bool isScriptEnabled() const { return m_isScriptEnabled; }
150     WEBCORE_EXPORT void setScriptEnabled(bool);
151
152
153     WEBCORE_EXPORT void setImagesEnabled(bool);
154     bool areImagesEnabled() const { return m_areImagesEnabled; }
155
156     WEBCORE_EXPORT void setPluginsEnabled(bool);
157     bool arePluginsEnabled() const { return m_arePluginsEnabled; }
158
159     WEBCORE_EXPORT void setDNSPrefetchingEnabled(bool);
160     bool dnsPrefetchingEnabled() const { return m_dnsPrefetchingEnabled; }
161
162     WEBCORE_EXPORT void setUserStyleSheetLocation(const URL&);
163     const URL& userStyleSheetLocation() const { return m_userStyleSheetLocation; }
164
165     WEBCORE_EXPORT void setMinimumDOMTimerInterval(Seconds); // Initialized to DOMTimer::defaultMinimumInterval().
166     Seconds minimumDOMTimerInterval() const { return m_minimumDOMTimerInterval; }
167
168     WEBCORE_EXPORT void setLayoutInterval(Seconds);
169     Seconds layoutInterval() const { return m_layoutInterval; }
170
171     bool hiddenPageDOMTimerThrottlingEnabled() const { return m_hiddenPageDOMTimerThrottlingEnabled; }
172     WEBCORE_EXPORT void setHiddenPageDOMTimerThrottlingEnabled(bool);
173     bool hiddenPageDOMTimerThrottlingAutoIncreases() const { return m_hiddenPageDOMTimerThrottlingAutoIncreases; }
174     WEBCORE_EXPORT void setHiddenPageDOMTimerThrottlingAutoIncreases(bool);
175
176     WEBCORE_EXPORT void setUsesPageCache(bool);
177     bool usesPageCache() const { return m_usesPageCache; }
178         
179 #if ENABLE(RESOURCE_USAGE)
180     bool resourceUsageOverlayVisible() const { return m_resourceUsageOverlayVisible; }
181     WEBCORE_EXPORT void setResourceUsageOverlayVisible(bool);
182 #endif
183
184 #if PLATFORM(WIN)
185     static void setShouldUseHighResolutionTimers(bool);
186     static bool shouldUseHighResolutionTimers() { return gShouldUseHighResolutionTimers; }
187 #endif
188
189     static bool isPostLoadCPUUsageMeasurementEnabled();
190     static bool isPostBackgroundingCPUUsageMeasurementEnabled();
191     static bool isPerActivityStateCPUUsageMeasurementEnabled();
192
193     static bool isPostLoadMemoryUsageMeasurementEnabled();
194     static bool isPostBackgroundingMemoryUsageMeasurementEnabled();
195
196     static bool globalConstRedeclarationShouldThrow();
197
198     WEBCORE_EXPORT void setBackgroundShouldExtendBeyondPage(bool);
199     bool backgroundShouldExtendBeyondPage() const { return m_backgroundShouldExtendBeyondPage; }
200
201 #if USE(AVFOUNDATION)
202     WEBCORE_EXPORT static void setAVFoundationEnabled(bool flag);
203     static bool isAVFoundationEnabled() { return gAVFoundationEnabled; }
204     WEBCORE_EXPORT static void setAVFoundationNSURLSessionEnabled(bool flag);
205     static bool isAVFoundationNSURLSessionEnabled() { return gAVFoundationNSURLSessionEnabled; }
206 #endif
207
208 #if PLATFORM(COCOA)
209     WEBCORE_EXPORT static void setQTKitEnabled(bool flag);
210     static bool isQTKitEnabled() { return gQTKitEnabled; }
211 #else
212     static bool isQTKitEnabled() { return false; }
213 #endif
214
215 #if USE(GSTREAMER)
216     WEBCORE_EXPORT static void setGStreamerEnabled(bool flag);
217     static bool isGStreamerEnabled() { return gGStreamerEnabled; }
218 #endif
219
220     static const unsigned defaultMaximumHTMLParserDOMTreeDepth = 512;
221     static const unsigned defaultMaximumRenderTreeDepth = 512;
222
223     WEBCORE_EXPORT static void setMockScrollbarsEnabled(bool flag);
224     WEBCORE_EXPORT static bool mockScrollbarsEnabled();
225
226     WEBCORE_EXPORT static void setUsesOverlayScrollbars(bool flag);
227     static bool usesOverlayScrollbars();
228
229     WEBCORE_EXPORT static void setUsesMockScrollAnimator(bool);
230     static bool usesMockScrollAnimator();
231
232     WEBCORE_EXPORT void setStorageBlockingPolicy(SecurityOrigin::StorageBlockingPolicy);
233     SecurityOrigin::StorageBlockingPolicy storageBlockingPolicy() const { return m_storageBlockingPolicy; }
234
235     WEBCORE_EXPORT void setScrollingPerformanceLoggingEnabled(bool);
236     bool scrollingPerformanceLoggingEnabled() { return m_scrollingPerformanceLoggingEnabled; }
237
238     WEBCORE_EXPORT static void setShouldRespectPriorityInCSSAttributeSetters(bool);
239     static bool shouldRespectPriorityInCSSAttributeSetters();
240
241     bool hiddenPageCSSAnimationSuspensionEnabled() const { return m_hiddenPageCSSAnimationSuspensionEnabled; }
242     WEBCORE_EXPORT void setHiddenPageCSSAnimationSuspensionEnabled(bool);
243
244     static bool lowPowerVideoAudioBufferSizeEnabled() { return gLowPowerVideoAudioBufferSizeEnabled; }
245     WEBCORE_EXPORT static void setLowPowerVideoAudioBufferSizeEnabled(bool);
246
247     static bool resourceLoadStatisticsEnabled() { return gResourceLoadStatisticsEnabledEnabled; }
248     WEBCORE_EXPORT static void setResourceLoadStatisticsEnabled(bool);
249
250 #if PLATFORM(IOS)
251     WEBCORE_EXPORT static void setAudioSessionCategoryOverride(unsigned);
252     static unsigned audioSessionCategoryOverride();
253
254     WEBCORE_EXPORT static void setNetworkDataUsageTrackingEnabled(bool);
255     static bool networkDataUsageTrackingEnabled();
256
257     WEBCORE_EXPORT static void setNetworkInterfaceName(const String&);
258     static const String& networkInterfaceName();
259
260 #if HAVE(AVKIT)
261     static void setAVKitEnabled(bool flag) { gAVKitEnabled = flag; }
262 #endif
263     static bool avKitEnabled() { return gAVKitEnabled; }
264
265     static void setShouldOptOutOfNetworkStateObservation(bool flag) { gShouldOptOutOfNetworkStateObservation = flag; }
266     static bool shouldOptOutOfNetworkStateObservation() { return gShouldOptOutOfNetworkStateObservation; }
267 #endif
268
269 #if USE(AUDIO_SESSION)
270     static void setShouldManageAudioSessionCategory(bool flag) { gManageAudioSession = flag; }
271     static bool shouldManageAudioSessionCategory() { return gManageAudioSession; }
272 #endif
273
274     static void setCustomPasteboardDataEnabled(bool enabled) { gCustomPasteboardDataEnabled = enabled; }
275     static bool customPasteboardDataEnabled() { return gCustomPasteboardDataEnabled; }
276     WEBCORE_EXPORT static bool defaultCustomPasteboardDataEnabled();
277     
278 #if ENABLE(MEDIA_STREAM)
279     static bool mockCaptureDevicesEnabled();
280     WEBCORE_EXPORT static void setMockCaptureDevicesEnabled(bool);
281
282     bool mediaCaptureRequiresSecureConnection() const;
283     WEBCORE_EXPORT static void setMediaCaptureRequiresSecureConnection(bool);
284 #endif
285
286     WEBCORE_EXPORT static void setAllowsAnySSLCertificate(bool);
287     static bool allowsAnySSLCertificate();
288
289     WEBCORE_EXPORT static const String& defaultMediaContentTypesRequiringHardwareSupport();
290     WEBCORE_EXPORT void setMediaContentTypesRequiringHardwareSupport(const Vector<ContentType>&);
291     WEBCORE_EXPORT void setMediaContentTypesRequiringHardwareSupport(const String&);
292     const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const { return m_mediaContentTypesRequiringHardwareSupport; }
293
294 protected:
295     explicit SettingsBase(Page*);
296
297     void initializeDefaultFontFamilies();
298
299     Page* m_page;
300
301     String m_mediaTypeOverride { "screen" };
302     URL m_userStyleSheetLocation;
303     const std::unique_ptr<FontGenericFamilies> m_fontGenericFamilies;
304     SecurityOrigin::StorageBlockingPolicy m_storageBlockingPolicy { SecurityOrigin::AllowAllStorage };
305     Seconds m_layoutInterval;
306     Seconds m_minimumDOMTimerInterval;
307
308     bool m_loadsImagesAutomatically : 1;
309     bool m_areImagesEnabled : 1;
310     bool m_arePluginsEnabled : 1;
311     bool m_isScriptEnabled : 1;
312     bool m_usesPageCache : 1;
313     bool m_showTiledScrollingIndicator : 1;
314     bool m_backgroundShouldExtendBeyondPage : 1;
315     bool m_dnsPrefetchingEnabled : 1;
316     bool m_scrollingPerformanceLoggingEnabled : 1;
317
318     Timer m_setImageLoadingSettingsTimer;
319     void imageLoadingSettingsTimerFired();
320
321     bool m_hiddenPageDOMTimerThrottlingEnabled : 1;
322     bool m_hiddenPageCSSAnimationSuspensionEnabled : 1;
323
324 #if ENABLE(RESOURCE_USAGE)
325     bool m_resourceUsageOverlayVisible { false };
326 #endif
327
328     bool m_hiddenPageDOMTimerThrottlingAutoIncreases { false };
329
330 #if USE(AVFOUNDATION)
331     WEBCORE_EXPORT static bool gAVFoundationEnabled;
332     WEBCORE_EXPORT static bool gAVFoundationNSURLSessionEnabled;
333 #endif
334
335 #if PLATFORM(COCOA)
336     WEBCORE_EXPORT static bool gQTKitEnabled;
337 #endif
338
339 #if USE(GSTREAMER)
340     WEBCORE_EXPORT static bool gGStreamerEnabled;
341 #endif
342
343     static bool gMockScrollbarsEnabled;
344     static bool gUsesOverlayScrollbars;
345     static bool gMockScrollAnimatorEnabled;
346
347 #if PLATFORM(WIN)
348     static bool gShouldUseHighResolutionTimers;
349 #endif
350     static bool gShouldRespectPriorityInCSSAttributeSetters;
351 #if PLATFORM(IOS)
352     static bool gNetworkDataUsageTrackingEnabled;
353     WEBCORE_EXPORT static bool gAVKitEnabled;
354     WEBCORE_EXPORT static bool gShouldOptOutOfNetworkStateObservation;
355 #endif
356     WEBCORE_EXPORT static bool gManageAudioSession;
357     WEBCORE_EXPORT static bool gCustomPasteboardDataEnabled;
358     
359 #if ENABLE(MEDIA_STREAM)
360     static bool gMockCaptureDevicesEnabled;
361     static bool gMediaCaptureRequiresSecureConnection;
362 #endif
363
364     static bool gLowPowerVideoAudioBufferSizeEnabled;
365     static bool gResourceLoadStatisticsEnabledEnabled;
366     static bool gAllowsAnySSLCertificate;
367
368     Vector<ContentType> m_mediaContentTypesRequiringHardwareSupport;
369 };
370
371 inline bool SettingsBase::isPostLoadCPUUsageMeasurementEnabled()
372 {
373 #if PLATFORM(COCOA)
374     return true;
375 #else
376     return false;
377 #endif
378 }
379
380 inline bool SettingsBase::isPostBackgroundingCPUUsageMeasurementEnabled()
381 {
382 #if PLATFORM(MAC)
383     return true;
384 #else
385     return false;
386 #endif
387 }
388
389 inline bool SettingsBase::isPerActivityStateCPUUsageMeasurementEnabled()
390 {
391 #if PLATFORM(MAC)
392     return true;
393 #else
394     return false;
395 #endif
396 }
397
398 inline bool SettingsBase::isPostLoadMemoryUsageMeasurementEnabled()
399 {
400 #if PLATFORM(COCOA)
401     return true;
402 #else
403     return false;
404 #endif
405 }
406
407 inline bool SettingsBase::isPostBackgroundingMemoryUsageMeasurementEnabled()
408 {
409 #if PLATFORM(MAC)
410     return true;
411 #else
412     return false;
413 #endif
414 }
415
416 } // namespace WebCore