aw_main_delegate.cc revision 558790d6acca3451cf3a6b497803a5f07d0bec58
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/scoped_allow_wait_for_legacy_web_view_api.h" 10#include "android_webview/lib/aw_browser_dependency_factory_impl.h" 11#include "android_webview/native/aw_geolocation_permission_context.h" 12#include "android_webview/native/aw_quota_manager_bridge_impl.h" 13#include "android_webview/native/aw_web_contents_view_delegate.h" 14#include "android_webview/renderer/aw_content_renderer_client.h" 15#include "base/command_line.h" 16#include "base/lazy_instance.h" 17#include "base/logging.h" 18#include "base/memory/scoped_ptr.h" 19#include "base/threading/thread_restrictions.h" 20#include "cc/base/switches.h" 21#include "content/public/browser/browser_main_runner.h" 22#include "content/public/browser/browser_thread.h" 23#include "content/public/common/content_switches.h" 24#include "gpu/command_buffer/client/gl_in_process_context.h" 25#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 26 27namespace android_webview { 28 29namespace { 30 31// TODO(boliu): Remove this global Allow once the underlying issues are 32// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. 33base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > 34 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 35 36} 37 38AwMainDelegate::AwMainDelegate() 39 : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) { 40} 41 42AwMainDelegate::~AwMainDelegate() { 43} 44 45bool AwMainDelegate::BasicStartupComplete(int* exit_code) { 46 content::SetContentClient(&content_client_); 47 48 gpu::GLInProcessContext::EnableVirtualizedContext(); 49 gpu::GLInProcessContext::SetGpuMemoryBufferFactory( 50 gpu_memory_buffer_factory_.get()); 51 52 CommandLine* cl = CommandLine::ForCurrentProcess(); 53 cl->AppendSwitch(switches::kEnableBeginFrameScheduling); 54 if (!cl->HasSwitch("disable-map-image")) 55 cl->AppendSwitch(cc::switches::kUseMapImage); 56 57 // WebView uses the Android system's scrollbars and overscroll glow. 58 cl->AppendSwitch(switches::kHideScrollbars); 59 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect); 60 61 return false; 62} 63 64void AwMainDelegate::PreSandboxStartup() { 65 // TODO(torne): When we have a separate renderer process, we need to handle 66 // being passed open FDs for the resource paks here. 67} 68 69void AwMainDelegate::SandboxInitialized(const std::string& process_type) { 70 // TODO(torne): Adjust linux OOM score here. 71} 72 73int AwMainDelegate::RunProcess( 74 const std::string& process_type, 75 const content::MainFunctionParams& main_function_params) { 76 if (process_type.empty()) { 77 AwBrowserDependencyFactoryImpl::InstallInstance(); 78 79 browser_runner_.reset(content::BrowserMainRunner::Create()); 80 int exit_code = browser_runner_->Initialize(main_function_params); 81 DCHECK(exit_code < 0); 82 83 g_allow_wait_in_ui_thread.Get().reset( 84 new ScopedAllowWaitForLegacyWebViewApi); 85 86 // Return 0 so that we do NOT trigger the default behavior. On Android, the 87 // UI message loop is managed by the Java application. 88 return 0; 89 } 90 91 return -1; 92} 93 94void AwMainDelegate::ProcessExiting(const std::string& process_type) { 95 // TODO(torne): Clean up resources when we handle them. 96 97 logging::CloseLogFile(); 98} 99 100content::ContentBrowserClient* 101 AwMainDelegate::CreateContentBrowserClient() { 102 content_browser_client_.reset(new AwContentBrowserClient(this)); 103 return content_browser_client_.get(); 104} 105 106content::ContentRendererClient* 107 AwMainDelegate::CreateContentRendererClient() { 108 content_renderer_client_.reset(new AwContentRendererClient()); 109 return content_renderer_client_.get(); 110} 111 112AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge( 113 AwBrowserContext* browser_context) { 114 return new AwQuotaManagerBridgeImpl(browser_context); 115} 116 117content::GeolocationPermissionContext* 118 AwMainDelegate::CreateGeolocationPermission( 119 AwBrowserContext* browser_context) { 120 return AwGeolocationPermissionContext::Create(browser_context); 121} 122 123content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( 124 content::WebContents* web_contents) { 125 return AwWebContentsViewDelegate::Create(web_contents); 126} 127 128} // namespace android_webview 129