OLD | NEW |
| (Empty) |
1 // Copyright 2015 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. | |
4 | |
5 #include "ipc/attachment_broker_unprivileged_win.h" | |
6 | |
7 #include "base/process/process.h" | |
8 #include "ipc/attachment_broker_messages.h" | |
9 #include "ipc/brokerable_attachment.h" | |
10 #include "ipc/handle_attachment_win.h" | |
11 #include "ipc/ipc_sender.h" | |
12 | |
13 namespace IPC { | |
14 | |
15 AttachmentBrokerUnprivilegedWin::AttachmentBrokerUnprivilegedWin() {} | |
16 | |
17 AttachmentBrokerUnprivilegedWin::~AttachmentBrokerUnprivilegedWin() {} | |
18 | |
19 bool AttachmentBrokerUnprivilegedWin::SendAttachmentToProcess( | |
20 const scoped_refptr<BrokerableAttachment>& attachment, | |
21 base::ProcessId destination_process) { | |
22 switch (attachment->GetBrokerableType()) { | |
23 case BrokerableAttachment::WIN_HANDLE: { | |
24 internal::HandleAttachmentWin* handle_attachment = | |
25 static_cast<internal::HandleAttachmentWin*>(attachment.get()); | |
26 internal::HandleAttachmentWin::WireFormat format = | |
27 handle_attachment->GetWireFormat(destination_process); | |
28 bool success = get_sender()->Send( | |
29 new AttachmentBrokerMsg_DuplicateWinHandle(format)); | |
30 if (success) | |
31 handle_attachment->reset_handle_ownership(); | |
32 return success; | |
33 } | |
34 case BrokerableAttachment::MACH_PORT: | |
35 case BrokerableAttachment::PLACEHOLDER: | |
36 NOTREACHED(); | |
37 return false; | |
38 } | |
39 return false; | |
40 } | |
41 | |
42 bool AttachmentBrokerUnprivilegedWin::OnMessageReceived(const Message& msg) { | |
43 bool handled = true; | |
44 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerUnprivilegedWin, msg) | |
45 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated, | |
46 OnWinHandleHasBeenDuplicated) | |
47 IPC_MESSAGE_UNHANDLED(handled = false) | |
48 IPC_END_MESSAGE_MAP() | |
49 return handled; | |
50 } | |
51 | |
52 void AttachmentBrokerUnprivilegedWin::OnWinHandleHasBeenDuplicated( | |
53 const IPC::internal::HandleAttachmentWin::WireFormat& wire_format) { | |
54 // The IPC message was intended for a different process. Ignore it. | |
55 if (wire_format.destination_process != base::Process::Current().Pid()) { | |
56 LogError(WRONG_DESTINATION); | |
57 return; | |
58 } | |
59 | |
60 scoped_refptr<BrokerableAttachment> attachment( | |
61 new IPC::internal::HandleAttachmentWin(wire_format)); | |
62 HandleReceivedAttachment(attachment); | |
63 LogError(SUCCESS); | |
64 } | |
65 | |
66 } // namespace IPC | |
OLD | NEW |