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/gpu_memory_buffer_factory_impl.h" 9 #include "android_webview/browser/in_process_view_renderer.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/renderer/aw_content_renderer_client.h" 18 #include "base/command_line.h" 19 #include "base/lazy_instance.h" 20 #include "base/logging.h" 21 #include "base/memory/scoped_ptr.h" 22 #include "base/threading/thread_restrictions.h" 23 #include "cc/base/switches.h" 24 #include "content/public/browser/browser_main_runner.h" 25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/common/content_switches.h" 27 #include "gpu/command_buffer/client/gl_in_process_context.h" 28 #include "gpu/command_buffer/service/gpu_switches.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 33 namespace android_webview { 34 35 namespace { 36 37 // TODO(boliu): Remove this global Allow once the underlying issues are 38 // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. 39 base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > 40 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 41 42 } 43 AwMainDelegate()44AwMainDelegate::AwMainDelegate() 45 : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) { 46 } 47 ~AwMainDelegate()48AwMainDelegate::~AwMainDelegate() { 49 } 50 BasicStartupComplete(int * exit_code)51bool AwMainDelegate::BasicStartupComplete(int* exit_code) { 52 content::SetContentClient(&content_client_); 53 54 gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory( 55 gpu_memory_buffer_factory_.get()); 56 57 InProcessViewRenderer::CalculateTileMemoryPolicy(); 58 59 CommandLine* cl = CommandLine::ForCurrentProcess(); 60 cl->AppendSwitch(switches::kEnableBeginFrameScheduling); 61 cl->AppendSwitch(cc::switches::kEnableMapImage); 62 63 // Disable GLSL translator. Webview is single-process so has no benefit. 64 cl->AppendSwitch(switches::kDisableGLSLTranslator); 65 66 // WebView uses the Android system's scrollbars and overscroll glow. 67 cl->AppendSwitch(switches::kHideScrollbars); 68 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect); 69 70 // Not yet supported in single-process mode. 71 cl->AppendSwitch(switches::kDisableExperimentalWebGL); 72 cl->AppendSwitch(switches::kDisableSharedWorkers); 73 74 75 // File system API not supported (requires some new API; internal bug 6930981) 76 cl->AppendSwitch(switches::kDisableFileSystem); 77 78 // Disable compositor touch hit testing for now to mitigate risk of bugs. 79 cl->AppendSwitch(cc::switches::kDisableCompositorTouchHitTesting); 80 81 // Disable WebRTC. 82 cl->AppendSwitch(switches::kDisableWebRTC); 83 84 return false; 85 } 86 PreSandboxStartup()87void AwMainDelegate::PreSandboxStartup() { 88 // TODO(torne): When we have a separate renderer process, we need to handle 89 // being passed open FDs for the resource paks here. 90 } 91 SandboxInitialized(const std::string & process_type)92void AwMainDelegate::SandboxInitialized(const std::string& process_type) { 93 // TODO(torne): Adjust linux OOM score here. 94 } 95 RunProcess(const std::string & process_type,const content::MainFunctionParams & main_function_params)96int AwMainDelegate::RunProcess( 97 const std::string& process_type, 98 const content::MainFunctionParams& main_function_params) { 99 if (process_type.empty()) { 100 AwBrowserDependencyFactoryImpl::InstallInstance(); 101 102 browser_runner_.reset(content::BrowserMainRunner::Create()); 103 int exit_code = browser_runner_->Initialize(main_function_params); 104 DCHECK(exit_code < 0); 105 106 g_allow_wait_in_ui_thread.Get().reset( 107 new ScopedAllowWaitForLegacyWebViewApi); 108 109 // Return 0 so that we do NOT trigger the default behavior. On Android, the 110 // UI message loop is managed by the Java application. 111 return 0; 112 } 113 114 return -1; 115 } 116 ProcessExiting(const std::string & process_type)117void AwMainDelegate::ProcessExiting(const std::string& process_type) { 118 // TODO(torne): Clean up resources when we handle them. 119 120 logging::CloseLogFile(); 121 } 122 123 content::ContentBrowserClient* CreateContentBrowserClient()124 AwMainDelegate::CreateContentBrowserClient() { 125 content_browser_client_.reset(new AwContentBrowserClient(this)); 126 return content_browser_client_.get(); 127 } 128 129 content::ContentRendererClient* CreateContentRendererClient()130 AwMainDelegate::CreateContentRendererClient() { 131 content_renderer_client_.reset(new AwContentRendererClient()); 132 return content_renderer_client_.get(); 133 } 134 CreateAwQuotaManagerBridge(AwBrowserContext * browser_context)135scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge( 136 AwBrowserContext* browser_context) { 137 return AwQuotaManagerBridgeImpl::Create(browser_context); 138 } 139 140 content::GeolocationPermissionContext* CreateGeolocationPermission(AwBrowserContext * browser_context)141 AwMainDelegate::CreateGeolocationPermission( 142 AwBrowserContext* browser_context) { 143 return AwGeolocationPermissionContext::Create(browser_context); 144 } 145 CreateViewDelegate(content::WebContents * web_contents)146content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( 147 content::WebContents* web_contents) { 148 return AwWebContentsViewDelegate::Create(web_contents); 149 } 150 CreateWebPreferencesPopulater()151AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() { 152 return new AwWebPreferencesPopulaterImpl(); 153 } 154 155 } // namespace android_webview 156