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/public/common/content_switches.h"
9 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
11 #if defined(OS_ANDROID)
12 #include <cpu-features.h>
13 #include "base/android/build_info.h"
14 #include "media/base/android/media_codec_bridge.h"
17 using WebKit::WebRuntimeFeatures;
21 static void SetRuntimeFeatureDefaultsForPlatform() {
22 #if defined(OS_ANDROID)
23 #if !defined(GOOGLE_TV)
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 #endif // !defined(GOOGLE_TV)
31 // WebAudio needs Android MediaCodec API that was introduced in
33 bool enable_webaudio =
34 (base::android::BuildInfo::GetInstance()->sdk_int() >= 16);
35 WebRuntimeFeatures::enableWebAudio(enable_webaudio);
36 // Android does not support the Gamepad API.
37 WebRuntimeFeatures::enableGamepad(false);
38 // Android does not have support for PagePopup
39 WebRuntimeFeatures::enablePagePopup(false);
40 // datalist on Android is not enabled
41 WebRuntimeFeatures::enableDataListElement(false);
42 // Android does not yet support the Web Notification API. crbug.com/115320
43 WebRuntimeFeatures::enableNotifications(false);
44 // Android does not yet support SharedWorker. crbug.com/154571
45 WebRuntimeFeatures::enableSharedWorker(false);
46 #endif // defined(OS_ANDROID)
49 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
50 const CommandLine& command_line) {
51 WebRuntimeFeatures::enableStableFeatures(true);
53 if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
54 WebRuntimeFeatures::enableExperimentalFeatures(true);
56 SetRuntimeFeatureDefaultsForPlatform();
58 if (command_line.HasSwitch(switches::kDisableDatabases))
59 WebRuntimeFeatures::enableDatabase(false);
61 if (command_line.HasSwitch(switches::kDisableApplicationCache))
62 WebRuntimeFeatures::enableApplicationCache(false);
64 if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
65 WebRuntimeFeatures::enableNotifications(false);
67 if (command_line.HasSwitch(switches::kDisableLocalStorage))
68 WebRuntimeFeatures::enableLocalStorage(false);
70 if (command_line.HasSwitch(switches::kDisableSessionStorage))
71 WebRuntimeFeatures::enableSessionStorage(false);
73 if (command_line.HasSwitch(switches::kDisableGeolocation))
74 WebRuntimeFeatures::enableGeolocation(false);
76 if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
77 WebRuntimeFeatures::enableWebKitMediaSource(false);
79 if (command_line.HasSwitch(switches::kDisableUnprefixedMediaSource))
80 WebRuntimeFeatures::enableMediaSource(false);
82 if (command_line.HasSwitch(switches::kDisableSharedWorkers))
83 WebRuntimeFeatures::enableSharedWorker(false);
85 #if defined(OS_ANDROID)
86 if (command_line.HasSwitch(switches::kDisableWebRTC)) {
87 WebRuntimeFeatures::enableMediaStream(false);
88 WebRuntimeFeatures::enablePeerConnection(false);
91 if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
92 WebRuntimeFeatures::enableScriptedSpeech(false);
95 if (command_line.HasSwitch(switches::kEnableServiceWorker))
96 WebRuntimeFeatures::enableServiceWorker(true);
98 if (command_line.HasSwitch(switches::kDisableWebAudio))
99 WebRuntimeFeatures::enableWebAudio(false);
101 if (command_line.HasSwitch(switches::kDisableFullScreen))
102 WebRuntimeFeatures::enableFullscreen(false);
104 if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
105 WebRuntimeFeatures::enableEncryptedMedia(true);
107 if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
108 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
110 if (command_line.HasSwitch(switches::kEnableWebAnimationsCSS))
111 WebRuntimeFeatures::enableWebAnimationsCSS();
113 if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
114 WebRuntimeFeatures::enableWebAnimationsSVG();
116 if (command_line.HasSwitch(switches::kEnableWebMIDI))
117 WebRuntimeFeatures::enableWebMIDI(true);
119 if (command_line.HasSwitch(switches::kDisableDeviceMotion))
120 WebRuntimeFeatures::enableDeviceMotion(false);
122 if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
123 WebRuntimeFeatures::enableDeviceOrientation(false);
125 if (command_line.HasSwitch(switches::kDisableSpeechInput))
126 WebRuntimeFeatures::enableSpeechInput(false);
128 if (command_line.HasSwitch(switches::kDisableFileSystem))
129 WebRuntimeFeatures::enableFileSystem(false);
131 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
132 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
134 if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
135 WebRuntimeFeatures::enableSpeechSynthesis(true);
137 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
138 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
140 if (command_line.HasSwitch(switches::kEnableHTMLImports))
141 WebRuntimeFeatures::enableHTMLImports(true);
143 if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
144 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
146 if (command_line.HasSwitch(switches::kEnableOverlayScrollbars))
147 WebRuntimeFeatures::enableOverlayScrollbars(true);
149 if (command_line.HasSwitch(switches::kEnableInputModeAttribute))
150 WebRuntimeFeatures::enableInputModeAttribute(true);
152 if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
153 WebRuntimeFeatures::enableFastTextAutosizing(true);
155 if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
156 WebRuntimeFeatures::enableRepaintAfterLayout(true);
159 } // namespace content