| 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 | namespace WebCore { |
| 35 | |
| 36 | #if USE(AVFOUNDATION) |
| 37 | bool DeprecatedGlobalSettings::gAVFoundationEnabled = true; |
| 38 | bool DeprecatedGlobalSettings::gAVFoundationNSURLSessionEnabled = true; |
| 39 | #endif |
| 40 | |
| 41 | #if USE(GSTREAMER) |
| 42 | bool DeprecatedGlobalSettings::gGStreamerEnabled = true; |
| 43 | #endif |
| 44 | |
| 45 | bool DeprecatedGlobalSettings::gMockScrollbarsEnabled = false; |
| 46 | bool DeprecatedGlobalSettings::gUsesOverlayScrollbars = false; |
| 47 | bool DeprecatedGlobalSettings::gMockScrollAnimatorEnabled = false; |
| 48 | |
| 49 | #if PLATFORM(WIN) |
| 50 | bool DeprecatedGlobalSettings::gShouldUseHighResolutionTimers = true; |
| 51 | #endif |
| 52 | |
| 53 | bool DeprecatedGlobalSettings::gShouldRespectPriorityInCSSAttributeSetters = false; |
| 54 | bool DeprecatedGlobalSettings::gLowPowerVideoAudioBufferSizeEnabled = false; |
| 55 | bool DeprecatedGlobalSettings::gResourceLoadStatisticsEnabledEnabled = false; |
| 56 | bool DeprecatedGlobalSettings::gAllowsAnySSLCertificate = false; |
| 57 | |
| 58 | #if PLATFORM(IOS_FAMILY) |
| 59 | bool DeprecatedGlobalSettings::gNetworkDataUsageTrackingEnabled = false; |
| 60 | bool DeprecatedGlobalSettings::gAVKitEnabled = false; |
| 61 | bool DeprecatedGlobalSettings::gShouldOptOutOfNetworkStateObservation = false; |
| 62 | bool DeprecatedGlobalSettings::gDisableScreenSizeOverride = false; |
| 63 | #endif |
| 64 | bool DeprecatedGlobalSettings::gManageAudioSession = false; |
| 65 | |
| 66 | #if PLATFORM(WIN) |
| 67 | void DeprecatedGlobalSettings::setShouldUseHighResolutionTimers(bool shouldUseHighResolutionTimers) |
| 68 | { |
| 69 | gShouldUseHighResolutionTimers = shouldUseHighResolutionTimers; |
| 70 | } |
| 71 | #endif |
| 72 | |
| 73 | #if USE(AVFOUNDATION) |
| 74 | void DeprecatedGlobalSettings::setAVFoundationEnabled(bool enabled) |
| 75 | { |
| 76 | if (gAVFoundationEnabled == enabled) |
| 77 | return; |
| 78 | |
| 79 | gAVFoundationEnabled = enabled; |
| 80 | HTMLMediaElement::resetMediaEngines(); |
| 81 | } |
| 82 | |
| 83 | void DeprecatedGlobalSettings::setAVFoundationNSURLSessionEnabled(bool enabled) |
| 84 | { |
| 85 | if (gAVFoundationNSURLSessionEnabled == enabled) |
| 86 | return; |
| 87 | |
| 88 | gAVFoundationNSURLSessionEnabled = enabled; |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | #if USE(GSTREAMER) |
| 93 | void 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. |
| 110 | void DeprecatedGlobalSettings::setMockScrollbarsEnabled(bool flag) |
| 111 | { |
| 112 | gMockScrollbarsEnabled = flag; |
| 113 | // FIXME: This should update scroll bars in existing pages. |
| 114 | } |
| 115 | |
| 116 | bool DeprecatedGlobalSettings::mockScrollbarsEnabled() |
| 117 | { |
| 118 | return gMockScrollbarsEnabled; |
| 119 | } |
| 120 | |
| 121 | void DeprecatedGlobalSettings::setUsesOverlayScrollbars(bool flag) |
| 122 | { |
| 123 | gUsesOverlayScrollbars = flag; |
| 124 | // FIXME: This should update scroll bars in existing pages. |
| 125 | } |
| 126 | |
| 127 | bool DeprecatedGlobalSettings::usesOverlayScrollbars() |
| 128 | { |
| 129 | return gUsesOverlayScrollbars; |
| 130 | } |
| 131 | |
| 132 | void DeprecatedGlobalSettings::setUsesMockScrollAnimator(bool flag) |
| 133 | { |
| 134 | gMockScrollAnimatorEnabled = flag; |
| 135 | } |
| 136 | |
| 137 | bool DeprecatedGlobalSettings::usesMockScrollAnimator() |
| 138 | { |
| 139 | return gMockScrollAnimatorEnabled; |
| 140 | } |
| 141 | |
| 142 | void DeprecatedGlobalSettings::setShouldRespectPriorityInCSSAttributeSetters(bool flag) |
| 143 | { |
| 144 | gShouldRespectPriorityInCSSAttributeSetters = flag; |
| 145 | } |
| 146 | |
| 147 | bool DeprecatedGlobalSettings::shouldRespectPriorityInCSSAttributeSetters() |
| 148 | { |
| 149 | return gShouldRespectPriorityInCSSAttributeSetters; |
| 150 | } |
| 151 | |
| 152 | void DeprecatedGlobalSettings::setLowPowerVideoAudioBufferSizeEnabled(bool flag) |
| 153 | { |
| 154 | gLowPowerVideoAudioBufferSizeEnabled = flag; |
| 155 | } |
| 156 | |
| 157 | void DeprecatedGlobalSettings::setResourceLoadStatisticsEnabled(bool flag) |
| 158 | { |
| 159 | gResourceLoadStatisticsEnabledEnabled = flag; |
| 160 | } |
| 161 | |
| 162 | #if PLATFORM(IOS_FAMILY) |
| 163 | void DeprecatedGlobalSettings::setAudioSessionCategoryOverride(unsigned sessionCategory) |
| 164 | { |
| 165 | AudioSession::sharedSession().setCategoryOverride(static_cast<AudioSession::CategoryType>(sessionCategory)); |
| 166 | } |
| 167 | |
| 168 | unsigned DeprecatedGlobalSettings::audioSessionCategoryOverride() |
| 169 | { |
| 170 | return AudioSession::sharedSession().categoryOverride(); |
| 171 | } |
| 172 | |
| 173 | void DeprecatedGlobalSettings::setNetworkDataUsageTrackingEnabled(bool trackingEnabled) |
| 174 | { |
| 175 | gNetworkDataUsageTrackingEnabled = trackingEnabled; |
| 176 | } |
| 177 | |
| 178 | bool DeprecatedGlobalSettings::networkDataUsageTrackingEnabled() |
| 179 | { |
| 180 | return gNetworkDataUsageTrackingEnabled; |
| 181 | } |
| 182 | |
| 183 | static String& sharedNetworkInterfaceNameGlobal() |
| 184 | { |
| 185 | static NeverDestroyed<String> networkInterfaceName; |
| 186 | return networkInterfaceName; |
| 187 | } |
| 188 | |
| 189 | void DeprecatedGlobalSettings::setNetworkInterfaceName(const String& networkInterfaceName) |
| 190 | { |
| 191 | sharedNetworkInterfaceNameGlobal() = networkInterfaceName; |
| 192 | } |
| 193 | |
| 194 | const String& DeprecatedGlobalSettings::networkInterfaceName() |
| 195 | { |
| 196 | return sharedNetworkInterfaceNameGlobal(); |
| 197 | } |
| 198 | #endif |
| 199 | |
| 200 | bool 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 | |
| 211 | void DeprecatedGlobalSettings::setAllowsAnySSLCertificate(bool allowAnySSLCertificate) |
| 212 | { |
| 213 | gAllowsAnySSLCertificate = allowAnySSLCertificate; |
| 214 | } |
| 215 | |
| 216 | bool DeprecatedGlobalSettings::allowsAnySSLCertificate() |
| 217 | { |
| 218 | return gAllowsAnySSLCertificate; |
| 219 | } |
| 220 | |
| 221 | } // namespace WebCore |
| 222 | |