runtime_features.cc revision a02191e04bc25c4935f804f2c080ae28663d096d
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/common/content_switches_internal.h"
9#include "content/public/common/content_switches.h"
10#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
11#include "ui/native_theme/native_theme_switches.h"
12
13#if defined(OS_ANDROID)
14#include <cpu-features.h>
15#include "media/base/android/media_codec_bridge.h"
16#endif
17
18using blink::WebRuntimeFeatures;
19
20namespace content {
21
22static void SetRuntimeFeatureDefaultsForPlatform() {
23#if defined(OS_ANDROID)
24  // MSE/EME implementation needs Android MediaCodec API.
25  if (!media::MediaCodecBridge::IsAvailable()) {
26    WebRuntimeFeatures::enableMediaSource(false);
27    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
28  }
29  // WebAudio is enabled by default on ARM and X86 and only when the
30  // MediaCodec API is available.
31  WebRuntimeFeatures::enableWebAudio(
32      media::MediaCodecBridge::IsAvailable() &&
33      ((android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) ||
34       (android_getCpuFamily() == ANDROID_CPU_FAMILY_X86)));
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  WebRuntimeFeatures::enableTouchIconLoading(true);
46  WebRuntimeFeatures::enableOrientationEvent(true);
47#else
48  WebRuntimeFeatures::enableNavigatorContentUtils(true);
49#endif  // defined(OS_ANDROID)
50}
51
52void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
53    const CommandLine& command_line) {
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::kDisableNavigatorContentUtils))
69    WebRuntimeFeatures::enableNavigatorContentUtils(false);
70
71  if (command_line.HasSwitch(switches::kDisableLocalStorage))
72    WebRuntimeFeatures::enableLocalStorage(false);
73
74  if (command_line.HasSwitch(switches::kDisableSessionStorage))
75    WebRuntimeFeatures::enableSessionStorage(false);
76
77  if (command_line.HasSwitch(switches::kDisableMediaSource))
78    WebRuntimeFeatures::enableMediaSource(false);
79
80  if (command_line.HasSwitch(switches::kDisableSharedWorkers))
81    WebRuntimeFeatures::enableSharedWorker(false);
82
83#if defined(OS_ANDROID)
84  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
85    WebRuntimeFeatures::enableMediaStream(false);
86    WebRuntimeFeatures::enablePeerConnection(false);
87  }
88
89  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
90    WebRuntimeFeatures::enableScriptedSpeech(false);
91#endif
92
93  if (command_line.HasSwitch(switches::kEnableServiceWorker))
94    WebRuntimeFeatures::enableServiceWorker(true);
95
96#if defined(OS_ANDROID)
97  // WebAudio is enabled by default on ARM and X86, if the MediaCodec
98  // API is available.
99  WebRuntimeFeatures::enableWebAudio(
100      !command_line.HasSwitch(switches::kDisableWebAudio) &&
101      media::MediaCodecBridge::IsAvailable());
102#else
103  if (command_line.HasSwitch(switches::kDisableWebAudio))
104    WebRuntimeFeatures::enableWebAudio(false);
105#endif
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::kEnableWebAnimationsSVG))
114    WebRuntimeFeatures::enableWebAnimationsSVG(true);
115
116  if (command_line.HasSwitch(switches::kEnableWebMIDI))
117    WebRuntimeFeatures::enableWebMIDI(true);
118
119  if (command_line.HasSwitch(switches::kDisableSpeechInput))
120    WebRuntimeFeatures::enableSpeechInput(false);
121
122  if (command_line.HasSwitch(switches::kDisableFileSystem))
123    WebRuntimeFeatures::enableFileSystem(false);
124
125  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
126    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
127
128  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
129    WebRuntimeFeatures::enableSpeechSynthesis(true);
130
131  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
132    WebRuntimeFeatures::enableWebGLDraftExtensions(true);
133
134  if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
135    WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
136
137  if (ui::IsOverlayScrollbarEnabled())
138    WebRuntimeFeatures::enableOverlayScrollbars(true);
139
140  if (command_line.HasSwitch(switches::kEnableFastTextAutosizing)
141      && !command_line.HasSwitch(switches::kDisableFastTextAutosizing))
142    WebRuntimeFeatures::enableFastTextAutosizing(true);
143
144  if (command_line.HasSwitch(switches::kDisableRepaintAfterLayout))
145    WebRuntimeFeatures::enableRepaintAfterLayout(false);
146
147  if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
148    WebRuntimeFeatures::enableRepaintAfterLayout(true);
149
150  if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
151    WebRuntimeFeatures::enableTargetedStyleRecalc(true);
152
153  if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
154    WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
155}
156
157}  // namespace content
158