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
34namespace WebCore {
35
36#if USE(AVFOUNDATION)
37bool DeprecatedGlobalSettings::gAVFoundationEnabled = true;
38bool DeprecatedGlobalSettings::gAVFoundationNSURLSessionEnabled = true;
39#endif
40
41#if USE(GSTREAMER)
42bool DeprecatedGlobalSettings::gGStreamerEnabled = true;
43#endif
44
45bool DeprecatedGlobalSettings::gMockScrollbarsEnabled = false;
46bool DeprecatedGlobalSettings::gUsesOverlayScrollbars = false;
47bool DeprecatedGlobalSettings::gMockScrollAnimatorEnabled = false;
48
49#if PLATFORM(WIN)
50bool DeprecatedGlobalSettings::gShouldUseHighResolutionTimers = true;
51#endif
52
53bool DeprecatedGlobalSettings::gShouldRespectPriorityInCSSAttributeSetters = false;
54bool DeprecatedGlobalSettings::gLowPowerVideoAudioBufferSizeEnabled = false;
55bool DeprecatedGlobalSettings::gResourceLoadStatisticsEnabledEnabled = false;
56bool DeprecatedGlobalSettings::gAllowsAnySSLCertificate = false;
57
58#if PLATFORM(IOS_FAMILY)
59bool DeprecatedGlobalSettings::gNetworkDataUsageTrackingEnabled = false;
60bool DeprecatedGlobalSettings::gAVKitEnabled = false;
61bool DeprecatedGlobalSettings::gShouldOptOutOfNetworkStateObservation = false;
62bool DeprecatedGlobalSettings::gDisableScreenSizeOverride = false;
63#endif
64bool DeprecatedGlobalSettings::gManageAudioSession = false;
65
66#if PLATFORM(WIN)
67void DeprecatedGlobalSettings::setShouldUseHighResolutionTimers(bool shouldUseHighResolutionTimers)
68{
69 gShouldUseHighResolutionTimers = shouldUseHighResolutionTimers;
70}
71#endif
72
73#if USE(AVFOUNDATION)
74void DeprecatedGlobalSettings::setAVFoundationEnabled(bool enabled)
75{
76 if (gAVFoundationEnabled == enabled)
77 return;
78
79 gAVFoundationEnabled = enabled;
80 HTMLMediaElement::resetMediaEngines();
81}
82
83void DeprecatedGlobalSettings::setAVFoundationNSURLSessionEnabled(bool enabled)
84{
85 if (gAVFoundationNSURLSessionEnabled == enabled)
86 return;
87
88 gAVFoundationNSURLSessionEnabled = enabled;
89}
90#endif
91
92#if USE(GSTREAMER)
93void DeprecatedGlobalSettings::setGStreamerEnabled(bool enabled)
94{
95 if (gGStreamerEnabled == enabled)
96 return;
97
98 gGStreamerEnabled = enabled;
99
100#if ENABLE(VIDEO)
101 HTMLMediaElement::resetMediaEngines();
102#endif
103}
104#endif
105
106// It's very important that this setting doesn't change in the middle of a document's lifetime.
107// The Mac port uses this flag when registering and deregistering platform-dependent scrollbar
108// objects. Therefore, if this changes at an unexpected time, deregistration may not happen
109// correctly, which may cause the platform to follow dangling pointers.
110void DeprecatedGlobalSettings::setMockScrollbarsEnabled(bool flag)
111{
112 gMockScrollbarsEnabled = flag;
113 // FIXME: This should update scroll bars in existing pages.
114}
115
116bool DeprecatedGlobalSettings::mockScrollbarsEnabled()
117{
118 return gMockScrollbarsEnabled;
119}
120
121void DeprecatedGlobalSettings::setUsesOverlayScrollbars(bool flag)
122{
123 gUsesOverlayScrollbars = flag;
124 // FIXME: This should update scroll bars in existing pages.
125}
126
127bool DeprecatedGlobalSettings::usesOverlayScrollbars()
128{
129 return gUsesOverlayScrollbars;
130}
131
132void DeprecatedGlobalSettings::setUsesMockScrollAnimator(bool flag)
133{
134 gMockScrollAnimatorEnabled = flag;
135}
136
137bool DeprecatedGlobalSettings::usesMockScrollAnimator()
138{
139 return gMockScrollAnimatorEnabled;
140}
141
142void DeprecatedGlobalSettings::setShouldRespectPriorityInCSSAttributeSetters(bool flag)
143{
144 gShouldRespectPriorityInCSSAttributeSetters = flag;
145}
146
147bool DeprecatedGlobalSettings::shouldRespectPriorityInCSSAttributeSetters()
148{
149 return gShouldRespectPriorityInCSSAttributeSetters;
150}
151
152void DeprecatedGlobalSettings::setLowPowerVideoAudioBufferSizeEnabled(bool flag)
153{
154 gLowPowerVideoAudioBufferSizeEnabled = flag;
155}
156
157void DeprecatedGlobalSettings::setResourceLoadStatisticsEnabled(bool flag)
158{
159 gResourceLoadStatisticsEnabledEnabled = flag;
160}
161
162#if PLATFORM(IOS_FAMILY)
163void DeprecatedGlobalSettings::setAudioSessionCategoryOverride(unsigned sessionCategory)
164{
165 AudioSession::sharedSession().setCategoryOverride(static_cast<AudioSession::CategoryType>(sessionCategory));
166}
167
168unsigned DeprecatedGlobalSettings::audioSessionCategoryOverride()
169{
170 return AudioSession::sharedSession().categoryOverride();
171}
172
173void DeprecatedGlobalSettings::setNetworkDataUsageTrackingEnabled(bool trackingEnabled)
174{
175 gNetworkDataUsageTrackingEnabled = trackingEnabled;
176}
177
178bool DeprecatedGlobalSettings::networkDataUsageTrackingEnabled()
179{
180 return gNetworkDataUsageTrackingEnabled;
181}
182
183static String& sharedNetworkInterfaceNameGlobal()
184{
185 static NeverDestroyed<String> networkInterfaceName;
186 return networkInterfaceName;
187}
188
189void DeprecatedGlobalSettings::setNetworkInterfaceName(const String& networkInterfaceName)
190{
191 sharedNetworkInterfaceNameGlobal() = networkInterfaceName;
192}
193
194const String& DeprecatedGlobalSettings::networkInterfaceName()
195{
196 return sharedNetworkInterfaceNameGlobal();
197}
198#endif
199
200bool DeprecatedGlobalSettings::globalConstRedeclarationShouldThrow()
201{
202#if PLATFORM(MAC)
203 return !MacApplication::isIBooks();
204#elif PLATFORM(IOS_FAMILY)
205 return !IOSApplication::isIBooks();
206#else
207 return true;
208#endif
209}
210
211void DeprecatedGlobalSettings::setAllowsAnySSLCertificate(bool allowAnySSLCertificate)
212{
213 gAllowsAnySSLCertificate = allowAnySSLCertificate;
214}
215
216bool DeprecatedGlobalSettings::allowsAnySSLCertificate()
217{
218 return gAllowsAnySSLCertificate;
219}
220
221} // namespace WebCore
222