blob: 83cd27d876d00a18ee3448bc444db7960425bcac [file] [log] [blame]
[email protected]878aa822012-08-09 10:55:041// 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
[email protected]c1a47df2012-08-30 00:29:565#include "android_webview/lib/main/aw_main_delegate.h"
[email protected]878aa822012-08-09 10:55:046
[email protected]f81fa202012-10-25 23:32:287#include "android_webview/browser/aw_content_browser_client.h"
[email protected]b80a63b2013-07-28 20:09:138#include "android_webview/browser/gpu_memory_buffer_factory_impl.h"
[email protected]0552c8e2013-09-10 22:44:439#include "android_webview/browser/in_process_view_renderer.h"
[email protected]9a50bf92013-05-09 05:39:5110#include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
[email protected]5d730a32012-08-23 19:11:2311#include "android_webview/lib/aw_browser_dependency_factory_impl.h"
[email protected]4230ed92013-01-10 05:51:4212#include "android_webview/native/aw_geolocation_permission_context.h"
[email protected]2a3a0592013-02-22 18:53:0413#include "android_webview/native/aw_quota_manager_bridge_impl.h"
[email protected]ce507cb2012-12-11 23:42:2214#include "android_webview/native/aw_web_contents_view_delegate.h"
[email protected]710b2602012-10-11 21:41:0915#include "android_webview/renderer/aw_content_renderer_client.h"
[email protected]a6e8c49d2012-12-24 13:19:3716#include "base/command_line.h"
[email protected]9a50bf92013-05-09 05:39:5117#include "base/lazy_instance.h"
[email protected]878aa822012-08-09 10:55:0418#include "base/logging.h"
[email protected]86b74e062012-10-03 01:44:4619#include "base/memory/scoped_ptr.h"
[email protected]a1811b8912013-05-09 15:35:1920#include "base/threading/thread_restrictions.h"
[email protected]1d0a6b82013-05-16 09:03:1121#include "cc/base/switches.h"
[email protected]878aa822012-08-09 10:55:0422#include "content/public/browser/browser_main_runner.h"
[email protected]ea5f70a2013-03-07 12:30:3623#include "content/public/browser/browser_thread.h"
[email protected]a6e8c49d2012-12-24 13:19:3724#include "content/public/common/content_switches.h"
[email protected]d7cf3932013-06-26 04:08:0425#include "gpu/command_buffer/client/gl_in_process_context.h"
[email protected]92dd77772013-08-01 23:57:5626#include "gpu/command_buffer/service/in_process_command_buffer.h"
[email protected]1fb9e7e2013-05-26 03:23:4827#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
[email protected]878aa822012-08-09 10:55:0428
29namespace android_webview {
30
[email protected]9a50bf92013-05-09 05:39:5131namespace {
32
[email protected]0d66d7e2013-06-13 17:44:3233// TODO(boliu): Remove this global Allow once the underlying issues are
[email protected]1d0a6b82013-05-16 09:03:1134// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
[email protected]9a50bf92013-05-09 05:39:5135base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
36 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
37
[email protected]9a50bf92013-05-09 05:39:5138}
39
[email protected]b80a63b2013-07-28 20:09:1340AwMainDelegate::AwMainDelegate()
41 : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) {
[email protected]878aa822012-08-09 10:55:0442}
43
[email protected]c1a47df2012-08-30 00:29:5644AwMainDelegate::~AwMainDelegate() {
[email protected]878aa822012-08-09 10:55:0445}
46
[email protected]c1a47df2012-08-30 00:29:5647bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
[email protected]9b57401b2012-10-10 16:01:4748 content::SetContentClient(&content_client_);
[email protected]878aa822012-08-09 10:55:0449
[email protected]bac37fd32013-08-16 17:31:0050 gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory(
[email protected]b80a63b2013-07-28 20:09:1351 gpu_memory_buffer_factory_.get());
[email protected]92dd77772013-08-01 23:57:5652 gpu::InProcessCommandBuffer::EnableVirtualizedContext();
[email protected]cd3464972013-05-06 18:06:5653
[email protected]0552c8e2013-09-10 22:44:4354 InProcessViewRenderer::CalculateTileMemoryPolicy();
55
[email protected]eeb93112013-05-01 19:41:1056 CommandLine* cl = CommandLine::ForCurrentProcess();
[email protected]0d66d7e2013-06-13 17:44:3257 cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
[email protected]be2e40a2013-08-27 02:49:2058 cl->AppendSwitch(cc::switches::kEnableMapImage);
[email protected]6c2385332013-05-21 00:05:0659
[email protected]14f29f02013-07-17 02:09:0860 // WebView uses the Android system's scrollbars and overscroll glow.
61 cl->AppendSwitch(switches::kHideScrollbars);
[email protected]6c2385332013-05-21 00:05:0662 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
63
[email protected]0e176fa2013-09-11 14:07:1464 // Not yet supported in single-process mode.
[email protected]c660d46f2013-08-05 22:40:5965 cl->AppendSwitch(switches::kDisableExperimentalWebGL);
[email protected]0e176fa2013-09-11 14:07:1466 cl->AppendSwitch(switches::kDisableSharedWorkers);
[email protected]c660d46f2013-08-05 22:40:5967
[email protected]055137232013-08-20 09:56:4968 // Ganesh backed 2D-Canvas is not yet working and causes crashes.
69 cl->AppendSwitch(switches::kDisableAccelerated2dCanvas);
70
[email protected]047fcf72013-09-09 11:03:3271 // File system API not supported (requires some new API; internal bug 6930981)
[email protected]0e176fa2013-09-11 14:07:1472 cl->AppendSwitch(switches::kDisableFileSystem);
[email protected]047fcf72013-09-09 11:03:3273
74 // Enable D-PAD navigation for application compatibility.
[email protected]0e176fa2013-09-11 14:07:1475 cl->AppendSwitch(switches::kEnableSpatialNavigation);
[email protected]047fcf72013-09-09 11:03:3276
[email protected]878aa822012-08-09 10:55:0477 return false;
78}
79
[email protected]c1a47df2012-08-30 00:29:5680void AwMainDelegate::PreSandboxStartup() {
[email protected]878aa822012-08-09 10:55:0481 // TODO(torne): When we have a separate renderer process, we need to handle
82 // being passed open FDs for the resource paks here.
83}
84
[email protected]c1a47df2012-08-30 00:29:5685void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
[email protected]878aa822012-08-09 10:55:0486 // TODO(torne): Adjust linux OOM score here.
87}
88
[email protected]c1a47df2012-08-30 00:29:5689int AwMainDelegate::RunProcess(
[email protected]878aa822012-08-09 10:55:0490 const std::string& process_type,
91 const content::MainFunctionParams& main_function_params) {
92 if (process_type.empty()) {
[email protected]5d730a32012-08-23 19:11:2393 AwBrowserDependencyFactoryImpl::InstallInstance();
94
[email protected]878aa822012-08-09 10:55:0495 browser_runner_.reset(content::BrowserMainRunner::Create());
96 int exit_code = browser_runner_->Initialize(main_function_params);
97 DCHECK(exit_code < 0);
98
[email protected]0d66d7e2013-06-13 17:44:3299 g_allow_wait_in_ui_thread.Get().reset(
100 new ScopedAllowWaitForLegacyWebViewApi);
[email protected]9a50bf92013-05-09 05:39:51101
[email protected]878aa822012-08-09 10:55:04102 // Return 0 so that we do NOT trigger the default behavior. On Android, the
103 // UI message loop is managed by the Java application.
104 return 0;
105 }
106
107 return -1;
108}
109
[email protected]c1a47df2012-08-30 00:29:56110void AwMainDelegate::ProcessExiting(const std::string& process_type) {
[email protected]878aa822012-08-09 10:55:04111 // TODO(torne): Clean up resources when we handle them.
112
113 logging::CloseLogFile();
114}
115
116content::ContentBrowserClient*
[email protected]c1a47df2012-08-30 00:29:56117 AwMainDelegate::CreateContentBrowserClient() {
[email protected]2a3a0592013-02-22 18:53:04118 content_browser_client_.reset(new AwContentBrowserClient(this));
[email protected]ce507cb2012-12-11 23:42:22119 return content_browser_client_.get();
[email protected]878aa822012-08-09 10:55:04120}
121
122content::ContentRendererClient*
[email protected]c1a47df2012-08-30 00:29:56123 AwMainDelegate::CreateContentRendererClient() {
[email protected]913d99a2013-05-31 07:16:07124 content_renderer_client_.reset(new AwContentRendererClient());
[email protected]ce507cb2012-12-11 23:42:22125 return content_renderer_client_.get();
[email protected]878aa822012-08-09 10:55:04126}
127
[email protected]2a3a0592013-02-22 18:53:04128AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge(
129 AwBrowserContext* browser_context) {
130 return new AwQuotaManagerBridgeImpl(browser_context);
131}
132
133content::GeolocationPermissionContext*
134 AwMainDelegate::CreateGeolocationPermission(
135 AwBrowserContext* browser_context) {
136 return AwGeolocationPermissionContext::Create(browser_context);
137}
138
139content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
140 content::WebContents* web_contents) {
141 return AwWebContentsViewDelegate::Create(web_contents);
142}
143
[email protected]878aa822012-08-09 10:55:04144} // namespace android_webview