runtime_features.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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::enableWebKitMediaSource(false);
27    WebRuntimeFeatures::enableMediaSource(false);
28    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
29  }
30  // WebAudio is enabled by default on ARM and X86 and only when the
31  // MediaCodec API is available.
32  WebRuntimeFeatures::enableWebAudio(
33      media::MediaCodecBridge::IsAvailable() &&
34      ((android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) ||
35       (android_getCpuFamily() == ANDROID_CPU_FAMILY_X86)));
36  // Android does not support the Gamepad API.
37  WebRuntimeFeatures::enableGamepad(false);
38  // Android does not have support for PagePopup
39  WebRuntimeFeatures::enablePagePopup(false);
40  // Android does not yet support the Web Notification API. crbug.com/115320
41  WebRuntimeFeatures::enableNotifications(false);
42  // Android does not yet support SharedWorker. crbug.com/154571
43  WebRuntimeFeatures::enableSharedWorker(false);
44  // Android does not yet support NavigatorContentUtils.
45  WebRuntimeFeatures::enableNavigatorContentUtils(false);
46  WebRuntimeFeatures::enableTouchIconLoading(true);
47  WebRuntimeFeatures::enableOrientationEvent(true);
48#else
49  WebRuntimeFeatures::enableNavigatorContentUtils(true);
50#endif  // defined(OS_ANDROID)
51}
52
53void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
54    const CommandLine& command_line) {
55  if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
56    WebRuntimeFeatures::enableExperimentalFeatures(true);
57
58  SetRuntimeFeatureDefaultsForPlatform();
59
60  if (command_line.HasSwitch(switches::kDisableDatabases))
61    WebRuntimeFeatures::enableDatabase(false);
62
63  if (command_line.HasSwitch(switches::kDisableApplicationCache))
64    WebRuntimeFeatures::enableApplicationCache(false);
65
66  if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
67    WebRuntimeFeatures::enableNotifications(false);
68
69  if (command_line.HasSwitch(switches::kDisableNavigatorContentUtils))
70    WebRuntimeFeatures::enableNavigatorContentUtils(false);
71
72  if (command_line.HasSwitch(switches::kDisableLocalStorage))
73    WebRuntimeFeatures::enableLocalStorage(false);
74
75  if (command_line.HasSwitch(switches::kDisableSessionStorage))
76    WebRuntimeFeatures::enableSessionStorage(false);
77
78  if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
79    WebRuntimeFeatures::enableWebKitMediaSource(false);
80
81  if (command_line.HasSwitch(switches::kDisableUnprefixedMediaSource))
82    WebRuntimeFeatures::enableMediaSource(false);
83
84  if (command_line.HasSwitch(switches::kDisableSharedWorkers))
85    WebRuntimeFeatures::enableSharedWorker(false);
86
87#if defined(OS_ANDROID)
88  if (command_line.HasSwitch(switches::kDisableWebRTC)) {
89    WebRuntimeFeatures::enableMediaStream(false);
90    WebRuntimeFeatures::enablePeerConnection(false);
91  }
92
93  if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
94    WebRuntimeFeatures::enableScriptedSpeech(false);
95#endif
96
97  if (command_line.HasSwitch(switches::kEnableServiceWorker))
98    WebRuntimeFeatures::enableServiceWorker(true);
99
100#if defined(OS_ANDROID)
101  // WebAudio is enabled by default on ARM and X86, if the MediaCodec
102  // API is available.
103  WebRuntimeFeatures::enableWebAudio(
104      !command_line.HasSwitch(switches::kDisableWebAudio) &&
105      media::MediaCodecBridge::IsAvailable());
106#else
107  if (command_line.HasSwitch(switches::kDisableWebAudio))
108    WebRuntimeFeatures::enableWebAudio(false);
109#endif
110
111  if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
112    WebRuntimeFeatures::enableEncryptedMedia(true);
113
114  if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
115    WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
116
117  if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
118    WebRuntimeFeatures::enableWebAnimationsSVG(true);
119
120  if (command_line.HasSwitch(switches::kEnableWebMIDI))
121    WebRuntimeFeatures::enableWebMIDI(true);
122
123  if (command_line.HasSwitch(switches::kDisableSpeechInput))
124    WebRuntimeFeatures::enableSpeechInput(false);
125
126  if (command_line.HasSwitch(switches::kDisableFileSystem))
127    WebRuntimeFeatures::enableFileSystem(false);
128
129  if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
130    WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
131
132  if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
133    WebRuntimeFeatures::enableSpeechSynthesis(true);
134
135  if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
136    WebRuntimeFeatures::enableWebGLDraftExtensions(true);
137
138  if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
139    WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
140
141  if (ui::IsOverlayScrollbarEnabled())
142    WebRuntimeFeatures::enableOverlayScrollbars(true);
143
144  if (command_line.HasSwitch(switches::kEnableFastTextAutosizing)
145      && !command_line.HasSwitch(switches::kDisableFastTextAutosizing))
146    WebRuntimeFeatures::enableFastTextAutosizing(true);
147
148  if (command_line.HasSwitch(switches::kDisableRepaintAfterLayout))
149    WebRuntimeFeatures::enableRepaintAfterLayout(false);
150
151  if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
152    WebRuntimeFeatures::enableRepaintAfterLayout(true);
153
154  if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
155    WebRuntimeFeatures::enableTargetedStyleRecalc(true);
156
157  if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
158    WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
159}
160
161}  // namespace content
162