runtime_features.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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 19using blink::WebRuntimeFeatures; 20 21namespace content { 22 23static 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 WebRuntimeFeatures::enableMediaCapture(true); 56#else 57 WebRuntimeFeatures::enableNavigatorContentUtils(true); 58#endif // defined(OS_ANDROID) 59} 60 61void SetRuntimeFeaturesDefaultsAndUpdateFromArgs( 62 const CommandLine& command_line) { 63 if (command_line.HasSwitch(switches::kEnableExperimentalWebPlatformFeatures)) 64 WebRuntimeFeatures::enableExperimentalFeatures(true); 65 66 SetRuntimeFeatureDefaultsForPlatform(); 67 68 if (command_line.HasSwitch(switches::kDisableDatabases)) 69 WebRuntimeFeatures::enableDatabase(false); 70 71 if (command_line.HasSwitch(switches::kDisableApplicationCache)) 72 WebRuntimeFeatures::enableApplicationCache(false); 73 74 if (command_line.HasSwitch(switches::kDisableDesktopNotifications)) 75 WebRuntimeFeatures::enableNotifications(false); 76 77 if (command_line.HasSwitch(switches::kDisableLocalStorage)) 78 WebRuntimeFeatures::enableLocalStorage(false); 79 80 if (command_line.HasSwitch(switches::kDisableSessionStorage)) 81 WebRuntimeFeatures::enableSessionStorage(false); 82 83 if (command_line.HasSwitch(switches::kDisableMediaSource)) 84 WebRuntimeFeatures::enableMediaSource(false); 85 86 if (command_line.HasSwitch(switches::kDisableSharedWorkers)) 87 WebRuntimeFeatures::enableSharedWorker(false); 88 89#if defined(OS_ANDROID) 90 if (command_line.HasSwitch(switches::kDisableWebRTC)) { 91 WebRuntimeFeatures::enableMediaStream(false); 92 WebRuntimeFeatures::enablePeerConnection(false); 93 } 94 95 if (!command_line.HasSwitch(switches::kEnableSpeechRecognition)) 96 WebRuntimeFeatures::enableScriptedSpeech(false); 97 98 // WebAudio is enabled by default on ARM and X86, if the MediaCodec 99 // API is available. 100 WebRuntimeFeatures::enableWebAudio( 101 !command_line.HasSwitch(switches::kDisableWebAudio) && 102 media::MediaCodecBridge::IsAvailable()); 103#else 104 if (command_line.HasSwitch(switches::kDisableWebAudio)) 105 WebRuntimeFeatures::enableWebAudio(false); 106#endif 107 108 if (command_line.HasSwitch(switches::kEnableEncryptedMedia)) 109 WebRuntimeFeatures::enableEncryptedMedia(true); 110 111 if (command_line.HasSwitch(switches::kDisablePrefixedEncryptedMedia)) 112 WebRuntimeFeatures::enablePrefixedEncryptedMedia(false); 113 114 if (command_line.HasSwitch(switches::kEnableWebAnimationsSVG)) 115 WebRuntimeFeatures::enableWebAnimationsSVG(true); 116 117 if (command_line.HasSwitch(switches::kEnableWebMIDI)) 118 WebRuntimeFeatures::enableWebMIDI(true); 119 120 if (command_line.HasSwitch(switches::kDisableFileSystem)) 121 WebRuntimeFeatures::enableFileSystem(false); 122 123 if (command_line.HasSwitch(switches::kEnableExperimentalCanvasFeatures)) 124 WebRuntimeFeatures::enableExperimentalCanvasFeatures(true); 125 126 if (command_line.HasSwitch(switches::kEnableSpeechSynthesis)) 127 WebRuntimeFeatures::enableSpeechSynthesis(true); 128 129 if (command_line.HasSwitch(switches::kEnableWebGLDraftExtensions)) 130 WebRuntimeFeatures::enableWebGLDraftExtensions(true); 131 132 if (command_line.HasSwitch(switches::kEnableWebGLImageChromium)) 133 WebRuntimeFeatures::enableWebGLImageChromium(true); 134 135 if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo)) 136 WebRuntimeFeatures::enableOverlayFullscreenVideo(true); 137 138 if (ui::IsOverlayScrollbarEnabled()) 139 WebRuntimeFeatures::enableOverlayScrollbars(true); 140 141 if (command_line.HasSwitch(switches::kEnableFastTextAutosizing)) 142 WebRuntimeFeatures::enableFastTextAutosizing(true); 143 144 if (command_line.HasSwitch(switches::kDisableFastTextAutosizing)) 145 WebRuntimeFeatures::enableFastTextAutosizing(false); 146 147 if (command_line.HasSwitch(switches::kEnableTargetedStyleRecalc)) 148 WebRuntimeFeatures::enableTargetedStyleRecalc(true); 149 150 if (command_line.HasSwitch(switches::kEnableBleedingEdgeRenderingFastPaths)) 151 WebRuntimeFeatures::enableBleedingEdgeFastPaths(true); 152 153 if (command_line.HasSwitch(switches::kEnablePreciseMemoryInfo)) 154 WebRuntimeFeatures::enablePreciseMemoryInfo(true); 155 156 if (command_line.HasSwitch(switches::kEnableLayerSquashing)) 157 WebRuntimeFeatures::enableLayerSquashing(true); 158} 159 160} // namespace content 161