aw_main_delegate.cc revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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 "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 24 25namespace android_webview { 26 27namespace { 28 29// TODO(boliu): Remove this global Allow once the underlying issues are 30// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. 31base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > 32 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 33 34} 35 36AwMainDelegate::AwMainDelegate() { 37} 38 39AwMainDelegate::~AwMainDelegate() { 40} 41 42bool AwMainDelegate::BasicStartupComplete(int* exit_code) { 43 content::SetContentClient(&content_client_); 44 45 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl 46 ::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 existing Android View edge effect for overscroll glow. 54 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect); 55 56 return false; 57} 58 59void AwMainDelegate::PreSandboxStartup() { 60 // TODO(torne): When we have a separate renderer process, we need to handle 61 // being passed open FDs for the resource paks here. 62} 63 64void AwMainDelegate::SandboxInitialized(const std::string& process_type) { 65 // TODO(torne): Adjust linux OOM score here. 66} 67 68int AwMainDelegate::RunProcess( 69 const std::string& process_type, 70 const content::MainFunctionParams& main_function_params) { 71 if (process_type.empty()) { 72 AwBrowserDependencyFactoryImpl::InstallInstance(); 73 74 browser_runner_.reset(content::BrowserMainRunner::Create()); 75 int exit_code = browser_runner_->Initialize(main_function_params); 76 DCHECK(exit_code < 0); 77 78 g_allow_wait_in_ui_thread.Get().reset( 79 new ScopedAllowWaitForLegacyWebViewApi); 80 81 // Return 0 so that we do NOT trigger the default behavior. On Android, the 82 // UI message loop is managed by the Java application. 83 return 0; 84 } 85 86 return -1; 87} 88 89void AwMainDelegate::ProcessExiting(const std::string& process_type) { 90 // TODO(torne): Clean up resources when we handle them. 91 92 logging::CloseLogFile(); 93} 94 95content::ContentBrowserClient* 96 AwMainDelegate::CreateContentBrowserClient() { 97 content_browser_client_.reset(new AwContentBrowserClient(this)); 98 return content_browser_client_.get(); 99} 100 101content::ContentRendererClient* 102 AwMainDelegate::CreateContentRendererClient() { 103 content_renderer_client_.reset(new AwContentRendererClient()); 104 return content_renderer_client_.get(); 105} 106 107AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge( 108 AwBrowserContext* browser_context) { 109 return new AwQuotaManagerBridgeImpl(browser_context); 110} 111 112content::GeolocationPermissionContext* 113 AwMainDelegate::CreateGeolocationPermission( 114 AwBrowserContext* browser_context) { 115 return AwGeolocationPermissionContext::Create(browser_context); 116} 117 118content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( 119 content::WebContents* web_contents) { 120 return AwWebContentsViewDelegate::Create(web_contents); 121} 122 123} // namespace android_webview 124