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