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 "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 #include "content/public/browser/site_instance.h" | 10 #include "content/public/browser/site_instance.h" |
| 11 #include "content/public/common/content_descriptors.h" |
11 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
12 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
13 #include "content/shell/browser/shell_browser_context.h" | 14 #include "content/shell/browser/shell_browser_context.h" |
14 #include "content/shell/browser/shell_devtools_manager_delegate.h" | 15 #include "content/shell/browser/shell_devtools_manager_delegate.h" |
15 #include "extensions/browser/extension_message_filter.h" | 16 #include "extensions/browser/extension_message_filter.h" |
16 #include "extensions/browser/extension_protocols.h" | 17 #include "extensions/browser/extension_protocols.h" |
17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/browser/guest_view/guest_view_message_filter.h" | 19 #include "extensions/browser/guest_view/guest_view_message_filter.h" |
19 #include "extensions/browser/info_map.h" | 20 #include "extensions/browser/info_map.h" |
20 #include "extensions/browser/io_thread_extension_message_filter.h" | 21 #include "extensions/browser/io_thread_extension_message_filter.h" |
21 #include "extensions/browser/process_map.h" | 22 #include "extensions/browser/process_map.h" |
22 #include "extensions/common/constants.h" | 23 #include "extensions/common/constants.h" |
23 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
24 #include "extensions/common/switches.h" | 25 #include "extensions/common/switches.h" |
25 #include "extensions/shell/browser/shell_browser_context.h" | 26 #include "extensions/shell/browser/shell_browser_context.h" |
26 #include "extensions/shell/browser/shell_browser_main_parts.h" | 27 #include "extensions/shell/browser/shell_browser_main_parts.h" |
27 #include "extensions/shell/browser/shell_extension_system.h" | 28 #include "extensions/shell/browser/shell_extension_system.h" |
28 #include "extensions/shell/browser/shell_speech_recognition_manager_delegate.h" | 29 #include "extensions/shell/browser/shell_speech_recognition_manager_delegate.h" |
| 30 #include "gin/public/isolate_holder.h" |
29 #include "url/gurl.h" | 31 #include "url/gurl.h" |
30 | 32 |
31 #if !defined(DISABLE_NACL) | 33 #if !defined(DISABLE_NACL) |
32 #include "components/nacl/browser/nacl_browser.h" | 34 #include "components/nacl/browser/nacl_browser.h" |
33 #include "components/nacl/browser/nacl_host_message_filter.h" | 35 #include "components/nacl/browser/nacl_host_message_filter.h" |
34 #include "components/nacl/browser/nacl_process_host.h" | 36 #include "components/nacl/browser/nacl_process_host.h" |
35 #include "components/nacl/common/nacl_process_type.h" | 37 #include "components/nacl/common/nacl_process_type.h" |
36 #include "components/nacl/common/nacl_switches.h" | 38 #include "components/nacl/common/nacl_switches.h" |
37 #include "content/public/browser/browser_child_process_host.h" | 39 #include "content/public/browser/browser_child_process_host.h" |
38 #include "content/public/browser/child_process_data.h" | 40 #include "content/public/browser/child_process_data.h" |
39 #endif | 41 #endif |
40 | 42 |
41 using base::CommandLine; | 43 using base::CommandLine; |
42 using content::BrowserContext; | 44 using content::BrowserContext; |
43 using content::BrowserThread; | 45 using content::BrowserThread; |
44 | 46 |
45 namespace extensions { | 47 namespace extensions { |
46 namespace { | 48 namespace { |
47 | 49 |
48 ShellContentBrowserClient* g_instance = NULL; | 50 ShellContentBrowserClient* g_instance = nullptr; |
49 | 51 |
50 } // namespace | 52 } // namespace |
51 | 53 |
52 ShellContentBrowserClient::ShellContentBrowserClient( | 54 ShellContentBrowserClient::ShellContentBrowserClient( |
53 ShellBrowserMainDelegate* browser_main_delegate) | 55 ShellBrowserMainDelegate* browser_main_delegate) |
54 : browser_main_parts_(NULL), browser_main_delegate_(browser_main_delegate) { | 56 : |
| 57 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 58 v8_natives_fd_(-1), |
| 59 v8_snapshot_fd_(-1), |
| 60 #endif // OS_POSIX && !OS_MACOSX |
| 61 browser_main_parts_(nullptr), |
| 62 browser_main_delegate_(browser_main_delegate) { |
55 DCHECK(!g_instance); | 63 DCHECK(!g_instance); |
56 g_instance = this; | 64 g_instance = this; |
57 } | 65 } |
58 | 66 |
59 ShellContentBrowserClient::~ShellContentBrowserClient() { | 67 ShellContentBrowserClient::~ShellContentBrowserClient() { |
60 g_instance = NULL; | 68 g_instance = nullptr; |
61 } | 69 } |
62 | 70 |
63 // static | 71 // static |
64 ShellContentBrowserClient* ShellContentBrowserClient::Get() { | 72 ShellContentBrowserClient* ShellContentBrowserClient::Get() { |
65 return g_instance; | 73 return g_instance; |
66 } | 74 } |
67 | 75 |
68 content::BrowserContext* ShellContentBrowserClient::GetBrowserContext() { | 76 content::BrowserContext* ShellContentBrowserClient::GetBrowserContext() { |
69 return browser_main_parts_->browser_context(); | 77 return browser_main_parts_->browser_context(); |
70 } | 78 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>( | 220 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>( |
213 iter.GetDelegate()); | 221 iter.GetDelegate()); |
214 if (host->process() && | 222 if (host->process() && |
215 host->process()->GetData().id == plugin_process_id) { | 223 host->process()->GetData().id == plugin_process_id) { |
216 // Found the plugin. | 224 // Found the plugin. |
217 return host->browser_ppapi_host(); | 225 return host->browser_ppapi_host(); |
218 } | 226 } |
219 ++iter; | 227 ++iter; |
220 } | 228 } |
221 #endif | 229 #endif |
222 return NULL; | 230 return nullptr; |
223 } | 231 } |
224 | 232 |
225 void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 233 void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
226 std::vector<std::string>* additional_allowed_schemes) { | 234 std::vector<std::string>* additional_allowed_schemes) { |
227 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 235 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
228 additional_allowed_schemes); | 236 additional_allowed_schemes); |
229 additional_allowed_schemes->push_back(kExtensionScheme); | 237 additional_allowed_schemes->push_back(kExtensionScheme); |
230 } | 238 } |
231 | 239 |
| 240 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 241 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
| 242 const base::CommandLine& command_line, |
| 243 int child_process_id, |
| 244 content::FileDescriptorInfo* mappings) { |
| 245 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 246 if (v8_natives_fd_.get() == -1 || v8_snapshot_fd_.get() == -1) { |
| 247 int v8_natives_fd = -1; |
| 248 int v8_snapshot_fd = -1; |
| 249 if (gin::IsolateHolder::OpenV8FilesForChildProcesses(&v8_natives_fd, |
| 250 &v8_snapshot_fd)) { |
| 251 v8_natives_fd_.reset(v8_natives_fd); |
| 252 v8_snapshot_fd_.reset(v8_snapshot_fd); |
| 253 } |
| 254 } |
| 255 DCHECK(v8_natives_fd_.get() != -1 && v8_snapshot_fd_.get() != -1); |
| 256 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); |
| 257 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); |
| 258 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 259 } |
| 260 #endif // OS_POSIX && !OS_MACOSX |
| 261 |
232 content::DevToolsManagerDelegate* | 262 content::DevToolsManagerDelegate* |
233 ShellContentBrowserClient::GetDevToolsManagerDelegate() { | 263 ShellContentBrowserClient::GetDevToolsManagerDelegate() { |
234 return new content::ShellDevToolsManagerDelegate(GetBrowserContext()); | 264 return new content::ShellDevToolsManagerDelegate(GetBrowserContext()); |
235 } | 265 } |
236 | 266 |
237 ShellBrowserMainParts* ShellContentBrowserClient::CreateShellBrowserMainParts( | 267 ShellBrowserMainParts* ShellContentBrowserClient::CreateShellBrowserMainParts( |
238 const content::MainFunctionParams& parameters, | 268 const content::MainFunctionParams& parameters, |
239 ShellBrowserMainDelegate* browser_main_delegate) { | 269 ShellBrowserMainDelegate* browser_main_delegate) { |
240 return new ShellBrowserMainParts(parameters, browser_main_delegate); | 270 return new ShellBrowserMainParts(parameters, browser_main_delegate); |
241 } | 271 } |
(...skipping 18 matching lines...) Expand all Loading... |
260 | 290 |
261 const Extension* ShellContentBrowserClient::GetExtension( | 291 const Extension* ShellContentBrowserClient::GetExtension( |
262 content::SiteInstance* site_instance) { | 292 content::SiteInstance* site_instance) { |
263 ExtensionRegistry* registry = | 293 ExtensionRegistry* registry = |
264 ExtensionRegistry::Get(site_instance->GetBrowserContext()); | 294 ExtensionRegistry::Get(site_instance->GetBrowserContext()); |
265 return registry->enabled_extensions().GetExtensionOrAppByURL( | 295 return registry->enabled_extensions().GetExtensionOrAppByURL( |
266 site_instance->GetSiteURL()); | 296 site_instance->GetSiteURL()); |
267 } | 297 } |
268 | 298 |
269 } // namespace extensions | 299 } // namespace extensions |
OLD | NEW |