Chromium Code Reviews| 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_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 12 #include "content/public/common/url_constants.h" | 12 #include "content/public/common/url_constants.h" |
| 13 #include "content/shell/browser/shell_browser_context.h" | 13 #include "content/shell/browser/shell_browser_context.h" |
| 14 #include "extensions/browser/extension_message_filter.h" | 14 #include "extensions/browser/extension_message_filter.h" |
| 15 #include "extensions/browser/extension_protocols.h" | 15 #include "extensions/browser/extension_protocols.h" |
| 16 #include "extensions/browser/extension_registry.h" | 16 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/browser/info_map.h" | 17 #include "extensions/browser/info_map.h" |
| 18 #include "extensions/browser/process_map.h" | 18 #include "extensions/browser/process_map.h" |
| 19 #include "extensions/common/constants.h" | 19 #include "extensions/common/constants.h" |
| 20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/switches.h" | 21 #include "extensions/common/switches.h" |
| 22 #include "extensions/shell/browser/shell_browser_context.h" | 22 #include "extensions/shell/browser/shell_browser_context.h" |
| 23 #include "extensions/shell/browser/shell_browser_main_parts.h" | 23 #include "extensions/shell/browser/shell_browser_main_parts.h" |
| 24 #include "extensions/shell/browser/shell_extension_system.h" | 24 #include "extensions/shell/browser/shell_extension_system.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 | 26 |
| 27 #if !defined(DISABLE_NACL) | |
| 28 //JAMES do we need all these? | |
| 29 #include "components/nacl/browser/nacl_browser.h" | |
| 30 #include "components/nacl/browser/nacl_host_message_filter.h" | |
| 31 #include "components/nacl/browser/nacl_process_host.h" | |
| 32 #include "components/nacl/common/nacl_process_type.h" | |
| 33 #include "components/nacl/common/nacl_switches.h" | |
| 34 #include "content/public/browser/browser_child_process_host.h" | |
| 35 #include "content/public/browser/child_process_data.h" | |
| 36 #endif | |
| 37 | |
| 38 using base::CommandLine; | |
| 39 using content::BrowserContext; | |
| 27 using content::BrowserThread; | 40 using content::BrowserThread; |
| 28 | 41 |
| 29 namespace extensions { | 42 namespace extensions { |
| 30 namespace { | 43 namespace { |
| 31 | 44 |
| 32 ShellContentBrowserClient* g_instance = NULL; | 45 ShellContentBrowserClient* g_instance = NULL; |
| 33 | 46 |
| 34 } // namespace | 47 } // namespace |
| 35 | 48 |
| 36 ShellContentBrowserClient::ShellContentBrowserClient( | 49 ShellContentBrowserClient::ShellContentBrowserClient( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 56 content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( | 69 content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( |
| 57 const content::MainFunctionParams& parameters) { | 70 const content::MainFunctionParams& parameters) { |
| 58 browser_main_parts_ = | 71 browser_main_parts_ = |
| 59 new ShellBrowserMainParts(parameters, browser_main_delegate_); | 72 new ShellBrowserMainParts(parameters, browser_main_delegate_); |
| 60 return browser_main_parts_; | 73 return browser_main_parts_; |
| 61 } | 74 } |
| 62 | 75 |
| 63 void ShellContentBrowserClient::RenderProcessWillLaunch( | 76 void ShellContentBrowserClient::RenderProcessWillLaunch( |
| 64 content::RenderProcessHost* host) { | 77 content::RenderProcessHost* host) { |
| 65 int render_process_id = host->GetID(); | 78 int render_process_id = host->GetID(); |
| 66 host->AddFilter(new ExtensionMessageFilter( | 79 BrowserContext* browser_context = browser_main_parts_->browser_context(); |
| 67 render_process_id, browser_main_parts_->browser_context())); | 80 host->AddFilter( |
| 81 new ExtensionMessageFilter(render_process_id, browser_context)); | |
| 82 // PluginInfoMessageFilter is not required because app_shell does not have | |
| 83 // the concept of disabled plugins. | |
| 84 #if !defined(DISABLE_NACL) | |
| 85 host->AddFilter(new nacl::NaClHostMessageFilter( | |
| 86 render_process_id, | |
| 87 browser_context->IsOffTheRecord(), | |
| 88 browser_context->GetPath(), | |
| 89 browser_context->GetRequestContextForRenderProcess(render_process_id))); | |
| 90 #endif | |
| 68 } | 91 } |
| 69 | 92 |
| 70 bool ShellContentBrowserClient::ShouldUseProcessPerSite( | 93 bool ShellContentBrowserClient::ShouldUseProcessPerSite( |
| 71 content::BrowserContext* browser_context, | 94 content::BrowserContext* browser_context, |
| 72 const GURL& effective_url) { | 95 const GURL& effective_url) { |
| 73 // This ensures that all render views created for a single app will use the | 96 // This ensures that all render views created for a single app will use the |
| 74 // same render process (see content::SiteInstance::GetProcess). Otherwise the | 97 // same render process (see content::SiteInstance::GetProcess). Otherwise the |
| 75 // default behavior of ContentBrowserClient will lead to separate render | 98 // default behavior of ContentBrowserClient will lead to separate render |
| 76 // processes for the background page and each app window view. | 99 // processes for the background page and each app window view. |
| 77 return true; | 100 return true; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 site_instance->GetProcess()->GetID(), | 183 site_instance->GetProcess()->GetID(), |
| 161 site_instance->GetId())); | 184 site_instance->GetId())); |
| 162 } | 185 } |
| 163 | 186 |
| 164 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( | 187 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
| 165 CommandLine* command_line, | 188 CommandLine* command_line, |
| 166 int child_process_id) { | 189 int child_process_id) { |
| 167 std::string process_type = | 190 std::string process_type = |
| 168 command_line->GetSwitchValueASCII(::switches::kProcessType); | 191 command_line->GetSwitchValueASCII(::switches::kProcessType); |
| 169 if (process_type == ::switches::kRendererProcess) { | 192 if (process_type == ::switches::kRendererProcess) { |
| 170 // TODO(jamescook): Should we check here if the process is in the extension | 193 AppendRendererSwitches(command_line); |
| 171 // service process map, or can we assume all renderers are extension | 194 } else if (process_type == ::switches::kZygoteProcess) { |
| 172 // renderers? | 195 AppendZygoteSwitches(command_line); |
| 173 command_line->AppendSwitch(switches::kExtensionProcess); | |
| 174 } | 196 } |
| 175 } | 197 } |
| 176 | 198 |
| 199 void ShellContentBrowserClient::DidCreatePpapiPlugin( | |
| 200 content::BrowserPpapiHost* browser_host) { | |
| 201 // TODO(jamescook): Does this need a PepperHostFactory filter? | |
|
teravest
2014/08/12 15:48:31
I don't think you need to do anything for DidCreat
James Cook
2014/08/12 18:17:06
Removed.
| |
| 202 } | |
| 203 | |
| 204 content::BrowserPpapiHost* | |
| 205 ShellContentBrowserClient::GetExternalBrowserPpapiHost( | |
| 206 int plugin_process_id) { | |
| 207 #if !defined(DISABLE_NACL) | |
| 208 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); | |
| 209 while (!iter.Done()) { | |
| 210 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>( | |
| 211 iter.GetDelegate()); | |
| 212 if (host->process() && | |
| 213 host->process()->GetData().id == plugin_process_id) { | |
| 214 // Found the plugin. | |
| 215 return host->browser_ppapi_host(); | |
| 216 } | |
| 217 ++iter; | |
| 218 } | |
| 219 #endif | |
| 220 return NULL; | |
| 221 } | |
| 222 | |
| 177 void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 223 void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 178 std::vector<std::string>* additional_allowed_schemes) { | 224 std::vector<std::string>* additional_allowed_schemes) { |
| 179 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 225 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 180 additional_allowed_schemes); | 226 additional_allowed_schemes); |
| 181 additional_allowed_schemes->push_back(kExtensionScheme); | 227 additional_allowed_schemes->push_back(kExtensionScheme); |
| 182 } | 228 } |
| 183 | 229 |
| 230 void ShellContentBrowserClient::AppendRendererSwitches( | |
| 231 CommandLine* command_line) { | |
| 232 // TODO(jamescook): Should we check here if the process is in the extension | |
| 233 // service process map, or can we assume all renderers are extension | |
| 234 // renderers? | |
| 235 command_line->AppendSwitch(switches::kExtensionProcess); | |
| 236 | |
| 237 #if !defined(DISABLE_NACL) | |
| 238 // TODO(jamescook): What about kAllowNaClFileHandleAPI? | |
|
teravest
2014/08/12 15:48:31
You'd only need kAllowNaClFileHandleAPI for Reques
James Cook
2014/08/12 18:17:06
Removed.
| |
| 239 static const char* const kSwitchNames[] = { | |
| 240 ::switches::kEnableNaClDebug, | |
| 241 ::switches::kEnableNaClNonSfiMode, | |
| 242 }; | |
| 243 command_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), | |
| 244 kSwitchNames, | |
| 245 arraysize(kSwitchNames)); | |
| 246 #endif // !defined(DISABLE_NACL) | |
| 247 } | |
| 248 | |
| 249 void ShellContentBrowserClient::AppendZygoteSwitches( | |
| 250 CommandLine* command_line) { | |
| 251 #if !defined(DISABLE_NACL) | |
| 252 static const char* const kSwitchNames[] = { | |
| 253 ::switches::kEnableNaClNonSfiMode, | |
| 254 ::switches::kNaClDangerousNoSandboxNonSfi, | |
| 255 }; | |
| 256 command_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), | |
| 257 kSwitchNames, | |
| 258 arraysize(kSwitchNames)); | |
| 259 #endif // !defined(DISABLE_NACL) | |
| 260 } | |
| 261 | |
| 184 const Extension* ShellContentBrowserClient::GetExtension( | 262 const Extension* ShellContentBrowserClient::GetExtension( |
| 185 content::SiteInstance* site_instance) { | 263 content::SiteInstance* site_instance) { |
| 186 ExtensionRegistry* registry = | 264 ExtensionRegistry* registry = |
| 187 ExtensionRegistry::Get(site_instance->GetBrowserContext()); | 265 ExtensionRegistry::Get(site_instance->GetBrowserContext()); |
| 188 return registry->enabled_extensions().GetExtensionOrAppByURL( | 266 return registry->enabled_extensions().GetExtensionOrAppByURL( |
| 189 site_instance->GetSiteURL()); | 267 site_instance->GetSiteURL()); |
| 190 } | 268 } |
| 191 | 269 |
| 192 } // namespace extensions | 270 } // namespace extensions |
| OLD | NEW |