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 #include "ppapi/proxy/nacl_message_scanner.h" | 5 #include "ppapi/proxy/nacl_message_scanner.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 it != file_systems_.end(); ++it) | 282 it != file_systems_.end(); ++it) |
283 delete it->second; | 283 delete it->second; |
284 for (FileIOMap::iterator it = files_.begin(); it != files_.end(); ++it) | 284 for (FileIOMap::iterator it = files_.begin(); it != files_.end(); ++it) |
285 delete it->second; | 285 delete it->second; |
286 } | 286 } |
287 | 287 |
288 // Windows IPC differs from POSIX in that native handles are serialized in the | 288 // Windows IPC differs from POSIX in that native handles are serialized in the |
289 // message body, rather than passed in a separate FileDescriptorSet. Therefore, | 289 // message body, rather than passed in a separate FileDescriptorSet. Therefore, |
290 // on Windows, any message containing handles must be rewritten in the POSIX | 290 // on Windows, any message containing handles must be rewritten in the POSIX |
291 // format before we can send it to the NaCl plugin. | 291 // format before we can send it to the NaCl plugin. |
292 // | |
293 // On POSIX and Windows we have to rewrite PpapiMsg_CreateNaClChannel messages. | |
294 // These contain a handle with an invalid (place holder) descriptor. We need to | |
295 // locate this handle so it can be replaced with a valid one when the channel is | |
296 // created. | |
297 bool NaClMessageScanner::ScanMessage( | 292 bool NaClMessageScanner::ScanMessage( |
298 const IPC::Message& msg, | 293 const IPC::Message& msg, |
299 std::vector<SerializedHandle>* handles, | 294 std::vector<SerializedHandle>* handles, |
300 scoped_ptr<IPC::Message>* new_msg_ptr) { | 295 scoped_ptr<IPC::Message>* new_msg_ptr) { |
301 DCHECK(handles); | 296 DCHECK(handles); |
302 DCHECK(handles->empty()); | 297 DCHECK(handles->empty()); |
303 DCHECK(new_msg_ptr); | 298 DCHECK(new_msg_ptr); |
304 DCHECK(!new_msg_ptr->get()); | 299 DCHECK(!new_msg_ptr->get()); |
305 | 300 |
306 bool rewrite_msg = | 301 bool rewrite_msg = |
307 #if defined(OS_WIN) | 302 #if defined(OS_WIN) |
308 true; | 303 true; |
309 #else | 304 #else |
310 (msg.type() == PpapiMsg_CreateNaClChannel::ID); | 305 false; |
311 #endif | 306 #endif |
312 | 307 |
313 // We can't always tell from the message ID if rewriting is needed. Therefore, | 308 // We can't always tell from the message ID if rewriting is needed. Therefore, |
314 // scan any message types that might contain a handle. If we later determine | 309 // scan any message types that might contain a handle. If we later determine |
315 // that there are no handles, we can cancel the rewriting by clearing the | 310 // that there are no handles, we can cancel the rewriting by clearing the |
316 // results.new_msg pointer. | 311 // results.new_msg pointer. |
317 ScanningResults results; | 312 ScanningResults results; |
318 results.nested_msg_callback = | 313 results.nested_msg_callback = |
319 base::Bind(&NaClMessageScanner::AuditNestedMessage, | 314 base::Bind(&NaClMessageScanner::AuditNestedMessage, |
320 base::Unretained(this)); | 315 base::Unretained(this)); |
321 switch (msg.type()) { | 316 switch (msg.type()) { |
322 CASE_FOR_MESSAGE(PpapiMsg_CreateNaClChannel) | |
323 CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated) | 317 CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated) |
324 CASE_FOR_MESSAGE(PpapiMsg_PPPMessaging_HandleMessage) | 318 CASE_FOR_MESSAGE(PpapiMsg_PPPMessaging_HandleMessage) |
325 CASE_FOR_MESSAGE(PpapiPluginMsg_ResourceReply) | 319 CASE_FOR_MESSAGE(PpapiPluginMsg_ResourceReply) |
326 case IPC_REPLY_ID: { | 320 case IPC_REPLY_ID: { |
327 int id = IPC::SyncMessage::GetMessageId(msg); | 321 int id = IPC::SyncMessage::GetMessageId(msg); |
328 PendingSyncMsgMap::iterator iter(pending_sync_msgs_.find(id)); | 322 PendingSyncMsgMap::iterator iter(pending_sync_msgs_.find(id)); |
329 if (iter == pending_sync_msgs_.end()) { | 323 if (iter == pending_sync_msgs_.end()) { |
330 NOTREACHED(); | 324 NOTREACHED(); |
331 return false; | 325 return false; |
332 } | 326 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 fio_it->second->SetMaxWrittenOffset(offset_it->second); | 532 fio_it->second->SetMaxWrittenOffset(offset_it->second); |
539 } | 533 } |
540 } | 534 } |
541 break; | 535 break; |
542 } | 536 } |
543 } | 537 } |
544 } | 538 } |
545 | 539 |
546 } // namespace proxy | 540 } // namespace proxy |
547 } // namespace ppapi | 541 } // namespace ppapi |
OLD | NEW |