Roll src/third_party/WebKit 6c137a7:4aace46 (svn 202008:202009)
[chromium-blink-merge.git] / ipc / attachment_broker_unprivileged_win.cc
blob3d3e845d6b8d50c68bf611e05a28c58960ce96eb
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.
5 #include "ipc/attachment_broker_unprivileged_win.h"
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"
13 namespace IPC {
15 AttachmentBrokerUnprivilegedWin::AttachmentBrokerUnprivilegedWin() {}
17 AttachmentBrokerUnprivilegedWin::~AttachmentBrokerUnprivilegedWin() {}
19 bool AttachmentBrokerUnprivilegedWin::SendAttachmentToProcess(
20 const BrokerableAttachment* attachment,
21 base::ProcessId destination_process) {
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);
28 return get_sender()->Send(
29 new AttachmentBrokerMsg_DuplicateWinHandle(format));
31 return false;
34 bool AttachmentBrokerUnprivilegedWin::OnMessageReceived(const Message& msg) {
35 bool handled = true;
36 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerUnprivilegedWin, msg)
37 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated,
38 OnWinHandleHasBeenDuplicated)
39 IPC_MESSAGE_UNHANDLED(handled = false)
40 IPC_END_MESSAGE_MAP()
41 return handled;
44 void AttachmentBrokerUnprivilegedWin::OnWinHandleHasBeenDuplicated(
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;
50 scoped_refptr<BrokerableAttachment> attachment(
51 new IPC::internal::HandleAttachmentWin(wire_format));
52 HandleReceivedAttachment(attachment);
55 } // namespace IPC