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 "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::enableMediaSource(false);
27 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
28 WebRuntimeFeatures::enableEncryptedMedia(false);
30 // WebAudio is enabled by default on ARM and X86 and only when the
31 // MediaCodec API is available.
32 WebRuntimeFeatures::enableWebAudio(
33 media::MediaCodecBridge::IsAvailable() &&
34 ((android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) ||
35 (android_getCpuFamily() == ANDROID_CPU_FAMILY_X86)));
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 // Crosswalk supports the Web Notification API on Android.
41 WebRuntimeFeatures::enableNotifications(true);
42 // Android does not yet support SharedWorker. crbug.com/154571
43 WebRuntimeFeatures::enableSharedWorker(false);
44 // Android does not yet support NavigatorContentUtils.
45 WebRuntimeFeatures::enableNavigatorContentUtils(false);
46 WebRuntimeFeatures::enableTouchIconLoading(true);
47 WebRuntimeFeatures::enableScreenOrientation(true);
48 WebRuntimeFeatures::enableOrientationEvent(true);
50 WebRuntimeFeatures::enableNavigatorContentUtils(true);
51 #endif // defined(OS_ANDROID)
53 WebRuntimeFeatures::enableScreenOrientation(true);
54 WebRuntimeFeatures::enableOrientationEvent(true);
55 #endif // defined(OS_TIZEN)
58 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
59 const CommandLine& command_line) {
60 if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
61 WebRuntimeFeatures::enableExperimentalFeatures(true);
63 SetRuntimeFeatureDefaultsForPlatform();
65 if (command_line.HasSwitch(switches::kDisableDatabases))
66 WebRuntimeFeatures::enableDatabase(false);
68 if (command_line.HasSwitch(switches::kDisableApplicationCache))
69 WebRuntimeFeatures::enableApplicationCache(false);
71 if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
72 WebRuntimeFeatures::enableNotifications(false);
74 if (command_line.HasSwitch(switches::kDisableNavigatorContentUtils))
75 WebRuntimeFeatures::enableNavigatorContentUtils(false);
77 if (command_line.HasSwitch(switches::kDisableLocalStorage))
78 WebRuntimeFeatures::enableLocalStorage(false);
80 if (command_line.HasSwitch(switches::kDisableSessionStorage))
81 WebRuntimeFeatures::enableSessionStorage(false);
83 if (command_line.HasSwitch(switches::kDisableMediaSource))
84 WebRuntimeFeatures::enableMediaSource(false);
86 if (command_line.HasSwitch(switches::kDisableSharedWorkers))
87 WebRuntimeFeatures::enableSharedWorker(false);
89 #if defined(OS_ANDROID)
90 if (command_line.HasSwitch(switches::kDisableWebRTC)) {
91 WebRuntimeFeatures::enableMediaStream(false);
92 WebRuntimeFeatures::enablePeerConnection(false);
95 if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
96 WebRuntimeFeatures::enableScriptedSpeech(false);
99 if (command_line.HasSwitch(switches::kEnableServiceWorker))
100 WebRuntimeFeatures::enableServiceWorker(true);
102 #if defined(OS_ANDROID)
103 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
105 WebRuntimeFeatures::enableWebAudio(
106 !command_line.HasSwitch(switches::kDisableWebAudio) &&
107 media::MediaCodecBridge::IsAvailable());
109 if (command_line.HasSwitch(switches::kDisableWebAudio))
110 WebRuntimeFeatures::enableWebAudio(false);
113 if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
114 WebRuntimeFeatures::enableEncryptedMedia(true);
116 if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
117 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
119 if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
120 WebRuntimeFeatures::enableWebAnimationsSVG(true);
122 if (command_line.HasSwitch(switches::kEnableWebMIDI))
123 WebRuntimeFeatures::enableWebMIDI(true);
125 if (command_line.HasSwitch(switches::kDisableFileSystem))
126 WebRuntimeFeatures::enableFileSystem(false);
128 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
129 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
131 if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
132 WebRuntimeFeatures::enableSpeechSynthesis(true);
134 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
135 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
137 if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
138 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
140 if (ui::IsOverlayScrollbarEnabled())
141 WebRuntimeFeatures::enableOverlayScrollbars(true);
143 if (command_line.HasSwitch(switches::kEnableFastTextAutosizing)
144 && !command_line.HasSwitch(switches::kDisableFastTextAutosizing))
145 WebRuntimeFeatures::enableFastTextAutosizing(true);
147 if (command_line.HasSwitch(switches::kDisableRepaintAfterLayout))
148 WebRuntimeFeatures::enableRepaintAfterLayout(false);
150 if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
151 WebRuntimeFeatures::enableRepaintAfterLayout(true);
153 if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
154 WebRuntimeFeatures::enableTargetedStyleRecalc(true);
156 if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
157 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
159 if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
160 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
163 } // namespace content