Update V8 to version 4.6.66.
[chromium-blink-merge.git] / android_webview / lib / main / aw_main_delegate.cc
blob232bd96dfc99cac6a9c936f804a1d4db43a4c08f
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/common/aw_switches.h"
11 #include "android_webview/crash_reporter/aw_microdump_crash_reporter.h"
12 #include "android_webview/lib/aw_browser_dependency_factory_impl.h"
13 #include "android_webview/native/aw_locale_manager_impl.h"
14 #include "android_webview/native/aw_media_url_interceptor.h"
15 #include "android_webview/native/aw_message_port_service_impl.h"
16 #include "android_webview/native/aw_quota_manager_bridge_impl.h"
17 #include "android_webview/native/aw_web_contents_view_delegate.h"
18 #include "android_webview/native/aw_web_preferences_populater_impl.h"
19 #include "android_webview/renderer/aw_content_renderer_client.h"
20 #include "base/android/apk_assets.h"
21 #include "base/command_line.h"
22 #include "base/cpu.h"
23 #include "base/i18n/icu_util.h"
24 #include "base/lazy_instance.h"
25 #include "base/logging.h"
26 #include "base/memory/scoped_ptr.h"
27 #include "base/threading/thread_restrictions.h"
28 #include "cc/base/switches.h"
29 #include "components/external_video_surface/browser/android/external_video_surface_container_impl.h"
30 #include "content/public/browser/android/browser_media_player_manager_register.h"
31 #include "content/public/browser/browser_main_runner.h"
32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/common/content_descriptors.h"
34 #include "content/public/common/content_switches.h"
35 #include "gin/public/isolate_holder.h"
36 #include "gpu/command_buffer/client/gl_in_process_context.h"
37 #include "gpu/command_buffer/service/gpu_switches.h"
38 #include "media/base/media_switches.h"
39 #include "ui/events/gesture_detection/gesture_configuration.h"
41 namespace android_webview {
43 namespace {
45 // TODO(boliu): Remove this global Allow once the underlying issues are
46 // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
47 base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
48 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
52 AwMainDelegate::AwMainDelegate() {
55 AwMainDelegate::~AwMainDelegate() {
58 bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
59 content::SetContentClient(&content_client_);
61 content::RegisterMediaUrlInterceptor(new AwMediaUrlInterceptor());
63 BrowserViewRenderer::CalculateTileMemoryPolicy();
65 // WebView apps can override WebView#computeScroll to achieve custom
66 // scroll/fling. As a result, fling animations may not be ticked, potentially
67 // confusing the tap suppression controller. Simply disable it for WebView.
68 ui::GestureConfiguration::GetInstance()
69 ->set_fling_touchscreen_tap_suppression_enabled(false);
71 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
72 cl->AppendSwitch(switches::kUseIpcCommandBuffer);
73 cl->AppendSwitch(cc::switches::kEnableBeginFrameScheduling);
75 // WebView uses the Android system's scrollbars and overscroll glow.
76 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
78 // Pull-to-refresh should never be a default WebView action.
79 cl->AppendSwitch(switches::kDisablePullToRefreshEffect);
81 // Not yet supported in single-process mode.
82 cl->AppendSwitch(switches::kDisableSharedWorkers);
84 // File system API not supported (requires some new API; internal bug 6930981)
85 cl->AppendSwitch(switches::kDisableFileSystem);
87 // Web Notification API and the Push API are not supported (crbug.com/434712)
88 cl->AppendSwitch(switches::kDisableNotifications);
90 // WebRTC hardware decoding is not supported, internal bug 15075307
91 cl->AppendSwitch(switches::kDisableWebRtcHWDecoding);
92 cl->AppendSwitch(switches::kDisableAcceleratedVideoDecode);
94 // This is needed for sharing textures across the different GL threads.
95 cl->AppendSwitch(switches::kEnableThreadedTextureMailboxes);
97 // WebView does not yet support screen orientation locking.
98 cl->AppendSwitch(switches::kDisableScreenOrientationLock);
100 // WebView does not currently support Web Speech API (crbug.com/487255)
101 cl->AppendSwitch(switches::kDisableSpeechAPI);
103 // WebView does not currently support the Permissions API (crbug.com/490120)
104 cl->AppendSwitch(switches::kDisablePermissionsAPI);
106 // WebView does not (yet) save Chromium data during shutdown, so add setting
107 // for Chrome to aggressively persist DOM Storage to minimize data loss.
108 // http://crbug.com/479767
109 cl->AppendSwitch(switches::kEnableAggressiveDOMStorageFlushing);
111 // This is needed to be able to mmap the V8 snapshot and ICU data file
112 // directly from the WebView .apk.
113 // This needs to be here so that it gets to run before the code in
114 // content_main_runner that reads these values tries to do so.
115 // In multi-process mode this code would live in
116 // AwContentBrowserClient::GetAdditionalMappedFilesForChildProcess.
117 #ifdef __LP64__
118 const char kNativesFileName[] = "assets/natives_blob_64.bin";
119 const char kSnapshotFileName[] = "assets/snapshot_blob_64.bin";
120 #else
121 const char kNativesFileName[] = "assets/natives_blob_32.bin";
122 const char kSnapshotFileName[] = "assets/snapshot_blob_32.bin";
123 #endif // __LP64__
124 // TODO(gsennton) we should use
125 // gin::IsolateHolder::kNativesFileName/kSnapshotFileName
126 // here when those files have arch specific names http://crbug.com/455699
127 CHECK(base::android::RegisterApkAssetWithGlobalDescriptors(
128 kV8NativesDataDescriptor, kNativesFileName));
129 CHECK(base::android::RegisterApkAssetWithGlobalDescriptors(
130 kV8SnapshotDataDescriptor, kSnapshotFileName));
131 CHECK(base::android::RegisterApkAssetWithGlobalDescriptors(
132 kAndroidICUDataDescriptor, "assets/icudtl.dat"));
134 return false;
137 void AwMainDelegate::PreSandboxStartup() {
138 // TODO(torne): When we have a separate renderer process, we need to handle
139 // being passed open FDs for the resource paks here.
140 #if defined(ARCH_CPU_ARM_FAMILY)
141 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
142 // cpu_brand info.
143 base::CPU cpu_info;
144 #endif
146 crash_reporter::EnableMicrodumpCrashReporter();
149 void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
150 // TODO(torne): Adjust linux OOM score here.
153 int AwMainDelegate::RunProcess(
154 const std::string& process_type,
155 const content::MainFunctionParams& main_function_params) {
156 if (process_type.empty()) {
157 AwBrowserDependencyFactoryImpl::InstallInstance();
159 browser_runner_.reset(content::BrowserMainRunner::Create());
160 int exit_code = browser_runner_->Initialize(main_function_params);
161 DCHECK_LT(exit_code, 0);
163 g_allow_wait_in_ui_thread.Get().reset(
164 new ScopedAllowWaitForLegacyWebViewApi);
166 // Return 0 so that we do NOT trigger the default behavior. On Android, the
167 // UI message loop is managed by the Java application.
168 return 0;
171 return -1;
174 void AwMainDelegate::ProcessExiting(const std::string& process_type) {
175 // TODO(torne): Clean up resources when we handle them.
177 logging::CloseLogFile();
180 content::ContentBrowserClient*
181 AwMainDelegate::CreateContentBrowserClient() {
182 content_browser_client_.reset(new AwContentBrowserClient(this));
183 return content_browser_client_.get();
186 content::ContentRendererClient*
187 AwMainDelegate::CreateContentRendererClient() {
188 content_renderer_client_.reset(new AwContentRendererClient());
189 return content_renderer_client_.get();
192 scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge(
193 AwBrowserContext* browser_context) {
194 return AwQuotaManagerBridgeImpl::Create(browser_context);
197 content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
198 content::WebContents* web_contents) {
199 return AwWebContentsViewDelegate::Create(web_contents);
202 AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() {
203 return new AwWebPreferencesPopulaterImpl();
206 AwMessagePortService* AwMainDelegate::CreateAwMessagePortService() {
207 return new AwMessagePortServiceImpl();
210 AwLocaleManager* AwMainDelegate::CreateAwLocaleManager() {
211 return new AwLocaleManagerImpl();
214 #if defined(VIDEO_HOLE)
215 content::ExternalVideoSurfaceContainer*
216 AwMainDelegate::CreateExternalVideoSurfaceContainer(
217 content::WebContents* web_contents) {
218 return external_video_surface::ExternalVideoSurfaceContainerImpl::Create(
219 web_contents);
221 #endif
223 } // namespace android_webview