[GCM] Support registration before unregistration finishes
[chromium-blink-merge.git] / android_webview / lib / main / aw_main_delegate.cc
blobea3c67de99be2cdb237b4312cd47cb4b1830b1d9
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.
5 #include "android_webview/lib/main/aw_main_delegate.h"
7 #include "android_webview/browser/aw_content_browser_client.h"
8 #include "android_webview/browser/browser_view_renderer.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_media_url_interceptor.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 "cc/base/switches.h"
24 #include "content/browser/media/android/browser_media_player_manager.h"
25 #include "content/public/browser/browser_main_runner.h"
26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/common/content_switches.h"
28 #include "gpu/command_buffer/client/gl_in_process_context.h"
29 #include "gpu/command_buffer/service/gpu_switches.h"
30 #include "media/base/media_switches.h"
31 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
33 namespace android_webview {
35 namespace {
37 // TODO(boliu): Remove this global Allow once the underlying issues are
38 // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
39 base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
40 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
44 AwMainDelegate::AwMainDelegate() {
47 AwMainDelegate::~AwMainDelegate() {
50 bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
51 content::SetContentClient(&content_client_);
53 content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
54 new AwMediaUrlInterceptor());
56 BrowserViewRenderer::CalculateTileMemoryPolicy();
58 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
59 cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
60 cl->AppendSwitch(switches::kEnableImplSidePainting);
62 // WebView uses the Android system's scrollbars and overscroll glow.
63 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
65 // Not yet supported in single-process mode.
66 cl->AppendSwitch(switches::kDisableSharedWorkers);
68 // File system API not supported (requires some new API; internal bug 6930981)
69 cl->AppendSwitch(switches::kDisableFileSystem);
71 // For fullscreen video we create a new container view to host the
72 // WebContents, ie. the FullscreenView. As a result we cannot reuse the
73 // embedded video blocker attached to the old container view, so we create a
74 // new blocker instead attached to the ContentVideoView.
75 cl->AppendSwitch(switches::kEnableContentVideoViewPowerSaveBlocker);
77 #if defined(VIDEO_HOLE)
78 // Support EME/L1 with hole-punching.
79 cl->AppendSwitch(switches::kMediaDrmEnableNonCompositing);
80 #endif
82 // WebRTC hardware decoding is not supported, internal bug 15075307
83 cl->AppendSwitch(switches::kDisableWebRtcHWDecoding);
85 // This is needed for sharing textures across the different GL threads.
86 cl->AppendSwitch(switches::kEnableThreadedTextureMailboxes);
88 // Virtual viewport doesn't behave well with web view. crbug.com/426891
89 cl->AppendSwitch(cc::switches::kDisablePinchVirtualViewport);
91 return false;
94 void AwMainDelegate::PreSandboxStartup() {
95 // TODO(torne): When we have a separate renderer process, we need to handle
96 // being passed open FDs for the resource paks here.
97 #if defined(ARCH_CPU_ARM_FAMILY)
98 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
99 // cpu_brand info.
100 base::CPU cpu_info;
101 #endif
104 void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
105 // TODO(torne): Adjust linux OOM score here.
108 int AwMainDelegate::RunProcess(
109 const std::string& process_type,
110 const content::MainFunctionParams& main_function_params) {
111 if (process_type.empty()) {
112 AwBrowserDependencyFactoryImpl::InstallInstance();
114 browser_runner_.reset(content::BrowserMainRunner::Create());
115 int exit_code = browser_runner_->Initialize(main_function_params);
116 DCHECK_LT(exit_code, 0);
118 g_allow_wait_in_ui_thread.Get().reset(
119 new ScopedAllowWaitForLegacyWebViewApi);
121 // Return 0 so that we do NOT trigger the default behavior. On Android, the
122 // UI message loop is managed by the Java application.
123 return 0;
126 return -1;
129 void AwMainDelegate::ProcessExiting(const std::string& process_type) {
130 // TODO(torne): Clean up resources when we handle them.
132 logging::CloseLogFile();
135 content::ContentBrowserClient*
136 AwMainDelegate::CreateContentBrowserClient() {
137 content_browser_client_.reset(new AwContentBrowserClient(this));
138 return content_browser_client_.get();
141 content::ContentRendererClient*
142 AwMainDelegate::CreateContentRendererClient() {
143 content_renderer_client_.reset(new AwContentRendererClient());
144 return content_renderer_client_.get();
147 scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge(
148 AwBrowserContext* browser_context) {
149 return AwQuotaManagerBridgeImpl::Create(browser_context);
152 content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
153 content::WebContents* web_contents) {
154 return AwWebContentsViewDelegate::Create(web_contents);
157 AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() {
158 return new AwWebPreferencesPopulaterImpl();
161 #if defined(VIDEO_HOLE)
162 content::ExternalVideoSurfaceContainer*
163 AwMainDelegate::CreateExternalVideoSurfaceContainer(
164 content::WebContents* web_contents) {
165 return new ExternalVideoSurfaceContainerImpl(web_contents);
167 #endif
169 } // namespace android_webview