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"
12 #if defined(OS_ANDROID)
13 #include <cpu-features.h>
14 #include "base/android/build_info.h"
15 #include "media/base/android/media_codec_bridge.h"
18 using blink::WebRuntimeFeatures;
22 static void SetRuntimeFeatureDefaultsForPlatform() {
23 #if defined(OS_ANDROID)
24 // MSE/EME implementation needs Android MediaCodec API.
25 if (!media::MediaCodecBridge::IsAvailable()) {
26 WebRuntimeFeatures::enableWebKitMediaSource(false);
27 WebRuntimeFeatures::enableMediaSource(false);
28 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
30 // WebAudio is enabled by default only on ARM and only when the
31 // MediaCodec API is available.
32 WebRuntimeFeatures::enableWebAudio(
33 media::MediaCodecBridge::IsAvailable());
34 // Android does not support the Gamepad API.
35 WebRuntimeFeatures::enableGamepad(false);
36 // Android does not have support for PagePopup
37 WebRuntimeFeatures::enablePagePopup(false);
38 // Crosswalk supports the Web Notification API on Android.
39 WebRuntimeFeatures::enableNotifications(true);
40 // Android does not yet support SharedWorker. crbug.com/154571
41 WebRuntimeFeatures::enableSharedWorker(false);
42 // Android does not yet support NavigatorContentUtils.
43 WebRuntimeFeatures::enableNavigatorContentUtils(false);
44 WebRuntimeFeatures::enableTouchIconLoading(true);
45 WebRuntimeFeatures::enableOrientationEvent(true);
47 WebRuntimeFeatures::enableNavigatorContentUtils(true);
48 #endif // defined(OS_ANDROID)
51 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
52 const CommandLine& command_line) {
53 WebRuntimeFeatures::enableStableFeatures(true);
55 if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
56 WebRuntimeFeatures::enableExperimentalFeatures(true);
58 SetRuntimeFeatureDefaultsForPlatform();
60 if (command_line.HasSwitch(switches::kDisableDatabases))
61 WebRuntimeFeatures::enableDatabase(false);
63 if (command_line.HasSwitch(switches::kDisableApplicationCache))
64 WebRuntimeFeatures::enableApplicationCache(false);
66 if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
67 WebRuntimeFeatures::enableNotifications(false);
69 if (command_line.HasSwitch(switches::kDisableNavigatorContentUtils))
70 WebRuntimeFeatures::enableNavigatorContentUtils(false);
72 if (command_line.HasSwitch(switches::kDisableLocalStorage))
73 WebRuntimeFeatures::enableLocalStorage(false);
75 if (command_line.HasSwitch(switches::kDisableSessionStorage))
76 WebRuntimeFeatures::enableSessionStorage(false);
78 if (command_line.HasSwitch(switches::kDisableGeolocation))
79 WebRuntimeFeatures::enableGeolocation(false);
81 if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
82 WebRuntimeFeatures::enableWebKitMediaSource(false);
84 if (command_line.HasSwitch(switches::kDisableUnprefixedMediaSource))
85 WebRuntimeFeatures::enableMediaSource(false);
87 if (command_line.HasSwitch(switches::kDisableSharedWorkers))
88 WebRuntimeFeatures::enableSharedWorker(false);
90 #if defined(OS_ANDROID)
91 if (command_line.HasSwitch(switches::kDisableWebRTC)) {
92 WebRuntimeFeatures::enableMediaStream(false);
93 WebRuntimeFeatures::enablePeerConnection(false);
96 if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
97 WebRuntimeFeatures::enableScriptedSpeech(false);
100 if (command_line.HasSwitch(switches::kEnableServiceWorker))
101 WebRuntimeFeatures::enableServiceWorker(true);
103 #if defined(OS_ANDROID)
104 // WebAudio requires the MediaCodec API.
105 #if defined(ARCH_CPU_X86)
106 // WebAudio is disabled by default on x86.
107 WebRuntimeFeatures::enableWebAudio(
108 command_line.HasSwitch(switches::kEnableWebAudio) &&
109 media::MediaCodecBridge::IsAvailable());
110 #elif defined(ARCH_CPU_ARMEL)
111 // WebAudio is enabled by default on ARM.
112 WebRuntimeFeatures::enableWebAudio(
113 !command_line.HasSwitch(switches::kDisableWebAudio) &&
114 media::MediaCodecBridge::IsAvailable());
116 WebRuntimeFeatures::enableWebAudio(false);
119 if (command_line.HasSwitch(switches::kDisableWebAudio))
120 WebRuntimeFeatures::enableWebAudio(false);
123 if (command_line.HasSwitch(switches::kDisableFullScreen))
124 WebRuntimeFeatures::enableFullscreen(false);
126 if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
127 WebRuntimeFeatures::enableEncryptedMedia(true);
129 if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
130 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
132 // FIXME: Remove the enable switch once Web Animations CSS is enabled by
134 if (command_line.HasSwitch(switches::kEnableWebAnimationsCSS))
135 WebRuntimeFeatures::enableWebAnimationsCSS(true);
136 else if (command_line.HasSwitch(switches::kDisableWebAnimationsCSS))
137 WebRuntimeFeatures::enableWebAnimationsCSS(false);
139 if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
140 WebRuntimeFeatures::enableWebAnimationsSVG(true);
142 if (command_line.HasSwitch(switches::kEnableWebMIDI))
143 WebRuntimeFeatures::enableWebMIDI(true);
145 if (command_line.HasSwitch(switches::kDisableDeviceMotion))
146 WebRuntimeFeatures::enableDeviceMotion(false);
148 if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
149 WebRuntimeFeatures::enableDeviceOrientation(false);
151 if (command_line.HasSwitch(switches::kDisableSpeechInput))
152 WebRuntimeFeatures::enableSpeechInput(false);
154 if (command_line.HasSwitch(switches::kDisableFileSystem))
155 WebRuntimeFeatures::enableFileSystem(false);
158 if (command_line.HasSwitch(switches::kEnableDirectWrite))
159 WebRuntimeFeatures::enableDirectWrite(true);
162 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
163 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
165 if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
166 WebRuntimeFeatures::enableSpeechSynthesis(true);
168 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
169 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
171 if (command_line.HasSwitch(switches::kEnableHTMLImports))
172 WebRuntimeFeatures::enableHTMLImports(true);
174 if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
175 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
177 if (IsOverlayScrollbarEnabled())
178 WebRuntimeFeatures::enableOverlayScrollbars(true);
180 if (command_line.HasSwitch(switches::kEnableInputModeAttribute))
181 WebRuntimeFeatures::enableInputModeAttribute(true);
183 if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
184 WebRuntimeFeatures::enableFastTextAutosizing(true);
186 if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
187 WebRuntimeFeatures::enableRepaintAfterLayout(true);
190 } // namespace content