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 "content/common/content_switches_internal.h"
9 #include "content/public/common/content_switches.h"
10 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
11 #include "ui/native_theme/native_theme_switches.h"
13 #if defined(OS_ANDROID)
14 #include <cpu-features.h>
15 #include "base/android/build_info.h"
16 #include "media/base/android/media_codec_bridge.h"
19 using blink::WebRuntimeFeatures
;
23 static void SetRuntimeFeatureDefaultsForPlatform() {
24 #if defined(OS_ANDROID)
25 // MSE/EME implementation needs Android MediaCodec API.
26 if (!media::MediaCodecBridge::IsAvailable()) {
27 WebRuntimeFeatures::enableMediaSource(false);
28 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
29 WebRuntimeFeatures::enableEncryptedMedia(false);
31 // WebAudio is enabled by default but only when the MediaCodec API
33 AndroidCpuFamily cpu_family
= android_getCpuFamily();
34 WebRuntimeFeatures::enableWebAudio(
35 media::MediaCodecBridge::IsAvailable() &&
36 ((cpu_family
== ANDROID_CPU_FAMILY_ARM
) ||
37 (cpu_family
== ANDROID_CPU_FAMILY_ARM64
) ||
38 (cpu_family
== ANDROID_CPU_FAMILY_X86
) ||
39 (cpu_family
== ANDROID_CPU_FAMILY_MIPS
)));
41 // Android supports gamepad API for JellyBean and beyond
42 WebRuntimeFeatures::enableGamepad(
43 base::android::BuildInfo::GetInstance()->sdk_int() >= 16);
44 // Android does not have support for PagePopup
45 WebRuntimeFeatures::enablePagePopup(false);
46 // Android does not yet support the Web Notification API. crbug.com/115320
47 WebRuntimeFeatures::enableNotifications(false);
48 // Android does not yet support SharedWorker. crbug.com/154571
49 WebRuntimeFeatures::enableSharedWorker(false);
50 // Android does not yet support NavigatorContentUtils.
51 WebRuntimeFeatures::enableNavigatorContentUtils(false);
52 WebRuntimeFeatures::enableTouchIconLoading(true);
53 WebRuntimeFeatures::enableOrientationEvent(true);
54 WebRuntimeFeatures::enableFastMobileScrolling(true);
55 WebRuntimeFeatures::enableMediaCapture(true);
57 WebRuntimeFeatures::enableNavigatorContentUtils(true);
58 #endif // defined(OS_ANDROID)
61 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
62 const CommandLine
& command_line
) {
63 if (command_line
.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures
))
64 WebRuntimeFeatures::enableExperimentalFeatures(true);
66 SetRuntimeFeatureDefaultsForPlatform();
68 if (command_line
.HasSwitch(switches::kDisableDatabases
))
69 WebRuntimeFeatures::enableDatabase(false);
71 if (command_line
.HasSwitch(switches::kDisableApplicationCache
))
72 WebRuntimeFeatures::enableApplicationCache(false);
74 if (command_line
.HasSwitch(switches::kDisableDesktopNotifications
))
75 WebRuntimeFeatures::enableNotifications(false);
77 if (command_line
.HasSwitch(switches::kDisableNavigatorContentUtils
))
78 WebRuntimeFeatures::enableNavigatorContentUtils(false);
80 if (command_line
.HasSwitch(switches::kDisableLocalStorage
))
81 WebRuntimeFeatures::enableLocalStorage(false);
83 if (command_line
.HasSwitch(switches::kDisableSessionStorage
))
84 WebRuntimeFeatures::enableSessionStorage(false);
86 if (command_line
.HasSwitch(switches::kDisableMediaSource
))
87 WebRuntimeFeatures::enableMediaSource(false);
89 if (command_line
.HasSwitch(switches::kDisableSharedWorkers
))
90 WebRuntimeFeatures::enableSharedWorker(false);
92 #if defined(OS_ANDROID)
93 if (command_line
.HasSwitch(switches::kDisableWebRTC
)) {
94 WebRuntimeFeatures::enableMediaStream(false);
95 WebRuntimeFeatures::enablePeerConnection(false);
98 if (!command_line
.HasSwitch(switches::kEnableSpeechRecognition
))
99 WebRuntimeFeatures::enableScriptedSpeech(false);
101 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
103 WebRuntimeFeatures::enableWebAudio(
104 !command_line
.HasSwitch(switches::kDisableWebAudio
) &&
105 media::MediaCodecBridge::IsAvailable());
107 if (command_line
.HasSwitch(switches::kDisableWebAudio
))
108 WebRuntimeFeatures::enableWebAudio(false);
111 if (command_line
.HasSwitch(switches::kEnableEncryptedMedia
))
112 WebRuntimeFeatures::enableEncryptedMedia(true);
114 if (command_line
.HasSwitch(switches::kDisablePrefixedEncryptedMedia
))
115 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
117 if (command_line
.HasSwitch(switches::kEnableWebAnimationsSVG
))
118 WebRuntimeFeatures::enableWebAnimationsSVG(true);
120 if (command_line
.HasSwitch(switches::kEnableWebMIDI
))
121 WebRuntimeFeatures::enableWebMIDI(true);
123 if (command_line
.HasSwitch(switches::kDisableFileSystem
))
124 WebRuntimeFeatures::enableFileSystem(false);
126 if (command_line
.HasSwitch(switches::kEnableExperimentalCanvasFeatures
))
127 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
129 if (command_line
.HasSwitch(switches::kEnableSpeechSynthesis
))
130 WebRuntimeFeatures::enableSpeechSynthesis(true);
132 if (command_line
.HasSwitch(switches::kEnableWebGLDraftExtensions
))
133 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
135 if (command_line
.HasSwitch(switches::kEnableWebGLImageChromium
))
136 WebRuntimeFeatures::enableWebGLImageChromium(true);
138 if (command_line
.HasSwitch(switches::kEnableOverlayFullscreenVideo
))
139 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
141 if (ui::IsOverlayScrollbarEnabled())
142 WebRuntimeFeatures::enableOverlayScrollbars(true);
144 if (command_line
.HasSwitch(switches::kEnableFastTextAutosizing
))
145 WebRuntimeFeatures::enableFastTextAutosizing(true);
147 if (command_line
.HasSwitch(switches::kDisableFastTextAutosizing
))
148 WebRuntimeFeatures::enableFastTextAutosizing(false);
150 if (command_line
.HasSwitch(switches::kEnableTargetedStyleRecalc
))
151 WebRuntimeFeatures::enableTargetedStyleRecalc(true);
153 if (command_line
.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths
))
154 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
156 if (command_line
.HasSwitch(switches::kEnablePreciseMemoryInfo
))
157 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
159 if (command_line
.HasSwitch(switches::kEnableLayerSquashing
))
160 WebRuntimeFeatures::enableLayerSquashing(true);
163 } // namespace content