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