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"
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "content/common/content_switches_internal.h"
10 #include "content/public/common/content_switches.h"
11 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
12 #include "ui/native_theme/native_theme_switches.h"
14 #if defined(OS_ANDROID)
15 #include <cpu-features.h>
16 #include "base/android/build_info.h"
17 #include "base/metrics/field_trial.h"
18 #include "media/base/android/media_codec_bridge.h"
20 #include "base/win/windows_version.h"
23 using blink::WebRuntimeFeatures
;
27 static void SetRuntimeFeatureDefaultsForPlatform() {
28 #if defined(OS_ANDROID)
29 // MSE/EME implementation needs Android MediaCodec API.
30 if (!media::MediaCodecBridge::IsAvailable()) {
31 WebRuntimeFeatures::enableMediaSource(false);
32 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
33 WebRuntimeFeatures::enableEncryptedMedia(false);
35 // WebAudio is enabled by default but only when the MediaCodec API
37 AndroidCpuFamily cpu_family
= android_getCpuFamily();
38 WebRuntimeFeatures::enableWebAudio(
39 media::MediaCodecBridge::IsAvailable() &&
40 ((cpu_family
== ANDROID_CPU_FAMILY_ARM
) ||
41 (cpu_family
== ANDROID_CPU_FAMILY_ARM64
) ||
42 (cpu_family
== ANDROID_CPU_FAMILY_X86
) ||
43 (cpu_family
== ANDROID_CPU_FAMILY_MIPS
)));
45 // Android supports gamepad API for JellyBean and beyond
46 WebRuntimeFeatures::enableGamepad(
47 base::android::BuildInfo::GetInstance()->sdk_int() >= 16);
48 // Android does not have support for PagePopup
49 WebRuntimeFeatures::enablePagePopup(false);
50 // Android does not yet support the Web Notification API. crbug.com/115320
51 WebRuntimeFeatures::enableNotifications(false);
52 // Android does not yet support SharedWorker. crbug.com/154571
53 WebRuntimeFeatures::enableSharedWorker(false);
54 // Android does not yet support NavigatorContentUtils.
55 WebRuntimeFeatures::enableNavigatorContentUtils(false);
56 WebRuntimeFeatures::enableTouchIconLoading(true);
57 WebRuntimeFeatures::enableOrientationEvent(true);
58 WebRuntimeFeatures::enableFastMobileScrolling(true);
59 WebRuntimeFeatures::enableMediaCapture(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);
66 WebRuntimeFeatures::enableNavigatorContentUtils(true);
67 #endif // defined(OS_ANDROID)
69 #if !(defined OS_ANDROID || defined OS_CHROMEOS || defined OS_IOS)
70 // Only Android, ChromeOS, and IOS support NetInfo right now.
71 WebRuntimeFeatures::enableNetworkInformation(false);
75 // Screen Orientation API is currently broken on Windows 8 Metro mode and
76 // until we can find how to disable it only for Blink instances running in a
77 // renderer process in Metro, we need to disable the API altogether for Win8.
78 // See http://crbug.com/400846
79 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8
)
80 WebRuntimeFeatures::enableScreenOrientation(false);
84 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
85 const base::CommandLine
& command_line
) {
86 if (command_line
.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures
))
87 WebRuntimeFeatures::enableExperimentalFeatures(true);
89 SetRuntimeFeatureDefaultsForPlatform();
91 if (command_line
.HasSwitch(switches::kDisableDatabases
))
92 WebRuntimeFeatures::enableDatabase(false);
94 if (command_line
.HasSwitch(switches::kDisableApplicationCache
))
95 WebRuntimeFeatures::enableApplicationCache(false);
97 if (command_line
.HasSwitch(switches::kDisableDesktopNotifications
))
98 WebRuntimeFeatures::enableNotifications(false);
100 if (command_line
.HasSwitch(switches::kDisableLocalStorage
))
101 WebRuntimeFeatures::enableLocalStorage(false);
103 if (command_line
.HasSwitch(switches::kDisableSessionStorage
))
104 WebRuntimeFeatures::enableSessionStorage(false);
106 if (command_line
.HasSwitch(switches::kDisableMediaSource
))
107 WebRuntimeFeatures::enableMediaSource(false);
109 if (command_line
.HasSwitch(switches::kDisableSharedWorkers
))
110 WebRuntimeFeatures::enableSharedWorker(false);
112 #if defined(OS_ANDROID)
113 if (command_line
.HasSwitch(switches::kDisableWebRTC
)) {
114 WebRuntimeFeatures::enableMediaStream(false);
115 WebRuntimeFeatures::enablePeerConnection(false);
118 if (!command_line
.HasSwitch(switches::kEnableSpeechRecognition
))
119 WebRuntimeFeatures::enableScriptedSpeech(false);
121 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
123 WebRuntimeFeatures::enableWebAudio(
124 !command_line
.HasSwitch(switches::kDisableWebAudio
) &&
125 media::MediaCodecBridge::IsAvailable());
127 if (command_line
.HasSwitch(switches::kDisableWebAudio
))
128 WebRuntimeFeatures::enableWebAudio(false);
131 if (command_line
.HasSwitch(switches::kEnableEncryptedMedia
))
132 WebRuntimeFeatures::enableEncryptedMedia(true);
134 if (command_line
.HasSwitch(switches::kDisablePrefixedEncryptedMedia
))
135 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
137 if (command_line
.HasSwitch(switches::kEnableWebAnimationsSVG
))
138 WebRuntimeFeatures::enableWebAnimationsSVG(true);
140 if (command_line
.HasSwitch(switches::kEnableWebMIDI
))
141 WebRuntimeFeatures::enableWebMIDI(true);
143 if (command_line
.HasSwitch(switches::kDisableFileSystem
))
144 WebRuntimeFeatures::enableFileSystem(false);
146 if (command_line
.HasSwitch(switches::kEnableExperimentalCanvasFeatures
))
147 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
149 if (command_line
.HasSwitch(switches::kDisableDisplayList2dCanvas
)) {
150 WebRuntimeFeatures::enableDisplayList2dCanvas(false);
151 } else if (command_line
.HasSwitch(switches::kEnableDisplayList2dCanvas
)) {
152 WebRuntimeFeatures::enableDisplayList2dCanvas(true);
154 WebRuntimeFeatures::enableDisplayList2dCanvas(
155 base::FieldTrialList::FindFullName("DisplayList2dCanvas") == "Enabled"
159 if (command_line
.HasSwitch(switches::kEnableWebGLDraftExtensions
))
160 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
162 if (command_line
.HasSwitch(switches::kEnableWebGLImageChromium
))
163 WebRuntimeFeatures::enableWebGLImageChromium(true);
165 if (command_line
.HasSwitch(switches::kEnableOverlayFullscreenVideo
))
166 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
168 if (ui::IsOverlayScrollbarEnabled())
169 WebRuntimeFeatures::enableOverlayScrollbars(true);
171 if (command_line
.HasSwitch(switches::kEnableTargetedStyleRecalc
))
172 WebRuntimeFeatures::enableTargetedStyleRecalc(true);
174 if (command_line
.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths
))
175 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
177 if (command_line
.HasSwitch(switches::kEnablePreciseMemoryInfo
))
178 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
180 if (command_line
.HasSwitch(switches::kEnableLayerSquashing
))
181 WebRuntimeFeatures::enableLayerSquashing(true);
183 if (command_line
.HasSwitch(switches::kEnableNetworkInformation
) ||
184 command_line
.HasSwitch(
185 switches::kEnableExperimentalWebPlatformFeatures
)) {
186 WebRuntimeFeatures::enableNetworkInformation(true);
190 } // namespace content