• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/android/build_info.h"
16 #include "media/base/android/media_codec_bridge.h"
17 #endif
18 
19 using blink::WebRuntimeFeatures;
20 
21 namespace content {
22 
SetRuntimeFeatureDefaultsForPlatform()23 static void SetRuntimeFeatureDefaultsForPlatform() {
24 #if defined(OS_ANDROID)
25   // MSE/EME implementation needs Android MediaCodec API.
26   if (!media::MediaCodecBridge::IsAvailable()) {
27     WebRuntimeFeatures::enableMediaSource(false);
28     WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
29     WebRuntimeFeatures::enableEncryptedMedia(false);
30   }
31   // WebAudio is enabled by default but only when the MediaCodec API
32   // is available.
33   AndroidCpuFamily cpu_family = android_getCpuFamily();
34   WebRuntimeFeatures::enableWebAudio(
35       media::MediaCodecBridge::IsAvailable() &&
36       ((cpu_family == ANDROID_CPU_FAMILY_ARM) ||
37        (cpu_family == ANDROID_CPU_FAMILY_ARM64) ||
38        (cpu_family == ANDROID_CPU_FAMILY_X86) ||
39        (cpu_family == ANDROID_CPU_FAMILY_MIPS)));
40 
41   // Android supports gamepad API for JellyBean and beyond
42   WebRuntimeFeatures::enableGamepad(
43       base::android::BuildInfo::GetInstance()->sdk_int() >= 16);
44   // Android does not have support for PagePopup
45   WebRuntimeFeatures::enablePagePopup(false);
46   // Android does not yet support the Web Notification API. crbug.com/115320
47   WebRuntimeFeatures::enableNotifications(false);
48   // Android does not yet support SharedWorker. crbug.com/154571
49   WebRuntimeFeatures::enableSharedWorker(false);
50   // Android does not yet support NavigatorContentUtils.
51   WebRuntimeFeatures::enableNavigatorContentUtils(false);
52   WebRuntimeFeatures::enableTouchIconLoading(true);
53   WebRuntimeFeatures::enableOrientationEvent(true);
54   WebRuntimeFeatures::enableFastMobileScrolling(true);
55 #else
56   WebRuntimeFeatures::enableNavigatorContentUtils(true);
57 #endif  // defined(OS_ANDROID)
58 }
59 
SetRuntimeFeaturesDefaultsAndUpdateFromArgs(const CommandLine & command_line)60 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
61     const CommandLine& command_line) {
62   if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures))
63     WebRuntimeFeatures::enableExperimentalFeatures(true);
64 
65   SetRuntimeFeatureDefaultsForPlatform();
66 
67   if (command_line.HasSwitch(switches::kDisableDatabases))
68     WebRuntimeFeatures::enableDatabase(false);
69 
70   if (command_line.HasSwitch(switches::kDisableApplicationCache))
71     WebRuntimeFeatures::enableApplicationCache(false);
72 
73   if (command_line.HasSwitch(switches::kDisableDesktopNotifications))
74     WebRuntimeFeatures::enableNotifications(false);
75 
76   if (command_line.HasSwitch(switches::kDisableNavigatorContentUtils))
77     WebRuntimeFeatures::enableNavigatorContentUtils(false);
78 
79   if (command_line.HasSwitch(switches::kDisableLocalStorage))
80     WebRuntimeFeatures::enableLocalStorage(false);
81 
82   if (command_line.HasSwitch(switches::kDisableSessionStorage))
83     WebRuntimeFeatures::enableSessionStorage(false);
84 
85   if (command_line.HasSwitch(switches::kDisableMediaSource))
86     WebRuntimeFeatures::enableMediaSource(false);
87 
88   if (command_line.HasSwitch(switches::kDisableSharedWorkers))
89     WebRuntimeFeatures::enableSharedWorker(false);
90 
91 #if defined(OS_ANDROID)
92   if (command_line.HasSwitch(switches::kDisableWebRTC)) {
93     WebRuntimeFeatures::enableMediaStream(false);
94     WebRuntimeFeatures::enablePeerConnection(false);
95   }
96 
97   if (!command_line.HasSwitch(switches::kEnableSpeechRecognition))
98     WebRuntimeFeatures::enableScriptedSpeech(false);
99 #endif
100 
101   if (command_line.HasSwitch(switches::kEnableServiceWorker))
102     WebRuntimeFeatures::enableServiceWorker(true);
103 
104 #if defined(OS_ANDROID)
105   // WebAudio is enabled by default on ARM and X86, if the MediaCodec
106   // API is available.
107   WebRuntimeFeatures::enableWebAudio(
108       !command_line.HasSwitch(switches::kDisableWebAudio) &&
109       media::MediaCodecBridge::IsAvailable());
110 #else
111   if (command_line.HasSwitch(switches::kDisableWebAudio))
112     WebRuntimeFeatures::enableWebAudio(false);
113 #endif
114 
115   if (command_line.HasSwitch(switches::kEnableEncryptedMedia))
116     WebRuntimeFeatures::enableEncryptedMedia(true);
117 
118   if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia))
119     WebRuntimeFeatures::enablePrefixedEncryptedMedia(false);
120 
121   if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG))
122     WebRuntimeFeatures::enableWebAnimationsSVG(true);
123 
124   if (command_line.HasSwitch(switches::kEnableWebMIDI))
125     WebRuntimeFeatures::enableWebMIDI(true);
126 
127   if (command_line.HasSwitch(switches::kDisableFileSystem))
128     WebRuntimeFeatures::enableFileSystem(false);
129 
130   if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures))
131     WebRuntimeFeatures::enableExperimentalCanvasFeatures(true);
132 
133   if (command_line.HasSwitch(switches::kEnableSpeechSynthesis))
134     WebRuntimeFeatures::enableSpeechSynthesis(true);
135 
136   if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions))
137     WebRuntimeFeatures::enableWebGLDraftExtensions(true);
138 
139   if (command_line.HasSwitch(switches::kEnableWebGLImageChromium))
140     WebRuntimeFeatures::enableWebGLImageChromium(true);
141 
142   if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
143     WebRuntimeFeatures::enableOverlayFullscreenVideo(true);
144 
145   if (ui::IsOverlayScrollbarEnabled())
146     WebRuntimeFeatures::enableOverlayScrollbars(true);
147 
148   if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
149     WebRuntimeFeatures::enableFastTextAutosizing(true);
150 
151   if (command_line.HasSwitch(switches::kDisableFastTextAutosizing))
152     WebRuntimeFeatures::enableFastTextAutosizing(false);
153 
154   if (command_line.HasSwitch(switches::kDisableRepaintAfterLayout))
155     WebRuntimeFeatures::enableRepaintAfterLayout(false);
156 
157   if (command_line.HasSwitch(switches::kEnableRepaintAfterLayout))
158     WebRuntimeFeatures::enableRepaintAfterLayout(true);
159 
160   if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc))
161     WebRuntimeFeatures::enableTargetedStyleRecalc(true);
162 
163   if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths))
164     WebRuntimeFeatures::enableBleedingEdgeFastPaths(true);
165 
166   if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo))
167     WebRuntimeFeatures::enablePreciseMemoryInfo(true);
168 
169   if (command_line.HasSwitch(switches::kEnableLayerSquashing))
170     WebRuntimeFeatures::enableLayerSquashing(true);
171 }
172 
173 }  // namespace content
174