[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 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 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 5 | #include "android_webview/lib/main/aw_main_delegate.h" |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 6 | |
[email protected] | f81fa20 | 2012-10-25 23:32:28 | [diff] [blame] | 7 | #include "android_webview/browser/aw_content_browser_client.h" |
[email protected] | b80a63b | 2013-07-28 20:09:13 | [diff] [blame] | 8 | #include "android_webview/browser/gpu_memory_buffer_factory_impl.h" |
[email protected] | 0552c8e | 2013-09-10 22:44:43 | [diff] [blame] | 9 | #include "android_webview/browser/in_process_view_renderer.h" |
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 10 | #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" |
[email protected] | 5d730a3 | 2012-08-23 19:11:23 | [diff] [blame] | 11 | #include "android_webview/lib/aw_browser_dependency_factory_impl.h" |
[email protected] | 4230ed9 | 2013-01-10 05:51:42 | [diff] [blame] | 12 | #include "android_webview/native/aw_geolocation_permission_context.h" |
[email protected] | 2a3a059 | 2013-02-22 18:53:04 | [diff] [blame] | 13 | #include "android_webview/native/aw_quota_manager_bridge_impl.h" |
[email protected] | ce507cb | 2012-12-11 23:42:22 | [diff] [blame] | 14 | #include "android_webview/native/aw_web_contents_view_delegate.h" |
[email protected] | 710b260 | 2012-10-11 21:41:09 | [diff] [blame] | 15 | #include "android_webview/renderer/aw_content_renderer_client.h" |
[email protected] | a6e8c49d | 2012-12-24 13:19:37 | [diff] [blame] | 16 | #include "base/command_line.h" |
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 17 | #include "base/lazy_instance.h" |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 18 | #include "base/logging.h" |
[email protected] | 86b74e06 | 2012-10-03 01:44:46 | [diff] [blame] | 19 | #include "base/memory/scoped_ptr.h" |
[email protected] | a1811b891 | 2013-05-09 15:35:19 | [diff] [blame] | 20 | #include "base/threading/thread_restrictions.h" |
[email protected] | 1d0a6b8 | 2013-05-16 09:03:11 | [diff] [blame] | 21 | #include "cc/base/switches.h" |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 22 | #include "content/public/browser/browser_main_runner.h" |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 23 | #include "content/public/browser/browser_thread.h" |
[email protected] | a6e8c49d | 2012-12-24 13:19:37 | [diff] [blame] | 24 | #include "content/public/common/content_switches.h" |
[email protected] | d7cf393 | 2013-06-26 04:08:04 | [diff] [blame] | 25 | #include "gpu/command_buffer/client/gl_in_process_context.h" |
[email protected] | 92dd7777 | 2013-08-01 23:57:56 | [diff] [blame] | 26 | #include "gpu/command_buffer/service/in_process_command_buffer.h" |
[email protected] | 1fb9e7e | 2013-05-26 03:23:48 | [diff] [blame] | 27 | #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 28 | |
29 | namespace android_webview { | ||||
30 | |||||
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 31 | namespace { |
32 | |||||
[email protected] | 0d66d7e | 2013-06-13 17:44:32 | [diff] [blame] | 33 | // TODO(boliu): Remove this global Allow once the underlying issues are |
[email protected] | 1d0a6b8 | 2013-05-16 09:03:11 | [diff] [blame] | 34 | // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. |
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 35 | base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > |
36 | g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; | ||||
37 | |||||
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 38 | } |
39 | |||||
[email protected] | b80a63b | 2013-07-28 20:09:13 | [diff] [blame] | 40 | AwMainDelegate::AwMainDelegate() |
41 | : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) { | ||||
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 42 | } |
43 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 44 | AwMainDelegate::~AwMainDelegate() { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 45 | } |
46 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 47 | bool AwMainDelegate::BasicStartupComplete(int* exit_code) { |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 48 | content::SetContentClient(&content_client_); |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 49 | |
[email protected] | bac37fd3 | 2013-08-16 17:31:00 | [diff] [blame] | 50 | gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory( |
[email protected] | b80a63b | 2013-07-28 20:09:13 | [diff] [blame] | 51 | gpu_memory_buffer_factory_.get()); |
[email protected] | 92dd7777 | 2013-08-01 23:57:56 | [diff] [blame] | 52 | gpu::InProcessCommandBuffer::EnableVirtualizedContext(); |
[email protected] | cd346497 | 2013-05-06 18:06:56 | [diff] [blame] | 53 | |
[email protected] | 0552c8e | 2013-09-10 22:44:43 | [diff] [blame] | 54 | InProcessViewRenderer::CalculateTileMemoryPolicy(); |
55 | |||||
[email protected] | eeb9311 | 2013-05-01 19:41:10 | [diff] [blame] | 56 | CommandLine* cl = CommandLine::ForCurrentProcess(); |
[email protected] | 0d66d7e | 2013-06-13 17:44:32 | [diff] [blame] | 57 | cl->AppendSwitch(switches::kEnableBeginFrameScheduling); |
[email protected] | be2e40a | 2013-08-27 02:49:20 | [diff] [blame] | 58 | cl->AppendSwitch(cc::switches::kEnableMapImage); |
[email protected] | 6c238533 | 2013-05-21 00:05:06 | [diff] [blame] | 59 | |
[email protected] | 14f29f0 | 2013-07-17 02:09:08 | [diff] [blame] | 60 | // WebView uses the Android system's scrollbars and overscroll glow. |
61 | cl->AppendSwitch(switches::kHideScrollbars); | ||||
[email protected] | 6c238533 | 2013-05-21 00:05:06 | [diff] [blame] | 62 | cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect); |
63 | |||||
[email protected] | 0e176fa | 2013-09-11 14:07:14 | [diff] [blame] | 64 | // Not yet supported in single-process mode. |
[email protected] | c660d46f | 2013-08-05 22:40:59 | [diff] [blame] | 65 | cl->AppendSwitch(switches::kDisableExperimentalWebGL); |
[email protected] | 0e176fa | 2013-09-11 14:07:14 | [diff] [blame] | 66 | cl->AppendSwitch(switches::kDisableSharedWorkers); |
[email protected] | c660d46f | 2013-08-05 22:40:59 | [diff] [blame] | 67 | |
[email protected] | 05513723 | 2013-08-20 09:56:49 | [diff] [blame] | 68 | // Ganesh backed 2D-Canvas is not yet working and causes crashes. |
69 | cl->AppendSwitch(switches::kDisableAccelerated2dCanvas); | ||||
70 | |||||
[email protected] | 047fcf7 | 2013-09-09 11:03:32 | [diff] [blame] | 71 | // File system API not supported (requires some new API; internal bug 6930981) |
[email protected] | 0e176fa | 2013-09-11 14:07:14 | [diff] [blame] | 72 | cl->AppendSwitch(switches::kDisableFileSystem); |
[email protected] | 047fcf7 | 2013-09-09 11:03:32 | [diff] [blame] | 73 | |
74 | // Enable D-PAD navigation for application compatibility. | ||||
[email protected] | 0e176fa | 2013-09-11 14:07:14 | [diff] [blame] | 75 | cl->AppendSwitch(switches::kEnableSpatialNavigation); |
[email protected] | 047fcf7 | 2013-09-09 11:03:32 | [diff] [blame] | 76 | |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 77 | return false; |
78 | } | ||||
79 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 80 | void AwMainDelegate::PreSandboxStartup() { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 81 | // 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] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 85 | void AwMainDelegate::SandboxInitialized(const std::string& process_type) { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 86 | // TODO(torne): Adjust linux OOM score here. |
87 | } | ||||
88 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 89 | int AwMainDelegate::RunProcess( |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 90 | const std::string& process_type, |
91 | const content::MainFunctionParams& main_function_params) { | ||||
92 | if (process_type.empty()) { | ||||
[email protected] | 5d730a3 | 2012-08-23 19:11:23 | [diff] [blame] | 93 | AwBrowserDependencyFactoryImpl::InstallInstance(); |
94 | |||||
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 95 | browser_runner_.reset(content::BrowserMainRunner::Create()); |
96 | int exit_code = browser_runner_->Initialize(main_function_params); | ||||
97 | DCHECK(exit_code < 0); | ||||
98 | |||||
[email protected] | 0d66d7e | 2013-06-13 17:44:32 | [diff] [blame] | 99 | g_allow_wait_in_ui_thread.Get().reset( |
100 | new ScopedAllowWaitForLegacyWebViewApi); | ||||
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 101 | |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 102 | // 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] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 110 | void AwMainDelegate::ProcessExiting(const std::string& process_type) { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 111 | // TODO(torne): Clean up resources when we handle them. |
112 | |||||
113 | logging::CloseLogFile(); | ||||
114 | } | ||||
115 | |||||
116 | content::ContentBrowserClient* | ||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 117 | AwMainDelegate::CreateContentBrowserClient() { |
[email protected] | 2a3a059 | 2013-02-22 18:53:04 | [diff] [blame] | 118 | content_browser_client_.reset(new AwContentBrowserClient(this)); |
[email protected] | ce507cb | 2012-12-11 23:42:22 | [diff] [blame] | 119 | return content_browser_client_.get(); |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 120 | } |
121 | |||||
122 | content::ContentRendererClient* | ||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 123 | AwMainDelegate::CreateContentRendererClient() { |
[email protected] | 913d99a | 2013-05-31 07:16:07 | [diff] [blame] | 124 | content_renderer_client_.reset(new AwContentRendererClient()); |
[email protected] | ce507cb | 2012-12-11 23:42:22 | [diff] [blame] | 125 | return content_renderer_client_.get(); |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 126 | } |
127 | |||||
[email protected] | 2a3a059 | 2013-02-22 18:53:04 | [diff] [blame] | 128 | AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge( |
129 | AwBrowserContext* browser_context) { | ||||
130 | return new AwQuotaManagerBridgeImpl(browser_context); | ||||
131 | } | ||||
132 | |||||
133 | content::GeolocationPermissionContext* | ||||
134 | AwMainDelegate::CreateGeolocationPermission( | ||||
135 | AwBrowserContext* browser_context) { | ||||
136 | return AwGeolocationPermissionContext::Create(browser_context); | ||||
137 | } | ||||
138 | |||||
139 | content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( | ||||
140 | content::WebContents* web_contents) { | ||||
141 | return AwWebContentsViewDelegate::Create(web_contents); | ||||
142 | } | ||||
143 | |||||
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 144 | } // namespace android_webview |