aw_main_delegate.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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/common/aw_switches.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 "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 25 26namespace android_webview { 27 28namespace { 29 30// TODO(boliu): Remove these global Allows once the underlying issues are 31// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. 32 33base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > 34 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 35 36base::LazyInstance<scoped_ptr<base::ThreadRestrictions::ScopedAllowIO> > 37 g_allow_io_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 38 39bool UIAndRendererCompositorThreadsNotMerged() { 40 return CommandLine::ForCurrentProcess()->HasSwitch( 41 switches::kNoMergeUIAndRendererCompositorThreads); 42} 43} 44 45AwMainDelegate::AwMainDelegate() { 46} 47 48AwMainDelegate::~AwMainDelegate() { 49} 50 51bool AwMainDelegate::BasicStartupComplete(int* exit_code) { 52 content::SetContentClient(&content_client_); 53 54 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl 55 ::EnableVirtualizedContext(); 56 57 CommandLine* cl = CommandLine::ForCurrentProcess(); 58 if (UIAndRendererCompositorThreadsNotMerged()) { 59 cl->AppendSwitch(cc::switches::kEnableCompositorFrameMessage); 60 cl->AppendSwitch(switches::kEnableWebViewSynchronousAPIs); 61 } else { 62 cl->AppendSwitch(switches::kEnableBeginFrameScheduling); 63 if (!cl->HasSwitch("disable-map-image")) 64 cl->AppendSwitch(cc::switches::kUseMapImage); 65 } 66 67 // WebView uses the existing Android View edge effect for overscroll glow. 68 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect); 69 70 return false; 71} 72 73void AwMainDelegate::PreSandboxStartup() { 74 // TODO(torne): When we have a separate renderer process, we need to handle 75 // being passed open FDs for the resource paks here. 76} 77 78void AwMainDelegate::SandboxInitialized(const std::string& process_type) { 79 // TODO(torne): Adjust linux OOM score here. 80} 81 82int AwMainDelegate::RunProcess( 83 const std::string& process_type, 84 const content::MainFunctionParams& main_function_params) { 85 if (process_type.empty()) { 86 AwBrowserDependencyFactoryImpl::InstallInstance(); 87 88 browser_runner_.reset(content::BrowserMainRunner::Create()); 89 int exit_code = browser_runner_->Initialize(main_function_params); 90 DCHECK(exit_code < 0); 91 92 if (!UIAndRendererCompositorThreadsNotMerged()) { 93 // This is temporary until we remove the browser compositor 94 g_allow_wait_in_ui_thread.Get().reset( 95 new ScopedAllowWaitForLegacyWebViewApi); 96 97 // TODO(boliu): This is a HUGE hack to work around the fact that 98 // cc::WorkerPool joins on worker threads on the UI thread. 99 // See crbug.com/239423. 100 g_allow_io_in_ui_thread.Get().reset( 101 new base::ThreadRestrictions::ScopedAllowIO); 102 } 103 104 // Return 0 so that we do NOT trigger the default behavior. On Android, the 105 // UI message loop is managed by the Java application. 106 return 0; 107 } 108 109 return -1; 110} 111 112void AwMainDelegate::ProcessExiting(const std::string& process_type) { 113 // TODO(torne): Clean up resources when we handle them. 114 115 logging::CloseLogFile(); 116} 117 118content::ContentBrowserClient* 119 AwMainDelegate::CreateContentBrowserClient() { 120 content_browser_client_.reset(new AwContentBrowserClient(this)); 121 return content_browser_client_.get(); 122} 123 124content::ContentRendererClient* 125 AwMainDelegate::CreateContentRendererClient() { 126 content_renderer_client_.reset(new AwContentRendererClient()); 127 return content_renderer_client_.get(); 128} 129 130AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge( 131 AwBrowserContext* browser_context) { 132 return new AwQuotaManagerBridgeImpl(browser_context); 133} 134 135content::GeolocationPermissionContext* 136 AwMainDelegate::CreateGeolocationPermission( 137 AwBrowserContext* browser_context) { 138 return AwGeolocationPermissionContext::Create(browser_context); 139} 140 141content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( 142 content::WebContents* web_contents) { 143 return AwWebContentsViewDelegate::Create(web_contents); 144} 145 146} // namespace android_webview 147