aw_main_delegate.cc revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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
5#include "android_webview/lib/main/aw_main_delegate.h"
6
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_quota_manager_bridge_impl.h"
13#include "android_webview/native/aw_web_contents_view_delegate.h"
14#include "android_webview/native/aw_web_preferences_populater_impl.h"
15#include "android_webview/native/external_video_surface_container_impl.h"
16#include "android_webview/renderer/aw_content_renderer_client.h"
17#include "base/command_line.h"
18#include "base/cpu.h"
19#include "base/lazy_instance.h"
20#include "base/logging.h"
21#include "base/memory/scoped_ptr.h"
22#include "base/threading/thread_restrictions.h"
23#include "content/public/browser/browser_main_runner.h"
24#include "content/public/browser/browser_thread.h"
25#include "content/public/common/content_switches.h"
26#include "gpu/command_buffer/client/gl_in_process_context.h"
27#include "gpu/command_buffer/service/in_process_command_buffer.h"
28#include "media/base/media_switches.h"
29#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
30
31namespace android_webview {
32
33namespace {
34
35// TODO(boliu): Remove this global Allow once the underlying issues are
36// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
37base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
38    g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
39
40}
41
42AwMainDelegate::AwMainDelegate()
43    : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) {
44}
45
46AwMainDelegate::~AwMainDelegate() {
47}
48
49bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
50  content::SetContentClient(&content_client_);
51
52  gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory(
53      gpu_memory_buffer_factory_.get());
54
55  BrowserViewRenderer::CalculateTileMemoryPolicy();
56
57  CommandLine* cl = CommandLine::ForCurrentProcess();
58  cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
59  cl->AppendSwitch(switches::kEnableZeroCopy);
60  cl->AppendSwitch(switches::kEnableImplSidePainting);
61
62  // WebView uses the Android system's scrollbars and overscroll glow.
63  cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
64
65  // Not yet supported in single-process mode.
66  cl->AppendSwitch(switches::kDisableSharedWorkers);
67
68  // File system API not supported (requires some new API; internal bug 6930981)
69  cl->AppendSwitch(switches::kDisableFileSystem);
70
71  // Fullscreen video with subtitle is not yet supported.
72  cl->AppendSwitch(switches::kDisableOverlayFullscreenVideoSubtitle);
73
74#if defined(VIDEO_HOLE)
75  // Support EME/L1 with hole-punching.
76  cl->AppendSwitch(switches::kMediaDrmEnableNonCompositing);
77#endif
78
79  // WebRTC hardware decoding is not supported, internal bug 15075307
80  cl->AppendSwitch(switches::kDisableWebRtcHWDecoding);
81  return false;
82}
83
84void AwMainDelegate::PreSandboxStartup() {
85  // TODO(torne): When we have a separate renderer process, we need to handle
86  // being passed open FDs for the resource paks here.
87#if defined(ARCH_CPU_ARM_FAMILY)
88  // Create an instance of the CPU class to parse /proc/cpuinfo and cache
89  // cpu_brand info.
90  base::CPU cpu_info;
91#endif
92}
93
94void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
95  // TODO(torne): Adjust linux OOM score here.
96}
97
98int AwMainDelegate::RunProcess(
99    const std::string& process_type,
100    const content::MainFunctionParams& main_function_params) {
101  if (process_type.empty()) {
102    AwBrowserDependencyFactoryImpl::InstallInstance();
103
104    browser_runner_.reset(content::BrowserMainRunner::Create());
105    int exit_code = browser_runner_->Initialize(main_function_params);
106    DCHECK(exit_code < 0);
107
108    g_allow_wait_in_ui_thread.Get().reset(
109        new ScopedAllowWaitForLegacyWebViewApi);
110
111    // Return 0 so that we do NOT trigger the default behavior. On Android, the
112    // UI message loop is managed by the Java application.
113    return 0;
114  }
115
116  return -1;
117}
118
119void AwMainDelegate::ProcessExiting(const std::string& process_type) {
120  // TODO(torne): Clean up resources when we handle them.
121
122  logging::CloseLogFile();
123}
124
125content::ContentBrowserClient*
126    AwMainDelegate::CreateContentBrowserClient() {
127  content_browser_client_.reset(new AwContentBrowserClient(this));
128  return content_browser_client_.get();
129}
130
131content::ContentRendererClient*
132    AwMainDelegate::CreateContentRendererClient() {
133  content_renderer_client_.reset(new AwContentRendererClient());
134  return content_renderer_client_.get();
135}
136
137scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge(
138    AwBrowserContext* browser_context) {
139  return AwQuotaManagerBridgeImpl::Create(browser_context);
140}
141
142content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
143    content::WebContents* web_contents) {
144  return AwWebContentsViewDelegate::Create(web_contents);
145}
146
147AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() {
148  return new AwWebPreferencesPopulaterImpl();
149}
150
151#if defined(VIDEO_HOLE)
152content::ExternalVideoSurfaceContainer*
153AwMainDelegate::CreateExternalVideoSurfaceContainer(
154    content::WebContents* web_contents) {
155  return new ExternalVideoSurfaceContainerImpl(web_contents);
156}
157#endif
158
159}  // namespace android_webview
160