• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "content/child/runtime_features.h"
6 
7 #include "base/command_line.h"
8 #include "content/public/common/content_switches.h"
9 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
10 
11 #if defined(OS_ANDROID)
12 #include <cpu-features.h>
13 #include "media/base/android/media_codec_bridge.h"
14 #endif
15 
16 using blink::WebRuntimeFeatures;
17 
18 namespace content {
19 
SetRuntimeFeatureDefaultsForPlatform()20 static void SetRuntimeFeatureDefaultsForPlatform() {
21 #if defined(OS_ANDROID)
22 #if !defined(GOOGLE_TV)
23   // MSE/EME implementation needs Android MediaCodec API.
24   if (!media::MediaCodecBridge::IsAvailable()) {
25     WebRuntimeFeatures::enableWebKitMediaSource(false);
26     WebRuntimeFeatures::enableMediaSource(false);
27     WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
28   }
29 #endif  // !defined(GOOGLE_TV)
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_getCpuFamily() == ANDROID_CPU_FAMILY_ARM));
35   // Android does not support the Gamepad API.
36   WebRuntimeFeatures::enableGamepad(false);
37   // Android does not have support for PagePopup
38   WebRuntimeFeatures::enablePagePopup(false);
39   // Android does not yet support the Web Notification API. crbug.com/115320
40   WebRuntimeFeatures::enableNotifications(false);
41   // Android does not yet support SharedWorker. crbug.com/154571
42   WebRuntimeFeatures::enableSharedWorker(false);
43   // Android does not yet support NavigatorContentUtils.
44   WebRuntimeFeatures::enableNavigatorContentUtils(false);
45 #endif  // defined(OS_ANDROID)
46 }
47 
SetRuntimeFeaturesDefaultsAndUpdateFromArgs(const CommandLine & command_line)48 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
49     const CommandLine& command_line) {
50   WebRuntimeFeatures::enableStableFeatures(true);
51 
52   if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
53     WebRuntimeFeatures::enableExperimentalFeatures(true);
54 
55   SetRuntimeFeatureDefaultsForPlatform();
56 
57   if (command_line.HasSwitch(switches::kDisableDatabases))
58     WebRuntimeFeatures::enableDatabase(false);
59 
60   if (command_line.HasSwitch(switches::kDisableApplicationCache))
61     WebRuntimeFeatures::enableApplicationCache(false);
62 
63   if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
64     WebRuntimeFeatures::enableNotifications(false);
65 
66   if (command_line.HasSwitch(switches::kDisableNavigatorContentUtils))
67     WebRuntimeFeatures::enableNavigatorContentUtils(false);
68 
69   if (command_line.HasSwitch(switches::kDisableLocalStorage))
70     WebRuntimeFeatures::enableLocalStorage(false);
71 
72   if (command_line.HasSwitch(switches::kDisableSessionStorage))
73     WebRuntimeFeatures::enableSessionStorage(false);
74 
75   if (command_line.HasSwitch(switches::kDisableGeolocation))
76     WebRuntimeFeatures::enableGeolocation(false);
77 
78   if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
79     WebRuntimeFeatures::enableWebKitMediaSource(false);
80 
81   if (command_line.HasSwitch(switches::kDisableUnprefixedMediaSource))
82     WebRuntimeFeatures::enableMediaSource(false);
83 
84   if (command_line.HasSwitch(switches::kDisableSharedWorkers))
85     WebRuntimeFeatures::enableSharedWorker(false);
86 
87 #if defined(OS_ANDROID)
88   if (command_line.HasSwitch(switches::kDisableWebRTC)) {
89     WebRuntimeFeatures::enableMediaStream(false);
90     WebRuntimeFeatures::enablePeerConnection(false);
91   }
92 
93   if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
94     WebRuntimeFeatures::enableScriptedSpeech(false);
95 #endif
96 
97   if (command_line.HasSwitch(switches::kEnableServiceWorker))
98     WebRuntimeFeatures::enableServiceWorker(true);
99 
100 #if defined(OS_ANDROID)
101   // WebAudio requires the MediaCodec API.
102 #if defined(ARCH_CPU_X86)
103   // WebAudio is disabled by default on x86.
104   WebRuntimeFeatures::enableWebAudio(
105       command_line.HasSwitch(switches::kEnableWebAudio) &&
106       media::MediaCodecBridge::IsAvailable());
107 #elif defined(ARCH_CPU_ARMEL)
108   // WebAudio is enabled by default on ARM.
109   WebRuntimeFeatures::enableWebAudio(
110       !command_line.HasSwitch(switches::kDisableWebAudio) &&
111       media::MediaCodecBridge::IsAvailable());
112 #else
113   WebRuntimeFeatures::enableWebAudio(false);
114 #endif
115 #else
116   if (command_line.HasSwitch(switches::kDisableWebAudio))
117     WebRuntimeFeatures::enableWebAudio(false);
118 #endif
119 
120   if (command_line.HasSwitch(switches::kDisableFullScreen))
121     WebRuntimeFeatures::enableFullscreen(false);
122 
123   if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
124     WebRuntimeFeatures::enableEncryptedMedia(true);
125 
126   if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
127     WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
128 
129   // FIXME: Remove the enable switch once Web Animations CSS is enabled by
130   // default in Blink.
131   if (command_line.HasSwitch(switches::kEnableWebAnimationsCSS))
132     WebRuntimeFeatures::enableWebAnimationsCSS(true);
133   else if (command_line.HasSwitch(switches::kDisableWebAnimationsCSS))
134     WebRuntimeFeatures::enableWebAnimationsCSS(false);
135 
136   if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
137     WebRuntimeFeatures::enableWebAnimationsSVG(true);
138 
139   if (command_line.HasSwitch(switches::kEnableWebMIDI))
140     WebRuntimeFeatures::enableWebMIDI(true);
141 
142   if (command_line.HasSwitch(switches::kDisableDeviceMotion))
143     WebRuntimeFeatures::enableDeviceMotion(false);
144 
145   if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
146     WebRuntimeFeatures::enableDeviceOrientation(false);
147 
148   if (command_line.HasSwitch(switches::kDisableSpeechInput))
149     WebRuntimeFeatures::enableSpeechInput(false);
150 
151   if (command_line.HasSwitch(switches::kDisableFileSystem))
152     WebRuntimeFeatures::enableFileSystem(false);
153 
154 #if defined(OS_WIN)
155   if (command_line.HasSwitch(switches::kEnableDirectWrite))
156     WebRuntimeFeatures::enableDirectWrite(true);
157 #endif
158 
159   if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
160     WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
161 
162   if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
163     WebRuntimeFeatures::enableSpeechSynthesis(true);
164 
165   if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
166     WebRuntimeFeatures::enableWebGLDraftExtensions(true);
167 
168   if (command_line.HasSwitch(switches::kEnableHTMLImports))
169     WebRuntimeFeatures::enableHTMLImports(true);
170 
171   if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
172     WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
173 
174   if (command_line.HasSwitch(switches::kEnableOverlayScrollbars))
175     WebRuntimeFeatures::enableOverlayScrollbars(true);
176 
177   if (command_line.HasSwitch(switches::kEnableInputModeAttribute))
178     WebRuntimeFeatures::enableInputModeAttribute(true);
179 
180   if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
181     WebRuntimeFeatures::enableFastTextAutosizing(true);
182 
183   if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
184     WebRuntimeFeatures::enableRepaintAfterLayout(true);
185 }
186 
187 }  // namespace content
188