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