| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 BrowserThread::PostTask( | 187 BrowserThread::PostTask( |
| 194 BrowserThread::IO, | 188 BrowserThread::IO, |
| 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( | |
| 204 base::CommandLine* command_line) { | |
| 205 std::string process_type = | |
| 206 command_line->GetSwitchValueASCII(::switches::kProcessType); | |
| 207 | |
| 208 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 209 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
| 210 DCHECK(natives_fd_exists()); | |
| 211 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); | |
| 212 if (snapshot_fd_exists()) | |
| 213 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | |
| 214 #endif // V8_USE_EXTERNAL_STARTUP_DATA | |
| 215 #endif // OS_POSIX && !OS_MACOSX | |
| 216 } | |
| 217 | |
| 218 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( | 197 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
| 219 base::CommandLine* command_line, | 198 base::CommandLine* command_line, |
| 220 int child_process_id) { | 199 int child_process_id) { |
| 221 std::string process_type = | 200 std::string process_type = |
| 222 command_line->GetSwitchValueASCII(::switches::kProcessType); | 201 command_line->GetSwitchValueASCII(::switches::kProcessType); |
| 223 if (process_type == ::switches::kRendererProcess) | 202 if (process_type == ::switches::kRendererProcess) |
| 224 AppendRendererSwitches(command_line); | 203 AppendRendererSwitches(command_line); |
| 225 } | 204 } |
| 226 | 205 |
| 227 content::SpeechRecognitionManagerDelegate* | 206 content::SpeechRecognitionManagerDelegate* |
| (...skipping 19 matching lines...) Expand all Loading... |
| 247 return nullptr; | 226 return nullptr; |
| 248 } | 227 } |
| 249 | 228 |
| 250 void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 229 void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 251 std::vector<std::string>* additional_allowed_schemes) { | 230 std::vector<std::string>* additional_allowed_schemes) { |
| 252 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 231 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 253 additional_allowed_schemes); | 232 additional_allowed_schemes); |
| 254 additional_allowed_schemes->push_back(kExtensionScheme); | 233 additional_allowed_schemes->push_back(kExtensionScheme); |
| 255 } | 234 } |
| 256 | 235 |
| 257 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 258 void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( | |
| 259 const base::CommandLine& command_line, | |
| 260 int child_process_id, | |
| 261 content::FileDescriptorInfo* mappings) { | |
| 262 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
| 263 if (!natives_fd_exists()) { | |
| 264 int v8_natives_fd = -1; | |
| 265 int v8_snapshot_fd = -1; | |
| 266 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd, | |
| 267 &v8_snapshot_fd)) { | |
| 268 v8_natives_fd_.reset(v8_natives_fd); | |
| 269 v8_snapshot_fd_.reset(v8_snapshot_fd); | |
| 270 } | |
| 271 } | |
| 272 // V8 can't start up without the source of the natives, but it can | |
| 273 // start up (slower) without the snapshot. | |
| 274 DCHECK(natives_fd_exists()); | |
| 275 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); | |
| 276 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); | |
| 277 #endif // V8_USE_EXTERNAL_STARTUP_DATA | |
| 278 } | |
| 279 #endif // OS_POSIX && !OS_MACOSX | |
| 280 | |
| 281 content::DevToolsManagerDelegate* | 236 content::DevToolsManagerDelegate* |
| 282 ShellContentBrowserClient::GetDevToolsManagerDelegate() { | 237 ShellContentBrowserClient::GetDevToolsManagerDelegate() { |
| 283 return new content::ShellDevToolsManagerDelegate(GetBrowserContext()); | 238 return new content::ShellDevToolsManagerDelegate(GetBrowserContext()); |
| 284 } | 239 } |
| 285 | 240 |
| 286 ShellBrowserMainParts* ShellContentBrowserClient::CreateShellBrowserMainParts( | 241 ShellBrowserMainParts* ShellContentBrowserClient::CreateShellBrowserMainParts( |
| 287 const content::MainFunctionParams& parameters, | 242 const content::MainFunctionParams& parameters, |
| 288 ShellBrowserMainDelegate* browser_main_delegate) { | 243 ShellBrowserMainDelegate* browser_main_delegate) { |
| 289 return new ShellBrowserMainParts(parameters, browser_main_delegate); | 244 return new ShellBrowserMainParts(parameters, browser_main_delegate); |
| 290 } | 245 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 309 | 264 |
| 310 const Extension* ShellContentBrowserClient::GetExtension( | 265 const Extension* ShellContentBrowserClient::GetExtension( |
| 311 content::SiteInstance* site_instance) { | 266 content::SiteInstance* site_instance) { |
| 312 ExtensionRegistry* registry = | 267 ExtensionRegistry* registry = |
| 313 ExtensionRegistry::Get(site_instance->GetBrowserContext()); | 268 ExtensionRegistry::Get(site_instance->GetBrowserContext()); |
| 314 return registry->enabled_extensions().GetExtensionOrAppByURL( | 269 return registry->enabled_extensions().GetExtensionOrAppByURL( |
| 315 site_instance->GetSiteURL()); | 270 site_instance->GetSiteURL()); |
| 316 } | 271 } |
| 317 | 272 |
| 318 } // namespace extensions | 273 } // namespace extensions |
| OLD | NEW |