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" |
9 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
10 #include "ipc/ipc_channel.h" | 11 #include "ipc/ipc_channel.h" |
11 #include "ipc/ipc_sync_channel.h" | 12 #include "ipc/ipc_sync_channel.h" |
12 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
14 | 15 |
15 namespace nacl { | 16 namespace nacl { |
16 | 17 |
17 ManifestServiceChannel::ManifestServiceChannel( | 18 ManifestServiceChannel::ManifestServiceChannel( |
18 const IPC::ChannelHandle& handle, | 19 const IPC::ChannelHandle& handle, |
19 const base::Callback<void(int32_t)>& connected_callback, | 20 const base::Callback<void(int32_t)>& connected_callback, |
20 scoped_ptr<Delegate> delegate, | 21 scoped_ptr<Delegate> delegate, |
21 base::WaitableEvent* waitable_event) | 22 base::WaitableEvent* waitable_event) |
22 : connected_callback_(connected_callback), | 23 : connected_callback_(connected_callback), |
23 delegate_(delegate.Pass()), | 24 delegate_(delegate.Pass()), |
24 channel_(new IPC::SyncChannel( | 25 channel_(new IPC::SyncChannel( |
25 handle, IPC::Channel::MODE_CLIENT, this, | 26 handle, IPC::Channel::MODE_CLIENT, this, |
26 content::RenderThread::Get()->GetIOMessageLoopProxy(), | 27 content::RenderThread::Get()->GetIOMessageLoopProxy(), |
27 true, waitable_event)) { | 28 true, waitable_event)), |
29 weak_ptr_factory_(this) { | |
28 } | 30 } |
29 | 31 |
30 ManifestServiceChannel::~ManifestServiceChannel() { | 32 ManifestServiceChannel::~ManifestServiceChannel() { |
31 if (!connected_callback_.is_null()) | 33 if (!connected_callback_.is_null()) |
32 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); | 34 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); |
33 } | 35 } |
34 | 36 |
37 void ManifestServiceChannel::Send(IPC::Message* message) { | |
38 channel_->Send(message); | |
39 } | |
40 | |
35 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) { | 41 bool ManifestServiceChannel::OnMessageReceived(const IPC::Message& message) { |
36 // TODO(hidehiko): Implement OpenResource. | |
37 bool handled = true; | 42 bool handled = true; |
38 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message) | 43 IPC_BEGIN_MESSAGE_MAP(ManifestServiceChannel, message) |
39 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete, | 44 IPC_MESSAGE_HANDLER(PpapiHostMsg_StartupInitializationComplete, |
40 OnStartupInitializationComplete) | 45 OnStartupInitializationComplete) |
46 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiHostMsg_OpenResource, | |
47 OnOpenResource) | |
41 IPC_MESSAGE_UNHANDLED(handled = false) | 48 IPC_MESSAGE_UNHANDLED(handled = false) |
42 IPC_END_MESSAGE_MAP() | 49 IPC_END_MESSAGE_MAP() |
43 return handled; | 50 return handled; |
44 } | 51 } |
45 | 52 |
46 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) { | 53 void ManifestServiceChannel::OnChannelConnected(int32 peer_pid) { |
47 if (!connected_callback_.is_null()) | 54 if (!connected_callback_.is_null()) |
48 base::ResetAndReturn(&connected_callback_).Run(PP_OK); | 55 base::ResetAndReturn(&connected_callback_).Run(PP_OK); |
49 } | 56 } |
50 | 57 |
51 void ManifestServiceChannel::OnChannelError() { | 58 void ManifestServiceChannel::OnChannelError() { |
52 if (!connected_callback_.is_null()) | 59 if (!connected_callback_.is_null()) |
53 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); | 60 base::ResetAndReturn(&connected_callback_).Run(PP_ERROR_FAILED); |
54 } | 61 } |
55 | 62 |
56 void ManifestServiceChannel::OnStartupInitializationComplete() { | 63 void ManifestServiceChannel::OnStartupInitializationComplete() { |
57 delegate_->StartupInitializationComplete(); | 64 delegate_->StartupInitializationComplete(); |
58 } | 65 } |
59 | 66 |
67 void ManifestServiceChannel::OnOpenResource( | |
68 const std::string& key, IPC::Message* reply) { | |
69 delegate_->OpenResource(key, | |
Mark Seaborn
2014/04/30 21:20:58
On Windows, it would be better for this to be a no
hidehiko
2014/05/01 05:20:31
Done.
| |
70 base::Bind(&ManifestServiceChannel::DidOpenResource, | |
71 weak_ptr_factory_.GetWeakPtr(), reply)); | |
72 } | |
73 | |
74 void ManifestServiceChannel::DidOpenResource( | |
75 IPC::Message* reply, const base::PlatformFile& platform_file) { | |
76 #if defined(OS_WIN) | |
77 // Currently this is used only for non-SFI mode, which is not supported on | |
78 // windows. | |
79 NOTREACHED(); | |
Mark Seaborn
2014/04/30 21:20:58
This would allow the NaCl process to crash the ren
hidehiko
2014/05/01 05:20:31
IMHO, crashing on Debug build is fine. Actually, t
Mark Seaborn
2014/05/01 06:32:35
For what meaning of "should"? :-) Untrusted code
hidehiko
2014/05/01 13:05:40
I'm a bit confused. I thought nacl_helper is a par
Mark Seaborn
2014/05/01 23:28:33
Ah, sorry, I hadn't realised that the new IPC chan
hidehiko
2014/05/02 01:32:27
Thanks. So let's keep the current error handling.
| |
80 #else | |
81 // Here, PlatformFileForTransit is alias of base::FileDescriptor. | |
82 PpapiHostMsg_OpenResource::WriteReplyParams( | |
83 reply, | |
84 ppapi::proxy::SerializedHandle( | |
85 ppapi::proxy::SerializedHandle::FILE, | |
86 base::FileDescriptor(platform_file, true))); | |
Mark Seaborn
2014/04/30 21:20:58
On error, platform_file will be PP_kInvalidFileHan
hidehiko
2014/05/01 05:20:31
I think it's fine. Anyway, let's add a test case i
Mark Seaborn
2014/05/01 06:32:35
Hmm, as I read it, that means you're not sure whet
hidehiko
2014/05/01 13:05:40
I've already confirmed manually, and invoking open
| |
87 #endif | |
88 Send(reply); | |
Mark Seaborn
2014/04/30 21:20:58
What are the implications of calling Send(Reply) w
hidehiko
2014/05/01 05:20:31
acknowledged.
| |
89 } | |
90 | |
60 } // namespace nacl | 91 } // namespace nacl |
OLD | NEW |