4afc6fa8ad2dc4bd367057afa624eeb08943b9b6
[WebKit-https.git] / Source / WebCore / page / DeprecatedGlobalSettings.cpp
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2009, 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. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "config.h"
27 #include "DeprecatedGlobalSettings.h"
28
29 #include "AudioSession.h"
30 #include "HTMLMediaElement.h"
31 #include "RuntimeApplicationChecks.h"
32 #include <wtf/NeverDestroyed.h>
33
34 #if ENABLE(MEDIA_STREAM)
35 #include "MockRealtimeMediaSourceCenter.h"
36
37 #if USE(AVFOUNDATION)
38 #include "RealtimeMediaSourceCenterMac.h"
39 #endif
40 #endif
41
42 #if PLATFORM(COCOA)
43 #include <wtf/spi/darwin/dyldSPI.h>
44 #endif
45
46 namespace WebCore {
47
48 #if USE(AVFOUNDATION)
49 bool DeprecatedGlobalSettings::gAVFoundationEnabled = true;
50 bool DeprecatedGlobalSettings::gAVFoundationNSURLSessionEnabled = true;
51 #endif
52
53 #if PLATFORM(COCOA)
54 bool DeprecatedGlobalSettings::gQTKitEnabled = false;
55 #endif
56
57 #if USE(GSTREAMER)
58 bool DeprecatedGlobalSettings::gGStreamerEnabled = true;
59 #endif
60
61 bool DeprecatedGlobalSettings::gMockScrollbarsEnabled = false;
62 bool DeprecatedGlobalSettings::gUsesOverlayScrollbars = false;
63 bool DeprecatedGlobalSettings::gMockScrollAnimatorEnabled = false;
64
65 #if ENABLE(MEDIA_STREAM)
66 bool DeprecatedGlobalSettings::gMockCaptureDevicesEnabled = false;
67 bool DeprecatedGlobalSettings::gMediaCaptureRequiresSecureConnection = true;
68 #endif
69
70 #if PLATFORM(WIN)
71 bool DeprecatedGlobalSettings::gShouldUseHighResolutionTimers = true;
72 #endif
73     
74 bool DeprecatedGlobalSettings::gShouldRespectPriorityInCSSAttributeSetters = false;
75 bool DeprecatedGlobalSettings::gLowPowerVideoAudioBufferSizeEnabled = false;
76 bool DeprecatedGlobalSettings::gResourceLoadStatisticsEnabledEnabled = false;
77 bool DeprecatedGlobalSettings::gAllowsAnySSLCertificate = false;
78
79 #if PLATFORM(IOS)
80 bool DeprecatedGlobalSettings::gNetworkDataUsageTrackingEnabled = false;
81 bool DeprecatedGlobalSettings::gAVKitEnabled = false;
82 bool DeprecatedGlobalSettings::gShouldOptOutOfNetworkStateObservation = false;
83 #endif
84 bool DeprecatedGlobalSettings::gManageAudioSession = false;
85 bool DeprecatedGlobalSettings::gCustomPasteboardDataEnabled = false;
86
87 bool DeprecatedGlobalSettings::defaultCustomPasteboardDataEnabled()
88 {
89 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110300
90     return IOSApplication::isMobileSafari() || dyld_get_program_sdk_version() >= DYLD_IOS_VERSION_11_3;
91 #elif PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
92     return MacApplication::isSafari() || dyld_get_program_sdk_version() > DYLD_MACOSX_VERSION_10_13;
93 #elif PLATFORM(MAC)
94     return MacApplication::isSafari();
95 #else
96     return false;
97 #endif
98 }
99
100 #if PLATFORM(WIN)
101 void DeprecatedGlobalSettings::setShouldUseHighResolutionTimers(bool shouldUseHighResolutionTimers)
102 {
103     gShouldUseHighResolutionTimers = shouldUseHighResolutionTimers;
104 }
105 #endif
106
107 #if USE(AVFOUNDATION)
108 void DeprecatedGlobalSettings::setAVFoundationEnabled(bool enabled)
109 {
110     if (gAVFoundationEnabled == enabled)
111         return;
112
113     gAVFoundationEnabled = enabled;
114     HTMLMediaElement::resetMediaEngines();
115 }
116
117 void DeprecatedGlobalSettings::setAVFoundationNSURLSessionEnabled(bool enabled)
118 {
119     if (gAVFoundationNSURLSessionEnabled == enabled)
120         return;
121
122     gAVFoundationNSURLSessionEnabled = enabled;
123 }
124 #endif
125
126 #if PLATFORM(COCOA)
127 void DeprecatedGlobalSettings::setQTKitEnabled(bool enabled)
128 {
129     if (gQTKitEnabled == enabled)
130         return;
131
132     gQTKitEnabled = enabled;
133     HTMLMediaElement::resetMediaEngines();
134 }
135 #endif
136
137 #if USE(GSTREAMER)
138 void DeprecatedGlobalSettings::setGStreamerEnabled(bool enabled)
139 {
140     if (gGStreamerEnabled == enabled)
141         return;
142
143     gGStreamerEnabled = enabled;
144
145 #if ENABLE(VIDEO)
146     HTMLMediaElement::resetMediaEngines();
147 #endif
148 }
149 #endif
150
151 #if ENABLE(MEDIA_STREAM)
152 bool DeprecatedGlobalSettings::mockCaptureDevicesEnabled()
153 {
154     return gMockCaptureDevicesEnabled;
155 }
156
157 void DeprecatedGlobalSettings::setMockCaptureDevicesEnabled(bool enabled)
158 {
159     gMockCaptureDevicesEnabled = enabled;
160     MockRealtimeMediaSourceCenter::setMockRealtimeMediaSourceCenterEnabled(enabled);
161 }
162
163 bool DeprecatedGlobalSettings::mediaCaptureRequiresSecureConnection()
164 {
165     return gMediaCaptureRequiresSecureConnection;
166 }
167
168 void DeprecatedGlobalSettings::setMediaCaptureRequiresSecureConnection(bool mediaCaptureRequiresSecureConnection)
169 {
170     gMediaCaptureRequiresSecureConnection = mediaCaptureRequiresSecureConnection;
171 }
172 #endif
173
174 // It's very important that this setting doesn't change in the middle of a document's lifetime.
175 // The Mac port uses this flag when registering and deregistering platform-dependent scrollbar
176 // objects. Therefore, if this changes at an unexpected time, deregistration may not happen
177 // correctly, which may cause the platform to follow dangling pointers.
178 void DeprecatedGlobalSettings::setMockScrollbarsEnabled(bool flag)
179 {
180     gMockScrollbarsEnabled = flag;
181     // FIXME: This should update scroll bars in existing pages.
182 }
183
184 bool DeprecatedGlobalSettings::mockScrollbarsEnabled()
185 {
186     return gMockScrollbarsEnabled;
187 }
188
189 void DeprecatedGlobalSettings::setUsesOverlayScrollbars(bool flag)
190 {
191     gUsesOverlayScrollbars = flag;
192     // FIXME: This should update scroll bars in existing pages.
193 }
194
195 bool DeprecatedGlobalSettings::usesOverlayScrollbars()
196 {
197     return gUsesOverlayScrollbars;
198 }
199
200 void DeprecatedGlobalSettings::setUsesMockScrollAnimator(bool flag)
201 {
202     gMockScrollAnimatorEnabled = flag;
203 }
204
205 bool DeprecatedGlobalSettings::usesMockScrollAnimator()
206 {
207     return gMockScrollAnimatorEnabled;
208 }
209
210 void DeprecatedGlobalSettings::setShouldRespectPriorityInCSSAttributeSetters(bool flag)
211 {
212     gShouldRespectPriorityInCSSAttributeSetters = flag;
213 }
214
215 bool DeprecatedGlobalSettings::shouldRespectPriorityInCSSAttributeSetters()
216 {
217     return gShouldRespectPriorityInCSSAttributeSetters;
218 }
219
220 void DeprecatedGlobalSettings::setLowPowerVideoAudioBufferSizeEnabled(bool flag)
221 {
222     gLowPowerVideoAudioBufferSizeEnabled = flag;
223 }
224
225 void DeprecatedGlobalSettings::setResourceLoadStatisticsEnabled(bool flag)
226 {
227     gResourceLoadStatisticsEnabledEnabled = flag;
228 }
229
230 #if PLATFORM(IOS)
231 void DeprecatedGlobalSettings::setAudioSessionCategoryOverride(unsigned sessionCategory)
232 {
233     AudioSession::sharedSession().setCategoryOverride(static_cast<AudioSession::CategoryType>(sessionCategory));
234 }
235
236 unsigned DeprecatedGlobalSettings::audioSessionCategoryOverride()
237 {
238     return AudioSession::sharedSession().categoryOverride();
239 }
240
241 void DeprecatedGlobalSettings::setNetworkDataUsageTrackingEnabled(bool trackingEnabled)
242 {
243     gNetworkDataUsageTrackingEnabled = trackingEnabled;
244 }
245
246 bool DeprecatedGlobalSettings::networkDataUsageTrackingEnabled()
247 {
248     return gNetworkDataUsageTrackingEnabled;
249 }
250
251 static String& sharedNetworkInterfaceNameGlobal()
252 {
253     static NeverDestroyed<String> networkInterfaceName;
254     return networkInterfaceName;
255 }
256
257 void DeprecatedGlobalSettings::setNetworkInterfaceName(const String& networkInterfaceName)
258 {
259     sharedNetworkInterfaceNameGlobal() = networkInterfaceName;
260 }
261
262 const String& DeprecatedGlobalSettings::networkInterfaceName()
263 {
264     return sharedNetworkInterfaceNameGlobal();
265 }
266 #endif
267
268 bool DeprecatedGlobalSettings::globalConstRedeclarationShouldThrow()
269 {
270 #if PLATFORM(MAC)
271     return !MacApplication::isIBooks();
272 #elif PLATFORM(IOS)
273     return !IOSApplication::isIBooks();
274 #else
275     return true;
276 #endif
277 }
278
279 void DeprecatedGlobalSettings::setAllowsAnySSLCertificate(bool allowAnySSLCertificate)
280 {
281     gAllowsAnySSLCertificate = allowAnySSLCertificate;
282 }
283
284 bool DeprecatedGlobalSettings::allowsAnySSLCertificate()
285 {
286     return gAllowsAnySSLCertificate;
287 }
288
289 } // namespace WebCore