runtime_features.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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
16using WebKit::WebRuntimeFeatures;
17
18namespace content {
19
20static 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  bool enable_webaudio = false;
31#if defined(ARCH_CPU_ARMEL)
32  // WebAudio needs Android MediaCodec API, and also currently needs NEON
33  // support for the FFT.
34  enable_webaudio =
35      (media::MediaCodecBridge::IsAvailable()) &&
36      ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
37#endif  // defined(ARCH_CPU_ARMEL)
38  WebRuntimeFeatures::enableWebAudio(enable_webaudio);
39  // Android does not support the Gamepad API.
40  WebRuntimeFeatures::enableGamepad(false);
41  // Android does not have support for PagePopup
42  WebRuntimeFeatures::enablePagePopup(false);
43  // datalist on Android is not enabled
44  WebRuntimeFeatures::enableDataListElement(false);
45  // Android does not yet support the Web Notification API. crbug.com/115320
46  WebRuntimeFeatures::enableNotifications(false);
47  // Android does not yet support SharedWorker. crbug.com/154571
48  WebRuntimeFeatures::enableSharedWorker(false);
49#endif  // defined(OS_ANDROID)
50}
51
52void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
53    const CommandLine& command_line) {
54  WebRuntimeFeatures::enableStableFeatures(true);
55
56  if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
57    WebRuntimeFeatures::enableExperimentalFeatures(true);
58
59  SetRuntimeFeatureDefaultsForPlatform();
60
61  if (command_line.HasSwitch(switches::kDisableDatabases))
62    WebRuntimeFeatures::enableDatabase(false);
63
64  if (command_line.HasSwitch(switches::kDisableApplicationCache))
65    WebRuntimeFeatures::enableApplicationCache(false);
66
67  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
68    WebRuntimeFeatures::enableNotifications(false);
69
70  if (command_line.HasSwitch(switches::kDisableLocalStorage))
71    WebRuntimeFeatures::enableLocalStorage(false);
72
73  if (command_line.HasSwitch(switches::kDisableSessionStorage))
74    WebRuntimeFeatures::enableSessionStorage(false);
75
76  if (command_line.HasSwitch(switches::kDisableGeolocation))
77    WebRuntimeFeatures::enableGeolocation(false);
78
79  if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
80    WebRuntimeFeatures::enableWebKitMediaSource(false);
81
82  if (command_line.HasSwitch(switches::kDisableUnprefixedMediaSource))
83    WebRuntimeFeatures::enableMediaSource(false);
84
85  if (command_line.HasSwitch(switches::kDisableSharedWorkers))
86    WebRuntimeFeatures::enableSharedWorker(false);
87
88#if defined(OS_ANDROID)
89  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
90    WebRuntimeFeatures::enableMediaStream(false);
91    WebRuntimeFeatures::enablePeerConnection(false);
92  }
93
94  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
95    WebRuntimeFeatures::enableScriptedSpeech(false);
96#endif
97
98  if (command_line.HasSwitch(switches::kEnableServiceWorker))
99    WebRuntimeFeatures::enableServiceWorker(true);
100
101  if (command_line.HasSwitch(switches::kDisableWebAudio))
102    WebRuntimeFeatures::enableWebAudio(false);
103
104  if (command_line.HasSwitch(switches::kDisableFullScreen))
105    WebRuntimeFeatures::enableFullscreen(false);
106
107  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
108    WebRuntimeFeatures::enableEncryptedMedia(true);
109
110  if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
111    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
112
113  if (command_line.HasSwitch(switches::kEnableWebAnimationsCSS))
114    WebRuntimeFeatures::enableWebAnimationsCSS();
115
116  if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
117    WebRuntimeFeatures::enableWebAnimationsSVG();
118
119  if (command_line.HasSwitch(switches::kEnableWebMIDI))
120    WebRuntimeFeatures::enableWebMIDI(true);
121
122  if (command_line.HasSwitch(switches::kDisableDeviceMotion))
123    WebRuntimeFeatures::enableDeviceMotion(false);
124
125  if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
126    WebRuntimeFeatures::enableDeviceOrientation(false);
127
128  if (command_line.HasSwitch(switches::kDisableSpeechInput))
129    WebRuntimeFeatures::enableSpeechInput(false);
130
131  if (command_line.HasSwitch(switches::kDisableFileSystem))
132    WebRuntimeFeatures::enableFileSystem(false);
133
134  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
135    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
136
137  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
138    WebRuntimeFeatures::enableSpeechSynthesis(true);
139
140  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
141    WebRuntimeFeatures::enableWebGLDraftExtensions(true);
142
143  if (command_line.HasSwitch(switches::kEnableHTMLImports))
144    WebRuntimeFeatures::enableHTMLImports(true);
145
146  if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
147    WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
148
149  if (command_line.HasSwitch(switches::kEnableOverlayScrollbars))
150    WebRuntimeFeatures::enableOverlayScrollbars(true);
151
152  if (command_line.HasSwitch(switches::kEnableInputModeAttribute))
153    WebRuntimeFeatures::enableInputModeAttribute(true);
154
155  if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
156    WebRuntimeFeatures::enableFastTextAutosizing(true);
157}
158
159}  // namespace content
160