| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ash/shell/content_client/shell_content_browser_client.h" | 5 #include "ash/shell/content_client/shell_content_browser_client.h" |
| 6 | 6 |
| 7 #include "ash/shell/content_client/shell_browser_main_parts.h" | 7 #include "ash/shell/content_client/shell_browser_main_parts.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "content/public/common/content_descriptors.h" | 9 #include "content/public/common/content_descriptors.h" |
| 10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 11 #include "content/shell/browser/shell_browser_context.h" | 11 #include "content/shell/browser/shell_browser_context.h" |
| 12 #include "gin/v8_initializer.h" | 12 #include "gin/v8_initializer.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 | 14 |
| 15 namespace ash { | 15 namespace ash { |
| 16 namespace shell { | 16 namespace shell { |
| 17 | 17 |
| 18 ShellContentBrowserClient::ShellContentBrowserClient() | 18 ShellContentBrowserClient::ShellContentBrowserClient() |
| 19 : | 19 : shell_browser_main_parts_(nullptr) { |
| 20 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 21 v8_natives_fd_(-1), | |
| 22 v8_snapshot_fd_(-1), | |
| 23 #endif // OS_POSIX && !OS_MACOSX | |
| 24 shell_browser_main_parts_(nullptr) { | |
| 25 } | 20 } |
| 26 | 21 |
| 27 ShellContentBrowserClient::~ShellContentBrowserClient() { | 22 ShellContentBrowserClient::~ShellContentBrowserClient() { |
| 28 } | 23 } |
| 29 | 24 |
| 30 content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( | 25 content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( |
| 31 const content::MainFunctionParams& parameters) { | 26 const content::MainFunctionParams& parameters) { |
| 32 shell_browser_main_parts_ = new ShellBrowserMainParts(parameters); | 27 shell_browser_main_parts_ = new ShellBrowserMainParts(parameters); |
| 33 return shell_browser_main_parts_; | 28 return shell_browser_main_parts_; |
| 34 } | 29 } |
| 35 | 30 |
| 36 net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext( | 31 net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext( |
| 37 content::BrowserContext* content_browser_context, | 32 content::BrowserContext* content_browser_context, |
| 38 content::ProtocolHandlerMap* protocol_handlers, | 33 content::ProtocolHandlerMap* protocol_handlers, |
| 39 content::URLRequestInterceptorScopedVector request_interceptors) { | 34 content::URLRequestInterceptorScopedVector request_interceptors) { |
| 40 content::ShellBrowserContext* shell_context = | 35 content::ShellBrowserContext* shell_context = |
| 41 static_cast<content::ShellBrowserContext*>(content_browser_context); | 36 static_cast<content::ShellBrowserContext*>(content_browser_context); |
| 42 return shell_context->CreateRequestContext(protocol_handlers, | 37 return shell_context->CreateRequestContext(protocol_handlers, |
| 43 request_interceptors.Pass()); | 38 request_interceptors.Pass()); |
| 44 } | 39 } |
| 45 | 40 |
| 46 void ShellContentBrowserClient::AppendMappedFileCommandLineSwitches( | 41 void ShellContentBrowserClient::AppendMappedFileCommandLineSwitches( |
| 47 base::CommandLine* command_line) { | 42 base::CommandLine* command_line) { |
| 48 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 43 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 49 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 44 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 50 std::string process_type = | 45 std::string process_type = |
| 51 command_line->GetSwitchValueASCII(switches::kProcessType); | 46 command_line->GetSwitchValueASCII(switches::kProcessType); |
| 52 if (process_type != switches::kZygoteProcess) { | 47 if (process_type != switches::kZygoteProcess) { |
| 53 DCHECK(natives_fd_exists()); | 48 DCHECK(v8_files_.natives_fd.is_valid()); |
| 54 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); | 49 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); |
| 55 if (snapshot_fd_exists()) | 50 if (v8_files_.snapshot_fd.is_valid()) { |
| 56 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | 51 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); |
| 52 } |
| 57 } | 53 } |
| 58 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 54 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 59 #endif // OS_POSIX && !OS_MACOSX | 55 #endif // OS_POSIX && !OS_MACOSX |
| 60 } | 56 } |
| 61 | 57 |
| 62 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 58 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 63 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 59 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
| 64 const base::CommandLine& command_line, | 60 const base::CommandLine& command_line, |
| 65 int child_process_id, | 61 int child_process_id, |
| 66 content::FileDescriptorInfo* mappings | 62 content::FileDescriptorInfo* mappings |
| 67 #if defined(OS_ANDROID) | 63 #if defined(OS_ANDROID) |
| 68 , std::map<int, base::MemoryMappedFile::Region>* regions | 64 , std::map<int, base::MemoryMappedFile::Region>* regions |
| 69 #endif | 65 #endif |
| 70 ) { | 66 ) { |
| 71 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 67 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 72 if (!natives_fd_exists()) { | 68 if (!v8_files_.natives_fd.is_valid()) { |
| 73 int v8_natives_fd = -1; | 69 gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_files_); |
| 74 int v8_snapshot_fd = -1; | |
| 75 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd, | |
| 76 &v8_snapshot_fd)) { | |
| 77 v8_natives_fd_.reset(v8_natives_fd); | |
| 78 v8_snapshot_fd_.reset(v8_snapshot_fd); | |
| 79 } | |
| 80 } | 70 } |
| 81 // V8 can't start up without the source of the natives, but it can | 71 DCHECK(v8_files_.natives_fd.is_valid()); |
| 82 // start up (slower) without the snapshot. | 72 mappings->Share(kV8NativesDataDescriptor, v8_files_.natives_fd.get()); |
| 83 DCHECK(natives_fd_exists()); | 73 #if defined(OS_ANDROID) |
| 84 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); | 74 regions->insert( |
| 85 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); | 75 std::make_pair(kV8NativesDataDescriptor, v8_files_.natives_region)); |
| 76 #endif |
| 77 if (v8_files_.snapshot_fd.is_valid()) { |
| 78 mappings->Share(kV8SnapshotDataDescriptor, v8_files_.snapshot_fd.get()); |
| 79 #if defined(OS_ANDROID) |
| 80 regions->insert( |
| 81 std::make_pair(kV8SnapshotDataDescriptor, v8_files_.snapshot_region)); |
| 82 #endif |
| 83 } |
| 86 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 84 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 87 } | 85 } |
| 88 #endif // OS_POSIX && !OS_MACOSX | 86 #endif // OS_POSIX && !OS_MACOSX |
| 89 | 87 |
| 90 content::ShellBrowserContext* ShellContentBrowserClient::browser_context() { | 88 content::ShellBrowserContext* ShellContentBrowserClient::browser_context() { |
| 91 return shell_browser_main_parts_->browser_context(); | 89 return shell_browser_main_parts_->browser_context(); |
| 92 } | 90 } |
| 93 | 91 |
| 94 } // namespace examples | 92 } // namespace examples |
| 95 } // namespace views | 93 } // namespace views |
| OLD | NEW |