Upstream version 6.35.121.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 #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
18 using blink::WebRuntimeFeatures;
19
20 namespace content {
21
22 static 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 only on ARM 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 does not support the Gamepad API.
36   WebRuntimeFeatures::enableGamepad(false);
37   // Android does not have support for PagePopup
38   WebRuntimeFeatures::enablePagePopup(false);
39   // Crosswalk supports the Web Notification API on Android.
40   WebRuntimeFeatures::enableNotifications(true);
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
52 void 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::kDisableWebKitMediaSource))
78     WebRuntimeFeatures::enableWebKitMediaSource(false);
79
80   if (command_line.HasSwitch(switches::kDisableUnprefixedMediaSource))
81     WebRuntimeFeatures::enableMediaSource(false);
82
83   if (command_line.HasSwitch(switches::kDisableSharedWorkers))
84     WebRuntimeFeatures::enableSharedWorker(false);
85
86 #if defined(OS_ANDROID)
87   if (command_line.HasSwitch(switches::kDisableWebRTC)) {
88     WebRuntimeFeatures::enableMediaStream(false);
89     WebRuntimeFeatures::enablePeerConnection(false);
90   }
91
92   if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
93     WebRuntimeFeatures::enableScriptedSpeech(false);
94 #endif
95
96   if (command_line.HasSwitch(switches::kEnableServiceWorker))
97     WebRuntimeFeatures::enableServiceWorker(true);
98
99 #if defined(OS_ANDROID)
100   // WebAudio requires the MediaCodec API.
101 #if defined(ARCH_CPU_X86)
102   // WebAudio is disabled by default on x86.
103   WebRuntimeFeatures::enableWebAudio(
104       command_line.HasSwitch(switches::kEnableWebAudio) &&
105       media::MediaCodecBridge::IsAvailable());
106 #elif defined(ARCH_CPU_ARMEL)
107   // WebAudio is enabled by default on ARM.
108   WebRuntimeFeatures::enableWebAudio(
109       !command_line.HasSwitch(switches::kDisableWebAudio) &&
110       media::MediaCodecBridge::IsAvailable());
111 #else
112   WebRuntimeFeatures::enableWebAudio(false);
113 #endif
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::kDisableSpeechInput))
132     WebRuntimeFeatures::enableSpeechInput(false);
133
134   if (command_line.HasSwitch(switches::kDisableFileSystem))
135     WebRuntimeFeatures::enableFileSystem(false);
136
137   if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
138     WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
139
140   if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
141     WebRuntimeFeatures::enableSpeechSynthesis(true);
142
143   if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
144     WebRuntimeFeatures::enableWebGLDraftExtensions(true);
145
146   if (command_line.HasSwitch(switches::kEnableHTMLImports))
147     WebRuntimeFeatures::enableHTMLImports(true);
148
149   if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
150     WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
151
152   if (ui::IsOverlayScrollbarEnabled())
153     WebRuntimeFeatures::enableOverlayScrollbars(true);
154
155   if (command_line.HasSwitch(switches::kEnableFastTextAutosizing)
156       && !command_line.HasSwitch(switches::kDisableFastTextAutosizing))
157     WebRuntimeFeatures::enableFastTextAutosizing(true);
158
159   if (command_line.HasSwitch(switches::kDisableRepaintAfterLayout))
160     WebRuntimeFeatures::enableRepaintAfterLayout(false);
161
162   if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
163     WebRuntimeFeatures::enableRepaintAfterLayout(true);
164
165   if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
166     WebRuntimeFeatures::enableTargetedStyleRecalc(true);
167
168   if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
169     WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
170 }
171
172 }  // namespace content