OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/browser/cast_content_browser_client.h" | 5 #include "chromecast/browser/cast_content_browser_client.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/scoped_file.h" | 11 #include "base/files/scoped_file.h" |
| 12 #include "base/i18n/icu_util.h" |
12 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "chromecast/base/cast_paths.h" | 15 #include "chromecast/base/cast_paths.h" |
15 #include "chromecast/base/chromecast_switches.h" | 16 #include "chromecast/base/chromecast_switches.h" |
16 #include "chromecast/browser/cast_browser_context.h" | 17 #include "chromecast/browser/cast_browser_context.h" |
17 #include "chromecast/browser/cast_browser_main_parts.h" | 18 #include "chromecast/browser/cast_browser_main_parts.h" |
18 #include "chromecast/browser/cast_browser_process.h" | 19 #include "chromecast/browser/cast_browser_process.h" |
19 #include "chromecast/browser/cast_network_delegate.h" | 20 #include "chromecast/browser/cast_network_delegate.h" |
20 #include "chromecast/browser/cast_quota_permission_context.h" | 21 #include "chromecast/browser/cast_quota_permission_context.h" |
21 #include "chromecast/browser/cast_resource_dispatcher_host_delegate.h" | 22 #include "chromecast/browser/cast_resource_dispatcher_host_delegate.h" |
22 #include "chromecast/browser/geolocation/cast_access_token_store.h" | 23 #include "chromecast/browser/geolocation/cast_access_token_store.h" |
23 #include "chromecast/browser/media/cma_message_filter_host.h" | 24 #include "chromecast/browser/media/cma_message_filter_host.h" |
24 #include "chromecast/browser/url_request_context_factory.h" | 25 #include "chromecast/browser/url_request_context_factory.h" |
25 #include "chromecast/common/global_descriptors.h" | 26 #include "chromecast/common/global_descriptors.h" |
26 #include "chromecast/media/cma/backend/media_pipeline_device.h" | 27 #include "chromecast/media/cma/backend/media_pipeline_device.h" |
27 #include "components/crash/app/breakpad_linux.h" | 28 #include "components/crash/app/breakpad_linux.h" |
28 #include "components/crash/browser/crash_handler_host_linux.h" | 29 #include "components/crash/browser/crash_handler_host_linux.h" |
29 #include "components/network_hints/browser/network_hints_message_filter.h" | 30 #include "components/network_hints/browser/network_hints_message_filter.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/certificate_request_result_type.h" | 32 #include "content/public/browser/certificate_request_result_type.h" |
32 #include "content/public/browser/client_certificate_delegate.h" | 33 #include "content/public/browser/client_certificate_delegate.h" |
33 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
34 #include "content/public/browser/resource_dispatcher_host.h" | 35 #include "content/public/browser/resource_dispatcher_host.h" |
35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
36 #include "content/public/common/content_descriptors.h" | 37 #include "content/public/common/content_descriptors.h" |
37 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
38 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
39 #include "content/public/common/web_preferences.h" | 40 #include "content/public/common/web_preferences.h" |
| 41 #include "gin/v8_initializer.h" |
40 #include "media/audio/audio_manager_factory.h" | 42 #include "media/audio/audio_manager_factory.h" |
41 #include "net/ssl/ssl_cert_request_info.h" | 43 #include "net/ssl/ssl_cert_request_info.h" |
42 #include "net/url_request/url_request_context_getter.h" | 44 #include "net/url_request/url_request_context_getter.h" |
43 #include "ui/gl/gl_switches.h" | 45 #include "ui/gl/gl_switches.h" |
44 | 46 |
45 #if defined(OS_ANDROID) | 47 #if defined(OS_ANDROID) |
46 #include "components/crash/browser/crash_dump_manager_android.h" | 48 #include "components/crash/browser/crash_dump_manager_android.h" |
47 #include "components/external_video_surface/browser/android/external_video_surfa
ce_container_impl.h" | 49 #include "components/external_video_surface/browser/android/external_video_surfa
ce_container_impl.h" |
48 #endif // defined(OS_ANDROID) | 50 #endif // defined(OS_ANDROID) |
49 | 51 |
50 namespace chromecast { | 52 namespace chromecast { |
51 namespace shell { | 53 namespace shell { |
52 | 54 |
53 CastContentBrowserClient::CastContentBrowserClient() | 55 CastContentBrowserClient::CastContentBrowserClient() |
54 : url_request_context_factory_(new URLRequestContextFactory()) { | 56 : v8_natives_fd_(-1), |
| 57 v8_snapshot_fd_(-1), |
| 58 url_request_context_factory_(new URLRequestContextFactory()) { |
55 } | 59 } |
56 | 60 |
57 CastContentBrowserClient::~CastContentBrowserClient() { | 61 CastContentBrowserClient::~CastContentBrowserClient() { |
58 content::BrowserThread::DeleteSoon( | 62 content::BrowserThread::DeleteSoon( |
59 content::BrowserThread::IO, | 63 content::BrowserThread::IO, |
60 FROM_HERE, | 64 FROM_HERE, |
61 url_request_context_factory_.release()); | 65 url_request_context_factory_.release()); |
62 } | 66 } |
63 | 67 |
64 void CastContentBrowserClient::AppendExtraCommandLineSwitches( | 68 void CastContentBrowserClient::AppendExtraCommandLineSwitches( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 168 } |
165 | 169 |
166 if (scheme == url::kFileScheme) { | 170 if (scheme == url::kFileScheme) { |
167 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 171 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
168 switches::kEnableLocalFileAccesses); | 172 switches::kEnableLocalFileAccesses); |
169 } | 173 } |
170 | 174 |
171 return false; | 175 return false; |
172 } | 176 } |
173 | 177 |
| 178 void CastContentBrowserClient::AppendMappedFileCommandLineSwitches( |
| 179 base::CommandLine* command_line) { |
| 180 std::string process_type = |
| 181 command_line->GetSwitchValueNative(switches::kProcessType); |
| 182 |
| 183 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 184 if (process_type != switches::kZygoteProcess) { |
| 185 DCHECK(natives_fd_exists()); |
| 186 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); |
| 187 if (snapshot_fd_exists()) |
| 188 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); |
| 189 } |
| 190 } |
| 191 |
| 192 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
174 void CastContentBrowserClient::AppendExtraCommandLineSwitches( | 193 void CastContentBrowserClient::AppendExtraCommandLineSwitches( |
175 base::CommandLine* command_line, | 194 base::CommandLine* command_line, |
176 int child_process_id) { | 195 int child_process_id) { |
177 std::string process_type = | 196 std::string process_type = |
178 command_line->GetSwitchValueNative(switches::kProcessType); | 197 command_line->GetSwitchValueNative(switches::kProcessType); |
179 base::CommandLine* browser_command_line = | 198 base::CommandLine* browser_command_line = |
180 base::CommandLine::ForCurrentProcess(); | 199 base::CommandLine::ForCurrentProcess(); |
181 | 200 |
182 // IsCrashReporterEnabled() is set when InitCrashReporter() is called, and | 201 // IsCrashReporterEnabled() is set when InitCrashReporter() is called, and |
183 // controlled by GetBreakpadClient()->EnableBreakpadForProcess(), therefore | 202 // controlled by GetBreakpadClient()->EnableBreakpadForProcess(), therefore |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 int opener_render_frame_id, | 345 int opener_render_frame_id, |
327 bool* no_javascript_access) { | 346 bool* no_javascript_access) { |
328 *no_javascript_access = true; | 347 *no_javascript_access = true; |
329 return false; | 348 return false; |
330 } | 349 } |
331 | 350 |
332 void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 351 void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
333 const base::CommandLine& command_line, | 352 const base::CommandLine& command_line, |
334 int child_process_id, | 353 int child_process_id, |
335 content::FileDescriptorInfo* mappings) { | 354 content::FileDescriptorInfo* mappings) { |
| 355 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 356 if (!natives_fd_exists()) { |
| 357 int v8_natives_fd = -1; |
| 358 int v8_snapshot_fd = -1; |
| 359 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd, |
| 360 &v8_snapshot_fd)) { |
| 361 v8_natives_fd_.reset(v8_natives_fd); |
| 362 v8_snapshot_fd_.reset(v8_snapshot_fd); |
| 363 } |
| 364 } |
| 365 // V8 can't start up without the source of the natives, but it can |
| 366 // start up (slower) without the snapshot. |
| 367 DCHECK(natives_fd_exists()); |
| 368 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); |
| 369 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); |
| 370 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
336 #if defined(OS_ANDROID) | 371 #if defined(OS_ANDROID) |
337 const int flags_open_read = base::File::FLAG_OPEN | base::File::FLAG_READ; | 372 const int flags_open_read = base::File::FLAG_OPEN | base::File::FLAG_READ; |
338 base::FilePath pak_file_path; | 373 base::FilePath pak_file_path; |
339 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file_path)); | 374 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file_path)); |
340 base::File pak_file(pak_file_path, flags_open_read); | 375 base::File pak_file(pak_file_path, flags_open_read); |
341 if (!pak_file.IsValid()) { | 376 if (!pak_file.IsValid()) { |
342 NOTREACHED() << "Failed to open file when creating renderer process: " | 377 NOTREACHED() << "Failed to open file when creating renderer process: " |
343 << "cast_shell.pak"; | 378 << "cast_shell.pak"; |
344 } | 379 } |
345 mappings->Transfer(kAndroidPakDescriptor, | 380 mappings->Transfer(kAndroidPakDescriptor, |
346 base::ScopedFD(pak_file.TakePlatformFile())); | 381 base::ScopedFD(pak_file.TakePlatformFile())); |
347 | 382 |
348 if (breakpad::IsCrashReporterEnabled()) { | 383 if (breakpad::IsCrashReporterEnabled()) { |
349 base::File minidump_file( | 384 base::File minidump_file( |
350 breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile( | 385 breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile( |
351 child_process_id)); | 386 child_process_id)); |
352 if (!minidump_file.IsValid()) { | 387 if (!minidump_file.IsValid()) { |
353 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " | 388 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " |
354 << "be disabled for this process."; | 389 << "be disabled for this process."; |
355 } else { | 390 } else { |
356 mappings->Transfer(kAndroidMinidumpDescriptor, | 391 mappings->Transfer(kAndroidMinidumpDescriptor, |
357 base::ScopedFD(minidump_file.TakePlatformFile())); | 392 base::ScopedFD(minidump_file.TakePlatformFile())); |
358 } | 393 } |
359 } | 394 } |
| 395 |
| 396 base::FilePath app_data_path; |
| 397 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path)); |
| 398 base::FilePath icudata_path = |
| 399 app_data_path.AppendASCII(base::i18n::kIcuDataFileName); |
| 400 base::File icudata_file(icudata_path, flags_open_read); |
| 401 if (!icudata_file.IsValid()) |
| 402 NOTREACHED() << "Failed to open ICU file when creating renderer process"; |
| 403 mappings->Transfer(kAndroidICUDataDescriptor, |
| 404 base::ScopedFD(icudata_file.TakePlatformFile())); |
360 #else | 405 #else |
361 int crash_signal_fd = GetCrashSignalFD(command_line); | 406 int crash_signal_fd = GetCrashSignalFD(command_line); |
362 if (crash_signal_fd >= 0) { | 407 if (crash_signal_fd >= 0) { |
363 mappings->Share(kCrashDumpSignal, crash_signal_fd); | 408 mappings->Share(kCrashDumpSignal, crash_signal_fd); |
364 } | 409 } |
365 #endif // defined(OS_ANDROID) | 410 #endif // defined(OS_ANDROID) |
366 } | 411 } |
367 | 412 |
368 #if defined(OS_ANDROID) && defined(VIDEO_HOLE) | 413 #if defined(OS_ANDROID) && defined(VIDEO_HOLE) |
369 content::ExternalVideoSurfaceContainer* | 414 content::ExternalVideoSurfaceContainer* |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 process_type, dumps_path, false /* upload */); | 453 process_type, dumps_path, false /* upload */); |
409 // StartUploaderThread() even though upload is diferred. | 454 // StartUploaderThread() even though upload is diferred. |
410 // Breakpad-related memory is freed in the uploader thread. | 455 // Breakpad-related memory is freed in the uploader thread. |
411 crash_handler->StartUploaderThread(); | 456 crash_handler->StartUploaderThread(); |
412 return crash_handler; | 457 return crash_handler; |
413 } | 458 } |
414 #endif // !defined(OS_ANDROID) | 459 #endif // !defined(OS_ANDROID) |
415 | 460 |
416 } // namespace shell | 461 } // namespace shell |
417 } // namespace chromecast | 462 } // namespace chromecast |
OLD | NEW |