[Android WebView] AwMediaUrlInterceptor to handle media assets.
[chromium-blink-merge.git] / android_webview / lib / main / aw_main_delegate.cc
blob371a45e30f918d5e6803ac0e0a17c7e8138d4922
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/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_media_url_interceptor.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/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 "media/base/media_switches.h"
30 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
32 namespace android_webview {
34 namespace {
36 // TODO(boliu): Remove this global Allow once the underlying issues are
37 // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
38 base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
39 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
43 AwMainDelegate::AwMainDelegate()
44 : gpu_memory_buffer_factory_(new GpuMemoryBufferFactoryImpl) {
47 AwMainDelegate::~AwMainDelegate() {
50 bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
51 content::SetContentClient(&content_client_);
53 CommandLine* cl = CommandLine::ForCurrentProcess();
54 bool zero_copy_disabled_by_switch = cl->HasSwitch(switches::kDisableZeroCopy);
55 bool use_zero_copy = !zero_copy_disabled_by_switch &&
56 gpu_memory_buffer_factory_.get()->Initialize();
58 if (use_zero_copy) {
59 cl->AppendSwitch(switches::kEnableZeroCopy);
60 } else if (!zero_copy_disabled_by_switch) {
61 cl->AppendSwitch(switches::kDisableZeroCopy);
64 content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
65 new AwMediaUrlInterceptor());
67 BrowserViewRenderer::CalculateTileMemoryPolicy(use_zero_copy);
69 cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
70 cl->AppendSwitch(switches::kEnableImplSidePainting);
72 // WebView uses the Android system's scrollbars and overscroll glow.
73 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
75 // Not yet supported in single-process mode.
76 cl->AppendSwitch(switches::kDisableSharedWorkers);
78 // File system API not supported (requires some new API; internal bug 6930981)
79 cl->AppendSwitch(switches::kDisableFileSystem);
81 #if defined(VIDEO_HOLE)
82 // Support EME/L1 with hole-punching.
83 cl->AppendSwitch(switches::kMediaDrmEnableNonCompositing);
84 #endif
86 // WebRTC hardware decoding is not supported, internal bug 15075307
87 cl->AppendSwitch(switches::kDisableWebRtcHWDecoding);
89 return false;
92 void AwMainDelegate::PreSandboxStartup() {
93 // TODO(torne): When we have a separate renderer process, we need to handle
94 // being passed open FDs for the resource paks here.
95 #if defined(ARCH_CPU_ARM_FAMILY)
96 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
97 // cpu_brand info.
98 base::CPU cpu_info;
99 #endif
102 void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
103 // TODO(torne): Adjust linux OOM score here.
106 int AwMainDelegate::RunProcess(
107 const std::string& process_type,
108 const content::MainFunctionParams& main_function_params) {
109 if (process_type.empty()) {
110 AwBrowserDependencyFactoryImpl::InstallInstance();
112 browser_runner_.reset(content::BrowserMainRunner::Create());
113 int exit_code = browser_runner_->Initialize(main_function_params);
114 DCHECK(exit_code < 0);
116 g_allow_wait_in_ui_thread.Get().reset(
117 new ScopedAllowWaitForLegacyWebViewApi);
119 // Return 0 so that we do NOT trigger the default behavior. On Android, the
120 // UI message loop is managed by the Java application.
121 return 0;
124 return -1;
127 void AwMainDelegate::ProcessExiting(const std::string& process_type) {
128 // TODO(torne): Clean up resources when we handle them.
130 logging::CloseLogFile();
133 content::ContentBrowserClient*
134 AwMainDelegate::CreateContentBrowserClient() {
135 content_browser_client_.reset(new AwContentBrowserClient(this));
136 return content_browser_client_.get();
139 content::ContentRendererClient*
140 AwMainDelegate::CreateContentRendererClient() {
141 content_renderer_client_.reset(new AwContentRendererClient());
142 return content_renderer_client_.get();
145 scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge(
146 AwBrowserContext* browser_context) {
147 return AwQuotaManagerBridgeImpl::Create(browser_context);
150 content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
151 content::WebContents* web_contents) {
152 return AwWebContentsViewDelegate::Create(web_contents);
155 AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() {
156 return new AwWebPreferencesPopulaterImpl();
159 #if defined(VIDEO_HOLE)
160 content::ExternalVideoSurfaceContainer*
161 AwMainDelegate::CreateExternalVideoSurfaceContainer(
162 content::WebContents* web_contents) {
163 return new ExternalVideoSurfaceContainerImpl(web_contents);
165 #endif
167 } // namespace android_webview