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