tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ProtocolMessageUtils.h (3343B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef IPC_GLUE_PROTOCOLMESSAGEUTILS_H
      8 #define IPC_GLUE_PROTOCOLMESSAGEUTILS_H
      9 
     10 #include "base/string_util.h"
     11 #include "chrome/common/ipc_channel.h"
     12 #include "chrome/common/ipc_message_utils.h"
     13 #include "ipc/EnumSerializer.h"
     14 #include "mozilla/ipc/Endpoint.h"
     15 #include "mozilla/ipc/ProtocolUtils.h"
     16 
     17 class PickleIterator;
     18 
     19 namespace mozilla::ipc {
     20 class FileDescriptor;
     21 template <class PFooSide>
     22 class Endpoint;
     23 template <class PFooSide>
     24 class ManagedEndpoint;
     25 }  // namespace mozilla::ipc
     26 
     27 namespace IPC {
     28 
     29 class Message;
     30 class MessageReader;
     31 class MessageWriter;
     32 
     33 template <>
     34 struct ParamTraits<IPCMessageStart>
     35    : ContiguousEnumSerializer<IPCMessageStart, IPCMessageStart(0),
     36                               LastMsgIndex> {};
     37 
     38 template <>
     39 struct ParamTraits<mozilla::ipc::IProtocol*> {
     40  using paramType = mozilla::ipc::IProtocol*;
     41 
     42  static void Write(MessageWriter* aWriter, const paramType& aParam);
     43 
     44  static bool Read(MessageReader* aReader, paramType* aResult);
     45 };
     46 
     47 template <>
     48 struct ParamTraits<mozilla::ipc::UntypedEndpoint> {
     49  using paramType = mozilla::ipc::UntypedEndpoint;
     50 
     51  static void Write(MessageWriter* aWriter, paramType&& aParam);
     52 
     53  static bool Read(MessageReader* aReader, paramType* aResult);
     54 };
     55 
     56 template <class PFooSide>
     57 struct ParamTraits<mozilla::ipc::Endpoint<PFooSide>>
     58    : ParamTraits<mozilla::ipc::UntypedEndpoint> {};
     59 
     60 template <>
     61 struct ParamTraits<mozilla::ipc::EndpointProcInfo> {
     62  using paramType = mozilla::ipc::EndpointProcInfo;
     63 
     64  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     65    IPC::WriteParam(aWriter, aParam.mPid);
     66    IPC::WriteParam(aWriter, aParam.mChildID);
     67  }
     68 
     69  static bool Read(MessageReader* aReader, paramType* aResult) {
     70    return IPC::ReadParam(aReader, &aResult->mPid) &&
     71           IPC::ReadParam(aReader, &aResult->mChildID);
     72  }
     73 };
     74 
     75 template <>
     76 struct ParamTraits<mozilla::ipc::UntypedManagedEndpoint> {
     77  using paramType = mozilla::ipc::UntypedManagedEndpoint;
     78 
     79  static void Write(MessageWriter* aWriter, paramType&& aParam);
     80  static bool Read(MessageReader* aReader, paramType* aResult);
     81 };
     82 
     83 template <class PFooSide>
     84 struct ParamTraits<mozilla::ipc::ManagedEndpoint<PFooSide>> {
     85  using paramType = mozilla::ipc::ManagedEndpoint<PFooSide>;
     86 
     87  static void Write(IPC::MessageWriter* aWriter, paramType&& aParam) {
     88    ParamTraits<mozilla::ipc::UntypedManagedEndpoint>::Write(aWriter,
     89                                                             std::move(aParam));
     90  }
     91 
     92  static bool Read(IPC::MessageReader* aReader, paramType* aResult) {
     93    return ParamTraits<mozilla::ipc::UntypedManagedEndpoint>::Read(aReader,
     94                                                                   aResult);
     95  }
     96 };
     97 
     98 template <>
     99 struct ParamTraits<mozilla::ipc::FileDescriptor> {
    100  using paramType = mozilla::ipc::FileDescriptor;
    101 
    102  static void Write(MessageWriter* aWriter, const paramType& aParam);
    103  static bool Read(MessageReader* aReader, paramType* aResult);
    104 };
    105 
    106 }  // namespace IPC
    107 
    108 #endif  // IPC_GLUE_PROTOCOLMESSAGEUTILS_H