aw_main_delegate.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt// Use of this source code is governed by a BSD-style license that can be 3e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt// found in the LICENSE file. 4e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt 5e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt#include "android_webview/lib/main/aw_main_delegate.h" 6e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt 7e86eee143ed21592f88a46623a81f71002430459Dmitry Shmidt#include "android_webview/browser/aw_content_browser_client.h" 8f7c5421560640d23fc10803b9d59a9ff1d83e467The Android Open Source Project#include "android_webview/browser/gpu_memory_buffer_factory_impl.h" 909cda4fad9681e8500485ef0b71974d16c28fcc3Elliott Hughes#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/in_process_command_buffer.h" 29#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 30 31namespace android_webview { 32 33namespace { 34 35// TODO(boliu): Remove this global Allow once the underlying issues are 36// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. 37base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > 38 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 39 40} 41 42AwMainDelegate::AwMainDelegate() 43 : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) { 44} 45 46AwMainDelegate::~AwMainDelegate() { 47} 48 49bool AwMainDelegate::BasicStartupComplete(int* exit_code) { 50 content::SetContentClient(&content_client_); 51 52 gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory( 53 gpu_memory_buffer_factory_.get()); 54 55 InProcessViewRenderer::CalculateTileMemoryPolicy(); 56 57 CommandLine* cl = CommandLine::ForCurrentProcess(); 58 cl->AppendSwitch(switches::kEnableBeginFrameScheduling); 59 cl->AppendSwitch(cc::switches::kEnableMapImage); 60 61 // WebView uses the Android system's scrollbars and overscroll glow. 62 cl->AppendSwitch(switches::kHideScrollbars); 63 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect); 64 65 // Not yet supported in single-process mode. 66 cl->AppendSwitch(switches::kDisableExperimentalWebGL); 67 cl->AppendSwitch(switches::kDisableSharedWorkers); 68 69 // Ganesh backed 2D-Canvas integration is being implemented but not ready to 70 // be turned on by default yet. 71 if (!cl->HasSwitch(switches::kEnableAccelerated2dCanvas)) 72 cl->AppendSwitch(switches::kDisableAccelerated2dCanvas); 73 74 // File system API not supported (requires some new API; internal bug 6930981) 75 cl->AppendSwitch(switches::kDisableFileSystem); 76 77 // Disable compositor touch hit testing for now to mitigate risk of bugs. 78 cl->AppendSwitch(cc::switches::kDisableCompositorTouchHitTesting); 79 80 // Disable WebRTC. 81 cl->AppendSwitch(switches::kDisableWebRTC); 82 83 return false; 84} 85 86void AwMainDelegate::PreSandboxStartup() { 87 // TODO(torne): When we have a separate renderer process, we need to handle 88 // being passed open FDs for the resource paks here. 89} 90 91void AwMainDelegate::SandboxInitialized(const std::string& process_type) { 92 // TODO(torne): Adjust linux OOM score here. 93} 94 95int AwMainDelegate::RunProcess( 96 const std::string& process_type, 97 const content::MainFunctionParams& main_function_params) { 98 if (process_type.empty()) { 99 AwBrowserDependencyFactoryImpl::InstallInstance(); 100 101 browser_runner_.reset(content::BrowserMainRunner::Create()); 102 int exit_code = browser_runner_->Initialize(main_function_params); 103 DCHECK(exit_code < 0); 104 105 g_allow_wait_in_ui_thread.Get().reset( 106 new ScopedAllowWaitForLegacyWebViewApi); 107 108 // Return 0 so that we do NOT trigger the default behavior. On Android, the 109 // UI message loop is managed by the Java application. 110 return 0; 111 } 112 113 return -1; 114} 115 116void AwMainDelegate::ProcessExiting(const std::string& process_type) { 117 // TODO(torne): Clean up resources when we handle them. 118 119 logging::CloseLogFile(); 120} 121 122content::ContentBrowserClient* 123 AwMainDelegate::CreateContentBrowserClient() { 124 content_browser_client_.reset(new AwContentBrowserClient(this)); 125 return content_browser_client_.get(); 126} 127 128content::ContentRendererClient* 129 AwMainDelegate::CreateContentRendererClient() { 130 content_renderer_client_.reset(new AwContentRendererClient()); 131 return content_renderer_client_.get(); 132} 133 134scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge( 135 AwBrowserContext* browser_context) { 136 return AwQuotaManagerBridgeImpl::Create(browser_context); 137} 138 139content::GeolocationPermissionContext* 140 AwMainDelegate::CreateGeolocationPermission( 141 AwBrowserContext* browser_context) { 142 return AwGeolocationPermissionContext::Create(browser_context); 143} 144 145content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( 146 content::WebContents* web_contents) { 147 return AwWebContentsViewDelegate::Create(web_contents); 148} 149 150AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() { 151 return new AwWebPreferencesPopulaterImpl(); 152} 153 154} // namespace android_webview 155