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 "gpu/command_buffer/service/gpu_switches.h"
15 #include "third_party/WebKit/public/web/WebRuntimeFeatures.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 #if defined(OS_ANDROID)
33 // MSE/EME implementation needs Android MediaCodec API.
34 if (!media::MediaCodecBridge::IsAvailable()) {
35 WebRuntimeFeatures::enableMediaSource(false);
36 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
37 WebRuntimeFeatures::enableEncryptedMedia(false);
39 // WebAudio is enabled by default but only when the MediaCodec API
41 AndroidCpuFamily cpu_family
= android_getCpuFamily();
42 WebRuntimeFeatures::enableWebAudio(
43 media::MediaCodecBridge::IsAvailable() &&
44 ((cpu_family
== ANDROID_CPU_FAMILY_ARM
) ||
45 (cpu_family
== ANDROID_CPU_FAMILY_ARM64
) ||
46 (cpu_family
== ANDROID_CPU_FAMILY_X86
) ||
47 (cpu_family
== ANDROID_CPU_FAMILY_MIPS
)));
49 // Android does not have support for PagePopup
50 WebRuntimeFeatures::enablePagePopup(false);
51 // Android does not yet support SharedWorker. crbug.com/154571
52 WebRuntimeFeatures::enableSharedWorker(false);
53 // Android does not yet support NavigatorContentUtils.
54 WebRuntimeFeatures::enableNavigatorContentUtils(false);
55 WebRuntimeFeatures::enableTouchIconLoading(true);
56 WebRuntimeFeatures::enableOrientationEvent(true);
57 WebRuntimeFeatures::enableFastMobileScrolling(true);
58 WebRuntimeFeatures::enableMediaCapture(true);
59 WebRuntimeFeatures::enableCompositedSelectionUpdate(true);
60 // If navigation transitions gets activated via field trial, enable it in
61 // blink. We don't set this to false in case the user has manually enabled
62 // the feature via experimental web platform features.
63 if (base::FieldTrialList::FindFullName("NavigationTransitions") == "Enabled")
64 WebRuntimeFeatures::enableNavigationTransitions(true);
65 // Android won't be able to reliably support non-persistent notifications, the
66 // intended behavior for which is in flux by itself.
67 WebRuntimeFeatures::enableNotificationConstructor(false);
69 WebRuntimeFeatures::enableNavigatorContentUtils(true);
70 #endif // defined(OS_ANDROID)
72 #if !(defined OS_ANDROID || defined OS_CHROMEOS || defined OS_IOS)
73 // Only Android, ChromeOS, and IOS support NetInfo right now.
74 WebRuntimeFeatures::enableNetworkInformation(false);
78 // Screen Orientation API is currently broken on Windows 8 Metro mode and
79 // until we can find how to disable it only for Blink instances running in a
80 // renderer process in Metro, we need to disable the API altogether for Win8.
81 // See http://crbug.com/400846
82 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8
)
83 WebRuntimeFeatures::enableScreenOrientation(false);
87 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
88 const base::CommandLine
& command_line
) {
89 if (command_line
.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures
))
90 WebRuntimeFeatures::enableExperimentalFeatures(true);
92 SetRuntimeFeatureDefaultsForPlatform();
94 if (command_line
.HasSwitch(switches::kDisableDatabases
))
95 WebRuntimeFeatures::enableDatabase(false);
97 if (command_line
.HasSwitch(switches::kDisableBlinkScheduler
))
98 WebRuntimeFeatures::enableBlinkScheduler(false);
100 if (command_line
.HasSwitch(switches::kDisableLocalStorage
))
101 WebRuntimeFeatures::enableLocalStorage(false);
103 if (command_line
.HasSwitch(switches::kDisableMediaSource
))
104 WebRuntimeFeatures::enableMediaSource(false);
106 if (command_line
.HasSwitch(switches::kDisableNotifications
)) {
107 WebRuntimeFeatures::enableNotifications(false);
109 // Chrome's Push Messaging implementation relies on Web Notifications.
110 WebRuntimeFeatures::enablePushMessaging(false);
113 if (command_line
.HasSwitch(switches::kDisableSharedWorkers
))
114 WebRuntimeFeatures::enableSharedWorker(false);
116 #if defined(OS_ANDROID)
117 if (command_line
.HasSwitch(switches::kDisableWebRTC
))
118 WebRuntimeFeatures::enablePeerConnection(false);
120 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
122 WebRuntimeFeatures::enableWebAudio(
123 !command_line
.HasSwitch(switches::kDisableWebAudio
) &&
124 media::MediaCodecBridge::IsAvailable());
126 if (command_line
.HasSwitch(switches::kDisableWebAudio
))
127 WebRuntimeFeatures::enableWebAudio(false);
130 if (command_line
.HasSwitch(switches::kDisableEncryptedMedia
))
131 WebRuntimeFeatures::enableEncryptedMedia(false);
133 if (command_line
.HasSwitch(switches::kDisablePrefixedEncryptedMedia
))
134 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
136 if (command_line
.HasSwitch(switches::kEnableWebMIDI
))
137 WebRuntimeFeatures::enableWebMIDI(true);
139 if (command_line
.HasSwitch(switches::kDisableFileSystem
))
140 WebRuntimeFeatures::enableFileSystem(false);
142 if (command_line
.HasSwitch(switches::kEnableExperimentalCanvasFeatures
))
143 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
145 if (!command_line
.HasSwitch(switches::kDisableAcceleratedJpegDecoding
))
146 WebRuntimeFeatures::enableDecodeToYUV(true);
148 if (command_line
.HasSwitch(switches::kEnableDisplayList2dCanvas
))
149 WebRuntimeFeatures::enableDisplayList2dCanvas(true);
151 if (command_line
.HasSwitch(switches::kDisableDisplayList2dCanvas
))
152 WebRuntimeFeatures::enableDisplayList2dCanvas(false);
154 if (command_line
.HasSwitch(switches::kForceDisplayList2dCanvas
))
155 WebRuntimeFeatures::forceDisplayList2dCanvas(true);
157 if (command_line
.HasSwitch(switches::kEnableWebGLDraftExtensions
))
158 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
160 if (command_line
.HasSwitch(switches::kEnableWebGLImageChromium
))
161 WebRuntimeFeatures::enableWebGLImageChromium(true);
163 if (command_line
.HasSwitch(switches::kEnableOverlayFullscreenVideo
))
164 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
166 if (ui::IsOverlayScrollbarEnabled())
167 WebRuntimeFeatures::enableOverlayScrollbars(true);
169 if (command_line
.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths
))
170 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
172 if (command_line
.HasSwitch(switches::kEnablePreciseMemoryInfo
))
173 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
175 if (command_line
.HasSwitch(switches::kEnableNetworkInformation
) ||
176 command_line
.HasSwitch(
177 switches::kEnableExperimentalWebPlatformFeatures
)) {
178 WebRuntimeFeatures::enableNetworkInformation(true);
181 if (command_line
.HasSwitch(switches::kEnableCredentialManagerAPI
))
182 WebRuntimeFeatures::enableCredentialManagerAPI(true);
184 if (command_line
.HasSwitch(switches::kDisableSVG1DOM
)) {
185 WebRuntimeFeatures::enableSVG1DOM(false);
188 if (command_line
.HasSwitch(switches::kReducedReferrerGranularity
))
189 WebRuntimeFeatures::enableReducedReferrerGranularity(true);
191 if (command_line
.HasSwitch(switches::kEnablePushMessagePayload
))
192 WebRuntimeFeatures::enablePushMessagingData(true);
194 if (command_line
.HasSwitch(switches::kEnablePushMessagingHasPermission
))
195 WebRuntimeFeatures::enablePushMessagingHasPermission(true);
197 if (command_line
.HasSwitch(switches::kDisableV8IdleTasks
))
198 WebRuntimeFeatures::enableV8IdleTasks(false);
200 WebRuntimeFeatures::enableV8IdleTasks(true);
202 if (command_line
.HasSwitch(switches::kEnableUnsafeES3APIs
))
203 WebRuntimeFeatures::enableUnsafeES3APIs(true);
205 // Enable explicitly enabled features, and then disable explicitly disabled
207 if (command_line
.HasSwitch(switches::kEnableBlinkFeatures
)) {
208 std::vector
<std::string
> enabled_features
;
210 command_line
.GetSwitchValueASCII(switches::kEnableBlinkFeatures
), ',',
212 for (const std::string
& feature
: enabled_features
) {
213 WebRuntimeFeatures::enableFeatureFromString(
214 blink::WebString::fromLatin1(feature
), true);
217 if (command_line
.HasSwitch(switches::kDisableBlinkFeatures
)) {
218 std::vector
<std::string
> disabled_features
;
220 command_line
.GetSwitchValueASCII(switches::kDisableBlinkFeatures
), ',',
222 for (const std::string
& feature
: disabled_features
) {
223 WebRuntimeFeatures::enableFeatureFromString(
224 blink::WebString::fromLatin1(feature
), false);
229 } // namespace content