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 "components/scheduler/common/scheduler_switches.h"
13 #include "content/common/content_switches_internal.h"
14 #include "content/public/common/content_switches.h"
15 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
16 #include "ui/gl/gl_switches.h"
17 #include "ui/native_theme/native_theme_switches.h"
19 #if defined(OS_ANDROID)
20 #include <cpu-features.h>
21 #include "base/android/build_info.h"
22 #include "base/metrics/field_trial.h"
23 #include "media/base/android/media_codec_bridge.h"
25 #include "base/win/windows_version.h"
28 using blink::WebRuntimeFeatures
;
32 static void SetRuntimeFeatureDefaultsForPlatform() {
33 // Enable non-standard "apple-touch-icon" and "apple-touch-icon-precomposed".
34 WebRuntimeFeatures::enableTouchIconLoading(true);
36 #if defined(OS_ANDROID)
37 // MSE/EME implementation needs Android MediaCodec API.
38 if (!media::MediaCodecBridge::IsAvailable()) {
39 WebRuntimeFeatures::enableMediaSource(false);
40 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
41 WebRuntimeFeatures::enableEncryptedMedia(false);
43 // WebAudio is enabled by default but only when the MediaCodec API
45 AndroidCpuFamily cpu_family
= android_getCpuFamily();
46 WebRuntimeFeatures::enableWebAudio(
47 media::MediaCodecBridge::IsAvailable() &&
48 ((cpu_family
== ANDROID_CPU_FAMILY_ARM
) ||
49 (cpu_family
== ANDROID_CPU_FAMILY_ARM64
) ||
50 (cpu_family
== ANDROID_CPU_FAMILY_X86
) ||
51 (cpu_family
== ANDROID_CPU_FAMILY_MIPS
)));
53 // Android does not have support for PagePopup
54 WebRuntimeFeatures::enablePagePopup(false);
55 // Android does not yet support SharedWorker. crbug.com/154571
56 WebRuntimeFeatures::enableSharedWorker(false);
57 // Android does not yet support NavigatorContentUtils.
58 WebRuntimeFeatures::enableNavigatorContentUtils(false);
59 WebRuntimeFeatures::enableOrientationEvent(true);
60 WebRuntimeFeatures::enableFastMobileScrolling(true);
61 WebRuntimeFeatures::enableMediaCapture(true);
62 WebRuntimeFeatures::enableCompositedSelectionUpdate(true);
63 // Android won't be able to reliably support non-persistent notifications, the
64 // intended behavior for which is in flux by itself.
65 WebRuntimeFeatures::enableNotificationConstructor(false);
67 WebRuntimeFeatures::enableNavigatorContentUtils(true);
68 #endif // defined(OS_ANDROID)
70 #if !(defined OS_ANDROID || defined OS_CHROMEOS || defined OS_IOS)
71 // Only Android, ChromeOS, and IOS support NetInfo right now.
72 WebRuntimeFeatures::enableNetworkInformation(false);
76 // Screen Orientation API is currently broken on Windows 8 Metro mode and
77 // until we can find how to disable it only for Blink instances running in a
78 // renderer process in Metro, we need to disable the API altogether for Win8.
79 // See http://crbug.com/400846
80 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8
)
81 WebRuntimeFeatures::enableScreenOrientation(false);
85 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
86 const base::CommandLine
& command_line
) {
87 if (command_line
.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures
))
88 WebRuntimeFeatures::enableExperimentalFeatures(true);
90 if (command_line
.HasSwitch(switches::kEnableWebBluetooth
))
91 WebRuntimeFeatures::enableWebBluetooth(true);
93 SetRuntimeFeatureDefaultsForPlatform();
95 if (command_line
.HasSwitch(switches::kDisableDatabases
))
96 WebRuntimeFeatures::enableDatabase(false);
98 if (command_line
.HasSwitch(switches::kDisableMediaSource
))
99 WebRuntimeFeatures::enableMediaSource(false);
101 if (command_line
.HasSwitch(switches::kDisableNotifications
)) {
102 WebRuntimeFeatures::enableNotifications(false);
104 // Chrome's Push Messaging implementation relies on Web Notifications.
105 WebRuntimeFeatures::enablePushMessaging(false);
108 if (command_line
.HasSwitch(switches::kDisableSharedWorkers
))
109 WebRuntimeFeatures::enableSharedWorker(false);
111 #if defined(OS_ANDROID)
112 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
114 WebRuntimeFeatures::enableWebAudio(
115 !command_line
.HasSwitch(switches::kDisableWebAudio
) &&
116 media::MediaCodecBridge::IsAvailable());
118 if (command_line
.HasSwitch(switches::kDisableWebAudio
))
119 WebRuntimeFeatures::enableWebAudio(false);
122 if (command_line
.HasSwitch(switches::kDisableSpeechAPI
))
123 WebRuntimeFeatures::enableScriptedSpeech(false);
125 if (command_line
.HasSwitch(switches::kDisableEncryptedMedia
))
126 WebRuntimeFeatures::enableEncryptedMedia(false);
128 if (command_line
.HasSwitch(switches::kDisablePrefixedEncryptedMedia
))
129 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
131 if (command_line
.HasSwitch(switches::kDisableFileSystem
))
132 WebRuntimeFeatures::enableFileSystem(false);
134 if (command_line
.HasSwitch(switches::kEnableExperimentalCanvasFeatures
))
135 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
137 if (!command_line
.HasSwitch(switches::kDisableAcceleratedJpegDecoding
))
138 WebRuntimeFeatures::enableDecodeToYUV(true);
140 if (command_line
.HasSwitch(switches::kEnableDisplayList2dCanvas
))
141 WebRuntimeFeatures::enableDisplayList2dCanvas(true);
143 if (command_line
.HasSwitch(switches::kDisableDisplayList2dCanvas
))
144 WebRuntimeFeatures::enableDisplayList2dCanvas(false);
146 if (command_line
.HasSwitch(switches::kForceDisplayList2dCanvas
))
147 WebRuntimeFeatures::forceDisplayList2dCanvas(true);
149 if (command_line
.HasSwitch(switches::kEnableWebGLDraftExtensions
))
150 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
152 if (command_line
.HasSwitch(switches::kEnableWebGLImageChromium
))
153 WebRuntimeFeatures::enableWebGLImageChromium(true);
155 if (command_line
.HasSwitch(switches::kEnableOverlayFullscreenVideo
))
156 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
158 if (ui::IsOverlayScrollbarEnabled())
159 WebRuntimeFeatures::enableOverlayScrollbars(true);
161 if (command_line
.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths
))
162 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
164 if (command_line
.HasSwitch(switches::kEnablePreciseMemoryInfo
))
165 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
167 if (command_line
.HasSwitch(switches::kEnableNetworkInformation
) ||
168 command_line
.HasSwitch(
169 switches::kEnableExperimentalWebPlatformFeatures
)) {
170 WebRuntimeFeatures::enableNetworkInformation(true);
173 if (command_line
.HasSwitch(switches::kEnableCredentialManagerAPI
))
174 WebRuntimeFeatures::enableCredentialManagerAPI(true);
176 if (command_line
.HasSwitch(switches::kDisableSVG1DOM
)) {
177 WebRuntimeFeatures::enableSVG1DOM(false);
180 if (command_line
.HasSwitch(switches::kReducedReferrerGranularity
))
181 WebRuntimeFeatures::enableReducedReferrerGranularity(true);
183 if (command_line
.HasSwitch(switches::kEnablePushMessagePayload
))
184 WebRuntimeFeatures::enablePushMessagingData(true);
186 if (command_line
.HasSwitch(switches::kDisablePermissionsAPI
))
187 WebRuntimeFeatures::enablePermissionsAPI(false);
189 // Delete "StaleWhileRevalidate" line from chrome_browser_field_trials.cc
190 // when this experiment is done.
191 if (base::FieldTrialList::FindFullName("StaleWhileRevalidate") == "Enabled" ||
192 command_line
.HasSwitch(switches::kEnableStaleWhileRevalidate
))
193 WebRuntimeFeatures::enableStaleWhileRevalidateCacheControl(true);
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("GeometryInterfaces", true);
208 // Enable explicitly enabled features, and then disable explicitly disabled
210 if (command_line
.HasSwitch(switches::kEnableBlinkFeatures
)) {
211 std::vector
<std::string
> enabled_features
;
213 command_line
.GetSwitchValueASCII(switches::kEnableBlinkFeatures
), ',',
215 for (const std::string
& feature
: enabled_features
) {
216 WebRuntimeFeatures::enableFeatureFromString(
217 blink::WebString::fromLatin1(feature
), true);
220 if (command_line
.HasSwitch(switches::kDisableBlinkFeatures
)) {
221 std::vector
<std::string
> disabled_features
;
223 command_line
.GetSwitchValueASCII(switches::kDisableBlinkFeatures
), ',',
225 for (const std::string
& feature
: disabled_features
) {
226 WebRuntimeFeatures::enableFeatureFromString(
227 blink::WebString::fromLatin1(feature
), false);
232 } // namespace content