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
3 // found in the LICENSE file.
5 #include "ppapi/nacl_irt/manifest_service.h"
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "ipc/ipc_channel_handle.h"
9 #include "ipc/ipc_channel_proxy.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"
14 #include "ppapi/proxy/ppapi_messages.h"
18 const char kFilePrefix
[] = "files/";
20 ManifestService::ManifestService(
21 const IPC::ChannelHandle
& handle
,
22 scoped_refptr
<base::MessageLoopProxy
> io_message_loop
,
23 base::WaitableEvent
* shutdown_event
) {
24 filter_
= new IPC::SyncMessageFilter(shutdown_event
);
25 channel_
.reset(new IPC::ChannelProxy(handle
,
26 IPC::Channel::MODE_SERVER
,
29 channel_
->AddFilter(filter_
.get());
32 ManifestService::~ManifestService() {
35 void ManifestService::StartupInitializationComplete() {
36 filter_
->Send(new PpapiHostMsg_StartupInitializationComplete
);
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
)) ||
46 LOG(ERROR
) << "ManifestService::OpenResource failed:" << file
;
51 *fd
= ipc_fd
.descriptor().fd
;
55 int IrtOpenResource(const char* file
, int* fd
) {
56 // Remove leading '/' character.
60 ManifestService
* manifest_service
= GetManifestService();
61 if (manifest_service
== NULL
||
62 !manifest_service
->OpenResource(file
, fd
)) {
66 return (*fd
== -1) ? NACL_ABI_ENOENT
: 0;