Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / child / runtime_features.cc
blob39adb1276985bebf57643e7f2944c884fdbf6e16
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 "content/common/content_switches_internal.h"
13 #include "content/public/common/content_switches.h"
14 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
15 #include "ui/gl/gl_switches.h"
16 #include "ui/native_theme/native_theme_switches.h"
18 #if defined(OS_ANDROID)
19 #include <cpu-features.h>
20 #include "base/android/build_info.h"
21 #include "base/metrics/field_trial.h"
22 #include "media/base/android/media_codec_bridge.h"
23 #elif defined(OS_WIN)
24 #include "base/win/windows_version.h"
25 #endif
27 using blink::WebRuntimeFeatures;
29 namespace content {
31 static void SetRuntimeFeatureDefaultsForPlatform() {
32 // Enable non-standard "apple-touch-icon" and "apple-touch-icon-precomposed".
33 WebRuntimeFeatures::enableTouchIconLoading(true);
35 #if defined(OS_ANDROID)
36 // MSE/EME implementation needs Android MediaCodec API.
37 if (!media::MediaCodecBridge::IsAvailable()) {
38 WebRuntimeFeatures::enableMediaSource(false);
39 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
40 WebRuntimeFeatures::enableEncryptedMedia(false);
42 // WebAudio is enabled by default but only when the MediaCodec API
43 // is available.
44 AndroidCpuFamily cpu_family = android_getCpuFamily();
45 WebRuntimeFeatures::enableWebAudio(
46 media::MediaCodecBridge::IsAvailable() &&
47 ((cpu_family == ANDROID_CPU_FAMILY_ARM) ||
48 (cpu_family == ANDROID_CPU_FAMILY_ARM64) ||
49 (cpu_family == ANDROID_CPU_FAMILY_X86) ||
50 (cpu_family == ANDROID_CPU_FAMILY_MIPS)));
52 // Android does not have support for PagePopup
53 WebRuntimeFeatures::enablePagePopup(false);
54 // Android does not yet support SharedWorker. crbug.com/154571
55 WebRuntimeFeatures::enableSharedWorker(false);
56 // Android does not yet support NavigatorContentUtils.
57 WebRuntimeFeatures::enableNavigatorContentUtils(false);
58 WebRuntimeFeatures::enableOrientationEvent(true);
59 WebRuntimeFeatures::enableFastMobileScrolling(true);
60 WebRuntimeFeatures::enableMediaCapture(true);
61 WebRuntimeFeatures::enableCompositedSelectionUpdate(true);
62 // If navigation transitions gets activated via field trial, enable it in
63 // blink. We don't set this to false in case the user has manually enabled
64 // the feature via experimental web platform features.
65 if (base::FieldTrialList::FindFullName("NavigationTransitions") == "Enabled")
66 WebRuntimeFeatures::enableNavigationTransitions(true);
67 // Android won't be able to reliably support non-persistent notifications, the
68 // intended behavior for which is in flux by itself.
69 WebRuntimeFeatures::enableNotificationConstructor(false);
70 #else
71 WebRuntimeFeatures::enableNavigatorContentUtils(true);
72 #endif // defined(OS_ANDROID)
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 SetRuntimeFeatureDefaultsForPlatform();
96 if (command_line.HasSwitch(switches::kDisableDatabases))
97 WebRuntimeFeatures::enableDatabase(false);
99 if (command_line.HasSwitch(switches::kDisableBlinkScheduler))
100 WebRuntimeFeatures::enableBlinkScheduler(false);
102 if (command_line.HasSwitch(switches::kDisableLocalStorage))
103 WebRuntimeFeatures::enableLocalStorage(false);
105 if (command_line.HasSwitch(switches::kDisableMediaSource))
106 WebRuntimeFeatures::enableMediaSource(false);
108 if (command_line.HasSwitch(switches::kDisableNotifications)) {
109 WebRuntimeFeatures::enableNotifications(false);
111 // Chrome's Push Messaging implementation relies on Web Notifications.
112 WebRuntimeFeatures::enablePushMessaging(false);
115 if (command_line.HasSwitch(switches::kDisableSharedWorkers))
116 WebRuntimeFeatures::enableSharedWorker(false);
118 #if defined(OS_ANDROID)
119 if (command_line.HasSwitch(switches::kDisableWebRTC))
120 WebRuntimeFeatures::enablePeerConnection(false);
122 // WebAudio is enabled by default on ARM and X86, if the MediaCodec
123 // API is available.
124 WebRuntimeFeatures::enableWebAudio(
125 !command_line.HasSwitch(switches::kDisableWebAudio) &&
126 media::MediaCodecBridge::IsAvailable());
127 #else
128 if (command_line.HasSwitch(switches::kDisableWebAudio))
129 WebRuntimeFeatures::enableWebAudio(false);
130 #endif
132 if (command_line.HasSwitch(switches::kDisableEncryptedMedia))
133 WebRuntimeFeatures::enableEncryptedMedia(false);
135 if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
136 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
138 if (command_line.HasSwitch(switches::kDisableFileSystem))
139 WebRuntimeFeatures::enableFileSystem(false);
141 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
142 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
144 if (!command_line.HasSwitch(switches::kDisableAcceleratedJpegDecoding))
145 WebRuntimeFeatures::enableDecodeToYUV(true);
147 if (command_line.HasSwitch(switches::kEnableDisplayList2dCanvas))
148 WebRuntimeFeatures::enableDisplayList2dCanvas(true);
150 if (command_line.HasSwitch(switches::kDisableDisplayList2dCanvas))
151 WebRuntimeFeatures::enableDisplayList2dCanvas(false);
153 if (command_line.HasSwitch(switches::kForceDisplayList2dCanvas))
154 WebRuntimeFeatures::forceDisplayList2dCanvas(true);
156 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
157 WebRuntimeFeatures::enableWebGLDraftExtensions(true);
159 if (command_line.HasSwitch(switches::kEnableWebGLImageChromium))
160 WebRuntimeFeatures::enableWebGLImageChromium(true);
162 if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
163 WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
165 if (ui::IsOverlayScrollbarEnabled())
166 WebRuntimeFeatures::enableOverlayScrollbars(true);
168 if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
169 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
171 if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
172 WebRuntimeFeatures::enablePreciseMemoryInfo(true);
174 if (command_line.HasSwitch(switches::kEnableNetworkInformation) ||
175 command_line.HasSwitch(
176 switches::kEnableExperimentalWebPlatformFeatures)) {
177 WebRuntimeFeatures::enableNetworkInformation(true);
180 if (command_line.HasSwitch(switches::kEnableCredentialManagerAPI))
181 WebRuntimeFeatures::enableCredentialManagerAPI(true);
183 if (command_line.HasSwitch(switches::kDisableSVG1DOM)) {
184 WebRuntimeFeatures::enableSVG1DOM(false);
187 if (command_line.HasSwitch(switches::kReducedReferrerGranularity))
188 WebRuntimeFeatures::enableReducedReferrerGranularity(true);
190 if (command_line.HasSwitch(switches::kEnablePushMessagePayload))
191 WebRuntimeFeatures::enablePushMessagingData(true);
193 if (command_line.HasSwitch(switches::kEnablePushMessagingHasPermission))
194 WebRuntimeFeatures::enablePushMessagingHasPermission(true);
196 // Delete "StaleWhileRevalidate" line from chrome_browser_field_trials.cc
197 // when this experiment is done.
198 if (base::FieldTrialList::FindFullName("StaleWhileRevalidate") == "Enabled" ||
199 command_line.HasSwitch(switches::kEnableStaleWhileRevalidate))
200 WebRuntimeFeatures::enableStaleWhileRevalidateCacheControl(true);
202 if (command_line.HasSwitch(switches::kDisableV8IdleTasks))
203 WebRuntimeFeatures::enableV8IdleTasks(false);
204 else
205 WebRuntimeFeatures::enableV8IdleTasks(true);
207 if (command_line.HasSwitch(switches::kEnableUnsafeES3APIs))
208 WebRuntimeFeatures::enableUnsafeES3APIs(true);
210 // Enable explicitly enabled features, and then disable explicitly disabled
211 // ones.
212 if (command_line.HasSwitch(switches::kEnableBlinkFeatures)) {
213 std::vector<std::string> enabled_features;
214 base::SplitString(
215 command_line.GetSwitchValueASCII(switches::kEnableBlinkFeatures), ',',
216 &enabled_features);
217 for (const std::string& feature : enabled_features) {
218 WebRuntimeFeatures::enableFeatureFromString(
219 blink::WebString::fromLatin1(feature), true);
222 if (command_line.HasSwitch(switches::kDisableBlinkFeatures)) {
223 std::vector<std::string> disabled_features;
224 base::SplitString(
225 command_line.GetSwitchValueASCII(switches::kDisableBlinkFeatures), ',',
226 &disabled_features);
227 for (const std::string& feature : disabled_features) {
228 WebRuntimeFeatures::enableFeatureFromString(
229 blink::WebString::fromLatin1(feature), false);
234 } // namespace content