Upstream version 5.34.97.0
[platform/framework/web/crosswalk.git] / src / content / child / runtime_features.cc
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
12 #if defined(OS_ANDROID)
13 #include <cpu-features.h>
14 #include "media/base/android/media_codec_bridge.h"
15 #endif
16
17 using blink::WebRuntimeFeatures;
18
19 namespace content {
20
21 static void SetRuntimeFeatureDefaultsForPlatform() {
22 #if defined(OS_ANDROID)
23   // MSE/EME implementation needs Android MediaCodec API.
24   if (!media::MediaCodecBridge::IsAvailable()) {
25     WebRuntimeFeatures::enableWebKitMediaSource(false);
26     WebRuntimeFeatures::enableMediaSource(false);
27     WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
28   }
29   // WebAudio is enabled by default only on ARM 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 does not support the Gamepad API.
35   WebRuntimeFeatures::enableGamepad(false);
36   // Android does not have support for PagePopup
37   WebRuntimeFeatures::enablePagePopup(false);
38   // Crosswalk supports the Web Notification API on Android.
39   WebRuntimeFeatures::enableNotifications(true);
40   // Android does not yet support SharedWorker. crbug.com/154571
41   WebRuntimeFeatures::enableSharedWorker(false);
42   // Android does not yet support NavigatorContentUtils.
43   WebRuntimeFeatures::enableNavigatorContentUtils(false);
44   WebRuntimeFeatures::enableTouchIconLoading(true);
45   WebRuntimeFeatures::enableOrientationEvent(true);
46 #else
47   WebRuntimeFeatures::enableNavigatorContentUtils(true);
48 #endif  // defined(OS_ANDROID)
49 }
50
51 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
52     const CommandLine& command_line) {
53   WebRuntimeFeatures::enableStableFeatures(true);
54
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::kDisableGeolocation))
79     WebRuntimeFeatures::enableGeolocation(false);
80
81   if (command_line.HasSwitch(switches::kDisableWebKitMediaSource))
82     WebRuntimeFeatures::enableWebKitMediaSource(false);
83
84   if (command_line.HasSwitch(switches::kDisableUnprefixedMediaSource))
85     WebRuntimeFeatures::enableMediaSource(false);
86
87   if (command_line.HasSwitch(switches::kDisableSharedWorkers))
88     WebRuntimeFeatures::enableSharedWorker(false);
89
90 #if defined(OS_ANDROID)
91   if (command_line.HasSwitch(switches::kDisableWebRTC)) {
92     WebRuntimeFeatures::enableMediaStream(false);
93     WebRuntimeFeatures::enablePeerConnection(false);
94   }
95
96   if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
97     WebRuntimeFeatures::enableScriptedSpeech(false);
98 #endif
99
100   if (command_line.HasSwitch(switches::kEnableServiceWorker))
101     WebRuntimeFeatures::enableServiceWorker(true);
102
103 #if defined(OS_ANDROID)
104   // WebAudio requires the MediaCodec API.
105 #if defined(ARCH_CPU_X86)
106   // WebAudio is disabled by default on x86.
107   WebRuntimeFeatures::enableWebAudio(
108       command_line.HasSwitch(switches::kEnableWebAudio) &&
109       media::MediaCodecBridge::IsAvailable());
110 #elif defined(ARCH_CPU_ARMEL)
111   // WebAudio is enabled by default on ARM.
112   WebRuntimeFeatures::enableWebAudio(
113       !command_line.HasSwitch(switches::kDisableWebAudio) &&
114       media::MediaCodecBridge::IsAvailable());
115 #else
116   WebRuntimeFeatures::enableWebAudio(false);
117 #endif
118 #else
119   if (command_line.HasSwitch(switches::kDisableWebAudio))
120     WebRuntimeFeatures::enableWebAudio(false);
121 #endif
122
123   if (command_line.HasSwitch(switches::kDisableFullScreen))
124     WebRuntimeFeatures::enableFullscreen(false);
125
126   if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
127     WebRuntimeFeatures::enableEncryptedMedia(true);
128
129   if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
130     WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
131
132   // FIXME: Remove the enable switch once Web Animations CSS is enabled by
133   // default in Blink.
134   if (command_line.HasSwitch(switches::kEnableWebAnimationsCSS))
135     WebRuntimeFeatures::enableWebAnimationsCSS(true);
136   else if (command_line.HasSwitch(switches::kDisableWebAnimationsCSS))
137     WebRuntimeFeatures::enableWebAnimationsCSS(false);
138
139   if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
140     WebRuntimeFeatures::enableWebAnimationsSVG(true);
141
142   if (command_line.HasSwitch(switches::kEnableWebMIDI))
143     WebRuntimeFeatures::enableWebMIDI(true);
144
145   if (command_line.HasSwitch(switches::kDisableDeviceMotion))
146     WebRuntimeFeatures::enableDeviceMotion(false);
147
148   if (command_line.HasSwitch(switches::kDisableDeviceOrientation))
149     WebRuntimeFeatures::enableDeviceOrientation(false);
150
151   if (command_line.HasSwitch(switches::kDisableSpeechInput))
152     WebRuntimeFeatures::enableSpeechInput(false);
153
154   if (command_line.HasSwitch(switches::kDisableFileSystem))
155     WebRuntimeFeatures::enableFileSystem(false);
156
157 #if defined(OS_WIN)
158   if (command_line.HasSwitch(switches::kEnableDirectWrite))
159     WebRuntimeFeatures::enableDirectWrite(true);
160 #endif
161
162   if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
163     WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
164
165   if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
166     WebRuntimeFeatures::enableSpeechSynthesis(true);
167
168   if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
169     WebRuntimeFeatures::enableWebGLDraftExtensions(true);
170
171   if (command_line.HasSwitch(switches::kEnableHTMLImports))
172     WebRuntimeFeatures::enableHTMLImports(true);
173
174   if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
175     WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
176
177   if (IsOverlayScrollbarEnabled())
178     WebRuntimeFeatures::enableOverlayScrollbars(true);
179
180   if (command_line.HasSwitch(switches::kEnableInputModeAttribute))
181     WebRuntimeFeatures::enableInputModeAttribute(true);
182
183   if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
184     WebRuntimeFeatures::enableFastTextAutosizing(true);
185
186   if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
187     WebRuntimeFeatures::enableRepaintAfterLayout(true);
188 }
189
190 }  // namespace content