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