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/scoped_allow_wait_for_legacy_web_view_api.h"
10 #include "android_webview/lib/aw_browser_dependency_factory_impl.h"
11 #include "android_webview/native/aw_assets.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/i18n/icu_util.h"
21 #include "base/lazy_instance.h"
22 #include "base/logging.h"
23 #include "base/memory/scoped_ptr.h"
24 #include "base/threading/thread_restrictions.h"
25 #include "cc/base/switches.h"
26 #include "content/browser/media/android/browser_media_player_manager.h"
27 #include "content/public/browser/browser_main_runner.h"
28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/common/content_descriptors.h"
30 #include "content/public/common/content_switches.h"
31 #include "gin/public/isolate_holder.h"
32 #include "gpu/command_buffer/client/gl_in_process_context.h"
33 #include "gpu/command_buffer/service/gpu_switches.h"
34 #include "media/base/media_switches.h"
36 namespace android_webview
{
40 // TODO(boliu): Remove this global Allow once the underlying issues are
41 // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
42 base::LazyInstance
<scoped_ptr
<ScopedAllowWaitForLegacyWebViewApi
> >
43 g_allow_wait_in_ui_thread
= LAZY_INSTANCE_INITIALIZER
;
47 AwMainDelegate::AwMainDelegate() {
50 AwMainDelegate::~AwMainDelegate() {
53 bool AwMainDelegate::BasicStartupComplete(int* exit_code
) {
54 content::SetContentClient(&content_client_
);
56 content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
57 new AwMediaUrlInterceptor());
59 BrowserViewRenderer::CalculateTileMemoryPolicy();
61 base::CommandLine
* cl
= base::CommandLine::ForCurrentProcess();
62 cl
->AppendSwitch(switches::kEnableBeginFrameScheduling
);
63 cl
->AppendSwitch(switches::kEnableImplSidePainting
);
65 // WebView uses the Android system's scrollbars and overscroll glow.
66 cl
->AppendSwitch(switches::kDisableOverscrollEdgeEffect
);
68 // Pull-to-refresh should never be a default WebView action.
69 cl
->AppendSwitch(switches::kDisablePullToRefreshEffect
);
71 // Not yet supported in single-process mode.
72 cl
->AppendSwitch(switches::kDisableSharedWorkers
);
74 // File system API not supported (requires some new API; internal bug 6930981)
75 cl
->AppendSwitch(switches::kDisableFileSystem
);
77 #if defined(VIDEO_HOLE)
78 // Support EME/L1 with hole-punching.
79 cl
->AppendSwitch(switches::kMediaDrmEnableNonCompositing
);
82 // WebRTC hardware decoding is not supported, internal bug 15075307
83 cl
->AppendSwitch(switches::kDisableWebRtcHWDecoding
);
85 // This is needed for sharing textures across the different GL threads.
86 cl
->AppendSwitch(switches::kEnableThreadedTextureMailboxes
);
88 // This is needed to be able to mmap the V8 snapshot and ICU data file
89 // directly from the WebView .apk.
90 // This needs to be here so that it gets to run before the code in
91 // content_main_runner that reads these values tries to do so.
92 // In multi-process mode this code would live in
93 // AwContentBrowserClient::GetAdditionalMappedFilesForChildProcess.
94 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
95 CHECK(AwAssets::RegisterAssetWithGlobalDescriptors(
96 kV8NativesDataDescriptor
, gin::IsolateHolder::kNativesFileName
));
97 CHECK(AwAssets::RegisterAssetWithGlobalDescriptors(
98 kV8SnapshotDataDescriptor
, gin::IsolateHolder::kSnapshotFileName
));
100 // TODO(mkosiba): make this CHECK when the android_webview_build uses an asset
101 // from the .apk too.
102 AwAssets::RegisterAssetWithGlobalDescriptors(
103 kAndroidICUDataDescriptor
, base::i18n::kIcuDataFileName
);
108 void AwMainDelegate::PreSandboxStartup() {
109 // TODO(torne): When we have a separate renderer process, we need to handle
110 // being passed open FDs for the resource paks here.
111 #if defined(ARCH_CPU_ARM_FAMILY)
112 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
118 void AwMainDelegate::SandboxInitialized(const std::string
& process_type
) {
119 // TODO(torne): Adjust linux OOM score here.
122 int AwMainDelegate::RunProcess(
123 const std::string
& process_type
,
124 const content::MainFunctionParams
& main_function_params
) {
125 if (process_type
.empty()) {
126 AwBrowserDependencyFactoryImpl::InstallInstance();
128 browser_runner_
.reset(content::BrowserMainRunner::Create());
129 int exit_code
= browser_runner_
->Initialize(main_function_params
);
130 DCHECK_LT(exit_code
, 0);
132 g_allow_wait_in_ui_thread
.Get().reset(
133 new ScopedAllowWaitForLegacyWebViewApi
);
135 // Return 0 so that we do NOT trigger the default behavior. On Android, the
136 // UI message loop is managed by the Java application.
143 void AwMainDelegate::ProcessExiting(const std::string
& process_type
) {
144 // TODO(torne): Clean up resources when we handle them.
146 logging::CloseLogFile();
149 content::ContentBrowserClient
*
150 AwMainDelegate::CreateContentBrowserClient() {
151 content_browser_client_
.reset(new AwContentBrowserClient(this));
152 return content_browser_client_
.get();
155 content::ContentRendererClient
*
156 AwMainDelegate::CreateContentRendererClient() {
157 content_renderer_client_
.reset(new AwContentRendererClient());
158 return content_renderer_client_
.get();
161 scoped_refptr
<AwQuotaManagerBridge
> AwMainDelegate::CreateAwQuotaManagerBridge(
162 AwBrowserContext
* browser_context
) {
163 return AwQuotaManagerBridgeImpl::Create(browser_context
);
166 content::WebContentsViewDelegate
* AwMainDelegate::CreateViewDelegate(
167 content::WebContents
* web_contents
) {
168 return AwWebContentsViewDelegate::Create(web_contents
);
171 AwWebPreferencesPopulater
* AwMainDelegate::CreateWebPreferencesPopulater() {
172 return new AwWebPreferencesPopulaterImpl();
175 #if defined(VIDEO_HOLE)
176 content::ExternalVideoSurfaceContainer
*
177 AwMainDelegate::CreateExternalVideoSurfaceContainer(
178 content::WebContents
* web_contents
) {
179 return new ExternalVideoSurfaceContainerImpl(web_contents
);
183 } // namespace android_webview