runtime_features.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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 "base/metrics/field_trial.h"
17#include "media/base/android/media_codec_bridge.h"
18#endif
19
20using blink::WebRuntimeFeatures;
21
22namespace content {
23
24static void SetRuntimeFeatureDefaultsForPlatform() {
25#if defined(OS_ANDROID)
26  // MSE/EME implementation needs Android MediaCodec API.
27  if (!media::MediaCodecBridge::IsAvailable()) {
28    WebRuntimeFeatures::enableMediaSource(false);
29    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
30    WebRuntimeFeatures::enableEncryptedMedia(false);
31  }
32  // WebAudio is enabled by default but only when the MediaCodec API
33  // is available.
34  AndroidCpuFamily cpu_family = android_getCpuFamily();
35  WebRuntimeFeatures::enableWebAudio(
36      media::MediaCodecBridge::IsAvailable() &&
37      ((cpu_family == ANDROID_CPU_FAMILY_ARM) ||
38       (cpu_family == ANDROID_CPU_FAMILY_ARM64) ||
39       (cpu_family == ANDROID_CPU_FAMILY_X86) ||
40       (cpu_family == ANDROID_CPU_FAMILY_MIPS)));
41
42  // Android supports gamepad API for JellyBean and beyond
43  WebRuntimeFeatures::enableGamepad(
44      base::android::BuildInfo::GetInstance()->sdk_int() >= 16);
45  // Android does not have support for PagePopup
46  WebRuntimeFeatures::enablePagePopup(false);
47  // Android does not yet support the Web Notification API. crbug.com/115320
48  WebRuntimeFeatures::enableNotifications(false);
49  // Android does not yet support SharedWorker. crbug.com/154571
50  WebRuntimeFeatures::enableSharedWorker(false);
51  // Android does not yet support NavigatorContentUtils.
52  WebRuntimeFeatures::enableNavigatorContentUtils(false);
53  WebRuntimeFeatures::enableTouchIconLoading(true);
54  WebRuntimeFeatures::enableOrientationEvent(true);
55  WebRuntimeFeatures::enableFastMobileScrolling(true);
56  WebRuntimeFeatures::enableMediaCapture(true);
57  // If navigation transitions gets activated via field trial, enable it in
58  // blink. We don't set this to false in case the user has manually enabled
59  // the feature via experimental web platform features.
60  if (base::FieldTrialList::FindFullName("NavigationTransitions") == "Enabled")
61    WebRuntimeFeatures::enableNavigationTransitions(true);
62#else
63  WebRuntimeFeatures::enableNavigatorContentUtils(true);
64#endif  // defined(OS_ANDROID)
65
66#if !(defined OS_ANDROID || defined OS_CHROMEOS || defined OS_IOS)
67    // Only Android, ChromeOS, and IOS support NetInfo right now.
68    WebRuntimeFeatures::enableNetworkInformation(false);
69#endif
70}
71
72void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
73    const CommandLine& command_line) {
74  if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
75    WebRuntimeFeatures::enableExperimentalFeatures(true);
76
77  SetRuntimeFeatureDefaultsForPlatform();
78
79  if (command_line.HasSwitch(switches::kDisableDatabases))
80    WebRuntimeFeatures::enableDatabase(false);
81
82  if (command_line.HasSwitch(switches::kDisableApplicationCache))
83    WebRuntimeFeatures::enableApplicationCache(false);
84
85  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
86    WebRuntimeFeatures::enableNotifications(false);
87
88  if (command_line.HasSwitch(switches::kDisableLocalStorage))
89    WebRuntimeFeatures::enableLocalStorage(false);
90
91  if (command_line.HasSwitch(switches::kDisableSessionStorage))
92    WebRuntimeFeatures::enableSessionStorage(false);
93
94  if (command_line.HasSwitch(switches::kDisableMediaSource))
95    WebRuntimeFeatures::enableMediaSource(false);
96
97  if (command_line.HasSwitch(switches::kDisableSharedWorkers))
98    WebRuntimeFeatures::enableSharedWorker(false);
99
100#if defined(OS_ANDROID)
101  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
102    WebRuntimeFeatures::enableMediaStream(false);
103    WebRuntimeFeatures::enablePeerConnection(false);
104  }
105
106  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
107    WebRuntimeFeatures::enableScriptedSpeech(false);
108
109  // WebAudio is enabled by default on ARM and X86, if the MediaCodec
110  // API is available.
111  WebRuntimeFeatures::enableWebAudio(
112      !command_line.HasSwitch(switches::kDisableWebAudio) &&
113      media::MediaCodecBridge::IsAvailable());
114#else
115  if (command_line.HasSwitch(switches::kDisableWebAudio))
116    WebRuntimeFeatures::enableWebAudio(false);
117#endif
118
119  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
120    WebRuntimeFeatures::enableEncryptedMedia(true);
121
122  if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
123    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
124
125  if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
126    WebRuntimeFeatures::enableWebAnimationsSVG(true);
127
128  if (command_line.HasSwitch(switches::kEnableWebMIDI))
129    WebRuntimeFeatures::enableWebMIDI(true);
130
131  if (command_line.HasSwitch(switches::kDisableFileSystem))
132    WebRuntimeFeatures::enableFileSystem(false);
133
134  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
135    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
136
137  if (command_line.HasSwitch(switches::kEnableDisplayList2dCanvas))
138    WebRuntimeFeatures::enableDisplayList2dCanvas(true);
139
140  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
141    WebRuntimeFeatures::enableWebGLDraftExtensions(true);
142
143  if (command_line.HasSwitch(switches::kEnableWebGLImageChromium))
144    WebRuntimeFeatures::enableWebGLImageChromium(true);
145
146  if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
147    WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
148
149  if (ui::IsOverlayScrollbarEnabled())
150    WebRuntimeFeatures::enableOverlayScrollbars(true);
151
152  if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
153    WebRuntimeFeatures::enableTargetedStyleRecalc(true);
154
155  if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
156    WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
157
158  if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
159    WebRuntimeFeatures::enablePreciseMemoryInfo(true);
160
161  if (command_line.HasSwitch(switches::kEnableLayerSquashing))
162    WebRuntimeFeatures::enableLayerSquashing(true);
163
164  if (command_line.HasSwitch(switches::kEnableNetworkInformation) ||
165      command_line.HasSwitch(
166          switches::kEnableExperimentalWebPlatformFeatures)) {
167    WebRuntimeFeatures::enableNetworkInformation(true);
168  }
169}
170
171}  // namespace content
172