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 "components/nacl/renderer/manifest_service_channel.h" | 5 #include "components/nacl/renderer/manifest_service_channel.h" |
6 | 6 |
7 #include "base/bind.h" | |
7 #include "base/callback.h" | 8 #include "base/callback.h" |
8 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "content/common/sandbox_util.h" | |
9 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
10 #include "ipc/ipc_channel.h" | 12 #include "ipc/ipc_channel.h" |
11 #include "ipc/ipc_sync_channel.h" | 13 #include "ipc/ipc_sync_channel.h" |
12 #include "ppapi/c/pp_errors.h" | 14 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
14 | 16 |
15 namespace nacl { | 17 namespace nacl { |
16 | 18 |
17 ManifestServiceChannel::ManifestServiceChannel( | 19 ManifestServiceChannel::ManifestServiceChannel( |
18 const IPC::ChannelHandle& handle, | 20 const IPC::ChannelHandle& handle, |
19 const base::Callback<void(int32_t)>& connected_callback, | 21 const base::Callback<void(int32_t)>& connected_callback, |
20 scoped_ptr<Delegate> delegate, | 22 scoped_ptr<Delegate> delegate, |
21 base::WaitableEvent* waitable_event) | 23 base::WaitableEvent* waitable_event) |
22 : connected_callback_(connected_callback), | 24 : connected_callback_(connected_callback), |
23 delegate_(delegate.Pass()), | 25 delegate_(delegate.Pass()), |
24 channel_(new IPC::SyncChannel( | 26 channel_(new IPC::SyncChannel( |
25 handle, IPC::Channel::MODE_CLIENT, this, | 27 handle, IPC::Channel::MODE_CLIENT, this, |
26 content::RenderThread::Get()->GetIOMessageLoopProxy(), | 28 content::RenderThread::Get()->GetIOMessageLoopProxy(), |
27 true, waitable_event)) { | 29 true, waitable_event)), |
30 peer_handle_(base::kNullProcessHandle), | |
31 weak_ptr_factory_(this) { | |
28 } | 32 } |
29 | 33 |
30 ManifestServiceChannel::~ManifestServiceChannel() { | 34 ManifestServiceChannel::~ManifestServiceChannel() { |
31 if (!connected_callback_.is_null()) | 35 if (!connected_callback_.is_null()) |
32 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); | 36 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); |
37 if (peer_handle_ != base::kNullProcessHandle) | |
38 base::CloseProcessHandle(peer_handle_); | |
39 } | |
40 | |
41 void ManifestServiceChannel::Send(IPC::Message* message) { | |
42 channel_->Send(message); | |
33 } | 43 } |
34 | 44 |
35 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) { | 45 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) { |
36 // TODO(hidehiko): Implement OpenResource. | |
37 bool handled = true; | 46 bool handled = true; |
38 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message) | 47 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message) |
39 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete, | 48 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete, |
40 OnStartupInitializationComplete) | 49 OnStartupInitializationComplete) |
50 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource, | |
51 OnOpenResource) | |
41 IPC_MESSAGE_UNHANDLED(handled = false) | 52 IPC_MESSAGE_UNHANDLED(handled = false) |
42 IPC_END_MESSAGE_MAP() | 53 IPC_END_MESSAGE_MAP() |
43 return handled; | 54 return handled; |
44 } | 55 } |
45 | 56 |
46 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) { | 57 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) { |
47 if (!connected_callback_.is_null()) | 58 if (!connected_callback_.is_null()) |
48 base::ResetAndReturn(&connected_callback_).Run(PP_OK); | 59 base::ResetAndReturn(&connected_callback_).Run(PP_OK); |
49 } | 60 } |
50 | 61 |
51 void ManifestServiceChannel::OnChannelError() { | 62 void ManifestServiceChannel::OnChannelError() { |
52 if (!connected_callback_.is_null()) | 63 if (!connected_callback_.is_null()) |
53 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); | 64 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); |
54 } | 65 } |
55 | 66 |
56 void ManifestServiceChannel::OnStartupInitializationComplete() { | 67 void ManifestServiceChannel::OnStartupInitializationComplete() { |
57 delegate_->StartupInitializationComplete(); | 68 delegate_->StartupInitializationComplete(); |
58 } | 69 } |
59 | 70 |
71 void ManifestServiceChannel::OnOpenResource( | |
72 const std::string& key, IPC::Message* reply) { | |
73 delegate_->OpenResource(key, | |
74 base::Bind(&ManifestServiceChannel::DidOpenResource, | |
75 weak_ptr_factory_.GetWeakPtr(), reply)); | |
76 } | |
77 | |
78 void ManifestServiceChannel::DidOpenResource( | |
79 IPC::Message* reply, int32_t pp_error, | |
dmichael (off chromium)
2014/04/25 21:06:58
style nit: Parameters should be either all on one
hidehiko
2014/04/28 08:44:27
Done.
| |
80 const base::PlatformFile& platform_file) { | |
81 PpapiHostMsg_OpenResource::WriteReplyParams( | |
82 reply, | |
83 ppapi::proxy::SerializedHandle( | |
84 ppapi::proxy::SerializedHandle::FILE, | |
85 content::BrokerGetFileHandleForProcess( | |
86 platform_file, PeerHandle(), true))); | |
Mark Seaborn
2014/04/26 00:18:59
On Unix, the PeerHandle() arg is ignored... You c
hidehiko
2014/04/28 08:44:27
Ok, then, let's ifdef.
I just tried to keep the sa
| |
87 Send(reply); | |
88 } | |
89 | |
90 base::ProcessHandle ManifestServiceChannel::PeerHandle() { | |
91 // This function is only called from DidOpenResource(), which always runs on | |
92 // the same thread. | |
93 if (peer_handle_ == base::kNullProcessHandle) | |
94 base::OpenPrivilegedProcessHandle(channel_->peer_pid(), &peer_handle_); | |
Mark Seaborn
2014/04/26 00:18:59
This only does something interesting on Windows, s
hidehiko
2014/04/28 08:44:27
Removed.
| |
95 return peer_handle_; | |
96 } | |
97 | |
60 } // namespace nacl | 98 } // namespace nacl |
OLD | NEW |