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.
5 #include "android_webview/lib/main/aw_main_delegate.h"
7 #include "android_webview/browser/aw_content_browser_client.h"
8 #include "android_webview/browser/browser_view_renderer.h"
9 #include "android_webview/browser/gpu_memory_buffer_factory_impl.h"
10 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
11 #include "android_webview/lib/aw_browser_dependency_factory_impl.h"
12 #include "android_webview/native/aw_media_url_interceptor.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/native/aw_web_preferences_populater_impl.h"
16 #include "android_webview/native/external_video_surface_container_impl.h"
17 #include "android_webview/renderer/aw_content_renderer_client.h"
18 #include "base/command_line.h"
20 #include "base/lazy_instance.h"
21 #include "base/logging.h"
22 #include "base/memory/scoped_ptr.h"
23 #include "base/threading/thread_restrictions.h"
24 #include "content/browser/media/android/browser_media_player_manager.h"
25 #include "content/public/browser/browser_main_runner.h"
26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/common/content_switches.h"
28 #include "gpu/command_buffer/client/gl_in_process_context.h"
29 #include "media/base/media_switches.h"
30 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
32 namespace android_webview
{
36 // TODO(boliu): Remove this global Allow once the underlying issues are
37 // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
38 base::LazyInstance
<scoped_ptr
<ScopedAllowWaitForLegacyWebViewApi
> >
39 g_allow_wait_in_ui_thread
= LAZY_INSTANCE_INITIALIZER
;
43 AwMainDelegate::AwMainDelegate()
44 : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl
) {
47 AwMainDelegate::~AwMainDelegate() {
50 bool AwMainDelegate::BasicStartupComplete(int* exit_code
) {
51 content::SetContentClient(&content_client_
);
53 CommandLine
* cl
= CommandLine::ForCurrentProcess();
54 bool zero_copy_disabled_by_switch
= cl
->HasSwitch(switches::kDisableZeroCopy
);
55 bool use_zero_copy
= !zero_copy_disabled_by_switch
&&
56 cl
->HasSwitch(switches::kEnableZeroCopy
) &&
57 gpu_memory_buffer_factory_
.get()->Initialize();
60 cl
->AppendSwitch(switches::kEnableZeroCopy
);
61 } else if (!zero_copy_disabled_by_switch
) {
62 cl
->AppendSwitch(switches::kDisableZeroCopy
);
65 content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
66 new AwMediaUrlInterceptor());
68 BrowserViewRenderer::CalculateTileMemoryPolicy(use_zero_copy
);
70 cl
->AppendSwitch(switches::kEnableBeginFrameScheduling
);
71 cl
->AppendSwitch(switches::kEnableImplSidePainting
);
73 // WebView uses the Android system's scrollbars and overscroll glow.
74 cl
->AppendSwitch(switches::kDisableOverscrollEdgeEffect
);
76 // Not yet supported in single-process mode.
77 cl
->AppendSwitch(switches::kDisableSharedWorkers
);
79 // File system API not supported (requires some new API; internal bug 6930981)
80 cl
->AppendSwitch(switches::kDisableFileSystem
);
82 #if defined(VIDEO_HOLE)
83 // Support EME/L1 with hole-punching.
84 cl
->AppendSwitch(switches::kMediaDrmEnableNonCompositing
);
87 // WebRTC hardware decoding is not supported, internal bug 15075307
88 cl
->AppendSwitch(switches::kDisableWebRtcHWDecoding
);
93 void AwMainDelegate::PreSandboxStartup() {
94 // TODO(torne): When we have a separate renderer process, we need to handle
95 // being passed open FDs for the resource paks here.
96 #if defined(ARCH_CPU_ARM_FAMILY)
97 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
103 void AwMainDelegate::SandboxInitialized(const std::string
& process_type
) {
104 // TODO(torne): Adjust linux OOM score here.
107 int AwMainDelegate::RunProcess(
108 const std::string
& process_type
,
109 const content::MainFunctionParams
& main_function_params
) {
110 if (process_type
.empty()) {
111 AwBrowserDependencyFactoryImpl::InstallInstance();
113 browser_runner_
.reset(content::BrowserMainRunner::Create());
114 int exit_code
= browser_runner_
->Initialize(main_function_params
);
115 DCHECK(exit_code
< 0);
117 g_allow_wait_in_ui_thread
.Get().reset(
118 new ScopedAllowWaitForLegacyWebViewApi
);
120 // Return 0 so that we do NOT trigger the default behavior. On Android, the
121 // UI message loop is managed by the Java application.
128 void AwMainDelegate::ProcessExiting(const std::string
& process_type
) {
129 // TODO(torne): Clean up resources when we handle them.
131 logging::CloseLogFile();
134 content::ContentBrowserClient
*
135 AwMainDelegate::CreateContentBrowserClient() {
136 content_browser_client_
.reset(new AwContentBrowserClient(this));
137 return content_browser_client_
.get();
140 content::ContentRendererClient
*
141 AwMainDelegate::CreateContentRendererClient() {
142 content_renderer_client_
.reset(new AwContentRendererClient());
143 return content_renderer_client_
.get();
146 scoped_refptr
<AwQuotaManagerBridge
> AwMainDelegate::CreateAwQuotaManagerBridge(
147 AwBrowserContext
* browser_context
) {
148 return AwQuotaManagerBridgeImpl::Create(browser_context
);
151 content::WebContentsViewDelegate
* AwMainDelegate::CreateViewDelegate(
152 content::WebContents
* web_contents
) {
153 return AwWebContentsViewDelegate::Create(web_contents
);
156 AwWebPreferencesPopulater
* AwMainDelegate::CreateWebPreferencesPopulater() {
157 return new AwWebPreferencesPopulaterImpl();
160 #if defined(VIDEO_HOLE)
161 content::ExternalVideoSurfaceContainer
*
162 AwMainDelegate::CreateExternalVideoSurfaceContainer(
163 content::WebContents
* web_contents
) {
164 return new ExternalVideoSurfaceContainerImpl(web_contents
);
168 } // namespace android_webview