blob: 3d3e845d6b8d50c68bf611e05a28c58960ce96eb [file] [log] [blame]
erikchen151b2f92015-06-16 20:20:511// 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
erikchen484c00842015-07-28 23:25:445#include "ipc/attachment_broker_unprivileged_win.h"
erikchen151b2f92015-06-16 20:20:516
erikchen7252aa362015-07-15 01:35:397#include "base/process/process.h"
erikcheneece6c32015-07-07 22:13:118#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
erikchen151b2f92015-06-16 20:20:5113namespace IPC {
14
erikchen484c00842015-07-28 23:25:4415AttachmentBrokerUnprivilegedWin::AttachmentBrokerUnprivilegedWin() {}
erikchen151b2f92015-06-16 20:20:5116
erikchen484c00842015-07-28 23:25:4417AttachmentBrokerUnprivilegedWin::~AttachmentBrokerUnprivilegedWin() {}
erikchen151b2f92015-06-16 20:20:5118
erikchen484c00842015-07-28 23:25:4419bool AttachmentBrokerUnprivilegedWin::SendAttachmentToProcess(
erikcheneece6c32015-07-07 22:13:1120 const BrokerableAttachment* attachment,
erikchen151b2f92015-06-16 20:20:5121 base::ProcessId destination_process) {
erikcheneece6c32015-07-07 22:13:1122 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);
erikchen484c00842015-07-28 23:25:4428 return get_sender()->Send(
29 new AttachmentBrokerMsg_DuplicateWinHandle(format));
erikchende9412b82015-07-27 18:26:1430 }
erikchen151b2f92015-06-16 20:20:5131 return false;
32}
33
erikchen484c00842015-07-28 23:25:4434bool AttachmentBrokerUnprivilegedWin::OnMessageReceived(const Message& msg) {
erikchen7252aa362015-07-15 01:35:3935 bool handled = true;
erikchen484c00842015-07-28 23:25:4436 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerUnprivilegedWin, msg)
erikchen7252aa362015-07-15 01:35:3937 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated,
38 OnWinHandleHasBeenDuplicated)
39 IPC_MESSAGE_UNHANDLED(handled = false)
40 IPC_END_MESSAGE_MAP()
41 return handled;
42}
43
erikchen484c00842015-07-28 23:25:4444void AttachmentBrokerUnprivilegedWin::OnWinHandleHasBeenDuplicated(
erikchen7252aa362015-07-15 01:35:3945 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));
erikchenc04ab34c2015-07-27 20:28:2052 HandleReceivedAttachment(attachment);
erikchen7252aa362015-07-15 01:35:3953}
54
erikchen151b2f92015-06-16 20:20:5155} // namespace IPC