aw_main_delegate.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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/in_process_renderer/in_process_renderer_client.h" 9#include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" 10#include "android_webview/common/aw_switches.h" 11#include "android_webview/lib/aw_browser_dependency_factory_impl.h" 12#include "android_webview/native/aw_geolocation_permission_context.h" 13#include "android_webview/native/aw_quota_manager_bridge_impl.h" 14#include "android_webview/native/aw_web_contents_view_delegate.h" 15#include "android_webview/renderer/aw_content_renderer_client.h" 16#include "base/command_line.h" 17#include "base/lazy_instance.h" 18#include "base/logging.h" 19#include "base/memory/scoped_ptr.h" 20#include "base/threading/thread_restrictions.h" 21#include "cc/base/switches.h" 22#include "content/public/browser/browser_main_runner.h" 23#include "content/public/browser/browser_thread.h" 24#include "content/public/common/content_switches.h" 25#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 26 27namespace android_webview { 28 29namespace { 30 31// TODO(boliu): Remove these global Allows once the underlying issues are 32// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. 33 34base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > 35 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 36 37base::LazyInstance<scoped_ptr<base::ThreadRestrictions::ScopedAllowIO> > 38 g_allow_io_in_ui_thread = LAZY_INSTANCE_INITIALIZER; 39 40bool UIAndRendererCompositorThreadsNotMerged() { 41 return CommandLine::ForCurrentProcess()->HasSwitch( 42 switches::kNoMergeUIAndRendererCompositorThreads); 43} 44} 45 46AwMainDelegate::AwMainDelegate() { 47} 48 49AwMainDelegate::~AwMainDelegate() { 50} 51 52bool AwMainDelegate::BasicStartupComplete(int* exit_code) { 53 content::SetContentClient(&content_client_); 54 55 webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl 56 ::EnableVirtualizedContext(); 57 58 CommandLine* cl = CommandLine::ForCurrentProcess(); 59 if (UIAndRendererCompositorThreadsNotMerged()) { 60 cl->AppendSwitch(cc::switches::kEnableCompositorFrameMessage); 61 cl->AppendSwitch(switches::kEnableWebViewSynchronousAPIs); 62 } else { 63 cl->AppendSwitch(switches::kEnableSynchronousRendererCompositor); 64 cl->AppendSwitch(switches::kEnableVsyncNotification); 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 // None of this makes sense for multiprocess. 127 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)); 128 // During transition period allow running in either threading mode; eventually 129 // only the compositor/UI thread merge mode will be supported. 130 const bool no_merge_threads = UIAndRendererCompositorThreadsNotMerged(); 131 content_renderer_client_.reset( 132 no_merge_threads ? new AwContentRendererClient() : 133 new InProcessRendererClient()); 134 return content_renderer_client_.get(); 135} 136 137AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge( 138 AwBrowserContext* browser_context) { 139 return new AwQuotaManagerBridgeImpl(browser_context); 140} 141 142content::GeolocationPermissionContext* 143 AwMainDelegate::CreateGeolocationPermission( 144 AwBrowserContext* browser_context) { 145 return AwGeolocationPermissionContext::Create(browser_context); 146} 147 148content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( 149 content::WebContents* web_contents) { 150 return AwWebContentsViewDelegate::Create(web_contents); 151} 152 153} // namespace android_webview 154