runtime_features.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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#endif
14
15using WebKit::WebRuntimeFeatures;
16
17namespace content {
18
19static void SetRuntimeFeatureDefaultsForPlatform() {
20#if defined(OS_ANDROID) && !defined(GOOGLE_TV)
21  WebRuntimeFeatures::enableWebKitMediaSource(false);
22  WebRuntimeFeatures::enableLegacyEncryptedMedia(false);
23  WebRuntimeFeatures::enableEncryptedMedia(false);
24#endif
25
26#if defined(OS_ANDROID)
27  bool enable_webaudio = false;
28#if defined(ARCH_CPU_ARMEL)
29  enable_webaudio =
30      ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0);
31#endif
32  WebRuntimeFeatures::enableWebAudio(enable_webaudio);
33  // Android does not support the Gamepad API.
34  WebRuntimeFeatures::enableGamepad(false);
35  // Android does not have support for PagePopup
36  WebRuntimeFeatures::enablePagePopup(false);
37  // datalist on Android is not enabled
38  WebRuntimeFeatures::enableDataListElement(false);
39#endif
40}
41
42void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
43    const CommandLine& command_line) {
44  WebRuntimeFeatures::enableStableFeatures(true);
45
46  if (command_line.HasSwitch(switches::kEnableExperimentalWebKitFeatures))
47    WebRuntimeFeatures::enableExperimentalFeatures(true);
48
49  SetRuntimeFeatureDefaultsForPlatform();
50
51  if (command_line.HasSwitch(switches::kDisableDatabases))
52    WebRuntimeFeatures::enableDatabase(false);
53
54  if (command_line.HasSwitch(switches::kDisableApplicationCache))
55    WebRuntimeFeatures::enableApplicationCache(false);
56
57  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
58    WebRuntimeFeatures::enableNotifications(false);
59
60  if (command_line.HasSwitch(switches::kDisableLocalStorage))
61    WebRuntimeFeatures::enableLocalStorage(false);
62
63  if (command_line.HasSwitch(switches::kDisableSessionStorage))
64    WebRuntimeFeatures::enableSessionStorage(false);
65
66  if (command_line.HasSwitch(switches::kDisableGeolocation))
67    WebRuntimeFeatures::enableGeolocation(false);
68
69#if defined(OS_ANDROID) && !defined(GOOGLE_TV)
70  if (command_line.HasSwitch(switches::kEnableWebKitMediaSource))
71    WebRuntimeFeatures::enableWebKitMediaSource(true);
72#else
73  if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
74    WebRuntimeFeatures::enableWebKitMediaSource(false);
75#endif
76
77#if defined(OS_ANDROID)
78  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
79    WebRuntimeFeatures::enableMediaStream(false);
80    WebRuntimeFeatures::enablePeerConnection(false);
81  }
82
83  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
84    WebRuntimeFeatures::enableScriptedSpeech(false);
85#endif
86
87  if (command_line.HasSwitch(switches::kDisableWebAudio))
88    WebRuntimeFeatures::enableWebAudio(false);
89
90  if (command_line.HasSwitch(switches::kDisableFullScreen))
91    WebRuntimeFeatures::enableFullscreen(false);
92
93  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
94    WebRuntimeFeatures::enableEncryptedMedia(true);
95
96  if (command_line.HasSwitch(switches::kDisableLegacyEncryptedMedia))
97    WebRuntimeFeatures::enableLegacyEncryptedMedia(false);
98
99  if (command_line.HasSwitch(switches::kEnableWebMIDI))
100    WebRuntimeFeatures::enableWebMIDI(true);
101
102  if (command_line.HasSwitch(switches::kEnableDeviceMotion))
103      WebRuntimeFeatures::enableDeviceMotion(true);
104
105  if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
106    WebRuntimeFeatures::enableDeviceOrientation(false);
107
108  if (command_line.HasSwitch(switches::kDisableSpeechInput))
109    WebRuntimeFeatures::enableSpeechInput(false);
110
111  if (command_line.HasSwitch(switches::kDisableFileSystem))
112    WebRuntimeFeatures::enableFileSystem(false);
113
114  if (command_line.HasSwitch(switches::kDisableJavaScriptI18NAPI))
115    WebRuntimeFeatures::enableJavaScriptI18NAPI(false);
116
117  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
118    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
119
120  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
121    WebRuntimeFeatures::enableSpeechSynthesis(true);
122
123  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
124    WebRuntimeFeatures::enableWebGLDraftExtensions(true);
125}
126
127}  // namespace content
128