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 #ifndef CHROME_NACL_NACL_IPC_ADAPTER_H_ | 5 #ifndef CHROME_NACL_NACL_IPC_ADAPTER_H_ |
6 #define CHROME_NACL_NACL_IPC_ADAPTER_H_ | 6 #define CHROME_NACL_NACL_IPC_ADAPTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 #pragma pack(pop) | 73 #pragma pack(pop) |
74 | 74 |
75 typedef base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> | 75 typedef base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)> |
76 ResolveFileTokenReplyCallback; | 76 ResolveFileTokenReplyCallback; |
77 | 77 |
78 typedef base::Callback<void(uint64_t, // file_token_lo | 78 typedef base::Callback<void(uint64_t, // file_token_lo |
79 uint64_t, // file_token_hi | 79 uint64_t, // file_token_hi |
80 ResolveFileTokenReplyCallback)> | 80 ResolveFileTokenReplyCallback)> |
81 ResolveFileTokenCallback; | 81 ResolveFileTokenCallback; |
82 | 82 |
| 83 typedef base::Callback<void(const IPC::Message&, |
| 84 IPC::PlatformFileForTransit, |
| 85 base::FilePath)> OpenResourceReplyCallback; |
| 86 |
| 87 typedef base::Callback<bool(const IPC::Message&, |
| 88 const std::string&, // key |
| 89 OpenResourceReplyCallback)> OpenResourceCallback; |
| 90 |
83 // Creates an adapter, using the thread associated with the given task | 91 // Creates an adapter, using the thread associated with the given task |
84 // runner for posting messages. In normal use, the task runner will post to | 92 // runner for posting messages. In normal use, the task runner will post to |
85 // the I/O thread of the process. | 93 // the I/O thread of the process. |
86 // | 94 // |
87 // If you use this constructor, you MUST call ConnectChannel after the | 95 // If you use this constructor, you MUST call ConnectChannel after the |
88 // NaClIPCAdapter is constructed, or the NaClIPCAdapter's channel will not be | 96 // NaClIPCAdapter is constructed, or the NaClIPCAdapter's channel will not be |
89 // connected. | 97 // connected. |
90 // | 98 // |
91 // |resolve_file_token_cb| is an optional callback to be invoked for | 99 // |resolve_file_token_cb| is an optional callback to be invoked for |
92 // resolving file tokens received from the renderer. When the file token | 100 // resolving file tokens received from the renderer. When the file token |
93 // is resolved, the ResolveFileTokenReplyCallback passed inside the | 101 // is resolved, the ResolveFileTokenReplyCallback passed inside the |
94 // ResolveFileTokenCallback will be invoked. | 102 // ResolveFileTokenCallback will be invoked. |open_resource_cb| is also an |
| 103 // optional callback to be invoked for intercepting open_resource IRT calls. |
| 104 // |open_resource_cb| may immediately call a OpenResourceReplyCallback |
| 105 // function to send a pre-opened resource descriptor to the untrusted side. |
| 106 // OpenResourceCallback returns true when OpenResourceReplyCallback is called. |
95 NaClIPCAdapter( | 107 NaClIPCAdapter( |
96 const IPC::ChannelHandle& handle, | 108 const IPC::ChannelHandle& handle, |
97 base::TaskRunner* runner, | 109 base::TaskRunner* runner, |
98 ResolveFileTokenCallback resolve_file_token_cb); | 110 ResolveFileTokenCallback resolve_file_token_cb, |
| 111 OpenResourceCallback open_resource_cb); |
99 | 112 |
100 // Initializes with a given channel that's already created for testing | 113 // Initializes with a given channel that's already created for testing |
101 // purposes. This function will take ownership of the given channel. | 114 // purposes. This function will take ownership of the given channel. |
102 NaClIPCAdapter(scoped_ptr<IPC::Channel> channel, base::TaskRunner* runner); | 115 NaClIPCAdapter(scoped_ptr<IPC::Channel> channel, base::TaskRunner* runner); |
103 | 116 |
104 // Connect the channel. This must be called after the constructor that accepts | 117 // Connect the channel. This must be called after the constructor that accepts |
105 // an IPC::ChannelHandle, and causes the Channel to be connected on the IO | 118 // an IPC::ChannelHandle, and causes the Channel to be connected on the IO |
106 // thread. | 119 // thread. |
107 void ConnectChannel(); | 120 void ConnectChannel(); |
108 | 121 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 183 |
171 // When we send a synchronous message (from untrusted to trusted), we store | 184 // When we send a synchronous message (from untrusted to trusted), we store |
172 // its type here, so that later we can associate the reply with its type | 185 // its type here, so that later we can associate the reply with its type |
173 // for scanning. | 186 // for scanning. |
174 typedef std::map<int, uint32> PendingSyncMsgMap; | 187 typedef std::map<int, uint32> PendingSyncMsgMap; |
175 PendingSyncMsgMap pending_sync_msgs_; | 188 PendingSyncMsgMap pending_sync_msgs_; |
176 }; | 189 }; |
177 | 190 |
178 ~NaClIPCAdapter() override; | 191 ~NaClIPCAdapter() override; |
179 | 192 |
180 void OnFileTokenResolved(const IPC::Message& orig_msg, | 193 void SaveOpenResourceMessage(const IPC::Message& orig_msg, |
181 IPC::PlatformFileForTransit ipc_fd, | 194 IPC::PlatformFileForTransit ipc_fd, |
182 base::FilePath file_path); | 195 base::FilePath file_path); |
183 | 196 |
184 bool RewriteMessage(const IPC::Message& msg, uint32_t type); | 197 bool RewriteMessage(const IPC::Message& msg, uint32_t type); |
185 | 198 |
186 // Returns 0 if nothing is waiting. | 199 // Returns 0 if nothing is waiting. |
187 int LockedReceive(NaClImcTypedMsgHdr* msg); | 200 int LockedReceive(NaClImcTypedMsgHdr* msg); |
188 | 201 |
189 // Sends a message that we know has been completed to the Chrome process. | 202 // Sends a message that we know has been completed to the Chrome process. |
190 bool SendCompleteMessage(const char* buffer, size_t buffer_len); | 203 bool SendCompleteMessage(const char* buffer, size_t buffer_len); |
191 | 204 |
192 // Clears the LockedData.to_be_sent_ structure in a way to make sure that | 205 // Clears the LockedData.to_be_sent_ structure in a way to make sure that |
193 // the memory is deleted. std::string can sometimes hold onto the buffer | 206 // the memory is deleted. std::string can sometimes hold onto the buffer |
194 // for future use which we don't want. | 207 // for future use which we don't want. |
195 void ClearToBeSent(); | 208 void ClearToBeSent(); |
196 | 209 |
197 void ConnectChannelOnIOThread(); | 210 void ConnectChannelOnIOThread(); |
198 void CloseChannelOnIOThread(); | 211 void CloseChannelOnIOThread(); |
199 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); | 212 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); |
200 | 213 |
201 // Saves the message to forward to NaCl. This method assumes that the caller | 214 // Saves the message to forward to NaCl. This method assumes that the caller |
202 // holds the lock for locked_data_. | 215 // holds the lock for locked_data_. |
203 void SaveMessage(const IPC::Message& message, | 216 void SaveMessage(const IPC::Message& message, |
204 RewrittenMessage* rewritten_message); | 217 RewrittenMessage* rewritten_message); |
205 | 218 |
206 base::Lock lock_; | 219 base::Lock lock_; |
207 base::ConditionVariable cond_var_; | 220 base::ConditionVariable cond_var_; |
208 | 221 |
209 scoped_refptr<base::TaskRunner> task_runner_; | 222 scoped_refptr<base::TaskRunner> task_runner_; |
210 | 223 |
211 ResolveFileTokenCallback resolve_file_token_cb_; | 224 ResolveFileTokenCallback resolve_file_token_cb_; |
| 225 OpenResourceCallback open_resource_cb_; |
212 | 226 |
213 // To be accessed inside of lock_ only. | 227 // To be accessed inside of lock_ only. |
214 LockedData locked_data_; | 228 LockedData locked_data_; |
215 | 229 |
216 // To be accessed on the I/O thread (via task runner) only. | 230 // To be accessed on the I/O thread (via task runner) only. |
217 IOThreadData io_thread_data_; | 231 IOThreadData io_thread_data_; |
218 | 232 |
219 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); | 233 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); |
220 }; | 234 }; |
221 | 235 |
222 // Export TranslatePepperFileReadWriteOpenFlags for testing. | 236 // Export TranslatePepperFileReadWriteOpenFlags for testing. |
223 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags); | 237 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags); |
224 | 238 |
225 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ | 239 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ |
OLD | NEW |