Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/nacl_host/nacl_process_host.h" | 5 #include "chrome/browser/nacl_host/nacl_process_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
| 19 #include "base/process/process_iterator.h" | 19 #include "base/process/process_iterator.h" |
| 20 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "chrome/browser/extensions/extension_service.h" | |
|
Mark Seaborn
2013/11/15 01:32:56
I don't know if you want a review for this change
scheib
2013/12/11 21:35:40
Done.
| |
| 29 #include "chrome/browser/extensions/extension_system.h" | |
| 28 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" | 30 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" |
| 31 #include "chrome/browser/profiles/profile.h" | |
| 29 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 30 #include "components/nacl/browser/nacl_browser.h" | 33 #include "components/nacl/browser/nacl_browser.h" |
| 31 #include "components/nacl/common/nacl_cmd_line.h" | 34 #include "components/nacl/common/nacl_cmd_line.h" |
| 32 #include "components/nacl/common/nacl_host_messages.h" | 35 #include "components/nacl/common/nacl_host_messages.h" |
| 33 #include "components/nacl/common/nacl_messages.h" | 36 #include "components/nacl/common/nacl_messages.h" |
| 34 #include "components/nacl/common/nacl_process_type.h" | 37 #include "components/nacl/common/nacl_process_type.h" |
| 35 #include "components/nacl/common/nacl_switches.h" | 38 #include "components/nacl/common/nacl_switches.h" |
| 36 #include "content/public/browser/browser_child_process_host.h" | 39 #include "content/public/browser/browser_child_process_host.h" |
| 37 #include "content/public/browser/browser_ppapi_host.h" | 40 #include "content/public/browser/browser_ppapi_host.h" |
| 38 #include "content/public/browser/child_process_data.h" | 41 #include "content/public/browser/child_process_data.h" |
| 42 #include "content/public/browser/render_view_host.h" | |
| 43 #include "content/public/browser/site_instance.h" | |
| 39 #include "content/public/common/child_process_host.h" | 44 #include "content/public/common/child_process_host.h" |
| 40 #include "content/public/common/content_switches.h" | 45 #include "content/public/common/content_switches.h" |
| 41 #include "content/public/common/process_type.h" | 46 #include "content/public/common/process_type.h" |
| 47 #include "extensions/browser/process_manager.h" | |
| 42 #include "ipc/ipc_channel.h" | 48 #include "ipc/ipc_channel.h" |
| 43 #include "ipc/ipc_switches.h" | 49 #include "ipc/ipc_switches.h" |
| 44 #include "native_client/src/shared/imc/nacl_imc_c.h" | 50 #include "native_client/src/shared/imc/nacl_imc_c.h" |
| 45 #include "net/base/net_util.h" | 51 #include "net/base/net_util.h" |
| 46 #include "net/socket/tcp_listen_socket.h" | 52 #include "net/socket/tcp_listen_socket.h" |
| 47 #include "ppapi/host/host_factory.h" | 53 #include "ppapi/host/host_factory.h" |
| 48 #include "ppapi/host/ppapi_host.h" | 54 #include "ppapi/host/ppapi_host.h" |
| 49 #include "ppapi/proxy/ppapi_messages.h" | 55 #include "ppapi/proxy/ppapi_messages.h" |
| 50 #include "ppapi/shared_impl/ppapi_nacl_channel_args.h" | 56 #include "ppapi/shared_impl/ppapi_nacl_channel_args.h" |
| 51 | 57 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 } | 197 } |
| 192 | 198 |
| 193 ppapi::PpapiPermissions GetNaClPermissions(uint32 permission_bits) { | 199 ppapi::PpapiPermissions GetNaClPermissions(uint32 permission_bits) { |
| 194 // Only allow NaCl plugins to request certain permissions. We don't want | 200 // Only allow NaCl plugins to request certain permissions. We don't want |
| 195 // a compromised renderer to be able to start a nacl plugin with e.g. Flash | 201 // a compromised renderer to be able to start a nacl plugin with e.g. Flash |
| 196 // permissions which may expand the surface area of the sandbox. | 202 // permissions which may expand the surface area of the sandbox. |
| 197 uint32 masked_bits = permission_bits & ppapi::PERMISSION_DEV; | 203 uint32 masked_bits = permission_bits & ppapi::PERMISSION_DEV; |
| 198 return ppapi::PpapiPermissions::GetForCommandLine(masked_bits); | 204 return ppapi::PpapiPermissions::GetForCommandLine(masked_bits); |
| 199 } | 205 } |
| 200 | 206 |
| 207 // Handles an extension's NaCl process transitioning in or out of idle state by | |
| 208 // relaying the state to the extension's process manager. | |
| 209 // | |
| 210 // A NaCl instance monitors its activity and sends an IPC to the browser | |
| 211 // process BrowserPpapiHost upon transitioning in our out of idleness. The | |
| 212 // content::BrowserPpapiHost passes context information up to the chrome level | |
| 213 // NaClProcessHost where we use the instance's context to find the associated | |
| 214 // extension process manager. | |
| 215 // | |
| 216 // There is 1:many relationship for extension:nacl-embeds, but only a | |
| 217 // 1:1 relationship for NaClProcessHost:PP_Instance. The content layer doesn't | |
| 218 // rely on this knowledge because it routes messages for ppapi non-nacl | |
| 219 // instances as well, though they won't have callbacks set. Here the 1:1 | |
| 220 // assumption is made and DCHECKed. | |
| 221 void OnIdleStateChangeOnUIThread( | |
| 222 content::BrowserPpapiHost::OnIdleChangeInstanceData intance_data, | |
| 223 const base::FilePath profile_data_directory, | |
| 224 bool idle) { | |
| 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 226 | |
| 227 // Only one instance will exist for NaCl embeds, even when more than one | |
| 228 // embed of the same plugin exists on the same page. | |
| 229 DCHECK(intance_data.size() == 1); | |
| 230 if (intance_data.size() < 1) | |
| 231 return; | |
| 232 | |
| 233 content::RenderViewHost* render_view_host = content::RenderViewHost::FromID( | |
| 234 intance_data[0].render_process_id, intance_data[0].render_view_id); | |
| 235 DCHECK(render_view_host); | |
| 236 if (!render_view_host) | |
| 237 return; | |
| 238 | |
| 239 content::SiteInstance* site_instance = render_view_host->GetSiteInstance(); | |
| 240 DCHECK(site_instance); | |
| 241 if (!site_instance) | |
| 242 return; | |
| 243 | |
| 244 extensions::ExtensionSystem* extension_system = | |
| 245 extensions::ExtensionSystem::GetForBrowserContext( | |
| 246 site_instance->GetBrowserContext()); | |
| 247 DCHECK(extension_system); | |
| 248 if (!extension_system) | |
| 249 return; | |
| 250 | |
| 251 const ExtensionService* extension_service = | |
| 252 extension_system->extension_service(); | |
| 253 DCHECK(extension_service); | |
| 254 if (!extension_service) | |
| 255 return; | |
| 256 | |
| 257 const extensions::Extension* extension = extension_service->GetExtensionById( | |
| 258 intance_data[0].document_url.host(), false); | |
| 259 if (!extension) | |
| 260 return; | |
| 261 | |
| 262 extensions::ProcessManager* pm = extension_system->process_manager(); | |
| 263 DCHECK(pm); | |
| 264 if (!pm) | |
| 265 return; | |
| 266 | |
| 267 if (idle) { | |
| 268 fprintf(stderr, "%s:%s:%d DecrementLazyKeepaliveCount\n", | |
| 269 __FILE__, __FUNCTION__, __LINE__); | |
| 270 pm->DecrementLazyKeepaliveCount(extension); | |
| 271 } else { | |
| 272 fprintf(stderr, "%s:%s:%d IncrementLazyKeepaliveCount\n", | |
| 273 __FILE__, __FUNCTION__, __LINE__); | |
| 274 pm->IncrementLazyKeepaliveCount(extension); | |
| 275 } | |
| 276 } | |
| 277 | |
| 278 // Calls OnIdleStateChangeOnUIThread on UI thread. | |
| 279 void OnIdleStateChange( | |
| 280 content::BrowserPpapiHost::OnIdleChangeInstanceData intance_data, | |
| 281 const base::FilePath profile_data_directory, | |
| 282 bool idle) { | |
| 283 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 284 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 285 base::Bind(&OnIdleStateChangeOnUIThread, | |
| 286 intance_data, | |
| 287 profile_data_directory, | |
| 288 idle)); | |
| 289 } | |
| 290 | |
| 201 } // namespace | 291 } // namespace |
| 202 | 292 |
| 203 struct NaClProcessHost::NaClInternal { | 293 struct NaClProcessHost::NaClInternal { |
| 204 NaClHandle socket_for_renderer; | 294 NaClHandle socket_for_renderer; |
| 205 NaClHandle socket_for_sel_ldr; | 295 NaClHandle socket_for_sel_ldr; |
| 206 | 296 |
| 207 NaClInternal() | 297 NaClInternal() |
| 208 : socket_for_renderer(NACL_INVALID_HANDLE), | 298 : socket_for_renderer(NACL_INVALID_HANDLE), |
| 209 socket_for_sel_ldr(NACL_INVALID_HANDLE) { } | 299 socket_for_sel_ldr(NACL_INVALID_HANDLE) { } |
| 210 }; | 300 }; |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 // browser process. | 880 // browser process. |
| 791 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( | 881 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( |
| 792 ipc_proxy_channel_.get(), // sender | 882 ipc_proxy_channel_.get(), // sender |
| 793 permissions_, | 883 permissions_, |
| 794 process_->GetData().handle, | 884 process_->GetData().handle, |
| 795 ipc_proxy_channel_.get(), | 885 ipc_proxy_channel_.get(), |
| 796 nacl_host_message_filter_->render_process_id(), | 886 nacl_host_message_filter_->render_process_id(), |
| 797 render_view_id_, | 887 render_view_id_, |
| 798 profile_directory_)); | 888 profile_directory_)); |
| 799 | 889 |
| 890 ppapi_host_->SetOnIdleChangeCallback(base::Bind(&OnIdleStateChange)); | |
| 891 | |
| 800 ppapi::PpapiNaClChannelArgs args; | 892 ppapi::PpapiNaClChannelArgs args; |
| 801 args.off_the_record = nacl_host_message_filter_->off_the_record(); | 893 args.off_the_record = nacl_host_message_filter_->off_the_record(); |
| 802 args.permissions = permissions_; | 894 args.permissions = permissions_; |
| 803 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 895 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 804 DCHECK(cmdline); | 896 DCHECK(cmdline); |
| 805 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; | 897 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; |
| 806 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { | 898 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { |
| 807 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); | 899 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); |
| 808 if (!value.empty()) { | 900 if (!value.empty()) { |
| 809 args.switch_names.push_back(flag_whitelist[i]); | 901 args.switch_names.push_back(flag_whitelist[i]); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1014 } else { | 1106 } else { |
| 1015 NaClStartDebugExceptionHandlerThread( | 1107 NaClStartDebugExceptionHandlerThread( |
| 1016 process_handle.Take(), info, | 1108 process_handle.Take(), info, |
| 1017 base::MessageLoopProxy::current(), | 1109 base::MessageLoopProxy::current(), |
| 1018 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1110 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 1019 weak_factory_.GetWeakPtr())); | 1111 weak_factory_.GetWeakPtr())); |
| 1020 return true; | 1112 return true; |
| 1021 } | 1113 } |
| 1022 } | 1114 } |
| 1023 #endif | 1115 #endif |
| OLD | NEW |