Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: android_webview/lib/main/aw_main_delegate.cc

Issue 2901333003: [WebView] Flatten lib/main to lib (Closed)
Patch Set: nits Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 <memory>
8
9 #include "android_webview/browser/aw_content_browser_client.h"
10 #include "android_webview/browser/aw_media_url_interceptor.h"
11 #include "android_webview/browser/aw_safe_browsing_config_helper.h"
12 #include "android_webview/browser/browser_view_renderer.h"
13 #include "android_webview/browser/command_line_helper.h"
14 #include "android_webview/browser/deferred_gpu_command_service.h"
15 #include "android_webview/common/aw_descriptors.h"
16 #include "android_webview/common/aw_paths.h"
17 #include "android_webview/common/aw_switches.h"
18 #include "android_webview/common/crash_reporter/aw_microdump_crash_reporter.h"
19 #include "android_webview/common/crash_reporter/crash_keys.h"
20 #include "android_webview/gpu/aw_content_gpu_client.h"
21 #include "android_webview/renderer/aw_content_renderer_client.h"
22 #include "base/android/apk_assets.h"
23 #include "base/android/build_info.h"
24 #include "base/command_line.h"
25 #include "base/cpu.h"
26 #include "base/debug/crash_logging.h"
27 #include "base/i18n/icu_util.h"
28 #include "base/lazy_instance.h"
29 #include "base/logging.h"
30 #include "base/strings/string_number_conversions.h"
31 #include "base/threading/thread_restrictions.h"
32 #include "cc/base/switches.h"
33 #include "components/crash/content/app/breakpad_linux.h"
34 #include "components/safe_browsing_db/android/safe_browsing_api_handler_bridge.h "
35 #include "components/spellcheck/common/spellcheck_features.h"
36 #include "content/public/browser/android/browser_media_player_manager_register.h "
37 #include "content/public/browser/browser_main_runner.h"
38 #include "content/public/browser/browser_thread.h"
39 #include "content/public/common/content_descriptor_keys.h"
40 #include "content/public/common/content_features.h"
41 #include "content/public/common/content_switches.h"
42 #include "gin/public/isolate_holder.h"
43 #include "gin/v8_initializer.h"
44 #include "gpu/command_buffer/service/gpu_switches.h"
45 #include "gpu/ipc/gl_in_process_context.h"
46 #include "media/base/media_switches.h"
47 #include "media/media_features.h"
48 #include "ui/base/resource/resource_bundle.h"
49 #include "ui/events/gesture_detection/gesture_configuration.h"
50
51 namespace android_webview {
52
53 AwMainDelegate::AwMainDelegate() {
54 }
55
56 AwMainDelegate::~AwMainDelegate() {
57 }
58
59 bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
60 content::SetContentClient(&content_client_);
61
62 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
63
64 // WebView uses the Android system's scrollbars and overscroll glow.
65 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
66
67 // Pull-to-refresh should never be a default WebView action.
68 cl->AppendSwitch(switches::kDisablePullToRefreshEffect);
69
70 // Not yet supported in single-process mode.
71 cl->AppendSwitch(switches::kDisableSharedWorkers);
72
73 // File system API not supported (requires some new API; internal bug 6930981)
74 cl->AppendSwitch(switches::kDisableFileSystem);
75
76 // Web Notification API and the Push API are not supported (crbug.com/434712)
77 cl->AppendSwitch(switches::kDisableNotifications);
78
79 // WebRTC hardware decoding is not supported, internal bug 15075307
80 #if BUILDFLAG(ENABLE_WEBRTC)
81 cl->AppendSwitch(switches::kDisableWebRtcHWDecoding);
82 #endif
83
84 // This is needed for sharing textures across the different GL threads.
85 cl->AppendSwitch(switches::kEnableThreadedTextureMailboxes);
86
87 // WebView does not yet support screen orientation locking.
88 cl->AppendSwitch(switches::kDisableScreenOrientationLock);
89
90 // WebView does not currently support Web Speech API (crbug.com/487255)
91 cl->AppendSwitch(switches::kDisableSpeechAPI);
92
93 // WebView does not currently support the Permissions API (crbug.com/490120)
94 cl->AppendSwitch(switches::kDisablePermissionsAPI);
95
96 // WebView does not (yet) save Chromium data during shutdown, so add setting
97 // for Chrome to aggressively persist DOM Storage to minimize data loss.
98 // http://crbug.com/479767
99 cl->AppendSwitch(switches::kEnableAggressiveDOMStorageFlushing);
100
101 // Webview does not currently support the Presentation API, see
102 // https://crbug.com/521319
103 cl->AppendSwitch(switches::kDisablePresentationAPI);
104
105 // WebView doesn't support Remote Playback API for the same reason as the
106 // Presentation API, see https://crbug.com/521319.
107 cl->AppendSwitch(switches::kDisableRemotePlaybackAPI);
108
109 // WebView does not support MediaSession API since there's no UI for media
110 // metadata and controls.
111 cl->AppendSwitch(switches::kDisableMediaSessionAPI);
112
113 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
114 if (cl->GetSwitchValueASCII(switches::kProcessType).empty()) {
115 // Browser process (no type specified).
116
117 content::RegisterMediaUrlInterceptor(new AwMediaUrlInterceptor());
118 BrowserViewRenderer::CalculateTileMemoryPolicy();
119 // WebView apps can override WebView#computeScroll to achieve custom
120 // scroll/fling. As a result, fling animations may not be ticked,
121 // potentially
122 // confusing the tap suppression controller. Simply disable it for WebView
123 ui::GestureConfiguration::GetInstance()
124 ->set_fling_touchscreen_tap_suppression_enabled(false);
125
126 base::android::RegisterApkAssetWithFileDescriptorStore(
127 content::kV8NativesDataDescriptor,
128 gin::V8Initializer::GetNativesFilePath());
129 base::android::RegisterApkAssetWithFileDescriptorStore(
130 content::kV8Snapshot32DataDescriptor,
131 gin::V8Initializer::GetSnapshotFilePath(true));
132 base::android::RegisterApkAssetWithFileDescriptorStore(
133 content::kV8Snapshot64DataDescriptor,
134 gin::V8Initializer::GetSnapshotFilePath(false));
135 }
136 #endif // V8_USE_EXTERNAL_STARTUP_DATA
137
138 if (cl->HasSwitch(switches::kWebViewSandboxedRenderer)) {
139 cl->AppendSwitch(switches::kInProcessGPU);
140 cl->AppendSwitchASCII(switches::kRendererProcessLimit, "1");
141 cl->AppendSwitch(switches::kDisableRendererPriorityManagement);
142 }
143
144 CommandLineHelper::AddEnabledFeature(
145 *cl, spellcheck::kAndroidSpellCheckerNonLowEnd.name);
146
147 CommandLineHelper::AddDisabledFeature(*cl, features::kWebPayments.name);
148
149 android_webview::RegisterPathProvider();
150
151 safe_browsing_api_handler_.reset(
152 new safe_browsing::SafeBrowsingApiHandlerBridge());
153 safe_browsing::SafeBrowsingApiHandler::SetInstance(
154 safe_browsing_api_handler_.get());
155
156 return false;
157 }
158
159 void AwMainDelegate::PreSandboxStartup() {
160 #if defined(ARCH_CPU_ARM_FAMILY)
161 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
162 // cpu_brand info.
163 base::CPU cpu_info;
164 #endif
165
166 const base::CommandLine& command_line =
167 *base::CommandLine::ForCurrentProcess();
168 std::string process_type =
169 command_line.GetSwitchValueASCII(switches::kProcessType);
170 int crash_signal_fd = -1;
171 if (process_type == switches::kRendererProcess) {
172 auto* global_descriptors = base::GlobalDescriptors::GetInstance();
173 int pak_fd = global_descriptors->Get(kAndroidWebViewLocalePakDescriptor);
174 base::MemoryMappedFile::Region pak_region =
175 global_descriptors->GetRegion(kAndroidWebViewLocalePakDescriptor);
176 ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd),
177 pak_region);
178
179 std::pair<int, ui::ScaleFactor> extra_paks[] = {
180 {kAndroidWebViewMainPakDescriptor, ui::SCALE_FACTOR_NONE},
181 {kAndroidWebView100PercentPakDescriptor, ui::SCALE_FACTOR_100P}};
182
183 for (const auto& pak_info : extra_paks) {
184 pak_fd = global_descriptors->Get(pak_info.first);
185 pak_region = global_descriptors->GetRegion(pak_info.first);
186 ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
187 base::File(pak_fd), pak_region, pak_info.second);
188 }
189
190 crash_signal_fd =
191 global_descriptors->Get(kAndroidWebViewCrashSignalDescriptor);
192 }
193 if (process_type.empty()) {
194 if (command_line.HasSwitch(switches::kWebViewSandboxedRenderer)) {
195 process_type = breakpad::kBrowserProcessType;
196 } else {
197 process_type = breakpad::kWebViewSingleProcessType;
198 }
199 }
200
201 crash_reporter::EnableCrashReporter(process_type, crash_signal_fd);
202
203 base::android::BuildInfo* android_build_info =
204 base::android::BuildInfo::GetInstance();
205 base::debug::SetCrashKeyValue(crash_keys::kAppPackageName,
206 android_build_info->package_name());
207 base::debug::SetCrashKeyValue(crash_keys::kAppPackageVersionCode,
208 android_build_info->package_version_code());
209 base::debug::SetCrashKeyValue(
210 crash_keys::kAndroidSdkInt,
211 base::IntToString(android_build_info->sdk_int()));
212 }
213
214 int AwMainDelegate::RunProcess(
215 const std::string& process_type,
216 const content::MainFunctionParams& main_function_params) {
217 if (process_type.empty()) {
218 browser_runner_.reset(content::BrowserMainRunner::Create());
219 int exit_code = browser_runner_->Initialize(main_function_params);
220 DCHECK_LT(exit_code, 0);
221
222 // At this point the content client has received the GPU info required
223 // to create a GPU fingerpring, and we can pass it to the microdump
224 // crash handler on the same thread as the crash handler was initialized.
225 crash_reporter::AddGpuFingerprintToMicrodumpCrashHandler(
226 content_client_.gpu_fingerprint());
227
228 // Return 0 so that we do NOT trigger the default behavior. On Android, the
229 // UI message loop is managed by the Java application.
230 return 0;
231 }
232
233 return -1;
234 }
235
236 void AwMainDelegate::ProcessExiting(const std::string& process_type) {
237 // TODO(torne): Clean up resources when we handle them.
238
239 logging::CloseLogFile();
240 }
241
242 content::ContentBrowserClient*
243 AwMainDelegate::CreateContentBrowserClient() {
244 content_browser_client_.reset(new AwContentBrowserClient());
245 return content_browser_client_.get();
246 }
247
248 namespace {
249 gpu::SyncPointManager* GetSyncPointManager() {
250 DCHECK(DeferredGpuCommandService::GetInstance());
251 return DeferredGpuCommandService::GetInstance()->sync_point_manager();
252 }
253 } // namespace
254
255 content::ContentGpuClient* AwMainDelegate::CreateContentGpuClient() {
256 content_gpu_client_.reset(
257 new AwContentGpuClient(base::Bind(&GetSyncPointManager)));
258 return content_gpu_client_.get();
259 }
260
261 content::ContentRendererClient*
262 AwMainDelegate::CreateContentRendererClient() {
263 content_renderer_client_.reset(new AwContentRendererClient());
264 return content_renderer_client_.get();
265 }
266
267 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/lib/main/aw_main_delegate.h ('k') | android_webview/lib/main/webview_entry_point.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698