aw_main_delegate.cc revision 3551c9c881056c480085172ff9840cab31610854
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/gpu_memory_buffer_factory_impl.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_geolocation_permission_context.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/renderer/aw_content_renderer_client.h"
15#include "base/command_line.h"
16#include "base/lazy_instance.h"
17#include "base/logging.h"
18#include "base/memory/scoped_ptr.h"
19#include "base/threading/thread_restrictions.h"
20#include "cc/base/switches.h"
21#include "content/public/browser/browser_main_runner.h"
22#include "content/public/browser/browser_thread.h"
23#include "content/public/common/content_switches.h"
24#include "gpu/command_buffer/client/gl_in_process_context.h"
25#include "gpu/command_buffer/service/in_process_command_buffer.h"
26#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
27
28namespace android_webview {
29
30namespace {
31
32// TODO(boliu): Remove this global Allow once the underlying issues are
33// resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
34base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
35    g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
36
37}
38
39AwMainDelegate::AwMainDelegate()
40    : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) {
41}
42
43AwMainDelegate::~AwMainDelegate() {
44}
45
46bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
47  content::SetContentClient(&content_client_);
48
49  gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory(
50      gpu_memory_buffer_factory_.get());
51  gpu::InProcessCommandBuffer::EnableVirtualizedContext();
52
53  CommandLine* cl = CommandLine::ForCurrentProcess();
54  cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
55  if (!cl->HasSwitch("disable-map-image"))
56    cl->AppendSwitch(cc::switches::kUseMapImage);
57
58  // WebView uses the Android system's scrollbars and overscroll glow.
59  cl->AppendSwitch(switches::kHideScrollbars);
60  cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
61
62  // Not yet secure in single-process mode.
63  cl->AppendSwitch(switches::kDisableExperimentalWebGL);
64
65  // Ganesh backed 2D-Canvas is not yet working and causes crashes.
66  cl->AppendSwitch(switches::kDisableAccelerated2dCanvas);
67
68  return false;
69}
70
71void AwMainDelegate::PreSandboxStartup() {
72  // TODO(torne): When we have a separate renderer process, we need to handle
73  // being passed open FDs for the resource paks here.
74}
75
76void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
77  // TODO(torne): Adjust linux OOM score here.
78}
79
80int AwMainDelegate::RunProcess(
81    const std::string& process_type,
82    const content::MainFunctionParams& main_function_params) {
83  if (process_type.empty()) {
84    AwBrowserDependencyFactoryImpl::InstallInstance();
85
86    browser_runner_.reset(content::BrowserMainRunner::Create());
87    int exit_code = browser_runner_->Initialize(main_function_params);
88    DCHECK(exit_code < 0);
89
90    g_allow_wait_in_ui_thread.Get().reset(
91        new ScopedAllowWaitForLegacyWebViewApi);
92
93    // Return 0 so that we do NOT trigger the default behavior. On Android, the
94    // UI message loop is managed by the Java application.
95    return 0;
96  }
97
98  return -1;
99}
100
101void AwMainDelegate::ProcessExiting(const std::string& process_type) {
102  // TODO(torne): Clean up resources when we handle them.
103
104  logging::CloseLogFile();
105}
106
107content::ContentBrowserClient*
108    AwMainDelegate::CreateContentBrowserClient() {
109  content_browser_client_.reset(new AwContentBrowserClient(this));
110  return content_browser_client_.get();
111}
112
113content::ContentRendererClient*
114    AwMainDelegate::CreateContentRendererClient() {
115  content_renderer_client_.reset(new AwContentRendererClient());
116  return content_renderer_client_.get();
117}
118
119AwQuotaManagerBridge* AwMainDelegate::CreateAwQuotaManagerBridge(
120    AwBrowserContext* browser_context) {
121  return new AwQuotaManagerBridgeImpl(browser_context);
122}
123
124content::GeolocationPermissionContext*
125    AwMainDelegate::CreateGeolocationPermission(
126        AwBrowserContext* browser_context) {
127  return AwGeolocationPermissionContext::Create(browser_context);
128}
129
130content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
131    content::WebContents* web_contents) {
132  return AwWebContentsViewDelegate::Create(web_contents);
133}
134
135}  // namespace android_webview
136