aw_main_delegate.cc revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
1// Copyright (c) 2012 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 "android_webview/lib/main/aw_main_delegate.h" 6 7#include "android_webview/browser/aw_content_browser_client.h" 8#include "android_webview/browser/browser_view_renderer.h" 9#include "android_webview/browser/gpu_memory_buffer_factory_impl.h" 10#include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" 11#include "android_webview/common/aw_switches.h" 12#include "android_webview/lib/aw_browser_dependency_factory_impl.h" 13#include "android_webview/native/aw_geolocation_permission_context.h" 14#include "android_webview/native/aw_quota_manager_bridge_impl.h" 15#include "android_webview/native/aw_web_contents_view_delegate.h" 16#include "android_webview/native/aw_web_preferences_populater_impl.h" 17#include "android_webview/native/external_video_surface_container_impl.h" 18#include "android_webview/renderer/aw_content_renderer_client.h" 19#include "base/command_line.h" 20#include "base/cpu.h" 21#include "base/lazy_instance.h" 22#include "base/logging.h" 23#include "base/memory/scoped_ptr.h" 24#include "base/threading/thread_restrictions.h" 25#include "content/public/browser/browser_main_runner.h" 26#include "content/public/browser/browser_thread.h" 27#include "content/public/common/content_switches.h" 28#include "gpu/command_buffer/client/gl_in_process_context.h" 29#include "gpu/command_buffer/service/in_process_command_buffer.h" 30#include "media/base/media_switches.h" 31#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 32 33namespace android_webview { 34 35namespace { 36 37// TODO(boliu): Remove this global Allow once the underlying issues are 38// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. 39base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > 40 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 41 42} 43 44AwMainDelegate::AwMainDelegate() 45 : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) { 46} 47 48AwMainDelegate::~AwMainDelegate() { 49} 50 51bool AwMainDelegate::BasicStartupComplete(int* exit_code) { 52 content::SetContentClient(&content_client_); 53 54 gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory( 55 gpu_memory_buffer_factory_.get()); 56 57 BrowserViewRenderer::CalculateTileMemoryPolicy(); 58 59 CommandLine* cl = CommandLine::ForCurrentProcess(); 60 cl->AppendSwitch(switches::kEnableBeginFrameScheduling); 61 cl->AppendSwitch(switches::kEnableZeroCopy); 62 cl->AppendSwitch(switches::kEnableImplSidePainting); 63 64 // WebView uses the Android system's scrollbars and overscroll glow. 65 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect); 66 67 // Not yet supported in single-process mode. 68 cl->AppendSwitch(switches::kDisableSharedWorkers); 69 70 if (!switches::UbercompEnabled()) { 71 cl->AppendSwitch(switches::kDisableDelegatedRenderer); 72 } else { 73 cl->AppendSwitch(switches::kDisableAccelerated2dCanvas); 74 cl->AppendSwitch(switches::kDisableExperimentalWebGL); 75 } 76 77 // File system API not supported (requires some new API; internal bug 6930981) 78 cl->AppendSwitch(switches::kDisableFileSystem); 79 80 // Fullscreen video with subtitle is not yet supported. 81 cl->AppendSwitch(switches::kDisableOverlayFullscreenVideoSubtitle); 82 83#if defined(VIDEO_HOLE) 84 // Support EME/L1 with hole-punching. 85 cl->AppendSwitch(switches::kMediaDrmEnableNonCompositing); 86#endif 87 88 // WebRTC hardware decoding is not supported, internal bug 15075307 89 cl->AppendSwitch(switches::kDisableWebRtcHWDecoding); 90 return false; 91} 92 93void AwMainDelegate::PreSandboxStartup() { 94 // TODO(torne): When we have a separate renderer process, we need to handle 95 // being passed open FDs for the resource paks here. 96#if defined(ARCH_CPU_ARM_FAMILY) 97 // Create an instance of the CPU class to parse /proc/cpuinfo and cache 98 // cpu_brand info. 99 base::CPU cpu_info; 100#endif 101} 102 103void AwMainDelegate::SandboxInitialized(const std::string& process_type) { 104 // TODO(torne): Adjust linux OOM score here. 105} 106 107int AwMainDelegate::RunProcess( 108 const std::string& process_type, 109 const content::MainFunctionParams& main_function_params) { 110 if (process_type.empty()) { 111 AwBrowserDependencyFactoryImpl::InstallInstance(); 112 113 browser_runner_.reset(content::BrowserMainRunner::Create()); 114 int exit_code = browser_runner_->Initialize(main_function_params); 115 DCHECK(exit_code < 0); 116 117 g_allow_wait_in_ui_thread.Get().reset( 118 new ScopedAllowWaitForLegacyWebViewApi); 119 120 // Return 0 so that we do NOT trigger the default behavior. On Android, the 121 // UI message loop is managed by the Java application. 122 return 0; 123 } 124 125 return -1; 126} 127 128void AwMainDelegate::ProcessExiting(const std::string& process_type) { 129 // TODO(torne): Clean up resources when we handle them. 130 131 logging::CloseLogFile(); 132} 133 134content::ContentBrowserClient* 135 AwMainDelegate::CreateContentBrowserClient() { 136 content_browser_client_.reset(new AwContentBrowserClient(this)); 137 return content_browser_client_.get(); 138} 139 140content::ContentRendererClient* 141 AwMainDelegate::CreateContentRendererClient() { 142 content_renderer_client_.reset(new AwContentRendererClient()); 143 return content_renderer_client_.get(); 144} 145 146scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge( 147 AwBrowserContext* browser_context) { 148 return AwQuotaManagerBridgeImpl::Create(browser_context); 149} 150 151content::GeolocationPermissionContext* 152 AwMainDelegate::CreateGeolocationPermission( 153 AwBrowserContext* browser_context) { 154 return AwGeolocationPermissionContext::Create(browser_context); 155} 156 157content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( 158 content::WebContents* web_contents) { 159 return AwWebContentsViewDelegate::Create(web_contents); 160} 161 162AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() { 163 return new AwWebPreferencesPopulaterImpl(); 164} 165 166#if defined(VIDEO_HOLE) 167content::ExternalVideoSurfaceContainer* 168AwMainDelegate::CreateExternalVideoSurfaceContainer( 169 content::WebContents* web_contents) { 170 return new ExternalVideoSurfaceContainerImpl(web_contents); 171} 172#endif 173 174} // namespace android_webview 175