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 SetRuntimeFeatureDefaultsForPlatform()27static 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 // Android does not yet support the Web Notification API. crbug.com/115320 48 WebRuntimeFeatures::enableNotifications(false); 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 SetRuntimeFeaturesDefaultsAndUpdateFromArgs(const base::CommandLine & command_line)82void SetRuntimeFeaturesDefaultsAndUpdateFromArgs( 83 const base::CommandLine& command_line) { 84 if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures)) 85 WebRuntimeFeatures::enableExperimentalFeatures(true); 86 87 SetRuntimeFeatureDefaultsForPlatform(); 88 89 if (command_line.HasSwitch(switches::kDisableDatabases)) 90 WebRuntimeFeatures::enableDatabase(false); 91 92 if (command_line.HasSwitch(switches::kDisableApplicationCache)) 93 WebRuntimeFeatures::enableApplicationCache(false); 94 95 if (command_line.HasSwitch(switches::kDisableDesktopNotifications)) 96 WebRuntimeFeatures::enableNotifications(false); 97 98 if (command_line.HasSwitch(switches::kDisableLocalStorage)) 99 WebRuntimeFeatures::enableLocalStorage(false); 100 101 if (command_line.HasSwitch(switches::kDisableSessionStorage)) 102 WebRuntimeFeatures::enableSessionStorage(false); 103 104 if (command_line.HasSwitch(switches::kDisableMediaSource)) 105 WebRuntimeFeatures::enableMediaSource(false); 106 107 if (command_line.HasSwitch(switches::kDisableSharedWorkers)) 108 WebRuntimeFeatures::enableSharedWorker(false); 109 110 #if defined(OS_ANDROID) 111 if (command_line.HasSwitch(switches::kDisableWebRTC)) 112 WebRuntimeFeatures::enablePeerConnection(false); 113 114 if (!command_line.HasSwitch(switches::kEnableSpeechRecognition)) 115 WebRuntimeFeatures::enableScriptedSpeech(false); 116 117 // WebAudio is enabled by default on ARM and X86, if the MediaCodec 118 // API is available. 119 WebRuntimeFeatures::enableWebAudio( 120 !command_line.HasSwitch(switches::kDisableWebAudio) && 121 media::MediaCodecBridge::IsAvailable()); 122 #else 123 if (command_line.HasSwitch(switches::kDisableWebAudio)) 124 WebRuntimeFeatures::enableWebAudio(false); 125 #endif 126 127 if (command_line.HasSwitch(switches::kEnableEncryptedMedia)) 128 WebRuntimeFeatures::enableEncryptedMedia(true); 129 130 if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia)) 131 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false); 132 133 if (command_line.HasSwitch(switches::kEnableWebMIDI)) 134 WebRuntimeFeatures::enableWebMIDI(true); 135 136 if (command_line.HasSwitch(switches::kDisableFileSystem)) 137 WebRuntimeFeatures::enableFileSystem(false); 138 139 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures)) 140 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true); 141 142 if (command_line.HasSwitch(switches::kEnableAcceleratedJpegDecoding)) 143 WebRuntimeFeatures::enableDecodeToYUV(true); 144 145 if (command_line.HasSwitch(switches::kDisableDisplayList2dCanvas)) { 146 WebRuntimeFeatures::enableDisplayList2dCanvas(false); 147 } else if (command_line.HasSwitch(switches::kEnableDisplayList2dCanvas)) { 148 WebRuntimeFeatures::enableDisplayList2dCanvas(true); 149 } else { 150 WebRuntimeFeatures::enableDisplayList2dCanvas( 151 base::FieldTrialList::FindFullName("DisplayList2dCanvas") == "Enabled" 152 ); 153 } 154 155 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions)) 156 WebRuntimeFeatures::enableWebGLDraftExtensions(true); 157 158 if (command_line.HasSwitch(switches::kEnableWebGLImageChromium)) 159 WebRuntimeFeatures::enableWebGLImageChromium(true); 160 161 if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo)) 162 WebRuntimeFeatures::enableOverlayFullscreenVideo(true); 163 164 if (ui::IsOverlayScrollbarEnabled()) 165 WebRuntimeFeatures::enableOverlayScrollbars(true); 166 167 if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths)) 168 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true); 169 170 if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo)) 171 WebRuntimeFeatures::enablePreciseMemoryInfo(true); 172 173 if (command_line.HasSwitch(switches::kEnableLayerSquashing)) 174 WebRuntimeFeatures::enableLayerSquashing(true); 175 176 if (command_line.HasSwitch(switches::kEnableNetworkInformation) || 177 command_line.HasSwitch( 178 switches::kEnableExperimentalWebPlatformFeatures)) { 179 WebRuntimeFeatures::enableNetworkInformation(true); 180 } 181 } 182 183 } // namespace content 184