erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 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 | |
erikchen | 484c0084 | 2015-07-28 23:25:44 | [diff] [blame] | 5 | #include "ipc/attachment_broker_unprivileged_win.h" |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 6 | |
erikchen | 7252aa36 | 2015-07-15 01:35:39 | [diff] [blame] | 7 | #include "base/process/process.h" |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 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 | |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 13 | namespace IPC { |
| 14 | |
erikchen | 484c0084 | 2015-07-28 23:25:44 | [diff] [blame] | 15 | AttachmentBrokerUnprivilegedWin::AttachmentBrokerUnprivilegedWin() {} |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 16 | |
erikchen | 484c0084 | 2015-07-28 23:25:44 | [diff] [blame] | 17 | AttachmentBrokerUnprivilegedWin::~AttachmentBrokerUnprivilegedWin() {} |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 18 | |
erikchen | 484c0084 | 2015-07-28 23:25:44 | [diff] [blame] | 19 | bool AttachmentBrokerUnprivilegedWin::SendAttachmentToProcess( |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 20 | const BrokerableAttachment* attachment, |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 21 | base::ProcessId destination_process) { |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 22 | switch (attachment->GetBrokerableType()) { |
| 23 | case BrokerableAttachment::WIN_HANDLE: |
| 24 | const internal::HandleAttachmentWin* handle_attachment = |
| 25 | static_cast<const internal::HandleAttachmentWin*>(attachment); |
| 26 | internal::HandleAttachmentWin::WireFormat format = |
| 27 | handle_attachment->GetWireFormat(destination_process); |
erikchen | 484c0084 | 2015-07-28 23:25:44 | [diff] [blame] | 28 | return get_sender()->Send( |
| 29 | new AttachmentBrokerMsg_DuplicateWinHandle(format)); |
erikchen | de9412b8 | 2015-07-27 18:26:14 | [diff] [blame] | 30 | } |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 31 | return false; |
| 32 | } |
| 33 | |
erikchen | 484c0084 | 2015-07-28 23:25:44 | [diff] [blame] | 34 | bool AttachmentBrokerUnprivilegedWin::OnMessageReceived(const Message& msg) { |
erikchen | 7252aa36 | 2015-07-15 01:35:39 | [diff] [blame] | 35 | bool handled = true; |
erikchen | 484c0084 | 2015-07-28 23:25:44 | [diff] [blame] | 36 | IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerUnprivilegedWin, msg) |
erikchen | 7252aa36 | 2015-07-15 01:35:39 | [diff] [blame] | 37 | IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated, |
| 38 | OnWinHandleHasBeenDuplicated) |
| 39 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 40 | IPC_END_MESSAGE_MAP() |
| 41 | return handled; |
| 42 | } |
| 43 | |
erikchen | 484c0084 | 2015-07-28 23:25:44 | [diff] [blame] | 44 | void AttachmentBrokerUnprivilegedWin::OnWinHandleHasBeenDuplicated( |
erikchen | 7252aa36 | 2015-07-15 01:35:39 | [diff] [blame] | 45 | const IPC::internal::HandleAttachmentWin::WireFormat& wire_format) { |
| 46 | // The IPC message was intended for a different process. Ignore it. |
| 47 | if (wire_format.destination_process != base::Process::Current().Pid()) |
| 48 | return; |
| 49 | |
| 50 | scoped_refptr<BrokerableAttachment> attachment( |
| 51 | new IPC::internal::HandleAttachmentWin(wire_format)); |
erikchen | c04ab34c | 2015-07-27 20:28:20 | [diff] [blame] | 52 | HandleReceivedAttachment(attachment); |
erikchen | 7252aa36 | 2015-07-15 01:35:39 | [diff] [blame] | 53 | } |
| 54 | |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 55 | } // namespace IPC |