Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/loader/nacl_listener.h" | 5 #include "components/nacl/loader/nacl_listener.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 return false; | 124 return false; |
| 125 return result; | 125 return result; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void DebugStubPortSelectedHandler(uint16_t port) { | 128 void DebugStubPortSelectedHandler(uint16_t port) { |
| 129 g_listener->Send(new NaClProcessHostMsg_DebugStubPortSelected(port)); | 129 g_listener->Send(new NaClProcessHostMsg_DebugStubPortSelected(port)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 #endif | 132 #endif |
| 133 | 133 |
| 134 // TODO(teravest): Decide if we should have a global callback here or look it | |
| 135 // up in a map based on the token values. | |
| 136 base::Callback<void(IPC::PlatformFileForTransit, | |
| 137 base::FilePath)> g_resolved_cb; | |
|
dmichael (off chromium)
2014/08/27 20:49:14
I think the maybe map sounds best? I guess you're
Mark Seaborn
2014/08/28 23:40:22
A mapping (from IDs to callbacks) would be better.
teravest
2014/09/04 22:13:30
open_resource() should only have one request in fl
| |
| 138 | |
| 139 void ResolveFileToken( | |
| 140 uint64_t token_lo, | |
| 141 uint64_t token_hi, | |
| 142 base::Callback<void(IPC::PlatformFileForTransit, | |
| 143 base::FilePath)> resolved_cb) { | |
| 144 if (!g_listener) | |
| 145 resolved_cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); | |
| 146 base::FilePath file_path; | |
| 147 if (g_listener->Send(new NaClProcessMsg_ResolveFileTokenAsync(token_lo, | |
| 148 token_hi))) | |
| 149 g_resolved_cb = resolved_cb; | |
| 150 else | |
| 151 resolved_cb.Run(IPC::PlatformFileForTransit(), base::FilePath()); | |
| 152 } | |
| 153 | |
| 134 // Creates the PPAPI IPC channel between the NaCl IRT and the host | 154 // Creates the PPAPI IPC channel between the NaCl IRT and the host |
| 135 // (browser/renderer) process, and starts to listen it on the thread where | 155 // (browser/renderer) process, and starts to listen it on the thread where |
| 136 // the given message_loop_proxy runs. | 156 // the given message_loop_proxy runs. |
| 137 // Also, creates and sets the corresponding NaClDesc to the given nap with | 157 // Also, creates and sets the corresponding NaClDesc to the given nap with |
| 138 // the FD #. | 158 // the FD #. |
| 139 void SetUpIPCAdapter(IPC::ChannelHandle* handle, | 159 scoped_refptr<NaClIPCAdapter> SetUpIPCAdapter( |
| 140 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 160 IPC::ChannelHandle* handle, |
| 141 struct NaClApp* nap, | 161 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 142 int nacl_fd) { | 162 struct NaClApp* nap, |
| 163 int nacl_fd) { | |
| 143 scoped_refptr<NaClIPCAdapter> ipc_adapter( | 164 scoped_refptr<NaClIPCAdapter> ipc_adapter( |
| 144 new NaClIPCAdapter(*handle, message_loop_proxy.get())); | 165 new NaClIPCAdapter(*handle, message_loop_proxy.get())); |
| 145 ipc_adapter->ConnectChannel(); | 166 ipc_adapter->ConnectChannel(); |
| 146 #if defined(OS_POSIX) | 167 #if defined(OS_POSIX) |
| 147 handle->socket = | 168 handle->socket = |
| 148 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor(), true); | 169 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor(), true); |
| 149 #endif | 170 #endif |
| 150 | 171 |
| 151 // Pass a NaClDesc to the untrusted side. This will hold a ref to the | 172 // Pass a NaClDesc to the untrusted side. This will hold a ref to the |
| 152 // NaClIPCAdapter. | 173 // NaClIPCAdapter. |
| 153 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); | 174 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); |
| 175 return ipc_adapter; | |
| 154 } | 176 } |
| 155 | 177 |
| 156 } // namespace | 178 } // namespace |
| 157 | 179 |
| 158 class BrowserValidationDBProxy : public NaClValidationDB { | 180 class BrowserValidationDBProxy : public NaClValidationDB { |
| 159 public: | 181 public: |
| 160 explicit BrowserValidationDBProxy(NaClListener* listener) | 182 explicit BrowserValidationDBProxy(NaClListener* listener) |
| 161 : listener_(listener) { | 183 : listener_(listener) { |
| 162 } | 184 } |
| 163 | 185 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 DCHECK(main_loop_ != NULL); | 266 DCHECK(main_loop_ != NULL); |
| 245 if (base::MessageLoop::current() == main_loop_) { | 267 if (base::MessageLoop::current() == main_loop_) { |
| 246 // This thread owns the channel. | 268 // This thread owns the channel. |
| 247 return channel_->Send(msg); | 269 return channel_->Send(msg); |
| 248 } else { | 270 } else { |
| 249 // This thread does not own the channel. | 271 // This thread does not own the channel. |
| 250 return filter_->Send(msg); | 272 return filter_->Send(msg); |
| 251 } | 273 } |
| 252 } | 274 } |
| 253 | 275 |
| 276 class FileTokenMessageFilter : public IPC::MessageFilter { | |
| 277 public: | |
| 278 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { | |
|
Mark Seaborn
2014/08/28 23:40:22
Why is this handled in a new MessageFilter? Can't
teravest
2014/09/04 22:13:30
This has to be handled in a new MessageFilter so t
Mark Seaborn
2014/09/09 04:42:29
Makes sense. Can you add that as a comment on Fil
teravest
2014/09/09 16:49:06
Done.
| |
| 279 bool handled = true; | |
| 280 IPC_BEGIN_MESSAGE_MAP(FileTokenMessageFilter, msg) | |
| 281 IPC_MESSAGE_HANDLER(NaClProcessMsg_ResolveFileTokenAsyncReply, | |
| 282 OnResolveFileTokenAsyncReply) | |
| 283 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 284 IPC_END_MESSAGE_MAP() | |
| 285 return handled; | |
| 286 } | |
| 287 void OnResolveFileTokenAsyncReply( | |
| 288 uint64_t token_lo, | |
| 289 uint64_t token_hi, | |
| 290 IPC::PlatformFileForTransit ipc_fd, | |
| 291 base::FilePath file_path) { | |
| 292 // TODO: Replace this with a token lookup. | |
| 293 g_resolved_cb.Run(ipc_fd, file_path); | |
| 294 g_resolved_cb.Reset(); | |
| 295 } | |
| 296 private: | |
| 297 virtual ~FileTokenMessageFilter() { } | |
| 298 }; | |
| 299 | |
| 254 void NaClListener::Listen() { | 300 void NaClListener::Listen() { |
| 255 std::string channel_name = | 301 std::string channel_name = |
| 256 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 302 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 257 switches::kProcessChannelID); | 303 switches::kProcessChannelID); |
| 258 channel_ = IPC::SyncChannel::Create( | 304 channel_ = IPC::SyncChannel::Create( |
| 259 this, io_thread_.message_loop_proxy().get(), &shutdown_event_); | 305 this, io_thread_.message_loop_proxy().get(), &shutdown_event_); |
| 260 filter_ = new IPC::SyncMessageFilter(&shutdown_event_); | 306 filter_ = new IPC::SyncMessageFilter(&shutdown_event_); |
| 261 channel_->AddFilter(filter_.get()); | 307 channel_->AddFilter(filter_.get()); |
| 308 channel_->AddFilter(new FileTokenMessageFilter()); | |
| 262 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); | 309 channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); |
| 263 main_loop_ = base::MessageLoop::current(); | 310 main_loop_ = base::MessageLoop::current(); |
| 264 main_loop_->Run(); | 311 main_loop_->Run(); |
| 265 } | 312 } |
| 266 | 313 |
| 267 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { | 314 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { |
| 268 bool handled = true; | 315 bool handled = true; |
| 269 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) | 316 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) |
| 270 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) | 317 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) |
| 271 IPC_MESSAGE_UNHANDLED(handled = false) | 318 IPC_MESSAGE_UNHANDLED(handled = false) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 291 NaClSetFatalErrorCallback(&FatalLogHandler); | 338 NaClSetFatalErrorCallback(&FatalLogHandler); |
| 292 | 339 |
| 293 nap = NaClAppCreate(); | 340 nap = NaClAppCreate(); |
| 294 if (nap == NULL) { | 341 if (nap == NULL) { |
| 295 LOG(ERROR) << "NaClAppCreate() failed"; | 342 LOG(ERROR) << "NaClAppCreate() failed"; |
| 296 return; | 343 return; |
| 297 } | 344 } |
| 298 | 345 |
| 299 IPC::ChannelHandle browser_handle; | 346 IPC::ChannelHandle browser_handle; |
| 300 IPC::ChannelHandle ppapi_renderer_handle; | 347 IPC::ChannelHandle ppapi_renderer_handle; |
| 348 IPC::ChannelHandle manifest_service_handle; | |
| 301 | 349 |
| 302 if (params.enable_ipc_proxy) { | 350 if (params.enable_ipc_proxy) { |
| 303 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); | 351 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); |
| 304 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); | 352 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); |
| 353 manifest_service_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); | |
| 305 | 354 |
| 306 // Create the PPAPI IPC channels between the NaCl IRT and the host | 355 // Create the PPAPI IPC channels between the NaCl IRT and the host |
| 307 // (browser/renderer) processes. The IRT uses these channels to | 356 // (browser/renderer) processes. The IRT uses these channels to |
| 308 // communicate with the host and to initialize the IPC dispatchers. | 357 // communicate with the host and to initialize the IPC dispatchers. |
| 309 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), | 358 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), |
| 310 nap, NACL_CHROME_DESC_BASE); | 359 nap, NACL_CHROME_DESC_BASE); |
| 311 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), | 360 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), |
| 312 nap, NACL_CHROME_DESC_BASE + 1); | 361 nap, NACL_CHROME_DESC_BASE + 1); |
| 362 | |
| 363 scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter = | |
| 364 SetUpIPCAdapter(&manifest_service_handle, | |
| 365 io_thread_.message_loop_proxy(), | |
| 366 nap, | |
| 367 NACL_CHROME_DESC_BASE + 2); | |
| 368 manifest_ipc_adapter->set_resolve_file_token_callback( | |
| 369 base::Bind(&ResolveFileToken)); | |
| 313 } | 370 } |
| 314 | 371 |
| 315 trusted_listener_ = new NaClTrustedListener( | 372 trusted_listener_ = new NaClTrustedListener( |
| 316 IPC::Channel::GenerateVerifiedChannelID("nacl"), | 373 IPC::Channel::GenerateVerifiedChannelID("nacl"), |
| 317 io_thread_.message_loop_proxy().get(), | 374 io_thread_.message_loop_proxy().get(), |
| 318 &shutdown_event_); | 375 &shutdown_event_); |
| 319 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 376 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
| 320 browser_handle, | 377 browser_handle, |
| 321 ppapi_renderer_handle, | 378 ppapi_renderer_handle, |
| 322 trusted_listener_->TakeClientChannelHandle(), | 379 trusted_listener_->TakeClientChannelHandle(), |
| 323 IPC::ChannelHandle()))) | 380 manifest_service_handle))) |
| 324 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; | 381 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; |
| 325 | 382 |
| 326 std::vector<nacl::FileDescriptor> handles = params.handles; | 383 std::vector<nacl::FileDescriptor> handles = params.handles; |
| 327 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | 384 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); |
| 328 if (args == NULL) { | 385 if (args == NULL) { |
| 329 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; | 386 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; |
| 330 return; | 387 return; |
| 331 } | 388 } |
| 332 | 389 |
| 333 #if defined(OS_LINUX) || defined(OS_MACOSX) | 390 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 args->nexe_desc = NaClDescIoFromFileInfo(nexe_file_info, NACL_ABI_O_RDONLY); | 477 args->nexe_desc = NaClDescIoFromFileInfo(nexe_file_info, NACL_ABI_O_RDONLY); |
| 421 | 478 |
| 422 int exit_status; | 479 int exit_status; |
| 423 if (!NaClChromeMainStart(nap, args, &exit_status)) | 480 if (!NaClChromeMainStart(nap, args, &exit_status)) |
| 424 NaClExit(1); | 481 NaClExit(1); |
| 425 | 482 |
| 426 // Report the plugin's exit status if the application started successfully. | 483 // Report the plugin's exit status if the application started successfully. |
| 427 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); | 484 trusted_listener_->Send(new NaClRendererMsg_ReportExitStatus(exit_status)); |
| 428 NaClExit(exit_status); | 485 NaClExit(exit_status); |
| 429 } | 486 } |
| OLD | NEW |