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 // If navigation transitions gets activated via field trial, enable it in
64 // blink. We don't set this to false in case the user has manually enabled
65 // the feature via experimental web platform features.
66 if (base::FieldTrialList::FindFullName("NavigationTransitions") == "Enabled")
67 WebRuntimeFeatures::enableNavigationTransitions(true);
68 // Android won't be able to reliably support non-persistent notifications, the
69 // intended behavior for which is in flux by itself.
70 WebRuntimeFeatures::enableNotificationConstructor(false);
72 WebRuntimeFeatures::enableNavigatorContentUtils(true);
73 #endif // defined(OS_ANDROID)
75 #if !(defined OS_ANDROID || defined OS_CHROMEOS || defined OS_IOS)
76 // Only Android, ChromeOS, and IOS support NetInfo right now.
77 WebRuntimeFeatures::enableNetworkInformation(false);
81 // Screen Orientation API is currently broken on Windows 8 Metro mode and
82 // until we can find how to disable it only for Blink instances running in a
83 // renderer process in Metro, we need to disable the API altogether for Win8.
84 // See http://crbug.com/400846
85 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8
)
86 WebRuntimeFeatures::enableScreenOrientation(false);
90 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
91 const base::CommandLine
& command_line
) {
92 if (command_line
.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures
))
93 WebRuntimeFeatures::enableExperimentalFeatures(true);
95 SetRuntimeFeatureDefaultsForPlatform();
97 if (command_line
.HasSwitch(switches::kDisableDatabases
))
98 WebRuntimeFeatures::enableDatabase(false);
100 if (command_line
.HasSwitch(scheduler::switches::kDisableBlinkScheduler
))
101 WebRuntimeFeatures::enableBlinkScheduler(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 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
119 WebRuntimeFeatures::enableWebAudio(
120 !command_line
.HasSwitch(switches::kDisableWebAudio
) &&
121 media::MediaCodecBridge::IsAvailable());
123 if (command_line
.HasSwitch(switches::kDisableWebAudio
))
124 WebRuntimeFeatures::enableWebAudio(false);
127 if (command_line
.HasSwitch(switches::kDisableEncryptedMedia
))
128 WebRuntimeFeatures::enableEncryptedMedia(false);
130 if (command_line
.HasSwitch(switches::kDisablePrefixedEncryptedMedia
))
131 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
133 if (command_line
.HasSwitch(switches::kDisableFileSystem
))
134 WebRuntimeFeatures::enableFileSystem(false);
136 if (command_line
.HasSwitch(switches::kEnableExperimentalCanvasFeatures
))
137 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
139 if (!command_line
.HasSwitch(switches::kDisableAcceleratedJpegDecoding
))
140 WebRuntimeFeatures::enableDecodeToYUV(true);
142 if (command_line
.HasSwitch(switches::kEnableDisplayList2dCanvas
))
143 WebRuntimeFeatures::enableDisplayList2dCanvas(true);
145 if (command_line
.HasSwitch(switches::kDisableDisplayList2dCanvas
))
146 WebRuntimeFeatures::enableDisplayList2dCanvas(false);
148 if (command_line
.HasSwitch(switches::kForceDisplayList2dCanvas
))
149 WebRuntimeFeatures::forceDisplayList2dCanvas(true);
151 if (command_line
.HasSwitch(switches::kEnableWebGLDraftExtensions
))
152 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
154 if (command_line
.HasSwitch(switches::kEnableWebGLImageChromium
))
155 WebRuntimeFeatures::enableWebGLImageChromium(true);
157 if (command_line
.HasSwitch(switches::kEnableOverlayFullscreenVideo
))
158 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
160 if (ui::IsOverlayScrollbarEnabled())
161 WebRuntimeFeatures::enableOverlayScrollbars(true);
163 if (command_line
.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths
))
164 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
166 if (command_line
.HasSwitch(switches::kEnablePreciseMemoryInfo
))
167 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
169 if (command_line
.HasSwitch(switches::kEnableNetworkInformation
) ||
170 command_line
.HasSwitch(
171 switches::kEnableExperimentalWebPlatformFeatures
)) {
172 WebRuntimeFeatures::enableNetworkInformation(true);
175 if (command_line
.HasSwitch(switches::kEnableCredentialManagerAPI
))
176 WebRuntimeFeatures::enableCredentialManagerAPI(true);
178 if (command_line
.HasSwitch(switches::kDisableSVG1DOM
)) {
179 WebRuntimeFeatures::enableSVG1DOM(false);
182 if (command_line
.HasSwitch(switches::kReducedReferrerGranularity
))
183 WebRuntimeFeatures::enableReducedReferrerGranularity(true);
185 if (command_line
.HasSwitch(switches::kEnablePushMessagePayload
))
186 WebRuntimeFeatures::enablePushMessagingData(true);
188 if (command_line
.HasSwitch(switches::kEnablePushMessagingHasPermission
))
189 WebRuntimeFeatures::enablePushMessagingHasPermission(true);
191 // Delete "StaleWhileRevalidate" line from chrome_browser_field_trials.cc
192 // when this experiment is done.
193 if (base::FieldTrialList::FindFullName("StaleWhileRevalidate") == "Enabled" ||
194 command_line
.HasSwitch(switches::kEnableStaleWhileRevalidate
))
195 WebRuntimeFeatures::enableStaleWhileRevalidateCacheControl(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