tor-browser

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

nsIIPCSerializableInputStream.h (4925B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_ipc_nsIIPCSerializableInputStream_h
      8 #define mozilla_ipc_nsIIPCSerializableInputStream_h
      9 
     10 #include "nsISupports.h"
     11 #include "nsTArrayForwardDeclare.h"
     12 
     13 namespace mozilla {
     14 namespace ipc {
     15 
     16 class FileDescriptor;
     17 class InputStreamParams;
     18 
     19 }  // namespace ipc
     20 
     21 }  // namespace mozilla
     22 
     23 #define NS_IIPCSERIALIZABLEINPUTSTREAM_IID \
     24  {0xb0211b14, 0xea6d, 0x40d4, {0x87, 0xb5, 0x7b, 0xe3, 0xdf, 0xac, 0x09, 0xd1}}
     25 
     26 class NS_NO_VTABLE nsIIPCSerializableInputStream : public nsISupports {
     27 public:
     28  NS_INLINE_DECL_STATIC_IID(NS_IIPCSERIALIZABLEINPUTSTREAM_IID)
     29 
     30  // Determine the serialized complexity of this input stream, initializing
     31  // `*aSizeUsed`, `*aPipes` and `*aTransferables` to the number of inline
     32  // bytes/pipes/transferable resources which would be used. This will be used
     33  // by other `Serialize` implementations to potentially simplify the resulting
     34  // stream, reducing the number of pipes or file descriptors required.
     35  //
     36  // Each outparameter corresponds to a type of resource which will be included
     37  // in the serialized message, as follows:
     38  //
     39  // *aSizeUsed:
     40  //    Raw bytes to be included inline in the message's payload, usually in the
     41  //    form of a nsCString for a StringInputStreamParams. This must be less
     42  //    than or equal to `aMaxSize`. Larger payloads should instead be
     43  //    serialized using SerializeInputStreamAsPipe.
     44  // *aPipes:
     45  //    New pipes, created using SerializeInputStreamAsPipe, which will be used
     46  //    to asynchronously transfer part of the pipe over IPC. Callers such as
     47  //    nsMultiplexInputStream may choose to serialize themselves as a DataPipe
     48  //    if they contain DataPipes themselves, so existing DataPipe instances
     49  //    which are cheaply transferred should be counted as transferrables.
     50  // *aTransferables:
     51  //    Existing objects which can be more cheaply transferred over IPC than by
     52  //    serializing them inline in a payload or transferring them through a new
     53  //    DataPipe. This includes RemoteLazyInputStreams, FileDescriptors, and
     54  //    existing DataPipeReceiver instances.
     55  //
     56  // Callers of this method must have initialized all of `*aSizeUsed`,
     57  // `*aPipes`, and `*aTransferables` to 0, so implementations are not required
     58  // to initialize all outparameters. The outparameters must not be null.
     59  virtual void SerializedComplexity(uint32_t aMaxSize, uint32_t* aSizeUsed,
     60                                    uint32_t* aPipes,
     61                                    uint32_t* aTransferables) = 0;
     62 
     63  virtual void Serialize(mozilla::ipc::InputStreamParams& aParams,
     64                         uint32_t aMaxSize, uint32_t* aSizeUsed) = 0;
     65 
     66  virtual bool Deserialize(const mozilla::ipc::InputStreamParams& aParams) = 0;
     67 };
     68 
     69 #define NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM                               \
     70  virtual void SerializedComplexity(uint32_t aMaxSize, uint32_t* aSizeUsed, \
     71                                    uint32_t* aPipes,                       \
     72                                    uint32_t* aTransferrables) override;    \
     73  virtual void Serialize(mozilla::ipc::InputStreamParams&, uint32_t,        \
     74                         uint32_t*) override;                               \
     75                                                                            \
     76  virtual bool Deserialize(const mozilla::ipc::InputStreamParams&) override;
     77 
     78 #define NS_FORWARD_NSIIPCSERIALIZABLEINPUTSTREAM(_to)                       \
     79  virtual void SerializedComplexity(uint32_t aMaxSize, uint32_t* aSizeUsed, \
     80                                    uint32_t* aPipes,                       \
     81                                    uint32_t* aTransferables) override {    \
     82    _to SerializedComplexity(aMaxSize, aSizeUsed, aPipes, aTransferables);  \
     83  };                                                                        \
     84                                                                            \
     85  virtual void Serialize(mozilla::ipc::InputStreamParams& aParams,          \
     86                         uint32_t aMaxSize, uint32_t* aSizeUsed) override { \
     87    _to Serialize(aParams, aMaxSize, aSizeUsed);                            \
     88  }                                                                         \
     89                                                                            \
     90  virtual bool Deserialize(const mozilla::ipc::InputStreamParams& aParams)  \
     91      override {                                                            \
     92    return _to Deserialize(aParams);                                        \
     93  }
     94 
     95 #endif  // mozilla_ipc_nsIIPCSerializableInputStream_h