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 "components/crash/app/breakpad_linux.h" | 27 #include "components/crash/app/breakpad_linux.h" |
29 #include "components/crash/browser/crash_handler_host_linux.h" | 28 #include "components/crash/browser/crash_handler_host_linux.h" |
30 #include "components/network_hints/browser/network_hints_message_filter.h" | 29 #include "components/network_hints/browser/network_hints_message_filter.h" |
31 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/certificate_request_result_type.h" | 31 #include "content/public/browser/certificate_request_result_type.h" |
33 #include "content/public/browser/client_certificate_delegate.h" | 32 #include "content/public/browser/client_certificate_delegate.h" |
34 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
35 #include "content/public/browser/resource_dispatcher_host.h" | 34 #include "content/public/browser/resource_dispatcher_host.h" |
36 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
37 #include "content/public/common/content_descriptors.h" | 36 #include "content/public/common/content_descriptors.h" |
38 #include "content/public/common/content_switches.h" | 37 #include "content/public/common/content_switches.h" |
39 #include "content/public/common/url_constants.h" | 38 #include "content/public/common/url_constants.h" |
40 #include "content/public/common/web_preferences.h" | 39 #include "content/public/common/web_preferences.h" |
41 #include "gin/v8_initializer.h" | |
42 #include "media/audio/audio_manager_factory.h" | 40 #include "media/audio/audio_manager_factory.h" |
43 #include "net/ssl/ssl_cert_request_info.h" | 41 #include "net/ssl/ssl_cert_request_info.h" |
44 #include "net/url_request/url_request_context_getter.h" | 42 #include "net/url_request/url_request_context_getter.h" |
45 #include "ui/gl/gl_switches.h" | 43 #include "ui/gl/gl_switches.h" |
46 | 44 |
47 #if defined(OS_ANDROID) | 45 #if defined(OS_ANDROID) |
48 #include "components/crash/browser/crash_dump_manager_android.h" | 46 #include "components/crash/browser/crash_dump_manager_android.h" |
49 #include "components/external_video_surface/browser/android/external_video_surfa
ce_container_impl.h" | 47 #include "components/external_video_surface/browser/android/external_video_surfa
ce_container_impl.h" |
50 #endif // defined(OS_ANDROID) | 48 #endif // defined(OS_ANDROID) |
51 | 49 |
52 namespace chromecast { | 50 namespace chromecast { |
53 namespace shell { | 51 namespace shell { |
54 | 52 |
55 CastContentBrowserClient::CastContentBrowserClient() | 53 CastContentBrowserClient::CastContentBrowserClient() |
56 : v8_natives_fd_(-1), | 54 : url_request_context_factory_(new URLRequestContextFactory()) { |
57 v8_snapshot_fd_(-1), | |
58 url_request_context_factory_(new URLRequestContextFactory()) { | |
59 } | 55 } |
60 | 56 |
61 CastContentBrowserClient::~CastContentBrowserClient() { | 57 CastContentBrowserClient::~CastContentBrowserClient() { |
62 content::BrowserThread::DeleteSoon( | 58 content::BrowserThread::DeleteSoon( |
63 content::BrowserThread::IO, | 59 content::BrowserThread::IO, |
64 FROM_HERE, | 60 FROM_HERE, |
65 url_request_context_factory_.release()); | 61 url_request_context_factory_.release()); |
66 } | 62 } |
67 | 63 |
68 void CastContentBrowserClient::AppendExtraCommandLineSwitches( | 64 void CastContentBrowserClient::AppendExtraCommandLineSwitches( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 164 } |
169 | 165 |
170 if (scheme == url::kFileScheme) { | 166 if (scheme == url::kFileScheme) { |
171 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 167 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
172 switches::kEnableLocalFileAccesses); | 168 switches::kEnableLocalFileAccesses); |
173 } | 169 } |
174 | 170 |
175 return false; | 171 return false; |
176 } | 172 } |
177 | 173 |
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 | |
193 void CastContentBrowserClient::AppendExtraCommandLineSwitches( | 174 void CastContentBrowserClient::AppendExtraCommandLineSwitches( |
194 base::CommandLine* command_line, | 175 base::CommandLine* command_line, |
195 int child_process_id) { | 176 int child_process_id) { |
196 std::string process_type = | 177 std::string process_type = |
197 command_line->GetSwitchValueNative(switches::kProcessType); | 178 command_line->GetSwitchValueNative(switches::kProcessType); |
198 base::CommandLine* browser_command_line = | 179 base::CommandLine* browser_command_line = |
199 base::CommandLine::ForCurrentProcess(); | 180 base::CommandLine::ForCurrentProcess(); |
200 | 181 |
201 // IsCrashReporterEnabled() is set when InitCrashReporter() is called, and | 182 // IsCrashReporterEnabled() is set when InitCrashReporter() is called, and |
202 // controlled by GetBreakpadClient()->EnableBreakpadForProcess(), therefore | 183 // controlled by GetBreakpadClient()->EnableBreakpadForProcess(), therefore |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 int opener_render_frame_id, | 326 int opener_render_frame_id, |
346 bool* no_javascript_access) { | 327 bool* no_javascript_access) { |
347 *no_javascript_access = true; | 328 *no_javascript_access = true; |
348 return false; | 329 return false; |
349 } | 330 } |
350 | 331 |
351 void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 332 void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
352 const base::CommandLine& command_line, | 333 const base::CommandLine& command_line, |
353 int child_process_id, | 334 int child_process_id, |
354 content::FileDescriptorInfo* mappings) { | 335 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 | |
371 #if defined(OS_ANDROID) | 336 #if defined(OS_ANDROID) |
372 const int flags_open_read = base::File::FLAG_OPEN | base::File::FLAG_READ; | 337 const int flags_open_read = base::File::FLAG_OPEN | base::File::FLAG_READ; |
373 base::FilePath pak_file_path; | 338 base::FilePath pak_file_path; |
374 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file_path)); | 339 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file_path)); |
375 base::File pak_file(pak_file_path, flags_open_read); | 340 base::File pak_file(pak_file_path, flags_open_read); |
376 if (!pak_file.IsValid()) { | 341 if (!pak_file.IsValid()) { |
377 NOTREACHED() << "Failed to open file when creating renderer process: " | 342 NOTREACHED() << "Failed to open file when creating renderer process: " |
378 << "cast_shell.pak"; | 343 << "cast_shell.pak"; |
379 } | 344 } |
380 mappings->Transfer(kAndroidPakDescriptor, | 345 mappings->Transfer(kAndroidPakDescriptor, |
381 base::ScopedFD(pak_file.TakePlatformFile())); | 346 base::ScopedFD(pak_file.TakePlatformFile())); |
382 | 347 |
383 if (breakpad::IsCrashReporterEnabled()) { | 348 if (breakpad::IsCrashReporterEnabled()) { |
384 base::File minidump_file( | 349 base::File minidump_file( |
385 breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile( | 350 breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile( |
386 child_process_id)); | 351 child_process_id)); |
387 if (!minidump_file.IsValid()) { | 352 if (!minidump_file.IsValid()) { |
388 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " | 353 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " |
389 << "be disabled for this process."; | 354 << "be disabled for this process."; |
390 } else { | 355 } else { |
391 mappings->Transfer(kAndroidMinidumpDescriptor, | 356 mappings->Transfer(kAndroidMinidumpDescriptor, |
392 base::ScopedFD(minidump_file.TakePlatformFile())); | 357 base::ScopedFD(minidump_file.TakePlatformFile())); |
393 } | 358 } |
394 } | 359 } |
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())); | |
405 #else | 360 #else |
406 int crash_signal_fd = GetCrashSignalFD(command_line); | 361 int crash_signal_fd = GetCrashSignalFD(command_line); |
407 if (crash_signal_fd >= 0) { | 362 if (crash_signal_fd >= 0) { |
408 mappings->Share(kCrashDumpSignal, crash_signal_fd); | 363 mappings->Share(kCrashDumpSignal, crash_signal_fd); |
409 } | 364 } |
410 #endif // defined(OS_ANDROID) | 365 #endif // defined(OS_ANDROID) |
411 } | 366 } |
412 | 367 |
413 #if defined(OS_ANDROID) && defined(VIDEO_HOLE) | 368 #if defined(OS_ANDROID) && defined(VIDEO_HOLE) |
414 content::ExternalVideoSurfaceContainer* | 369 content::ExternalVideoSurfaceContainer* |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 process_type, dumps_path, false /* upload */); | 408 process_type, dumps_path, false /* upload */); |
454 // StartUploaderThread() even though upload is diferred. | 409 // StartUploaderThread() even though upload is diferred. |
455 // Breakpad-related memory is freed in the uploader thread. | 410 // Breakpad-related memory is freed in the uploader thread. |
456 crash_handler->StartUploaderThread(); | 411 crash_handler->StartUploaderThread(); |
457 return crash_handler; | 412 return crash_handler; |
458 } | 413 } |
459 #endif // !defined(OS_ANDROID) | 414 #endif // !defined(OS_ANDROID) |
460 | 415 |
461 } // namespace shell | 416 } // namespace shell |
462 } // namespace chromecast | 417 } // namespace chromecast |
OLD | NEW |