[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] | 7d67302a | 2014-05-03 02:17:07 | [diff] [blame] | 8 | #include "android_webview/browser/browser_view_renderer.h" |
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 9 | #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" |
[email protected] | 5d730a3 | 2012-08-23 19:11:23 | [diff] [blame] | 10 | #include "android_webview/lib/aw_browser_dependency_factory_impl.h" |
[email protected] | 63ab505 | 2014-08-04 10:44:11 | [diff] [blame] | 11 | #include "android_webview/native/aw_media_url_interceptor.h" |
[email protected] | 2a3a059 | 2013-02-22 18:53:04 | [diff] [blame] | 12 | #include "android_webview/native/aw_quota_manager_bridge_impl.h" |
[email protected] | ce507cb | 2012-12-11 23:42:22 | [diff] [blame] | 13 | #include "android_webview/native/aw_web_contents_view_delegate.h" |
[email protected] | 9f8797b | 2013-09-27 00:18:13 | [diff] [blame] | 14 | #include "android_webview/native/aw_web_preferences_populater_impl.h" |
[email protected] | 11572b4 | 2014-04-15 16:28:36 | [diff] [blame] | 15 | #include "android_webview/native/external_video_surface_container_impl.h" |
[email protected] | 710b260 | 2012-10-11 21:41:09 | [diff] [blame] | 16 | #include "android_webview/renderer/aw_content_renderer_client.h" |
[email protected] | a6e8c49d | 2012-12-24 13:19:37 | [diff] [blame] | 17 | #include "base/command_line.h" |
[email protected] | 3a23f63c | 2014-04-28 15:33:26 | [diff] [blame] | 18 | #include "base/cpu.h" |
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 19 | #include "base/lazy_instance.h" |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 20 | #include "base/logging.h" |
[email protected] | 86b74e06 | 2012-10-03 01:44:46 | [diff] [blame] | 21 | #include "base/memory/scoped_ptr.h" |
[email protected] | a1811b891 | 2013-05-09 15:35:19 | [diff] [blame] | 22 | #include "base/threading/thread_restrictions.h" |
[email protected] | 63ab505 | 2014-08-04 10:44:11 | [diff] [blame] | 23 | #include "content/browser/media/android/browser_media_player_manager.h" |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 24 | #include "content/public/browser/browser_main_runner.h" |
[email protected] | ea5f70a | 2013-03-07 12:30:36 | [diff] [blame] | 25 | #include "content/public/browser/browser_thread.h" |
[email protected] | a6e8c49d | 2012-12-24 13:19:37 | [diff] [blame] | 26 | #include "content/public/common/content_switches.h" |
[email protected] | d7cf393 | 2013-06-26 04:08:04 | [diff] [blame] | 27 | #include "gpu/command_buffer/client/gl_in_process_context.h" |
sievers | b727d53 | 2014-10-24 19:11:34 | [diff] [blame] | 28 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | 8b4efe9 | 2014-02-21 16:08:20 | [diff] [blame] | 29 | #include "media/base/media_switches.h" |
[email protected] | 1fb9e7e | 2013-05-26 03:23:48 | [diff] [blame] | 30 | #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 31 | |
32 | namespace android_webview { | ||||
33 | |||||
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 34 | namespace { |
35 | |||||
[email protected] | 0d66d7e | 2013-06-13 17:44:32 | [diff] [blame] | 36 | // TODO(boliu): Remove this global Allow once the underlying issues are |
[email protected] | 1d0a6b8 | 2013-05-16 09:03:11 | [diff] [blame] | 37 | // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below. |
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 38 | base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> > |
39 | g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER; | ||||
40 | |||||
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 41 | } |
42 | |||||
reveman | ec103f0 | 2014-09-29 19:12:31 | [diff] [blame] | 43 | AwMainDelegate::AwMainDelegate() { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 44 | } |
45 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 46 | AwMainDelegate::~AwMainDelegate() { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 47 | } |
48 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 49 | bool AwMainDelegate::BasicStartupComplete(int* exit_code) { |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 50 | content::SetContentClient(&content_client_); |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 51 | |
[email protected] | 63ab505 | 2014-08-04 10:44:11 | [diff] [blame] | 52 | content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor( |
53 | new AwMediaUrlInterceptor()); | ||||
54 | |||||
reveman | ec103f0 | 2014-09-29 19:12:31 | [diff] [blame] | 55 | BrowserViewRenderer::CalculateTileMemoryPolicy(); |
[email protected] | 0552c8e | 2013-09-10 22:44:43 | [diff] [blame] | 56 | |
pgal.u-szeged | 929d45a9 | 2014-10-28 11:50:41 | [diff] [blame^] | 57 | base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
[email protected] | 0d66d7e | 2013-06-13 17:44:32 | [diff] [blame] | 58 | cl->AppendSwitch(switches::kEnableBeginFrameScheduling); |
[email protected] | a23530d | 2014-03-11 06:04:14 | [diff] [blame] | 59 | cl->AppendSwitch(switches::kEnableImplSidePainting); |
[email protected] | 6c238533 | 2013-05-21 00:05:06 | [diff] [blame] | 60 | |
[email protected] | 14f29f0 | 2013-07-17 02:09:08 | [diff] [blame] | 61 | // WebView uses the Android system's scrollbars and overscroll glow. |
[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] | 0e176fa | 2013-09-11 14:07:14 | [diff] [blame] | 65 | cl->AppendSwitch(switches::kDisableSharedWorkers); |
[email protected] | c660d46f | 2013-08-05 22:40:59 | [diff] [blame] | 66 | |
[email protected] | 047fcf7 | 2013-09-09 11:03:32 | [diff] [blame] | 67 | // File system API not supported (requires some new API; internal bug 6930981) |
[email protected] | 0e176fa | 2013-09-11 14:07:14 | [diff] [blame] | 68 | cl->AppendSwitch(switches::kDisableFileSystem); |
[email protected] | 047fcf7 | 2013-09-09 11:03:32 | [diff] [blame] | 69 | |
igsolla | ec9b886 | 2014-09-25 17:46:23 | [diff] [blame] | 70 | // For fullscreen video we create a new container view to host the |
71 | // WebContents, ie. the FullscreenView. As a result we cannot reuse the | ||||
72 | // embedded video blocker attached to the old container view, so we create a | ||||
73 | // new blocker instead attached to the ContentVideoView. | ||||
74 | cl->AppendSwitch(switches::kEnableContentVideoViewPowerSaveBlocker); | ||||
75 | |||||
[email protected] | 8b4efe9 | 2014-02-21 16:08:20 | [diff] [blame] | 76 | #if defined(VIDEO_HOLE) |
77 | // Support EME/L1 with hole-punching. | ||||
78 | cl->AppendSwitch(switches::kMediaDrmEnableNonCompositing); | ||||
79 | #endif | ||||
[email protected] | 846c0c1 | 2014-06-04 23:07:07 | [diff] [blame] | 80 | |
81 | // WebRTC hardware decoding is not supported, internal bug 15075307 | ||||
82 | cl->AppendSwitch(switches::kDisableWebRtcHWDecoding); | ||||
[email protected] | 8a59280 | 2014-07-02 07:31:33 | [diff] [blame] | 83 | |
sievers | b727d53 | 2014-10-24 19:11:34 | [diff] [blame] | 84 | // This is needed for sharing textures across the different GL threads. |
85 | cl->AppendSwitch(switches::kEnableThreadedTextureMailboxes); | ||||
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 86 | return false; |
87 | } | ||||
88 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 89 | void AwMainDelegate::PreSandboxStartup() { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 90 | // TODO(torne): When we have a separate renderer process, we need to handle |
91 | // being passed open FDs for the resource paks here. | ||||
[email protected] | 3a23f63c | 2014-04-28 15:33:26 | [diff] [blame] | 92 | #if defined(ARCH_CPU_ARM_FAMILY) |
93 | // Create an instance of the CPU class to parse /proc/cpuinfo and cache | ||||
94 | // cpu_brand info. | ||||
95 | base::CPU cpu_info; | ||||
96 | #endif | ||||
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 97 | } |
98 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 99 | void AwMainDelegate::SandboxInitialized(const std::string& process_type) { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 100 | // TODO(torne): Adjust linux OOM score here. |
101 | } | ||||
102 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 103 | int AwMainDelegate::RunProcess( |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 104 | const std::string& process_type, |
105 | const content::MainFunctionParams& main_function_params) { | ||||
106 | if (process_type.empty()) { | ||||
[email protected] | 5d730a3 | 2012-08-23 19:11:23 | [diff] [blame] | 107 | AwBrowserDependencyFactoryImpl::InstallInstance(); |
108 | |||||
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 109 | browser_runner_.reset(content::BrowserMainRunner::Create()); |
110 | int exit_code = browser_runner_->Initialize(main_function_params); | ||||
boliu | 2d46b52 | 2014-08-29 22:33:44 | [diff] [blame] | 111 | DCHECK_LT(exit_code, 0); |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 112 | |
[email protected] | 0d66d7e | 2013-06-13 17:44:32 | [diff] [blame] | 113 | g_allow_wait_in_ui_thread.Get().reset( |
114 | new ScopedAllowWaitForLegacyWebViewApi); | ||||
[email protected] | 9a50bf9 | 2013-05-09 05:39:51 | [diff] [blame] | 115 | |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 116 | // Return 0 so that we do NOT trigger the default behavior. On Android, the |
117 | // UI message loop is managed by the Java application. | ||||
118 | return 0; | ||||
119 | } | ||||
120 | |||||
121 | return -1; | ||||
122 | } | ||||
123 | |||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 124 | void AwMainDelegate::ProcessExiting(const std::string& process_type) { |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 125 | // TODO(torne): Clean up resources when we handle them. |
126 | |||||
127 | logging::CloseLogFile(); | ||||
128 | } | ||||
129 | |||||
130 | content::ContentBrowserClient* | ||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 131 | AwMainDelegate::CreateContentBrowserClient() { |
[email protected] | 2a3a059 | 2013-02-22 18:53:04 | [diff] [blame] | 132 | content_browser_client_.reset(new AwContentBrowserClient(this)); |
[email protected] | ce507cb | 2012-12-11 23:42:22 | [diff] [blame] | 133 | return content_browser_client_.get(); |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 134 | } |
135 | |||||
136 | content::ContentRendererClient* | ||||
[email protected] | c1a47df | 2012-08-30 00:29:56 | [diff] [blame] | 137 | AwMainDelegate::CreateContentRendererClient() { |
[email protected] | 913d99a | 2013-05-31 07:16:07 | [diff] [blame] | 138 | content_renderer_client_.reset(new AwContentRendererClient()); |
[email protected] | ce507cb | 2012-12-11 23:42:22 | [diff] [blame] | 139 | return content_renderer_client_.get(); |
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 140 | } |
141 | |||||
[email protected] | 1a64c31 | 2013-10-08 12:56:26 | [diff] [blame] | 142 | scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge( |
[email protected] | 2a3a059 | 2013-02-22 18:53:04 | [diff] [blame] | 143 | AwBrowserContext* browser_context) { |
[email protected] | 1a64c31 | 2013-10-08 12:56:26 | [diff] [blame] | 144 | return AwQuotaManagerBridgeImpl::Create(browser_context); |
[email protected] | 2a3a059 | 2013-02-22 18:53:04 | [diff] [blame] | 145 | } |
146 | |||||
[email protected] | 2a3a059 | 2013-02-22 18:53:04 | [diff] [blame] | 147 | content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( |
148 | content::WebContents* web_contents) { | ||||
149 | return AwWebContentsViewDelegate::Create(web_contents); | ||||
150 | } | ||||
151 | |||||
[email protected] | 9f8797b | 2013-09-27 00:18:13 | [diff] [blame] | 152 | AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() { |
153 | return new AwWebPreferencesPopulaterImpl(); | ||||
154 | } | ||||
155 | |||||
[email protected] | 11572b4 | 2014-04-15 16:28:36 | [diff] [blame] | 156 | #if defined(VIDEO_HOLE) |
157 | content::ExternalVideoSurfaceContainer* | ||||
158 | AwMainDelegate::CreateExternalVideoSurfaceContainer( | ||||
159 | content::WebContents* web_contents) { | ||||
160 | return new ExternalVideoSurfaceContainerImpl(web_contents); | ||||
161 | } | ||||
162 | #endif | ||||
163 | |||||
[email protected] | 878aa82 | 2012-08-09 10:55:04 | [diff] [blame] | 164 | } // namespace android_webview |