runtime_features.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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 "base/android/build_info.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 that was introduced
24  // in JellyBrean.
25  if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) {
26    WebRuntimeFeatures::enableWebKitMediaSource(false);
27    WebRuntimeFeatures::enableMediaSource(false);
28    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
29  }
30#endif  // !defined(GOOGLE_TV)
31  bool enable_webaudio = false;
32#if defined(ARCH_CPU_ARMEL)
33  // WebAudio needs Android MediaCodec API that was introduced in
34  // JellyBean, and also currently needs NEON support for the FFT.
35  enable_webaudio =
36      (base::android::BuildInfo::GetInstance()->sdk_int() >= 16) &&
37      ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
38#endif  // defined(ARCH_CPU_ARMEL)
39  WebRuntimeFeatures::enableWebAudio(enable_webaudio);
40  // Android does not support the Gamepad API.
41  WebRuntimeFeatures::enableGamepad(false);
42  // Android does not have support for PagePopup
43  WebRuntimeFeatures::enablePagePopup(false);
44  // datalist on Android is not enabled
45  WebRuntimeFeatures::enableDataListElement(false);
46  // Android does not yet support the Web Notification API. crbug.com/115320
47  WebRuntimeFeatures::enableNotifications(false);
48#endif  // defined(OS_ANDROID)
49}
50
51void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
52    const CommandLine& command_line) {
53  WebRuntimeFeatures::enableStableFeatures(true);
54
55  if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
56    WebRuntimeFeatures::enableExperimentalFeatures(true);
57
58  SetRuntimeFeatureDefaultsForPlatform();
59
60  if (command_line.HasSwitch(switches::kDisableDatabases))
61    WebRuntimeFeatures::enableDatabase(false);
62
63  if (command_line.HasSwitch(switches::kDisableApplicationCache))
64    WebRuntimeFeatures::enableApplicationCache(false);
65
66  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
67    WebRuntimeFeatures::enableNotifications(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 defined(OS_ANDROID)
85  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
86    WebRuntimeFeatures::enableMediaStream(false);
87    WebRuntimeFeatures::enablePeerConnection(false);
88  }
89
90  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
91    WebRuntimeFeatures::enableScriptedSpeech(false);
92#endif
93
94  if (command_line.HasSwitch(switches::kEnableServiceWorker))
95    WebRuntimeFeatures::enableServiceWorker(true);
96
97  if (command_line.HasSwitch(switches::kDisableWebAudio))
98    WebRuntimeFeatures::enableWebAudio(false);
99
100  if (command_line.HasSwitch(switches::kDisableFullScreen))
101    WebRuntimeFeatures::enableFullscreen(false);
102
103  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
104    WebRuntimeFeatures::enableEncryptedMedia(true);
105
106  if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
107    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
108
109  if (command_line.HasSwitch(switches::kEnableWebAnimationsCSS))
110    WebRuntimeFeatures::enableWebAnimationsCSS();
111
112  if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
113    WebRuntimeFeatures::enableWebAnimationsSVG();
114
115  if (command_line.HasSwitch(switches::kEnableWebMIDI))
116    WebRuntimeFeatures::enableWebMIDI(true);
117
118  if (command_line.HasSwitch(switches::kDisableDeviceMotion))
119    WebRuntimeFeatures::enableDeviceMotion(false);
120
121  if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
122    WebRuntimeFeatures::enableDeviceOrientation(false);
123
124  if (command_line.HasSwitch(switches::kDisableSpeechInput))
125    WebRuntimeFeatures::enableSpeechInput(false);
126
127  if (command_line.HasSwitch(switches::kDisableFileSystem))
128    WebRuntimeFeatures::enableFileSystem(false);
129
130  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
131    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
132
133  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
134    WebRuntimeFeatures::enableSpeechSynthesis(true);
135
136  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
137    WebRuntimeFeatures::enableWebGLDraftExtensions(true);
138
139  if (command_line.HasSwitch(switches::kEnableHTMLImports))
140    WebRuntimeFeatures::enableHTMLImports(true);
141
142  if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
143    WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
144
145  if (command_line.HasSwitch(switches::kEnableOverlayScrollbars))
146    WebRuntimeFeatures::enableOverlayScrollbars(true);
147
148  if (command_line.HasSwitch(switches::kEnableInputModeAttribute))
149    WebRuntimeFeatures::enableInputModeAttribute(true);
150
151  if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
152    WebRuntimeFeatures::enableFastTextAutosizing(true);
153}
154
155}  // namespace content
156