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 "ppapi/nacl_irt/manifest_service.h" | 5 #include "ppapi/nacl_irt/manifest_service.h" |
6 | 6 |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "ipc/ipc_channel_handle.h" | 8 #include "ipc/ipc_channel_handle.h" |
9 #include "ipc/ipc_channel_proxy.h" | 9 #include "ipc/ipc_channel_proxy.h" |
10 #include "ipc/ipc_sync_message_filter.h" | 10 #include "ipc/ipc_sync_message_filter.h" |
| 11 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" |
| 12 #include "ppapi/nacl_irt/irt_manifest.h" |
| 13 #include "ppapi/nacl_irt/plugin_startup.h" |
11 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
12 | 15 |
13 namespace ppapi { | 16 namespace ppapi { |
14 | 17 |
| 18 const char kFilePrefix[] = "files/"; |
| 19 |
15 ManifestService::ManifestService( | 20 ManifestService::ManifestService( |
16 const IPC::ChannelHandle& handle, | 21 const IPC::ChannelHandle& handle, |
17 scoped_refptr<base::MessageLoopProxy> io_message_loop, | 22 scoped_refptr<base::MessageLoopProxy> io_message_loop, |
18 base::WaitableEvent* shutdown_event) { | 23 base::WaitableEvent* shutdown_event) { |
19 filter_ = new IPC::SyncMessageFilter(shutdown_event); | 24 filter_ = new IPC::SyncMessageFilter(shutdown_event); |
20 channel_.reset(new IPC::ChannelProxy(handle, | 25 channel_.reset(new IPC::ChannelProxy(handle, |
21 IPC::Channel::MODE_SERVER, | 26 IPC::Channel::MODE_SERVER, |
22 NULL, // Listener | 27 NULL, // Listener |
23 io_message_loop)); | 28 io_message_loop)); |
24 channel_->AddFilter(filter_.get()); | 29 channel_->AddFilter(filter_.get()); |
25 } | 30 } |
26 | 31 |
27 ManifestService::~ManifestService() { | 32 ManifestService::~ManifestService() { |
28 } | 33 } |
29 | 34 |
30 void ManifestService::StartupInitializationComplete() { | 35 void ManifestService::StartupInitializationComplete() { |
31 filter_->Send(new PpapiHostMsg_StartupInitializationComplete); | 36 filter_->Send(new PpapiHostMsg_StartupInitializationComplete); |
32 } | 37 } |
33 | 38 |
| 39 bool ManifestService::OpenResource(const char* file, int* fd) { |
| 40 // OpenResource will return INVALID SerializedHandle, if it is not supported. |
| 41 // Specifically, PNaCl doesn't support open resource. |
| 42 ppapi::proxy::SerializedHandle ipc_fd; |
| 43 if (!filter_->Send(new PpapiHostMsg_OpenResource( |
| 44 std::string(kFilePrefix) + file, &ipc_fd)) || |
| 45 !ipc_fd.is_file()) { |
| 46 LOG(ERROR) << "ManifestService::OpenResource failed:" << file; |
| 47 *fd = -1; |
| 48 return false; |
| 49 } |
| 50 |
| 51 *fd = ipc_fd.descriptor().fd; |
| 52 return true; |
| 53 } |
| 54 |
| 55 int IrtOpenResource(const char* file, int* fd) { |
| 56 // Remove leading '/' character. |
| 57 if (file[0] == '/') |
| 58 ++file; |
| 59 |
| 60 ManifestService* manifest_service = GetManifestService(); |
| 61 if (manifest_service == NULL || |
| 62 !manifest_service->OpenResource(file, fd)) { |
| 63 return NACL_ABI_EIO; |
| 64 } |
| 65 |
| 66 return (*fd == -1) ? NACL_ABI_ENOENT : 0; |
| 67 } |
| 68 |
34 } // namespace ppapi | 69 } // namespace ppapi |
OLD | NEW |