Add configs that depend on linux builder and linux builder (dbg).
[chromium-blink-merge.git] / content / child / runtime_features.cc
blob94a6f2aeed74a55b822f65ee552adb6128ff7049
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.
5 #include "content/child/runtime_features.h"
7 #include <vector>
9 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/strings/string_split.h"
12 #include "components/scheduler/common/scheduler_switches.h"
13 #include "content/common/content_switches_internal.h"
14 #include "content/public/common/content_switches.h"
15 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
16 #include "ui/gl/gl_switches.h"
17 #include "ui/native_theme/native_theme_switches.h"
19 #if defined(OS_ANDROID)
20 #include <cpu-features.h>
21 #include "base/android/build_info.h"
22 #include "base/metrics/field_trial.h"
23 #include "media/base/android/media_codec_bridge.h"
24 #elif defined(OS_WIN)
25 #include "base/win/windows_version.h"
26 #endif
28 using blink::WebRuntimeFeatures;
30 namespace content {
32 static void SetRuntimeFeatureDefaultsForPlatform() {
33 // Enable non-standard "apple-touch-icon" and "apple-touch-icon-precomposed".
34 WebRuntimeFeatures::enableTouchIconLoading(true);
36 #if defined(OS_ANDROID)
37 // MSE/EME implementation needs Android MediaCodec API.
38 if (!media::MediaCodecBridge::IsAvailable()) {
39 WebRuntimeFeatures::enableMediaSource(false);
40 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
41 WebRuntimeFeatures::enableEncryptedMedia(false);
43 // WebAudio is enabled by default but only when the MediaCodec API
44 // is available.
45 AndroidCpuFamily cpu_family = android_getCpuFamily();
46 WebRuntimeFeatures::enableWebAudio(
47 media::MediaCodecBridge::IsAvailable() &&
48 ((cpu_family == ANDROID_CPU_FAMILY_ARM) ||
49 (cpu_family == ANDROID_CPU_FAMILY_ARM64) ||
50 (cpu_family == ANDROID_CPU_FAMILY_X86) ||
51 (cpu_family == ANDROID_CPU_FAMILY_MIPS)));
53 // Android does not have support for PagePopup
54 WebRuntimeFeatures::enablePagePopup(false);
55 // Android does not yet support SharedWorker. crbug.com/154571
56 WebRuntimeFeatures::enableSharedWorker(false);
57 // Android does not yet support NavigatorContentUtils.
58 WebRuntimeFeatures::enableNavigatorContentUtils(false);
59 WebRuntimeFeatures::enableOrientationEvent(true);
60 WebRuntimeFeatures::enableFastMobileScrolling(true);
61 WebRuntimeFeatures::enableMediaCapture(true);
62 // Android won't be able to reliably support non-persistent notifications, the
63 // intended behavior for which is in flux by itself.
64 WebRuntimeFeatures::enableNotificationConstructor(false);
65 WebRuntimeFeatures::enableNewMediaPlaybackUi(true);
66 #else
67 WebRuntimeFeatures::enableNavigatorContentUtils(true);
68 #endif // defined(OS_ANDROID)
70 #if defined(OS_ANDROID) || defined(USE_AURA)
71 WebRuntimeFeatures::enableCompositedSelectionUpdate(true);
72 #endif
74 #if !(defined OS_ANDROID || defined OS_CHROMEOS || defined OS_IOS)
75 // Only Android, ChromeOS, and IOS support NetInfo right now.
76 WebRuntimeFeatures::enableNetworkInformation(false);
77 #endif
79 #if defined(OS_WIN)
80 // Screen Orientation API is currently broken on Windows 8 Metro mode and
81 // until we can find how to disable it only for Blink instances running in a
82 // renderer process in Metro, we need to disable the API altogether for Win8.
83 // See http://crbug.com/400846
84 if (base::win::OSInfo::GetInstance()->version() >= base::win::VERSION_WIN8)
85 WebRuntimeFeatures::enableScreenOrientation(false);
86 #endif // OS_WIN
89 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
90 const base::CommandLine& command_line) {
91 if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
92 WebRuntimeFeatures::enableExperimentalFeatures(true);
94 if (command_line.HasSwitch(switches::kEnableWebBluetooth))
95 WebRuntimeFeatures::enableWebBluetooth(true);
97 SetRuntimeFeatureDefaultsForPlatform();
99 if (command_line.HasSwitch(switches::kDisableDatabases))
100 WebRuntimeFeatures::enableDatabase(false);
102 if (command_line.HasSwitch(switches::kDisableMediaSource))
103 WebRuntimeFeatures::enableMediaSource(false);
105 if (command_line.HasSwitch(switches::kDisableNotifications)) {
106 WebRuntimeFeatures::enableNotifications(false);
108 // Chrome's Push Messaging implementation relies on Web Notifications.
109 WebRuntimeFeatures::enablePushMessaging(false);
112 if (command_line.HasSwitch(switches::kDisableSharedWorkers))
113 WebRuntimeFeatures::enableSharedWorker(false);
115 #if defined(OS_ANDROID)
116 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
117 // API is available.
118 WebRuntimeFeatures::enableWebAudio(
119 !command_line.HasSwitch(switches::kDisableWebAudio) &&
120 media::MediaCodecBridge::IsAvailable());
121 #else
122 if (command_line.HasSwitch(switches::kDisableWebAudio))
123 WebRuntimeFeatures::enableWebAudio(false);
124 #endif
126 if (command_line.HasSwitch(switches::kDisableSpeechAPI))
127 WebRuntimeFeatures::enableScriptedSpeech(false);
129 if (command_line.HasSwitch(switches::kDisableEncryptedMedia))
130 WebRuntimeFeatures::enableEncryptedMedia(false);
132 if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
133 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
135 if (command_line.HasSwitch(switches::kDisableFileSystem))
136 WebRuntimeFeatures::enableFileSystem(false);
138 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
139 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
141 if (!command_line.HasSwitch(switches::kDisableAcceleratedJpegDecoding))
142 WebRuntimeFeatures::enableDecodeToYUV(true);
144 if (command_line.HasSwitch(switches::kEnableDisplayList2dCanvas))
145 WebRuntimeFeatures::enableDisplayList2dCanvas(true);
147 if (command_line.HasSwitch(switches::kDisableDisplayList2dCanvas))
148 WebRuntimeFeatures::enableDisplayList2dCanvas(false);
150 if (command_line.HasSwitch(switches::kForceDisplayList2dCanvas))
151 WebRuntimeFeatures::forceDisplayList2dCanvas(true);
153 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
154 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
156 if (command_line.HasSwitch(switches::kEnableWebGLImageChromium))
157 WebRuntimeFeatures::enableWebGLImageChromium(true);
159 if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
160 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
162 if (ui::IsOverlayScrollbarEnabled())
163 WebRuntimeFeatures::enableOverlayScrollbars(true);
165 if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
166 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
168 if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
169 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
171 if (command_line.HasSwitch(switches::kEnableNetworkInformation) ||
172 command_line.HasSwitch(
173 switches::kEnableExperimentalWebPlatformFeatures)) {
174 WebRuntimeFeatures::enableNetworkInformation(true);
177 if (command_line.HasSwitch(switches::kEnableCredentialManagerAPI))
178 WebRuntimeFeatures::enableCredentialManagerAPI(true);
180 if (command_line.HasSwitch(switches::kDisableSVG1DOM)) {
181 WebRuntimeFeatures::enableSVG1DOM(false);
184 if (command_line.HasSwitch(switches::kReducedReferrerGranularity))
185 WebRuntimeFeatures::enableReducedReferrerGranularity(true);
187 if (command_line.HasSwitch(switches::kEnablePushMessagePayload))
188 WebRuntimeFeatures::enablePushMessagingData(true);
190 if (command_line.HasSwitch(switches::kDisablePermissionsAPI))
191 WebRuntimeFeatures::enablePermissionsAPI(false);
193 // Delete "StaleWhileRevalidate" line from chrome_browser_field_trials.cc
194 // when this experiment is done.
195 if (base::FieldTrialList::FindFullName("StaleWhileRevalidate") == "Enabled" ||
196 command_line.HasSwitch(switches::kEnableStaleWhileRevalidate))
197 WebRuntimeFeatures::enableStaleWhileRevalidateCacheControl(true);
199 if (command_line.HasSwitch(switches::kDisableV8IdleTasks))
200 WebRuntimeFeatures::enableV8IdleTasks(false);
201 else
202 WebRuntimeFeatures::enableV8IdleTasks(true);
204 if (command_line.HasSwitch(switches::kEnableUnsafeES3APIs))
205 WebRuntimeFeatures::enableUnsafeES3APIs(true);
207 if (command_line.HasSwitch(switches::kEnableWebVR)) {
208 WebRuntimeFeatures::enableWebVR(true);
209 WebRuntimeFeatures::enableFeatureFromString(
210 std::string("GeometryInterfaces"), true);
213 // Enable explicitly enabled features, and then disable explicitly disabled
214 // ones.
215 if (command_line.HasSwitch(switches::kEnableBlinkFeatures)) {
216 std::vector<std::string> enabled_features = base::SplitString(
217 command_line.GetSwitchValueASCII(switches::kEnableBlinkFeatures),
218 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
219 for (const std::string& feature : enabled_features)
220 WebRuntimeFeatures::enableFeatureFromString(feature, true);
222 if (command_line.HasSwitch(switches::kDisableBlinkFeatures)) {
223 std::vector<std::string> disabled_features = base::SplitString(
224 command_line.GetSwitchValueASCII(switches::kDisableBlinkFeatures),
225 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
226 for (const std::string& feature : disabled_features)
227 WebRuntimeFeatures::enableFeatureFromString(feature, false);
231 } // namespace content