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