blob: 41aaf4a1faaf2aad564922af4a0f8f8cda58e510 [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]7d67302a2014-05-03 02:17:078#include "android_webview/browser/browser_view_renderer.h"
[email protected]9a50bf92013-05-09 05:39:519#include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
[email protected]5d730a32012-08-23 19:11:2310#include "android_webview/lib/aw_browser_dependency_factory_impl.h"
[email protected]63ab5052014-08-04 10:44:1111#include "android_webview/native/aw_media_url_interceptor.h"
[email protected]2a3a0592013-02-22 18:53:0412#include "android_webview/native/aw_quota_manager_bridge_impl.h"
[email protected]ce507cb2012-12-11 23:42:2213#include "android_webview/native/aw_web_contents_view_delegate.h"
[email protected]9f8797b2013-09-27 00:18:1314#include "android_webview/native/aw_web_preferences_populater_impl.h"
[email protected]11572b42014-04-15 16:28:3615#include "android_webview/native/external_video_surface_container_impl.h"
[email protected]710b2602012-10-11 21:41:0916#include "android_webview/renderer/aw_content_renderer_client.h"
[email protected]a6e8c49d2012-12-24 13:19:3717#include "base/command_line.h"
[email protected]3a23f63c2014-04-28 15:33:2618#include "base/cpu.h"
[email protected]9a50bf92013-05-09 05:39:5119#include "base/lazy_instance.h"
[email protected]878aa822012-08-09 10:55:0420#include "base/logging.h"
[email protected]86b74e062012-10-03 01:44:4621#include "base/memory/scoped_ptr.h"
[email protected]a1811b8912013-05-09 15:35:1922#include "base/threading/thread_restrictions.h"
[email protected]63ab5052014-08-04 10:44:1123#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]878aa822012-08-09 10:55:0424#include "content/public/browser/browser_main_runner.h"
[email protected]ea5f70a2013-03-07 12:30:3625#include "content/public/browser/browser_thread.h"
[email protected]a6e8c49d2012-12-24 13:19:3726#include "content/public/common/content_switches.h"
[email protected]d7cf3932013-06-26 04:08:0427#include "gpu/command_buffer/client/gl_in_process_context.h"
sieversb727d532014-10-24 19:11:3428#include "gpu/command_buffer/service/gpu_switches.h"
[email protected]8b4efe92014-02-21 16:08:2029#include "media/base/media_switches.h"
[email protected]1fb9e7e2013-05-26 03:23:4830#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
[email protected]878aa822012-08-09 10:55:0431
32namespace android_webview {
33
[email protected]9a50bf92013-05-09 05:39:5134namespace {
35
[email protected]0d66d7e2013-06-13 17:44:3236// TODO(boliu): Remove this global Allow once the underlying issues are
[email protected]1d0a6b82013-05-16 09:03:1137// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
[email protected]9a50bf92013-05-09 05:39:5138base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
39 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
40
[email protected]9a50bf92013-05-09 05:39:5141}
42
revemanec103f02014-09-29 19:12:3143AwMainDelegate::AwMainDelegate() {
[email protected]878aa822012-08-09 10:55:0444}
45
[email protected]c1a47df2012-08-30 00:29:5646AwMainDelegate::~AwMainDelegate() {
[email protected]878aa822012-08-09 10:55:0447}
48
[email protected]c1a47df2012-08-30 00:29:5649bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
[email protected]9b57401b2012-10-10 16:01:4750 content::SetContentClient(&content_client_);
[email protected]878aa822012-08-09 10:55:0451
[email protected]63ab5052014-08-04 10:44:1152 content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
53 new AwMediaUrlInterceptor());
54
revemanec103f02014-09-29 19:12:3155 BrowserViewRenderer::CalculateTileMemoryPolicy();
[email protected]0552c8e2013-09-10 22:44:4356
pgal.u-szeged929d45a92014-10-28 11:50:4157 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
[email protected]0d66d7e2013-06-13 17:44:3258 cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
[email protected]a23530d2014-03-11 06:04:1459 cl->AppendSwitch(switches::kEnableImplSidePainting);
[email protected]6c2385332013-05-21 00:05:0660
[email protected]14f29f02013-07-17 02:09:0861 // WebView uses the Android system's scrollbars and overscroll glow.
[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]0e176fa2013-09-11 14:07:1465 cl->AppendSwitch(switches::kDisableSharedWorkers);
[email protected]c660d46f2013-08-05 22:40:5966
[email protected]047fcf72013-09-09 11:03:3267 // File system API not supported (requires some new API; internal bug 6930981)
[email protected]0e176fa2013-09-11 14:07:1468 cl->AppendSwitch(switches::kDisableFileSystem);
[email protected]047fcf72013-09-09 11:03:3269
igsollaec9b8862014-09-25 17:46:2370 // 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]8b4efe92014-02-21 16:08:2076#if defined(VIDEO_HOLE)
77 // Support EME/L1 with hole-punching.
78 cl->AppendSwitch(switches::kMediaDrmEnableNonCompositing);
79#endif
[email protected]846c0c12014-06-04 23:07:0780
81 // WebRTC hardware decoding is not supported, internal bug 15075307
82 cl->AppendSwitch(switches::kDisableWebRtcHWDecoding);
[email protected]8a592802014-07-02 07:31:3383
sieversb727d532014-10-24 19:11:3484 // This is needed for sharing textures across the different GL threads.
85 cl->AppendSwitch(switches::kEnableThreadedTextureMailboxes);
[email protected]878aa822012-08-09 10:55:0486 return false;
87}
88
[email protected]c1a47df2012-08-30 00:29:5689void AwMainDelegate::PreSandboxStartup() {
[email protected]878aa822012-08-09 10:55:0490 // 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]3a23f63c2014-04-28 15:33:2692#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]878aa822012-08-09 10:55:0497}
98
[email protected]c1a47df2012-08-30 00:29:5699void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
[email protected]878aa822012-08-09 10:55:04100 // TODO(torne): Adjust linux OOM score here.
101}
102
[email protected]c1a47df2012-08-30 00:29:56103int AwMainDelegate::RunProcess(
[email protected]878aa822012-08-09 10:55:04104 const std::string& process_type,
105 const content::MainFunctionParams& main_function_params) {
106 if (process_type.empty()) {
[email protected]5d730a32012-08-23 19:11:23107 AwBrowserDependencyFactoryImpl::InstallInstance();
108
[email protected]878aa822012-08-09 10:55:04109 browser_runner_.reset(content::BrowserMainRunner::Create());
110 int exit_code = browser_runner_->Initialize(main_function_params);
boliu2d46b522014-08-29 22:33:44111 DCHECK_LT(exit_code, 0);
[email protected]878aa822012-08-09 10:55:04112
[email protected]0d66d7e2013-06-13 17:44:32113 g_allow_wait_in_ui_thread.Get().reset(
114 new ScopedAllowWaitForLegacyWebViewApi);
[email protected]9a50bf92013-05-09 05:39:51115
[email protected]878aa822012-08-09 10:55:04116 // 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]c1a47df2012-08-30 00:29:56124void AwMainDelegate::ProcessExiting(const std::string& process_type) {
[email protected]878aa822012-08-09 10:55:04125 // TODO(torne): Clean up resources when we handle them.
126
127 logging::CloseLogFile();
128}
129
130content::ContentBrowserClient*
[email protected]c1a47df2012-08-30 00:29:56131 AwMainDelegate::CreateContentBrowserClient() {
[email protected]2a3a0592013-02-22 18:53:04132 content_browser_client_.reset(new AwContentBrowserClient(this));
[email protected]ce507cb2012-12-11 23:42:22133 return content_browser_client_.get();
[email protected]878aa822012-08-09 10:55:04134}
135
136content::ContentRendererClient*
[email protected]c1a47df2012-08-30 00:29:56137 AwMainDelegate::CreateContentRendererClient() {
[email protected]913d99a2013-05-31 07:16:07138 content_renderer_client_.reset(new AwContentRendererClient());
[email protected]ce507cb2012-12-11 23:42:22139 return content_renderer_client_.get();
[email protected]878aa822012-08-09 10:55:04140}
141
[email protected]1a64c312013-10-08 12:56:26142scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge(
[email protected]2a3a0592013-02-22 18:53:04143 AwBrowserContext* browser_context) {
[email protected]1a64c312013-10-08 12:56:26144 return AwQuotaManagerBridgeImpl::Create(browser_context);
[email protected]2a3a0592013-02-22 18:53:04145}
146
[email protected]2a3a0592013-02-22 18:53:04147content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
148 content::WebContents* web_contents) {
149 return AwWebContentsViewDelegate::Create(web_contents);
150}
151
[email protected]9f8797b2013-09-27 00:18:13152AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() {
153 return new AwWebPreferencesPopulaterImpl();
154}
155
[email protected]11572b42014-04-15 16:28:36156#if defined(VIDEO_HOLE)
157content::ExternalVideoSurfaceContainer*
158AwMainDelegate::CreateExternalVideoSurfaceContainer(
159 content::WebContents* web_contents) {
160 return new ExternalVideoSurfaceContainerImpl(web_contents);
161}
162#endif
163
[email protected]878aa822012-08-09 10:55:04164} // namespace android_webview