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 #include "components/nacl/browser/nacl_browser.h" | |
29 #include "components/nacl/browser/nacl_host_message_filter.h" | |
30 #include "components/nacl/browser/nacl_process_host.h" | |
31 #include "components/nacl/common/nacl_process_type.h" | |
32 #include "components/nacl/common/nacl_switches.h" | |
33 #include "content/public/browser/browser_child_process_host.h" | |
34 #include "content/public/browser/child_process_data.h" | |
35 #endif | |
36 | |
37 using base::CommandLine; | |
38 using content::BrowserContext; | |
27 using content::BrowserThread; | 39 using content::BrowserThread; |
28 | 40 |
29 namespace extensions { | 41 namespace extensions { |
30 namespace { | 42 namespace { |
31 | 43 |
32 ShellContentBrowserClient* g_instance = NULL; | 44 ShellContentBrowserClient* g_instance = NULL; |
33 | 45 |
34 } // namespace | 46 } // namespace |
35 | 47 |
36 ShellContentBrowserClient::ShellContentBrowserClient( | 48 ShellContentBrowserClient::ShellContentBrowserClient( |
(...skipping 19 matching lines...) Expand all Loading... | |
56 content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( | 68 content::BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( |
57 const content::MainFunctionParams& parameters) { | 69 const content::MainFunctionParams& parameters) { |
58 browser_main_parts_ = | 70 browser_main_parts_ = |
59 new ShellBrowserMainParts(parameters, browser_main_delegate_); | 71 new ShellBrowserMainParts(parameters, browser_main_delegate_); |
60 return browser_main_parts_; | 72 return browser_main_parts_; |
61 } | 73 } |
62 | 74 |
63 void ShellContentBrowserClient::RenderProcessWillLaunch( | 75 void ShellContentBrowserClient::RenderProcessWillLaunch( |
64 content::RenderProcessHost* host) { | 76 content::RenderProcessHost* host) { |
65 int render_process_id = host->GetID(); | 77 int render_process_id = host->GetID(); |
66 host->AddFilter(new ExtensionMessageFilter( | 78 BrowserContext* browser_context = browser_main_parts_->browser_context(); |
67 render_process_id, browser_main_parts_->browser_context())); | 79 host->AddFilter( |
80 new ExtensionMessageFilter(render_process_id, browser_context)); | |
81 // PluginInfoMessageFilter is not required because app_shell does not have | |
82 // the concept of disabled plugins. | |
83 #if !defined(DISABLE_NACL) | |
84 host->AddFilter(new nacl::NaClHostMessageFilter( | |
85 render_process_id, | |
86 browser_context->IsOffTheRecord(), | |
87 browser_context->GetPath(), | |
88 browser_context->GetRequestContextForRenderProcess(render_process_id))); | |
89 #endif | |
68 } | 90 } |
69 | 91 |
70 bool ShellContentBrowserClient::ShouldUseProcessPerSite( | 92 bool ShellContentBrowserClient::ShouldUseProcessPerSite( |
71 content::BrowserContext* browser_context, | 93 content::BrowserContext* browser_context, |
72 const GURL& effective_url) { | 94 const GURL& effective_url) { |
73 // This ensures that all render views created for a single app will use the | 95 // This ensures that all render views created for a single app will use the |
74 // same render process (see content::SiteInstance::GetProcess). Otherwise the | 96 // same render process (see content::SiteInstance::GetProcess). Otherwise the |
75 // default behavior of ContentBrowserClient will lead to separate render | 97 // default behavior of ContentBrowserClient will lead to separate render |
76 // processes for the background page and each app window view. | 98 // processes for the background page and each app window view. |
77 return true; | 99 return true; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 extension->id(), | 181 extension->id(), |
160 site_instance->GetProcess()->GetID(), | 182 site_instance->GetProcess()->GetID(), |
161 site_instance->GetId())); | 183 site_instance->GetId())); |
162 } | 184 } |
163 | 185 |
164 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( | 186 void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
165 CommandLine* command_line, | 187 CommandLine* command_line, |
166 int child_process_id) { | 188 int child_process_id) { |
167 std::string process_type = | 189 std::string process_type = |
168 command_line->GetSwitchValueASCII(::switches::kProcessType); | 190 command_line->GetSwitchValueASCII(::switches::kProcessType); |
169 if (process_type == ::switches::kRendererProcess) { | 191 if (process_type == ::switches::kRendererProcess) |
170 // TODO(jamescook): Should we check here if the process is in the extension | 192 AppendRendererSwitches(command_line); |
171 // service process map, or can we assume all renderers are extension | 193 } |
172 // renderers? | 194 |
173 command_line->AppendSwitch(switches::kExtensionProcess); | 195 content::BrowserPpapiHost* |
196 ShellContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) { | |
197 #if !defined(DISABLE_NACL) | |
198 content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); | |
199 while (!iter.Done()) { | |
200 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>( | |
201 iter.GetDelegate()); | |
202 if (host->process() && | |
203 host->process()->GetData().id == plugin_process_id) { | |
204 // Found the plugin. | |
205 return host->browser_ppapi_host(); | |
206 } | |
207 ++iter; | |
174 } | 208 } |
209 #endif | |
210 return NULL; | |
175 } | 211 } |
176 | 212 |
177 void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 213 void ShellContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
178 std::vector<std::string>* additional_allowed_schemes) { | 214 std::vector<std::string>* additional_allowed_schemes) { |
179 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 215 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
180 additional_allowed_schemes); | 216 additional_allowed_schemes); |
181 additional_allowed_schemes->push_back(kExtensionScheme); | 217 additional_allowed_schemes->push_back(kExtensionScheme); |
182 } | 218 } |
183 | 219 |
220 void ShellContentBrowserClient::AppendRendererSwitches( | |
221 CommandLine* command_line) { | |
222 // TODO(jamescook): Should we check here if the process is in the extension | |
223 // service process map, or can we assume all renderers are extension | |
224 // renderers? | |
225 command_line->AppendSwitch(switches::kExtensionProcess); | |
226 | |
227 #if !defined(DISABLE_NACL) | |
228 // NOTE: app_shell does not support ARC or non-SFI mode, so does not pass | |
Mark Seaborn
2014/08/14 21:00:35
Nit: You don't need to mention "ARC" here, just no
James Cook
2014/08/14 21:53:40
Done.
| |
229 // through those switches either here or for the zygote process. | |
230 static const char* const kSwitchNames[] = { | |
231 ::switches::kEnableNaClDebug, | |
232 }; | |
233 command_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), | |
234 kSwitchNames, | |
235 arraysize(kSwitchNames)); | |
236 #endif // !defined(DISABLE_NACL) | |
237 } | |
238 | |
184 const Extension* ShellContentBrowserClient::GetExtension( | 239 const Extension* ShellContentBrowserClient::GetExtension( |
185 content::SiteInstance* site_instance) { | 240 content::SiteInstance* site_instance) { |
186 ExtensionRegistry* registry = | 241 ExtensionRegistry* registry = |
187 ExtensionRegistry::Get(site_instance->GetBrowserContext()); | 242 ExtensionRegistry::Get(site_instance->GetBrowserContext()); |
188 return registry->enabled_extensions().GetExtensionOrAppByURL( | 243 return registry->enabled_extensions().GetExtensionOrAppByURL( |
189 site_instance->GetSiteURL()); | 244 site_instance->GetSiteURL()); |
190 } | 245 } |
191 | 246 |
192 } // namespace extensions | 247 } // namespace extensions |
OLD | NEW |