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/public/common/content_switches.h" 9 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 10 11 #if defined(OS_ANDROID) 12 #include <cpu-features.h> 13 #include "base/android/build_info.h" 14 #endif 15 16 using WebKit::WebRuntimeFeatures; 17 18 namespace content { 19 20 static void SetRuntimeFeatureDefaultsForPlatform() { 21 #if defined(OS_ANDROID) 22 #if !defined(GOOGLE_TV) 23 // MSE/EME implementation needs Android MediaCodec API that was introduced 24 // in JellyBrean. 25 if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) { 26 WebRuntimeFeatures::enableWebKitMediaSource(false); 27 WebRuntimeFeatures::enableLegacyEncryptedMedia(false); 28 } 29 #endif // !defined(GOOGLE_TV) 30 bool enable_webaudio = false; 31 #if defined(ARCH_CPU_ARMEL) 32 // WebAudio needs Android MediaCodec API that was introduced in 33 // JellyBean, and also currently needs NEON support for the FFT. 34 enable_webaudio = 35 (base::android::BuildInfo::GetInstance()->sdk_int() >= 16) && 36 ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0); 37 #endif // defined(ARCH_CPU_ARMEL) 38 WebRuntimeFeatures::enableWebAudio(enable_webaudio); 39 // Android does not support the Gamepad API. 40 WebRuntimeFeatures::enableGamepad(false); 41 // Android does not have support for PagePopup 42 WebRuntimeFeatures::enablePagePopup(false); 43 // datalist on Android is not enabled 44 WebRuntimeFeatures::enableDataListElement(false); 45 #endif // defined(OS_ANDROID) 46 } 47 48 void SetRuntimeFeaturesDefaultsAndUpdateFromArgs( 49 const CommandLine& command_line) { 50 WebRuntimeFeatures::enableStableFeatures(true); 51 52 if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures)) 53 WebRuntimeFeatures::enableExperimentalFeatures(true); 54 55 SetRuntimeFeatureDefaultsForPlatform(); 56 57 if (command_line.HasSwitch(switches::kDisableDatabases)) 58 WebRuntimeFeatures::enableDatabase(false); 59 60 if (command_line.HasSwitch(switches::kDisableApplicationCache)) 61 WebRuntimeFeatures::enableApplicationCache(false); 62 63 if (command_line.HasSwitch(switches::kDisableDesktopNotifications)) 64 WebRuntimeFeatures::enableNotifications(false); 65 66 if (command_line.HasSwitch(switches::kDisableLocalStorage)) 67 WebRuntimeFeatures::enableLocalStorage(false); 68 69 if (command_line.HasSwitch(switches::kDisableSessionStorage)) 70 WebRuntimeFeatures::enableSessionStorage(false); 71 72 if (command_line.HasSwitch(switches::kDisableGeolocation)) 73 WebRuntimeFeatures::enableGeolocation(false); 74 75 if (command_line.HasSwitch(switches::kDisableWebKitMediaSource)) 76 WebRuntimeFeatures::enableWebKitMediaSource(false); 77 78 #if defined(OS_ANDROID) 79 if (command_line.HasSwitch(switches::kDisableWebRTC)) { 80 WebRuntimeFeatures::enableMediaStream(false); 81 WebRuntimeFeatures::enablePeerConnection(false); 82 } 83 84 if (!command_line.HasSwitch(switches::kEnableSpeechRecognition) || 85 !command_line.HasSwitch( 86 switches::kEnableExperimentalWebPlatformFeatures)) { 87 WebRuntimeFeatures::enableScriptedSpeech(false); 88 } 89 #endif 90 91 if (command_line.HasSwitch(switches::kDisableWebAudio)) 92 WebRuntimeFeatures::enableWebAudio(false); 93 94 if (command_line.HasSwitch(switches::kDisableFullScreen)) 95 WebRuntimeFeatures::enableFullscreen(false); 96 97 if (command_line.HasSwitch(switches::kEnableEncryptedMedia)) 98 WebRuntimeFeatures::enableEncryptedMedia(true); 99 100 if (command_line.HasSwitch(switches::kDisableLegacyEncryptedMedia)) 101 WebRuntimeFeatures::enableLegacyEncryptedMedia(false); 102 103 if (command_line.HasSwitch(switches::kEnableWebAnimationsCSS)) 104 WebRuntimeFeatures::enableWebAnimationsCSS(); 105 106 if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG)) 107 WebRuntimeFeatures::enableWebAnimationsSVG(); 108 109 if (command_line.HasSwitch(switches::kEnableWebMIDI)) 110 WebRuntimeFeatures::enableWebMIDI(true); 111 112 #if defined(OS_ANDROID) 113 // Enable Device Motion on Android by default. 114 WebRuntimeFeatures::enableDeviceMotion( 115 !command_line.HasSwitch(switches::kDisableDeviceMotion)); 116 #else 117 if (command_line.HasSwitch(switches::kEnableDeviceMotion)) 118 WebRuntimeFeatures::enableDeviceMotion(true); 119 #endif 120 121 if (command_line.HasSwitch(switches::kDisableDeviceOrientation)) 122 WebRuntimeFeatures::enableDeviceOrientation(false); 123 124 if (command_line.HasSwitch(switches::kDisableSpeechInput)) 125 WebRuntimeFeatures::enableSpeechInput(false); 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::kEnableHTMLImports)) 140 WebRuntimeFeatures::enableHTMLImports(true); 141 142 if (command_line.HasSwitch(switches::kEnableOverlayScrollbars)) 143 WebRuntimeFeatures::enableOverlayScrollbars(true); 144 } 145 146 } // namespace content 147