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 "extensions/shell/browser/shell_content_browser_client.h" | 5 #include "extensions/shell/browser/shell_content_browser_client.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "components/guest_view/browser/guest_view_message_filter.h" | 8 #include "components/guest_view/browser/guest_view_message_filter.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "extensions/browser/info_map.h" | 21 #include "extensions/browser/info_map.h" |
22 #include "extensions/browser/io_thread_extension_message_filter.h" | 22 #include "extensions/browser/io_thread_extension_message_filter.h" |
23 #include "extensions/browser/process_map.h" | 23 #include "extensions/browser/process_map.h" |
24 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "extensions/common/switches.h" | 26 #include "extensions/common/switches.h" |
27 #include "extensions/shell/browser/shell_browser_context.h" | 27 #include "extensions/shell/browser/shell_browser_context.h" |
28 #include "extensions/shell/browser/shell_browser_main_parts.h" | 28 #include "extensions/shell/browser/shell_browser_main_parts.h" |
29 #include "extensions/shell/browser/shell_extension_system.h" | 29 #include "extensions/shell/browser/shell_extension_system.h" |
30 #include "extensions/shell/browser/shell_speech_recognition_manager_delegate.h" | 30 #include "extensions/shell/browser/shell_speech_recognition_manager_delegate.h" |
31 #include "gin/v8_initializer.h" | |
32 #include "url/gurl.h" | 31 #include "url/gurl.h" |
33 | 32 |
34 #if !defined(DISABLE_NACL) | 33 #if !defined(DISABLE_NACL) |
35 #include "components/nacl/browser/nacl_browser.h" | 34 #include "components/nacl/browser/nacl_browser.h" |
36 #include "components/nacl/browser/nacl_host_message_filter.h" | 35 #include "components/nacl/browser/nacl_host_message_filter.h" |
37 #include "components/nacl/browser/nacl_process_host.h" | 36 #include "components/nacl/browser/nacl_process_host.h" |
38 #include "components/nacl/common/nacl_process_type.h" | 37 #include "components/nacl/common/nacl_process_type.h" |
39 #include "components/nacl/common/nacl_switches.h" | 38 #include "components/nacl/common/nacl_switches.h" |
40 #include "content/public/browser/browser_child_process_host.h" | 39 #include "content/public/browser/browser_child_process_host.h" |
41 #include "content/public/browser/child_process_data.h" | 40 #include "content/public/browser/child_process_data.h" |
42 #endif | 41 #endif |
43 | 42 |
44 using base::CommandLine; | 43 using base::CommandLine; |
45 using content::BrowserContext; | 44 using content::BrowserContext; |
46 using content::BrowserThread; | 45 using content::BrowserThread; |
47 | 46 |
48 namespace extensions { | 47 namespace extensions { |
49 namespace { | 48 namespace { |
50 | 49 |
51 ShellContentBrowserClient* g_instance = nullptr; | 50 ShellContentBrowserClient* g_instance = nullptr; |
52 | 51 |
53 } // namespace | 52 } // namespace |
54 | 53 |
55 ShellContentBrowserClient::ShellContentBrowserClient( | 54 ShellContentBrowserClient::ShellContentBrowserClient( |
56 ShellBrowserMainDelegate* browser_main_delegate) | 55 ShellBrowserMainDelegate* browser_main_delegate) |
57 : | 56 : browser_main_parts_(nullptr), |
58 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
59 v8_natives_fd_(-1), | |
60 v8_snapshot_fd_(-1), | |
61 #endif // OS_POSIX && !OS_MACOSX | |
62 browser_main_parts_(nullptr), | |
63 browser_main_delegate_(browser_main_delegate) { | 57 browser_main_delegate_(browser_main_delegate) { |
64 DCHECK(!g_instance); | 58 DCHECK(!g_instance); |
65 g_instance = this; | 59 g_instance = this; |
66 } | 60 } |
67 | 61 |
68 ShellContentBrowserClient::~ShellContentBrowserClient() { | 62 ShellContentBrowserClient::~ShellContentBrowserClient() { |
69 g_instance = nullptr; | 63 g_instance = nullptr; |
70 } | 64 } |
71 | 65 |
72 // static | 66 // static |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 FROM_HERE, | 189 FROM_HERE, |
196 base::Bind(&InfoMap::UnregisterExtensionProcess, | 190 base::Bind(&InfoMap::UnregisterExtensionProcess, |
197 browser_main_parts_->extension_system()->info_map(), | 191 browser_main_parts_->extension_system()->info_map(), |
198 extension->id(), | 192 extension->id(), |
199 site_instance->GetProcess()->GetID(), | 193 site_instance->GetProcess()->GetID(), |
200 site_instance->GetId())); | 194 site_instance->GetId())); |
201 } | 195 } |
202 | 196 |
203 void ShellContentBrowserClient::AppendMappedFileCommandLineSwitches( | 197 void ShellContentBrowserClient::AppendMappedFileCommandLineSwitches( |
204 base::CommandLine* command_line) { | 198 base::CommandLine* command_line) { |
205 std::string process_type = | |
206 command_line->GetSwitchValueASCII(::switches::kProcessType); | |
207 | |
208 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 199 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
209 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 200 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
210 DCHECK(natives_fd_exists()); | 201 std::string process_type = |
211 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); | 202 command_line->GetSwitchValueASCII(switches::kProcessType); |
212 if (snapshot_fd_exists()) | 203 if (process_type != switches::kZygoteProcess) { |
213 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | 204 DCHECK(v8_files_.natives_fd.is_valid()); |
205 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); | |
206 if (v8_files_.snapshot_fd.is_valid()) { | |
207 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | |
208 } | |
209 } | |
214 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 210 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
215 #endif // OS_POSIX && !OS_MACOSX | 211 #endif // OS_POSIX && !OS_MACOSX |
216 } | 212 } |
217 | 213 |
218 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( | 214 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
219 base::CommandLine* command_line, | 215 base::CommandLine* command_line, |
220 int child_process_id) { | 216 int child_process_id) { |
221 std::string process_type = | 217 std::string process_type = |
222 command_line->GetSwitchValueASCII(::switches::kProcessType); | 218 command_line->GetSwitchValueASCII(::switches::kProcessType); |
223 if (process_type == ::switches::kRendererProcess) | 219 if (process_type == ::switches::kRendererProcess) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 253 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
258 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | 254 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
259 const base::CommandLine& command_line, | 255 const base::CommandLine& command_line, |
260 int child_process_id, | 256 int child_process_id, |
261 content::FileDescriptorInfo* mappings | 257 content::FileDescriptorInfo* mappings |
262 #if defined(OS_ANDROID) | 258 #if defined(OS_ANDROID) |
263 , std::map<int, base::MemoryMappedFile::Region>* regions | 259 , std::map<int, base::MemoryMappedFile::Region>* regions |
264 #endif | 260 #endif |
265 ) { | 261 ) { |
266 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 262 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
267 if (!natives_fd_exists()) { | 263 if (!v8_files_.natives_fd.is_valid()) { |
268 int v8_natives_fd = -1; | 264 gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_files_); |
269 int v8_snapshot_fd = -1; | |
270 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd, | |
271 &v8_snapshot_fd)) { | |
272 v8_natives_fd_.reset(v8_natives_fd); | |
273 v8_snapshot_fd_.reset(v8_snapshot_fd); | |
274 } | |
275 } | 265 } |
276 // V8 can't start up without the source of the natives, but it can | 266 DCHECK(v8_files_.natives_fd.is_valid()); |
277 // start up (slower) without the snapshot. | 267 mappings->Share(kV8NativesDataDescriptor, v8_files_.natives_fd.get()); |
278 DCHECK(natives_fd_exists()); | 268 #if defined(OS_ANDROID) |
rmcilroy
2015/06/09 11:52:54
I don't think this needs to be #ifdef ANDROID - al
| |
279 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); | 269 regions->insert( |
280 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); | 270 std::make_pair(kV8NativesDataDescriptor, v8_files_.natives_region)); |
271 #endif | |
272 if (v8_files_.snapshot_fd.is_valid()) { | |
273 mappings->Share(kV8SnapshotDataDescriptor, v8_files_.snapshot_fd.get()); | |
274 #if defined(OS_ANDROID) | |
275 regions->insert( | |
276 std::make_pair(kV8SnapshotDataDescriptor, v8_files_.snapshot_region)); | |
277 #endif | |
278 } | |
281 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 279 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
282 } | 280 } |
283 #endif // OS_POSIX && !OS_MACOSX | 281 #endif // OS_POSIX && !OS_MACOSX |
284 | 282 |
285 content::DevToolsManagerDelegate* | 283 content::DevToolsManagerDelegate* |
286 ShellContentBrowserClient::GetDevToolsManagerDelegate() { | 284 ShellContentBrowserClient::GetDevToolsManagerDelegate() { |
287 return new content::ShellDevToolsManagerDelegate(GetBrowserContext()); | 285 return new content::ShellDevToolsManagerDelegate(GetBrowserContext()); |
288 } | 286 } |
289 | 287 |
290 ShellBrowserMainParts* ShellContentBrowserClient::CreateShellBrowserMainParts( | 288 ShellBrowserMainParts* ShellContentBrowserClient::CreateShellBrowserMainParts( |
(...skipping 22 matching lines...) Expand all Loading... | |
313 | 311 |
314 const Extension* ShellContentBrowserClient::GetExtension( | 312 const Extension* ShellContentBrowserClient::GetExtension( |
315 content::SiteInstance* site_instance) { | 313 content::SiteInstance* site_instance) { |
316 ExtensionRegistry* registry = | 314 ExtensionRegistry* registry = |
317 ExtensionRegistry::Get(site_instance->GetBrowserContext()); | 315 ExtensionRegistry::Get(site_instance->GetBrowserContext()); |
318 return registry->enabled_extensions().GetExtensionOrAppByURL( | 316 return registry->enabled_extensions().GetExtensionOrAppByURL( |
319 site_instance->GetSiteURL()); | 317 site_instance->GetSiteURL()); |
320 } | 318 } |
321 | 319 |
322 } // namespace extensions | 320 } // namespace extensions |
OLD | NEW |