runtime_features.cc revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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 "base/android/build_info.h"
16#include "media/base/android/media_codec_bridge.h"
17#endif
18
19using blink::WebRuntimeFeatures;
20
21namespace content {
22
23static void SetRuntimeFeatureDefaultsForPlatform() {
24#if defined(OS_ANDROID)
25  // MSE/EME implementation needs Android MediaCodec API.
26  if (!media::MediaCodecBridge::IsAvailable()) {
27    WebRuntimeFeatures::enableMediaSource(false);
28    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
29    WebRuntimeFeatures::enableEncryptedMedia(false);
30  }
31  // WebAudio is enabled by default on ARM and X86 and only when the
32  // MediaCodec API is available.
33  WebRuntimeFeatures::enableWebAudio(
34      media::MediaCodecBridge::IsAvailable() &&
35      ((android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) ||
36       (android_getCpuFamily() == ANDROID_CPU_FAMILY_X86)));
37
38  // Android supports gamepad API for JellyBean and beyond
39  WebRuntimeFeatures::enableGamepad(
40      base::android::BuildInfo::GetInstance()->sdk_int() >= 16);
41  // Android does not have support for PagePopup
42  WebRuntimeFeatures::enablePagePopup(false);
43  // Android does not yet support the Web Notification API. crbug.com/115320
44  WebRuntimeFeatures::enableNotifications(false);
45  // Android does not yet support SharedWorker. crbug.com/154571
46  WebRuntimeFeatures::enableSharedWorker(false);
47  // Android does not yet support NavigatorContentUtils.
48  WebRuntimeFeatures::enableNavigatorContentUtils(false);
49  WebRuntimeFeatures::enableTouchIconLoading(true);
50  WebRuntimeFeatures::enableOrientationEvent(true);
51  WebRuntimeFeatures::enableFastMobileScrolling(true);
52#else
53  WebRuntimeFeatures::enableNavigatorContentUtils(true);
54#endif  // defined(OS_ANDROID)
55}
56
57void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
58    const CommandLine& command_line) {
59  if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
60    WebRuntimeFeatures::enableExperimentalFeatures(true);
61
62  SetRuntimeFeatureDefaultsForPlatform();
63
64  if (command_line.HasSwitch(switches::kDisableDatabases))
65    WebRuntimeFeatures::enableDatabase(false);
66
67  if (command_line.HasSwitch(switches::kDisableApplicationCache))
68    WebRuntimeFeatures::enableApplicationCache(false);
69
70  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
71    WebRuntimeFeatures::enableNotifications(false);
72
73  if (command_line.HasSwitch(switches::kDisableNavigatorContentUtils))
74    WebRuntimeFeatures::enableNavigatorContentUtils(false);
75
76  if (command_line.HasSwitch(switches::kDisableLocalStorage))
77    WebRuntimeFeatures::enableLocalStorage(false);
78
79  if (command_line.HasSwitch(switches::kDisableSessionStorage))
80    WebRuntimeFeatures::enableSessionStorage(false);
81
82  if (command_line.HasSwitch(switches::kDisableMediaSource))
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 defined(OS_ANDROID)
102  // WebAudio is enabled by default on ARM and X86, if the MediaCodec
103  // API is available.
104  WebRuntimeFeatures::enableWebAudio(
105      !command_line.HasSwitch(switches::kDisableWebAudio) &&
106      media::MediaCodecBridge::IsAvailable());
107#else
108  if (command_line.HasSwitch(switches::kDisableWebAudio))
109    WebRuntimeFeatures::enableWebAudio(false);
110#endif
111
112  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
113    WebRuntimeFeatures::enableEncryptedMedia(true);
114
115  if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
116    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
117
118  if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
119    WebRuntimeFeatures::enableWebAnimationsSVG(true);
120
121  if (command_line.HasSwitch(switches::kEnableWebMIDI))
122    WebRuntimeFeatures::enableWebMIDI(true);
123
124  if (command_line.HasSwitch(switches::kDisableFileSystem))
125    WebRuntimeFeatures::enableFileSystem(false);
126
127  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
128    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
129
130  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
131    WebRuntimeFeatures::enableSpeechSynthesis(true);
132
133  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
134    WebRuntimeFeatures::enableWebGLDraftExtensions(true);
135
136  if (command_line.HasSwitch(switches::kEnableWebGLImageChromium))
137    WebRuntimeFeatures::enableWebGLImageChromium(true);
138
139  if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
140    WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
141
142  if (ui::IsOverlayScrollbarEnabled())
143    WebRuntimeFeatures::enableOverlayScrollbars(true);
144
145  if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
146    WebRuntimeFeatures::enableFastTextAutosizing(true);
147
148  if (command_line.HasSwitch(switches::kDisableFastTextAutosizing))
149    WebRuntimeFeatures::enableFastTextAutosizing(false);
150
151  if (command_line.HasSwitch(switches::kDisableRepaintAfterLayout))
152    WebRuntimeFeatures::enableRepaintAfterLayout(false);
153
154  if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
155    WebRuntimeFeatures::enableRepaintAfterLayout(true);
156
157  if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
158    WebRuntimeFeatures::enableTargetedStyleRecalc(true);
159
160  if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
161    WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
162
163  if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
164    WebRuntimeFeatures::enablePreciseMemoryInfo(true);
165
166  if (command_line.HasSwitch(switches::kEnableLayerSquashing))
167    WebRuntimeFeatures::enableLayerSquashing(true);
168}
169
170}  // namespace content
171