aw_main_delegate.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/common/aw_switches.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/logging.h" 16#include "base/memory/scoped_ptr.h" 17#include "content/public/browser/browser_main_runner.h" 18#include "content/public/browser/browser_thread.h" 19#include "content/public/common/content_switches.h" 20 21namespace android_webview { 22 23AwMainDelegate::AwMainDelegate() { 24} 25 26AwMainDelegate::~AwMainDelegate() { 27} 28 29bool AwMainDelegate::BasicStartupComplete(int* exit_code) { 30 content::SetContentClient(&content_client_); 31 32 CommandLine* command_line = CommandLine::ForCurrentProcess(); 33 // Set the command line to enable synchronous API compatibility. 34 command_line->AppendSwitch(switches::kEnableWebViewSynchronousAPIs); 35 36 return false; 37} 38 39void AwMainDelegate::PreSandboxStartup() { 40 // TODO(torne): When we have a separate renderer process, we need to handle 41 // being passed open FDs for the resource paks here. 42} 43 44void AwMainDelegate::SandboxInitialized(const std::string& process_type) { 45 // TODO(torne): Adjust linux OOM score here. 46} 47 48int AwMainDelegate::RunProcess( 49 const std::string& process_type, 50 const content::MainFunctionParams& main_function_params) { 51 if (process_type.empty()) { 52 AwBrowserDependencyFactoryImpl::InstallInstance(); 53 54 browser_runner_.reset(content::BrowserMainRunner::Create()); 55 int exit_code = browser_runner_->Initialize(main_function_params); 56 DCHECK(exit_code < 0); 57 58 // Return 0 so that we do NOT trigger the default behavior. On Android, the 59 // UI message loop is managed by the Java application. 60 return 0; 61 } 62 63 return -1; 64} 65 66void AwMainDelegate::ProcessExiting(const std::string& process_type) { 67 // TODO(torne): Clean up resources when we handle them. 68 69 logging::CloseLogFile(); 70} 71 72content::ContentBrowserClient* 73 AwMainDelegate::CreateContentBrowserClient() { 74 content_browser_client_.reset(new AwContentBrowserClient(this)); 75 return content_browser_client_.get(); 76} 77 78namespace { 79bool UIAndRendererCompositorThreadsMerged() { 80 return CommandLine::ForCurrentProcess()->HasSwitch( 81 switches::kMergeUIAndRendererCompositorThreads); 82} 83 84MessageLoop* GetRendererCompositorThreadOverrideLoop() { 85 if (!UIAndRendererCompositorThreadsMerged()) 86 return NULL; 87 88 MessageLoop* rv = content::BrowserThread::UnsafeGetMessageLoopForThread( 89 content::BrowserThread::UI); 90 DCHECK(rv); 91 return rv; 92} 93} 94 95content::ContentRendererClient* 96 AwMainDelegate::CreateContentRendererClient() { 97 // Compositor input handling will be performed by the renderer host 98 // when UI and compositor threads are merged, so we disable client compositor 99 // input handling in this case. 100 const bool enable_client_compositor_input_handling = 101 !UIAndRendererCompositorThreadsMerged(); 102 content_renderer_client_.reset( 103 new AwContentRendererClient(&GetRendererCompositorThreadOverrideLoop, 104 enable_client_compositor_input_handling)); 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