1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/child/runtime_features.h"
9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/strings/string_split.h"
12 #include "content/common/content_switches_internal.h"
13 #include "content/public/common/content_switches.h"
14 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
15 #include "ui/gl/gl_switches.h"
16 #include "ui/native_theme/native_theme_switches.h"
18 #if defined(OS_ANDROID)
19 #include <cpu-features.h>
20 #include "base/android/build_info.h"
21 #include "base/metrics/field_trial.h"
22 #include "media/base/android/media_codec_bridge.h"
24 #include "base/win/windows_version.h"
27 using blink::WebRuntimeFeatures
;
31 static void SetRuntimeFeatureDefaultsForPlatform() {
32 // Enable non-standard "apple-touch-icon" and "apple-touch-icon-precomposed".
33 WebRuntimeFeatures::enableTouchIconLoading(true);
35 #if defined(OS_ANDROID)
36 // MSE/EME implementation needs Android MediaCodec API.
37 if (!media::MediaCodecBridge::IsAvailable()) {
38 WebRuntimeFeatures::enableMediaSource(false);
39 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
40 WebRuntimeFeatures::enableEncryptedMedia(false);
42 // WebAudio is enabled by default but only when the MediaCodec API
44 AndroidCpuFamily cpu_family
= android_getCpuFamily();
45 WebRuntimeFeatures::enableWebAudio(
46 media::MediaCodecBridge::IsAvailable() &&
47 ((cpu_family
== ANDROID_CPU_FAMILY_ARM
) ||
48 (cpu_family
== ANDROID_CPU_FAMILY_ARM64
) ||
49 (cpu_family
== ANDROID_CPU_FAMILY_X86
) ||
50 (cpu_family
== ANDROID_CPU_FAMILY_MIPS
)));
52 // Android does not have support for PagePopup
53 WebRuntimeFeatures::enablePagePopup(false);
54 // Android does not yet support SharedWorker. crbug.com/154571
55 WebRuntimeFeatures::enableSharedWorker(false);
56 // Android does not yet support NavigatorContentUtils.
57 WebRuntimeFeatures::enableNavigatorContentUtils(false);
58 WebRuntimeFeatures::enableOrientationEvent(true);
59 WebRuntimeFeatures::enableFastMobileScrolling(true);
60 WebRuntimeFeatures::enableMediaCapture(true);
61 // Android won't be able to reliably support non-persistent notifications, the
62 // intended behavior for which is in flux by itself.
63 WebRuntimeFeatures::enableNotificationConstructor(false);
64 WebRuntimeFeatures::enableNewMediaPlaybackUi(true);
66 WebRuntimeFeatures::enableNavigatorContentUtils(true);
67 #endif // defined(OS_ANDROID)
69 #if defined(OS_ANDROID) || defined(USE_AURA)
70 WebRuntimeFeatures::enableCompositedSelectionUpdate(true);
73 #if !(defined OS_ANDROID || defined OS_CHROMEOS || defined OS_IOS)
74 // Only Android, ChromeOS, and IOS support NetInfo right now.
75 WebRuntimeFeatures::enableNetworkInformation(false);
79 // Screen Orientation API is currently broken on Windows 8 Metro mode and
80 // until we can find how to disable it only for Blink instances running in a
81 // renderer process in Metro, we need to disable the API altogether for Win8.
82 // See http://crbug.com/400846
83 base::win::Version version
= base::win::OSInfo::GetInstance()->version();
84 if (version
== base::win::VERSION_WIN8
||
85 version
== base::win::VERSION_WIN8_1
) {
86 WebRuntimeFeatures::enableScreenOrientation(false);
91 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
92 const base::CommandLine
& command_line
) {
93 if (command_line
.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures
))
94 WebRuntimeFeatures::enableExperimentalFeatures(true);
96 if (command_line
.HasSwitch(switches::kEnableWebBluetooth
))
97 WebRuntimeFeatures::enableWebBluetooth(true);
99 SetRuntimeFeatureDefaultsForPlatform();
101 if (command_line
.HasSwitch(switches::kDisableDatabases
))
102 WebRuntimeFeatures::enableDatabase(false);
104 if (command_line
.HasSwitch(switches::kDisableMediaSource
))
105 WebRuntimeFeatures::enableMediaSource(false);
107 if (command_line
.HasSwitch(switches::kDisableNotifications
)) {
108 WebRuntimeFeatures::enableNotifications(false);
110 // Chrome's Push Messaging implementation relies on Web Notifications.
111 WebRuntimeFeatures::enablePushMessaging(false);
114 if (command_line
.HasSwitch(switches::kDisableSharedWorkers
))
115 WebRuntimeFeatures::enableSharedWorker(false);
117 #if defined(OS_ANDROID)
118 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
120 WebRuntimeFeatures::enableWebAudio(
121 !command_line
.HasSwitch(switches::kDisableWebAudio
) &&
122 media::MediaCodecBridge::IsAvailable());
124 if (command_line
.HasSwitch(switches::kDisableWebAudio
))
125 WebRuntimeFeatures::enableWebAudio(false);
128 if (command_line
.HasSwitch(switches::kDisableSpeechAPI
))
129 WebRuntimeFeatures::enableScriptedSpeech(false);
131 if (command_line
.HasSwitch(switches::kDisableEncryptedMedia
))
132 WebRuntimeFeatures::enableEncryptedMedia(false);
134 if (command_line
.HasSwitch(switches::kEnablePrefixedEncryptedMedia
))
135 WebRuntimeFeatures::enablePrefixedEncryptedMedia(true);
137 if (command_line
.HasSwitch(switches::kDisableFileSystem
))
138 WebRuntimeFeatures::enableFileSystem(false);
140 if (command_line
.HasSwitch(switches::kEnableExperimentalCanvasFeatures
))
141 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
143 if (!command_line
.HasSwitch(switches::kDisableAcceleratedJpegDecoding
))
144 WebRuntimeFeatures::enableDecodeToYUV(true);
146 if (command_line
.HasSwitch(switches::kEnableDisplayList2dCanvas
))
147 WebRuntimeFeatures::enableDisplayList2dCanvas(true);
149 if (command_line
.HasSwitch(switches::kDisableDisplayList2dCanvas
))
150 WebRuntimeFeatures::enableDisplayList2dCanvas(false);
152 if (command_line
.HasSwitch(switches::kForceDisplayList2dCanvas
))
153 WebRuntimeFeatures::forceDisplayList2dCanvas(true);
155 if (command_line
.HasSwitch(switches::kEnableWebGLDraftExtensions
))
156 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
158 if (command_line
.HasSwitch(switches::kEnableWebGLImageChromium
))
159 WebRuntimeFeatures::enableWebGLImageChromium(true);
161 if (command_line
.HasSwitch(switches::kForceOverlayFullscreenVideo
))
162 WebRuntimeFeatures::forceOverlayFullscreenVideo(true);
164 if (ui::IsOverlayScrollbarEnabled())
165 WebRuntimeFeatures::enableOverlayScrollbars(true);
167 if (command_line
.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths
))
168 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
170 if (command_line
.HasSwitch(switches::kEnablePreciseMemoryInfo
))
171 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
173 if (command_line
.HasSwitch(switches::kEnableNetworkInformation
) ||
174 command_line
.HasSwitch(
175 switches::kEnableExperimentalWebPlatformFeatures
)) {
176 WebRuntimeFeatures::enableNetworkInformation(true);
179 if (command_line
.HasSwitch(switches::kEnableCredentialManagerAPI
))
180 WebRuntimeFeatures::enableCredentialManagerAPI(true);
182 if (command_line
.HasSwitch(switches::kDisableSVG1DOM
)) {
183 WebRuntimeFeatures::enableSVG1DOM(false);
186 if (command_line
.HasSwitch(switches::kReducedReferrerGranularity
))
187 WebRuntimeFeatures::enableReducedReferrerGranularity(true);
189 if (command_line
.HasSwitch(switches::kEnablePushMessagePayload
))
190 WebRuntimeFeatures::enablePushMessagingData(true);
192 if (command_line
.HasSwitch(switches::kDisablePermissionsAPI
))
193 WebRuntimeFeatures::enablePermissionsAPI(false);
195 if (command_line
.HasSwitch(switches::kDisableV8IdleTasks
))
196 WebRuntimeFeatures::enableV8IdleTasks(false);
198 WebRuntimeFeatures::enableV8IdleTasks(true);
200 if (command_line
.HasSwitch(switches::kEnableUnsafeES3APIs
))
201 WebRuntimeFeatures::enableUnsafeES3APIs(true);
203 if (command_line
.HasSwitch(switches::kEnableWebVR
)) {
204 WebRuntimeFeatures::enableWebVR(true);
205 WebRuntimeFeatures::enableFeatureFromString(
206 std::string("GeometryInterfaces"), true);
209 if (command_line
.HasSwitch(switches::kDisablePresentationAPI
))
210 WebRuntimeFeatures::enablePresentationAPI(false);
212 // Enable explicitly enabled features, and then disable explicitly disabled
214 if (command_line
.HasSwitch(switches::kEnableBlinkFeatures
)) {
215 std::vector
<std::string
> enabled_features
= base::SplitString(
216 command_line
.GetSwitchValueASCII(switches::kEnableBlinkFeatures
),
217 ",", base::TRIM_WHITESPACE
, base::SPLIT_WANT_ALL
);
218 for (const std::string
& feature
: enabled_features
)
219 WebRuntimeFeatures::enableFeatureFromString(feature
, true);
221 if (command_line
.HasSwitch(switches::kDisableBlinkFeatures
)) {
222 std::vector
<std::string
> disabled_features
= base::SplitString(
223 command_line
.GetSwitchValueASCII(switches::kDisableBlinkFeatures
),
224 ",", base::TRIM_WHITESPACE
, base::SPLIT_WANT_ALL
);
225 for (const std::string
& feature
: disabled_features
)
226 WebRuntimeFeatures::enableFeatureFromString(feature
, false);
230 } // namespace content