Update To 11.40.268.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 "base/metrics/field_trial.h"
9 #include "content/common/content_switches_internal.h"
10 #include "content/public/common/content_switches.h"
11 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
12 #include "ui/native_theme/native_theme_switches.h"
13
14 #if defined(OS_ANDROID)
15 #include <cpu-features.h>
16 #include "base/android/build_info.h"
17 #include "base/metrics/field_trial.h"
18 #include "media/base/android/media_codec_bridge.h"
19 #elif defined(OS_WIN)
20 #include "base/win/windows_version.h"
21 #endif
22
23 using blink::WebRuntimeFeatures;
24
25 namespace content {
26
27 static void SetRuntimeFeatureDefaultsForPlatform() {
28 #if defined(OS_ANDROID)
29   // MSE/EME implementation needs Android MediaCodec API.
30   if (!media::MediaCodecBridge::IsAvailable()) {
31     WebRuntimeFeatures::enableMediaSource(false);
32     WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
33     WebRuntimeFeatures::enableEncryptedMedia(false);
34   }
35   // WebAudio is enabled by default but only when the MediaCodec API
36   // is available.
37   AndroidCpuFamily cpu_family = android_getCpuFamily();
38   WebRuntimeFeatures::enableWebAudio(
39       media::MediaCodecBridge::IsAvailable() &&
40       ((cpu_family == ANDROID_CPU_FAMILY_ARM) ||
41        (cpu_family == ANDROID_CPU_FAMILY_ARM64) ||
42        (cpu_family == ANDROID_CPU_FAMILY_X86) ||
43        (cpu_family == ANDROID_CPU_FAMILY_MIPS)));
44
45   // Android does not have support for PagePopup
46   WebRuntimeFeatures::enablePagePopup(false);
47   // Crosswalk supports the Web Notification API on Android.
48   WebRuntimeFeatures::enableNotifications(true);
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   WebRuntimeFeatures::enableCompositedSelectionUpdate(true);
58   // If navigation transitions gets activated via field trial, enable it in
59   // blink. We don't set this to false in case the user has manually enabled
60   // the feature via experimental web platform features.
61   if (base::FieldTrialList::FindFullName("NavigationTransitions") == "Enabled")
62     WebRuntimeFeatures::enableNavigationTransitions(true);
63 #else
64   WebRuntimeFeatures::enableNavigatorContentUtils(true);
65 #endif  // defined(OS_ANDROID)
66
67 #if !(defined OS_ANDROID || defined OS_CHROMEOS || defined OS_IOS)
68     // Only Android, ChromeOS, and IOS support NetInfo right now.
69     WebRuntimeFeatures::enableNetworkInformation(false);
70 #endif
71
72 #if defined(OS_WIN)
73   // Screen Orientation API is currently broken on Windows 8 Metro mode and
74   // until we can find how to disable it only for Blink instances running in a
75   // renderer process in Metro, we need to disable the API altogether for Win8.
76   // See http://crbug.com/400846
77   if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8)
78     WebRuntimeFeatures::enableScreenOrientation(false);
79 #endif // OS_WIN
80
81 #if defined(OS_TIZEN)
82   WebRuntimeFeatures::enableOrientationEvent(true);
83 #endif  // defined(OS_TIZEN)
84 }
85
86 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
87     const base::CommandLine& command_line) {
88   if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
89     WebRuntimeFeatures::enableExperimentalFeatures(true);
90
91   SetRuntimeFeatureDefaultsForPlatform();
92
93   if (command_line.HasSwitch(switches::kDisableDatabases))
94     WebRuntimeFeatures::enableDatabase(false);
95
96   if (command_line.HasSwitch(switches::kDisableApplicationCache))
97     WebRuntimeFeatures::enableApplicationCache(false);
98
99   if (command_line.HasSwitch(switches::kDisableBlinkScheduler))
100     WebRuntimeFeatures::enableBlinkScheduler(false);
101
102   if (command_line.HasSwitch(switches::kDisableLocalStorage))
103     WebRuntimeFeatures::enableLocalStorage(false);
104
105   if (command_line.HasSwitch(switches::kDisableSessionStorage))
106     WebRuntimeFeatures::enableSessionStorage(false);
107
108   if (command_line.HasSwitch(switches::kDisableMediaSource))
109     WebRuntimeFeatures::enableMediaSource(false);
110
111   if (command_line.HasSwitch(switches::kDisableSharedWorkers))
112     WebRuntimeFeatures::enableSharedWorker(false);
113
114 #if defined(OS_ANDROID)
115   if (command_line.HasSwitch(switches::kDisableWebRTC))
116     WebRuntimeFeatures::enablePeerConnection(false);
117
118   if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
119     WebRuntimeFeatures::enableScriptedSpeech(false);
120
121   if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
122     WebRuntimeFeatures::enableNotifications(true);
123
124   // WebAudio is enabled by default on ARM and X86, if the MediaCodec
125   // API is available.
126   WebRuntimeFeatures::enableWebAudio(
127       !command_line.HasSwitch(switches::kDisableWebAudio) &&
128       media::MediaCodecBridge::IsAvailable());
129 #else
130   if (command_line.HasSwitch(switches::kDisableWebAudio))
131     WebRuntimeFeatures::enableWebAudio(false);
132 #endif
133
134   if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
135     WebRuntimeFeatures::enableEncryptedMedia(true);
136
137   if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
138     WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
139
140   if (command_line.HasSwitch(switches::kEnableWebMIDI))
141     WebRuntimeFeatures::enableWebMIDI(true);
142
143   if (command_line.HasSwitch(switches::kDisableFileSystem))
144     WebRuntimeFeatures::enableFileSystem(false);
145
146   if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
147     WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
148
149   if (command_line.HasSwitch(switches::kEnableAcceleratedJpegDecoding))
150     WebRuntimeFeatures::enableDecodeToYUV(true);
151
152   if (command_line.HasSwitch(switches::kDisableDisplayList2dCanvas)) {
153     WebRuntimeFeatures::enableDisplayList2dCanvas(false);
154   } else if (command_line.HasSwitch(switches::kEnableDisplayList2dCanvas)) {
155     WebRuntimeFeatures::enableDisplayList2dCanvas(true);
156   } else {
157     WebRuntimeFeatures::enableDisplayList2dCanvas(
158         base::FieldTrialList::FindFullName("DisplayList2dCanvas") == "Enabled"
159     );
160   }
161
162   if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
163     WebRuntimeFeatures::enableWebGLDraftExtensions(true);
164
165   if (command_line.HasSwitch(switches::kEnableWebGLImageChromium))
166     WebRuntimeFeatures::enableWebGLImageChromium(true);
167
168   if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
169     WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
170
171   if (ui::IsOverlayScrollbarEnabled())
172     WebRuntimeFeatures::enableOverlayScrollbars(true);
173
174   if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
175     WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
176
177   if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
178     WebRuntimeFeatures::enablePreciseMemoryInfo(true);
179
180   if (command_line.HasSwitch(switches::kEnableLayerSquashing))
181     WebRuntimeFeatures::enableLayerSquashing(true);
182
183   if (command_line.HasSwitch(switches::kEnableNetworkInformation) ||
184       command_line.HasSwitch(
185           switches::kEnableExperimentalWebPlatformFeatures)) {
186     WebRuntimeFeatures::enableNetworkInformation(true);
187   }
188
189   if (command_line.HasSwitch(switches::kEnableCredentialManagerAPI))
190     WebRuntimeFeatures::enableCredentialManagerAPI(true);
191
192   if (command_line.HasSwitch(switches::kEnableViewport))
193     WebRuntimeFeatures::enableCSSViewport(true);
194
195   if (command_line.HasSwitch(switches::kDisableSVG1DOM)) {
196     WebRuntimeFeatures::enableSVG1DOM(false);
197   }
198 }
199
200 }  // namespace content