- add sources.
[platform/framework/web/crosswalk.git] / src / android_webview / lib / main / aw_main_delegate.cc
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/in_process_view_renderer.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_geolocation_permission_context.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/renderer/aw_content_renderer_client.h"
17 #include "base/command_line.h"
18 #include "base/lazy_instance.h"
19 #include "base/logging.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/threading/thread_restrictions.h"
22 #include "cc/base/switches.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 "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
29
30 namespace android_webview {
31
32 namespace {
33
34 // TODO(boliu): Remove this global Allow once the underlying issues are
35 // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
36 base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
37     g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
38
39 }
40
41 AwMainDelegate::AwMainDelegate()
42     : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) {
43 }
44
45 AwMainDelegate::~AwMainDelegate() {
46 }
47
48 bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
49   content::SetContentClient(&content_client_);
50
51   gpu::InProcessCommandBuffer::SetGpuMemoryBufferFactory(
52       gpu_memory_buffer_factory_.get());
53   gpu::InProcessCommandBuffer::EnableVirtualizedContext();
54
55   InProcessViewRenderer::CalculateTileMemoryPolicy();
56
57   CommandLine* cl = CommandLine::ForCurrentProcess();
58   cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
59   cl->AppendSwitch(cc::switches::kEnableMapImage);
60
61   // WebView uses the Android system's scrollbars and overscroll glow.
62   cl->AppendSwitch(switches::kHideScrollbars);
63   cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
64
65   // Not yet supported in single-process mode.
66   cl->AppendSwitch(switches::kDisableExperimentalWebGL);
67   cl->AppendSwitch(switches::kDisableSharedWorkers);
68
69   // Ganesh backed 2D-Canvas is not yet working and causes crashes.
70   cl->AppendSwitch(switches::kDisableAccelerated2dCanvas);
71
72   // File system API not supported (requires some new API; internal bug 6930981)
73   cl->AppendSwitch(switches::kDisableFileSystem);
74
75   // Disable compositor touch hit testing for now to mitigate risk of bugs.
76   cl->AppendSwitch(cc::switches::kDisableCompositorTouchHitTesting);
77
78   // Disable WebRTC.
79   cl->AppendSwitch(switches::kDisableWebRTC);
80
81   return false;
82 }
83
84 void 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 }
88
89 void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
90   // TODO(torne): Adjust linux OOM score here.
91 }
92
93 int AwMainDelegate::RunProcess(
94     const std::string& process_type,
95     const content::MainFunctionParams& main_function_params) {
96   if (process_type.empty()) {
97     AwBrowserDependencyFactoryImpl::InstallInstance();
98
99     browser_runner_.reset(content::BrowserMainRunner::Create());
100     int exit_code = browser_runner_->Initialize(main_function_params);
101     DCHECK(exit_code < 0);
102
103     g_allow_wait_in_ui_thread.Get().reset(
104         new ScopedAllowWaitForLegacyWebViewApi);
105
106     // Return 0 so that we do NOT trigger the default behavior. On Android, the
107     // UI message loop is managed by the Java application.
108     return 0;
109   }
110
111   return -1;
112 }
113
114 void AwMainDelegate::ProcessExiting(const std::string& process_type) {
115   // TODO(torne): Clean up resources when we handle them.
116
117   logging::CloseLogFile();
118 }
119
120 content::ContentBrowserClient*
121     AwMainDelegate::CreateContentBrowserClient() {
122   content_browser_client_.reset(new AwContentBrowserClient(this));
123   return content_browser_client_.get();
124 }
125
126 content::ContentRendererClient*
127     AwMainDelegate::CreateContentRendererClient() {
128   content_renderer_client_.reset(new AwContentRendererClient());
129   return content_renderer_client_.get();
130 }
131
132 scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge(
133     AwBrowserContext* browser_context) {
134   return AwQuotaManagerBridgeImpl::Create(browser_context);
135 }
136
137 content::GeolocationPermissionContext*
138     AwMainDelegate::CreateGeolocationPermission(
139         AwBrowserContext* browser_context) {
140   return AwGeolocationPermissionContext::Create(browser_context);
141 }
142
143 content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
144     content::WebContents* web_contents) {
145   return AwWebContentsViewDelegate::Create(web_contents);
146 }
147
148 AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() {
149   return new AwWebPreferencesPopulaterImpl();
150 }
151
152 }  // namespace android_webview