runtime_features.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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::enableLegacyEncryptedMedia(false);
28  }
29#endif  // !defined(GOOGLE_TV)
30  bool enable_webaudio = false;
31#if defined(ARCH_CPU_ARMEL)
32  // WebAudio needs Android MediaCodec API that was introduced in
33  // JellyBean, and also currently needs NEON support for the FFT.
34  enable_webaudio =
35      (base::android::BuildInfo::GetInstance()->sdk_int() >= 16) &&
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#endif  // defined(OS_ANDROID)
48}
49
50void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
51    const CommandLine& command_line) {
52  WebRuntimeFeatures::enableStableFeatures(true);
53
54  if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
55    WebRuntimeFeatures::enableExperimentalFeatures(true);
56
57  SetRuntimeFeatureDefaultsForPlatform();
58
59  if (command_line.HasSwitch(switches::kDisableDatabases))
60    WebRuntimeFeatures::enableDatabase(false);
61
62  if (command_line.HasSwitch(switches::kDisableApplicationCache))
63    WebRuntimeFeatures::enableApplicationCache(false);
64
65  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
66    WebRuntimeFeatures::enableNotifications(false);
67
68  if (command_line.HasSwitch(switches::kDisableLocalStorage))
69    WebRuntimeFeatures::enableLocalStorage(false);
70
71  if (command_line.HasSwitch(switches::kDisableSessionStorage))
72    WebRuntimeFeatures::enableSessionStorage(false);
73
74  if (command_line.HasSwitch(switches::kDisableGeolocation))
75    WebRuntimeFeatures::enableGeolocation(false);
76
77  if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
78    WebRuntimeFeatures::enableWebKitMediaSource(false);
79
80#if defined(OS_ANDROID)
81  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
82    WebRuntimeFeatures::enableMediaStream(false);
83    WebRuntimeFeatures::enablePeerConnection(false);
84  }
85
86  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
87    WebRuntimeFeatures::enableScriptedSpeech(false);
88#endif
89
90  if (command_line.HasSwitch(switches::kDisableWebAudio))
91    WebRuntimeFeatures::enableWebAudio(false);
92
93  if (command_line.HasSwitch(switches::kDisableFullScreen))
94    WebRuntimeFeatures::enableFullscreen(false);
95
96  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
97    WebRuntimeFeatures::enableEncryptedMedia(true);
98
99  if (command_line.HasSwitch(switches::kDisableLegacyEncryptedMedia))
100    WebRuntimeFeatures::enableLegacyEncryptedMedia(false);
101
102  if (command_line.HasSwitch(switches::kEnableWebAnimationsCSS))
103    WebRuntimeFeatures::enableWebAnimationsCSS();
104
105  if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
106    WebRuntimeFeatures::enableWebAnimationsSVG();
107
108  if (command_line.HasSwitch(switches::kEnableWebMIDI))
109    WebRuntimeFeatures::enableWebMIDI(true);
110
111  if (command_line.HasSwitch(switches::kDisableDeviceMotion))
112    WebRuntimeFeatures::enableDeviceMotion(false);
113
114  if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
115    WebRuntimeFeatures::enableDeviceOrientation(false);
116
117  if (command_line.HasSwitch(switches::kDisableSpeechInput))
118    WebRuntimeFeatures::enableSpeechInput(false);
119
120  if (command_line.HasSwitch(switches::kDisableFileSystem))
121    WebRuntimeFeatures::enableFileSystem(false);
122
123  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
124    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
125
126  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
127    WebRuntimeFeatures::enableSpeechSynthesis(true);
128
129  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
130    WebRuntimeFeatures::enableWebGLDraftExtensions(true);
131
132  if (command_line.HasSwitch(switches::kEnableHTMLImports))
133    WebRuntimeFeatures::enableHTMLImports(true);
134
135  if (command_line.HasSwitch(switches::kEnableOverlayScrollbars))
136    WebRuntimeFeatures::enableOverlayScrollbars(true);
137
138  if (command_line.HasSwitch(switches::kEnableInputModeAttribute))
139    WebRuntimeFeatures::enableInputModeAttribute(true);
140}
141
142}  // namespace content
143